From 338c5c30ebfbd9a535cd291fc679625f4ab86164 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Thu, 31 Jul 2014 12:13:19 -0400 Subject: [PATCH 01/13] Use Sage display hook in doctests --- src/sage/doctest/forker.py | 10 +++- src/sage/misc/displayhook.py | 98 ++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 4d3407ac8ad..031e997ffcc 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -88,6 +88,12 @@ def init_sage(): 2 + x + + The displayhook sorts dictionary keys to simplify doctesting of + dictionary output:: + + sage: {'a':23, 'b':34, 'au':56, 'bbf':234, 'aaa':234} + {'a': 23, 'aaa': 234, 'au': 56, 'b': 34, 'bbf': 234} """ # Do this once before forking. import sage.doctest @@ -95,7 +101,7 @@ def init_sage(): import sage.all_cmdline sage.interfaces.quit.invalidate_all() import sage.misc.displayhook - sys.displayhook = sage.misc.displayhook.DisplayHook(sys.displayhook) + sys.displayhook = sage.misc.displayhook.DisplayHook() # Switch on extra debugging from sage.structure.debug_options import debug @@ -2011,7 +2017,7 @@ def __init__(self, source): sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py') sage: FDS = FileDocTestSource(filename,DocTestDefaults()) sage: DocTestTask(FDS) - + """ self.source = source diff --git a/src/sage/misc/displayhook.py b/src/sage/misc/displayhook.py index 352fea2a86f..f22a31763d8 100644 --- a/src/sage/misc/displayhook.py +++ b/src/sage/misc/displayhook.py @@ -418,54 +418,6 @@ def try_format_graphics(self, obj): return False -class DisplayHook(DisplayHookBase): - """ - Display hook for Sage. - - This is not used directly in interactive Sage (where we use the - IPython system for display hooks). This class provides a way to - use the Sage display formatting when not using interactive Sage. - """ - def __init__(self, oldhook=sys.__displayhook__): - """ - Set the old display hook (default to repr) - - EXAMPLES:: - - sage: from sage.misc.displayhook import DisplayHook - sage: def f(o): print repr(o)[:5], "..." - sage: d = DisplayHook(f) - sage: d(range(10)) - [0, 1 ... - """ - self.oldhook = oldhook - - def __call__(self, obj): - """ - Format the object using Sage's formatting, or format it using the old - display hook if Sage does not want to handle the object. - - EXAMPLES:: - - sage: from sage.misc.displayhook import DisplayHook - sage: d = DisplayHook() - sage: d((identity_matrix(3), identity_matrix(3))) - ( - [1 0 0] [1 0 0] - [0 1 0] [0 1 0] - [0 0 1], [0 0 1] - ) - """ - if self.try_format_graphics(obj): - return - s = self.try_format_obj(obj) - if s is not None: - print(s) - __builtin__._ = obj - else: - self.oldhook(obj) - - from IPython.core.formatters import PlainTextFormatter class SagePlainTextFormatter(DisplayHookBase, PlainTextFormatter): r""" @@ -481,7 +433,7 @@ class SagePlainTextFormatter(DisplayHookBase, PlainTextFormatter): sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.display_formatter.formatters['text/plain'] - <...displayhook.SagePlainTextFormatter object at 0x...> + <...displayhook.SagePlainTextFormatter at 0x...> sage: shell.run_cell('a = identity_matrix(ZZ, 2); [a,a]') [ [1 0] [1 0] @@ -500,7 +452,7 @@ def __call__(self, obj): sage: shell = get_test_shell() sage: fmt = shell.display_formatter.formatters['text/plain'] sage: fmt - <...displayhook.SagePlainTextFormatter object at 0x...> + <...displayhook.SagePlainTextFormatter at 0x...> sage: shell.displayhook.compute_format_data(2) ({u'text/plain': '2'}, {}) sage: a = identity_matrix(ZZ, 2) @@ -526,3 +478,49 @@ def __call__(self, obj): SPTextFormatter = None + + +class DisplayHook(DisplayHookBase): + """ + Sage Display Hook + + This is not used directly in interactive Sage (where we use the + IPython system for display hooks). This class provides a way to + use the Sage "plain text" display formatting when not using + interactive Sage, for example when running doctests. + """ + def __init__(self): + """ + Python constructor + + EXAMPLES:: + + sage: from sage.misc.displayhook import DisplayHook + sage: d = DisplayHook() + sage: d(set([1, 2, 3])) # Sage commandline output + {1, 2, 3} + sage: print(set([1, 2, 3])) # Plain Python output + set([1, 2, 3]) + """ + self.formatter = SagePlainTextFormatter() + + def __call__(self, obj): + """ + Format the object using Sage's formatting, or format it using the old + display hook if Sage does not want to handle the object. + + EXAMPLES:: + + sage: from sage.misc.displayhook import DisplayHook + sage: d = DisplayHook() + sage: d((identity_matrix(3), identity_matrix(3))) + ( + [1 0 0] [1 0 0] + [0 1 0] [0 1 0] + [0 0 1], [0 0 1] + ) + """ + if obj is None: + return + print(self.formatter(obj)) + __builtin__._ = obj From a246e17f83b02d1ab63261032b17c81150dad6ea Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Wed, 17 Sep 2014 18:28:10 +0100 Subject: [PATCH 02/13] Fix printing of types --- src/sage/misc/displayhook.py | 110 +++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/src/sage/misc/displayhook.py b/src/sage/misc/displayhook.py index f22a31763d8..80d1cdff0fc 100644 --- a/src/sage/misc/displayhook.py +++ b/src/sage/misc/displayhook.py @@ -55,9 +55,13 @@ - Volker Braun (2013): refactored into DisplayHookBase """ -import sys, __builtin__ +import __builtin__ +import sys +import types + from sage.misc.lazy_import import lazy_import -lazy_import('sage.matrix.matrix','is_Matrix') +lazy_import('sage.matrix.matrix', 'is_Matrix') + class ListFormatter(object): @@ -259,27 +263,13 @@ def simple_format_obj(self, obj): sage: dhb.simple_format_obj( ....: [matrix([[1], [2]]), matrix([[3], [4]])]) '[\n[1] [3]\n[2], [4]\n]' - - TESTS: - - In :trac:`14466` we override IPython's special printing of - ``type`` objects and revert it to Python's standard string - representation:: - - sage: shell=sage.repl.interpreter.get_test_shell() - sage: shell.displayhook(type) - """ - if isinstance(obj, type): - return repr(obj) - # since #15036, we check in displayhook if a matrix is has # large enough dimensions to be printed in abbreviated form. # If so, we append a helpful message to indicate how to print # the entries of the matrix. # we need to do a late import of the is_Matrix method here to # avoid startup problems. - if is_Matrix(obj): from sage.matrix.matrix0 import max_rows,max_cols if obj.nrows() >= max_rows or obj.ncols() >= max_cols: @@ -433,13 +423,97 @@ class SagePlainTextFormatter(DisplayHookBase, PlainTextFormatter): sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.display_formatter.formatters['text/plain'] - <...displayhook.SagePlainTextFormatter at 0x...> + <...displayhook.SagePlainTextFormatter object at 0x...> sage: shell.run_cell('a = identity_matrix(ZZ, 2); [a,a]') [ [1 0] [1 0] [0 1], [0 1] ] """ + def __init__(self, *args, **kwds): + import IPython.lib.pretty + IPython.lib.pretty._default_pprint = self._python_default_pprint + super(SagePlainTextFormatter, self).__init__(*args, **kwds) + + def _python_default_pprint(self, obj, p, cycle): + """ + The default print function. + + IPython 2.2.0 has a non-configurable default pretty printer + that doesn't do what we want. So we are forced to monkey-patch + it with this method. + """ + from IPython.lib.pretty import _safe_repr + p.text(_safe_repr(obj)) + + def _type_printers_default(self): + """ + The default pretty printers + + OUTPUT: + + Dictionary with key the type to handle and value a + pretty-print function for said type. + + EXAMPLES:: + + sage: shell = sage.repl.interpreter.get_test_shell() + sage: sptf = shell.display_formatter.formatters[u'text/plain'] + sage: sptf._type_printers_default() + {: , + ... + sage: shell.displayhook(type) + + sage: shell.displayhook([type, type]) + [, ] + + TESTS: + + We don't like the following IPython defaults, see :trac:`14466`: + + sage: import types + sage: def ugly(obj): # show IPython defaults + ....: from StringIO import StringIO + ....: stream = StringIO() + ....: from IPython.lib import pretty + ....: printer = pretty.RepresentationPrinter(stream, False, + ....: 78, u'\n', + ....: singleton_pprinters=pretty._singleton_pprinters, + ....: type_pprinters=pretty._type_pprinters, + ....: deferred_pprinters=pretty._deferred_type_pprinters) + ....: printer.pretty(obj) + ....: printer.flush() + ....: return stream.getvalue() + + sage: cls_type = types.ClassType('name', (), {}); cls_type + + sage: ugly(cls_type) + '__main__.name' + + sage: types.TypeType + + sage: ugly(types.TypeType) + 'type' + + sage: types.BuiltinFunctionType + + sage: ugly(types.BuiltinFunctionType) + 'builtin_function_or_method' + """ + from IPython.lib.pretty import _safe_repr + pprinters = super(SagePlainTextFormatter, self)._type_printers_default() + # We don't like how IPython abbreviates types :trac:`14466` + del pprinters[types.TypeType]# = python_default + del pprinters[types.ClassType]# = python_default + del pprinters[types.BuiltinFunctionType]# = python_default + return pprinters + + + def _deferred_printers_default(self): + pprinters = super(SagePlainTextFormatter, self)._deferred_printers_default() + return pretty._deferred_type_pprinters.copy() + + def __call__(self, obj): r""" Computes the format data of ``result``. If the @@ -452,7 +526,7 @@ def __call__(self, obj): sage: shell = get_test_shell() sage: fmt = shell.display_formatter.formatters['text/plain'] sage: fmt - <...displayhook.SagePlainTextFormatter at 0x...> + <...displayhook.SagePlainTextFormatter object at 0x...> sage: shell.displayhook.compute_format_data(2) ({u'text/plain': '2'}, {}) sage: a = identity_matrix(ZZ, 2) From eb6a66b689158a087979f59fa0224ac3c93d8bad Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Thu, 18 Sep 2014 00:50:32 +0100 Subject: [PATCH 03/13] Refactor our displayhook IPython integration --- src/sage/doctest/forker.py | 4 +- src/sage/groups/matrix_gps/matrix_group.py | 2 +- src/sage/misc/displayhook.py | 592 +-------------------- src/sage/misc/latex.py | 2 +- src/sage/misc/sageinspect.py | 18 +- src/sage/repl/display/__init__.py | 0 src/sage/repl/display/fancy_repr.py | 372 +++++++++++++ src/sage/repl/display/formatter.py | 281 ++++++++++ src/sage/repl/display/pretty_print.py | 176 ++++++ src/sage/repl/display/python_hook.py | 62 +++ src/sage/repl/display/util.py | 163 ++++++ src/sage/repl/interpreter.py | 5 + src/sage/repl/ipython_extension.py | 4 +- src/sage/structure/parent.pyx | 2 +- 14 files changed, 1083 insertions(+), 600 deletions(-) create mode 100644 src/sage/repl/display/__init__.py create mode 100644 src/sage/repl/display/fancy_repr.py create mode 100644 src/sage/repl/display/formatter.py create mode 100644 src/sage/repl/display/pretty_print.py create mode 100644 src/sage/repl/display/python_hook.py create mode 100644 src/sage/repl/display/util.py diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 47c8cdc6c8f..78a5206ad89 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -100,8 +100,8 @@ def init_sage(): sage.doctest.DOCTEST_MODE=True import sage.all_cmdline sage.interfaces.quit.invalidate_all() - import sage.misc.displayhook - sys.displayhook = sage.misc.displayhook.DisplayHook() + import sage.repl.display.python_hook + sys.displayhook = sage.repl.display.python_hook.DoctestDisplayHook() # Switch on extra debugging from sage.structure.debug_options import debug diff --git a/src/sage/groups/matrix_gps/matrix_group.py b/src/sage/groups/matrix_gps/matrix_group.py index e920b5d9cef..b0185ea01ce 100644 --- a/src/sage/groups/matrix_gps/matrix_group.py +++ b/src/sage/groups/matrix_gps/matrix_group.py @@ -230,7 +230,7 @@ def _repr_(self): return 'Matrix group over {0} with {1} generators'.format( self.base_ring(), self.ngens()) else: - from sage.misc.displayhook import format_list + from sage.repl.display.util import format_list return 'Matrix group over {0} with {1} generators {2}'.format( self.base_ring(), self.ngens(), format_list(self.gens())) diff --git a/src/sage/misc/displayhook.py b/src/sage/misc/displayhook.py index 80d1cdff0fc..3878231620f 100644 --- a/src/sage/misc/displayhook.py +++ b/src/sage/misc/displayhook.py @@ -1,600 +1,28 @@ -# -*- coding: utf-8 -*- -r""" -Implements a displayhook for Sage. - -This displayhook has two new facilities, by default the displayhook contains a -new facility for displaying lists of matrices in an easier to read format:: - - sage: [identity_matrix(i) for i in range(2,5)] - [ - [1 0 0 0] - [1 0 0] [0 1 0 0] - [1 0] [0 1 0] [0 0 1 0] - [0 1], [0 0 1], [0 0 0 1] - ] - -This facility uses :meth:`_repr_` (and a simple string) to try do a nice read -format (see :meth:`sage.structure.parent._repr_option` for details). - -With this displayhook there exists an other way for displaying object and more -generally, all sage expression as an ASCII art object:: - - sage: from sage.repl.interpreter import get_test_shell - sage: shell = get_test_shell() - sage: shell.run_cell('%display ascii_art') - sage: shell.run_cell('integral(x^2/pi^x, x)') - / 2 2 \ -x*log(pi) - -\x *log (pi) + 2*x*log(pi) + 2/*e - --------------------------------------------- - 3 - log (pi) - sage: shell.run_cell("i = var('i')") - sage: shell.run_cell('sum(i*x^i, i, 0, 10)') - 10 9 8 7 6 5 4 3 2 - 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x - sage: shell.run_cell('StandardTableaux(4).list()') - [ - [ 1 4 1 3 - [ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2 - [ 1 2 3 4, 2 , 3 , 4 , 2 4, 3 4, 3 , 4 - - 1 ] - 1 2 2 ] - 3 3 ] - , 4 , 4 ] - sage: shell.run_cell('%display simple') - -This other facility uses a simple `AsciiArt` object -(see :class:`sage.misc.ascii_art.AsciiArt` and -:meth:`sage.structure.parent._ascii_art_`). - -AUTHORS: - -- Bill Cauchois (2009): initial version -- Jean-Baptiste Priez (2013): ASCII art -- Volker Braun (2013): refactored into DisplayHookBase """ +Old Displayhook -import __builtin__ -import sys -import types - -from sage.misc.lazy_import import lazy_import -lazy_import('sage.matrix.matrix', 'is_Matrix') - - -class ListFormatter(object): - - # This is used to wrap lines when printing "tall" lists. - MAX_COLUMN = 70 - - def _check_tall_list_and_format(self, the_list): - """ - First check whether a list is "tall" -- whether the reprs of the - elements of the list will span multiple lines and cause the list - to be printed awkwardly. If not, this function returns ``None`` and - does nothing; you should revert back to the normal method for - printing an object (its repr). If so, return the string in the - special format. Note that the special format isn't just for - matrices. Any object with a multiline repr will be formatted. - - INPUT: - - - ``the_list`` - The list (or a tuple). - - TESTS:: - - sage: from sage.misc.displayhook import DisplayHookBase - sage: dhb = DisplayHookBase() - - We test :meth:`_check_tall_list_and_format` indirectly by - calling :meth:`simple_format_obj` on a list of matrices:: - - sage: print dhb.simple_format_obj( - ....: [matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) for i in xrange(7)]) - [ - [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] - [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], - - [1 2 3 4] - [5 6 7 8] - ] - - We return ``None`` if we don't have anything special to do:: - - sage: dhb.simple_format_obj('one-line string') - sage: dhb.simple_format_obj(matrix([[1,2,3]])) - """ - # For every object to be printed, split its repr on newlines and store the - # result in this list. - split_reprs = [] - tall = False - for elem in the_list: - split_reprs.append(repr(elem).split('\n')) - if len(split_reprs[-1]) > 1: - # Meanwhile, check to make sure the list is actually "tall". - tall = True - if not tall: - return None - # Figure out which type of parenthesis to use, based on the type of the_list. - if isinstance(the_list, tuple): - parens = '()' - elif isinstance(the_list, list): - parens = '[]' - else: - raise TypeError('expected list or tuple') - - # running_lines is a list of lines, which are stored as lists of strings - # to be joined later. For each split repr, we add its lines to the - # running_lines array. When current_column exceeds MAX_COLUMN, process - # and output running_lines using _print_tall_list_row. - running_lines = [[]] - current_column = 0 - s = [parens[0]] - for split_repr in split_reprs: - width = max(len(x) for x in split_repr) - if current_column + width > self.MAX_COLUMN and not (width > self.MAX_COLUMN): - s.extend(self._tall_list_row(running_lines)) - running_lines = [[]] - current_column = 0 - current_column += width + 2 - # Add the lines from split_repr to the running_lines array. It may - # be necessary to add or remove lines from either one so that the - # number of lines matches up. - for i in xrange(len(running_lines), len(split_repr)): - running_lines.insert(0, [' ' * len(x) for x in running_lines[-1]]) - line_diff = len(running_lines) - len(split_repr) - for i, x in enumerate(split_repr): - running_lines[i + line_diff].append(x.ljust(width)) - for i in xrange(line_diff): - running_lines[i].append(' ' * width) - # Output any remaining entries. - if len(running_lines[0]) > 0: - s.extend(self._tall_list_row(running_lines, True)) - s.append(parens[1]) - return "\n".join(s) - - def _tall_list_row(self, running_lines, last_row=False): - """ - Helper for :meth:`_check_tall_list_and_format` - - This helper function processes and outputs the contents of the - running_lines array. - - TESTS:: - - sage: from sage.misc.displayhook import format_list - sage: format_list._tall_list_row(['a b', 'b c', 'c']) - ['a b', 'b c', 'c,', ''] - """ - s=[] - for i, line in enumerate(running_lines): - if i + 1 != len(running_lines): - sep, tail = ' ', '' - else: - # The commas go on the bottom line of this row. - sep, tail = ', ', '' if last_row else ',' - s.append(sep.join(line) + tail) - # Separate rows with a newline to make them stand out. - if not last_row: - s.append("") - return s - - def try_format_list(self, obj): - """ - Format list/tuple. - - OUTPUT: - - A string representation or ``None``. The latter means that no - Sage-specific formatting is defined and the default should be - used. - - EXAMPLES:: - - sage: from sage.misc.displayhook import format_list - sage: format_list.try_format_list('Hello, world!') - sage: format_list('Hello, world!') - "'Hello, world!'" - """ - ascii_art_repr = False - for o in obj: - try: - ascii_art_repr = ascii_art_repr or o.parent()._repr_option('element_ascii_art') - except (AttributeError, TypeError): - pass - if ascii_art_repr: - return self._check_tall_list_and_format(obj) - else: - return None - - def __call__(self, obj): - """ - Return a string formatting. - - This method is like :meth:`try_format_list` except that it - will always return a string. - - OUTPUT: - - String. - - EXAMPLES:: - - sage: from sage.misc.displayhook import format_list - sage: format_list.try_format_list('Hello, world!') - sage: format_list('Hello, world!') - "'Hello, world!'" - """ - s = self.try_format_list(obj) - if s is None: - return repr(obj) - else: - return s - -format_list = ListFormatter() - -class DisplayHookBase(object): - - def simple_format_obj(self, obj): - """This function is used internally by the displayhook. - - We attempt to keep ascii art of list/tuple members intact as we - print them. See :meth:`sage.structure.parent._repr_option` for - details. - - OUTPUT: - - Return a string if we want to print it in a special way; - otherwise, return ``None``. - - EXAMPLES:: - - sage: from sage.misc.displayhook import DisplayHookBase - sage: dhb = DisplayHookBase() - - For most objects, nothing is done (``None`` is returned): - - sage: dhb.simple_format_obj('Hello, world!') - sage: dhb.simple_format_obj((1, 2, 3, 4)) - - We demonstrate the special format for lists of matrices:: - - sage: dhb.simple_format_obj( - ....: [matrix([[1], [2]]), matrix([[3], [4]])]) - '[\n[1] [3]\n[2], [4]\n]' - """ - # since #15036, we check in displayhook if a matrix is has - # large enough dimensions to be printed in abbreviated form. - # If so, we append a helpful message to indicate how to print - # the entries of the matrix. - # we need to do a late import of the is_Matrix method here to - # avoid startup problems. - if is_Matrix(obj): - from sage.matrix.matrix0 import max_rows,max_cols - if obj.nrows() >= max_rows or obj.ncols() >= max_cols: - return repr(obj) + " (use the '.str()' method to see the entries)" - else: - return None - if isinstance(obj, (tuple, list)) and len(obj) > 0: - return format_list.try_format_list(obj) - else: - return None - - def set_display(self, mode): - r""" - Select the text formatting method. - - INPUT: - - - ``mode`` -- string. One of ``simple``, ``ascii_art``, or ``typeset``. - - See :func:`simple_format_obj` or :func:`sage.misc.ascii_art.ascii_art`. - - TESTS:: - - sage: [identity_matrix(i) for i in range(3,7)] - [ - [1 0 0 0 0 0] - [1 0 0 0 0] [0 1 0 0 0 0] - [1 0 0 0] [0 1 0 0 0] [0 0 1 0 0 0] - [1 0 0] [0 1 0 0] [0 0 1 0 0] [0 0 0 1 0 0] - [0 1 0] [0 0 1 0] [0 0 0 1 0] [0 0 0 0 1 0] - [0 0 1], [0 0 0 1], [0 0 0 0 1], [0 0 0 0 0 1] - ] - sage: from sage.repl.interpreter import get_test_shell - sage: shell = get_test_shell() - sage: shell.run_cell('%display ascii_art') # indirect doctest - sage: shell.run_cell("i = var('i')") - sage: shell.run_cell('sum(i*x^i, i, 0, 10)') - 10 9 8 7 6 5 4 3 2 - 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x - sage: shell.run_cell('%display simple') - """ - if mode not in ['simple', 'ascii_art', 'typeset']: - raise ValueError('invalid mode set') - self.mode = mode - - mode = 'simple' - - @property - def simple(self): - """ - Whether the mode is the "simple" (default) display. - - EXAMPLES:: - - sage: sys.displayhook.simple - True - sage: sys.displayhook.ascii_art - False - """ - return self.mode == 'simple' - - @property - def ascii_art(self): - """ - Whether the mode is the ascii art display. - - EXAMPLES:: - - sage: sys.displayhook.simple - True - sage: sys.displayhook.ascii_art - False - """ - return self.mode == 'ascii_art' - - @property - def typeset(self): - """ - Whether the mode is the notebook "Typeset" display. - - EXAMPLES:: - - sage: sys.displayhook.simple - True - sage: sys.displayhook.typeset - False - """ - return self.mode == 'typeset' - - def try_format_obj(self, obj): - """ - Format non-graphics object. - - OUTPUT: - - A string representation or ``None``. The latter means that no - Sage-specific formatting is defined and the default should be - used. - - TESTS:: - - sage: from sage.misc.displayhook import DisplayHookBase - sage: dhb = DisplayHookBase() - sage: dhb.try_format_obj('Hello, world!') - """ - if self.simple: - return self.simple_format_obj(obj) - if self.ascii_art: - from sage.misc.ascii_art import ascii_art - return ascii_art(obj) - if self.typeset: - from sage.misc.latex import pretty_print - pretty_print(obj) - return '' - assert(False) - - def try_format_graphics(self, obj): - """ - Format graphics object. - - OUTPUT: - - Boolean. Whether the object is graphics and was successfully - displayed. - - TESTS:: - - sage: from sage.misc.displayhook import DisplayHookBase - sage: dhb = DisplayHookBase() - sage: dhb.try_format_graphics('Hello, world!') - False - """ - from sage.structure.sage_object import SageObject - if isinstance(obj, SageObject) and hasattr(obj, '_graphics_'): - return obj._graphics_() - return False - - -from IPython.core.formatters import PlainTextFormatter -class SagePlainTextFormatter(DisplayHookBase, PlainTextFormatter): - r""" - A replacement for the plain text formatter which can use two facilities: - - - correctly print lists of matrices or other objects (see - :meth:`sage.structure.parent._repr_option`), - - print ASCII art objects (like expressions) (see - :meth:`sage.structure.parent._ascii_art_`). - - EXAMPLES:: - - sage: from sage.repl.interpreter import get_test_shell - sage: shell = get_test_shell() - sage: shell.display_formatter.formatters['text/plain'] - <...displayhook.SagePlainTextFormatter object at 0x...> - sage: shell.run_cell('a = identity_matrix(ZZ, 2); [a,a]') - [ - [1 0] [1 0] - [0 1], [0 1] - ] - """ - def __init__(self, *args, **kwds): - import IPython.lib.pretty - IPython.lib.pretty._default_pprint = self._python_default_pprint - super(SagePlainTextFormatter, self).__init__(*args, **kwds) - - def _python_default_pprint(self, obj, p, cycle): - """ - The default print function. - - IPython 2.2.0 has a non-configurable default pretty printer - that doesn't do what we want. So we are forced to monkey-patch - it with this method. - """ - from IPython.lib.pretty import _safe_repr - p.text(_safe_repr(obj)) - - def _type_printers_default(self): - """ - The default pretty printers - - OUTPUT: - - Dictionary with key the type to handle and value a - pretty-print function for said type. - - EXAMPLES:: - - sage: shell = sage.repl.interpreter.get_test_shell() - sage: sptf = shell.display_formatter.formatters[u'text/plain'] - sage: sptf._type_printers_default() - {: , - ... - sage: shell.displayhook(type) - - sage: shell.displayhook([type, type]) - [, ] - - TESTS: - - We don't like the following IPython defaults, see :trac:`14466`: - - sage: import types - sage: def ugly(obj): # show IPython defaults - ....: from StringIO import StringIO - ....: stream = StringIO() - ....: from IPython.lib import pretty - ....: printer = pretty.RepresentationPrinter(stream, False, - ....: 78, u'\n', - ....: singleton_pprinters=pretty._singleton_pprinters, - ....: type_pprinters=pretty._type_pprinters, - ....: deferred_pprinters=pretty._deferred_type_pprinters) - ....: printer.pretty(obj) - ....: printer.flush() - ....: return stream.getvalue() - - sage: cls_type = types.ClassType('name', (), {}); cls_type - - sage: ugly(cls_type) - '__main__.name' - - sage: types.TypeType - - sage: ugly(types.TypeType) - 'type' - - sage: types.BuiltinFunctionType - - sage: ugly(types.BuiltinFunctionType) - 'builtin_function_or_method' - """ - from IPython.lib.pretty import _safe_repr - pprinters = super(SagePlainTextFormatter, self)._type_printers_default() - # We don't like how IPython abbreviates types :trac:`14466` - del pprinters[types.TypeType]# = python_default - del pprinters[types.ClassType]# = python_default - del pprinters[types.BuiltinFunctionType]# = python_default - return pprinters - - - def _deferred_printers_default(self): - pprinters = super(SagePlainTextFormatter, self)._deferred_printers_default() - return pretty._deferred_type_pprinters.copy() - - - def __call__(self, obj): - r""" - Computes the format data of ``result``. If the - :func:`sage.misc.displayhook.simple_format_obj` writes a string, then - we override IPython's :class:`DisplayHook` formatting. - - EXAMPLES:: - - sage: from sage.repl.interpreter import get_test_shell - sage: shell = get_test_shell() - sage: fmt = shell.display_formatter.formatters['text/plain'] - sage: fmt - <...displayhook.SagePlainTextFormatter object at 0x...> - sage: shell.displayhook.compute_format_data(2) - ({u'text/plain': '2'}, {}) - sage: a = identity_matrix(ZZ, 2) - sage: shell.displayhook.compute_format_data([a,a]) - ({u'text/plain': '[\n[1 0] [1 0]\n[0 1], [0 1]\n]'}, {}) - sage: fmt.set_display('ascii_art') - sage: shell.displayhook.compute_format_data([a,a]) - ({u'text/plain': [ [1 0] [1 0] ] - [ [0 1], [0 1] ]}, {}) - - sage: i = var('i') - sage: shell.displayhook.compute_format_data(sum(i*x^i, i, 0, 10)) - ({u'text/plain': 10 9 8 7 6 5 4 3 2 - 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x}, {}) - sage: fmt.set_display('simple') - """ - if self.try_format_graphics(obj): - return '' - s = self.try_format_obj(obj) - if s is None: - s = super(SagePlainTextFormatter, self).__call__(obj) - return s - +Just for compatibility with the notebook, you should not use this any +more. Look into ``sage/repl/display`` instead. +""" -SPTextFormatter = None +from sage.repl.display.python_hook import DoctestDisplayHook +from sage.repl.display.formatter import SageConsoleTextFormatter -class DisplayHook(DisplayHookBase): - """ - Sage Display Hook +class DisplayHook(DoctestDisplayHook): - This is not used directly in interactive Sage (where we use the - IPython system for display hooks). This class provides a way to - use the Sage "plain text" display formatting when not using - interactive Sage, for example when running doctests. - """ def __init__(self): """ Python constructor EXAMPLES:: - sage: from sage.misc.displayhook import DisplayHook + sage: from sage.repl.display.python_hook import DisplayHook sage: d = DisplayHook() sage: d(set([1, 2, 3])) # Sage commandline output {1, 2, 3} sage: print(set([1, 2, 3])) # Plain Python output set([1, 2, 3]) """ - self.formatter = SagePlainTextFormatter() - - def __call__(self, obj): - """ - Format the object using Sage's formatting, or format it using the old - display hook if Sage does not want to handle the object. - - EXAMPLES:: - - sage: from sage.misc.displayhook import DisplayHook - sage: d = DisplayHook() - sage: d((identity_matrix(3), identity_matrix(3))) - ( - [1 0 0] [1 0 0] - [0 1 0] [0 1 0] - [0 0 1], [0 0 1] - ) - """ - if obj is None: - return - print(self.formatter(obj)) - __builtin__._ = obj + # do not call super, we set our own formatter + self.formatter = SageConsoleTextFormatter() diff --git a/src/sage/misc/latex.py b/src/sage/misc/latex.py index 41a1d12613d..b4f8de327a0 100644 --- a/src/sage/misc/latex.py +++ b/src/sage/misc/latex.py @@ -2519,7 +2519,7 @@ def pretty_print_default(enable=True): 'foo' """ import sys - sys.displayhook.set_display('typeset' if enable else 'simple') + sys.displayhook.formatter.set_display('typeset' if enable else 'simple') common_varnames = ['alpha', diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index dff4baa4fd8..be9af6f0996 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -1797,19 +1797,17 @@ def sage_getsourcelines(obj, is_binary=False): (['cdef class MPolynomialRing_libsingular(MPolynomialRing_generic):\n', '\n', ' def __cinit__(self):\n', - ... - ' M.append(new_MP(self, p_Copy(tempvector, _ring)))\n', - ' return M\n'], ...) + ...) sage: sage_getsourcelines(I) (['class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \\\n', - ... - ' return result_ring.ideal(result)\n'], ...) + ...) sage: x = var('x') sage: sage_getsourcelines(x) (['cdef class Expression(CommutativeRingElement):\n', ' cpdef object pyobject(self):\n', - ... - ' return self / x\n'], ...) + ...) + sage: sage_getsourcelines(x)[0][-1] # last line + ' return self / x\n' We show some enhancements provided by :trac:`11768`. First, we use a dummy parent class that has defined an element class by a @@ -1839,8 +1837,7 @@ class Element: sage: C = Rings() sage: HC = C.hom_category() sage: sage_getsourcelines(HC) - ([' class HomCategory(HomCategory):\n', ...], ...) - + ([' class HomCategory(HomCategory):\n', ...) Testing against a bug that has occured during work on #11768:: @@ -1852,8 +1849,7 @@ class Element: ' MPolynomialIdeal_magma_repr, \\\n', ' Ideal_generic ):\n', ' def __init__(self, ring, gens, coerce=True):\n', - ... - ' return result_ring.ideal(result)\n'], ...) + ...) AUTHORS: diff --git a/src/sage/repl/display/__init__.py b/src/sage/repl/display/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/sage/repl/display/fancy_repr.py b/src/sage/repl/display/fancy_repr.py new file mode 100644 index 00000000000..ad3d6189393 --- /dev/null +++ b/src/sage/repl/display/fancy_repr.py @@ -0,0 +1,372 @@ +# -*- coding: utf-8 -*- +""" +Representations of objects. +""" + +#***************************************************************************** +# Copyright (C) 2014 Volker Braun +# +# Distributed under the terms of the GNU General Public License (GPL) +# as published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + + +import types + +from IPython.lib.pretty import ( + _safe_getattr, _baseclass_reprs, _safe_repr, + _type_pprinters, +) + +from IPython.lib import pretty + +from sage.repl.display.util import format_list + + +class ObjectReprABC(object): + """ + The abstract base class of an object representer. + """ + def __repr__(self): + """ + Return string representation. + + OUTPUT: + + String. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import ObjectReprABC + sage: ObjectReprABC() + ObjectReprABC pretty printer + """ + return('{0} pretty printer'.format(self.__class__.__name__)) + + def __call__(self, obj, p, cycle): + """ + Format object. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import ObjectReprABC + sage: ObjectReprABC().format_string(123) # indirect doctest + 'Error: ObjectReprABC.__call__ is abstract' + """ + p.text('Error: ObjectReprABC.__call__ is abstract') + return True + + def format_string(self, obj): + """ + For doctesting only: Directly return string. + + INPUT: + + - ``obj`` -- anything. Object to format. + + OUTPUT: + + String. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import ObjectReprABC + sage: ObjectReprABC().format_string(123) + 'Error: ObjectReprABC.__call__ is abstract' + """ + from sage.repl.display.pretty_print import SagePrettyPrinter + import StringIO + stream = StringIO.StringIO() + p = SagePrettyPrinter(stream, 79, '\n') + ok = self(obj, p, False) + if ok: + p.flush() + return stream.getvalue() + else: + return '--- object not handled by representer ---' + + +class SomeIPythonRepr(ObjectReprABC): + + def __init__(self): + """ + Some selected representers from IPython + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import SomeIPythonRepr + sage: SomeIPythonRepr() + SomeIPythonRepr pretty printer + """ + type_repr = _type_pprinters.copy() + del type_repr[types.TypeType] + del type_repr[types.ClassType] + del type_repr[types.BuiltinFunctionType] + del type_repr[types.FunctionType] + del type_repr[str] + self._type_repr = type_repr + + def __call__(self, obj, p, cycle): + """ + Format object. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import SomeIPythonRepr + sage: pp = SomeIPythonRepr() + sage: pp.format_string(set([1, 2, 3])) + '{1, 2, 3}' + """ + try: + pretty_repr = self._type_repr[type(obj)] + except KeyError: + return False + pretty_repr(obj, p, cycle) + return True + + +class LargeMatrixHelpRepr(ObjectReprABC): + """ + Representation including help for large Sage matrices + """ + + def __call__(self, obj, p, cycle): + """ + Format matrix. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import LargeMatrixHelpRepr + sage: M = identity_matrix(40) + sage: pp = LargeMatrixHelpRepr() + sage: pp.format_string(M) + "40 x 40 dense matrix over Integer Ring (use the '.str()' method to see the entries)" + sage: pp.format_string([M, M]) + '--- object not handled by representer ---' + + Leads to:: + + sage: M + 40 x 40 dense matrix over Integer Ring (use the '.str()' method to see the entries) + sage: [M, M] + [40 x 40 dense matrix over Integer Ring, + 40 x 40 dense matrix over Integer Ring] + """ + if not p.toplevel(): + # Do not print the help for matrices inside containers + return False + from sage.matrix.matrix1 import Matrix + if not isinstance(obj, Matrix): + return False + from sage.matrix.matrix0 import max_rows, max_cols + if obj.nrows() < max_rows and obj.ncols() < max_cols: + return False + p.text( + str(obj) + " (use the '.str()' method to see the entries)" + ) + return True + + + +class PlainPythonRepr(ObjectReprABC): + """ + The ordinary Python representation + """ + + def __call__(self, obj, p, cycle): + """ + Format matrix. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import PlainPythonRepr + sage: pp = PlainPythonRepr() + sage: pp.format_string(type(1)) + "" + """ + klass = _safe_getattr(obj, '__class__', None) or type(obj) + klass_repr = _safe_getattr(klass, '__repr__', None) + if klass_repr in _baseclass_reprs: + p.text(klass_repr(obj)) + else: + # A user-provided repr. Find newlines and replace them with p.break_() + output = _safe_repr(obj) + for idx, output_line in enumerate(output.splitlines()): + if idx: + p.break_() + p.text(output_line) + return True + + +class AsciiArtRepr(ObjectReprABC): + """ + Ascii Art representation + """ + + def __call__(self, obj, p, cycle): + """ + Return ascii art format. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import AsciiArtRepr + sage: pp = AsciiArtRepr() + sage: pp.format_string(x/2) + 'x\n-\n2' + """ + from sage.misc.ascii_art import ascii_art + output = ascii_art(obj) + p.text(output) + return True + + +class TypesetRepr(ObjectReprABC): + """ + Typeset representation + """ + + def __call__(self, obj, p, cycle): + """ + Return typeset format. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import TypesetRepr + sage: pp = TypesetRepr() + sage: pp.format_string(x/2) + + '' + """ + # We should probably return that as string, but + # latex.pretty_print doesn't give us a useful interface + from sage.misc.latex import pretty_print + pretty_print(obj) + return True + + +class TallListRepr(ObjectReprABC): + """ + Special representation for lists with tall entries (e.g. matrices) + """ + + def __call__(self, obj, p, cycle): + """ + Format list/tuple. + + INPUT: + + - ``obj`` -- anything. Object to format. + + - ``p`` -- PrettyPrinter instance. + + - ``cycle`` -- boolean. Whether there is a cycle. + + OUTPUT: + + Boolean. Whether the representer is applicable to ``obj``. If + ``True``, the string representation is appended to ``p``. + + EXAMPLES:: + + sage: from sage.repl.display.fancy_repr import TallListRepr + sage: format_list = TallListRepr().format_string + sage: format_list([1, 2, identity_matrix(2)]) + '[\n [1 0]\n1, 2, [0 1]\n]' + """ + if not (isinstance(obj, (tuple, list)) and len(obj) > 0): + return False + ascii_art_repr = False + for o in obj: + try: + ascii_art_repr = ascii_art_repr or o.parent()._repr_option('element_ascii_art') + except (AttributeError, TypeError): + pass + if not ascii_art_repr: + return False + output = format_list.try_format(obj) + if output is None: + return False + p.text(output) + return True + + diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py new file mode 100644 index 00000000000..8d7e4f41339 --- /dev/null +++ b/src/sage/repl/display/formatter.py @@ -0,0 +1,281 @@ +# -*- coding: utf-8 -*- +r""" +IPython Displayhook Formatters + +The classes in this module can be used as IPython displayhook +formatters. It has two main features, by default the displayhook +contains a new facility for displaying lists of matrices in an easier +to read format:: + + sage: [identity_matrix(i) for i in range(2,5)] + [ + [1 0 0 0] + [1 0 0] [0 1 0 0] + [1 0] [0 1 0] [0 0 1 0] + [0 1], [0 0 1], [0 0 0 1] + ] + +This facility uses :meth:`_repr_` (and a simple string) to try do a nice read +format (see :meth:`sage.structure.parent._repr_option` for details). + +With this displayhook there exists an other way for displaying object and more +generally, all sage expression as an ASCII art object:: + + sage: from sage.repl.interpreter import get_test_shell + sage: shell = get_test_shell() + sage: shell.run_cell('%display ascii_art') + sage: shell.run_cell('integral(x^2/pi^x, x)') + / 2 2 \ -x*log(pi) + -\x *log (pi) + 2*x*log(pi) + 2/*e + --------------------------------------------- + 3 + log (pi) + sage: shell.run_cell("i = var('i')") + sage: shell.run_cell('sum(i*x^i, i, 0, 10)') + 10 9 8 7 6 5 4 3 2 + 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x + sage: shell.run_cell('StandardTableaux(4).list()') + [ + [ 1 4 1 3 + [ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2 + [ 1 2 3 4, 2 , 3 , 4 , 2 4, 3 4, 3 , 4 + + 1 ] + 1 2 2 ] + 3 3 ] + , 4 , 4 ] + sage: shell.run_cell('%display simple') + +This other facility uses a simple `AsciiArt` object (see +:class:`sage.misc.ascii_art.AsciiArt` and +:meth:`sage.structure.parent._ascii_art_`). +""" + +#***************************************************************************** +# Copyright (C) 2014 Volker Braun +# +# Distributed under the terms of the GNU General Public License (GPL) +# as published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + + +from IPython.core.formatters import PlainTextFormatter, warn_format_error +from IPython.utils.py3compat import str_to_unicode, unicode_to_str + +from sage.repl.display.pretty_print import ( + SagePrettyPrinter, AsciiArtPrettyPrinter, TypesetPrettyPrinter +) + + +class SagePlainTextFormatter(PlainTextFormatter): + + def __init__(self, *args, **kwds): + r""" + Improved plain text formatter. + + In particular, it has the following two features: + + - correctly print lists of matrices or other objects (see + :meth:`sage.structure.parent._repr_option`), + + - print ASCII art objects (like expressions) (see + :meth:`sage.structure.parent._ascii_art_`). + + EXAMPLES:: + + sage: from sage.repl.interpreter import get_test_shell + sage: shell = get_test_shell() + sage: shell.display_formatter.formatters['text/plain'] + + sage: shell.run_cell('a = identity_matrix(ZZ, 2); [a,a]') + [ + [1 0] [1 0] + [0 1], [0 1] + ] + """ + super(SagePlainTextFormatter, self).__init__(*args, **kwds) + self.set_display('simple') + + def set_display(self, mode): + r""" + Select the text formatting method. + + INPUT: + + - ``mode`` -- string. One of ``simple``, ``ascii_art``, or ``typeset``. + + EXAMPLES:: + + sage: [identity_matrix(i) for i in range(3,7)] + [ + [1 0 0 0 0 0] + [1 0 0 0 0] [0 1 0 0 0 0] + [1 0 0 0] [0 1 0 0 0] [0 0 1 0 0 0] + [1 0 0] [0 1 0 0] [0 0 1 0 0] [0 0 0 1 0 0] + [0 1 0] [0 0 1 0] [0 0 0 1 0] [0 0 0 0 1 0] + [0 0 1], [0 0 0 1], [0 0 0 0 1], [0 0 0 0 0 1] + ] + sage: from sage.repl.interpreter import get_test_shell + sage: shell = get_test_shell() + sage: shell.run_cell('%display ascii_art') # indirect doctest + sage: shell.run_cell("i = var('i')") + sage: shell.run_cell('sum(i*x^i, i, 0, 10)') + 10 9 8 7 6 5 4 3 2 + 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x + sage: shell.run_cell('%display simple') + """ + if mode not in ['simple', 'ascii_art', 'typeset']: + raise ValueError('invalid mode set') + self._mode = mode + self._pretty_printer_class = dict( + simple=SagePrettyPrinter, + ascii_art=AsciiArtPrettyPrinter, + typeset=TypesetPrettyPrinter, + )[mode] + + _mode = 'simple' + + @property + def simple(self): + """ + Whether the mode is the "simple" (default) display. + + OUTPUT: + + Boolean. + + EXAMPLES:: + + sage: sys.displayhook.formatter.simple + True + sage: sys.displayhook.formatter.ascii_art + False + """ + return self._mode == 'simple' + + @property + def ascii_art(self): + """ + Whether the mode is the ascii art display. + + OUTPUT: + + Boolean. + + EXAMPLES:: + + sage: sys.displayhook.formatter.simple + True + sage: sys.displayhook.formatter.ascii_art + False + """ + return self._mode == 'ascii_art' + + @property + def typeset(self): + """ + Whether the mode is the notebook "Typeset" display. + + OUTPUT: + + Boolean. + + EXAMPLES:: + + sage: sys.displayhook.formatter.simple + True + sage: sys.displayhook.formatter.typeset + False + """ + return self._mode == 'typeset' + + @warn_format_error + def __call__(self, obj): + """ + Compute the pretty representation of the object. + + Adapted from ``IPython.core.formatters.PlainTextPrettyPrint``. + + INPUT: + + - ``obj`` -- anything. + + OUTPUT: + + String. The plain text representation. + + EXAMPLES:: + + sage: from sage.repl.interpreter import get_test_shell + sage: shell = get_test_shell() + sage: fmt = shell.display_formatter.formatters['text/plain'] + sage: fmt + + sage: shell.displayhook.compute_format_data(2) + ({u'text/plain': '2'}, {}) + sage: a = identity_matrix(ZZ, 2) + sage: shell.displayhook.compute_format_data([a,a]) + ({u'text/plain': '[\n[1 0] [1 0]\n[0 1], [0 1]\n]'}, {}) + sage: fmt.set_display('ascii_art') + sage: shell.displayhook.compute_format_data([a,a]) + ({u'text/plain': '[ [1 0] [1 0] ]\n[ [0 1], [0 1] ]'}, {}) + sage: i = var('i') + sage: shell.displayhook.compute_format_data(sum(i*x^i, i, 0, 10)) + ({u'text/plain': ' 10 9 8 7 6 5 4 3 + 2 \n10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x'}, + {}) + sage: fmt.set_display('simple') + """ + import StringIO + stream = StringIO.StringIO() + printer = self._pretty_printer_class( + stream, self.max_width, unicode_to_str(self.newline)) + printer.pretty(obj) + printer.flush() + return stream.getvalue() + + +class SageConsoleTextFormatter(SagePlainTextFormatter): + + @warn_format_error + def __call__(self, obj): + """ + Display ``obj``. + + This is the default formatter for the Sage command line + interface. + + If the object is graphics, the empty string is written to the + output. An external viewer is started in a separate process as + a side effect. + + Otherwise, the usual textual representation is generated. + + INPUT: + + - ``obj`` -- anything. + + OUTPUT: + + String. The plain text representation. + + EXAMPLES:: + + sage: class FooGraphics(SageObject): + ....: def _graphics_(self): + ....: print('showing graphics') + ....: return True + sage: from sage.repl.display.formatter import SageConsoleTextFormatter + sage: fmt = SageConsoleTextFormatter() + sage: fmt(FooGraphics()) + showing graphics + '' + """ + from sage.structure.sage_object import SageObject + if isinstance(obj, SageObject) and hasattr(obj, '_graphics_'): + success = obj._graphics_() + if success: + return '' + return super(SageConsoleTextFormatter, self).__call__(obj) diff --git a/src/sage/repl/display/pretty_print.py b/src/sage/repl/display/pretty_print.py new file mode 100644 index 00000000000..7c5651c7760 --- /dev/null +++ b/src/sage/repl/display/pretty_print.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- +""" +The Sage pretty printer + +Any transformation to a string goes through here. In other words, the +:class:`~sage.repl.displayhook.formatter.SagePlainTextFormatter` is +entirely implemented via :class:`SagePrettyPrinter`. Other formatters +may or may not use :class:`SagePrettyPrinter` to generate text output. + +AUTHORS: + +- Bill Cauchois (2009): initial version +- Jean-Baptiste Priez (2013): ASCII art +- Volker Braun (2013): refactored into DisplayHookBase +""" + +#***************************************************************************** +# Copyright (C) 2014 Volker Braun +# +# Distributed under the terms of the GNU General Public License (GPL) +# as published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + + +from IPython.lib.pretty import PrettyPrinter + +from sage.repl.display.fancy_repr import * + + + + +class SagePrettyPrinter(PrettyPrinter): + + DEBUG = False + + # These object representers will be tried, in this order, until + # one is found that is able to deal with the object. + pretty_repr = ( + TallListRepr(), + LargeMatrixHelpRepr(), + SomeIPythonRepr(), + PlainPythonRepr(), + ) + + def toplevel(self): + """ + Return whether we are currently at the top level. + + OUTPUT: + + Boolean. Whether we are currently pretty-printing an object at + the outermost level (``True``), or whether the object is + inside a container (``False``). + + EXAMPLES:: + + sage: from sage.repl.display.pretty_print import SagePrettyPrinter + sage: import StringIO + sage: stream = StringIO.StringIO() + sage: spp = SagePrettyPrinter(stream, 78, '\n') + sage: spp.toplevel() + True + """ + return len(self.stack) <= 1 # only the object currently being represented + + def __init__(self, output, max_width, newline, max_seq_length=None): + """ + Pretty print Sage objects for the commandline + + INPUT: + + See IPython documentation. + + EXAMPLES:: + + sage: 123 + 123 + + IPython pretty printers:: + + sage: set({1, 2, 3}) + {1, 2, 3} + sage: dict(zzz=123, aaa=99, xab=10) # sorted by keys + {'aaa': 99, 'xab': 10, 'zzz': 123} + + These are overridden in IPython in a way that we feel is somewhat + confusing, and we prefer to print them like plain Python which is + more informative. See :trac:`14466` :: + + sage: 'this is a string' + 'this is a string' + sage: type(123) + + sage: type + + sage: [type, type] + [, ] + sage: import types + sage: types.ClassType('name', (), {}) + + sage: types.TypeType + + sage: types.BuiltinFunctionType + + + sage: def foo(): pass + sage: foo + + """ + super(SagePrettyPrinter, self).__init__( + output, max_width, newline, max_seq_length=max_seq_length) + self.stack = [] + + def pretty(self, obj): + r""" + Pretty print ``obj`` + + This is the only method that outside code should invoke. + + INPUT: + + - ``obj`` -- anything. + + OUTPUT: + + String representation for object. + + EXAMPLES:: + + sage: from sage.repl.display.pretty_print import SagePrettyPrinter + sage: import StringIO + sage: stream = StringIO.StringIO() + sage: SagePrettyPrinter(stream, 78, '\n').pretty([type, 123, 'foo']) + sage: stream.getvalue() + "[," + """ + obj_id = id(obj) + cycle = obj_id in self.stack + self.stack.append(obj_id) + self.begin_group() + try: + ok = False + for representation in self.pretty_repr: + if self.DEBUG: print('Trying {0}'.format(representation)) + ok = representation(obj, self, cycle) + if self.DEBUG: print('ok = {0}'.format(ok)) + if ok not in [True, False]: + raise RuntimeError('printer failed to return boolean') + if ok: + break + if not ok: + raise RuntimeError('no printer registered for object') + finally: + self.end_group() + self.stack.pop() + + + +class AsciiArtPrettyPrinter(SagePrettyPrinter): + + pretty_repr = ( + AsciiArtRepr(), + ) + SagePrettyPrinter.pretty_repr + + +class TypesetPrettyPrinter(SagePrettyPrinter): + + pretty_repr = ( + TypesetRepr(), + ) + SagePrettyPrinter.pretty_repr + + + + diff --git a/src/sage/repl/display/python_hook.py b/src/sage/repl/display/python_hook.py new file mode 100644 index 00000000000..e695b4f7f42 --- /dev/null +++ b/src/sage/repl/display/python_hook.py @@ -0,0 +1,62 @@ +""" +The display hook for plain Python + +This is not used directly in interactive Sage (where we use the +IPython system for display hooks). This class provides a way to use +the Sage "plain text" display formatting when not using interactive +Sage, for example when running doctests. +""" + +#***************************************************************************** +# Copyright (C) 2014 Volker Braun +# +# Distributed under the terms of the GNU General Public License (GPL) +# as published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + + +import __builtin__ + + +from sage.repl.display.formatter import SagePlainTextFormatter + + +class DoctestDisplayHook(object): + + def __init__(self): + """ + Python constructor + + EXAMPLES:: + + sage: from sage.repl.display.python_hook import DoctestDisplayHook + sage: d = DoctestDisplayHook() + sage: d(set([1, 2, 3])) # Sage commandline output + {1, 2, 3} + sage: print(set([1, 2, 3])) # Plain Python output + set([1, 2, 3]) + """ + self.formatter = SagePlainTextFormatter() + + def __call__(self, obj): + """ + Format the object using Sage's formatting, or format it using the old + display hook if Sage does not want to handle the object. + + EXAMPLES:: + + sage: from sage.repl.display.python_hook import DoctestDisplayHook + sage: d = DoctestDisplayHook() + sage: d((identity_matrix(3), identity_matrix(3))) + ( + [1 0 0] [1 0 0] + [0 1 0] [0 1 0] + [0 0 1], [0 0 1] + ) + """ + if obj is None: + return + print(self.formatter(obj)) + __builtin__._ = obj diff --git a/src/sage/repl/display/util.py b/src/sage/repl/display/util.py new file mode 100644 index 00000000000..6de8c031eb1 --- /dev/null +++ b/src/sage/repl/display/util.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*- +""" +Utility functions for pretty-printing + +These utility functions are used in the implementations of ``_repr_`` +methods elsewhere. +""" + +#***************************************************************************** +# Copyright (C) 2014 Volker Braun +# +# Distributed under the terms of the GNU General Public License (GPL) +# as published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + + +class _TallListFormatter(object): + """ + Special representation for lists with tall entries (e.g. matrices) + """ + + # This is used to wrap lines when printing "tall" lists. + MAX_COLUMN = 70 + + def _tall_list_row(self, running_lines, last_row=False): + """ + Helper for :meth:`_check_tall_list_and_format` + + This helper function processes and outputs the contents of the + running_lines array. + + TESTS:: + + sage: from sage.repl.display.util import format_list + sage: format_list._tall_list_row(['a b', 'b c', 'c']) + ['a b', 'b c', 'c,', ''] + """ + s=[] + for i, line in enumerate(running_lines): + if i + 1 != len(running_lines): + sep, tail = ' ', '' + else: + # The commas go on the bottom line of this row. + sep, tail = ', ', '' if last_row else ',' + s.append(sep.join(line) + tail) + # Separate rows with a newline to make them stand out. + if not last_row: + s.append("") + return s + + def try_format(self, the_list): + """ + First check whether a list is "tall" -- whether the reprs of the + elements of the list will span multiple lines and cause the list + to be printed awkwardly. If not, this function returns ``None`` and + does nothing; you should revert back to the normal method for + printing an object (its repr). If so, return the string in the + special format. Note that the special format isn't just for + matrices. Any object with a multiline repr will be formatted. + + INPUT: + + - ``the_list`` - The list (or a tuple). + + OUTPUT: + + String or ``None``. The latter is returned if the list is not + deemed to be tall enough and another formatter should be used. + + TESTS:: + + sage: from sage.repl.display.util import format_list + sage: print format_list.try_format( + ....: [matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) for i in xrange(7)]) + [ + [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] + [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], + + [1 2 3 4] + [5 6 7 8] + ] + + sage: format_list.try_format(['not', 'tall']) is None + True + """ + # For every object to be printed, split its repr on newlines and store the + # result in this list. + split_reprs = [] + tall = False + for elem in the_list: + split_reprs.append(repr(elem).split('\n')) + if len(split_reprs[-1]) > 1: + # Meanwhile, check to make sure the list is actually "tall". + tall = True + if not tall: + return None + # Figure out which type of parenthesis to use, based on the type of the_list. + if isinstance(the_list, tuple): + parens = '()' + elif isinstance(the_list, list): + parens = '[]' + else: + raise TypeError('expected list or tuple') + + # running_lines is a list of lines, which are stored as lists of strings + # to be joined later. For each split repr, we add its lines to the + # running_lines array. When current_column exceeds MAX_COLUMN, process + # and output running_lines using _print_tall_list_row. + running_lines = [[]] + current_column = 0 + s = [parens[0]] + for split_repr in split_reprs: + width = max(len(x) for x in split_repr) + if current_column + width > self.MAX_COLUMN and not (width > self.MAX_COLUMN): + s.extend(self._tall_list_row(running_lines)) + running_lines = [[]] + current_column = 0 + current_column += width + 2 + # Add the lines from split_repr to the running_lines array. It may + # be necessary to add or remove lines from either one so that the + # number of lines matches up. + for i in xrange(len(running_lines), len(split_repr)): + running_lines.insert(0, [' ' * len(x) for x in running_lines[-1]]) + line_diff = len(running_lines) - len(split_repr) + for i, x in enumerate(split_repr): + running_lines[i + line_diff].append(x.ljust(width)) + for i in xrange(line_diff): + running_lines[i].append(' ' * width) + # Output any remaining entries. + if len(running_lines[0]) > 0: + s.extend(self._tall_list_row(running_lines, True)) + s.append(parens[1]) + return "\n".join(s) + + def __call__(self, the_list): + """ + Return "tall list" string representation. + + See also :meth:`try_format`. + + INPUT: + + - ``the_list`` -- list or tuple. + + OUTPUT: + + String. + + EXAMPLES:: + + sage: from sage.repl.display.util import format_list + sage: format_list(['not', 'tall']) + "['not', 'tall']" + """ + output = self.try_format(the_list) + if output is None: + output = repr(the_list) + return output + + +format_list = _TallListFormatter() diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py index 51fef688094..a28a22de408 100644 --- a/src/sage/repl/interpreter.py +++ b/src/sage/repl/interpreter.py @@ -440,6 +440,11 @@ def get_test_shell(): app = SageTerminalApp.instance(config=copy.deepcopy(DEFAULT_SAGE_CONFIG)) if app.shell is None: app.initialize(argv=[]) + # overwrite the default (console + graphics) formatter with the plain text one + import sage.repl.display.formatter as formatter + app.shell.display_formatter.formatters['text/plain'] = ( + formatter.SagePlainTextFormatter(config=app.shell.config)) + # No quit noise app.shell.verbose_quit = False return app.shell diff --git a/src/sage/repl/ipython_extension.py b/src/sage/repl/ipython_extension.py index 5f7f9940472..8b5fc61c55d 100644 --- a/src/sage/repl/ipython_extension.py +++ b/src/sage/repl/ipython_extension.py @@ -298,9 +298,9 @@ def __init__(self, shell=None): self.auto_magics = SageMagics(shell) self.shell.register_magics(self.auto_magics) - import sage.misc.displayhook as displayhook + import sage.repl.display.formatter as formatter self.shell.display_formatter.formatters['text/plain'] = ( - displayhook.SagePlainTextFormatter(config=shell.config)) + formatter.SageConsoleTextFormatter(config=shell.config)) import sage.misc.edit_module as edit_module self.shell.set_hook('editor', edit_module.edit_devel) diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 60a85a64e7b..ee3ba9bdbf2 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -982,7 +982,7 @@ cdef class Parent(category_object.CategoryObject): column, or the meaning is lost. - ``'element_ascii_art'``: same but for the output of the - elements. Used in :mod:`sage.misc.displayhook`. + elements. Used in :mod:`sage.repl.display.formatter`. - ``'element_is_atomic'``: the elements print atomically, that is, parenthesis are not required when *printing* out any of From b579b925651aae99d40731436be2300f11238265 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Thu, 18 Sep 2014 01:04:53 +0100 Subject: [PATCH 04/13] Update doctests that depended on the old displayhook --- .../sage_gymnasium.rst | 10 + src/doc/de/tutorial/programming.rst | 6 +- src/doc/de/tutorial/tour_functions.rst | 7 + src/doc/de/tutorial/tour_plotting.rst | 21 +- src/doc/en/bordeaux_2008/introduction.rst | 2 + src/doc/en/constructions/calculus.rst | 1 + src/doc/en/constructions/plotting.rst | 7 + src/doc/en/prep/Advanced-2DPlotting.rst | 83 ++++- src/doc/en/prep/Calculus.rst | 9 +- src/doc/en/prep/Intro-Tutorial.rst | 1 + src/doc/en/prep/Programming.rst | 1 + .../Quickstarts/Differential-Equations.rst | 3 + .../prep/Quickstarts/Graphs-and-Discrete.rst | 5 + src/doc/en/prep/Quickstarts/Interact.rst | 2 + .../Quickstarts/Multivariable-Calculus.rst | 5 + src/doc/en/prep/Quickstarts/NumAnalysis.rst | 2 + src/doc/en/prep/Quickstarts/Number-Theory.rst | 3 + .../Statistics-and-Distributions.rst | 2 + .../en/prep/Symbolics-and-Basic-Plotting.rst | 10 + .../algebraic_combinatorics/n_cube.rst | 3 + .../algebraic_combinatorics/walks.rst | 1 + .../lie/affine_finite_crystals.rst | 2 +- .../en/thematic_tutorials/lie/crystals.rst | 4 + .../lie/weyl_character_ring.rst | 2 +- src/doc/en/thematic_tutorials/sandpile.rst | 74 ++-- .../tutorial-notebook-and-help-long.rst | 2 + .../tutorial-objects-and-classes.rst | 19 +- .../tutorial-programming-python.rst | 10 +- src/doc/en/tutorial/programming.rst | 6 +- src/doc/en/tutorial/tour_functions.rst | 7 + src/doc/en/tutorial/tour_plotting.rst | 21 +- src/doc/fr/tutorial/programming.rst | 6 +- src/doc/fr/tutorial/tour_functions.rst | 7 + src/doc/fr/tutorial/tour_plotting.rst | 16 +- src/doc/ru/tutorial/programming.rst | 6 +- src/doc/ru/tutorial/tour_functions.rst | 7 + src/doc/ru/tutorial/tour_plotting.rst | 18 +- .../free_algebra_element_letterplace.pyx | 2 +- .../letterplace/free_algebra_letterplace.pyx | 6 +- .../algebras/steenrod/steenrod_algebra.py | 6 +- .../steenrod/steenrod_algebra_mult.py | 10 +- src/sage/calculus/desolvers.py | 1 + src/sage/calculus/riemann.pyx | 18 + src/sage/categories/action.pyx | 8 +- src/sage/categories/additive_groups.py | 2 +- src/sage/categories/additive_magmas.py | 6 +- src/sage/categories/additive_semigroups.py | 4 +- src/sage/categories/category.py | 20 +- src/sage/categories/category_with_axiom.py | 14 +- src/sage/categories/crystals.py | 2 +- ...distributive_magmas_and_additive_magmas.py | 2 +- .../commutative_additive_semigroups.py | 4 +- .../categories/examples/finite_semigroups.py | 1 + .../categories/examples/finite_weyl_groups.py | 1 + src/sage/categories/finite_coxeter_groups.py | 5 +- src/sage/categories/finite_posets.py | 82 ++--- src/sage/categories/magmas.py | 2 +- src/sage/categories/map.pyx | 5 +- src/sage/categories/monoids.py | 2 +- src/sage/categories/morphism.pyx | 6 +- src/sage/categories/primer.py | 12 +- src/sage/categories/pushout.py | 2 +- src/sage/categories/semigroups.py | 2 +- src/sage/coding/code_bounds.py | 3 + src/sage/coding/source_coding/huffman.py | 14 +- .../cluster_algebra_quiver/cluster_seed.py | 10 +- src/sage/combinat/crystals/alcove_path.py | 2 +- src/sage/combinat/crystals/crystals.py | 1 + .../combinat/crystals/kirillov_reshetikhin.py | 53 ++- src/sage/combinat/dyck_word.py | 8 +- src/sage/combinat/e_one_star.py | 8 + src/sage/combinat/finite_state_machine.py | 3 +- .../combinat/integer_vectors_mod_permgroup.py | 6 +- src/sage/combinat/matrices/latin.py | 214 ++++++++++- src/sage/combinat/ncsf_qsym/tutorial.py | 2 +- src/sage/combinat/posets/hasse_diagram.py | 1 + src/sage/combinat/posets/posets.py | 70 +++- .../bij_abstract_class.py | 6 +- .../rigged_configurations/bij_type_D.py | 12 +- .../rigged_configuration_element.py | 8 +- .../combinat/root_system/associahedron.py | 2 + src/sage/combinat/root_system/cartan_type.py | 2 +- src/sage/combinat/root_system/plot.py | 32 ++ .../root_system/root_lattice_realizations.py | 36 +- src/sage/combinat/root_system/root_system.py | 1 + .../combinat/root_system/weyl_characters.py | 2 +- src/sage/combinat/shuffle.py | 24 +- src/sage/combinat/similarity_class_type.py | 2 +- .../symmetric_group_representations.py | 12 +- src/sage/combinat/tiling.py | 2 + src/sage/combinat/tutorial.py | 1 + src/sage/combinat/words/finite_word.py | 23 +- src/sage/combinat/words/morphism.py | 24 +- src/sage/combinat/words/paths.py | 20 +- src/sage/combinat/words/suffix_trees.py | 3 + src/sage/combinat/yang_baxter_graph.py | 17 +- src/sage/crypto/block_cipher/sdes.py | 4 +- src/sage/crypto/boolean_function.pyx | 2 +- src/sage/crypto/mq/sr.py | 50 ++- src/sage/databases/cremona.py | 5 +- src/sage/databases/sql_db.py | 72 ++-- src/sage/doctest/control.py | 2 +- src/sage/doctest/forker.py | 8 +- src/sage/doctest/parsing.py | 16 +- src/sage/doctest/util.py | 38 +- src/sage/dynamics/interval_exchanges/iet.py | 4 + src/sage/ext/fast_callable.pyx | 35 +- src/sage/ext/fast_eval.pyx | 8 +- src/sage/finance/time_series.pyx | 8 + src/sage/functions/bessel.py | 13 + src/sage/functions/hypergeometric.py | 2 + src/sage/functions/other.py | 1 + src/sage/functions/piecewise.py | 8 + src/sage/functions/prime_pi.pyx | 2 + src/sage/functions/transcendental.py | 1 + src/sage/game_theory/cooperative_game.py | 4 +- src/sage/games/hexad.py | 4 +- src/sage/games/quantumino.py | 4 + src/sage/geometry/cone.py | 11 +- src/sage/geometry/fan.py | 29 +- src/sage/geometry/fan_isomorphism.py | 4 +- src/sage/geometry/fan_morphism.py | 12 +- .../hyperplane_arrangement/arrangement.py | 2 + .../hyperplane_arrangement/hyperplane.py | 1 + .../geometry/hyperplane_arrangement/plot.py | 26 ++ src/sage/geometry/integral_points.pyx | 22 +- src/sage/geometry/lattice_polytope.py | 4 + src/sage/geometry/point_collection.pyx | 4 +- src/sage/geometry/polyhedron/base.py | 21 ++ src/sage/geometry/polyhedron/library.py | 1 + src/sage/geometry/polyhedron/plot.py | 27 ++ .../polyhedron/ppl_lattice_polygon.py | 2 + .../polyhedron/ppl_lattice_polytope.py | 38 +- .../parametrized_surface3d.py | 45 ++- .../surface3d_generators.py | 14 + src/sage/geometry/toric_lattice.py | 3 + src/sage/geometry/toric_lattice_element.pyx | 1 + src/sage/geometry/toric_plotter.py | 1 + src/sage/geometry/triangulation/element.py | 64 +++- .../triangulation/point_configuration.py | 5 + src/sage/graphs/base/graph_backends.py | 4 +- src/sage/graphs/bipartite_graph.py | 31 +- src/sage/graphs/digraph.py | 8 +- src/sage/graphs/digraph_generators.py | 14 +- src/sage/graphs/generators/families.py | 6 +- src/sage/graphs/generators/smallgraphs.py | 2 +- src/sage/graphs/generic_graph.py | 88 +++-- src/sage/graphs/graph.py | 10 +- src/sage/graphs/graph_database.py | 344 +++++++++--------- src/sage/graphs/graph_list.py | 1 + src/sage/graphs/graph_plot.py | 19 +- src/sage/graphs/isgci.py | 2 +- src/sage/groups/braid.py | 6 + src/sage/groups/finitely_presented.py | 2 +- src/sage/groups/perm_gps/cubegroup.py | 11 +- src/sage/gsl/fft.pyx | 5 + src/sage/homology/chain_complex.py | 11 +- src/sage/homology/chain_complex_homspace.py | 62 ++-- src/sage/homology/cubical_complex.py | 20 +- src/sage/homology/delta_complex.py | 28 +- src/sage/homology/examples.py | 4 +- src/sage/homology/simplicial_complex.py | 10 +- src/sage/interfaces/gap.py | 12 +- src/sage/interfaces/gp.py | 4 +- src/sage/interfaces/qepcad.py | 20 +- src/sage/interfaces/quit.py | 8 +- src/sage/interfaces/sage0.py | 2 +- src/sage/libs/gap/element.pyx | 4 +- src/sage/libs/gap/libgap.pyx | 6 +- src/sage/libs/lrcalc/lrcalc.pyx | 39 +- src/sage/libs/ppl.pyx | 24 +- src/sage/logic/logic.py | 22 +- src/sage/matrix/matrix0.pyx | 8 +- src/sage/matrix/matrix2.pyx | 3 + src/sage/matrix/matrix_generic_sparse.pyx | 2 +- src/sage/matrix/matrix_modn_sparse.pyx | 2 +- src/sage/matroids/basis_matroid.pyx | 2 +- src/sage/matroids/linear_matroid.pyx | 2 +- src/sage/matroids/matroid.pyx | 29 +- src/sage/matroids/matroids_plot_helpers.py | 1 + src/sage/misc/abstract_method.py | 3 +- src/sage/misc/bitset.pyx | 4 +- src/sage/misc/c3_controlled.pyx | 6 +- src/sage/misc/displayhook.py | 4 +- src/sage/misc/lazy_format.py | 4 +- src/sage/misc/lazy_list.pyx | 4 +- src/sage/misc/misc.py | 4 +- src/sage/misc/preparser.py | 2 +- src/sage/misc/sage_input.py | 6 +- src/sage/misc/sage_timeit.py | 5 +- src/sage/misc/sageinspect.py | 4 +- src/sage/modular/abvar/abvar.py | 8 +- .../modular/arithgroup/arithgroup_element.pyx | 6 +- .../modular/arithgroup/congroup_gammaH.py | 21 +- src/sage/modular/arithgroup/farey_symbol.pyx | 4 + src/sage/modular/modform/ambient.py | 4 +- src/sage/modular/modform/constructor.py | 4 +- src/sage/modular/modsym/ambient.py | 20 +- src/sage/modular/modsym/relation_matrix.py | 43 ++- src/sage/modular/overconvergent/genus0.py | 1 + src/sage/modules/free_module_element.pyx | 17 +- .../numerical/interactive_simplex_method.py | 2 + src/sage/numerical/linear_tensor.py | 2 +- src/sage/numerical/optimize.py | 1 + src/sage/plot/animate.py | 3 + src/sage/plot/arc.py | 6 + src/sage/plot/arrow.py | 15 + src/sage/plot/bar_chart.py | 6 + src/sage/plot/bezier_path.py | 8 + src/sage/plot/circle.py | 9 + src/sage/plot/colors.py | 5 +- src/sage/plot/complex_plot.pyx | 14 + src/sage/plot/contour_plot.py | 62 ++++ src/sage/plot/density_plot.py | 11 + src/sage/plot/disk.py | 9 + src/sage/plot/ellipse.py | 8 + src/sage/plot/graphics.py | 68 +++- src/sage/plot/hyperbolic_arc.py | 4 + src/sage/plot/hyperbolic_triangle.py | 2 + src/sage/plot/line.py | 26 ++ src/sage/plot/matrix_plot.py | 29 +- src/sage/plot/misc.py | 4 + src/sage/plot/plot.py | 134 +++++++ src/sage/plot/plot3d/base.pyx | 29 +- src/sage/plot/plot3d/implicit_plot3d.py | 39 ++ src/sage/plot/plot3d/implicit_surface.pyx | 13 +- src/sage/plot/plot3d/list_plot3d.py | 18 + src/sage/plot/plot3d/parametric_plot3d.py | 59 ++- src/sage/plot/plot3d/parametric_surface.pyx | 5 + src/sage/plot/plot3d/platonic.py | 39 +- src/sage/plot/plot3d/plot3d.py | 34 ++ src/sage/plot/plot3d/plot_field3d.py | 7 + src/sage/plot/plot3d/shapes.pyx | 17 +- src/sage/plot/plot3d/shapes2.py | 48 ++- src/sage/plot/plot3d/texture.py | 3 +- src/sage/plot/plot_field.py | 10 + src/sage/plot/point.py | 21 ++ src/sage/plot/polygon.py | 19 + src/sage/plot/primitive.py | 2 + src/sage/plot/scatter_plot.py | 4 + src/sage/plot/step.py | 3 + src/sage/plot/text.py | 9 + src/sage/repl/interpreter.py | 4 +- src/sage/rings/complex_interval.pyx | 3 + src/sage/rings/complex_number.pyx | 2 + .../finite_rings/finite_field_ext_pari.py | 2 +- src/sage/rings/fraction_field_FpT.pyx | 2 +- .../rings/multi_power_series_ring_element.py | 9 +- .../rings/number_field/number_field_ideal.py | 8 +- .../rings/number_field/number_field_rel.py | 4 +- src/sage/rings/padics/padic_base_generic.py | 3 + src/sage/rings/polynomial/cyclotomic.pyx | 2 +- src/sage/rings/polynomial/groebner_fan.py | 8 +- .../rings/polynomial/laurent_polynomial.pyx | 2 +- .../rings/polynomial/multi_polynomial.pyx | 2 +- .../polynomial/multi_polynomial_ideal.py | 18 +- .../multi_polynomial_libsingular.pyx | 2 +- src/sage/rings/polynomial/pbori.pyx | 7 +- src/sage/rings/polynomial/plural.pyx | 4 +- src/sage/rings/polynomial/polydict.pyx | 4 +- .../rings/polynomial/polynomial_element.pyx | 4 +- .../polynomial/polynomial_element_generic.py | 4 +- src/sage/rings/polynomial/toy_buchberger.py | 6 +- src/sage/rings/polynomial/toy_d_basis.py | 6 +- .../non_negative_integer_semiring.py | 1 + .../universal_cyclotomic_field.py | 12 +- src/sage/sandpiles/sandpile.py | 51 ++- src/sage/schemes/elliptic_curves/cm.py | 2 +- .../schemes/elliptic_curves/ell_generic.py | 5 + src/sage/schemes/elliptic_curves/ell_point.py | 1 + .../elliptic_curves/ell_rational_field.py | 1 + src/sage/schemes/elliptic_curves/heegner.py | 4 + .../schemes/elliptic_curves/lseries_ell.py | 1 + .../elliptic_curves/period_lattice_region.pyx | 12 + src/sage/schemes/generic/homset.py | 7 +- .../hyperelliptic_curves/invariants.py | 33 +- src/sage/schemes/plane_curves/affine_curve.py | 3 + .../schemes/plane_curves/projective_curve.py | 9 + .../schemes/projective/projective_space.py | 10 +- src/sage/schemes/toric/morphism.py | 4 +- src/sage/schemes/toric/variety.py | 1 + src/sage/schemes/toric/weierstrass.py | 13 +- src/sage/sets/family.py | 2 +- src/sage/sets/finite_set_map_cy.pyx | 4 +- src/sage/sets/set.py | 6 +- .../discrete_gaussian_integer.pyx | 1 + .../discrete_gaussian_lattice.py | 1 + src/sage/stats/hmm/distributions.pyx | 1 + src/sage/stats/hmm/hmm.pyx | 2 + src/sage/stats/intlist.pyx | 3 + src/sage/structure/coerce.pyx | 2 - src/sage/structure/coerce_dict.pyx | 2 +- src/sage/structure/coerce_maps.pyx | 4 +- src/sage/structure/element.pyx | 5 +- src/sage/structure/proof/all.py | 14 +- src/sage/symbolic/expression.pyx | 14 + src/sage/symbolic/expression_conversions.py | 1 + src/sage/tests/book_stein_ent.py | 4 + .../tests/french_book/calculus_doctest.py | 1 + .../tests/french_book/integration_doctest.py | 2 + src/sage/tests/french_book/mpoly.py | 4 +- src/sage/tests/french_book/recequadiff.py | 4 + src/sage_setup/clean.py | 4 +- src/sage_setup/find.py | 2 +- 304 files changed, 3120 insertions(+), 966 deletions(-) diff --git a/src/doc/de/thematische_anleitungen/sage_gymnasium.rst b/src/doc/de/thematische_anleitungen/sage_gymnasium.rst index f0d66c9878f..60af97ee550 100644 --- a/src/doc/de/thematische_anleitungen/sage_gymnasium.rst +++ b/src/doc/de/thematische_anleitungen/sage_gymnasium.rst @@ -607,6 +607,7 @@ darstellen:: sage: f(x) = x^2 sage: plot(f) + Graphics object consisting of 1 graphics primitive Sage versucht einen vernünftigen Bereich von x-Werten zu finden, um den Funktionsgraphen darzustellen. Falls dies nicht dem gewünschten Bereich entspricht, können wir diesen mit @@ -615,6 +616,7 @@ die y-Achse den zu darstellenden Bereich festlegen:: sage: f(x) = x^2 sage: plot(f, xmin=-12, xmax=12, ymin=-10, ymax=150) + Graphics object consisting of 1 graphics primitive Wollen wir mehrere Funktionsgraphen im selben Koordinatensystem darstellen, können wir die beiden Plots einzeln erstellen und in Variabeln abspeichern. Dies verhindert, dass @@ -625,6 +627,7 @@ zusammen anzuzeigen. Die Plots werden mit einem ``+``-Zeichen zusammengefügt. M sage: graph1 = plot(x^2 + 1, color="green", xmin = 0, xmax = 3) sage: graph2 = plot(e^x, color="red", xmin = 0, xmax = 3) sage: plot(graph1 + graph2, ) + Graphics object consisting of 2 graphics primitives Optionen, welche für beide Plots gültig sind (z.B. ``xmin`` oder ``xmax``) müssen auch bei beiden Plots angegeben werden, da sonst Sage sonst beim Graph, wo es nicht angegeben wird wie @@ -648,6 +651,7 @@ Wie wir oben gelernt haben, können wir den Wertebereich einfach einschränken:: sage: f(x)=(x^2 +1)/(x^2-1) sage: plot(f, xmin=-2, xmax=2, ymin=-10, ymax = 10) + Graphics object consisting of 1 graphics primitive Nun haben wir nur noch das Problem, dass der Graph zwei unerwünschte senkrechte Linien an den Polstellen hat. Dies kann mit der Option ``detect_poles`` verhindert werden. Falls wir die @@ -655,12 +659,14 @@ Option auf ``True`` stellen, werden die Linien nicht mehr dargestellt:: sage: f(x)=(x^2 +1)/(x^2-1) sage: plot(f, xmin=-2, xmax=2, ymin=-10, ymax = 10, detect_poles=True) + Graphics object consisting of 4 graphics primitives Möchten wir hingegen die vertikalen Asymptoten trotzdem darstellen, aber nicht in derselben Farbe wie den Funktionsgraphen, können wir die Option ``detect_poles`` auf ``"show"`` stellen:: sage: f(x)=(x^2 +1)/(x^2-1) sage: plot(f, xmin=-2, xmax=2, ymin=-10, ymax = 10, detect_poles="show") + Graphics object consisting of 6 graphics primitives Logarithmen =========== @@ -905,6 +911,7 @@ Die Addition von Vektoren könnte also zum Beispiel wie folgt veranschaulicht we sage: v2 = arrow((3,4), (6,1)) sage: sum_v1_v2 = arrow((0,0), (6,1), color='red') sage: plot(v1 + v2 + sum_v1_v2) + Graphics object consisting of 3 graphics primitives Falls die Vektorpfeile zu dick oder zu dünn sind, kann mit der ``width`` Option die Strichbreite angepasst werden. Der Plot-Befehl besitzt eine ``gridlines`` option, welche wir auf ``true`` setzen können, falls Gitternetzlinien @@ -914,6 +921,7 @@ in der Grafik erwünscht sind:: sage: v2 = arrow((3,4), (6,1), width=5) sage: sum_v1_v2 = arrow((0,0), (6,1), color='red', width=6) sage: plot(v1 + v2 + sum_v1_v2, gridlines=true) + Graphics object consisting of 3 graphics primitives Analysis ======== @@ -978,6 +986,7 @@ wir sogenannte Python List Comprehensions [#listcomp]_ benutzen, um die Liste zu sage: a(n) = 1/n^2 sage: punkte = [(n, a(n)) for n in range(1,10)] sage: scatter_plot(punkte) + Graphics object consisting of 1 graphics primitive Mit den Funktion ``range()`` geben wir an, welchen Bereich wir gerne darstellen möchten. Dabei wird @@ -993,6 +1002,7 @@ darzustellen:: sage: plot1 = scatter_plot(points) sage: plot2 = plot(a(x), xmin=1, xmax=5.4) sage: plot(plot1 + plot2) + Graphics object consisting of 2 graphics primitives Grenzwerte diff --git a/src/doc/de/tutorial/programming.rst b/src/doc/de/tutorial/programming.rst index f8bdd190b36..dc0c57526ce 100644 --- a/src/doc/de/tutorial/programming.rst +++ b/src/doc/de/tutorial/programming.rst @@ -501,15 +501,15 @@ ob ein Element zu der Menge gehört oder nicht, sehr schnell geht. sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) sage: X - set(['a', 1, 19]) + {1, 19, 'a'} sage: Y - set([1, 2/3]) + {2/3, 1} sage: 'a' in X True sage: 'a' in Y False sage: X.intersection(Y) - set([1]) + {1} Sage besitzt auch einen eigenen Mengen-Datentyp, welcher (manchmal) mit Hilfe des standardmäßigen Python-Mengen-Datentyps implementiert diff --git a/src/doc/de/tutorial/tour_functions.rst b/src/doc/de/tutorial/tour_functions.rst index ff4950ef79d..c76e3fa98b7 100644 --- a/src/doc/de/tutorial/tour_functions.rst +++ b/src/doc/de/tutorial/tour_functions.rst @@ -22,6 +22,7 @@ oder integriert werden. sage: f(3) 9 sage: plot(f, 0, 2) + Graphics object consisting of 1 graphics primitive Beachten Sie die Syntax in der letzten Zeile. Falls Sie stattdessen ``plot(f(z), 0, 2)`` verwenden, erhalten Sie einen Fehler, da ``z`` @@ -40,6 +41,7 @@ sollte. (Beachten Sie unten den 4. Punkt) sage: f(z) z^2 sage: plot(f(z), 0, 2) + Graphics object consisting of 1 graphics primitive Nun ist `f(z)`` ein symbolischer Ausdruck. Dies ist unser nächster Stichpunkt unserer Aufzählung. @@ -61,6 +63,7 @@ können geplottet, differenziert und integriert werden. sage: type(g) sage: plot(g, 0, 2) + Graphics object consisting of 1 graphics primitive Beachten Sie, dass während ``g`` ein aufrufbarer symbolischer Ausdruck ist, ``g(x)`` ein verwandtes aber unterschiedliches Objekt ist, @@ -79,6 +82,7 @@ Erläuterung zu erhalten. sage: g(x).derivative() 2*x sage: plot(g(x), 0, 2) + Graphics object consisting of 1 graphics primitive 3. Benutzung einer vordefinierten 'trigonometrischen Sage-Funktion'. Diese können mit ein wenig Hilfestellung differenziert und integriert @@ -89,9 +93,11 @@ werden. sage: type(sin) sage: plot(sin, 0, 2) + Graphics object consisting of 1 graphics primitive sage: type(sin(x)) sage: plot(sin(x), 0, 2) + Graphics object consisting of 1 graphics primitive Alleinestehend kann ``sin`` nicht differenziert werden, zumindest nicht um ``cos`` zu erhalten. @@ -151,6 +157,7 @@ Die Lösung: verwenden Sie nicht ``plot(h(x), 0, 4)``; benutzen Sie stattdessen: :: sage: plot(h, 0, 4) + Graphics object consisting of 1 graphics primitive \5. Versehentliches Erzeugen einer Konstanten anstelle von einer Funktion. diff --git a/src/doc/de/tutorial/tour_plotting.rst b/src/doc/de/tutorial/tour_plotting.rst index d8c0a42de3b..832d3862a58 100644 --- a/src/doc/de/tutorial/tour_plotting.rst +++ b/src/doc/de/tutorial/tour_plotting.rst @@ -22,12 +22,14 @@ Ursprung als Zentrum: :: sage: circle((0,0), 1, rgbcolor=(1,1,0)) + Graphics object consisting of 1 graphics primitive Sie können auch einen ausgefüllten Kreis erzeugen: :: sage: circle((0,0), 1, rgbcolor=(1,1,0), fill=True) + Graphics object consisting of 1 graphics primitive Sie können einen Kreis auch erstellen, indem Sie ihn einer Variable zuweisen; so wird kein Plot gezeigt. @@ -66,6 +68,7 @@ Es ist einfach elementare Funktionen zu plotten: :: sage: plot(cos, (-5,5)) + Graphics object consisting of 1 graphics primitive Sobald Sie einen Variablennamen angegeben haben, können Sie parametrische Plots erzeugen: @@ -74,6 +77,7 @@ parametrische Plots erzeugen: sage: x = var('x') sage: parametric_plot((cos(x),sin(x)^3),(x,0,2*pi),rgbcolor=hue(0.6)) + Graphics object consisting of 1 graphics primitive Es ist wichtig zu beachten, dass sich die Achsen eines Plots nur schneiden, wenn sich der Ursprung im angezeigten Bildbereich des @@ -82,6 +86,7 @@ wissenschaftliche Notation benutzt: :: sage: plot(x^2,(x,300,500)) + Graphics object consisting of 1 graphics primitive Sie können mehrere Plots zusammenfügen indem Sie diese addieren: @@ -104,6 +109,7 @@ bestimmten, Rand zu zeichnen. Zum Beispiel ist hier ein grünes Deltoid: ... 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] sage: p = polygon(L, rgbcolor=(1/8,3/4,1/2)) sage: p + Graphics object consisting of 1 graphics primitive Geben Sie ``show(p, axes=false)`` ein, um dies ohne Achsen zu sehen. @@ -127,6 +133,7 @@ Befehl erzeugt dies: sage: v = [(sin(x),x) for x in srange(-2*float(pi),2*float(pi),0.1)] sage: line(v) + Graphics object consisting of 1 graphics primitive Da die Tangensfunktion einen größeren Wertebereich als die Sinusfunktion besitzt, sollten Sie, falls Sie den gleichen Trick @@ -146,6 +153,7 @@ Beispiel eines Konturplots: sage: f = lambda x,y: cos(x*y) sage: contour_plot(f, (-4, 4), (-4, 4)) + Graphics object consisting of 1 graphics primitive Dreidimensionale Plots ---------------------- @@ -162,6 +170,7 @@ Benutzen Sie ``plot3d`` um eine Funktion der Form `f(x, y) = z` zu zeichnen: sage: x, y = var('x,y') sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2)) + Graphics3d Object Alternativ können Sie auch ``parametric_plot3d`` verwenden um eine parametrisierte Fläche zu zeichnen, wobei jede der Variablen `x, y, z` @@ -176,6 +185,7 @@ wie folgt parametrisiert angegeben werden: sage: f_y(u, v) = v sage: f_z(u, v) = u^2 + v^2 sage: parametric_plot3d([f_x, f_y, f_z], (u, -2, 2), (v, -2, 2)) + Graphics3d Object Die dritte Möglichkeit eine 3D Oberfläche zuplotten ist ``implicit_plot3d``, dies zeichnet eine Kontur einer Funktion mit @@ -186,6 +196,7 @@ Sphäre mithilfe einer klassischen Formel zeichnen: sage: x, y, z = var('x, y, z') sage: implicit_plot3d(x^2 + y^2 + z^2 - 4, (x,-2, 2), (y,-2, 2), (z,-2, 2)) + Graphics3d Object Hier sind noch ein paar Beispiele: @@ -198,7 +209,8 @@ Hier sind noch ein paar Beispiele: sage: fy = u sage: fz = v^2 sage: parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -1, 1), - ... frame=False, color="yellow") + ....: frame=False, color="yellow") + Graphics3d Object Die `Kreuz-Kappe `__: @@ -209,7 +221,8 @@ Die `Kreuz-Kappe `__: sage: fy = (1+cos(v))*sin(u) sage: fz = -tanh((2/3)*(u-pi))*sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Ein gedrehter Torus: @@ -220,7 +233,8 @@ Ein gedrehter Torus: sage: fy = (3+sin(v)+cos(u))*sin(2*v) sage: fz = sin(u)+2*cos(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Die `Lemniskate `__: @@ -229,3 +243,4 @@ Die `Lemniskate `__: sage: x, y, z = var('x,y,z') sage: f(x, y, z) = 4*x^2 * (x^2 + y^2 + z^2 + z) + y^2 * (y^2 + z^2 - 1) sage: implicit_plot3d(f, (x, -0.5, 0.5), (y, -1, 1), (z, -1, 1)) + Graphics3d Object diff --git a/src/doc/en/bordeaux_2008/introduction.rst b/src/doc/en/bordeaux_2008/introduction.rst index 2c7c265af6e..040ffed597c 100644 --- a/src/doc/en/bordeaux_2008/introduction.rst +++ b/src/doc/en/bordeaux_2008/introduction.rst @@ -66,12 +66,14 @@ positive integer up to :math:`500`. :: sage: line([(n, len(factor(n))) for n in [1..500]]) + Graphics object consisting of 1 graphics primitive And, this example draws a similar 3d plot:: sage: v = [[len(factor(n*m)) for n in [1..15]] for m in [1..15]] sage: list_plot3d(v, interpolation_type='nn') + Graphics3d Object The Sage-Pari-Magma Ecosystem diff --git a/src/doc/en/constructions/calculus.rst b/src/doc/en/constructions/calculus.rst index 2116913bec6..7be1cee68d1 100644 --- a/src/doc/en/constructions/calculus.rst +++ b/src/doc/en/constructions/calculus.rst @@ -317,6 +317,7 @@ for :math:`0 <= t <= 2`. The same result can be obtained by using ``desolve_syst sage: p1 = list_plot([[i,j] for i,j,k in P], plotjoined=True) sage: p2 = list_plot([[i,k] for i,j,k in P], plotjoined=True, color='red') sage: p1+p2 + Graphics object consisting of 2 graphics primitives Another way this system can be solved is to use the command ``desolve_system``. diff --git a/src/doc/en/constructions/plotting.rst b/src/doc/en/constructions/plotting.rst index 85832057b3f..d18c4f48984 100644 --- a/src/doc/en/constructions/plotting.rst +++ b/src/doc/en/constructions/plotting.rst @@ -40,6 +40,7 @@ You can plot piecewise-defined functions: sage: f4 = lambda x:sin(2*x) sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,10),f4]]) sage: f.plot() + Graphics object consisting of 4 graphics primitives Other function plots can be produced as well: @@ -93,6 +94,7 @@ A blue conchoid of Nicomedes: sage: L = [[1+5*cos(pi/2+pi*i/100), tan(pi/2+pi*i/100)*\ ... (1+5*cos(pi/2+pi*i/100))] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1/8,3/4)) + Graphics object consisting of 1 graphics primitive A blue hypotrochoid (3 leaves): @@ -102,6 +104,7 @@ A blue hypotrochoid (3 leaves): sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),\ ... n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A blue hypotrochoid (4 leaves): @@ -111,6 +114,7 @@ A blue hypotrochoid (4 leaves): sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),\ ... n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A red limaçon of Pascal: @@ -119,6 +123,7 @@ A red limaçon of Pascal: sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))]\ ... for i in range(-100,101)] sage: line(L, rgbcolor=(1,1/4,1/2)) + Graphics object consisting of 1 graphics primitive A light green trisectrix of Maclaurin: @@ -127,6 +132,7 @@ A light green trisectrix of Maclaurin: sage: L = [[2*(1-4*cos(-pi/2+pi*i/100)^2),10*tan(-pi/2+pi*i/100)*\ ... (1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1,1/8)) + Graphics object consisting of 1 graphics primitive A green lemniscate of Bernoulli (we omit i==100 since that would give a 0 division error): @@ -136,6 +142,7 @@ A green lemniscate of Bernoulli (we omit i==100 since that would give a 0 divisi sage: v = [(1/cos(-pi/2+pi*i/100), tan(-pi/2+pi*i/100)) for i in range(1,200) if i!=100 ] sage: L = [(a/(a^2+b^2), b/(a^2+b^2)) for a,b in v] sage: line(L, rgbcolor=(1/4,3/4,1/8)) + Graphics object consisting of 1 graphics primitive .. index:: plot;curve using surf diff --git a/src/doc/en/prep/Advanced-2DPlotting.rst b/src/doc/en/prep/Advanced-2DPlotting.rst index 8bdaf33133b..3d8319b6dce 100644 --- a/src/doc/en/prep/Advanced-2DPlotting.rst +++ b/src/doc/en/prep/Advanced-2DPlotting.rst @@ -56,6 +56,7 @@ A simple quadratic is easy. :: sage: plot(x^2, (x,-2,2)) + Graphics object consisting of 1 graphics primitive You can combine "plot objects" by adding them. @@ -64,6 +65,7 @@ You can combine "plot objects" by adding them. sage: regular = plot(x^2, (x,-2,2), color= 'purple') sage: skinny = plot(4*x^2, (x,-2,2), color = 'green') sage: regular + skinny + Graphics object consisting of 2 graphics primitives **Problem** : Plot a green :math:`y=\sin(x)` together with a red :math:`y=2\,\cos(x)`. (Hint: you can use ``pi`` as part of your range.) @@ -73,6 +75,7 @@ Boundaries of a plot can be specified, in addition to the overall size. :: sage: plot(1+e^(-x^2), xmin=-2, xmax=2, ymin=0, ymax=2.5, figsize=10) + Graphics object consisting of 1 graphics primitive **Problem** : Plot :math:`y=5+3\,\sin(4x)` with suitable boundaries. @@ -84,6 +87,7 @@ You can add lots of extra information. sage: max_line = plot(2, xmin=-2, xmax=2, linestyle='-.', color = 'red') sage: min_line = plot(1, xmin=-2, xmax=2, linestyle=':', color = 'red') sage: exponential + max_line + min_line + Graphics object consisting of 3 graphics primitives You can fill regions with transparent color, and thicken the curve. This example uses several options to fine\-tune our graphic. @@ -93,10 +97,12 @@ This example uses several options to fine\-tune our graphic. sage: exponential = plot(1+e^(-x^2), xmin=-2, xmax=2, ymin=0, ymax=2.5, fill=0.5, fillcolor='grey', fillalpha=0.3) sage: min_line = plot(1, xmin=-2, xmax=2, linestyle='-', thickness= 6, color = 'red') sage: exponential + min_line + Graphics object consisting of 3 graphics primitives :: sage: sum([plot(x^n,(x,0,1),color=rainbow(5)[n]) for n in [0..4]]) + Graphics object consisting of 5 graphics primitives **Problem** : Create a plot showing the cross-section area for the following solid of revolution problem: Consider the area bounded by @@ -119,6 +125,7 @@ to view this object. sage: t = var('t') sage: parametric_plot([cos(t) + 3 * cos(t/9), sin(t) - 3 * sin(t/9)], (t, 0, 18*pi), fill = True, aspect_ratio=1) + Graphics object consisting of 2 graphics primitives **Problem** : These parametric equations will create a hypocycloid. @@ -139,15 +146,18 @@ depending on how many variables and coordinates you specify. sage: t = var('t') sage: parametric_plot((t^2,sin(t)), (t,0,pi)) + Graphics object consisting of 1 graphics primitive :: sage: parametric_plot((t^2,sin(t),cos(t)), (t,0,pi)) + Graphics3d Object :: sage: r = var('r') sage: parametric_plot((t^2,sin(r*t),cos(r*t)), (t,0,pi),(r,-1,1)) + Graphics3d Object .. _Polar: @@ -159,6 +169,7 @@ Sage can also do polar plots. :: sage: polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.5), thickness=4) + Graphics object consisting of 1 graphics primitive Although they aren't essential, many of these examples try to demonstrate things like coloring, fills, and shading to give you a sense @@ -170,8 +181,9 @@ Notice the automatic graded shading of the fill color. :: sage: t = var('t') - sage: polar_plot([cos(4*t) + 1.5, 0.5 * cos(4*t) + 2.5], (t, 0, 2*pi),\ - ... color='black', thickness=2, fill=True, fillcolor='orange') + sage: polar_plot([cos(4*t) + 1.5, 0.5 * cos(4*t) + 2.5], (t, 0, 2*pi), + ....: color='black', thickness=2, fill=True, fillcolor='orange') + Graphics object consisting of 4 graphics primitives Problem: Create a plot for the following problem. Find the area that is inside the circle :math:`r=2`, but outside the cardiod @@ -344,6 +356,7 @@ plotting syntax. sage: f(x,y)=y^2+1-x^3-x sage: contour_plot(f, (x,-pi,pi), (y,-pi,pi)) + Graphics object consisting of 1 graphics primitive We can change colors, specify contours, label curves, and many other things. When there are many levels, the ``colorbar`` keyword becomes @@ -354,6 +367,7 @@ whether it appears or does not appear). :: sage: contour_plot(f, (x,-pi,pi), (y,-pi,pi),colorbar=True,labels=True) + Graphics object consisting of 1 graphics primitive This example is fairly self\-explanatory, but demonstrates the power of formatting, labeling, and the wide variety of built\-in color gradations @@ -364,8 +378,10 @@ consists of pairs connected by a colon, all inside curly braces. :: - sage: contour_plot(f, (x,-pi,pi), (y,-pi,pi), contours=[-4,0,4], fill=False,\ - ... cmap='cool', labels=True, label_inline=True, label_fmt={-4:"low", 0:"medium", 4: "hi"}, label_colors='black') + sage: contour_plot(f, (x,-pi,pi), (y,-pi,pi), contours=[-4,0,4], fill=False, + ....: cmap='cool', labels=True, label_inline=True, + ....: label_fmt={-4:"low", 0:"medium", 4: "hi"}, label_colors='black') + Graphics object consisting of 1 graphics primitive Implicit plots are a special type of contour plot (they just plot the zero contour). @@ -378,12 +394,14 @@ zero contour). :: sage: implicit_plot(f(x,y)==0,(x,-pi,pi),(y,-pi,pi)) + Graphics object consisting of 1 graphics primitive A density plot is like a contour plot, but without discrete levels. :: sage: density_plot(f, (x, -2, 2), (y, -2, 2)) + Graphics object consisting of 1 graphics primitive Sometimes contour plots can be a little misleading (which makes for a *great* classroom discussion about the problems of ignorantly relying on @@ -393,6 +411,7 @@ even better what is happening with the function. :: sage: density_plot(f,(x,-2,2),(y,-2,2))+contour_plot(f,(x,-2,2),(y,-2,2),fill=False,labels=True,label_inline=True,cmap='jet') + Graphics object consisting of 2 graphics primitives It can be worth getting familiar with the various options for different plots, especially if you will be doing a lot of them in a given @@ -409,7 +428,18 @@ Here are the options for contour plots. :: sage: contour_plot.options - {'labels': False, 'linestyles': None, 'region': None, 'axes': False, 'plot_points': 100, 'linewidths': None, 'colorbar': False, 'contours': None, 'aspect_ratio': 1, 'legend_label': None, 'frame': True, 'fill': True} + {'aspect_ratio': 1, + 'axes': False, + 'colorbar': False, + 'contours': None, + 'fill': True, + 'frame': True, + 'labels': False, + 'legend_label': None, + 'linestyles': None, + 'linewidths': None, + 'plot_points': 100, + 'region': None} Let's change it so that all future contour plots don't have the fill. That's how some of us might use them in a class. We'll also check that @@ -419,20 +449,43 @@ the change happened. sage: contour_plot.options["fill"]=False sage: contour_plot.options - {'labels': False, 'linestyles': None, 'region': None, 'axes': False, 'plot_points': 100, 'linewidths': None, 'colorbar': False, 'contours': None, 'aspect_ratio': 1, 'legend_label': None, 'frame': True, 'fill': False} + {'aspect_ratio': 1, + 'axes': False, + 'colorbar': False, + 'contours': None, + 'fill': False, + 'frame': True, + 'labels': False, + 'legend_label': None, + 'linestyles': None, + 'linewidths': None, + 'plot_points': 100, + 'region': None} And it works! :: sage: contour_plot(f,(x,-2,2),(y,-2,2)) + Graphics object consisting of 1 graphics primitive We can always access the default options, of course, to remind us. :: sage: contour_plot.defaults() - {'labels': False, 'linestyles': None, 'region': None, 'axes': False, 'plot_points': 100, 'linewidths': None, 'colorbar': False, 'contours': None, 'aspect_ratio': 1, 'legend_label': None, 'frame': True, 'fill': True} + {'aspect_ratio': 1, + 'axes': False, + 'colorbar': False, + 'contours': None, + 'fill': True, + 'frame': True, + 'labels': False, + 'legend_label': None, + 'linestyles': None, + 'linewidths': None, + 'plot_points': 100, + 'region': None} .. _Vector: @@ -448,12 +501,14 @@ colored by length in the 3D case. sage: var('x,y') (x, y) sage: plot_vector_field((-y+x,y*x),(x,-3,3),(y,-3,3)) + Graphics object consisting of 1 graphics primitive :: sage: var('x,y,z') (x, y, z) sage: plot_vector_field3d((-y,-z,x), (x,-3,3),(y,-3,3),(z,-3,3)) + Graphics3d Object 3d vector field plots are ideally viewed with 3d glasses (right\-click on the plot and select "Style" and "Stereographic") @@ -471,6 +526,7 @@ is indicated by the hue (red is a positive real number). sage: f(z) = exp(z) #z^5 + z - 1 + 1/z sage: complex_plot(f, (-5,5),(-5,5)) + Graphics object consisting of 1 graphics primitive .. _Region: @@ -482,12 +538,14 @@ These plot where an expression is true, and are useful for plotting inequalities :: sage: region_plot(cos(x^2+y^2) <= 0, (x, -3, 3), (y, -3, 3),aspect_ratio=1) + Graphics object consisting of 1 graphics primitive We can get fancier options as well. :: sage: region_plot(sin(x)*sin(y) >= 1/4, (x,-10,10), (y,-10,10), incol='yellow', bordercol='black', borderstyle='dashed', plot_points=250,aspect_ratio=1) + Graphics object consisting of 2 graphics primitives Remember, what command would give full information about the syntax, options, and examples? @@ -515,6 +573,7 @@ To make one point, a coordinate pair suffices. :: sage: point((3,5)) + Graphics object consisting of 1 graphics primitive It doesn't matter how multiple point are generated; they must go in as input via a list (square brackets). Here, we demonstrate the @@ -525,10 +584,12 @@ do this. sage: f(x)=x^2 sage: points([(0,f(0)), (1,f(1)), (2,f(2)), (3,f(3)), (4,f(4))]) + Graphics object consisting of 1 graphics primitive :: sage: points([(x,f(x)) for x in range(5)]) + Graphics object consisting of 1 graphics primitive Sage tries to tell how many dimensions you are working in automatically. @@ -536,6 +597,7 @@ Sage tries to tell how many dimensions you are working in automatically. sage: f(x,y)=x^2-y^2 sage: points([(x,y,f(x,y)) for x in range(5) for y in range(5)]) + Graphics3d Object Lines ##### @@ -547,6 +609,7 @@ well, you get connecting lines too! sage: f(x)=x^2 sage: line([(x,f(x)) for x in range(5)]) + Graphics object consisting of 1 graphics primitive Balls ##### @@ -558,10 +621,12 @@ possible. :: sage: circle((0,1),1,aspect_ratio=1) + Graphics object consisting of 1 graphics primitive :: sage: disk((0,0), 1, (pi, 3*pi/2), color='yellow',aspect_ratio=1) + Graphics object consisting of 1 graphics primitive There are also ellipses and various arcs; see the `full plot documentation `_. @@ -572,6 +637,7 @@ Arrows :: sage: arrow((0,0), (1,1)) + Graphics object consisting of 1 graphics primitive Polygons ######## @@ -582,6 +648,7 @@ otherwise the syntax is fairly self\-evident. :: sage: polygon([[0,0],[1,1],[1,2]]) + Graphics object consisting of 1 graphics primitive Text #### @@ -593,6 +660,7 @@ text is just text. :: sage: text('$\int_0^2 x^2\, dx$', (0.5,2))+plot(x^2,(x,0,2),fill=True) + Graphics object consisting of 3 graphics primitives .. _Saving: @@ -606,6 +674,7 @@ format based on the filename for the image. sage: p=plot(x^2,(x,-1,1)) sage: p + Graphics object consisting of 1 graphics primitive For testing purposes, we use the Sage standard temporary filename; however, you could use any string for a name that you wanted, like diff --git a/src/doc/en/prep/Calculus.rst b/src/doc/en/prep/Calculus.rst index abde951e563..f4a58224d3c 100644 --- a/src/doc/en/prep/Calculus.rst +++ b/src/doc/en/prep/Calculus.rst @@ -196,6 +196,7 @@ Finally, we plot everything together in the last line by adding sage: L(x)=fprime(c)*(x-c)+f(c) sage: Q=plot(L,(x,-1,1), color="red", linestyle="--") sage: P+Q + Graphics object consisting of 2 graphics primitives You may want to experiment by @@ -373,6 +374,7 @@ the plotting options from the plotting tutorial. :: sage: plot(cos(x),(x,0,pi/2),fill=True,ticks=[[0,pi/4,pi/2],None],tick_formatter=pi) + Graphics object consisting of 2 graphics primitives It is possible to be completely symbolic in doing integration. If you do this, you'll have to make sure you define anything that's a symbolic @@ -515,6 +517,7 @@ Notice how close the approximation is to the function on this interval! :: sage: plot(g,(x,0,2))+plot(log(x),(x,0,2),color='red') + Graphics object consisting of 2 graphics primitives .. _Calc3: @@ -600,6 +603,7 @@ cell below is the unit vector in the direction :math:`(1,2)`. sage: u=vector([1,2]) sage: Q=plot(u/u.norm()) sage: P+Q + Graphics object consisting of 2 graphics primitives Rather than actually figure out the unit vector in that direction, it's easier to let Sage compute it by dividing the vector by its norm. @@ -621,7 +625,8 @@ options with features of the graphic. sage: y = var('y') sage: contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi),\ - ... contours=[-8,-4,0,4,8], colorbar=True, labels=True, label_colors='red') + ....: contours=[-8,-4,0,4,8], colorbar=True, labels=True, label_colors='red') + Graphics object consisting of 1 graphics primitive In this one, we have used options to: @@ -658,6 +663,7 @@ mentioned in the symbolics and plotting tutorial. :: sage: plot3d(f,(x,0,pi),(y,0,pi),color='red')+plot3d(0,(x,0,pi),(y,0,pi)) + Graphics3d Object In addition to multivariate calculus, Calculus 3 often covers parametric calculus of a single variable. Sage can do arbitrary parametric plots, @@ -675,6 +681,7 @@ the beginning of this tutorial. sage: my_prime=my_curve.diff(t) sage: L=my_prime(1)*t+my_curve(1) # tangent line at t=1 sage: parametric_plot(L, (t,-2,2))+PP + Graphics object consisting of 2 graphics primitives .. tip:: - After a while, you'll find that giving things names other than ``f`` diff --git a/src/doc/en/prep/Intro-Tutorial.rst b/src/doc/en/prep/Intro-Tutorial.rst index 48550cfff98..82aef6ad728 100644 --- a/src/doc/en/prep/Intro-Tutorial.rst +++ b/src/doc/en/prep/Intro-Tutorial.rst @@ -330,6 +330,7 @@ We can also plot functions easily. :: sage: plot(f, (x,-3,3)) + Graphics object consisting of 1 graphics primitive In another tutorial, we will go more in depth with plotting. Here, note that the preferred syntax has the variable and endpoints for the diff --git a/src/doc/en/prep/Programming.rst b/src/doc/en/prep/Programming.rst index 6d664f098f8..35ad8f61ba0 100644 --- a/src/doc/en/prep/Programming.rst +++ b/src/doc/en/prep/Programming.rst @@ -342,6 +342,7 @@ This is phenomenally useful. Here is a nice plotting example. :: sage: plot([x^n for n in [2..6]],(x,0,1)) + Graphics object consisting of 5 graphics primitives Now we apply it to the example we were doing in the first place. Notice we now have a nice concise description of all determinants of these diff --git a/src/doc/en/prep/Quickstarts/Differential-Equations.rst b/src/doc/en/prep/Quickstarts/Differential-Equations.rst index 09ff4558806..a61aa4560c8 100644 --- a/src/doc/en/prep/Quickstarts/Differential-Equations.rst +++ b/src/doc/en/prep/Quickstarts/Differential-Equations.rst @@ -64,6 +64,7 @@ slope field. sage: Plot1=plot_slope_field(2-y,(x,0,3),(y,0,5)) sage: Plot2=plot(h,x,0,3) sage: Plot1+Plot2 + Graphics object consisting of 2 graphics primitives .. note:: Regarding symbolic functions versus symbolic variables: @@ -134,6 +135,7 @@ use the ``points`` command from the advanced plotting tutorial. sage: h1 = desolve(de, y, ics=[0,3]) sage: plot(h1,(x,0,5),color='red')+points(h) + Graphics object consisting of 2 graphics primitives The primary use of numerical routines from here is pedagogical in nature. @@ -163,6 +165,7 @@ This power series solution is pretty good for a while! sage: h = h.polynomial() sage: plot(h,-2,5)+plot(2+e^-x,(x,-2,5),color='red',linestyle=':',thickness=3) + Graphics object consisting of 2 graphics primitives This was just an introduction; there are a lot of resources for differential equations using Sage elsewhere, including a book by David diff --git a/src/doc/en/prep/Quickstarts/Graphs-and-Discrete.rst b/src/doc/en/prep/Quickstarts/Graphs-and-Discrete.rst index 64b6dbcbb70..8ffa3adf1a2 100644 --- a/src/doc/en/prep/Quickstarts/Graphs-and-Discrete.rst +++ b/src/doc/en/prep/Quickstarts/Graphs-and-Discrete.rst @@ -34,6 +34,7 @@ Visualizing a graph is similar to plotting functions. sage: G = graphs.HeawoodGraph() sage: plot(G) + Graphics object consisting of 36 graphics primitives Defining your own graph is easy. One way is the following. @@ -48,6 +49,7 @@ Defining your own graph is easy. One way is the following. sage: H=Graph({0:[1,2,3], 4:[0,2], 6:[1,2,3,4,5]}) sage: plot(H) + Graphics object consisting of 18 graphics primitives Adjacency matrices, other graphs, and similar inputs are also recognized. @@ -71,6 +73,7 @@ Pre\-defined graphs often come with "nice" layouts. sage: H.set_pos(H.layout_circular()) sage: plot(H) + Graphics object consisting of 18 graphics primitives Vertices can be lots of things, for example the codewords of an error\-correcting code. @@ -102,6 +105,7 @@ Edges can be labeled. ... v = edge[1] ... L.set_edge_label(u, v, u*v) sage: plot(L, edge_labels=True) + Graphics object consisting of 16 graphics primitives There are natural connections to other areas of mathematics. Here we compute the automorphism group and eigenvalues of the skeleton of a @@ -111,6 +115,7 @@ cube. sage: C = graphs.CubeGraph(3) sage: plot(C) + Graphics object consisting of 21 graphics primitives :: diff --git a/src/doc/en/prep/Quickstarts/Interact.rst b/src/doc/en/prep/Quickstarts/Interact.rst index c7c3b91d514..475a6978b2f 100644 --- a/src/doc/en/prep/Quickstarts/Interact.rst +++ b/src/doc/en/prep/Quickstarts/Interact.rst @@ -29,6 +29,7 @@ look like. Here we just want a simple plot. :: sage: plot(x^2,(x,-3,3)) + Graphics object consisting of 1 graphics primitive Then abstract out the parts you want to change. We'll be letting the user change the function, so let's make that a variable ``f``. @@ -37,6 +38,7 @@ user change the function, so let's make that a variable ``f``. sage: f=x^3 sage: plot(f,(x,-3,3)) + Graphics object consisting of 1 graphics primitive This was important because it allowed you to step back and think about what you would really be doing. diff --git a/src/doc/en/prep/Quickstarts/Multivariable-Calculus.rst b/src/doc/en/prep/Quickstarts/Multivariable-Calculus.rst index df957fcf34e..4d4ad26cc5b 100644 --- a/src/doc/en/prep/Quickstarts/Multivariable-Calculus.rst +++ b/src/doc/en/prep/Quickstarts/Multivariable-Calculus.rst @@ -56,6 +56,7 @@ equation of a line in three dimensions is with ``parametric_plot3d``. sage: plane = plot3d((1/5)*(-12+x-2*y), (x, 4, 10), (y, -13,-7), opacity=0.5) sage: intersect=point3d([7,-10,3],color='black',size=30) sage: line+plane+intersect + Graphics3d Object Vector\-Valued Functions ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -118,6 +119,7 @@ We can also plot vector fields, even in three dimensions. sage: x,y,z=var('x y z') sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),colors=['red','green','blue']) + Graphics3d Object If we know a little vector calculus, we can also do line integrals. Here, based on an example by Ben Woodruff of BYU-Idaho, we @@ -202,6 +204,7 @@ tutorials. Here is a reminder of what can be done. sage: # 'Spectral', 'summer', 'blues' sage: g(x,y)=e^-x*sin(y) sage: contour_plot(g, (x, -2, 2), (y, -4*pi, 4*pi), cmap = 'Blues', contours=10, colorbar=True) + Graphics object consisting of 1 graphics primitive Partial Differentiation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -268,6 +271,7 @@ this. :: sage: plot3d(f,(x,-5,5),(y,-5,5))+point((4,-2,f(4,-2)),color='red',size=20) + Graphics3d Object Multiple Integrals and More ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -292,5 +296,6 @@ Naturally, there is lots more that one can do. sage: domain = parametric_plot3d([3*u, 4*(3*u)*v,0], (u, 0, 1), (v, 0,1), color = 'green', opacity = 0.75) sage: image = parametric_plot3d([3*u, 4*(3*u)*v, f(3*u, 12*u*v)], (u, 0, 1), (v, 0,1), color = 'green', opacity = 1.00) sage: surface+domain+image + Graphics3d Object Quiz: why did we need to declare variables this time? diff --git a/src/doc/en/prep/Quickstarts/NumAnalysis.rst b/src/doc/en/prep/Quickstarts/NumAnalysis.rst index afc5bdde1bd..749aedd8e37 100644 --- a/src/doc/en/prep/Quickstarts/NumAnalysis.rst +++ b/src/doc/en/prep/Quickstarts/NumAnalysis.rst @@ -299,6 +299,7 @@ numbers. sage: f(x)=x^2*(sqrt(x^4+16)-x^2) sage: plot(f,(x,0,2e4)) + Graphics object consisting of 1 graphics primitive We can instead make a function that specifically evaluates all intermediate steps to 100 bits of precision using the ``fast_callable`` @@ -309,4 +310,5 @@ system. sage: R=RealField(100) # 100 bits sage: g=fast_callable(f, vars=[x], domain=R) sage: plot(g,(x,0,2e4)) + Graphics object consisting of 1 graphics primitive diff --git a/src/doc/en/prep/Quickstarts/Number-Theory.rst b/src/doc/en/prep/Quickstarts/Number-Theory.rst index c06201cb88d..f9e575572fc 100644 --- a/src/doc/en/prep/Quickstarts/Number-Theory.rst +++ b/src/doc/en/prep/Quickstarts/Number-Theory.rst @@ -194,6 +194,7 @@ One more very useful object is the prime counting function sage: prime_pi(100); plot(prime_pi,1,100) 25 + Graphics object consisting of 1 graphics primitive A very nice aspect of Sage is combining several aspects of mathematics together. It can be very eye\-opening to students to see analytic @@ -206,6 +207,7 @@ was a cryptographic key!) sage: var('x') x sage: plot(prime_pi,2,10^6,thickness=2)+plot(Li,2,10^6,color='red')+plot(x/ln(x),2,10^6,color='green') + Graphics object consisting of 3 graphics primitives Advanced Number Theory ---------------------- @@ -236,6 +238,7 @@ Riemann zeta. :: sage: complex_plot(zeta, (-30,30), (-30,30)) + Graphics object consisting of 1 graphics primitive Cryptography ------------ diff --git a/src/doc/en/prep/Quickstarts/Statistics-and-Distributions.rst b/src/doc/en/prep/Quickstarts/Statistics-and-Distributions.rst index 9f6bd52e785..ee557feb0a9 100644 --- a/src/doc/en/prep/Quickstarts/Statistics-and-Distributions.rst +++ b/src/doc/en/prep/Quickstarts/Statistics-and-Distributions.rst @@ -83,6 +83,7 @@ plot a histogram with 10 bins. sage: my_data2 = [dist.get_random_element()+2 for _ in range(1000)] sage: T = stats.TimeSeries(my_data) sage: T.plot_histogram(normalize=False,bins=10) + Graphics object consisting of 10 graphics primitives To access discrete distributions, we access another part of Sage which has statistics built in: `Scipy `_. @@ -101,6 +102,7 @@ has statistics built in: `Scipy `_. sage: import scipy.stats sage: binom_dist = scipy.stats.binom(20,.05) sage: bar_chart([binom_dist.pmf(x) for x in range(21)]) + Graphics object consisting of 1 graphics primitive The ``bar_chart`` function performs some of the duties of histograms. diff --git a/src/doc/en/prep/Symbolics-and-Basic-Plotting.rst b/src/doc/en/prep/Symbolics-and-Basic-Plotting.rst index 7a9d2303565..90eb9241b1c 100644 --- a/src/doc/en/prep/Symbolics-and-Basic-Plotting.rst +++ b/src/doc/en/prep/Symbolics-and-Basic-Plotting.rst @@ -260,6 +260,7 @@ define a function of :math:`x` and plot it between :math:`-1` and sage: f(x)=x^3+1 sage: plot(f,(x,-1,1)) + Graphics object consisting of 1 graphics primitive We can give the plot a name, so that if we want to do something with the plot later, we don't have to type out the entire plot command. @@ -282,6 +283,7 @@ for the line, but over the same interval. sage: Q=plot(1,(x,-1,1),color="red", linestyle="--") sage: Q + Graphics object consisting of 1 graphics primitive Because we put :math:`Q` in a line by itself at the end, it shows. We were able to use just one cell to define :math:`Q` and show it, by @@ -292,6 +294,7 @@ Now to show the plots superimposed on each other, we simply add them. :: sage: P+Q + Graphics object consisting of 2 graphics primitives Suppose we wanted to view a detail of this. @@ -335,6 +338,7 @@ Two of the most useful of these options help in labeling graphs. :: sage: plot(f,(x,-1,1),axes_labels=['$x$','$y$'],legend_label='$f(x)$',show_legend=True) + Graphics object consisting of 1 graphics primitive - The ``legend_label`` option is especially useful with multiple plots. @@ -348,6 +352,7 @@ Two of the most useful of these options help in labeling graphs. sage: P1 = plot(f,(x,-1,1),axes_labels=['$x$','$y$'],legend_label='$f(x)$') sage: P2 = plot(sin,(x,-1,1),axes_labels=['$x$','$y$'],legend_label='$\sin(x)$',color='red') sage: P1+P2 + Graphics object consisting of 2 graphics primitives One additional useful note is that plots of functions with vertical asymptotes may need their vertical viewing range set manually; otherwise @@ -356,6 +361,7 @@ the asymptote may really go to infinity! :: sage: plot(1/x^2,(x,-10,10),ymax=10) + Graphics object consisting of 1 graphics primitive Remember, you can use the command ``plot?`` to find out about most of the options demonstrated above. @@ -409,6 +415,7 @@ specify ranges for two variables instead of one. sage: g(x,y)=sin(x^2+y^2) sage: plot3d(g,(x,-5,5),(y,-5,5)) + Graphics3d Object There is a lot you can do with the 3D plots. @@ -443,6 +450,7 @@ points! :: sage: plot3d(g,(x,-5,5),(y,-5,5),plot_points=300) + Graphics3d Object As with 2D plots, we can superimpose 3D plots by adding them together. @@ -458,6 +466,7 @@ wisest to define the variables ahead of time. sage: P=plot3d(sin(x^2-y^2),(x,-b,b),(y,-b,b), opacity=.7) sage: Q=plot3d(0, (x,-b,b), (y,-b,b), color='red') sage: P+Q + Graphics3d Object As usual, only the last command shows up in the notebook, though clearly all are evaluated. This also demonstrates that many of the same options @@ -474,6 +483,7 @@ We close this tutorial with a cool plot that we define *implicitly* as a sage: p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x)) sage: r = 4.78 sage: implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=50, color='yellow') + Graphics3d Object The next tutorial will use all that you have learned about Sage basics, symbolics, and plotting in a specific mathematical venue \- the calculus diff --git a/src/doc/en/thematic_tutorials/algebraic_combinatorics/n_cube.rst b/src/doc/en/thematic_tutorials/algebraic_combinatorics/n_cube.rst index f6c809e4d01..a31dff543a2 100644 --- a/src/doc/en/thematic_tutorials/algebraic_combinatorics/n_cube.rst +++ b/src/doc/en/thematic_tutorials/algebraic_combinatorics/n_cube.rst @@ -40,6 +40,7 @@ they differ in one slot, that is, the distance function is 1:: We can plot the `3` and `4`-cube:: sage: cube(3).plot() + Graphics object consisting of 21 graphics primitives .. image:: ../media/cube3.png :scale: 75 @@ -48,6 +49,7 @@ We can plot the `3` and `4`-cube:: :: sage: cube(4).plot() + Graphics object consisting of 49 graphics primitives .. image:: ../media/cube4.png :scale: 75 @@ -94,6 +96,7 @@ Note that the graph is in fact disconnected. Do you understand why? :: sage: cube_2(4).plot() + Graphics object consisting of 65 graphics primitives .. image:: ../media/cube-dist.png :scale: 75 diff --git a/src/doc/en/thematic_tutorials/algebraic_combinatorics/walks.rst b/src/doc/en/thematic_tutorials/algebraic_combinatorics/walks.rst index d5f4c766640..78a441663c9 100644 --- a/src/doc/en/thematic_tutorials/algebraic_combinatorics/walks.rst +++ b/src/doc/en/thematic_tutorials/algebraic_combinatorics/walks.rst @@ -36,6 +36,7 @@ Now let us look at the graph! :: sage: G.plot() + Graphics object consisting of 11 graphics primitives .. image:: ../media/graph.png :scale: 75 diff --git a/src/doc/en/thematic_tutorials/lie/affine_finite_crystals.rst b/src/doc/en/thematic_tutorials/lie/affine_finite_crystals.rst index a3e0cd141a0..e11fe6d9c83 100644 --- a/src/doc/en/thematic_tutorials/lie/affine_finite_crystals.rst +++ b/src/doc/en/thematic_tutorials/lie/affine_finite_crystals.rst @@ -357,7 +357,7 @@ up to a relabeling of the arrows:: sage: for u,v,label in Gdual.edges(): ....: Gdual.set_edge_label(u,v,f[label]) sage: G.is_isomorphic(Gdual, edge_labels = True, certify = True) - (True, {[[-2]]: [[1]], [[-1]]: [[2]], [[1]]: [[-2]], []: [[0]], [[2]]: [[-1]]}) + (True, {[[1]]: [[-2]], [[2]]: [[-1]], [[-2]]: [[1]], [[-1]]: [[2]], []: [[0]]}) .. image:: ../media/KR_Atwisted_dual.png :scale: 60 diff --git a/src/doc/en/thematic_tutorials/lie/crystals.rst b/src/doc/en/thematic_tutorials/lie/crystals.rst index 081ff42dcbd..f6a4d322000 100644 --- a/src/doc/en/thematic_tutorials/lie/crystals.rst +++ b/src/doc/en/thematic_tutorials/lie/crystals.rst @@ -747,9 +747,13 @@ We see that two of these crystals are isomorphic, with character sage: [T1,T2,T3,T4] = \ [crystals.TensorProduct(C,C,C,generators=[v]) for v in T.highest_weight_vectors()] sage: T1.plot() + Graphics object consisting of 35 graphics primitives sage: T2.plot() + Graphics object consisting of 25 graphics primitives sage: T3.plot() + Graphics object consisting of 25 graphics primitives sage: T4.plot() + Graphics object consisting of 2 graphics primitives Elements of ``crystals.TensorProduct(A,B,C, ...)`` are represented by sequences ``[a,b,c, ...]`` with ``a`` in ``A``, ``b`` in ``B``, etc. diff --git a/src/doc/en/thematic_tutorials/lie/weyl_character_ring.rst b/src/doc/en/thematic_tutorials/lie/weyl_character_ring.rst index 3de07106812..3caeb368547 100644 --- a/src/doc/en/thematic_tutorials/lie/weyl_character_ring.rst +++ b/src/doc/en/thematic_tutorials/lie/weyl_character_ring.rst @@ -418,7 +418,7 @@ coroot notation, you are working with `SL` automatically:: sage: A2 = WeylCharacterRing("A2", style="coroots") sage: A2(1,0).weight_multiplicities() - {(-1/3, -1/3, 2/3): 1, (2/3, -1/3, -1/3): 1, (-1/3, 2/3, -1/3): 1} + {(-1/3, -1/3, 2/3): 1, (-1/3, 2/3, -1/3): 1, (2/3, -1/3, -1/3): 1} There is no convenient way to create the determinant in the Weyl character ring if you adopt the coroot style. diff --git a/src/doc/en/thematic_tutorials/sandpile.rst b/src/doc/en/thematic_tutorials/sandpile.rst index 24af2fb2f33..4d93ec18928 100644 --- a/src/doc/en/thematic_tutorials/sandpile.rst +++ b/src/doc/en/thematic_tutorials/sandpile.rst @@ -353,6 +353,7 @@ taken to be the sum of the number of times each vertex fires. sage: p = list_plot([[log(i+1),log(a.count(i))] for i in [0..max(a)] if a.count(i)]) # long time sage: p.axes_labels(['log(N)','log(D(N))']) # long time sage: p # long time + Graphics object consisting of 1 graphics primitive .. figure:: media/sandpile/btw.png :align: center @@ -4066,19 +4067,29 @@ Other EXAMPLES:: sage: aztec_sandpile(2) - {'sink': {(3/2, 1/2): 2, (-1/2, -3/2): 2, (-3/2, 1/2): 2, (1/2, 3/2): 2, - (1/2, -3/2): 2, (-3/2, -1/2): 2, (-1/2, 3/2): 2, (3/2, -1/2): 2}, - (1/2, 3/2): {(-1/2, 3/2): 1, (1/2, 1/2): 1, 'sink': 2}, (1/2, 1/2): - {(1/2, -1/2): 1, (3/2, 1/2): 1, (1/2, 3/2): 1, (-1/2, 1/2): 1}, - (-3/2, 1/2): {(-3/2, -1/2): 1, 'sink': 2, (-1/2, 1/2): 1}, (-1/2, -1/2): - {(-3/2, -1/2): 1, (1/2, -1/2): 1, (-1/2, -3/2): 1, (-1/2, 1/2): 1}, - (-1/2, 1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, (-1/2, 3/2): 1, - (1/2, 1/2): 1}, (-3/2, -1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, 'sink': 2}, - (3/2, 1/2): {(1/2, 1/2): 1, (3/2, -1/2): 1, 'sink': 2}, (-1/2, 3/2): - {(1/2, 3/2): 1, 'sink': 2, (-1/2, 1/2): 1}, (1/2, -3/2): {(1/2, -1/2): 1, - (-1/2, -3/2): 1, 'sink': 2}, (3/2, -1/2): {(3/2, 1/2): 1, (1/2, -1/2): 1, - 'sink': 2}, (1/2, -1/2): {(1/2, -3/2): 1, (-1/2, -1/2): 1, (1/2, 1/2): 1, - (3/2, -1/2): 1}, (-1/2, -3/2): {(-1/2, -1/2): 1, 'sink': 2, (1/2, -3/2): 1}} + {'sink': {(-3/2, -1/2): 2, + (-3/2, 1/2): 2, + (-1/2, -3/2): 2, + (-1/2, 3/2): 2, + (1/2, -3/2): 2, + (1/2, 3/2): 2, + (3/2, -1/2): 2, + (3/2, 1/2): 2}, + (-3/2, -1/2): {'sink': 2, (-3/2, 1/2): 1, (-1/2, -1/2): 1}, + (-3/2, 1/2): {'sink': 2, (-3/2, -1/2): 1, (-1/2, 1/2): 1}, + (-1/2, -3/2): {'sink': 2, (-1/2, -1/2): 1, (1/2, -3/2): 1}, + (-1/2, -1/2): {(-3/2, -1/2): 1, + (-1/2, -3/2): 1, + (-1/2, 1/2): 1, + (1/2, -1/2): 1}, + (-1/2, 1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, (-1/2, 3/2): 1, (1/2, 1/2): 1}, + (-1/2, 3/2): {'sink': 2, (-1/2, 1/2): 1, (1/2, 3/2): 1}, + (1/2, -3/2): {'sink': 2, (-1/2, -3/2): 1, (1/2, -1/2): 1}, + (1/2, -1/2): {(-1/2, -1/2): 1, (1/2, -3/2): 1, (1/2, 1/2): 1, (3/2, -1/2): 1}, + (1/2, 1/2): {(-1/2, 1/2): 1, (1/2, -1/2): 1, (1/2, 3/2): 1, (3/2, 1/2): 1}, + (1/2, 3/2): {'sink': 2, (-1/2, 3/2): 1, (1/2, 1/2): 1}, + (3/2, -1/2): {'sink': 2, (1/2, -1/2): 1, (3/2, 1/2): 1}, + (3/2, 1/2): {'sink': 2, (1/2, 1/2): 1, (3/2, -1/2): 1}} sage: Sandpile(aztec_sandpile(2),'sink').group_order() 4542720 @@ -4196,9 +4207,14 @@ Other sage: glue_y = {0: 1, 1: 2, 3: 1} sage: z = glue_graphs(x,y,glue_x,glue_y) sage: z - {0: {}, 'y2': {'y1': 2}, 'y1': {0: 2}, 'x2': {'x0': 1, 'x1': 1}, - 'x3': {'x2': 1, 'x0': 1, 'x1': 1}, 'y3': {0: 1, 'y2': 1}, - 'x1': {'x0': 1}, 'x0': {0: 1, 'x3': 2, 'y3': 1, 'x1': 1, 'y1': 2}} + {0: {}, + 'x0': {0: 1, 'x1': 1, 'x3': 2, 'y1': 2, 'y3': 1}, + 'x1': {'x0': 1}, + 'x2': {'x0': 1, 'x1': 1}, + 'x3': {'x0': 1, 'x1': 1, 'x2': 1}, + 'y1': {0: 2}, + 'y2': {'y1': 2}, + 'y3': {0: 1, 'y2': 1}} sage: S = Sandpile(z,0) sage: S.h_vector() [1, 6, 17, 31, 41, 41, 31, 17, 6, 1] @@ -4233,19 +4249,19 @@ Other EXAMPLES:: sage: grid_sandpile(3,4).dict() - {(1, 2): {(1, 1): 1, (1, 3): 1, 'sink': 1, (2, 2): 1}, - (3, 2): {(3, 3): 1, (3, 1): 1, 'sink': 1, (2, 2): 1}, - (1, 3): {(1, 2): 1, (2, 3): 1, 'sink': 1, (1, 4): 1}, - (3, 3): {(2, 3): 1, (3, 2): 1, (3, 4): 1, 'sink': 1}, - (3, 1): {(3, 2): 1, 'sink': 2, (2, 1): 1}, - (1, 4): {(1, 3): 1, (2, 4): 1, 'sink': 2}, - (2, 4): {(2, 3): 1, (3, 4): 1, 'sink': 1, (1, 4): 1}, - (2, 3): {(3, 3): 1, (1, 3): 1, (2, 4): 1, (2, 2): 1}, - (2, 1): {(1, 1): 1, (3, 1): 1, 'sink': 1, (2, 2): 1}, - (2, 2): {(1, 2): 1, (3, 2): 1, (2, 3): 1, (2, 1): 1}, - (3, 4): {(2, 4): 1, (3, 3): 1, 'sink': 2}, - (1, 1): {(1, 2): 1, 'sink': 2, (2, 1): 1}, - 'sink': {}} + {'sink': {}, + (1, 1): {'sink': 2, (1, 2): 1, (2, 1): 1}, + (1, 2): {'sink': 1, (1, 1): 1, (1, 3): 1, (2, 2): 1}, + (1, 3): {'sink': 1, (1, 2): 1, (1, 4): 1, (2, 3): 1}, + (1, 4): {'sink': 2, (1, 3): 1, (2, 4): 1}, + (2, 1): {'sink': 1, (1, 1): 1, (2, 2): 1, (3, 1): 1}, + (2, 2): {(1, 2): 1, (2, 1): 1, (2, 3): 1, (3, 2): 1}, + (2, 3): {(1, 3): 1, (2, 2): 1, (2, 4): 1, (3, 3): 1}, + (2, 4): {'sink': 1, (1, 4): 1, (2, 3): 1, (3, 4): 1}, + (3, 1): {'sink': 2, (2, 1): 1, (3, 2): 1}, + (3, 2): {'sink': 1, (2, 2): 1, (3, 1): 1, (3, 3): 1}, + (3, 3): {'sink': 1, (2, 3): 1, (3, 2): 1, (3, 4): 1}, + (3, 4): {'sink': 2, (2, 4): 1, (3, 3): 1}} sage: grid_sandpile(3,4).group_order() 4140081 diff --git a/src/doc/en/thematic_tutorials/tutorial-notebook-and-help-long.rst b/src/doc/en/thematic_tutorials/tutorial-notebook-and-help-long.rst index 4dc22e93f82..9ac92dbfb85 100644 --- a/src/doc/en/thematic_tutorials/tutorial-notebook-and-help-long.rst +++ b/src/doc/en/thematic_tutorials/tutorial-notebook-and-help-long.rst @@ -297,6 +297,7 @@ Here is a simple example:: sage: var('x') # make sure x is a symbolic variable x sage: plot(sin(x^2), (x,0,10)) + Graphics object consisting of 1 graphics primitive Here is a more complicated plot. Try to change every single input to the plot command in some way, evaluating to see what happens:: @@ -323,6 +324,7 @@ Plotting multiple functions at once is as easy as adding them together:: sage: P1 = plot(sin(x), (x,0,2*pi)) sage: P2 = plot(cos(x), (x,0,2*pi), rgbcolor='red') sage: P1 + P2 + Graphics object consisting of 2 graphics primitives Symbolic Expressions ==================== diff --git a/src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst b/src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst index 39de4602651..8900c8bc09d 100644 --- a/src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst +++ b/src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst @@ -285,7 +285,8 @@ Some particular actions modify the data structure of ``el``:: sage: el.__class__ sage: el.__dict__ - {'_monomial_coefficients': {[1, 2, 3]: 1, [1, 3, 2]: 3}, '__custom_name': 'foo'} + {'__custom_name': 'foo', + '_monomial_coefficients': {[1, 2, 3]: 1, [1, 3, 2]: 3}} Lots of Sage objects are not Python objects but compiled Cython objects. Python sees them as builtin objects and you don't have access to @@ -296,12 +297,8 @@ Some particular actions modify the data structure of ``el``:: sage: type(e) sage: e.__dict__ - dict_proxy({'__module__': 'sage.categories.category', - '_reduction': (, - (Join of Category of euclidean domains - and Category of infinite enumerated sets, 'element_class')), - '__doc__': ..., - '_sage_src_lines_': }) + }> sage: e.__dict__.keys() ['__module__', '_reduction', '__doc__', '_sage_src_lines_'] @@ -309,12 +306,8 @@ Some particular actions modify the data structure of ``el``:: sage: type(id4) sage: id4.__dict__ - dict_proxy({'__module__': 'sage.categories.category', - '_reduction': (, - (Join of Category of finite permutation groups - and Category of finite weyl groups, 'element_class')), - '__doc__': "...", - '_sage_src_lines_': }) + }> .. note:: diff --git a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst index 7e6511237da..fbce406be26 100644 --- a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst +++ b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst @@ -86,7 +86,7 @@ The *standard types* are :class:`bool`, :class:`int`, :class:`list`, must be hashable:: sage: set([2,2,1,4,5]) - set([1, 2, 4, 5]) + {1, 2, 4, 5} sage: set([ [1], [2] ]) Traceback (most recent call last): @@ -102,7 +102,7 @@ The *standard types* are :class:`bool`, :class:`int`, :class:`list`, For example:: sage: age = {'toto' : 8, 'mom' : 27}; age - {'toto': 8, 'mom': 27} + {'mom': 27, 'toto': 8} * Quotes (simple ``' '`` or double ``" "``) enclose *character strings*. One can concatenate them using ``+``. @@ -705,7 +705,7 @@ braces, ``{}``, with comma-separated entries given in the form sage: d = {3:17, "key":[4,1,5,2,3], (3,1,2):"goo", 3/2 : 17} sage: d - {3/2: 17, 3: 17, (3, 1, 2): 'goo', 'key': [4, 1, 5, 2, 3]} + {3/2: 17, 3: 17, 'key': [4, 1, 5, 2, 3], (3, 1, 2): 'goo'} A second method is to use the constructor :class:`dict` which admits a list (or actually any iterable) of 2-tuples *(key, value)*:: @@ -732,7 +732,7 @@ Dictionaries behave as lists and tuples for several important operations. sage: d[10]='a' sage: d - {3/2: 17, 10: 'a', 3: 17, (3, 1, 2): 'goo', 'key': [4, 1, 5, 2, 3]} + {3/2: 17, 3: 17, 10: 'a', 'key': [4, 1, 5, 2, 3], (3, 1, 2): 'goo'} A dictionary can have the same value multiple times, but each key must only appear once and must be immutable:: @@ -765,7 +765,7 @@ updates the dictionary from another dictionary:: sage: d.update( {10 : 'newvalue', 20: 'newervalue', 3: 14, 'a':[1,2,3]} ) sage: d - {'a': [1, 2, 3], 10: 'newvalue', 3: 14, 20: 'newervalue'} + {3: 14, 10: 'newvalue', 20: 'newervalue', 'a': [1, 2, 3]} We can iterate through the *keys*, or *values*, or both, of a dictionary:: diff --git a/src/doc/en/tutorial/programming.rst b/src/doc/en/tutorial/programming.rst index 656ed917784..bf334166d3b 100644 --- a/src/doc/en/tutorial/programming.rst +++ b/src/doc/en/tutorial/programming.rst @@ -483,15 +483,15 @@ or not, along with standard set-theoretic operations. sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) sage: X - set(['a', 1, 19]) + {1, 19, 'a'} sage: Y - set([1, 2/3]) + {2/3, 1} sage: 'a' in X True sage: 'a' in Y False sage: X.intersection(Y) - set([1]) + {1} Sage also has its own set type that is (in some cases) implemented using the built-in Python set type, but has a little bit of extra Sage-related diff --git a/src/doc/en/tutorial/tour_functions.rst b/src/doc/en/tutorial/tour_functions.rst index ae4a33f5e0a..672eb99b7be 100644 --- a/src/doc/en/tutorial/tour_functions.rst +++ b/src/doc/en/tutorial/tour_functions.rst @@ -21,6 +21,7 @@ These functions can be plotted, but not differentiated or integrated. sage: f(3) 9 sage: plot(f, 0, 2) + Graphics object consisting of 1 graphics primitive In the last line, note the syntax. Using ``plot(f(z), 0, 2)`` instead will give an error, because ``z`` is a dummy variable in the @@ -38,6 +39,7 @@ should probably be avoided (see item 4 below). sage: f(z) z^2 sage: plot(f(z), 0, 2) + Graphics object consisting of 1 graphics primitive At this point, ``f(z)`` is a symbolic expression, the next item in our list. @@ -59,6 +61,7 @@ differentiated, and integrated. sage: type(g) sage: plot(g, 0, 2) + Graphics object consisting of 1 graphics primitive Note that while ``g`` is a callable symbolic expression, ``g(x)`` is a related, but different sort of object, which can also be plotted, @@ -76,6 +79,7 @@ illustration. sage: g(x).derivative() 2*x sage: plot(g(x), 0, 2) + Graphics object consisting of 1 graphics primitive 3. Use a pre-defined Sage 'calculus function'. These can be plotted, and with a little help, differentiated, and integrated. @@ -85,9 +89,11 @@ and with a little help, differentiated, and integrated. sage: type(sin) sage: plot(sin, 0, 2) + Graphics object consisting of 1 graphics primitive sage: type(sin(x)) sage: plot(sin(x), 0, 2) + Graphics object consisting of 1 graphics primitive By itself, ``sin`` cannot be differentiated, at least not to produce ``cos``. @@ -145,6 +151,7 @@ The solution: don't use ``plot(h(x), 0, 4)``; instead, use :: sage: plot(h, 0, 4) + Graphics object consisting of 1 graphics primitive \5. Accidentally producing a constant instead of a function. diff --git a/src/doc/en/tutorial/tour_plotting.rst b/src/doc/en/tutorial/tour_plotting.rst index 11db733ac6e..2d859b3c99a 100644 --- a/src/doc/en/tutorial/tour_plotting.rst +++ b/src/doc/en/tutorial/tour_plotting.rst @@ -22,12 +22,14 @@ origin: :: sage: circle((0,0), 1, rgbcolor=(1,1,0)) + Graphics object consisting of 1 graphics primitive You can also produce a filled circle: :: sage: circle((0,0), 1, rgbcolor=(1,1,0), fill=True) + Graphics object consisting of 1 graphics primitive You can also create a circle by assigning it to a variable; this does not plot it: @@ -65,6 +67,7 @@ It's easy to plot basic functions: :: sage: plot(cos, (-5,5)) + Graphics object consisting of 1 graphics primitive Once you specify a variable name, you can create parametric plots also: @@ -73,6 +76,7 @@ also: sage: x = var('x') sage: parametric_plot((cos(x),sin(x)^3),(x,0,2*pi),rgbcolor=hue(0.6)) + Graphics object consisting of 1 graphics primitive It's important to notice that the axes of the plots will only intersect if the origin is in the viewing range of the graph, and @@ -81,6 +85,7 @@ that with sufficiently large values scientific notation may be used: :: sage: plot(x^2,(x,300,500)) + Graphics object consisting of 1 graphics primitive You can combine several plots by adding them: @@ -103,6 +108,7 @@ example, here is a green deltoid: ... 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] sage: p = polygon(L, rgbcolor=(1/8,3/4,1/2)) sage: p + Graphics object consisting of 1 graphics primitive Type ``show(p, axes=false)`` to see this without any axes. @@ -126,6 +132,7 @@ Sage commands construct this: sage: v = [(sin(x),x) for x in srange(-2*float(pi),2*float(pi),0.1)] sage: line(v) + Graphics object consisting of 1 graphics primitive Since the tangent function has a larger range than sine, if you use the same trick to plot the inverse tangent, you should change the @@ -144,6 +151,7 @@ plot: sage: f = lambda x,y: cos(x*y) sage: contour_plot(f, (-4, 4), (-4, 4)) + Graphics object consisting of 1 graphics primitive Three-Dimensional Plots ----------------------- @@ -159,6 +167,7 @@ Use ``plot3d`` to graph a function of the form `f(x, y) = z`: sage: x, y = var('x,y') sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2)) + Graphics3d Object Alternatively, you can use ``parametric_plot3d`` to graph a parametric surface where each of `x, y, z` is determined by @@ -173,6 +182,7 @@ as follows: sage: f_y(u, v) = v sage: f_z(u, v) = u^2 + v^2 sage: parametric_plot3d([f_x, f_y, f_z], (u, -2, 2), (v, -2, 2)) + Graphics3d Object The third way to plot a 3D surface in Sage is ``implicit_plot3d``, which graphs a contour of a function like `f(x, y, z) = 0` (this @@ -183,6 +193,7 @@ formula: sage: x, y, z = var('x, y, z') sage: implicit_plot3d(x^2 + y^2 + z^2 - 4, (x,-2, 2), (y,-2, 2), (z,-2, 2)) + Graphics3d Object Here are some more examples: @@ -195,7 +206,8 @@ Here are some more examples: sage: fy = u sage: fz = v^2 sage: parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -1, 1), - ... frame=False, color="yellow") + ....: frame=False, color="yellow") + Graphics3d Object `Cross cap `__: @@ -206,7 +218,8 @@ Here are some more examples: sage: fy = (1+cos(v))*sin(u) sage: fz = -tanh((2/3)*(u-pi))*sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Twisted torus: @@ -217,7 +230,8 @@ Twisted torus: sage: fy = (3+sin(v)+cos(u))*sin(2*v) sage: fz = sin(u)+2*cos(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Lemniscate: @@ -226,3 +240,4 @@ Lemniscate: sage: x, y, z = var('x,y,z') sage: f(x, y, z) = 4*x^2 * (x^2 + y^2 + z^2 + z) + y^2 * (y^2 + z^2 - 1) sage: implicit_plot3d(f, (x, -0.5, 0.5), (y, -1, 1), (z, -1, 1)) + Graphics3d Object diff --git a/src/doc/fr/tutorial/programming.rst b/src/doc/fr/tutorial/programming.rst index fe28e1d6db9..a9588f9f34e 100644 --- a/src/doc/fr/tutorial/programming.rst +++ b/src/doc/fr/tutorial/programming.rst @@ -499,15 +499,15 @@ ensemblistes usuelles. sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) sage: X - set(['a', 1, 19]) + {1, 19, 'a'} sage: Y - set([1, 2/3]) + {2/3, 1} sage: 'a' in X True sage: 'a' in Y False sage: X.intersection(Y) - set([1]) + {1} Sage a son propre type ensemble, qui est (dans certains cas) implémenté au-dessus du type Python, mais offre quelques fonctionnalités diff --git a/src/doc/fr/tutorial/tour_functions.rst b/src/doc/fr/tutorial/tour_functions.rst index d8546f15808..2c83d44b119 100644 --- a/src/doc/fr/tutorial/tour_functions.rst +++ b/src/doc/fr/tutorial/tour_functions.rst @@ -20,6 +20,7 @@ pour tracer des courbes, mais pas dérivées ou intégrées symboliquement:: sage: f(3) 9 sage: plot(f, 0, 2) + Graphics object consisting of 1 graphics primitive Remarquez la syntaxe de la dernière ligne. Écrire plutôt ``plot(f(z), 0, 2)`` provoquerait une erreur : en effet, le ``z`` qui apparaît dans @@ -39,6 +40,7 @@ s'abstenir de l'utiliser sage: f(z) z^2 sage: plot(f(z), 0, 2) + Graphics object consisting of 1 graphics primitive L'appel de fonction ``f(z)`` renvoie ici l'expression symbolique ``z^2``, qui est alors utilisée par la fonction ``plot``. @@ -59,6 +61,7 @@ et que l'on peut aussi dériver ou intégrer symboliquement :: sage: type(g) sage: plot(g, 0, 2) + Graphics object consisting of 1 graphics primitive Notez que, si ``g`` est une expression symbolique fonctionnelle (``x |--> x^2``), l'objet ``g(x)`` (``x^2``) est d'une nature un @@ -77,6 +80,7 @@ illustrées dans le point 5 ci-dessous. sage: g(x).derivative() 2*x sage: plot(g(x), 0, 2) + Graphics object consisting of 1 graphics primitive 3. Utiliser une fonction usuelle prédéfinie de Sage. Celles-ci peuvent servir à tracer des courbes, et, indirectement, être dérivées ou intégrées :: @@ -84,9 +88,11 @@ servir à tracer des courbes, et, indirectement, être dérivées ou intégrées sage: type(sin) sage: plot(sin, 0, 2) + Graphics object consisting of 1 graphics primitive sage: type(sin(x)) sage: plot(sin(x), 0, 2) + Graphics object consisting of 1 graphics primitive Il n'est pas possible de dériver la fonction ``sin`` tout court pour obtenir ``cos`` :: @@ -144,6 +150,7 @@ Solution : Il ne faut pas utiliser ``plot(h(x), 0, 4)``, mais plutôt ... else: ... return x-2 sage: plot(h, 0, 4) + Graphics object consisting of 1 graphics primitive \5. Constante plutôt que fonction :: diff --git a/src/doc/fr/tutorial/tour_plotting.rst b/src/doc/fr/tutorial/tour_plotting.rst index 31bbaa9851d..9bf20c2c5e2 100644 --- a/src/doc/fr/tutorial/tour_plotting.rst +++ b/src/doc/fr/tutorial/tour_plotting.rst @@ -22,12 +22,14 @@ La commande suivante produit un cercle jaune de rayon 1 centré à l'origine : :: sage: circle((0,0), 1, rgbcolor=(1,1,0)) + Graphics object consisting of 1 graphics primitive Il est également possible de produire un disque plein : :: sage: circle((0,0), 1, rgbcolor=(1,1,0), fill=True) + Graphics object consisting of 1 graphics primitive Il est aussi possible de créer un cercle en l'affectant à une variable ; ceci ne provoque pas son affichage. @@ -66,6 +68,7 @@ Il est très facile de tracer le graphique de fonctions de base : :: sage: plot(cos, (-5,5)) + Graphics object consisting of 1 graphics primitive En spécifiant un nom de variable, on peut aussi créer des graphes paramétriques : @@ -74,6 +77,7 @@ paramétriques : sage: x = var('x') sage: parametric_plot((cos(x),sin(x)^3),(x,0,2*pi),rgbcolor=hue(0.6)) + Graphics object consisting of 1 graphics primitive Différents graphiques peuvent se combiner sur une même image : @@ -95,6 +99,7 @@ par ces points. Par example, voici un deltoïde vert : sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)),\ ... 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] sage: polygon(L, rgbcolor=(1/8,3/4,1/2)) + Graphics object consisting of 1 graphics primitive Pour visualiser le graphique en masquant les axes, tapez ``show(p, axes=false)``. @@ -119,6 +124,7 @@ Sage suivante réalise cela : sage: v = [(sin(x),x) for x in srange(-2*float(pi),2*float(pi),0.1)] sage: line(v) + Graphics object consisting of 1 graphics primitive Comme les valeurs prises par la fonction tangente ne sont pas bornées, pour utiliser la même astuce pour représenter la fonction arctangente, @@ -137,6 +143,7 @@ vecteurs. Voici un exemple de lignes de niveau : sage: f = lambda x,y: cos(x*y) sage: contour_plot(f, (-4, 4), (-4, 4)) + Graphics object consisting of 1 graphics primitive Graphiques en trois dimensions ------------------------------ @@ -154,7 +161,8 @@ http://en.wikipedia.org/wiki/Whitney_umbrella: sage: fy = u sage: fz = v^2 sage: parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -1, 1), - ... frame=False, color="yellow") + ....: frame=False, color="yellow") + Graphics3d Object Une fois évaluée la commande ``parametric_plot3d``, qui affiche le @@ -171,7 +179,8 @@ http://www.mathcurve.com/surfaces/bonnetcroise/bonnetcroise.shtml) : sage: fy = (1+cos(v))*sin(u) sage: fz = -tanh((2/3)*(u-pi))*sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Un tore tordu : @@ -182,6 +191,7 @@ Un tore tordu : sage: fy = (3+sin(v)+cos(u))*sin(2*v) sage: fz = sin(u)+2*cos(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object diff --git a/src/doc/ru/tutorial/programming.rst b/src/doc/ru/tutorial/programming.rst index b96da1c301e..4ef166d9853 100644 --- a/src/doc/ru/tutorial/programming.rst +++ b/src/doc/ru/tutorial/programming.rst @@ -467,15 +467,15 @@ http://docs.python.org/lib/typesmapping.html) произвольным объе sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) sage: X - set(['a', 1, 19]) + {1, 19, 'a'} sage: Y - set([1, 2/3]) + {2/3, 1} sage: 'a' in X True sage: 'a' in Y False sage: X.intersection(Y) - set([1]) + {1} В Sage также имеется свой тип данных множество, который (в некоторых случаях) осуществлен с использованием встроенного типа множество Python, но включает в diff --git a/src/doc/ru/tutorial/tour_functions.rst b/src/doc/ru/tutorial/tour_functions.rst index c4a72fc2687..662b1fcf1c2 100644 --- a/src/doc/ru/tutorial/tour_functions.rst +++ b/src/doc/ru/tutorial/tour_functions.rst @@ -22,6 +22,7 @@ sage: f(3) 9 sage: plot(f, 0, 2) + Graphics object consisting of 1 graphics primitive Обратите внимание на синтаксис в последней строчке. ``plot(f(z), 0, 2)`` выдаст ошибку, так как ``z`` - это переменная-болванка в определении ``f``, @@ -38,6 +39,7 @@ sage: f(z) z^2 sage: plot(f(z), 0, 2) + Graphics object consisting of 1 graphics primitive В этом случае ``f(z)`` - это символьное выражение. @@ -58,6 +60,7 @@ sage: type(g) sage: plot(g, 0, 2) + Graphics object consisting of 1 graphics primitive Если ``g`` — это вызываемое символьное выражение, ``g(x)`` — это связянный с ним объект, но другого вида, для которого можно построить @@ -74,6 +77,7 @@ sage: g(x).derivative() 2*x sage: plot(g(x), 0, 2) + Graphics object consisting of 1 graphics primitive 3. Можно использовать уже определенную функцию Sage — 'функцию исчисления'. Для нее может быть построен график, она может быть продифференцирована @@ -84,9 +88,11 @@ sage: type(sin) sage: plot(sin, 0, 2) + Graphics object consisting of 1 graphics primitive sage: type(sin(x)) sage: plot(sin(x), 0, 2) + Graphics object consisting of 1 graphics primitive Сама по себе функция ``sin`` не может быть продифференцирована, по крайней мере, не может произвести ``cos``. @@ -138,6 +144,7 @@ :: sage: plot(h, 0, 4) + Graphics object consisting of 1 graphics primitive \5. Ошибочное создание константы вместо функции. diff --git a/src/doc/ru/tutorial/tour_plotting.rst b/src/doc/ru/tutorial/tour_plotting.rst index b974588b583..44ba116e793 100644 --- a/src/doc/ru/tutorial/tour_plotting.rst +++ b/src/doc/ru/tutorial/tour_plotting.rst @@ -21,12 +21,14 @@ Sage может строить двумерные и трехмерные гра :: sage: circle((0,0), 1, rgbcolor=(1,1,0)) + Graphics object consisting of 1 graphics primitive Также можно построить круг: :: sage: circle((0,0), 1, rgbcolor=(1,1,0), fill=True) + Graphics object consisting of 1 graphics primitive Можно создавать окружность и задавать ее какой-либо переменной. Данный пример не будет строить окружность: @@ -62,6 +64,7 @@ Sage может строить двумерные и трехмерные гра :: sage: plot(cos, (-5,5)) + Graphics object consisting of 1 graphics primitive Как только имя переменной определено, можно создать параметрический график: @@ -69,6 +72,7 @@ Sage может строить двумерные и трехмерные гра sage: x = var('x') sage: parametric_plot((cos(x),sin(x)^3),(x,0,2*pi),rgbcolor=hue(0.6)) + Graphics object consisting of 1 graphics primitive Важно отметить, что оси графика будут пересекаться лишь в том случае, когда начало координат находится в поле зрения графика, и что к @@ -77,6 +81,7 @@ Sage может строить двумерные и трехмерные гра :: sage: plot(x^2,(x,300,500)) + Graphics object consisting of 1 graphics primitive Можно объединять построения, добавляя их друг другу: @@ -99,6 +104,7 @@ Sage может строить двумерные и трехмерные гра ... 2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] sage: p = polygon(L, rgbcolor=(1/8,3/4,1/2)) sage: p + Graphics object consisting of 1 graphics primitive Напечатайте ``show(p, axes=false)``, чтобы не показывать осей на графике. @@ -122,6 +128,7 @@ Sage может строить двумерные и трехмерные гра sage: v = [(sin(x),x) for x in srange(-2*float(pi),2*float(pi),0.1)] sage: line(v) + Graphics object consisting of 1 graphics primitive Так как функция тангенса имеет больший интервал, чем синус, при использовании той же техники для перевертывания тангенса требуется @@ -140,6 +147,7 @@ Sage также может строить графики в полярных к sage: f = lambda x,y: cos(x*y) sage: contour_plot(f, (-4, 4), (-4, 4)) + Graphics object consisting of 1 graphics primitive Трехмерные графики ------------------ @@ -154,6 +162,7 @@ Sage также может быть использован для создани sage: x, y = var('x,y') sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2)) + Graphics3d Object Еще можно использовать ``parametric_plot3d`` для построения графиков параметрических поверхностей, где каждый из `x, y, z` определяется функцией @@ -167,6 +176,7 @@ Sage также может быть использован для создани sage: f_y(u, v) = v sage: f_z(u, v) = u^2 + v^2 sage: parametric_plot3d([f_x, f_y, f_z], (u, -2, 2), (v, -2, 2)) + Graphics3d Object Третий способ построить трехмерную поверхность в Sage - использование ``implicit_plot3d``, который строит контуры графиков функций, как @@ -176,6 +186,7 @@ Sage также может быть использован для создани sage: x, y, z = var('x, y, z') sage: implicit_plot3d(x^2 + y^2 + z^2 - 4, (x,-2, 2), (y,-2, 2), (z,-2, 2)) + Graphics3d Object Ниже показаны несколько примеров: @@ -190,7 +201,8 @@ Sage также может быть использован для создани sage: fy = (1+cos(v))*sin(u) sage: fz = -tanh((2/3)*(u-pi))*sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Крученый тороид: @@ -201,7 +213,8 @@ Sage также может быть использован для создани sage: fy = (3+sin(v)+cos(u))*sin(2*v) sage: fz = sin(u)+2*cos(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), - ... frame=False, color="red") + ....: frame=False, color="red") + Graphics3d Object Лемниската: @@ -210,3 +223,4 @@ Sage также может быть использован для создани sage: x, y, z = var('x,y,z') sage: f(x, y, z) = 4*x^2 * (x^2 + y^2 + z^2 + z) + y^2 * (y^2 + z^2 - 1) sage: implicit_plot3d(f, (x, -0.5, 0.5), (y, -1, 1), (z, -1, 1)) + Graphics3d Object diff --git a/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx index 832669df7c8..9951296cf2f 100644 --- a/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx @@ -124,7 +124,7 @@ cdef class FreeAlgebraElement_letterplace(AlgebraElement): sage: F. = FreeAlgebra(QQ, implementation='letterplace') sage: set([x*y*z, z*y+x*z,x*y*z]) # indirect doctest - set([x*z + z*y, x*y*z]) + {x*z + z*y, x*y*z} """ return hash(self._poly) diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx index a78c8616b77..be8de6aaa76 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx @@ -598,13 +598,11 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: from sage.algebras.letterplace.free_algebra_element_letterplace import FreeAlgebraElement_letterplace sage: P = F.commutative_ring() sage: FreeAlgebraElement_letterplace(F, P.0*P.1^2+P.1^3) # indirect doctest - Traceback (most recent call last): - ... - NotImplementedError: + ) failed: NotImplementedError: Apparently you tried to view the letterplace algebra with shift-multiplication as the free algebra over a finitely generated free abelian monoid. - In principle, this is correct, but it is not implemented, yet. + In principle, this is correct, but it is not implemented, yet.> """ cdef int ngens = self.__ngens diff --git a/src/sage/algebras/steenrod/steenrod_algebra.py b/src/sage/algebras/steenrod/steenrod_algebra.py index cd448f9a832..da7d1457c17 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra.py +++ b/src/sage/algebras/steenrod/steenrod_algebra.py @@ -403,7 +403,7 @@ 1 (5,) 1 (2, 1) sage: c.monomial_coefficients() - {(5,): 1, (2, 1): 1} + {(2, 1): 1, (5,): 1} sage: c.monomials() [Sq(2,1), Sq(5)] sage: c.support() @@ -3114,7 +3114,7 @@ class Element(CombinatorialFreeModuleElement): 1 (5,) 1 (2, 1) sage: c.monomial_coefficients() - {(5,): 1, (2, 1): 1} + {(2, 1): 1, (5,): 1} sage: c.monomials() [Sq(2,1), Sq(5)] sage: c.support() @@ -3357,7 +3357,7 @@ def _basis_dictionary(self,basis): Sq^2 Sq^1 sage: d = Sq(0,0,1) sage: d._basis_dictionary('arnonc') - {(7,): 1, (2, 5): 1, (4, 3): 1, (4, 2, 1): 1} + {(2, 5): 1, (4, 2, 1): 1, (4, 3): 1, (7,): 1} sage: d.change_basis('arnonc') Sq^2 Sq^5 + Sq^4 Sq^2 Sq^1 + Sq^4 Sq^3 + Sq^7 diff --git a/src/sage/algebras/steenrod/steenrod_algebra_mult.py b/src/sage/algebras/steenrod/steenrod_algebra_mult.py index cdec038d3b8..6e1e29e9198 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra_mult.py +++ b/src/sage/algebras/steenrod/steenrod_algebra_mult.py @@ -238,9 +238,9 @@ def milnor_multiplication(r,s): sage: milnor_multiplication((2,), (1,)) {(0, 1): 1, (3,): 1} sage: milnor_multiplication((4,), (2,1)) - {(6, 1): 1, (0, 3): 1, (2, 0, 1): 1} + {(0, 3): 1, (2, 0, 1): 1, (6, 1): 1} sage: milnor_multiplication((2,4), (0,1)) - {(2, 5): 1, (2, 0, 0, 1): 1} + {(2, 0, 0, 1): 1, (2, 5): 1} These examples correspond to the following product computations: @@ -410,7 +410,7 @@ def milnor_multiplication_odd(m1,m2,p): sage: milnor_multiplication_odd(((0,2,4),()), ((1,5),()), 7) {((0, 1, 2, 4, 5), ()): 1} sage: milnor_multiplication_odd(((),(6,)), ((),(2,)), 3) - {((), (4, 1)): 1, ((), (8,)): 1, ((), (0, 2)): 1} + {((), (0, 2)): 1, ((), (4, 1)): 1, ((), (8,)): 1} These examples correspond to the following product computations: @@ -776,9 +776,9 @@ def adem(a, b, c=0, p=2, generic=None): sage: adem(1,0,1, p=7) {(0, 2, 0): 2} sage: adem(1,1,1, p=5) - {(1, 2, 0): 1, (0, 2, 1): 1} + {(0, 2, 1): 1, (1, 2, 0): 1} sage: adem(1,1,2, p=5) - {(1, 3, 0): 2, (0, 3, 1): 1} + {(0, 3, 1): 1, (1, 3, 0): 2} """ if generic is None: generic = False if p==2 else True diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index dab970825e7..e78a3352188 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -139,6 +139,7 @@ def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False) :: sage: plot(f) + Graphics object consisting of 1 graphics primitive We can also solve second-order differential equations.:: diff --git a/src/sage/calculus/riemann.pyx b/src/sage/calculus/riemann.pyx index 9c46ce30b9f..3051a2fa8b4 100644 --- a/src/sage/calculus/riemann.pyx +++ b/src/sage/calculus/riemann.pyx @@ -138,12 +138,14 @@ cdef class Riemann_Map: sage: fprime(t) = I*e^(I*t) sage: m = Riemann_Map([f], [fprime], 0) # long time (4 sec) sage: m.plot_colored() + m.plot_spiderweb() # long time + Graphics object consisting of 22 graphics primitives The exterior map for the unit circle:: sage: m = Riemann_Map([f], [fprime], 0, exterior=True) # long time (4 sec) sage: #spiderwebs are not supported for exterior maps sage: m.plot_colored() # long time + Graphics object consisting of 1 graphics primitive The unit circle with a small hole:: @@ -155,6 +157,7 @@ cdef class Riemann_Map: sage: #spiderweb and color plots cannot be added for multiply sage: #connected regions. Instead we do this. sage: m.plot_spiderweb(withcolor = True) # long time + Graphics object consisting of 3 graphics primitives A square:: @@ -163,6 +166,7 @@ cdef class Riemann_Map: sage: fprime = lambda t: ps.derivative(real(t)) sage: m = Riemann_Map([f], [fprime], 0.25, ncorners=4) sage: m.plot_colored() + m.plot_spiderweb() # long time + Graphics object consisting of 22 graphics primitives Compute rough error for this map:: @@ -420,6 +424,7 @@ cdef class Riemann_Map: sage: sz = m.get_szego(boundary=0) sage: points = m.get_szego(absolute_value=True) sage: list_plot(points) + Graphics object consisting of 1 graphics primitive Extending the points by a spline:: @@ -427,6 +432,7 @@ cdef class Riemann_Map: sage: s(3*pi / 4) 0.0012158... sage: plot(s,0,2*pi) # plot the kernel + Graphics object consisting of 1 graphics primitive The unit circle with a small hole:: @@ -493,6 +499,7 @@ cdef class Riemann_Map: sage: m = Riemann_Map([f], [fprime], 0) sage: points = m.get_theta_points() sage: list_plot(points) + Graphics object consisting of 1 graphics primitive Extending the points by a spline:: @@ -749,10 +756,12 @@ cdef class Riemann_Map: Default plot:: sage: m.plot_boundaries() + Graphics object consisting of 1 graphics primitive Big blue collocation points:: sage: m.plot_boundaries(plotjoined=False, rgbcolor=[0,0,1], thickness=6) + Graphics object consisting of 1 graphics primitive """ plots = range(self.B) for k in xrange(self.B): @@ -909,14 +918,17 @@ cdef class Riemann_Map: Default plot:: sage: m.plot_spiderweb() + Graphics object consisting of 21 graphics primitives Simplified plot with many discrete points:: sage: m.plot_spiderweb(spokes=4, circles=1, pts=400, linescale=0.95, plotjoined=False) + Graphics object consisting of 6 graphics primitives Plot with thick, red lines:: sage: m.plot_spiderweb(rgbcolor=[1,0,0], thickness=3) + Graphics object consisting of 21 graphics primitives To generate the unit circle map, it's helpful to see what the original spiderweb looks like:: @@ -925,6 +937,7 @@ cdef class Riemann_Map: sage: fprime(t) = I*e^(I*t) sage: m = Riemann_Map([f], [fprime], 0, 1000) sage: m.plot_spiderweb() + Graphics object consisting of 21 graphics primitives A multiply connected region with corners. We set ``min_mag`` higher to remove "fuzz" outside the domain:: @@ -1026,14 +1039,17 @@ cdef class Riemann_Map: sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t) sage: m = Riemann_Map([f], [fprime], 0) sage: m.plot_colored() + Graphics object consisting of 1 graphics primitive Plot zoomed in on a specific spot:: sage: m.plot_colored(plot_range=[0,1,.25,.75]) + Graphics object consisting of 1 graphics primitive High resolution plot:: sage: m.plot_colored(plot_points=1000) # long time (29s on sage.math, 2012) + Graphics object consisting of 1 graphics primitive To generate the unit circle map, it's helpful to see what the colors correspond to:: @@ -1042,6 +1058,7 @@ cdef class Riemann_Map: sage: fprime(t) = I*e^(I*t) sage: m = Riemann_Map([f], [fprime], 0, 1000) sage: m.plot_colored() + Graphics object consisting of 1 graphics primitive """ z_values, xmin, xmax, ymin, ymax = self.compute_on_grid(plot_range, plot_points) @@ -1072,6 +1089,7 @@ cdef comp_pt(clist, loop=True): sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t) sage: m = Riemann_Map([f], [fprime], 0) sage: m.plot_spiderweb() + Graphics object consisting of 21 graphics primitives """ list2 = range(len(clist) + 1) if loop else range(len(clist)) for i in xrange(len(clist)): diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 0311f666c77..bad03c177ff 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -21,9 +21,7 @@ A group action $G \times S \rightarrow S$ is a functor from $G$ to Sets. sage: import gc sage: _ = gc.collect() sage: A - Traceback (most recent call last): - ... - RuntimeError: This action acted on a set that became garbage collected + ) failed: RuntimeError: This action acted on a set that became garbage collected> To avoid garbage collection of the underlying set, it is sufficient to create a strong reference to it before the action is created. @@ -181,9 +179,7 @@ cdef class Action(Functor): sage: import gc sage: _ = gc.collect() sage: A - Traceback (most recent call last): - ... - RuntimeError: This action acted on a set that became garbage collected + ) failed: RuntimeError: This action acted on a set that became garbage collected> """ S = self.US() if S is None: diff --git a/src/sage/categories/additive_groups.py b/src/sage/categories/additive_groups.py index 7e59bfa50f8..dbc7449f272 100644 --- a/src/sage/categories/additive_groups.py +++ b/src/sage/categories/additive_groups.py @@ -41,7 +41,7 @@ class AdditiveGroups(CategoryWithAxiom_singleton): Category of objects] sage: AdditiveGroups().axioms() - frozenset(['AdditiveAssociative', 'AdditiveUnital', 'AdditiveInverse']) + frozenset({'AdditiveAssociative', 'AdditiveInverse', 'AdditiveUnital'}) sage: AdditiveGroups() is AdditiveMonoids().AdditiveInverse() True diff --git a/src/sage/categories/additive_magmas.py b/src/sage/categories/additive_magmas.py index b35515de5b4..8d9e9dfe01a 100644 --- a/src/sage/categories/additive_magmas.py +++ b/src/sage/categories/additive_magmas.py @@ -492,7 +492,7 @@ def extra_super_categories(self): sage: C.super_categories() [Category of additive magmas, Category of Cartesian products of sets] sage: C.axioms() - frozenset([]) + frozenset() """ return [AdditiveMagmas()] @@ -586,7 +586,7 @@ def extra_super_categories(self): sage: C.extra_super_categories(); [Category of additive commutative additive magmas] sage: C.axioms() - frozenset(['AdditiveCommutative']) + frozenset({'AdditiveCommutative'}) """ return [AdditiveMagmas().AdditiveCommutative()] @@ -850,7 +850,7 @@ def extra_super_categories(self): sage: C.extra_super_categories(); [Category of additive unital additive magmas] sage: C.axioms() - frozenset(['AdditiveUnital']) + frozenset({'AdditiveUnital'}) """ return [AdditiveMagmas().AdditiveUnital()] diff --git a/src/sage/categories/additive_semigroups.py b/src/sage/categories/additive_semigroups.py index f2d5ae27db9..19015927a25 100644 --- a/src/sage/categories/additive_semigroups.py +++ b/src/sage/categories/additive_semigroups.py @@ -38,7 +38,7 @@ class AdditiveSemigroups(CategoryWithAxiom_singleton): Category of objects] sage: C.axioms() - frozenset(['AdditiveAssociative']) + frozenset({'AdditiveAssociative'}) sage: C is AdditiveMagmas().AdditiveAssociative() True @@ -97,7 +97,7 @@ def extra_super_categories(self): sage: C.extra_super_categories() [Category of additive semigroups] sage: C.axioms() - frozenset(['AdditiveAssociative']) + frozenset({'AdditiveAssociative'}) """ return [AdditiveSemigroups()] diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index 0bcef7e8fb5..5e5fb88be2b 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -900,7 +900,14 @@ def _set_of_super_categories(self): EXAMPLES:: sage: Groups()._set_of_super_categories - frozenset([...]) + frozenset({Category of inverse unital magmas, + Category of unital magmas, + Category of magmas, + Category of monoids, + Category of objects, + Category of semigroups, + Category of sets with partial maps, + Category of sets}) sage: sorted(Groups()._set_of_super_categories, key=str) [Category of inverse unital magmas, Category of magmas, Category of monoids, Category of objects, Category of semigroups, Category of sets, @@ -1338,7 +1345,8 @@ def required_methods(self): EXAMPLES:: sage: Algebras(QQ).required_methods() - {'parent': {'required': ['__contains__'], 'optional': ['algebra_generators']}, 'element': {'required': ['__nonzero__'], 'optional': ['_add_', '_mul_']}} + {'element': {'optional': ['_add_', '_mul_'], 'required': ['__nonzero__']}, + 'parent': {'optional': ['algebra_generators'], 'required': ['__contains__']}} """ return { "parent" : abstract_methods_of_class(self.parent_class), "element" : abstract_methods_of_class(self.element_class) } @@ -1567,9 +1575,9 @@ def axioms(self): EXAMPLES:: sage: Monoids().axioms() - frozenset(['Associative', 'Unital']) + frozenset({'Associative', 'Unital'}) sage: (EnumeratedSets().Infinite() & Sets().Facade()).axioms() - frozenset(['Infinite', 'Facade']) + frozenset({'Facade', 'Infinite'}) """ return frozenset(axiom for category in self._super_categories @@ -1989,7 +1997,7 @@ def join(categories, as_list=False, ignore_axioms=(), axioms=()): sage: TCF is (T.Facade() & T.Commutative()) True sage: TCF.axioms() - frozenset(['Facade', 'Commutative']) + frozenset({'Commutative', 'Facade'}) sage: type(TCF) @@ -2236,8 +2244,10 @@ def category_graph(categories = None): ['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects', 'semigroups', 'sets', 'sets with partial maps', 'unital magmas'] sage: G.plot() + Graphics object consisting of 20 graphics primitives sage: sage.categories.category.category_graph().plot() + Graphics object consisting of 312 graphics primitives """ from sage import graphs if categories is None: diff --git a/src/sage/categories/category_with_axiom.py b/src/sage/categories/category_with_axiom.py index 86023961f89..caf3a32f391 100644 --- a/src/sage/categories/category_with_axiom.py +++ b/src/sage/categories/category_with_axiom.py @@ -74,7 +74,7 @@ class ``Semigroups.Infinite`` inheriting from :class:`CategoryWithAxiom`. [Category of finite cs, Category of finite sets, Category of cs, Category of sets, ...] sage: Cs().Finite().axioms() - frozenset(['Finite']) + frozenset({'Finite'}) Now a parent declared in the category ``Cs().Finite()`` inherits from all the methods of finite sets and of finite `C`'s, as desired:: @@ -1615,7 +1615,13 @@ class ``Sets.Finite``), or in a separate file (typically in a class sage: C.AdditiveInverse() Category of rings sage: Rings().axioms() - frozenset([...]) + frozenset({'AdditiveAssociative', + 'AdditiveCommutative', + 'AdditiveInverse', + 'AdditiveUnital', + 'Associative', + 'Distributive', + 'Unital'}) sage: sorted(Rings().axioms()) ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'Unital'] @@ -2376,7 +2382,7 @@ def axioms(self): sage: C = Sets.Finite(); C Category of finite sets sage: C.axioms() - frozenset(['Finite']) + frozenset({'Finite'}) sage: C = Modules(GF(5)).FiniteDimensional(); C Category of finite finite dimensional vector spaces over Finite Field of size 5 @@ -2395,7 +2401,7 @@ def axioms(self): sage: from sage.categories.magmas_and_additive_magmas import MagmasAndAdditiveMagmas sage: MagmasAndAdditiveMagmas().Distributive().Unital().axioms() - frozenset(['Distributive', 'Unital']) + frozenset({'Distributive', 'Unital'}) sage: D = MagmasAndAdditiveMagmas().Distributive() sage: X = D.AdditiveAssociative().AdditiveCommutative().Associative() diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index 1e68177bde3..15166a1906d 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -54,7 +54,7 @@ class Crystals(Category_singleton): sage: from sage.misc.abstract_method import abstract_methods_of_class sage: abstract_methods_of_class(Crystals().element_class) - {'required': ['e', 'epsilon', 'f', 'phi', 'weight'], 'optional': []} + {'optional': [], 'required': ['e', 'epsilon', 'f', 'phi', 'weight']} TESTS:: diff --git a/src/sage/categories/distributive_magmas_and_additive_magmas.py b/src/sage/categories/distributive_magmas_and_additive_magmas.py index 65036f86b1c..0a0ff4986bd 100644 --- a/src/sage/categories/distributive_magmas_and_additive_magmas.py +++ b/src/sage/categories/distributive_magmas_and_additive_magmas.py @@ -93,6 +93,6 @@ def extra_super_categories(self): sage: C.extra_super_categories(); [Category of distributive magmas and additive magmas] sage: C.axioms() - frozenset(['Distributive']) + frozenset({'Distributive'}) """ return [DistributiveMagmasAndAdditiveMagmas()] diff --git a/src/sage/categories/examples/commutative_additive_semigroups.py b/src/sage/categories/examples/commutative_additive_semigroups.py index 5017f492399..d03b8873552 100644 --- a/src/sage/categories/examples/commutative_additive_semigroups.py +++ b/src/sage/categories/examples/commutative_additive_semigroups.py @@ -149,7 +149,7 @@ def __init__(self, parent, iterable): sage: x 2*a + c + 5*d sage: x.value - {'a': 2, 'c': 1, 'b': 0, 'd': 5} + {'a': 2, 'b': 0, 'c': 1, 'd': 5} sage: x.parent() An example of a commutative monoid: the free commutative monoid generated by ('a', 'b', 'c', 'd') @@ -159,7 +159,7 @@ def __init__(self, parent, iterable): via :class:`ElementWrapper`:: sage: x.value - {'a': 2, 'c': 1, 'b': 0, 'd': 5} + {'a': 2, 'b': 0, 'c': 1, 'd': 5} """ d = dict( (a,0) for a in parent.alphabet ) for (a, c) in iterable: diff --git a/src/sage/categories/examples/finite_semigroups.py b/src/sage/categories/examples/finite_semigroups.py index 87e80b504f9..0cbb6d15e0d 100644 --- a/src/sage/categories/examples/finite_semigroups.py +++ b/src/sage/categories/examples/finite_semigroups.py @@ -71,6 +71,7 @@ class LeftRegularBand(UniqueRepresentation, Parent): sage: S = FiniteSemigroups().example(alphabet = ('a','b','c')) sage: S.cayley_graph(side="left", simple=True).plot() + Graphics object consisting of 60 graphics primitives sage: S.j_transversal_of_idempotents() # random (arbitrary choice) ['acb', 'ac', 'ab', 'bc', 'a', 'c', 'b'] diff --git a/src/sage/categories/examples/finite_weyl_groups.py b/src/sage/categories/examples/finite_weyl_groups.py index b3f88d0afc9..ac39a8103a0 100644 --- a/src/sage/categories/examples/finite_weyl_groups.py +++ b/src/sage/categories/examples/finite_weyl_groups.py @@ -90,6 +90,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): sage: S.long_element() (3, 2, 1, 0) sage: S.cayley_graph(side = "left").plot() + Graphics object consisting of 120 graphics primitives Alternatively, one could have implemented :meth:`sage.categories.coxeter_groups.CoxeterGroups.ElementMethods.apply_simple_reflection` diff --git a/src/sage/categories/finite_coxeter_groups.py b/src/sage/categories/finite_coxeter_groups.py index 8dbce9b1268..d17296a5164 100644 --- a/src/sage/categories/finite_coxeter_groups.py +++ b/src/sage/categories/finite_coxeter_groups.py @@ -27,6 +27,7 @@ class FiniteCoxeterGroups(CategoryWithAxiom): sage: G = FiniteCoxeterGroups().example() sage: G.cayley_graph(side = "right").plot() + Graphics object consisting of 40 graphics primitives Here are some further examples:: @@ -335,12 +336,12 @@ def coxeter_knuth_neighbor(self, w): sage: word = [1,2,1,3,2] sage: w = W.from_reduced_word(word) sage: w.coxeter_knuth_neighbor(word) - set([(1, 2, 3, 1, 2), (2, 1, 2, 3, 2)]) + {(1, 2, 3, 1, 2), (2, 1, 2, 3, 2)} sage: word = [1,2,1,3,2,4,3] sage: w = W.from_reduced_word(word) sage: w.coxeter_knuth_neighbor(word) - set([(1, 2, 1, 3, 4, 2, 3), (2, 1, 2, 3, 2, 4, 3), (1, 2, 3, 1, 2, 4, 3)]) + {(1, 2, 1, 3, 4, 2, 3), (1, 2, 3, 1, 2, 4, 3), (2, 1, 2, 3, 2, 4, 3)} TESTS:: diff --git a/src/sage/categories/finite_posets.py b/src/sage/categories/finite_posets.py index dddf0d8a878..768c91059d3 100644 --- a/src/sage/categories/finite_posets.py +++ b/src/sage/categories/finite_posets.py @@ -349,22 +349,22 @@ def order_ideal_complement_generators(self, antichain, direction='up'): sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) sage: P.order_ideal_complement_generators([1]) - set([2]) + {2} sage: P.order_ideal_complement_generators([3]) - set([]) + set() sage: P.order_ideal_complement_generators([1,2]) - set([3]) + {3} sage: P.order_ideal_complement_generators([1,2,3]) - set([]) + set() sage: P.order_ideal_complement_generators([1], direction="down") - set([2]) + {2} sage: P.order_ideal_complement_generators([3], direction="down") - set([1, 2]) + {1, 2} sage: P.order_ideal_complement_generators([1,2], direction="down") - set([]) + set() sage: P.order_ideal_complement_generators([1,2,3], direction="down") - set([]) + set() .. WARNING:: @@ -1253,17 +1253,17 @@ def panyushev_orbits(self, element_constructor = set): sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) sage: P.panyushev_orbits() - [[set([2]), set([1])], [set([]), set([1, 2]), set([3])]] + [[{2}, {1}], [set(), {1, 2}, {3}]] sage: P.panyushev_orbits(element_constructor=list) [[[2], [1]], [[], [1, 2], [3]]] sage: P.panyushev_orbits(element_constructor=frozenset) - [[frozenset([2]), frozenset([1])], - [frozenset([]), frozenset([1, 2]), frozenset([3])]] + [[frozenset({2}), frozenset({1})], + [frozenset(), frozenset({1, 2}), frozenset({3})]] sage: P.panyushev_orbits(element_constructor=tuple) [[(2,), (1,)], [(), (1, 2), (3,)]] sage: P = Poset( {} ) sage: P.panyushev_orbits() - [[set([])]] + [[set()]] """ # TODO: implement a generic function taking a set and # bijections on this set, and returning the orbits. @@ -1418,32 +1418,32 @@ def panyushev_orbit_iter(self, antichain, element_constructor=set, stop=True, ch sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) sage: list(P.panyushev_orbit_iter(set([1, 2]))) - [set([1, 2]), set([3]), set([])] + [{1, 2}, {3}, set()] sage: list(P.panyushev_orbit_iter([1, 2])) - [set([1, 2]), set([3]), set([])] + [{1, 2}, {3}, set()] sage: list(P.panyushev_orbit_iter([2, 1])) - [set([1, 2]), set([3]), set([])] + [{1, 2}, {3}, set()] sage: list(P.panyushev_orbit_iter(set([1, 2]), element_constructor=list)) [[1, 2], [3], []] sage: list(P.panyushev_orbit_iter(set([1, 2]), element_constructor=frozenset)) - [frozenset([1, 2]), frozenset([3]), frozenset([])] + [frozenset({1, 2}), frozenset({3}), frozenset()] sage: list(P.panyushev_orbit_iter(set([1, 2]), element_constructor=tuple)) [(1, 2), (3,), ()] sage: P = Poset( {} ) sage: list(P.panyushev_orbit_iter([])) - [set([])] + [set()] sage: P = Poset({ 1: [2, 3], 2: [4], 3: [4], 4: [] }) sage: Piter = P.panyushev_orbit_iter([2], stop=False) sage: Piter.next() - set([2]) + {2} sage: Piter.next() - set([3]) + {3} sage: Piter.next() - set([2]) + {2} sage: Piter.next() - set([3]) + {3} """ # TODO: implement a generic function taking a set and # bijections on this set, and returning an orbit of a given @@ -1507,34 +1507,34 @@ def rowmotion_orbit_iter(self, oideal, element_constructor=set, stop=True, check sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) sage: list(P.rowmotion_orbit_iter(set([1, 2]))) - [set([1, 2]), set([1, 2, 3]), set([])] + [{1, 2}, {1, 2, 3}, set()] sage: list(P.rowmotion_orbit_iter([1, 2])) - [set([1, 2]), set([1, 2, 3]), set([])] + [{1, 2}, {1, 2, 3}, set()] sage: list(P.rowmotion_orbit_iter([2, 1])) - [set([1, 2]), set([1, 2, 3]), set([])] + [{1, 2}, {1, 2, 3}, set()] sage: list(P.rowmotion_orbit_iter(set([1, 2]), element_constructor=list)) [[1, 2], [1, 2, 3], []] sage: list(P.rowmotion_orbit_iter(set([1, 2]), element_constructor=frozenset)) - [frozenset([1, 2]), frozenset([1, 2, 3]), frozenset([])] + [frozenset({1, 2}), frozenset({1, 2, 3}), frozenset()] sage: list(P.rowmotion_orbit_iter(set([1, 2]), element_constructor=tuple)) [(1, 2), (1, 2, 3), ()] sage: P = Poset( {} ) sage: list(P.rowmotion_orbit_iter([])) - [set([])] + [set()] sage: P = Poset({ 1: [2, 3], 2: [4], 3: [4], 4: [] }) sage: Piter = P.rowmotion_orbit_iter([1, 2, 3], stop=False) sage: Piter.next() - set([1, 2, 3]) + {1, 2, 3} sage: Piter.next() - set([1, 2, 3, 4]) + {1, 2, 3, 4} sage: Piter.next() - set([]) + set() sage: Piter.next() - set([1]) + {1} sage: Piter.next() - set([1, 2, 3]) + {1, 2, 3} sage: P = Poset({ 1: [4], 2: [4, 5], 3: [5] }) sage: list(P.rowmotion_orbit_iter([1, 2], element_constructor=list)) @@ -1618,15 +1618,15 @@ def toggling_orbit_iter(self, vs, oideal, element_constructor=set, stop=True, ch sage: P = Poset( ( [1,2,3], [ [1,3], [2,3] ] ) ) sage: list(P.toggling_orbit_iter([1, 3, 1], set([1, 2]))) - [set([1, 2])] + [{1, 2}] sage: list(P.toggling_orbit_iter([1, 2, 3], set([1, 2]))) - [set([1, 2]), set([]), set([1, 2, 3])] + [{1, 2}, set(), {1, 2, 3}] sage: list(P.toggling_orbit_iter([3, 2, 1], set([1, 2]))) - [set([1, 2]), set([1, 2, 3]), set([])] + [{1, 2}, {1, 2, 3}, set()] sage: list(P.toggling_orbit_iter([3, 2, 1], set([1, 2]), element_constructor=list)) [[1, 2], [1, 2, 3], []] sage: list(P.toggling_orbit_iter([3, 2, 1], set([1, 2]), element_constructor=frozenset)) - [frozenset([1, 2]), frozenset([1, 2, 3]), frozenset([])] + [frozenset({1, 2}), frozenset({1, 2, 3}), frozenset()] sage: list(P.toggling_orbit_iter([3, 2, 1], set([1, 2]), element_constructor=tuple)) [(1, 2), (1, 2, 3), ()] sage: list(P.toggling_orbit_iter([3, 2, 1], [2, 1], element_constructor=tuple)) @@ -1634,20 +1634,20 @@ def toggling_orbit_iter(self, vs, oideal, element_constructor=set, stop=True, ch sage: P = Poset( {} ) sage: list(P.toggling_orbit_iter([], [])) - [set([])] + [set()] sage: P = Poset({ 1: [2, 3], 2: [4], 3: [4], 4: [] }) sage: Piter = P.toggling_orbit_iter([1, 2, 4, 3], [1, 2, 3], stop=False) sage: Piter.next() - set([1, 2, 3]) + {1, 2, 3} sage: Piter.next() - set([1]) + {1} sage: Piter.next() - set([]) + set() sage: Piter.next() - set([1, 2, 3]) + {1, 2, 3} sage: Piter.next() - set([1]) + {1} """ # TODO: implement a generic function taking a set and # bijections on this set, and returning an orbit of a given diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index b2edc4fda39..3205eb21f46 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -399,7 +399,7 @@ def extra_super_categories(self): sage: C.extra_super_categories(); [Category of unital magmas] sage: C.axioms() - frozenset(['Unital']) + frozenset({'Unital'}) sage: Monoids().CartesianProducts().is_subcategory(Monoids()) True diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 6cd098592d6..33dbf36ad90 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -456,7 +456,10 @@ cdef class Map(Element): sage: from sage.categories.map import Map sage: f = Map(Hom(QQ, ZZ, Rings())) sage: f._extra_slots_test({"bla": 1}) - {'_codomain': Integer Ring, '_domain': Rational Field, 'bla': 1, '_repr_type_str': None} + {'_codomain': Integer Ring, + '_domain': Rational Field, + '_repr_type_str': None, + 'bla': 1} """ return self._extra_slots(_slots) diff --git a/src/sage/categories/monoids.py b/src/sage/categories/monoids.py index 428b75e36bd..f7e0f0ebcd2 100644 --- a/src/sage/categories/monoids.py +++ b/src/sage/categories/monoids.py @@ -47,7 +47,7 @@ class Monoids(CategoryWithAxiom): Category of objects] sage: Monoids().axioms() - frozenset(['Associative', 'Unital']) + frozenset({'Associative', 'Unital'}) sage: Semigroups().Unital() Category of monoids diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 8de9b87b28f..ee012f00680 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -507,7 +507,11 @@ cdef class SetMorphism(Morphism): sage: f = sage.categories.morphism.SetMorphism(Hom(ZZ,ZZ, Sets()), operator.__abs__) sage: f._extra_slots_test({"bla":1}) - {'_codomain': Integer Ring, '_domain': Integer Ring, '_function': , 'bla': 1, '_repr_type_str': None} + {'_codomain': Integer Ring, + '_domain': Integer Ring, + '_function': , + '_repr_type_str': None, + 'bla': 1} """ _slots['_function'] = self._function return Map._extra_slots(self, _slots) diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index d369df53586..391900fb992 100644 --- a/src/sage/categories/primer.py +++ b/src/sage/categories/primer.py @@ -734,7 +734,7 @@ class SubcategoryMethods: sage: Groups().super_categories() [Category of monoids, Category of inverse unital magmas] sage: Groups().axioms() - frozenset(['Inverse', 'Associative', 'Unital']) + frozenset({'Associative', 'Inverse', 'Unital'}) or constructing the intersection of two categories, or the smallest category containing them:: @@ -752,8 +752,8 @@ class SubcategoryMethods: be implemented can be found by introspection with:: sage: Groups().required_methods() - {'parent': {'required': ['__contains__'], 'optional': []}, - 'element': {'required': [], 'optional': ['_mul_']}} + {'element': {'optional': ['_mul_'], 'required': []}, + 'parent': {'optional': [], 'required': ['__contains__']}} Documentation about those methods can be obtained with:: @@ -956,8 +956,8 @@ class SubcategoryMethods: implemented can be found by introspection with:: sage: FiniteSemigroups().required_methods() - {'parent': {'required': ['__contains__'], 'optional': []}, - 'element': {'required': [], 'optional': ['_mul_']}} + {'element': {'optional': ['_mul_'], 'required': []}, + 'parent': {'optional': [], 'required': ['__contains__']}} ``product`` does not appear in the list because a default implementation is provided in term of the method ``_mul_`` on elements. Of course, at @@ -1157,7 +1157,7 @@ class naming and introspection. Sage currently works around the example, groups:: sage: Groups().axioms() - frozenset(['Inverse', 'Associative', 'Unital']) + frozenset({'Associative', 'Inverse', 'Unital'}) In fact, the category of groups can be *defined* by stating that a group is a magma, that is a set endowed with an internal binary diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index 4798fb47438..75204f75b13 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -2053,7 +2053,7 @@ def __init__(self, p, prec, extras=None): sage: F2 Completion[+Infinity] sage: F2.extras - {'type': 'MPFR', 'sci_not': False, 'rnd': 'RNDN'} + {'rnd': 'RNDN', 'sci_not': False, 'type': 'MPFR'} """ Functor.__init__(self, Rings(), Rings()) diff --git a/src/sage/categories/semigroups.py b/src/sage/categories/semigroups.py index 5cc1aa90cdc..ff991fd32e2 100644 --- a/src/sage/categories/semigroups.py +++ b/src/sage/categories/semigroups.py @@ -45,7 +45,7 @@ class Semigroups(CategoryWithAxiom): [Category of semigroups, Category of magmas, Category of sets, Category of sets with partial maps, Category of objects] sage: C.axioms() - frozenset(['Associative']) + frozenset({'Associative'}) sage: C.example() An example of a semigroup: the left zero semigroup diff --git a/src/sage/coding/code_bounds.py b/src/sage/coding/code_bounds.py index b3592fdeb2c..eda438ae910 100644 --- a/src/sage/coding/code_bounds.py +++ b/src/sage/coding/code_bounds.py @@ -575,6 +575,7 @@ def gv_bound_asymp(delta,q): 0.18872187554086... sage: f = lambda x: gv_bound_asymp(x,2) sage: plot(f,0,1) + Graphics object consisting of 1 graphics primitive """ return (1-entropy(delta,q)) @@ -589,6 +590,7 @@ def hamming_bound_asymp(delta,q): 0.456435556800... sage: f = lambda x: hamming_bound_asymp(x,2) sage: plot(f,0,1) + Graphics object consisting of 1 graphics primitive """ return (1-entropy(delta/2,q)) @@ -602,6 +604,7 @@ def singleton_bound_asymp(delta,q): 3/4 sage: f = lambda x: singleton_bound_asymp(x,2) sage: plot(f,0,1) + Graphics object consisting of 1 graphics primitive """ return (1-delta) diff --git a/src/sage/coding/source_coding/huffman.py b/src/sage/coding/source_coding/huffman.py index 823cd87d919..af3cead28e4 100644 --- a/src/sage/coding/source_coding/huffman.py +++ b/src/sage/coding/source_coding/huffman.py @@ -150,7 +150,19 @@ class Huffman(SageObject): following table of frequency:: sage: ft = frequency_table("There once was a french fry"); ft - {'a': 2, ' ': 5, 'c': 2, 'e': 4, 'f': 2, 'h': 2, 'o': 1, 'n': 2, 's': 1, 'r': 3, 'T': 1, 'w': 1, 'y': 1} + {' ': 5, + 'T': 1, + 'a': 2, + 'c': 2, + 'e': 4, + 'f': 2, + 'h': 2, + 'n': 2, + 'o': 1, + 'r': 3, + 's': 1, + 'w': 1, + 'y': 1} sage: h2 = Huffman(ft) Once ``h1`` has been trained, and hence possesses an encoding table, diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index dfdeba8361d..43d8bd75da3 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -2088,15 +2088,15 @@ def PathSubset(n,m): sage: from sage.combinat.cluster_algebra_quiver.cluster_seed import PathSubset sage: PathSubset(4,0) - set([1, 3, 5, 7]) + {1, 3, 5, 7} sage: PathSubset(4,1) - set([1, 3, 5, 6, 7]) + {1, 3, 5, 6, 7} sage: PathSubset(4,2) - set([1, 2, 3, 5, 6, 7]) + {1, 2, 3, 5, 6, 7} sage: PathSubset(4,3) - set([1, 2, 3, 4, 5, 6, 7]) + {1, 2, 3, 4, 5, 6, 7} sage: PathSubset(4,4) - set([0, 1, 2, 3, 4, 5, 6, 7]) + {0, 1, 2, 3, 4, 5, 6, 7} """ from sage.misc.misc import union from sage.functions.other import floor diff --git a/src/sage/combinat/crystals/alcove_path.py b/src/sage/combinat/crystals/alcove_path.py index bc811702cdd..05e8ad3ca5d 100644 --- a/src/sage/combinat/crystals/alcove_path.py +++ b/src/sage/combinat/crystals/alcove_path.py @@ -815,7 +815,7 @@ def _folding_data(self, i): sage: C=crystals.AlcovePaths(['A',2],[1,1]) sage: x=C( () ).f(1) sage: x._folding_data(2) - {(alpha[1] + alpha[2], 1): 1, 'infinity': 1, (alpha[2], 0): 1} + {(alpha[2], 0): 1, (alpha[1] + alpha[2], 1): 1, 'infinity': 1} """ Parent = self.parent() diff --git a/src/sage/combinat/crystals/crystals.py b/src/sage/combinat/crystals/crystals.py index 5a89905371b..1a079c863dd 100644 --- a/src/sage/combinat/crystals/crystals.py +++ b/src/sage/combinat/crystals/crystals.py @@ -76,6 +76,7 @@ One can get (currently) crude plotting via:: sage: Tab.plot() + Graphics object consisting of 52 graphics primitives If dot2tex is installed, one can obtain nice latex pictures via:: diff --git a/src/sage/combinat/crystals/kirillov_reshetikhin.py b/src/sage/combinat/crystals/kirillov_reshetikhin.py index 3bb19502360..b2a30fa9687 100644 --- a/src/sage/combinat/crystals/kirillov_reshetikhin.py +++ b/src/sage/combinat/crystals/kirillov_reshetikhin.py @@ -1262,10 +1262,10 @@ def highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1) sage: K.highest_weight_dict() - {[[(5, -2, -6), (-6, 2)]]: ((0, 0, 0, 0, 0, 1, -2), 1), + {[[(2, -1), (1,)]]: ((-2, 0, 1, 0, 0, 0, 0), 1), [[(3, -1, -6), (1,)]]: ((-1, 0, 0, 1, 0, 0, -1), 1), [[(6, -2), (-6, 2)]]: ((0, 0, 0, 0, 0, 0, 0), 1), - [[(2, -1), (1,)]]: ((-2, 0, 1, 0, 0, 0, 0), 1), + [[(5, -2, -6), (-6, 2)]]: ((0, 0, 0, 0, 0, 1, -2), 1), []: ((0, 0, 0, 0, 0, 0, 0), 0)} """ hw = [x for x in self.hw_auxiliary() if x.epsilon(1) == 0] @@ -1283,11 +1283,11 @@ def highest_weight_dict_inv(self): sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1) sage: K.highest_weight_dict_inv() - {((0, 0, 0, 0, 0, 0, 0), 0): [], + {((-2, 0, 1, 0, 0, 0, 0), 1): [[(2, -1), (1,)]], ((-1, -1, 0, 0, 0, 1, 0), 1): [[(5, -3), (-1, 3)]], - ((0, 0, 0, 0, 0, 0, 0), 1): [[(1, -3), (-1, 3)]], ((0, -2, 0, 1, 0, 0, 0), 1): [[(-1,), (-1, 3)]], - ((-2, 0, 1, 0, 0, 0, 0), 1): [[(2, -1), (1,)]]} + ((0, 0, 0, 0, 0, 0, 0), 0): [], + ((0, 0, 0, 0, 0, 0, 0), 1): [[(1, -3), (-1, 3)]]} """ hw = [x for x in self.hw_auxiliary() if x.epsilon(6) == 0] dic = dict( ( tuple( [self.affine_weight(x), len(x)] ), x ) for x in hw ) @@ -1322,10 +1322,10 @@ def promotion_on_highest_weight_vectors(self): sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1) sage: dic = K.promotion_on_highest_weight_vectors() sage: dic - {[[(5, -2, -6), (-6, 2)]]: [[(2, -1), (1,)]], + {[[(2, -1), (1,)]]: [[(-1,), (-1, 3)]], [[(3, -1, -6), (1,)]]: [[(5, -3), (-1, 3)]], [[(6, -2), (-6, 2)]]: [], - [[(2, -1), (1,)]]: [[(-1,), (-1, 3)]], + [[(5, -2, -6), (-6, 2)]]: [[(2, -1), (1,)]], []: [[(1, -3), (-1, 3)]]} """ dic = self.highest_weight_dict() @@ -1449,10 +1449,14 @@ def ambient_dict_pm_diagrams(self): {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]} sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2) sage: K.ambient_dict_pm_diagrams() - {[2, 2]: [[0, 0], [0, 0], [2]], []: [[1, 1], [0, 0], [0]], [2]: [[0, 0], [1, 1], [0]]} + {[]: [[1, 1], [0, 0], [0]], + [2]: [[0, 0], [1, 1], [0]], + [2, 2]: [[0, 0], [0, 0], [2]]} sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,3) sage: K.ambient_dict_pm_diagrams() - {[3, 3]: [[0, 0], [0, 0], [3]], [3, 1]: [[0, 0], [1, 1], [1]], [1, 1]: [[1, 1], [0, 0], [1]]} + {[1, 1]: [[1, 1], [0, 0], [1]], + [3, 1]: [[0, 0], [1, 1], [1]], + [3, 3]: [[0, 0], [0, 0], [3]]} """ list = [] s = self.s() @@ -1474,7 +1478,7 @@ def ambient_highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2) sage: K.ambient_highest_weight_dict() - {[]: [[2], [-2]], [2, 2]: [[2, 2], [3, 3]], [2]: [[1, 2], [2, -1]]} + {[]: [[2], [-2]], [2]: [[1, 2], [2, -1]], [2, 2]: [[2, 2], [3, 3]]} """ A = self.ambient_dict_pm_diagrams() ambient = self.ambient_crystal() @@ -1490,7 +1494,7 @@ def highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2) sage: K.highest_weight_dict() - {[2, 2]: [[1, 1], [2, 2]], []: [], [2]: [[1, 1]]} + {[]: [], [2]: [[1, 1]], [2, 2]: [[1, 1], [2, 2]]} """ return dict( (x.lift().to_tableau().shape(),x) for x in self.module_generators ) @@ -1703,7 +1707,9 @@ def ambient_dict_pm_diagrams(self): {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]} sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 2, 2) sage: K.ambient_dict_pm_diagrams() - {[2, 2]: [[0, 0], [0, 0], [2]], []: [[1, 1], [0, 0], [0]], [2]: [[0, 0], [1, 1], [0]]} + {[]: [[1, 1], [0, 0], [0]], + [2]: [[0, 0], [1, 1], [0]], + [2, 2]: [[0, 0], [0, 0], [2]]} """ list = [] s = self.s() @@ -1959,7 +1965,12 @@ def highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['A',6,2], 2,2) sage: K.highest_weight_dict() - {[4, 2]: [[1, 1], [2]], [2, 2]: [[1], [2]], []: [], [4]: [[1, 1]], [4, 4]: [[1, 1], [2, 2]], [2]: [[1]]} + {[]: [], + [2]: [[1]], + [2, 2]: [[1], [2]], + [4]: [[1, 1]], + [4, 2]: [[1, 1], [2]], + [4, 4]: [[1, 1], [2, 2]]} """ return dict( (Partition([2*i for i in x.lift().to_tableau().shape()]),x) for x in self.module_generators ) @@ -1973,8 +1984,12 @@ def ambient_highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['A',6,2], 2,2) sage: K.ambient_highest_weight_dict() - {[4, 2]: [[1, 1, 1, 1], [2, 2]], [2, 2]: [[1, 1], [2, 2]], []: [], [4]: [[1, 1, 1, 1]], [4, 4]: [[1, 1, 1, 1], [2, 2, 2, 2]], - [2]: [[1, 1]]} + {[]: [], + [2]: [[1, 1]], + [2, 2]: [[1, 1], [2, 2]], + [4]: [[1, 1, 1, 1]], + [4, 2]: [[1, 1, 1, 1], [2, 2]], + [4, 4]: [[1, 1, 1, 1], [2, 2, 2, 2]]} """ return dict( (x.lift().to_tableau().shape(),x) for x in self.ambient_crystal().module_generators ) @@ -2227,7 +2242,7 @@ def highest_weight_dict(self): {(2,): [[1]], (2, 2, 2): [[1], [2], [3]]} sage: K = crystals.KirillovReshetikhin(['B',3,1],3,3) sage: K.highest_weight_dict() - {(3, 3, 3): [+++, [[1], [2], [3]]], (3, 1, 1): [+++, [[1]]]} + {(3, 1, 1): [+++, [[1]]], (3, 3, 3): [+++, [[1], [2], [3]]]} """ return dict( (tuple([2*i[1] for i in x.classical_weight()]),x) for x in self.module_generators ) @@ -2245,8 +2260,10 @@ def ambient_highest_weight_dict(self): sage: K = crystals.KirillovReshetikhin(['B',3,1],3,3) sage: K.ambient_highest_weight_dict() - {(3, 3, 3): [[1, 1, 1], [2, 2, 2], [3, 3, 3]], (3, 1, 1): [[1, 1, 1], [2], [3]], - (3, 2, 2): [[1, 1, 1], [2, 2], [3, 3]], (3,): [[1, 1, 1]]} + {(3,): [[1, 1, 1]], + (3, 1, 1): [[1, 1, 1], [2], [3]], + (3, 2, 2): [[1, 1, 1], [2, 2], [3, 3]], + (3, 3, 3): [[1, 1, 1], [2, 2, 2], [3, 3, 3]]} """ return dict( (tuple([i[1] for i in x.classical_weight()]),x) for x in self.ambient_crystal().module_generators ) diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index 6cee7e8b7e7..cd862b678f9 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -474,7 +474,13 @@ def latex_options(self): sage: D = DyckWord([1,0,1,0,1,0]) sage: D.latex_options() - {'valleys': False, 'peaks': False, 'tikz_scale': 1, 'color': 'black', 'diagonal': False, 'bounce path': False, 'line width': 2} + {'bounce path': False, + 'color': 'black', + 'diagonal': False, + 'line width': 2, + 'peaks': False, + 'tikz_scale': 1, + 'valleys': False} """ d = self._latex_options.copy() if "tikz_scale" not in d: diff --git a/src/sage/combinat/e_one_star.py b/src/sage/combinat/e_one_star.py index 9f28e77ad72..2e6f84601c7 100644 --- a/src/sage/combinat/e_one_star.py +++ b/src/sage/combinat/e_one_star.py @@ -160,7 +160,9 @@ sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) sage: E(P,5).plot() + Graphics object consisting of 21 graphics primitives sage: F(P,3).plot() + Graphics object consisting of 34 graphics primitives Everything works in any dimension (except for the plotting features which only work in dimension two or three):: @@ -495,6 +497,7 @@ def _plot(self, projmat, face_contour, opacity): sage: f = Face((0,0), 2) sage: f._plot(None, None, 1) + Graphics object consisting of 1 graphics primitive """ v = self.vector() t = self.type() @@ -1093,6 +1096,7 @@ def plot(self, projmat=None, opacity=0.75): sage: from sage.combinat.e_one_star import E1Star, Face, Patch sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: P.plot() + Graphics object consisting of 3 graphics primitives :: @@ -1101,6 +1105,7 @@ def plot(self, projmat=None, opacity=0.75): sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: P = E(P, 5) sage: P.plot() + Graphics object consisting of 57 graphics primitives Plot with a different projection matrix:: @@ -1110,6 +1115,7 @@ def plot(self, projmat=None, opacity=0.75): sage: M = matrix(2, 3, [1,0,-1,0.3,1,-3]) sage: P = E(P, 3) sage: P.plot(projmat=M) + Graphics object consisting of 17 graphics primitives Plot patches made of unit segments:: @@ -1117,7 +1123,9 @@ def plot(self, projmat=None, opacity=0.75): sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) sage: E(P,5).plot() + Graphics object consisting of 21 graphics primitives sage: F(P,3).plot() + Graphics object consisting of 34 graphics primitives """ if self.dimension() == 2: G = Graphics() diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 4f7bf2c3ac3..44a021d472f 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -8312,6 +8312,7 @@ def plot(self): TESTS:: sage: FiniteStateMachine([('A', 'A', 0)]).plot() + Graphics object consisting of 3 graphics primitives """ return self.graph(edge_labels='words_in_out').plot() @@ -11304,7 +11305,7 @@ def __deepcopy__(self, memo): sage: TC2._visited_states_.add(1) sage: TC3 = deepcopy(TC2) # indirect doctest sage: TC3._visited_states_ - set([1]) + {1} """ new = super(_FSMTapeCacheDetectEpsilon_, self).__deepcopy__(memo) new._visited_states_ = copy(self._visited_states_) diff --git a/src/sage/combinat/integer_vectors_mod_permgroup.py b/src/sage/combinat/integer_vectors_mod_permgroup.py index 7821a3da5c2..3be82f57cd1 100644 --- a/src/sage/combinat/integer_vectors_mod_permgroup.py +++ b/src/sage/combinat/integer_vectors_mod_permgroup.py @@ -148,7 +148,7 @@ class IntegerVectorsModPermutationGroup(UniqueRepresentation): sage: sorted(I.orbit([5,1,0])) [[0, 5, 1], [1, 0, 5], [5, 1, 0]] sage: I.orbit([2,2,2]) - set([[2, 2, 2]]) + {[2, 2, 2]} TESTS: @@ -496,7 +496,7 @@ def orbit(self, v): sage: sorted(I.orbit([2,0,2,0])) [[0, 2, 0, 2], [2, 0, 2, 0]] sage: I.orbit([1,1,1,1]) - set([[1, 1, 1, 1]]) + {[1, 1, 1, 1]} """ assert isinstance(v, (list, ClonableIntArray)), '%s shoud be a Python list or an element of %s'%(v, self) try: @@ -925,7 +925,7 @@ def orbit(self, v): sage: I = IntegerVectorsModPermutationGroup(PermutationGroup([[(1,2,3,4)]]),4) sage: I.orbit([1,1,1,1]) - set([[1, 1, 1, 1]]) + {[1, 1, 1, 1]} sage: sorted(I.orbit([3,0,0,1])) [[0, 0, 1, 3], [0, 1, 3, 0], [1, 3, 0, 0], [3, 0, 0, 1]] """ diff --git a/src/sage/combinat/matrices/latin.py b/src/sage/combinat/matrices/latin.py index 4f015b1039d..27cea4a3228 100644 --- a/src/sage/combinat/matrices/latin.py +++ b/src/sage/combinat/matrices/latin.py @@ -585,7 +585,30 @@ def filled_cells_map(self): sage: (a, b, c, G) = alternating_group_bitrade_generators(1) sage: (T1, T2) = bitrade_from_group(a, b, c, G) sage: T1.filled_cells_map() - {1: (0, 0), 2: (0, 2), 3: (0, 3), 4: (1, 1), 5: (1, 2), 6: (1, 3), 7: (2, 0), 8: (2, 1), 9: (2, 2), 10: (3, 0), 11: (3, 1), 12: (3, 3), (2, 1): 8, (1, 3): 6, (0, 3): 3, (1, 2): 5, (3, 3): 12, (3, 0): 10, (2, 2): 9, (1, 1): 4, (0, 0): 1, (3, 1): 11, (2, 0): 7, (0, 2): 2} + {1: (0, 0), + 2: (0, 2), + 3: (0, 3), + 4: (1, 1), + 5: (1, 2), + 6: (1, 3), + 7: (2, 0), + 8: (2, 1), + 9: (2, 2), + 10: (3, 0), + 11: (3, 1), + 12: (3, 3), + (0, 0): 1, + (0, 2): 2, + (0, 3): 3, + (1, 1): 4, + (1, 2): 5, + (1, 3): 6, + (2, 0): 7, + (2, 1): 8, + (2, 2): 9, + (3, 0): 10, + (3, 1): 11, + (3, 3): 12} """ cells_map = {} @@ -1019,7 +1042,134 @@ def disjoint_mate_dlxcpp_rows_and_map(self, allow_subtrade): sage: from sage.combinat.matrices.latin import * sage: B = back_circulant(4) sage: B.disjoint_mate_dlxcpp_rows_and_map(allow_subtrade = True) - ([[0, 16, 32], [1, 17, 32], [2, 18, 32], [3, 19, 32], [4, 16, 33], [5, 17, 33], [6, 18, 33], [7, 19, 33], [8, 16, 34], [9, 17, 34], [10, 18, 34], [11, 19, 34], [12, 16, 35], [13, 17, 35], [14, 18, 35], [15, 19, 35], [0, 20, 36], [1, 21, 36], [2, 22, 36], [3, 23, 36], [4, 20, 37], [5, 21, 37], [6, 22, 37], [7, 23, 37], [8, 20, 38], [9, 21, 38], [10, 22, 38], [11, 23, 38], [12, 20, 39], [13, 21, 39], [14, 22, 39], [15, 23, 39], [0, 24, 40], [1, 25, 40], [2, 26, 40], [3, 27, 40], [4, 24, 41], [5, 25, 41], [6, 26, 41], [7, 27, 41], [8, 24, 42], [9, 25, 42], [10, 26, 42], [11, 27, 42], [12, 24, 43], [13, 25, 43], [14, 26, 43], [15, 27, 43], [0, 28, 44], [1, 29, 44], [2, 30, 44], [3, 31, 44], [4, 28, 45], [5, 29, 45], [6, 30, 45], [7, 31, 45], [8, 28, 46], [9, 29, 46], [10, 30, 46], [11, 31, 46], [12, 28, 47], [13, 29, 47], [14, 30, 47], [15, 31, 47]], {(9, 29, 46): (3, 2, 1), (13, 17, 35): (0, 3, 1), (7, 19, 33): (0, 1, 3), (14, 26, 43): (2, 3, 2), (0, 28, 44): (3, 0, 0), (5, 25, 41): (2, 1, 1), (11, 31, 46): (3, 2, 3), (14, 18, 35): (0, 3, 2), (11, 23, 38): (1, 2, 3), (5, 29, 45): (3, 1, 1), (13, 21, 39): (1, 3, 1), (1, 29, 44): (3, 0, 1), (0, 20, 36): (1, 0, 0), (12, 24, 43): (2, 3, 0), (8, 28, 46): (3, 2, 0), (12, 20, 39): (1, 3, 0), (11, 27, 42): (2, 2, 3), (6, 22, 37): (1, 1, 2), (1, 17, 32): (0, 0, 1), (10, 18, 34): (0, 2, 2), (12, 28, 47): (3, 3, 0), (1, 25, 40): (2, 0, 1), (10, 22, 38): (1, 2, 2), (5, 17, 33): (0, 1, 1), (3, 23, 36): (1, 0, 3), (6, 26, 41): (2, 1, 2), (9, 25, 42): (2, 2, 1), (7, 31, 45): (3, 1, 3), (15, 27, 43): (2, 3, 3), (3, 31, 44): (3, 0, 3), (8, 20, 38): (1, 2, 0), (2, 22, 36): (1, 0, 2), (3, 19, 32): (0, 0, 3), (9, 17, 34): (0, 2, 1), (15, 31, 47): (3, 3, 3), (8, 16, 34): (0, 2, 0), (14, 22, 39): (1, 3, 2), (4, 16, 33): (0, 1, 0), (14, 30, 47): (3, 3, 2), (2, 30, 44): (3, 0, 2), (4, 20, 37): (1, 1, 0), (6, 30, 45): (3, 1, 2), (12, 16, 35): (0, 3, 0), (15, 19, 35): (0, 3, 3), (5, 21, 37): (1, 1, 1), (4, 24, 41): (2, 1, 0), (13, 25, 43): (2, 3, 1), (0, 16, 32): (0, 0, 0), (15, 23, 39): (1, 3, 3), (7, 23, 37): (1, 1, 3), (6, 18, 33): (0, 1, 2), (10, 30, 46): (3, 2, 2), (13, 29, 47): (3, 3, 1), (11, 19, 34): (0, 2, 3), (1, 21, 36): (1, 0, 1), (7, 27, 41): (2, 1, 3), (0, 24, 40): (2, 0, 0), (10, 26, 42): (2, 2, 2), (3, 27, 40): (2, 0, 3), (2, 26, 40): (2, 0, 2), (9, 21, 38): (1, 2, 1), (8, 24, 42): (2, 2, 0), (4, 28, 45): (3, 1, 0), (2, 18, 32): (0, 0, 2)}) + ([[0, 16, 32], + [1, 17, 32], + [2, 18, 32], + [3, 19, 32], + [4, 16, 33], + [5, 17, 33], + [6, 18, 33], + [7, 19, 33], + [8, 16, 34], + [9, 17, 34], + [10, 18, 34], + [11, 19, 34], + [12, 16, 35], + [13, 17, 35], + [14, 18, 35], + [15, 19, 35], + [0, 20, 36], + [1, 21, 36], + [2, 22, 36], + [3, 23, 36], + [4, 20, 37], + [5, 21, 37], + [6, 22, 37], + [7, 23, 37], + [8, 20, 38], + [9, 21, 38], + [10, 22, 38], + [11, 23, 38], + [12, 20, 39], + [13, 21, 39], + [14, 22, 39], + [15, 23, 39], + [0, 24, 40], + [1, 25, 40], + [2, 26, 40], + [3, 27, 40], + [4, 24, 41], + [5, 25, 41], + [6, 26, 41], + [7, 27, 41], + [8, 24, 42], + [9, 25, 42], + [10, 26, 42], + [11, 27, 42], + [12, 24, 43], + [13, 25, 43], + [14, 26, 43], + [15, 27, 43], + [0, 28, 44], + [1, 29, 44], + [2, 30, 44], + [3, 31, 44], + [4, 28, 45], + [5, 29, 45], + [6, 30, 45], + [7, 31, 45], + [8, 28, 46], + [9, 29, 46], + [10, 30, 46], + [11, 31, 46], + [12, 28, 47], + [13, 29, 47], + [14, 30, 47], + [15, 31, 47]], + {(0, 16, 32): (0, 0, 0), + (0, 20, 36): (1, 0, 0), + (0, 24, 40): (2, 0, 0), + (0, 28, 44): (3, 0, 0), + (1, 17, 32): (0, 0, 1), + (1, 21, 36): (1, 0, 1), + (1, 25, 40): (2, 0, 1), + (1, 29, 44): (3, 0, 1), + (2, 18, 32): (0, 0, 2), + (2, 22, 36): (1, 0, 2), + (2, 26, 40): (2, 0, 2), + (2, 30, 44): (3, 0, 2), + (3, 19, 32): (0, 0, 3), + (3, 23, 36): (1, 0, 3), + (3, 27, 40): (2, 0, 3), + (3, 31, 44): (3, 0, 3), + (4, 16, 33): (0, 1, 0), + (4, 20, 37): (1, 1, 0), + (4, 24, 41): (2, 1, 0), + (4, 28, 45): (3, 1, 0), + (5, 17, 33): (0, 1, 1), + (5, 21, 37): (1, 1, 1), + (5, 25, 41): (2, 1, 1), + (5, 29, 45): (3, 1, 1), + (6, 18, 33): (0, 1, 2), + (6, 22, 37): (1, 1, 2), + (6, 26, 41): (2, 1, 2), + (6, 30, 45): (3, 1, 2), + (7, 19, 33): (0, 1, 3), + (7, 23, 37): (1, 1, 3), + (7, 27, 41): (2, 1, 3), + (7, 31, 45): (3, 1, 3), + (8, 16, 34): (0, 2, 0), + (8, 20, 38): (1, 2, 0), + (8, 24, 42): (2, 2, 0), + (8, 28, 46): (3, 2, 0), + (9, 17, 34): (0, 2, 1), + (9, 21, 38): (1, 2, 1), + (9, 25, 42): (2, 2, 1), + (9, 29, 46): (3, 2, 1), + (10, 18, 34): (0, 2, 2), + (10, 22, 38): (1, 2, 2), + (10, 26, 42): (2, 2, 2), + (10, 30, 46): (3, 2, 2), + (11, 19, 34): (0, 2, 3), + (11, 23, 38): (1, 2, 3), + (11, 27, 42): (2, 2, 3), + (11, 31, 46): (3, 2, 3), + (12, 16, 35): (0, 3, 0), + (12, 20, 39): (1, 3, 0), + (12, 24, 43): (2, 3, 0), + (12, 28, 47): (3, 3, 0), + (13, 17, 35): (0, 3, 1), + (13, 21, 39): (1, 3, 1), + (13, 25, 43): (2, 3, 1), + (13, 29, 47): (3, 3, 1), + (14, 18, 35): (0, 3, 2), + (14, 22, 39): (1, 3, 2), + (14, 26, 43): (2, 3, 2), + (14, 30, 47): (3, 3, 2), + (15, 19, 35): (0, 3, 3), + (15, 23, 39): (1, 3, 3), + (15, 27, 43): (2, 3, 3), + (15, 31, 47): (3, 3, 3)}) """ assert self.nrows() == self.ncols() @@ -1211,7 +1361,48 @@ def tau123(T1, T2): [ 0 2 6 -1 -1 -1 -1] sage: (cells_map, t1, t2, t3) = tau123(T1, T2) sage: cells_map - {1: (0, 0), 2: (0, 1), 3: (0, 2), 4: (1, 0), 5: (1, 1), 6: (1, 2), 7: (2, 0), 8: (2, 1), 9: (2, 2), 10: (3, 0), 11: (3, 1), 12: (3, 2), 13: (4, 0), (2, 1): 8, 15: (4, 2), 16: (5, 0), 17: (5, 1), 18: (5, 2), 19: (6, 0), 20: (6, 1), 21: (6, 2), (5, 1): 17, (4, 0): 13, (1, 2): 6, (3, 0): 10, (5, 0): 16, (2, 2): 9, (4, 1): 14, (1, 1): 5, (3, 2): 12, (0, 0): 1, (6, 0): 19, 14: (4, 1), (4, 2): 15, (1, 0): 4, (0, 1): 2, (6, 1): 20, (3, 1): 11, (2, 0): 7, (6, 2): 21, (5, 2): 18, (0, 2): 3} + {1: (0, 0), + 2: (0, 1), + 3: (0, 2), + 4: (1, 0), + 5: (1, 1), + 6: (1, 2), + 7: (2, 0), + 8: (2, 1), + 9: (2, 2), + 10: (3, 0), + 11: (3, 1), + 12: (3, 2), + 13: (4, 0), + 14: (4, 1), + 15: (4, 2), + 16: (5, 0), + 17: (5, 1), + 18: (5, 2), + 19: (6, 0), + 20: (6, 1), + 21: (6, 2), + (0, 0): 1, + (0, 1): 2, + (0, 2): 3, + (1, 0): 4, + (1, 1): 5, + (1, 2): 6, + (2, 0): 7, + (2, 1): 8, + (2, 2): 9, + (3, 0): 10, + (3, 1): 11, + (3, 2): 12, + (4, 0): 13, + (4, 1): 14, + (4, 2): 15, + (5, 0): 16, + (5, 1): 17, + (5, 2): 18, + (6, 0): 19, + (6, 1): 20, + (6, 2): 21} sage: cells_map_as_square(cells_map, max(T1.nrows(), T1.ncols())) [ 1 2 3 -1 -1 -1 -1] [ 4 5 6 -1 -1 -1 -1] @@ -2558,7 +2749,22 @@ def dlxcpp_rows_and_map(P): sage: from sage.combinat.matrices.latin import * sage: dlxcpp_rows_and_map(LatinSquare(2)) - ([[0, 4, 8], [1, 5, 8], [2, 4, 9], [3, 5, 9], [0, 6, 10], [1, 7, 10], [2, 6, 11], [3, 7, 11]], {(2, 4, 9): (0, 1, 0), (1, 5, 8): (0, 0, 1), (1, 7, 10): (1, 0, 1), (0, 6, 10): (1, 0, 0), (3, 7, 11): (1, 1, 1), (2, 6, 11): (1, 1, 0), (0, 4, 8): (0, 0, 0), (3, 5, 9): (0, 1, 1)}) + ([[0, 4, 8], + [1, 5, 8], + [2, 4, 9], + [3, 5, 9], + [0, 6, 10], + [1, 7, 10], + [2, 6, 11], + [3, 7, 11]], + {(0, 4, 8): (0, 0, 0), + (0, 6, 10): (1, 0, 0), + (1, 5, 8): (0, 0, 1), + (1, 7, 10): (1, 0, 1), + (2, 4, 9): (0, 1, 0), + (2, 6, 11): (1, 1, 0), + (3, 5, 9): (0, 1, 1), + (3, 7, 11): (1, 1, 1)}) """ assert P.nrows() == P.ncols() diff --git a/src/sage/combinat/ncsf_qsym/tutorial.py b/src/sage/combinat/ncsf_qsym/tutorial.py index cb5ac6108d7..1c987793d64 100644 --- a/src/sage/combinat/ncsf_qsym/tutorial.py +++ b/src/sage/combinat/ncsf_qsym/tutorial.py @@ -111,7 +111,7 @@ [M[1, 2], M[3, 3], M[6]] sage: z.monomial_coefficients() - {[3, 3]: 2, [1, 2]: 3, [6]: 1} + {[1, 2]: 3, [3, 3]: 2, [6]: 1} As with the symmetric functions package, the quasisymmetric function ``1`` has several instantiations. However, the most obvious way to write ``1`` diff --git a/src/sage/combinat/posets/hasse_diagram.py b/src/sage/combinat/posets/hasse_diagram.py index 085abbae54e..57552974d11 100644 --- a/src/sage/combinat/posets/hasse_diagram.py +++ b/src/sage/combinat/posets/hasse_diagram.py @@ -124,6 +124,7 @@ def plot(self, label_elements=True, element_labels=None, sage: P = Posets.SymmetricGroupBruhatIntervalPoset([1,2,3,4], [3,4,1,2]) sage: P._hasse_diagram.plot() + Graphics object consisting of 42 graphics primitives """ # Set element_labels to default to the vertex set. if element_labels is None: diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 3a328f372e9..3784af3a65a 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -782,7 +782,7 @@ def __init__(self, hasse_diagram, elements, category, facade, key): - a dictionary mapping back elements to vertices:: sage: P._element_to_vertex_dict - {'a': 0, 'c': 2, 'b': 1, 'd': 3} + {'a': 0, 'b': 1, 'c': 2, 'd': 3} - and a boolean stating whether the poset is a facade poset:: @@ -1369,16 +1369,20 @@ def plot(self, label_elements=True, element_labels=None, sage: D = Poset({ 1:[2,3], 2:[4], 3:[4,5] }) sage: D.plot(label_elements=False) + Graphics object consisting of 6 graphics primitives sage: D.plot() + Graphics object consisting of 11 graphics primitives sage: type(D.plot()) sage: elm_labs = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e'} sage: D.plot(element_labels=elm_labs) + Graphics object consisting of 11 graphics primitives Plot of the empy poset:: sage: P = Poset({}) sage: P.plot() + Graphics object consisting of 0 graphics primitives Plot of a ranked poset:: @@ -1386,6 +1390,7 @@ def plot(self, label_elements=True, element_labels=None, sage: P.is_ranked() True sage: P.plot() + Graphics object consisting of 12 graphics primitives TESTS: @@ -1449,6 +1454,7 @@ def show(self, label_elements=True, element_labels=None, sage: D = Poset({ 0:[1,2], 1:[3], 2:[3,4] }) sage: D.plot(label_elements=False) + Graphics object consisting of 6 graphics primitives sage: D.show() sage: elm_labs = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e'} sage: D.show(element_labels=elm_labs) @@ -2087,7 +2093,11 @@ def is_EL_labelling(self, f, return_raising_chains=False): sage: P.is_EL_labelling(label) True sage: P.is_EL_labelling(label,return_raising_chains=True) - {((0, 0), (0, 1)): [1], ((0, 0), (1, 0)): [0], ((0, 1), (1, 1)): [0], ((1, 0), (1, 1)): [1], ((0, 0), (1, 1)): [0, 1]} + {((0, 0), (0, 1)): [1], + ((0, 0), (1, 0)): [0], + ((0, 0), (1, 1)): [0, 1], + ((0, 1), (1, 1)): [0], + ((1, 0), (1, 1)): [1]} REFERENCES: @@ -2674,7 +2684,7 @@ def antichains(self, element_constructor = __builtin__.list): ``element_constructor`` option:: sage: list(Posets.ChainPoset(3).antichains(element_constructor = set)) - [set([]), set([0]), set([1]), set([2])] + [set(), {0}, {1}, {2}] .. note:: Internally, this uses :class:`sage.combinat.subsets_pairwise.PairwiseCompatibleSubsets` @@ -4137,10 +4147,60 @@ def frank_network(self): sage: G.edges() [((-1, 0), (0, -13), None), ((-1, 0), (0, 12), None), ((-1, 0), (0, 14), None), ((-1, 0), (0, 16), None), ((0, -13), (1, -13), None), ((0, -13), (1, 12), None), ((0, -13), (1, 14), None), ((0, -13), (1, 16), None), ((0, 12), (1, 12), None), ((0, 14), (1, 12), None), ((0, 14), (1, 14), None), ((0, 16), (1, 12), None), ((0, 16), (1, 16), None), ((1, -13), (2, 0), None), ((1, 12), (2, 0), None), ((1, 14), (2, 0), None), ((1, 16), (2, 0), None)] sage: e - {((-1, 0), (0, 14)): 0, ((0, -13), (1, 12)): 0, ((-1, 0), (0, -13)): 0, ((0, 16), (1, 12)): 0, ((1, 16), (2, 0)): 0, ((0, -13), (1, 16)): 0, ((1, -13), (2, 0)): 0, ((0, -13), (1, -13)): 1, ((0, -13), (1, 14)): 0, ((-1, 0), (0, 16)): 0, ((0, 12), (1, 12)): 1, ((-1, 0), (0, 12)): 0, ((1, 14), (2, 0)): 0, ((1, 12), (2, 0)): 0, ((0, 14), (1, 12)): 0, ((0, 16), (1, 16)): 1, ((0, 14), (1, 14)): 1} + {((-1, 0), (0, -13)): 0, + ((-1, 0), (0, 12)): 0, + ((-1, 0), (0, 14)): 0, + ((-1, 0), (0, 16)): 0, + ((0, -13), (1, -13)): 1, + ((0, -13), (1, 12)): 0, + ((0, -13), (1, 14)): 0, + ((0, -13), (1, 16)): 0, + ((0, 12), (1, 12)): 1, + ((0, 14), (1, 12)): 0, + ((0, 14), (1, 14)): 1, + ((0, 16), (1, 12)): 0, + ((0, 16), (1, 16)): 1, + ((1, -13), (2, 0)): 0, + ((1, 12), (2, 0)): 0, + ((1, 14), (2, 0)): 0, + ((1, 16), (2, 0)): 0} sage: qs = [[1,2,3,4,5,6,7,8,9],[[1,3],[3,4],[5,7],[1,9],[2,3]]] sage: Poset(qs).frank_network() - (Digraph on 20 vertices, {((0, 3), (1, 1)): 0, ((1, 8), (2, 0)): 0, ((-1, 0), (0, 3)): 0, ((0, 6), (1, 6)): 1, ((1, 9), (2, 0)): 0, ((0, 9), (1, 9)): 1, ((1, 7), (2, 0)): 0, ((0, 3), (1, 2)): 0, ((0, 3), (1, 3)): 1, ((0, 4), (1, 4)): 1, ((1, 2), (2, 0)): 0, ((0, 4), (1, 3)): 0, ((-1, 0), (0, 5)): 0, ((-1, 0), (0, 8)): 0, ((1, 3), (2, 0)): 0, ((0, 1), (1, 1)): 1, ((1, 1), (2, 0)): 0, ((0, 8), (1, 8)): 1, ((0, 4), (1, 1)): 0, ((1, 4), (2, 0)): 0, ((0, 2), (1, 2)): 1, ((-1, 0), (0, 1)): 0, ((0, 7), (1, 7)): 1, ((-1, 0), (0, 2)): 0, ((0, 7), (1, 5)): 0, ((0, 9), (1, 1)): 0, ((0, 5), (1, 5)): 1, ((-1, 0), (0, 9)): 0, ((-1, 0), (0, 7)): 0, ((0, 4), (1, 2)): 0, ((-1, 0), (0, 6)): 0, ((-1, 0), (0, 4)): 0, ((1, 6), (2, 0)): 0, ((1, 5), (2, 0)): 0}) + (Digraph on 20 vertices, + {((-1, 0), (0, 1)): 0, + ((-1, 0), (0, 2)): 0, + ((-1, 0), (0, 3)): 0, + ((-1, 0), (0, 4)): 0, + ((-1, 0), (0, 5)): 0, + ((-1, 0), (0, 6)): 0, + ((-1, 0), (0, 7)): 0, + ((-1, 0), (0, 8)): 0, + ((-1, 0), (0, 9)): 0, + ((0, 1), (1, 1)): 1, + ((0, 2), (1, 2)): 1, + ((0, 3), (1, 1)): 0, + ((0, 3), (1, 2)): 0, + ((0, 3), (1, 3)): 1, + ((0, 4), (1, 1)): 0, + ((0, 4), (1, 2)): 0, + ((0, 4), (1, 3)): 0, + ((0, 4), (1, 4)): 1, + ((0, 5), (1, 5)): 1, + ((0, 6), (1, 6)): 1, + ((0, 7), (1, 5)): 0, + ((0, 7), (1, 7)): 1, + ((0, 8), (1, 8)): 1, + ((0, 9), (1, 1)): 0, + ((0, 9), (1, 9)): 1, + ((1, 1), (2, 0)): 0, + ((1, 2), (2, 0)): 0, + ((1, 3), (2, 0)): 0, + ((1, 4), (2, 0)): 0, + ((1, 5), (2, 0)): 0, + ((1, 6), (2, 0)): 0, + ((1, 7), (2, 0)): 0, + ((1, 8), (2, 0)): 0, + ((1, 9), (2, 0)): 0}) AUTHOR: diff --git a/src/sage/combinat/rigged_configurations/bij_abstract_class.py b/src/sage/combinat/rigged_configurations/bij_abstract_class.py index 121dc375ef7..b7a2622272e 100644 --- a/src/sage/combinat/rigged_configurations/bij_abstract_class.py +++ b/src/sage/combinat/rigged_configurations/bij_abstract_class.py @@ -458,11 +458,7 @@ def next_state(self, height): sage: bijection.next_state(0) 5 sage: bijection.cur_partitions - [(/) - , (/) - , (/) - , (/) - ] + [(/), (/), (/), (/)] """ def _update_vacancy_numbers(self, a): diff --git a/src/sage/combinat/rigged_configurations/bij_type_D.py b/src/sage/combinat/rigged_configurations/bij_type_D.py index 496bafcf06b..89d6fb5af93 100644 --- a/src/sage/combinat/rigged_configurations/bij_type_D.py +++ b/src/sage/combinat/rigged_configurations/bij_type_D.py @@ -691,18 +691,10 @@ def doubling_map(self): sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[],[],[1]])) sage: bijection.cur_partitions - [(/) - , (/) - , (/) - , -1[ ]-1 - ] + [(/), (/), (/), -1[ ]-1] sage: bijection.doubling_map() sage: bijection.cur_partitions - [(/) - , (/) - , (/) - , -2[ ][ ]-2 - ] + [(/), (/), (/), -2[ ][ ]-2] """ # Skip the first column since it is a spinor for i in range(1, len(self.cur_dims)): diff --git a/src/sage/combinat/rigged_configurations/rigged_configuration_element.py b/src/sage/combinat/rigged_configurations/rigged_configuration_element.py index 46a55917ffa..b1874200e40 100644 --- a/src/sage/combinat/rigged_configurations/rigged_configuration_element.py +++ b/src/sage/combinat/rigged_configurations/rigged_configuration_element.py @@ -469,12 +469,8 @@ def nu(self): sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]]) sage: RC(partition_list=[[2], [2,2], [2], [2]]).nu() - [0[ ][ ]0 - , -2[ ][ ]-2 - -2[ ][ ]-2 - , 2[ ][ ]2 - , -2[ ][ ]-2 - ] + [0[ ][ ]0, -2[ ][ ]-2 + -2[ ][ ]-2, 2[ ][ ]2, -2[ ][ ]-2] """ return list(self) diff --git a/src/sage/combinat/root_system/associahedron.py b/src/sage/combinat/root_system/associahedron.py index 027914d84f0..792e5f086ee 100644 --- a/src/sage/combinat/root_system/associahedron.py +++ b/src/sage/combinat/root_system/associahedron.py @@ -66,10 +66,12 @@ def Associahedron(cartan_type): sage: Asso = Associahedron(['A',3]); Asso Generalized associahedron of type ['A', 3] with 14 vertices sage: Asso.plot() + Graphics3d Object sage: Asso = Associahedron(['B',3]); Asso Generalized associahedron of type ['B', 3] with 20 vertices sage: Asso.plot() + Graphics3d Object TESTS:: diff --git a/src/sage/combinat/root_system/cartan_type.py b/src/sage/combinat/root_system/cartan_type.py index 30fff237965..260e9e22b5a 100644 --- a/src/sage/combinat/root_system/cartan_type.py +++ b/src/sage/combinat/root_system/cartan_type.py @@ -1573,7 +1573,7 @@ def index_set_bipartition(self): EXAMPLES:: sage: CartanType(['A',5]).index_set_bipartition() - (set([1, 3, 5]), set([2, 4])) + ({1, 3, 5}, {2, 4}) sage: CartanType(['A',2,1]).index_set_bipartition() Traceback (most recent call last): diff --git a/src/sage/combinat/root_system/plot.py b/src/sage/combinat/root_system/plot.py index b83002d3716..af9d5107b8b 100644 --- a/src/sage/combinat/root_system/plot.py +++ b/src/sage/combinat/root_system/plot.py @@ -30,6 +30,7 @@ sage: L = RootSystem(["A",2]).ambient_space() sage: L.plot() + Graphics object consisting of 13 graphics primitives Each of those hyperplane `H_{\alpha^\vee_i}` is described by a linear form `\alpha_i^\vee` called simple coroot. To each such hyperplane @@ -50,6 +51,7 @@ sage: L = RootSystem(["A",2]).ambient_space() sage: L.plot(projection=False) + Graphics3d Object However in this space, the line `(1,1,1)` is fixed by the action of the group. Therefore, the so called barycentric projection orthogonal @@ -59,6 +61,7 @@ sage: L = RootSystem(["G",2]).ambient_space() sage: L.plot(reflection_hyperplanes="all") + Graphics object consisting of 21 graphics primitives The group is now the dihedral group of order 12, generated by the two reflections `s_1` and `s_2`. The picture displays the hyperplanes for @@ -102,6 +105,7 @@ sage: Q = RootSystem(["G",2]).root_space() sage: L = RootSystem(["G",2]).ambient_space() sage: L.plot(roots=list(Q.positive_roots()), fundamental_weights=False) + Graphics object consisting of 17 graphics primitives One can also customize the projection by specifying a function. Here, we display all the roots for type `E_8` using the projection from its @@ -115,6 +119,7 @@ sage: L.dimension() 8 sage: L.plot(roots="all", reflection_hyperplanes=False, projection=lambda v: M*vector(v), labels=False) # long time + Graphics3d Object The projection function should be linear or affine, and return a vector with rational coordinates. The rationale for the later @@ -140,10 +145,12 @@ sure everything fits in the picture:: sage: RootSystem(["G",2]).ambient_space().plot(alcoves=True, alcove_labels=True, bounding_box=5) + Graphics object consisting of 37 graphics primitives The same picture in 3D, for type `B_3`:: sage: RootSystem(["B",3]).ambient_space().plot(alcoves=True, alcove_labels=True) + Graphics3d Object .. TOPIC:: Exercise @@ -157,6 +164,7 @@ sage: L = RootSystem(["A",2,1]).ambient_space() sage: L.plot() # long time + Graphics object consisting of 160 graphics primitives This picture is convenient because it is low dimensional and contains most of the relevant information. Beside, by choosing the ambient @@ -169,6 +177,7 @@ full picture in 3D:: sage: L.plot(bounding_box=[[-3,3],[-3,3],[-1,1]], affine=False) # long time + Graphics3d Object In fact, in type `A`, this really is a picture in 4D, but as usual the barycentric projection kills the boring extra dimension for us. @@ -177,6 +186,7 @@ reflection hyperplanes with the level `1` hyperplane:: sage: L.plot(affine=False, level=1) # long time + Graphics3d Object Such 3D pictures are useful to better understand technicalities, like the fact that the fundamental weights do not necessarily all live at @@ -184,6 +194,7 @@ sage: L = RootSystem(["G",2,1]).ambient_space() sage: L.plot(affine=False, level=1) + Graphics3d Object .. NOTE:: @@ -208,6 +219,7 @@ sage: L = RootSystem(["C",2,1]).ambient_space() sage: L.plot(coroots="simple", alcove_labels=True) # long time + Graphics object consisting of 216 graphics primitives Even 2D pictures of the rank `1 + 1` cases can give some food for thought. Here, we draw the root lattice, with the positive roots of @@ -220,6 +232,7 @@ sage: it = iter(positive_roots) sage: first_positive_roots = [it.next() for i in range(10)] sage: L.plot(roots=first_positive_roots, affine=False, alcoves=False) + Graphics object consisting of 24 graphics primitives .. TOPIC:: Exercises @@ -260,6 +273,7 @@ sage: L = RootSystem(["A",3,1]).ambient_space() sage: L.plot(reflection_hyperplanes=False, bounding_box=85/100) # long time + Graphics3d Object It is recommended to use a small bounding box here, for otherwise the number of simplices grows quicker than what Sage can handle @@ -269,12 +283,14 @@ sage: W = L.weyl_group() sage: L.plot(reflection_hyperplanes=False, alcoves=[W.one()], bounding_box=2) + Graphics3d Object and the fundamental polygon, specified by the coordinates of its center in the root lattice:: sage: W = L.weyl_group() sage: L.plot(reflection_hyperplanes=False, alcoves=[[0,0]], bounding_box=2) + Graphics3d Object Finally, we draw the alcoves in the classical fundamental chambers, using that those are indexed by the elements of the Weyl group having @@ -314,6 +330,7 @@ sage: L = RootSystem(["A",2,1]).ambient_space() sage: w1 = [0,2,1,2,0,2,1,0,2,1,2,1,2,0,2,0,1,2,0] sage: L.plot(alcove_walk=w1, bounding_box=6) # long time + Graphics object consisting of 535 graphics primitives Now, what about drawing several alcove walks, and specifying some colors? A single do-it-all plot method would be cumbersome; so @@ -321,6 +338,7 @@ below) that can be called independently and combined at will:: sage: L.plot_roots() + L.plot_reflection_hyperplanes() + Graphics object consisting of 12 graphics primitives .. NOTE:: @@ -331,6 +349,7 @@ sage: p = L.plot_roots() + L.plot_reflection_hyperplanes() sage: p.axes(False) sage: p + Graphics object consisting of 12 graphics primitives In order to specify common information for all the pieces of a root system plot (choice of projection, bounding box, color code for the @@ -344,6 +363,7 @@ sage: p += L.plot_alcove_walk(w1, color="green", plot_options=plot_options) sage: p += L.plot_alcove_walk(w2, color="orange", plot_options=plot_options) sage: p + Graphics object consisting of ... graphics primitives And another with some foldings:: @@ -366,7 +386,9 @@ sage: p += L.plot_alcove_walk(walk, color="green", plot_options=plot_options) sage: p += plot_options.family_of_vectors({t: L(t)}) sage: plot_options.finalize(p) + Graphics object consisting of ... graphics primitives sage: p + Graphics object consisting of ... graphics primitives Note that the coloring of the translated alcove does not match with that of the fundamental alcove: the translation actually lives in the @@ -379,6 +401,7 @@ sage: L = RootSystem(["B",3,1]).ambient_space() sage: w3 = [0,2,1,3,2,0,2,1,0,2,3,1,2,1,3,2,0,2,0,1,2,0] sage: L.plot_fundamental_weights() + L.plot_reflection_hyperplanes(bounding_box=2) + L.plot_alcove_walk(w3) + Graphics3d Object .. TOPIC:: Exercise @@ -414,6 +437,7 @@ sage: L = RootSystem(["C",2,1]).ambient_space() sage: p = L.plot(bounding_box=[[-8,9],[-5,7]], coroots="simple") # long time (10 s) sage: p + Graphics object consisting of ... graphics primitives By default Sage's plot are bitmap pictures which would come out ugly if printed on paper. Instead, we recommend saving the picture in @@ -451,6 +475,7 @@ ... color_by_label=plot_options.color) sage: p.axes(False) sage: p + Graphics object consisting of 30 graphics primitives .. TODO:: Could we have nice `\LaTeX` labels in this graph? @@ -465,6 +490,7 @@ sage: p = L.plot_roots() sage: p += g.plot3d(pos3d = positions, color_by_label=plot_options.color) sage: p + Graphics3d Object .. TOPIC:: Exercises @@ -516,6 +542,7 @@ sage: p += g.plot3d(pos3d = positions, vertex_labels=True, ... color_by_label=plot_options.color, edge_labels=True) sage: p + Graphics3d Object .. TOPIC:: Exercise @@ -991,6 +1018,7 @@ def family_of_vectors(self, vectors): sage: options = L.plot_parse_options() sage: alpha = L.simple_roots() sage: p = options.family_of_vectors(alpha); p + Graphics object consisting of 4 graphics primitives sage: list(p) [Arrow from (0.0,0.0) to (1.0,0.0), Text '$1$' at the point (1.05,0.0), @@ -1014,6 +1042,7 @@ def family_of_vectors(self, vectors): sage: options = L.plot_parse_options() sage: Lambda = L.fundamental_weights() sage: p = options.family_of_vectors(Lambda); p + Graphics object consisting of 5 graphics primitives sage: list(p) [Text '$0$' at the point (0.0,0.0), Arrow from (0.0,0.0) to (0.5,0.866024518389), @@ -1073,6 +1102,7 @@ def cone(self, rays=[], lines=[], color="black", thickness=1, alpha=1, wireframe sage: alpha = L.simple_roots() sage: p = options.cone(rays=[alpha[1]], lines=[alpha[2]], color='green', label=2) sage: p + Graphics object consisting of 2 graphics primitives sage: list(p) [Polygon defined by 4 points, Text '$2$' at the point (3.15,3.15)] @@ -1158,6 +1188,7 @@ def reflection_hyperplane(self, coroot, as_polyhedron=False): sage: alphacheck = L.simple_coroots() sage: options = L.plot_parse_options() sage: H = options.reflection_hyperplane(alphacheck[1]); H + Graphics object consisting of 2 graphics primitives TESTS:: @@ -1275,6 +1306,7 @@ def barycentric_projection_matrix(n, angle=0): Here is a plot of them:: sage: sum(arrow((0,0,0),x) for x in m.columns()) + Graphics3d Object For 2D drawings of root systems, it is desirable to rotate the result to match with the usual conventions:: diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index d463b76de21..d912a4295a6 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -2257,7 +2257,9 @@ def plot_roots(self, collection="simple", **options): EXAMPLES:: sage: RootSystem(["B",3]).ambient_space().plot_roots() + Graphics3d Object sage: RootSystem(["B",3]).ambient_space().plot_roots("all") + Graphics3d Object TESTS:: @@ -2339,6 +2341,7 @@ def plot_coroots(self, collection="simple", **options): EXAMPLES:: sage: RootSystem(["B",3]).ambient_space().plot_coroots() + Graphics3d Object TESTS:: @@ -2387,6 +2390,7 @@ def plot_fundamental_weights(self, **options): EXAMPLES:: sage: RootSystem(["B",3]).ambient_space().plot_fundamental_weights() + Graphics3d Object TESTS:: @@ -2439,13 +2443,21 @@ def plot_reflection_hyperplanes(self, collection="simple", **options): EXAMPLES:: sage: RootSystem(["A",2,1]).ambient_space().plot_reflection_hyperplanes() + Graphics object consisting of 6 graphics primitives sage: RootSystem(["G",2,1]).ambient_space().plot_reflection_hyperplanes() + Graphics object consisting of 6 graphics primitives sage: RootSystem(["A",3]).weight_space().plot_reflection_hyperplanes() + Graphics3d Object sage: RootSystem(["B",3]).ambient_space().plot_reflection_hyperplanes() + Graphics3d Object sage: RootSystem(["A",3,1]).weight_space().plot_reflection_hyperplanes() + Graphics3d Object sage: RootSystem(["B",3,1]).ambient_space().plot_reflection_hyperplanes() + Graphics3d Object sage: RootSystem(["A",2,1]).weight_space().plot_reflection_hyperplanes(affine=False, level=1) + Graphics3d Object sage: RootSystem(["A",2]).root_lattice().plot_reflection_hyperplanes() + Graphics object consisting of 4 graphics primitives TESTS:: @@ -2515,15 +2527,21 @@ def plot_hedron(self, **options): EXAMPLES:: sage: RootSystem(["A",2]).ambient_space().plot_hedron() + Graphics object consisting of 8 graphics primitives sage: RootSystem(["A",3]).ambient_space().plot_hedron() + Graphics3d Object sage: RootSystem(["B",3]).ambient_space().plot_hedron() + Graphics3d Object sage: RootSystem(["C",3]).ambient_space().plot_hedron() + Graphics3d Object sage: RootSystem(["D",3]).ambient_space().plot_hedron() + Graphics3d Object Surprise: polyhedrons of large dimension know how to project themselves nicely:: sage: RootSystem(["F",4]).ambient_space().plot_hedron() # long time + Graphics3d Object TESTS:: @@ -2568,13 +2586,18 @@ def plot_fundamental_chamber(self, style="normal", **options): 2D plots:: sage: RootSystem(["B",2]).ambient_space().plot_fundamental_chamber() + Graphics object consisting of 1 graphics primitive sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber() + Graphics object consisting of 1 graphics primitive sage: RootSystem(["B",2,1]).ambient_space().plot_fundamental_chamber("classical") + Graphics object consisting of 1 graphics primitive 3D plots:: sage: RootSystem(["A",3,1]).weight_space() .plot_fundamental_chamber() + Graphics3d Object sage: RootSystem(["B",3,1]).ambient_space().plot_fundamental_chamber() + Graphics3d Object This feature is currently not available in the root lattice/space:: @@ -2635,17 +2658,21 @@ def plot_alcoves(self, alcoves=True, alcove_labels=False, wireframe=False, **opt 2D plots:: sage: RootSystem(["B",2,1]).ambient_space().plot_alcoves() # long time (3s) + Graphics object consisting of 228 graphics primitives 3D plots:: sage: RootSystem(["A",2,1]).weight_space() .plot_alcoves(affine=False) # long time (3s) + Graphics3d Object sage: RootSystem(["G",2,1]).ambient_space().plot_alcoves(affine=False, level=1) # long time (3s) + Graphics3d Object Here we plot a single alcove:: sage: L = RootSystem(["A",3,1]).ambient_space() sage: W = L.weyl_group() sage: L.plot(alcoves=[W.one()], reflection_hyperplanes=False, bounding_box=2) + Graphics3d Object TESTS:: @@ -2824,6 +2851,7 @@ def plot_bounding_box(self, **options): sage: L = RootSystem(["A",2,1]).ambient_space() sage: L.plot_bounding_box() + Graphics object consisting of 1 graphics primitive TESTS:: @@ -2859,6 +2887,7 @@ def plot_alcove_walk(self, word, start=None, foldings=None, color ="orange", **o sage: p = L.plot_alcoves(bounding_box=5) # long time (5s) sage: p += L.plot_alcove_walk(w1) # long time sage: p # long time + Graphics object consisting of 375 graphics primitives The same plot with another alcove walk:: @@ -2868,9 +2897,10 @@ def plot_alcove_walk(self, word, start=None, foldings=None, color ="orange", **o And another with some foldings:: sage: L.plot_alcoves(bounding_box=3) + \ - ... L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], - ... foldings = [False, False, True, False, False, False, True, False, True, False], - ... color="green") # long time (3s) + ....: L.plot_alcove_walk([0,1,2,0,2,0,1,2,0,1], + ....: foldings = [False, False, True, False, False, False, True, False, True, False], + ....: color="green") # long time (3s) + Graphics object consisting of 155 graphics primitives TESTS:: diff --git a/src/sage/combinat/root_system/root_system.py b/src/sage/combinat/root_system/root_system.py index 1b563bfaa0d..b7f737c95fd 100644 --- a/src/sage/combinat/root_system/root_system.py +++ b/src/sage/combinat/root_system/root_system.py @@ -241,6 +241,7 @@ class RootSystem(UniqueRepresentation, SageObject): sage: L = RootSystem(['A',2]).ambient_space() sage: L.plot() + Graphics object consisting of 13 graphics primitives For more on plotting, see :ref:`sage.combinat.root_system.plot`. diff --git a/src/sage/combinat/root_system/weyl_characters.py b/src/sage/combinat/root_system/weyl_characters.py index 91144e1b1ae..81dd06761aa 100644 --- a/src/sage/combinat/root_system/weyl_characters.py +++ b/src/sage/combinat/root_system/weyl_characters.py @@ -925,7 +925,7 @@ def _char_from_weights(self, mdict): sage: v = A2._space([3,1,0]) sage: d = dict([(x,1) for x in v.orbit()]) sage: A2._char_from_weights(d) - {(2, 2, 0): -1, (3, 1, 0): 1, (2, 1, 1): -1} + {(2, 1, 1): -1, (2, 2, 0): -1, (3, 1, 0): 1} """ hdict = {} ddict = mdict.copy() diff --git a/src/sage/combinat/shuffle.py b/src/sage/combinat/shuffle.py index a49419b7912..e18c8755599 100644 --- a/src/sage/combinat/shuffle.py +++ b/src/sage/combinat/shuffle.py @@ -175,18 +175,18 @@ def __iter__(self): sage: list(SetShuffleProduct([[1,2],[3]], [[4]])) [[1, 2, 4], [4, 1, 2], [1, 4, 2], [3, 4], [4, 3]] sage: list(SetShuffleProduct([[1,2],[3,4]], [[1,4]], element_constructor=set)) #rando - [set([1, 2, 4]), - set([1, 2, 4]), - set([1, 2, 4]), - set([1, 2, 4]), - set([1, 2, 4]), - set([1, 2, 4]), - set([1, 3, 4]), - set([1, 3, 4]), - set([1, 3, 4]), - set([1, 3, 4]), - set([1, 3, 4]), - set([1, 3, 4])] + [{1, 2, 4}, + {1, 2, 4}, + {1, 2, 4}, + {1, 2, 4}, + {1, 2, 4}, + {1, 2, 4}, + {1, 3, 4}, + {1, 3, 4}, + {1, 3, 4}, + {1, 3, 4}, + {1, 3, 4}, + {1, 3, 4}] """ def shuffle_elements(pair): return ShuffleProduct(*pair, element_constructor=self._element_constructor_) diff --git a/src/sage/combinat/similarity_class_type.py b/src/sage/combinat/similarity_class_type.py index 54acc584ed8..7fcad4dd02a 100644 --- a/src/sage/combinat/similarity_class_type.py +++ b/src/sage/combinat/similarity_class_type.py @@ -1558,7 +1558,7 @@ def matrix_centralizer_cardinalities_length_two(n, q = None, selftranspose = Fal (q^4 - q^2, 1/2*q^4 - 1/2*q^3)] sage: from sage.combinat.similarity_class_type import dictionary_from_generator sage: dictionary_from_generator(matrix_centralizer_cardinalities_length_two(2, q = 2)) - {96: 4, 32: 4, 4: 4, 16: 2, 8: 8, 12: 4, 48: 2} + {4: 4, 8: 8, 12: 4, 16: 2, 32: 4, 48: 2, 96: 4} """ if q is None: q = FractionField(QQ['q']).gen() diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index c77bf7d0179..327675737cb 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -537,7 +537,11 @@ def _tableau_dict(self): sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") sage: orth._tableau_dict - {(0, 2, 1, -1, 0): [[1, 3, 4], [2, 5]], (2, 0, -1, 1, 0): [[1, 2, 5], [3, 4]], (2, 0, 1, -1, 0): [[1, 3, 5], [2, 4]], (0, 2, -1, 1, 0): [[1, 2, 4], [3, 5]], (0, -1, 2, 1, 0): [[1, 2, 3], [4, 5]]} + {(0, -1, 2, 1, 0): [[1, 2, 3], [4, 5]], + (0, 2, -1, 1, 0): [[1, 2, 4], [3, 5]], + (0, 2, 1, -1, 0): [[1, 3, 4], [2, 5]], + (2, 0, -1, 1, 0): [[1, 2, 5], [3, 4]], + (2, 0, 1, -1, 0): [[1, 3, 5], [2, 4]]} """ # construct a dictionary pairing vertices with tableau t = StandardTableaux(self._partition).last() @@ -558,7 +562,11 @@ def _word_dict(self): sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") sage: orth._word_dict - {(0, 2, -1, 1, 0): [3, 5, 1, 2, 4], (2, 0, -1, 1, 0): [3, 4, 1, 2, 5], (2, 0, 1, -1, 0): [2, 4, 1, 3, 5], (0, 2, 1, -1, 0): [2, 5, 1, 3, 4], (0, -1, 2, 1, 0): [4, 5, 1, 2, 3]} + {(0, -1, 2, 1, 0): [4, 5, 1, 2, 3], + (0, 2, -1, 1, 0): [3, 5, 1, 2, 4], + (0, 2, 1, -1, 0): [2, 5, 1, 3, 4], + (2, 0, -1, 1, 0): [3, 4, 1, 2, 5], + (2, 0, 1, -1, 0): [2, 4, 1, 3, 5]} """ word_dict = {} for (v,t) in self._tableau_dict.iteritems(): diff --git a/src/sage/combinat/tiling.py b/src/sage/combinat/tiling.py index a1f2d1d9d25..d8931210585 100644 --- a/src/sage/combinat/tiling.py +++ b/src/sage/combinat/tiling.py @@ -908,6 +908,7 @@ def show3d(self, size=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0,0), (0,1,0), (1,1,0), (1,1,1)], color='blue') sage: p.show3d() + Graphics3d Object """ assert self._dimension == 3, "Dimension of the polyomino must be 3." G = Graphics() @@ -938,6 +939,7 @@ def show2d(self, size=0.7, color='black', thickness=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0),(1,0),(1,1),(1,2)], color='deeppink') sage: p.show2d() # long time (0.5s) + Graphics object consisting of 17 graphics primitives """ assert self._dimension == 2, "Dimension of the polyomino must be 2." h = size / 2.0 diff --git a/src/sage/combinat/tutorial.py b/src/sage/combinat/tutorial.py index 5ba87213580..ddd5a87a785 100644 --- a/src/sage/combinat/tutorial.py +++ b/src/sage/combinat/tutorial.py @@ -864,6 +864,7 @@ :: sage: C.unrank(20).plot() + Graphics object consisting of 20 graphics primitives .. image:: ../../media/a_poset.png diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index a62daa92a70..0c544b41146 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -3586,7 +3586,7 @@ def last_position_dict(self): EXAMPLES:: sage: Word('1231232').last_position_dict() - {'1': 3, '3': 5, '2': 6} + {'1': 3, '2': 6, '3': 5} """ d = {} for (i, letter) in enumerate(self): @@ -3900,11 +3900,11 @@ def return_words(self, fact): EXAMPLES:: sage: Word('21331233213231').return_words(Word('2')) - set([word: 213, word: 21331, word: 233]) + {word: 213, word: 21331, word: 233} sage: Word().return_words(Word('213')) - set([]) + set() sage: Word('121212').return_words(Word('1212')) - set([word: 12]) + {word: 12} :: @@ -3942,9 +3942,9 @@ def complete_return_words(self, fact): sage: sorted(s) [word: 2132, word: 213312, word: 2332] sage: Word('').complete_return_words(Word('213')) - set([]) + set() sage: Word('121212').complete_return_words(Word('1212')) - set([word: 121212]) + {word: 121212} REFERENCES: @@ -4128,7 +4128,7 @@ def evaluation_dict(self): sage: Word([2,1,4,2,3,4,2]).evaluation_dict() {1: 1, 2: 3, 3: 1, 4: 2} sage: Word('badbcdb').evaluation_dict() - {'a': 1, 'c': 1, 'b': 3, 'd': 2} + {'a': 1, 'b': 3, 'c': 1, 'd': 2} sage: Word().evaluation_dict() {} @@ -5974,12 +5974,18 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn EXAMPLES:: sage: Word(range(20)).colored_vector() + Graphics object consisting of 21 graphics primitives sage: Word(range(100)).colored_vector(0,0,10,1) + Graphics object consisting of 101 graphics primitives sage: Words(range(100))(range(10)).colored_vector() + Graphics object consisting of 11 graphics primitives sage: w = Word('abbabaab') sage: w.colored_vector() + Graphics object consisting of 9 graphics primitives sage: w.colored_vector(cmap='autumn') + Graphics object consisting of 9 graphics primitives sage: Word(range(20)).colored_vector(label='Rainbow') + Graphics object consisting of 23 graphics primitives When two words are defined under the same parent, same letters are mapped to same colors:: @@ -5988,13 +5994,16 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn sage: w = W(range(20)) sage: y = W(range(10,20)) sage: y.colored_vector(y=1, x=10) + w.colored_vector() + Graphics object consisting of 32 graphics primitives TESTS: The empty word:: sage: Word().colored_vector() + Graphics object consisting of 1 graphics primitive sage: Word().colored_vector(label='empty') + Graphics object consisting of 3 graphics primitives Unknown cmap:: diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 2f5dda74603..66d91b5e334 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -2287,7 +2287,9 @@ def rauzy_fractal_projection(self, eig=None, prec=53): sage: s = WordMorphism('1->12,2->13,3->1') sage: s.rauzy_fractal_projection() - {'1': (1.00..., 0.00...), '3': (-0.77..., 1.11...), '2': (-1.41..., -0.60...)} + {'1': (1.00000000000000, 0.000000000000000), + '2': (-1.41964337760708, -0.606290729207199), + '3': (-0.771844506346038, 1.11514250803994)} TESTS:: @@ -2295,9 +2297,23 @@ def rauzy_fractal_projection(self, eig=None, prec=53): sage: E = t.incidence_matrix().eigenvalues() sage: x = [x for x in E if -0.8 < x < -0.7][0] sage: t.rauzy_fractal_projection(prec=10) - {'1': (1.0, 0.00), '3': (0.79, 1.3), '2': (-1.7, -0.56), '5': (-1.7, -0.56), '4': (1.9, -0.74), '7': (0.21, -1.3), '6': (0.79, 1.3), '8': (-0.88, 0.74)} + {'1': (1.0, 0.00), + '2': (-1.7, -0.56), + '3': (0.79, 1.3), + '4': (1.9, -0.74), + '5': (-1.7, -0.56), + '6': (0.79, 1.3), + '7': (0.21, -1.3), + '8': (-0.88, 0.74)} sage: t.rauzy_fractal_projection(eig=x, prec=10) - {'1': (1.0, 0.00), '3': (-0.66, -0.56), '2': (-0.12, -0.74), '5': (-0.54, 0.18), '4': (-0.46, -0.18), '7': (0.12, 0.74), '6': (-0.34, 0.56), '8': (0.66, 0.56)} + {'1': (1.0, 0.00), + '2': (-0.12, -0.74), + '3': (-0.66, -0.56), + '4': (-0.46, -0.18), + '5': (-0.54, 0.18), + '6': (-0.34, 0.56), + '7': (0.12, 0.74), + '8': (0.66, 0.56)} AUTHOR: @@ -2547,6 +2563,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, translate=None, p sage: s = WordMorphism('1->12,2->13,3->1') sage: s.rauzy_fractal_plot() # long time + Graphics object consisting of 3 graphics primitives #. The "Hokkaido" fractal. We tweak the plot using the plotting options to get a nice reusable picture, in which we mark the origin by a black dot:: @@ -2652,6 +2669,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, translate=None, p sage: s = WordMorphism('a->ab,b->c,c->d,d->e,e->a') sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', opacity={'a':0.5,'b':1,'c':0.7,'d':0,'e':0.2}, plot_origin=(100,"black"), plot_basis=True, point_size=2.5) + Graphics object consisting of 10 graphics primitives REFERENCES: diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index 171140626b0..d56ede67641 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -46,6 +46,7 @@ sage: p.is_closed() False sage: p.plot() + Graphics object consisting of 3 graphics primitives To obtain a list of all the available word path specific functions, use ``help(p)``:: @@ -105,12 +106,14 @@ sage: d = D('()()()(())'); d Path: ()()()(()) sage: d.plot() + Graphics object consisting of 3 graphics primitives :: sage: P = WordPaths('abcdef', steps='triangle_grid') sage: p = P('babaddefadabcadefaadfafabacdefa') sage: p.plot() + Graphics object consisting of 3 graphics primitives Vector steps may be in more than 2 dimensions:: @@ -119,6 +122,7 @@ Word Paths over 3 steps sage: p = P('abcabcabcabcaabacabcababcacbabacacabcaccbcac') sage: p.plot() + Graphics3d Object :: @@ -135,6 +139,7 @@ sage: CubePaths = WordPaths('abcABC', steps='cube_grid'); CubePaths Word Paths on the cube grid sage: CubePaths('abcabaabcabAAAAA').plot() + Graphics3d Object The input data may be a str, a list, a tuple, a callable or a finite iterator:: @@ -381,7 +386,7 @@ def __init__(self, alphabet, steps): sage: WordPaths('abcd',[(2,1),(2,4)]) Word Paths over 4 steps sage: _.letters_to_steps() - {'a': (2, 1), 'c': (-2, -1), 'b': (2, 4), 'd': (-2, -4)} + {'a': (2, 1), 'b': (2, 4), 'c': (-2, -1), 'd': (-2, -4)} TESTS:: @@ -1450,6 +1455,7 @@ def projected_path(self, v=None, ring=None): sage: p Path: 1213121121312121312112131213121121312121... sage: p[:20].plot() + Graphics object consisting of 3 graphics primitives The ``ring`` argument allows to change the precision of the projected steps:: @@ -1458,7 +1464,7 @@ def projected_path(self, v=None, ring=None): sage: p Path: 1213121121312121312112131213121121312121... sage: p.parent().letters_to_steps() - {'1': (-0.53, 0.00), '3': (0.41, 0.88), '2': (0.75, -0.48)} + {'1': (-0.53, 0.00), '2': (0.75, -0.48), '3': (0.41, 0.88)} """ if v is None: v = self.directive_vector() @@ -1534,25 +1540,30 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), sage: P = WordPaths('abAB') sage: P('abababAABAB').plot() + Graphics object consisting of 3 graphics primitives A closed path on the square grid:: sage: P('abababAABABB').plot() + Graphics object consisting of 4 graphics primitives A dyck path:: sage: P = WordPaths('()', steps='dyck') sage: P('()()()((()))').plot() + Graphics object consisting of 3 graphics primitives A path in the triangle grid:: sage: P = WordPaths('abcdef', steps='triangle_grid') sage: P('abcdedededefab').plot() + Graphics object consisting of 3 graphics primitives A polygon of length 220 that tiles the plane in two ways:: sage: P = WordPaths('abAB') sage: P('aBababAbabaBaBABaBabaBaBABAbABABaBabaBaBABaBababAbabaBaBABaBabaBaBABAbABABaBABAbAbabAbABABaBABAbABABaBabaBaBABAbABABaBABAbAbabAbABAbAbabaBababAbABAbAbabAbABABaBABAbAbabAbABAbAbabaBababAbabaBaBABaBababAbabaBababAbABAbAbab').plot() + Graphics object consisting of 4 graphics primitives With gridlines:: @@ -1562,7 +1573,9 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), sage: P = WordPaths('abAB') sage: P().plot() + Graphics object consisting of 3 graphics primitives sage: sum(map(plot,map(P,['a','A','b','B']))) + Graphics object consisting of 12 graphics primitives """ G = Graphics() pts = list(self.points()) @@ -1710,6 +1723,7 @@ def plot_directive_vector(self, options=dict(rgbcolor='blue')): A closed path:: sage: P('acbd').plot_directive_vector() + Graphics object consisting of 0 graphics primitives """ start = self.start_point() end = self.end_point() @@ -1954,10 +1968,12 @@ def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), sage: p = P('ababab'); p Path: ababab sage: p.plot() + Graphics3d Object sage: P = WordPaths('abcABC', steps='cube_grid') sage: p = P('abcabcAABBC') sage: p.plot() + Graphics3d Object """ #The following line seems not to work for 3d diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index c3632b0c79a..ea40dbaf4b5 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -462,6 +462,7 @@ def plot(self, layout='tree', tree_root=0, tree_orientation='up', sage: from sage.combinat.words.suffix_trees import SuffixTrie sage: SuffixTrie(Word("cacao")).plot() + Graphics object consisting of 38 graphics primitives TESTS:: @@ -864,7 +865,9 @@ def plot(self, word_labels=False, layout='tree', tree_root=0, sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) + Graphics object consisting of 23 graphics primitives sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) + Graphics object consisting of 23 graphics primitives TESTS:: diff --git a/src/sage/combinat/yang_baxter_graph.py b/src/sage/combinat/yang_baxter_graph.py index 2bdf18b7ab5..193fdbdd50d 100644 --- a/src/sage/combinat/yang_baxter_graph.py +++ b/src/sage/combinat/yang_baxter_graph.py @@ -82,6 +82,7 @@ def YangBaxterGraph(partition=None, root=None, operators=None): sage: Y = YangBaxterGraph(root=(1,2,3,4), operators=swappers); Y Yang-Baxter graph with root vertex (1, 2, 3, 4) sage: Y.plot() + Graphics object consisting of 97 graphics primitives The Cayley graph of a finite group can be realized as a Yang-Baxter graph. @@ -94,12 +95,14 @@ def YangBaxterGraph(partition=None, root=None, operators=None): sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () sage: Y.plot(edge_labels=False) + Graphics object consisting of 9 graphics primitives sage: G = SymmetricGroup(4) sage: operators = [left_multiplication_by(gen) for gen in G.gens()] sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () sage: Y.plot(edge_labels=False) + Graphics object consisting of 96 graphics primitives AUTHORS: @@ -382,7 +385,9 @@ def plot(self, *args, **kwds): sage: ops = [SwapIncreasingOperator(i) for i in range(4)] sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops) sage: Y.plot() + Graphics object consisting of 16 graphics primitives sage: Y.plot(edge_labels=False) + Graphics object consisting of 11 graphics primitives """ if "edge_labels" not in kwds: kwds["edge_labels"] = True @@ -445,7 +450,9 @@ def vertex_relabelling_dict(self, v, relabel_operator): ... i = op.position() ... return u[:i] + u[i:i+2][::-1] + u[i+2:] sage: Y.vertex_relabelling_dict((1,2,3,4), relabel_operator) - {(2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4), (0, 2, 1, 0): (1, 2, 3, 4)} + {(0, 2, 1, 0): (1, 2, 3, 4), + (2, 0, 1, 0): (2, 1, 3, 4), + (2, 1, 0, 0): (2, 3, 1, 4)} """ relabelling = {self._root:v} for (u,w,i) in self._edges_in_bfs(): @@ -687,9 +694,13 @@ def vertex_relabelling_dict(self, v): sage: Y = YangBaxterGraph(partition=[3,1]) sage: Y.vertex_relabelling_dict((1,2,3,4)) - {(2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4), (0, 2, 1, 0): (1, 2, 3, 4)} + {(0, 2, 1, 0): (1, 2, 3, 4), + (2, 0, 1, 0): (2, 1, 3, 4), + (2, 1, 0, 0): (2, 3, 1, 4)} sage: Y.vertex_relabelling_dict((4,3,2,1)) - {(2, 0, 1, 0): (3, 4, 2, 1), (2, 1, 0, 0): (3, 2, 4, 1), (0, 2, 1, 0): (4, 3, 2, 1)} + {(0, 2, 1, 0): (4, 3, 2, 1), + (2, 0, 1, 0): (3, 4, 2, 1), + (2, 1, 0, 0): (3, 2, 4, 1)} """ return super(YangBaxterGraph_partition, self).vertex_relabelling_dict(v, self._swap_operator) diff --git a/src/sage/crypto/block_cipher/sdes.py b/src/sage/crypto/block_cipher/sdes.py index 7389171ae85..904728c6cd3 100644 --- a/src/sage/crypto/block_cipher/sdes.py +++ b/src/sage/crypto/block_cipher/sdes.py @@ -802,9 +802,7 @@ def list_to_string(self, B): Input must be a non-empty list of bits:: sage: sdes.list_to_string([0, 1, 2]) - Traceback (most recent call last): - ... - IndexError: tuple index out of range + ) failed: IndexError: tuple index out of range> """ # sanity check if not isinstance(B, list): diff --git a/src/sage/crypto/boolean_function.pyx b/src/sage/crypto/boolean_function.pyx index 41f43833db6..ff6226c7482 100644 --- a/src/sage/crypto/boolean_function.pyx +++ b/src/sage/crypto/boolean_function.pyx @@ -947,7 +947,7 @@ cdef class BooleanFunction(SageObject): True sage: g = BooleanFunction( f.annihilator(3) ) sage: set([ fi*g(i) for i,fi in enumerate(f) ]) - set([0]) + {0} """ # NOTE: this is a toy implementation from sage.rings.polynomial.pbori import BooleanPolynomialRing diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index 064bd202ab6..efe368be9a4 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -1634,19 +1634,49 @@ def variable_dict(self): sage: sr = mq.SR(1,1,1,4) sage: sr.variable_dict() - {'x101': x101, 'x100': x100, 'x103': x103, 'x102': x102, - 's002': s002, 'w100': w100, 'w101': w101, 'w102': w102, - 'w103': w103, 'k100': k100, 'k101': k101, 'k102': k102, - 'k103': k103, 's003': s003, 's001': s001, 'k002': k002, - 'k001': k001, 'k000': k000, 'k003': k003, 's000': s000} + {'k000': k000, + 'k001': k001, + 'k002': k002, + 'k003': k003, + 'k100': k100, + 'k101': k101, + 'k102': k102, + 'k103': k103, + 's000': s000, + 's001': s001, + 's002': s002, + 's003': s003, + 'w100': w100, + 'w101': w101, + 'w102': w102, + 'w103': w103, + 'x100': x100, + 'x101': x101, + 'x102': x102, + 'x103': x103} sage: sr = mq.SR(1,1,1,4,gf2=True) sage: sr.variable_dict() - {'x101': x101, 'x100': x100, 'x103': x103, 'x102': x102, - 's002': s002, 'w100': w100, 'w101': w101, 'w102': w102, - 'w103': w103, 'k100': k100, 'k101': k101, 'k102': k102, - 'k103': k103, 's003': s003, 's001': s001, 'k002': k002, - 'k001': k001, 'k000': k000, 'k003': k003, 's000': s000} + {'k000': k000, + 'k001': k001, + 'k002': k002, + 'k003': k003, + 'k100': k100, + 'k101': k101, + 'k102': k102, + 'k103': k103, + 's000': s000, + 's001': s001, + 's002': s002, + 's003': s003, + 'w100': w100, + 'w101': w101, + 'w102': w102, + 'w103': w103, + 'x100': x100, + 'x101': x101, + 'x102': x102, + 'x103': x103} """ try: diff --git a/src/sage/databases/cremona.py b/src/sage/databases/cremona.py index f320a9f489c..fb08a7b07d0 100644 --- a/src/sage/databases/cremona.py +++ b/src/sage/databases/cremona.py @@ -594,8 +594,9 @@ class MiniCremonaDatabase(SQLDatabase): sage: c = CremonaDatabase() sage: c.allcurves(11) - {'a1': [[0, -1, 1, -10, -20], 0, 5], 'a3': [[0, -1, 1, 0, 0], 0, 5], - 'a2': [[0, -1, 1, -7820, -263580], 0, 1]} + {'a1': [[0, -1, 1, -10, -20], 0, 5], + 'a2': [[0, -1, 1, -7820, -263580], 0, 1], + 'a3': [[0, -1, 1, 0, 0], 0, 5]} """ def __init__(self, name, read_only=True, build=False): """ diff --git a/src/sage/databases/sql_db.py b/src/sage/databases/sql_db.py index 47dfa14db74..3b1e4eaa809 100644 --- a/src/sage/databases/sql_db.py +++ b/src/sage/databases/sql_db.py @@ -159,12 +159,10 @@ def verify_column(col_dict): sage: from sage.databases.sql_db import verify_column sage: col = {'sql':'BOOLEAN'} sage: verify_column(col) - {'index': False, 'unique': False, 'primary_key': False, - 'sql': 'BOOLEAN'} + {'index': False, 'primary_key': False, 'sql': 'BOOLEAN', 'unique': False} sage: col = {'primary_key':True, 'sql':'INTEGER'} sage: verify_column(col) - {'index': True, 'unique': True, 'primary_key': True, - 'sql': 'INTEGER'} + {'index': True, 'primary_key': True, 'sql': 'INTEGER', 'unique': True} sage: verify_column({}) Traceback (most recent call last): ... @@ -1787,9 +1785,14 @@ def make_index(self, col_name, table_name, unique=False): sage: MonicPolys.create_table('simon', {'n':{'sql':'INTEGER', 'index':True}, 'n2':{'sql':'INTEGER'}}) sage: MonicPolys.make_index('n2','simon') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': True, 'unique': False, - 'primary_key': False, 'sql': 'INTEGER'}, 'n': {'index': True, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}}} """ if self.__read_only__: raise RuntimeError('Cannot modify a read only database.') @@ -1823,9 +1826,14 @@ def drop_index(self, table_name, index_name): sage: MonicPolys.create_table('simon', {'n':{'sql':'INTEGER', 'index':True}, 'n2':{'sql':'INTEGER'}}) sage: MonicPolys.drop_index('simon', 'n') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': False, 'unique': False, - 'primary_key': False, 'sql': 'INTEGER'}, 'n': {'index': False, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': False, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': False, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}}} """ if self.__read_only__: raise RuntimeError('Cannot modify a read only database.') @@ -1858,9 +1866,14 @@ def make_unique(self, table_name, col_name): sage: MonicPolys.create_table('simon', {'n':{'sql':'INTEGER', 'index':True}, 'n2':{'sql':'INTEGER'}}) sage: MonicPolys.make_unique('simon', 'n2') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': False, 'unique': True, - 'primary_key': False, 'sql': 'INTEGER'}, 'n': {'index': True, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': False, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': True}}} """ if self.__read_only__: @@ -1892,9 +1905,14 @@ def drop_unique(self, table_name, col_name): sage: MonicPolys.make_unique('simon', 'n2') sage: MonicPolys.drop_unique('simon', 'n2') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': False, 'unique': False, - 'primary_key': False, 'sql': 'INTEGER'}, 'n': {'index': True, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': False, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}}} """ if self.__read_only__: raise RuntimeError('Cannot modify a read only database.') @@ -1930,9 +1948,14 @@ def make_primary_key(self, table_name, col_name): sage: MonicPolys.create_table('simon', {'n':{'sql':'INTEGER', 'index':True}, 'n2':{'sql':'INTEGER'}}) sage: MonicPolys.make_primary_key('simon', 'n2') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': False, 'unique': True, - 'primary_key': True, 'sql': 'INTEGER'}, 'n': {'index': True, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': False, + 'primary_key': True, + 'sql': 'INTEGER', + 'unique': True}}} """ if self.__read_only__: raise RuntimeError('Cannot modify a read only database.') @@ -1969,9 +1992,14 @@ def drop_primary_key(self, table_name, col_name): sage: MonicPolys.make_primary_key('simon', 'n2') sage: MonicPolys.drop_primary_key('simon', 'n2') sage: MonicPolys.get_skeleton() - {'simon': {'n2': {'index': False, 'unique': True, - 'primary_key': False, 'sql': 'INTEGER'}, 'n': {'index': True, - 'unique': False, 'primary_key': False, 'sql': 'INTEGER'}}} + {'simon': {'n': {'index': True, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': False}, + 'n2': {'index': False, + 'primary_key': False, + 'sql': 'INTEGER', + 'unique': True}}} """ if self.__read_only__: raise RuntimeError('Cannot modify a read only database.') diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index 85efb2833d7..f89e58d7373 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -66,7 +66,7 @@ def __init__(self, **kwds): sage: from sage.doctest.control import DocTestDefaults sage: D = DocTestDefaults(); D.optional - set(['sage']) + {'sage'} """ self.nthreads = 1 self.serial = False diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 78a5206ad89..d98d91b47b4 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -808,9 +808,9 @@ def compile_and_execute(self, example, compiler, globs): sage: globs['doctest_var'] 42 sage: globs.set - set(['doctest_var']) + {'doctest_var'} sage: globs.got - set(['Integer']) + {'Integer'} Now we can execute some more doctests to see the dependencies. :: @@ -820,7 +820,7 @@ def compile_and_execute(self, example, compiler, globs): sage: sorted(list(globs.set)) ['R', 'a'] sage: globs.got - set(['ZZ']) + {'ZZ'} sage: ex1.predecessors [] @@ -2043,7 +2043,7 @@ def __init__(self, source): sage: filename = os.path.join(SAGE_SRC,'sage','doctest','sources.py') sage: FDS = FileDocTestSource(filename,DocTestDefaults()) sage: DocTestTask(FDS) - + """ self.source = source diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py index 8e08b5e075e..e393b0fedd5 100644 --- a/src/sage/doctest/parsing.py +++ b/src/sage/doctest/parsing.py @@ -76,33 +76,33 @@ def parse_optional_tags(string): sage: from sage.doctest.parsing import parse_optional_tags sage: parse_optional_tags("sage: magma('2 + 2')# optional: magma") - set(['magma']) + {'magma'} sage: parse_optional_tags("sage: #optional -- mypkg") - set(['mypkg']) + {'mypkg'} sage: parse_optional_tags("sage: print(1) # parentheses are optional here") - set([]) + set() sage: parse_optional_tags("sage: print(1) # optional") - set(['']) + {''} sage: sorted(list(parse_optional_tags("sage: #optional -- foo bar, baz"))) ['bar', 'foo'] sage: sorted(list(parse_optional_tags(" sage: factor(10^(10^10) + 1) # LoNg TiME, NoT TeSTED; OptioNAL -- P4cka9e"))) ['long time', 'not tested', 'p4cka9e'] sage: parse_optional_tags(" sage: raise RuntimeError # known bug") - set(['bug']) + {'bug'} sage: sorted(list(parse_optional_tags(" sage: determine_meaning_of_life() # long time, not implemented"))) ['long time', 'not implemented'] We don't parse inside strings:: sage: parse_optional_tags(" sage: print ' # long time'") - set([]) + set() sage: parse_optional_tags(" sage: print ' # long time' # not tested") - set(['not tested']) + {'not tested'} UTF-8 works:: sage: parse_optional_tags("'ěščřžýáíéďĎ'") - set([]) + set() """ safe, literals, state = strip_string_literals(string) first_line = safe.split('\n', 1)[0] diff --git a/src/sage/doctest/util.py b/src/sage/doctest/util.py index f6f84cc663d..1b8866c2f98 100644 --- a/src/sage/doctest/util.py +++ b/src/sage/doctest/util.py @@ -206,20 +206,20 @@ class RecordingDict(dict): sage: from sage.doctest.util import RecordingDict sage: D = RecordingDict(test=17) sage: D.got - set([]) + set() sage: D['test'] 17 sage: D.got - set(['test']) + {'test'} sage: D.set - set([]) + set() sage: D['a'] = 1 sage: D['a'] 1 sage: D.set - set(['a']) + {'a'} sage: D.got - set(['test']) + {'test'} TESTS:: @@ -234,7 +234,7 @@ def __init__(self, *args, **kwds): sage: from sage.doctest.util import RecordingDict sage: D = RecordingDict(d = 42) sage: D.got - set([]) + set() """ dict.__init__(self, *args, **kwds) self.start() @@ -249,12 +249,12 @@ def start(self): sage: from sage.doctest.util import RecordingDict sage: D = RecordingDict(d = 42) sage: D.set - set([]) + set() sage: D['a'] = 4 sage: D.set - set(['a']) + {'a'} sage: D.start(); D.set - set([]) + set() """ self.set = set([]) self.got = set([]) @@ -267,15 +267,15 @@ def __getitem__(self, name): sage: D = RecordingDict(d = 42) sage: D['a'] = 4 sage: D.got - set([]) + set() sage: D['a'] # indirect doctest 4 sage: D.got - set([]) + set() sage: D['d'] 42 sage: D.got - set(['d']) + {'d'} """ if name not in self.set: self.got.add(name) @@ -289,7 +289,7 @@ def __setitem__(self, name, value): sage: D = RecordingDict(d = 42) sage: D['a'] = 4 # indirect doctest sage: D.set - set(['a']) + {'a'} """ self.set.add(name) dict.__setitem__(self, name, value) @@ -302,7 +302,7 @@ def __delitem__(self, name): sage: D = RecordingDict(d = 42) sage: del D['d'] # indirect doctest sage: D.set - set(['d']) + {'d'} """ self.set.add(name) dict.__delitem__(self, name) @@ -316,7 +316,7 @@ def get(self, name, default=None): sage: D.get('d') 42 sage: D.got - set(['d']) + {'d'} sage: D.get('not_here') sage: sorted(list(D.got)) ['d', 'not_here'] @@ -335,10 +335,10 @@ def copy(self): sage: D = RecordingDict(d = 42) sage: D['a'] = 4 sage: D.set - set(['a']) + {'a'} sage: E = D.copy() sage: E.set - set([]) + set() sage: sorted(E.keys()) ['a', 'd'] """ @@ -356,7 +356,7 @@ def __reduce__(self): sage: D.get('not_here') sage: E = loads(dumps(D)) sage: E.got - set(['not_here']) + {'not_here'} """ return make_recording_dict, (dict(self), self.set, self.got) @@ -371,7 +371,7 @@ def make_recording_dict(D, st, gt): sage: sorted(D.items()) [('a', 4), ('d', 42)] sage: D.got - set(['not_here']) + {'not_here'} """ ans = RecordingDict(D) ans.set = st diff --git a/src/sage/dynamics/interval_exchanges/iet.py b/src/sage/dynamics/interval_exchanges/iet.py index 91d1115aa8a..5fcf917d66f 100644 --- a/src/sage/dynamics/interval_exchanges/iet.py +++ b/src/sage/dynamics/interval_exchanges/iet.py @@ -35,10 +35,12 @@ .. plot the domain and the range of T:: sage: T.plot_two_intervals() + Graphics object consisting of 12 graphics primitives .. plot T as a function:: sage: T.plot_function() + Graphics object consisting of 3 graphics primitives """ from copy import copy from sage.structure.sage_object import SageObject @@ -790,6 +792,7 @@ def plot_function(self,**d): sage: t = iet.IntervalExchangeTransformation(('a b c d','d a c b'),[1,1,1,1]) sage: t.plot_function(rgbcolor=(0,1,0)) + Graphics object consisting of 4 graphics primitives """ from sage.plot.all import Graphics from sage.plot.plot import line2d @@ -835,6 +838,7 @@ def plot_two_intervals(self, sage: t = iet.IntervalExchangeTransformation(('a b','b a'),[1,1]) sage: t.plot_two_intervals() + Graphics object consisting of 8 graphics primitives """ from sage.plot.all import Graphics from sage.plot.plot import line2d diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index b44a953be70..da15b3d5ecb 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -1918,7 +1918,12 @@ cdef class InstructionStream: sage: from sage.ext.fast_callable import InstructionStream sage: instr_stream = InstructionStream(metadata, 1) sage: instr_stream.get_current() - {'domain': None, 'code': [], 'py_constants': [], 'args': 1, 'stack': 0, 'constants': []} + {'args': 1, + 'code': [], + 'constants': [], + 'domain': None, + 'py_constants': [], + 'stack': 0} sage: md = instr_stream.get_metadata() sage: type(md) @@ -2133,7 +2138,12 @@ cdef class InstructionStream: sage: from sage.ext.fast_callable import InstructionStream sage: instr_stream = InstructionStream(metadata, 1) sage: instr_stream.get_current() - {'domain': None, 'code': [], 'py_constants': [], 'args': 1, 'stack': 0, 'constants': []} + {'args': 1, + 'code': [], + 'constants': [], + 'domain': None, + 'py_constants': [], + 'stack': 0} sage: instr_stream.instr('load_arg', 0) sage: instr_stream.instr('py_call', math.sin, 1) sage: instr_stream.instr('abs') @@ -2141,7 +2151,12 @@ cdef class InstructionStream: sage: instr_stream.current_op_list() [('load_arg', 0), ('py_call', , 1), 'abs', 'return'] sage: instr_stream.get_current() - {'domain': None, 'code': [0, 0, 3, 0, 1, 12, 2], 'py_constants': [], 'args': 1, 'stack': 1, 'constants': []} + {'args': 1, + 'code': [0, 0, 3, 0, 1, 12, 2], + 'constants': [], + 'domain': None, + 'py_constants': [], + 'stack': 1} """ d = {'args': self._n_args, 'constants': self._constants, @@ -2317,7 +2332,12 @@ cdef class Wrapper: sage: instr_stream.instr('return') sage: v = Wrapper_py(instr_stream.get_current()) sage: v.get_orig_args() - {'domain': None, 'code': [0, 0, 1, 0, 4, 0, 0, 1, 1, 4, 6, 2], 'py_constants': [], 'args': 1, 'stack': 3, 'constants': [pi, 1]} + {'args': 1, + 'code': [0, 0, 1, 0, 4, 0, 0, 1, 1, 4, 6, 2], + 'constants': [pi, 1], + 'domain': None, + 'py_constants': [], + 'stack': 3} sage: v.op_list() [('load_arg', 0), ('load_const', pi), 'add', ('load_arg', 0), ('load_const', 1), 'add', 'mul', 'return'] """ @@ -2339,7 +2359,12 @@ cdef class Wrapper: EXAMPLES:: sage: fast_callable(sin(x)/x, vars=[x], domain=RDF).get_orig_args() - {'domain': Real Double Field, 'code': [0, 0, 16, 0, 0, 8, 2], 'py_constants': [], 'args': 1, 'stack': 2, 'constants': []} + {'args': 1, + 'code': [0, 0, 16, 0, 0, 8, 2], + 'constants': [], + 'domain': Real Double Field, + 'py_constants': [], + 'stack': 2} """ return self._orig_args diff --git a/src/sage/ext/fast_eval.pyx b/src/sage/ext/fast_eval.pyx index 939e9f39c57..545548a640f 100644 --- a/src/sage/ext/fast_eval.pyx +++ b/src/sage/ext/fast_eval.pyx @@ -467,8 +467,8 @@ cdef class FastDoubleFunc: 998.5 sage: h.is_pure_c() False - sage: list(h) # random address - ['load 0', 'push 1.5', 'py_call at 0x9fedf70>(2)'] + sage: list(h) + ['load 0', 'push 1.5', 'py_call at 0x...>(2)'] Here's a more complicated expression: sage: from sage.ext.fast_eval import fast_float_constant, fast_float_arg @@ -1310,8 +1310,8 @@ def fast_float_func(f, *args): -5.0 This is all that goes on under the hood: - sage: h.op_list() # random memory address - ['load 0', 'load 1', 'py_call at 0xb62b230>(2)'] + sage: h.op_list() + ['load 0', 'load 1', 'py_call at 0x...>(2)'] """ return FastDoubleFunc('callable', f, *args) diff --git a/src/sage/finance/time_series.pyx b/src/sage/finance/time_series.pyx index cffb9ddaf99..15c5a84490c 100644 --- a/src/sage/finance/time_series.pyx +++ b/src/sage/finance/time_series.pyx @@ -1033,6 +1033,7 @@ cdef class TimeSeries: Draw a plot of a time series:: sage: finance.TimeSeries([1..10]).show() + Graphics object consisting of 1 graphics primitive """ return self.plot(*args, **kwds) @@ -1058,9 +1059,13 @@ cdef class TimeSeries: sage: v = finance.TimeSeries([5,4,1.3,2,8,10,3,-5]); v [5.0000, 4.0000, 1.3000, 2.0000, 8.0000, 10.0000, 3.0000, -5.0000] sage: v.plot() + Graphics object consisting of 1 graphics primitive sage: v.plot(points=True) + Graphics object consisting of 1 graphics primitive sage: v.plot() + v.plot(points=True, rgbcolor='red') + Graphics object consisting of 2 graphics primitives sage: v.plot() + v.plot(points=True, rgbcolor='red', pointsize=50) + Graphics object consisting of 2 graphics primitives """ from sage.plot.all import line, point cdef Py_ssize_t s @@ -1979,10 +1984,12 @@ cdef class TimeSeries: sage: v = finance.TimeSeries([1..50]) sage: v.plot_histogram(bins=10) + Graphics object consisting of 10 graphics primitives :: sage: v.plot_histogram(bins=3,normalize=False,aspect_ratio=1) + Graphics object consisting of 3 graphics primitives """ from sage.plot.all import polygon counts, intervals = self.histogram(bins, normalize=normalize) @@ -2021,6 +2028,7 @@ cdef class TimeSeries: sage: v = finance.TimeSeries(1000).randomize() sage: v.plot_candlestick(bins=20) + Graphics object consisting of 40 graphics primitives """ from sage.plot.all import line, polygon, Graphics diff --git a/src/sage/functions/bessel.py b/src/sage/functions/bessel.py index dcbb808d8d6..a5c1b93b74b 100644 --- a/src/sage/functions/bessel.py +++ b/src/sage/functions/bessel.py @@ -111,11 +111,13 @@ sage: f(x) = Bessel(0)(x); f x |--> bessel_J(0, x) sage: plot(f, (x, 1, 10)) + Graphics object consisting of 1 graphics primitive Visualize the Bessel Y function on the complex plane (set plot_points to a higher value to get more detail):: sage: complex_plot(bessel_Y(0, x), (-5, 5), (-5, 5), plot_points=20) + Graphics object consisting of 1 graphics primitive Evaluate a combination of Bessel functions:: @@ -273,7 +275,9 @@ class Function_Bessel_J(BuiltinFunction): Visualization (set plot_points to a higher value to get more detail):: sage: plot(bessel_J(1,x), (x,0,5), color='blue') + Graphics object consisting of 1 graphics primitive sage: complex_plot(bessel_J(1, x), (-5, 5), (-5, 5), plot_points=20) + Graphics object consisting of 1 graphics primitive ALGORITHM: @@ -425,7 +429,9 @@ class Function_Bessel_Y(BuiltinFunction): Visualization (set plot_points to a higher value to get more detail):: sage: plot(bessel_Y(1,x), (x,0,5), color='blue') + Graphics object consisting of 1 graphics primitive sage: complex_plot(bessel_Y(1, x), (-5, 5), (-5, 5), plot_points=20) + Graphics object consisting of 1 graphics primitive ALGORITHM: @@ -579,7 +585,9 @@ class Function_Bessel_I(BuiltinFunction): Visualization (set plot_points to a higher value to get more detail):: sage: plot(bessel_I(1,x), (x,0,5), color='blue') + Graphics object consisting of 1 graphics primitive sage: complex_plot(bessel_I(1, x), (-5, 5), (-5, 5), plot_points=20) + Graphics object consisting of 1 graphics primitive ALGORITHM: @@ -744,7 +752,9 @@ class Function_Bessel_K(BuiltinFunction): Visualization (set plot_points to a higher value to get more detail):: sage: plot(bessel_K(1,x), (x,0,5), color='blue') + Graphics object consisting of 1 graphics primitive sage: complex_plot(bessel_K(1, x), (-5, 5), (-5, 5), plot_points=20) + Graphics object consisting of 1 graphics primitive ALGORITHM: @@ -963,14 +973,17 @@ def Bessel(*args, **kwds): 1 sage: plot(f, (x,0,5)) + Graphics object consisting of 1 graphics primitive Plotting:: sage: f(x) = Bessel(0)(x); f x |--> bessel_J(0, x) sage: plot(f, (x, 1, 10)) + Graphics object consisting of 1 graphics primitive sage: plot([ Bessel(i, 'J') for i in range(5) ], 2, 10) + Graphics object consisting of 5 graphics primitives sage: G = Graphics() sage: G += sum([ plot(Bessel(i), 0, 4*pi, rgbcolor=hue(sin(pi*i/10))) for i in range(5) ]) diff --git a/src/sage/functions/hypergeometric.py b/src/sage/functions/hypergeometric.py index b43c7d11aea..c9b10f3c60c 100644 --- a/src/sage/functions/hypergeometric.py +++ b/src/sage/functions/hypergeometric.py @@ -86,7 +86,9 @@ Plotting:: sage: plot(hypergeometric([1, 1], [3, 3, 3], x), x, -30, 30) + Graphics object consisting of 1 graphics primitive sage: complex_plot(hypergeometric([x], [], 2), (-1, 1), (-1, 1)) + Graphics object consisting of 1 graphics primitive Numeric evaluation:: diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index b6f4a3c874d..c3ebc4e6ee1 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -697,6 +697,7 @@ def __init__(self): :: sage: plot(gamma1(x),(x,1,5)) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: diff --git a/src/sage/functions/piecewise.py b/src/sage/functions/piecewise.py index a0e2db6fe89..a3e206e8c59 100644 --- a/src/sage/functions/piecewise.py +++ b/src/sage/functions/piecewise.py @@ -432,6 +432,7 @@ def riemann_sum(self,N,mode=None): sage: Q = rsf.plot(rgbcolor=(0.7,0.6,0.6), plot_points=40) sage: L = add([line([[a,0],[a,f(x=a)]],rgbcolor=(0.7,0.6,0.6)) for (a,b),f in rsf.list()]) sage: P + Q + L + Graphics object consisting of 15 graphics primitives :: @@ -441,6 +442,7 @@ def riemann_sum(self,N,mode=None): sage: Q = rsf.plot(rgbcolor=(0.7,0.6,0.6), plot_points=40) sage: L = add([line([[a,0],[a,f(x=a)]],rgbcolor=(0.7,0.6,0.6)) for (a,b),f in rsf.list()]) sage: P + Q + L + Graphics object consisting of 17 graphics primitives """ if mode is None: rsum = self._riemann_sum_helper(N, lambda x0,x1: [[(x0,x1),SR(self(x0))]], @@ -479,6 +481,7 @@ def trapezoid(self,N): sage: Q = tf.plot(rgbcolor=(0.7,0.6,0.6), plot_points=40) sage: L = add([line([[a,0],[a,f(a)]],rgbcolor=(0.7,0.6,0.6)) for (a,b),f in tf.list()]) sage: P+Q+L + Graphics object consisting of 9 graphics primitives :: @@ -489,6 +492,7 @@ def trapezoid(self,N): sage: Q = tf.plot(rgbcolor=(0.7,0.6,0.6), plot_points=40) sage: L = add([line([[a,0],[a,f(a)]],rgbcolor=(0.7,0.6,0.6)) for (a,b),f in tf.list()]) sage: P+Q+L + Graphics object consisting of 14 graphics primitives TESTS: @@ -527,6 +531,7 @@ def trapezoid_integral_approximation(self,N): sage: a = f.integral(definite=True) sage: tt = text('area under curve = %s'%a, (1.5, -0.5)) sage: P + Q + t + tt + Graphics object consisting of 10 graphics primitives :: @@ -538,6 +543,7 @@ def trapezoid_integral_approximation(self,N): sage: a = f.integral(definite=True) sage: tt = text('area under curve = %s'%a, (1.5, -0.5)) sage: P+Q+t+tt + Graphics object consisting of 8 graphics primitives """ def f(x0, x1): f0, f1 = self(x0), self(x1) @@ -1008,6 +1014,7 @@ def tangent_line(self, pt): sage: P = f.plot(rgbcolor=(0.7,0.1,0.5), plot_points=40) sage: Q = tf.plot(rgbcolor=(0.7,0.2,0.2), plot_points=40) sage: P + Q + Graphics object consisting of 4 graphics primitives """ pt = QQ(pt) R = QQ[self.default_variable()] @@ -1034,6 +1041,7 @@ def plot(self, *args, **kwds): sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,10),f4]]) sage: P = f.plot(rgbcolor=(0.7,0.1,0), plot_points=40) sage: P + Graphics object consisting of 4 graphics primitives Remember: to view this, type show(P) or P.save("path/myplot.png") and then open it in a graphics viewer such as GIMP. diff --git a/src/sage/functions/prime_pi.pyx b/src/sage/functions/prime_pi.pyx index c832a1f5887..543d9e4df93 100644 --- a/src/sage/functions/prime_pi.pyx +++ b/src/sage/functions/prime_pi.pyx @@ -459,7 +459,9 @@ cdef class PrimePi(BuiltinFunction): EXAMPLES:: sage: plot(prime_pi, 1, 100) + Graphics object consisting of 1 graphics primitive sage: prime_pi.plot(-2, sqrt(2501), thickness=2, vertical_lines=False) + Graphics object consisting of 16 graphics primitives """ from sage.plot.step import plot_step_function if xmax < xmin: diff --git a/src/sage/functions/transcendental.py b/src/sage/functions/transcendental.py index 6dc4ba3da8f..37ba5b76872 100644 --- a/src/sage/functions/transcendental.py +++ b/src/sage/functions/transcendental.py @@ -367,6 +367,7 @@ class DickmanRho(BuiltinFunction): sage: dickman_rho(10.00000000000000000000000000000000000000) 2.77017183772595898875812120063434232634e-11 sage: plot(log(dickman_rho(x)), (x, 0, 15)) + Graphics object consisting of 1 graphics primitive AUTHORS: diff --git a/src/sage/game_theory/cooperative_game.py b/src/sage/game_theory/cooperative_game.py index dcd4b9de1f1..9e6f7296e4b 100644 --- a/src/sage/game_theory/cooperative_game.py +++ b/src/sage/game_theory/cooperative_game.py @@ -158,7 +158,7 @@ class CooperativeGame(SageObject): To compute the Shapley value in Sage is simple:: sage: letter_game.shapley_value() - {'A': 2, 'C': 35, 'B': 5} + {'A': 2, 'B': 5, 'C': 35} The following example implements a (trivial) 10 player characteristic function game with `v(c) = |c|` for all `c \in 2^{\Omega}`. @@ -230,7 +230,7 @@ class CooperativeGame(SageObject): ....: ('B', 'A', 'C',): 42} sage: letter_game = CooperativeGame(letter_function) sage: letter_game.shapley_value() - {'A': 2, 'C': 35, 'B': 5} + {'A': 2, 'B': 5, 'C': 35} sage: letter_game.is_monotone() True sage: letter_game.is_superadditive() diff --git a/src/sage/games/hexad.py b/src/sage/games/hexad.py index a054d7f8110..eab3d568793 100644 --- a/src/sage/games/hexad.py +++ b/src/sage/games/hexad.py @@ -121,9 +121,9 @@ def picture_set(A,L): sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") sage: picture_set(M.picture00, M.cross[2]) - set([8, 9, 10, 5, 7]) + {5, 7, 8, 9, 10} sage: picture_set(M.picture02, M.square[7]) - set([8, 2, 3, 5]) + {2, 3, 5, 8} """ return set([A[x] for x in L]) diff --git a/src/sage/games/quantumino.py b/src/sage/games/quantumino.py index 812529b5846..c87a9367de5 100644 --- a/src/sage/games/quantumino.py +++ b/src/sage/games/quantumino.py @@ -54,6 +54,7 @@ sage: from sage.games.quantumino import show_pentaminos sage: show_pentaminos() + Graphics3d Object To solve the puzzle where the pentamino numbered 12 is put aside:: @@ -63,6 +64,7 @@ Quantumino state where the following pentamino is put aside : Polyomino: [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1)], Color: blue sage: s.show3d() # long time (<1s) + Graphics3d Object To remove the frame:: @@ -75,6 +77,7 @@ Quantumino state where the following pentamino is put aside : Polyomino: [(0, 0, 0), (0, 1, 0), (0, 2, 0), (0, 2, 1), (1, 0, 0)], Color: orange sage: s.show3d() # long time (<1s) + Graphics3d Object The solution is iterable. This may be used to explicitly list the positions of each pentamino:: @@ -479,6 +482,7 @@ def solve(self, partial=None): Quantumino state where the following pentamino is put aside : Polyomino: [(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0), (1, 1, 0)], Color: yellow sage: s.show3d() # long time (< 1s) + Graphics3d Object The explicit solution:: diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py index 7f4bdb8c8d7..a36dd8f319b 100644 --- a/src/sage/geometry/cone.py +++ b/src/sage/geometry/cone.py @@ -61,7 +61,7 @@ N(-1, 0, 0) in 3-d lattice N sage: rays.set() - frozenset([N(1, 0, 0), N(-1, 0, 0), N(0, 1, 0), N(0, 0, 1), N(0, -1, 0)]) + frozenset({N(-1, 0, 0), N(0, -1, 0), N(0, 0, 1), N(0, 1, 0), N(1, 0, 0)}) sage: rays.matrix() [ 0 0 1] [ 0 1 0] @@ -945,6 +945,7 @@ def plot(self, **options): sage: quadrant = Cone([(1,0), (0,1)]) sage: quadrant.plot() + Graphics object consisting of 9 graphics primitives """ tp = ToricPlotter(options, self.lattice().degree(), self.rays()) return tp.plot_lattice() + tp.plot_rays() + tp.plot_generators() @@ -2861,13 +2862,12 @@ def line_set(self): sage: halfplane = Cone([(1,0), (0,1), (-1,0)]) sage: halfplane.line_set() - doctest:...: DeprecationWarning: - line_set(...) is deprecated, please use lines().set() instead! + doctest:...: DeprecationWarning: line_set(...) is deprecated, please use lines().set() instead! See http://trac.sagemath.org/12544 for details. - frozenset([N(1, 0)]) + frozenset({N(1, 0)}) sage: fullplane = Cone([(1,0), (0,1), (-1,-1)]) sage: fullplane.line_set() - frozenset([N(0, 1), N(1, 0)]) + frozenset({N(0, 1), N(1, 0)}) """ deprecation(12544, "line_set(...) is deprecated, " "please use lines().set() instead!") @@ -2947,6 +2947,7 @@ def plot(self, **options): sage: quadrant = Cone([(1,0), (0,1)]) sage: quadrant.plot() + Graphics object consisting of 9 graphics primitives """ # What to do with 3-d cones in 5-d? Use some projection method? deg = self.lattice().degree() diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index 9d6bcea8669..60d3bdba84f 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -1622,10 +1622,9 @@ def _ray_to_cones(self, i=None): sage: fan = toric_varieties.P1xP1().fan() sage: fan._ray_to_cones(0) - frozenset([0, 3]) + frozenset({0, 3}) sage: fan._ray_to_cones() - (frozenset([0, 3]), frozenset([1, 2]), - frozenset([0, 1]), frozenset([2, 3])) + (frozenset({0, 3}), frozenset({1, 2}), frozenset({0, 1}), frozenset({2, 3})) """ # This function is close to self(1)[i].star_generator_indices(), but # it does not require computation of the cone lattice and is @@ -2548,11 +2547,11 @@ def _2d_echelon_forms(self): sage: fan = toric_varieties.dP8().fan() sage: fan._2d_echelon_forms() - frozenset([[ 1 0 -1 1] - [ 0 1 0 -1], [ 1 0 -1 -1] - [ 0 1 0 -1], [ 1 0 -1 0] - [ 0 1 1 -1], [ 1 0 -1 0] - [ 0 1 -1 -1]]) + frozenset({[ 1 0 -1 -1] + [ 0 1 0 -1], [ 1 0 -1 0] + [ 0 1 -1 -1], [ 1 0 -1 0] + [ 0 1 1 -1], [ 1 0 -1 1] + [ 0 1 0 -1]}) """ from sage.geometry.fan_isomorphism import fan_2d_echelon_forms return fan_2d_echelon_forms(self) @@ -2781,6 +2780,7 @@ def plot(self, **options): sage: fan = toric_varieties.dP6().fan() sage: fan.plot() + Graphics object consisting of 31 graphics primitives """ tp = ToricPlotter(options, self.lattice().degree(), self.rays()) result = tp.plot_lattice() + tp.plot_rays() + tp.plot_generators() @@ -2988,7 +2988,10 @@ def primitive_collections(self): sage: fan = Fan([[0,1,3],[3,4],[2,0],[1,2,4]], [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)]) sage: fan.primitive_collections() - [frozenset([0, 4]), frozenset([2, 3]), frozenset([0, 1, 2]), frozenset([1, 3, 4])] + [frozenset({0, 4}), + frozenset({2, 3}), + frozenset({0, 1, 2}), + frozenset({1, 3, 4})] """ try: return self._primitive_collections @@ -3275,7 +3278,7 @@ def complex(self, base_ring=ZZ, extended=False): sage: K_extended = fan.complex(extended=True); K_extended Chain complex with at most 5 nonzero terms over Integer Ring sage: K_extended.homology() - {0: 0, 1: 0, 2: 0, 3: 0, -1: 0} + {-1: 0, 0: 0, 1: 0, 2: 0, 3: 0} Homology computations are much faster over `\QQ` if you don't care about the torsion coefficients:: @@ -3283,10 +3286,10 @@ def complex(self, base_ring=ZZ, extended=False): sage: toric_varieties.P2_123().fan().complex(extended=True, base_ring=QQ) Chain complex with at most 4 nonzero terms over Rational Field sage: _.homology() - {0: Vector space of dimension 0 over Rational Field, + {-1: Vector space of dimension 0 over Rational Field, + 0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field, - 2: Vector space of dimension 0 over Rational Field, - -1: Vector space of dimension 0 over Rational Field} + 2: Vector space of dimension 0 over Rational Field} The extended complex is only defined for complete fans:: diff --git a/src/sage/geometry/fan_isomorphism.py b/src/sage/geometry/fan_isomorphism.py index d42dcccca88..5c4804e9b8d 100644 --- a/src/sage/geometry/fan_isomorphism.py +++ b/src/sage/geometry/fan_isomorphism.py @@ -317,8 +317,8 @@ def fan_2d_echelon_forms(fan): sage: fan = toric_varieties.P2().fan() sage: from sage.geometry.fan_isomorphism import fan_2d_echelon_forms sage: fan_2d_echelon_forms(fan) - frozenset([[ 1 0 -1] - [ 0 1 -1]]) + frozenset({[ 1 0 -1] + [ 0 1 -1]}) sage: fan = toric_varieties.dP7().fan() sage: list(fan_2d_echelon_forms(fan)) diff --git a/src/sage/geometry/fan_morphism.py b/src/sage/geometry/fan_morphism.py index d6278a9bcd3..bb1b22d1ca9 100644 --- a/src/sage/geometry/fan_morphism.py +++ b/src/sage/geometry/fan_morphism.py @@ -358,10 +358,14 @@ def _RISGIS(self): sage: fm = FanMorphism(identity_matrix(2), ... normal, face, subdivide=True) sage: fm._RISGIS() - (frozenset([3]), frozenset([2]), - frozenset([1]), frozenset([0]), - frozenset([1, 3]), frozenset([0, 1]), - frozenset([0, 2]), frozenset([2, 3])) + (frozenset({3}), + frozenset({2}), + frozenset({1}), + frozenset({0}), + frozenset({1, 3}), + frozenset({0, 1}), + frozenset({0, 2}), + frozenset({2, 3})) """ if "_RISGIS_" not in self.__dict__: try: diff --git a/src/sage/geometry/hyperplane_arrangement/arrangement.py b/src/sage/geometry/hyperplane_arrangement/arrangement.py index bcb82465d3f..adddb797bb9 100644 --- a/src/sage/geometry/hyperplane_arrangement/arrangement.py +++ b/src/sage/geometry/hyperplane_arrangement/arrangement.py @@ -621,6 +621,7 @@ def plot(self, **kwds): sage: L. = HyperplaneArrangements(QQ) sage: L(x, y, x+y-2).plot() + Graphics object consisting of 3 graphics primitives """ from sage.geometry.hyperplane_arrangement.plot import plot return plot(self, **kwds) @@ -1353,6 +1354,7 @@ def vertices(self, exclude_sandwiched=False): sage: A.vertices() ((-2/3, 1/3), (-1/3, -1/3), (0, -1), (0, 0), (1/3, -2/3), (2/3, -1/3)) sage: point2d(A.vertices(), size=20) + A.plot() + Graphics object consisting of 7 graphics primitives sage: H. = HyperplaneArrangements(QQ) sage: chessboard = [] diff --git a/src/sage/geometry/hyperplane_arrangement/hyperplane.py b/src/sage/geometry/hyperplane_arrangement/hyperplane.py index e54be4136cb..3f9e05a9c8f 100644 --- a/src/sage/geometry/hyperplane_arrangement/hyperplane.py +++ b/src/sage/geometry/hyperplane_arrangement/hyperplane.py @@ -602,6 +602,7 @@ def plot(self, **kwds): sage: L. = HyperplaneArrangements(QQ) sage: (x+y-2).plot() + Graphics object consisting of 2 graphics primitives """ from sage.geometry.hyperplane_arrangement.plot import plot_hyperplane return plot_hyperplane(self, **kwds) diff --git a/src/sage/geometry/hyperplane_arrangement/plot.py b/src/sage/geometry/hyperplane_arrangement/plot.py index 7f55dbccdd7..46415e83292 100644 --- a/src/sage/geometry/hyperplane_arrangement/plot.py +++ b/src/sage/geometry/hyperplane_arrangement/plot.py @@ -57,18 +57,25 @@ sage: H3. = HyperplaneArrangements(QQ) sage: A = H3([(1,0,0), 0], [(0,0,1), 5]) sage: A.plot(hyperplane_opacities=0.5, hyperplane_labels=True, hyperplane_legend=False) + Graphics3d Object sage: c = H3([(1,0,0),0], [(0,0,1),5]) sage: c.plot(ranges=10) + Graphics3d Object sage: c.plot(ranges=[[9.5,10], [-3,3]]) + Graphics3d Object sage: c.plot(ranges=[[[9.5,10], [-3,3]], [[-6,6], [-5,5]]]) + Graphics3d Object sage: H2. = HyperplaneArrangements(QQ) sage: h = H2([(1,1),0], [(1,-1),0], [(0,1),2]) sage: h.plot(ranges=20) + Graphics object consisting of 3 graphics primitives sage: h.plot(ranges=[-1, 10]) + Graphics object consisting of 3 graphics primitives sage: h.plot(ranges=[[-1, 1], [-5, 5], [-1, 10]]) + Graphics object consisting of 3 graphics primitives sage: a = hyperplane_arrangements.coordinate(3) sage: opts = {'hyperplane_colors':['yellow', 'green', 'blue']} @@ -77,18 +84,24 @@ sage: opts['hyperplane_legend'] = False sage: opts['hyperplane_opacities'] = 0.7 sage: a.plot(**opts) + Graphics3d Object sage: opts['hyperplane_labels'] = 'short' sage: a.plot(**opts) + Graphics3d Object sage: H. = HyperplaneArrangements(QQ) sage: pts = H(3*u+4, 2*u+5, 7*u+1) sage: pts.plot(hyperplane_colors=['yellow','black','blue']) + Graphics object consisting of 3 graphics primitives sage: pts.plot(point_sizes=[50,100,200], hyperplane_colors='blue') + Graphics object consisting of 3 graphics primitives sage: H. = HyperplaneArrangements(QQ) sage: a = H(x, y+1, y+2) sage: a.plot(hyperplane_labels=True,label_colors='blue',label_fontsize=18) + Graphics3d Object sage: a.plot(hyperplane_labels=True,label_colors=['red','green','black']) + Graphics3d Object """ from copy import copy @@ -133,6 +146,7 @@ def plot(hyperplane_arrangement, **kwds): sage: B = hyperplane_arrangements.semiorder(4) sage: B.plot() Displaying the essentialization. + Graphics3d Object """ N = len(hyperplane_arrangement) dim = hyperplane_arrangement.dimension() @@ -319,25 +333,34 @@ def plot_hyperplane(hyperplane, **kwds): sage: H1. = HyperplaneArrangements(QQ) sage: a = 3*x + 4 sage: a.plot() # indirect doctest + Graphics object consisting of 3 graphics primitives sage: a.plot(point_size=100,hyperplane_label='hello') + Graphics object consisting of 3 graphics primitives sage: H2. = HyperplaneArrangements(QQ) sage: b = 3*x + 4*y + 5 sage: b.plot() + Graphics object consisting of 2 graphics primitives sage: b.plot(ranges=(1,5),label_offset=(2,-1)) + Graphics object consisting of 2 graphics primitives sage: opts = {'hyperplane_label':True, 'label_color':'green', ....: 'label_fontsize':24, 'label_offset':(0,1.5)} sage: b.plot(**opts) + Graphics object consisting of 2 graphics primitives sage: H3. = HyperplaneArrangements(QQ) sage: c = 2*x + 3*y + 4*z + 5 sage: c.plot() + Graphics3d Object sage: c.plot(label_offset=(1,0,1), color='green', label_color='red', frame=False) + Graphics3d Object sage: d = -3*x + 2*y + 2*z + 3 sage: d.plot(opacity=0.8) + Graphics3d Object sage: e = 4*x + 2*z + 3 sage: e.plot(ranges=[[-1,1],[0,8]], label_offset=(2,2,1), aspect_ratio=1) + Graphics3d Object """ if hyperplane.base_ring().characteristic() != 0: raise NotImplementedError('base field must have characteristic zero') @@ -473,12 +496,15 @@ def legend_3d(hyperplane_arrangement, hyperplane_colors, length): sage: a = hyperplane_arrangements.semiorder(3) sage: from sage.geometry.hyperplane_arrangement.plot import legend_3d sage: legend_3d(a, colors.values()[:6],length='long') + Graphics object consisting of 6 graphics primitives sage: b = hyperplane_arrangements.semiorder(4) sage: c = b.essentialization() sage: legend_3d(c, colors.values()[:12], length='long') + Graphics object consisting of 12 graphics primitives sage: legend_3d(c, colors.values()[:12], length='short') + Graphics object consisting of 12 graphics primitives sage: p = legend_3d(c, colors.values()[:12], length='short') sage: p.set_legend_options(ncol=4) diff --git a/src/sage/geometry/integral_points.pyx b/src/sage/geometry/integral_points.pyx index 98dc9cedc37..bcfc18101ae 100644 --- a/src/sage/geometry/integral_points.pyx +++ b/src/sage/geometry/integral_points.pyx @@ -501,14 +501,14 @@ def rectangular_box_points(box_min, box_max, polyhedron=None, sage: cube.Hrepresentation(2) An inequality (-1, 0, 0) x + 1 >= 0 sage: rectangular_box_points([0]*3, [1]*3, cube, return_saturated=True) - (((0, 0, 0), frozenset([])), - ((0, 0, 1), frozenset([0])), - ((0, 1, 0), frozenset([1])), - ((0, 1, 1), frozenset([0, 1])), - ((1, 0, 0), frozenset([2])), - ((1, 0, 1), frozenset([0, 2])), - ((1, 1, 0), frozenset([1, 2])), - ((1, 1, 1), frozenset([0, 1, 2]))) + (((0, 0, 0), frozenset()), + ((0, 0, 1), frozenset({0})), + ((0, 1, 0), frozenset({1})), + ((0, 1, 1), frozenset({0, 1})), + ((1, 0, 0), frozenset({2})), + ((1, 0, 1), frozenset({0, 2})), + ((1, 1, 0), frozenset({1, 2})), + ((1, 1, 1), frozenset({0, 1, 2}))) """ assert len(box_min)==len(box_max) assert not (count_only and return_saturated) @@ -1322,11 +1322,11 @@ cdef class InequalityCollection: sage: ieqs.prepare_next_to_inner_loop([-1,0]) sage: ieqs.prepare_inner_loop([-1,0]) sage: ieqs.satisfied_as_equalities(-1) - frozenset([1]) + frozenset({1}) sage: ieqs.satisfied_as_equalities(0) - frozenset([0, 1]) + frozenset({0, 1}) sage: ieqs.satisfied_as_equalities(1) - frozenset([1]) + frozenset({1}) """ cdef int i result = [] diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index 748c8d78f16..a6b7e8dbcfd 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -3075,6 +3075,7 @@ def plot3d(self, sage: c = lattice_polytope.cross_polytope(3).polar() sage: c.plot3d() + Graphics3d Object Plot without facets and points, shown without the frame:: @@ -3083,16 +3084,19 @@ def plot3d(self, Plot with facets of different colors:: sage: c.plot3d(facet_colors=rainbow(c.nfacets(), 'rgbtuple')) + Graphics3d Object It is also possible to plot lower dimensional polytops in 3D (let's also change labels of vertices):: sage: lattice_polytope.cross_polytope(2).plot3d(vlabels=["A", "B", "C", "D"]) + Graphics3d Object TESTS:: sage: p = LatticePolytope([[0,0,0],[0,1,1],[1,0,1],[1,1,0]]) sage: p.plot3d() + Graphics3d Object """ dim = self.dim() amb_dim = self.ambient_dim() diff --git a/src/sage/geometry/point_collection.pyx b/src/sage/geometry/point_collection.pyx index 434c4be73dd..648295ff1fe 100644 --- a/src/sage/geometry/point_collection.pyx +++ b/src/sage/geometry/point_collection.pyx @@ -40,7 +40,7 @@ container for points of the same space that * allows (cached) access to alternative representations:: sage: c.set() - frozenset([N(0, 1, 1), N(1, 1, 1), N(0, 0, 1), N(1, 0, 1)]) + frozenset({N(0, 0, 1), N(0, 1, 1), N(1, 0, 1), N(1, 1, 1)}) * allows introduction of additional methods:: @@ -888,7 +888,7 @@ cdef class PointCollection(SageObject): sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays() sage: c.set() - frozenset([N(0, 1, 1), N(1, 1, 1), N(0, 0, 1), N(1, 0, 1)]) + frozenset({N(0, 0, 1), N(0, 1, 1), N(1, 0, 1), N(1, 1, 1)}) """ if self._set is None: self._set = frozenset(self._points) diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index d5eddb6aa8d..48f86e50fec 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -492,35 +492,55 @@ def plot(self, By default, the wireframe is rendered in blue and the fill in green:: sage: square.plot() + Graphics object consisting of 6 graphics primitives sage: point.plot() + Graphics object consisting of 1 graphics primitive sage: line.plot() + Graphics object consisting of 2 graphics primitives sage: cube.plot() + Graphics3d Object sage: hypercube.plot() + Graphics3d Object Draw the lines in red and nothing else:: sage: square.plot(point=False, line='red', polygon=False) + Graphics object consisting of 4 graphics primitives sage: point.plot(point=False, line='red', polygon=False) + Graphics object consisting of 0 graphics primitives sage: line.plot(point=False, line='red', polygon=False) + Graphics object consisting of 1 graphics primitive sage: cube.plot(point=False, line='red', polygon=False) + Graphics3d Object sage: hypercube.plot(point=False, line='red', polygon=False) + Graphics3d Object Draw points in red, no lines, and a blue polygon:: sage: square.plot(point={'color':'red'}, line=False, polygon=(0,0,1)) + Graphics object consisting of 2 graphics primitives sage: point.plot(point={'color':'red'}, line=False, polygon=(0,0,1)) + Graphics object consisting of 1 graphics primitive sage: line.plot(point={'color':'red'}, line=False, polygon=(0,0,1)) + Graphics object consisting of 1 graphics primitive sage: cube.plot(point={'color':'red'}, line=False, polygon=(0,0,1)) + Graphics3d Object sage: hypercube.plot(point={'color':'red'}, line=False, polygon=(0,0,1)) + Graphics3d Object If we instead use the ``fill`` and ``wireframe`` options, the coloring depends on the dimension of the object:: sage: square.plot(fill='green', wireframe='red') + Graphics object consisting of 6 graphics primitives sage: point.plot(fill='green', wireframe='red') + Graphics object consisting of 1 graphics primitive sage: line.plot(fill='green', wireframe='red') + Graphics object consisting of 2 graphics primitives sage: cube.plot(fill='green', wireframe='red') + Graphics3d Object sage: hypercube.plot(fill='green', wireframe='red') + Graphics3d Object TESTS:: @@ -3062,6 +3082,7 @@ def face_lattice(self): sage: [len(x) for x in c5_20_fl.level_sets()] # long time [1, 20, 190, 580, 680, 272, 1] sage: polytopes.n_cube(2).face_lattice().plot() + Graphics object consisting of 27 graphics primitives sage: level_sets = polytopes.cross_polytope(2).face_lattice().level_sets() sage: print level_sets[0], level_sets[-1] [<>] [<0,1,2,3>] diff --git a/src/sage/geometry/polyhedron/library.py b/src/sage/geometry/polyhedron/library.py index 44ed8bf641c..b6e79bb13b1 100644 --- a/src/sage/geometry/polyhedron/library.py +++ b/src/sage/geometry/polyhedron/library.py @@ -582,6 +582,7 @@ def permutahedron(self, n, project = True): sage: perm4 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices sage: polytopes.permutahedron(5).show() # long time + Graphics3d Object """ verts = range(1,n+1) verts = Permutations(verts).list() diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index 1e9f4c1ce8d..bd1c33791f8 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -46,6 +46,7 @@ def render_2d(projection, *args, **kwds): sage: p4 = Polyhedron(vertices=[[2,0]], rays=[[1,-1]], lines=[[1,1]]) sage: q4 = p4.projection() sage: q1.plot() + q2.plot() + q3.plot() + q4.plot() + Graphics object consisting of 17 graphics primitives sage: from sage.geometry.polyhedron.plot import render_2d sage: q = render_2d(p1.projection()) doctest:...: DeprecationWarning: use Projection.render_2d instead @@ -77,17 +78,26 @@ def render_3d(projection, *args, **kwds): sage: p2 = Polyhedron(vertices=[[2,0,0], [0,2,0], [0,0,2]]) sage: p3 = Polyhedron(vertices=[[1,0,0], [0,1,0], [0,0,1]], rays=[[-1,-1,-1]]) sage: p1.projection().plot() + p2.projection().plot() + p3.projection().plot() + Graphics3d Object It correctly handles various degenerate cases:: sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).plot() # whole space + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], lines=[[0,1,0],[0,0,1]]).plot() # half space + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], lines=[[0,1,0],[0,0,1]]).plot() # R^2 in R^3 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0],[0,0,1]], lines=[[1,0,0]]).plot() # quadrant wedge in R^2 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0]], lines=[[1,0,0]]).plot() # upper half plane in R^3 + Graphics3d Object sage: Polyhedron(lines=[[1,0,0]]).plot() # R^1 in R^2 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0]]).plot() # Half-line in R^3 + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]]).plot() # point in R^3 + Graphics3d Object """ from sage.misc.superseded import deprecation deprecation(16625, 'use Projection.render_3d instead') @@ -124,7 +134,9 @@ def render_4d(polyhedron, point_opts={}, line_opts={}, polygon_opts={}, projecti sage: poly A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 24 vertices sage: poly.plot() + Graphics3d Object sage: poly.plot(projection_direction=[2,5,11,17]) + Graphics3d Object sage: type( poly.plot() ) @@ -459,10 +471,12 @@ def __init__(self, polyhedron, proj=projection_func_identity): sage: Projection(p, lambda x: [x[1],x[2]] ) # another way of doing the same projection The projection of a polyhedron into 2 dimensions sage: _.plot() # plot of the projected icosahedron in 2d + Graphics object consisting of 51 graphics primitives sage: proj = Projection(p) sage: proj.stereographic([1,2,3]) The projection of a polyhedron into 2 dimensions sage: proj.plot() + Graphics object consisting of 51 graphics primitives sage: TestSuite(proj).run(skip='_test_pickling') """ self.parent_polyhedron = polyhedron @@ -560,6 +574,7 @@ def stereographic(self, projection_point=None): sage: proj #long time The projection of a polyhedron into 3 dimensions sage: proj.stereographic([5,2,3]).plot() #long time + Graphics object consisting of 123 graphics primitives sage: Projection( polytopes.twenty_four_cell() ).stereographic([2,0,0,0]) The projection of a polyhedron into 3 dimensions """ @@ -599,6 +614,7 @@ def schlegel(self, projection_direction=None, height=1.1): sage: Projection(cube4).schlegel([1,0,0,0]) The projection of a polyhedron into 3 dimensions sage: _.plot() + Graphics3d Object TESTS:: @@ -1156,6 +1172,7 @@ def render_1d(self, point_opts={}, line_opts={}, polygon_opts={}): EXAMPLES:: sage: Polyhedron([(0,), (1,)]).projection().render_1d() + Graphics object consisting of 2 graphics primitives """ plt = Graphics() if isinstance(point_opts, dict): @@ -1183,6 +1200,7 @@ def render_2d(self, point_opts={}, line_opts={}, polygon_opts={}): sage: p4 = Polyhedron(vertices=[[2,0]], rays=[[1,-1]], lines=[[1,1]]) sage: q4 = p4.projection() sage: q1.plot() + q2.plot() + q3.plot() + q4.plot() + Graphics object consisting of 17 graphics primitives """ plt = Graphics() if isinstance(point_opts, dict): @@ -1208,19 +1226,28 @@ def render_3d(self, point_opts={}, line_opts={}, polygon_opts={}): sage: p2 = Polyhedron(vertices=[[2,0,0], [0,2,0], [0,0,2]]) sage: p3 = Polyhedron(vertices=[[1,0,0], [0,1,0], [0,0,1]], rays=[[-1,-1,-1]]) sage: p1.projection().plot() + p2.projection().plot() + p3.projection().plot() + Graphics3d Object It correctly handles various degenerate cases:: sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).plot() # whole space + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], ....: lines=[[0,1,0],[0,0,1]]).plot() # half space + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], ....: lines=[[0,1,0],[0,0,1]]).plot() # R^2 in R^3 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0],[0,0,1]], lines=[[1,0,0]]).plot() # quadrant wedge in R^2 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0]], lines=[[1,0,0]]).plot() # upper half plane in R^3 + Graphics3d Object sage: Polyhedron(lines=[[1,0,0]]).plot() # R^1 in R^2 + Graphics3d Object sage: Polyhedron(rays=[[0,1,0]]).plot() # Half-line in R^3 + Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]]).plot() # point in R^3 + Graphics3d Object """ from sage.plot.plot3d.base import Graphics3d plt = Graphics3d() diff --git a/src/sage/geometry/polyhedron/ppl_lattice_polygon.py b/src/sage/geometry/polyhedron/ppl_lattice_polygon.py index e171f97d4ab..ad003898153 100644 --- a/src/sage/geometry/polyhedron/ppl_lattice_polygon.py +++ b/src/sage/geometry/polyhedron/ppl_lattice_polygon.py @@ -411,7 +411,9 @@ def plot(self): sage: P = LatticePolytope_PPL((1,0), (0,1), (0,0), (2,2)) sage: P.plot() # not tested sage: LatticePolytope_PPL([0], [1]).plot() + Graphics object consisting of 2 graphics primitives sage: LatticePolytope_PPL([0]).plot() + Graphics object consisting of 1 graphics primitive """ from sage.plot.point import point2d from sage.plot.polygon import polygon2d diff --git a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py index 64f43c66b76..5d8922e2ccc 100644 --- a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py +++ b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py @@ -49,7 +49,7 @@ sage: fibers = [ f.vertices() for f in square.fibration_generator(1) ]; fibers [((1, 0), (-1, 0)), ((0, 1), (0, -1)), ((-1, -1), (1, 1)), ((-1, 1), (1, -1))] sage: square.pointsets_mod_automorphism(fibers) - (frozenset([(0, 1), (0, -1)]), frozenset([(1, 1), (-1, -1)])) + (frozenset({(0, -1), (0, 1)}), frozenset({(-1, -1), (1, 1)})) AUTHORS: @@ -434,11 +434,11 @@ def _integral_points_saturating(self): sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: quad = LatticePolytope_PPL((-1,-1),(0,1),(1,0),(1,1)) sage: quad._integral_points_saturating() - (((-1, -1), frozenset([0, 1])), - ((0, 0), frozenset([])), - ((0, 1), frozenset([0, 3])), - ((1, 0), frozenset([1, 2])), - ((1, 1), frozenset([2, 3]))) + (((-1, -1), frozenset({0, 1})), + ((0, 0), frozenset()), + ((0, 1), frozenset({0, 3})), + ((1, 0), frozenset({1, 2})), + ((1, 1), frozenset({2, 3}))) """ if self.is_empty(): return tuple() @@ -653,7 +653,7 @@ def pointsets_mod_automorphism(self, pointsets): sage: square = LatticePolytope_PPL((-1,-1),(-1,1),(1,-1),(1,1)) sage: fibers = [ f.vertices() for f in square.fibration_generator(1) ] sage: square.pointsets_mod_automorphism(fibers) - (frozenset([(0, 1), (0, -1)]), frozenset([(1, 1), (-1, -1)])) + (frozenset({(0, -1), (0, 1)}), frozenset({(-1, -1), (1, 1)})) sage: cell24 = LatticePolytope_PPL( ... (1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1),(1,-1,-1,1),(0,0,-1,1), @@ -662,9 +662,13 @@ def pointsets_mod_automorphism(self, pointsets): ... (0,1,1,-1),(-1,1,1,0),(-1,1,0,0),(-1,0,1,0),(0,-1,-1,1),(0,0,0,-1)) sage: fibers = [ f.vertices() for f in cell24.fibration_generator(2) ] sage: cell24.pointsets_mod_automorphism(fibers) # long time - (frozenset([(1, 0, -1, 0), (-1, 0, 1, 0), (0, -1, -1, 1), (0, 1, 1, -1)]), - frozenset([(-1, 0, 0, 0), (1, 0, 0, 0), (0, 0, 0, 1), - (1, 0, 0, -1), (0, 0, 0, -1), (-1, 0, 0, 1)])) + (frozenset({(-1, 0, 1, 0), (0, -1, -1, 1), (0, 1, 1, -1), (1, 0, -1, 0)}), + frozenset({(-1, 0, 0, 0), + (-1, 0, 0, 1), + (0, 0, 0, -1), + (0, 0, 0, 1), + (1, 0, 0, -1), + (1, 0, 0, 0)})) """ points = set() for ps in pointsets: @@ -1233,11 +1237,15 @@ def embed_in_reflexive_polytope(self, output='hom'): sage: polygon.embed_in_reflexive_polytope('polytope') A 2-dimensional lattice polytope in ZZ^2 with 3 vertices sage: polygon.embed_in_reflexive_polytope('points') - {(0, 0, 2, 1): (1, 0), (2, 1, 0, 2): (2, 1), - (0, 1, 2, 0): (0, 1), (1, 1, 1, 1): (1, 1), - (1, 2, 1, 0): (0, 2), (2, 2, 0, 1): (1, 2), - (2, 3, 0, 0): (0, 3), (1, 0, 1, 2): (2, 0), - (2, 0, 0, 3): (3, 0)} + {(0, 0, 2, 1): (1, 0), + (0, 1, 2, 0): (0, 1), + (1, 0, 1, 2): (2, 0), + (1, 1, 1, 1): (1, 1), + (1, 2, 1, 0): (0, 2), + (2, 0, 0, 3): (3, 0), + (2, 1, 0, 2): (2, 1), + (2, 2, 0, 1): (1, 2), + (2, 3, 0, 0): (0, 3)} sage: LatticePolytope_PPL((0,0), (4,0), (0,4)).embed_in_reflexive_polytope() Traceback (most recent call last): diff --git a/src/sage/geometry/riemannian_manifolds/parametrized_surface3d.py b/src/sage/geometry/riemannian_manifolds/parametrized_surface3d.py index e054b82c1a1..2be014021db 100644 --- a/src/sage/geometry/riemannian_manifolds/parametrized_surface3d.py +++ b/src/sage/geometry/riemannian_manifolds/parametrized_surface3d.py @@ -97,6 +97,7 @@ class ParametrizedSurface3D(SageObject): sage: ellipsoid = ParametrizedSurface3D(ellipsoid_eq, coords, 'ellipsoid'); ellipsoid Parametrized surface ('ellipsoid') with equation (cos(u1)*cos(u2), 2*cos(u2)*sin(u1), 3*sin(u2)) sage: ellipsoid.plot() + Graphics3d Object Standard surfaces can be constructed using the ``surfaces`` generator:: @@ -119,6 +120,7 @@ class ParametrizedSurface3D(SageObject): sage: enneper = surfaces.Enneper(); enneper Parametrized surface ('Enneper's surface') with equation (-1/9*(u^2 - 3*v^2 - 3)*u, -1/9*(3*u^2 - v^2 + 3)*v, 1/3*u^2 - 1/3*v^2) sage: enneper.plot(aspect_ratio='automatic') + Graphics3d Object We construct an ellipsoid whose axes are given by symbolic variables `a`, `b` and `c`, and find the natural frame of tangent vectors, @@ -155,7 +157,7 @@ class ParametrizedSurface3D(SageObject): sage: a, b = var('a, b', domain='real') sage: torus = ParametrizedSurface3D(((a + b*cos(u))*cos(v),(a + b*cos(u))*sin(v), b*sin(u)),[u,v],'torus') sage: torus.first_fundamental_form_coefficients() - {(1, 2): 0, (1, 1): b^2, (2, 1): 0, (2, 2): b^2*cos(u)^2 + 2*a*b*cos(u) + a^2} + {(1, 1): b^2, (1, 2): 0, (2, 1): 0, (2, 2): b^2*cos(u)^2 + 2*a*b*cos(u) + a^2} The first fundamental form can be used to compute the length of a curve on the surface. For example, let us find the length of the @@ -487,6 +489,7 @@ def plot(self, urange=None, vrange=None, **kwds): sage: eq = (3*u + 3*u*v^2 - u^3, 3*v + 3*u^2*v - v^3, 3*(u^2-v^2)) sage: enneper = ParametrizedSurface3D(eq, (u, v), 'Enneper Surface') sage: enneper.plot((-5, 5), (-5, 5)) + Graphics3d Object """ @@ -645,7 +648,7 @@ def first_fundamental_form_coefficients(self): sage: u, v = var('u,v', domain='real') sage: sphere = ParametrizedSurface3D((cos(u)*cos(v), sin(u)*cos(v), sin(v)), (u, v), 'sphere') sage: sphere.first_fundamental_form_coefficients() - {(1, 2): 0, (1, 1): cos(v)^2, (2, 1): 0, (2, 2): 1} + {(1, 1): cos(v)^2, (1, 2): 0, (2, 1): 0, (2, 2): 1} """ coefficients = {} @@ -759,7 +762,7 @@ def first_fundamental_form_inverse_coefficients(self): sage: u, v = var('u, v', domain='real') sage: sphere = ParametrizedSurface3D([cos(u)*cos(v),sin(u)*cos(v),sin(v)],[u,v],'sphere') sage: sphere.first_fundamental_form_inverse_coefficients() - {(1, 2): 0, (1, 1): cos(v)^(-2), (2, 1): 0, (2, 2): 1} + {(1, 1): cos(v)^(-2), (1, 2): 0, (2, 1): 0, (2, 2): 1} """ @@ -1028,14 +1031,28 @@ def frame_structure_functions(self, e1, e2): sage: assume(cos(v) > 0) sage: sphere = ParametrizedSurface3D([cos(u)*cos(v), sin(u)*cos(v), sin(v)], [u, v], 'sphere') sage: sphere.frame_structure_functions([u, v], [-v, u]) - {(1, 2, 1): 0, (2, 1, 2): 0, (2, 2, 2): 0, (1, 2, 2): 0, (1, 1, 1): 0, (2, 1, 1): 0, (2, 2, 1): 0, (1, 1, 2): 0} + {(1, 1, 1): 0, + (1, 1, 2): 0, + (1, 2, 1): 0, + (1, 2, 2): 0, + (2, 1, 1): 0, + (2, 1, 2): 0, + (2, 2, 1): 0, + (2, 2, 2): 0} We construct the structure functions of the orthonormal frame on the surface:: sage: EE_int = sphere.orthonormal_frame(coordinates='int') sage: CC = sphere.frame_structure_functions(EE_int[1],EE_int[2]); CC - {(1, 2, 1): sin(v)/cos(v), (2, 1, 2): 0, (2, 2, 2): 0, (1, 2, 2): 0, (1, 1, 1): 0, (2, 1, 1): -sin(v)/cos(v), (2, 2, 1): 0, (1, 1, 2): 0} + {(1, 1, 1): 0, + (1, 1, 2): 0, + (1, 2, 1): sin(v)/cos(v), + (1, 2, 2): 0, + (2, 1, 1): -sin(v)/cos(v), + (2, 1, 2): 0, + (2, 2, 1): 0, + (2, 2, 2): 0} sage: sphere.lie_bracket(EE_int[1],EE_int[2]) - CC[(1,2,1)]*EE_int[1] - CC[(1,2,2)]*EE_int[2] (0, 0) """ @@ -1095,7 +1112,10 @@ def second_order_natural_frame(self): sage: u, v = var('u, v', domain='real') sage: sphere = ParametrizedSurface3D([cos(u)*cos(v),sin(u)*cos(v),sin(v)],[u,v],'sphere') sage: sphere.second_order_natural_frame() - {(1, 2): (sin(u)*sin(v), -cos(u)*sin(v), 0), (1, 1): (-cos(u)*cos(v), -cos(v)*sin(u), 0), (2, 1): (sin(u)*sin(v), -cos(u)*sin(v), 0), (2, 2): (-cos(u)*cos(v), -cos(v)*sin(u), -sin(v))} + {(1, 1): (-cos(u)*cos(v), -cos(v)*sin(u), 0), + (1, 2): (sin(u)*sin(v), -cos(u)*sin(v), 0), + (2, 1): (sin(u)*sin(v), -cos(u)*sin(v), 0), + (2, 2): (-cos(u)*cos(v), -cos(v)*sin(u), -sin(v))} """ @@ -1211,7 +1231,7 @@ def second_fundamental_form_coefficients(self): sage: assume(cos(v)>0) sage: sphere = ParametrizedSurface3D([cos(u)*cos(v),sin(u)*cos(v),sin(v)],[u,v],'sphere') sage: sphere.second_fundamental_form_coefficients() - {(1, 2): 0, (1, 1): -cos(v)^2, (2, 1): 0, (2, 2): -1} + {(1, 1): -cos(v)^2, (1, 2): 0, (2, 1): 0, (2, 2): -1} """ @@ -1337,7 +1357,7 @@ def shape_operator_coefficients(self): sage: assume(cos(v)>0) sage: sphere = ParametrizedSurface3D([R*cos(u)*cos(v),R*sin(u)*cos(v),R*sin(v)],[u,v],'sphere') sage: sphere.shape_operator_coefficients() - {(1, 2): 0, (1, 1): -1/R, (2, 1): 0, (2, 2): -1/R} + {(1, 1): -1/R, (1, 2): 0, (2, 1): 0, (2, 2): -1/R} """ @@ -1443,7 +1463,14 @@ def connection_coefficients(self): sage: assume(cos(v)>0) sage: sphere = ParametrizedSurface3D([r*cos(u)*cos(v),r*sin(u)*cos(v),r*sin(v)],[u,v],'sphere') sage: sphere.connection_coefficients() - {(1, 2, 1): -sin(v)/cos(v), (2, 2, 2): 0, (1, 2, 2): 0, (2, 1, 1): -sin(v)/cos(v), (1, 1, 2): cos(v)*sin(v), (2, 2, 1): 0, (2, 1, 2): 0, (1, 1, 1): 0} + {(1, 1, 1): 0, + (1, 1, 2): cos(v)*sin(v), + (1, 2, 1): -sin(v)/cos(v), + (1, 2, 2): 0, + (2, 1, 1): -sin(v)/cos(v), + (2, 1, 2): 0, + (2, 2, 1): 0, + (2, 2, 2): 0} """ x = self.variables diff --git a/src/sage/geometry/riemannian_manifolds/surface3d_generators.py b/src/sage/geometry/riemannian_manifolds/surface3d_generators.py index 62b17a73378..ae0e44127b4 100644 --- a/src/sage/geometry/riemannian_manifolds/surface3d_generators.py +++ b/src/sage/geometry/riemannian_manifolds/surface3d_generators.py @@ -55,6 +55,7 @@ def Catenoid(c=1, name="Catenoid"): sage: cat = surfaces.Catenoid(); cat Parametrized surface ('Catenoid') with equation (cos(u)*cosh(v), cosh(v)*sin(u), v) sage: cat.plot() + Graphics3d Object """ u, v = var('u, v') @@ -87,6 +88,7 @@ def Crosscap(r=1, name="Crosscap"): sage: crosscap = surfaces.Crosscap(); crosscap Parametrized surface ('Crosscap') with equation ((cos(v) + 1)*cos(u), (cos(v) + 1)*sin(u), -sin(v)*tanh(-pi + u)) sage: crosscap.plot() + Graphics3d Object """ @@ -160,6 +162,7 @@ def Ellipsoid(center=(0,0,0), axes=(1,1,1), name="Ellipsoid"): sage: ell = surfaces.Ellipsoid(axes=(1, 2, 3)); ell Parametrized surface ('Ellipsoid') with equation (cos(u)*cos(v), 2*cos(v)*sin(u), 3*sin(v)) sage: ell.plot() + Graphics3d Object """ @@ -195,6 +198,7 @@ def Enneper(name="Enneper's surface"): sage: enn = surfaces.Enneper(); enn Parametrized surface ('Enneper's surface') with equation (-1/9*(u^2 - 3*v^2 - 3)*u, -1/9*(3*u^2 - v^2 + 3)*v, 1/3*u^2 - 1/3*v^2) sage: enn.plot() + Graphics3d Object """ @@ -229,6 +233,7 @@ def Helicoid(h=1, name="Helicoid"): sage: helicoid = surfaces.Helicoid(h=2); helicoid Parametrized surface ('Helicoid') with equation (rho*cos(theta), rho*sin(theta), theta/pi) sage: helicoid.plot() + Graphics3d Object """ @@ -262,6 +267,7 @@ def Klein(r=1, name="Klein bottle"): sage: klein = surfaces.Klein(); klein Parametrized surface ('Klein bottle') with equation (-(sin(1/2*u)*sin(2*v) - cos(1/2*u)*sin(v) - 1)*cos(u), -(sin(1/2*u)*sin(2*v) - cos(1/2*u)*sin(v) - 1)*sin(u), cos(1/2*u)*sin(2*v) + sin(1/2*u)*sin(v)) sage: klein.plot() + Graphics3d Object """ @@ -292,6 +298,7 @@ def MonkeySaddle(name="Monkey saddle"): sage: saddle = surfaces.MonkeySaddle(); saddle Parametrized surface ('Monkey saddle') with equation (u, v, u^3 - 3*u*v^2) sage: saddle.plot() + Graphics3d Object """ @@ -327,10 +334,12 @@ def Paraboloid(a=1, b=1, c=1, elliptic=True, name=None): sage: epar = surfaces.Paraboloid(1, 3, 2); epar Parametrized surface ('Elliptic paraboloid') with equation (u, v, 2*u^2 + 2/9*v^2) sage: epar.plot() + Graphics3d Object sage: hpar = surfaces.Paraboloid(2, 3, 1, elliptic=False); hpar Parametrized surface ('Hyperbolic paraboloid') with equation (u, v, -1/4*u^2 + 1/9*v^2) sage: hpar.plot() + Graphics3d Object """ @@ -369,6 +378,7 @@ def Sphere(center=(0,0,0), R=1, name="Sphere"): sage: sphere = surfaces.Sphere(center=(0, 1, -1), R=2); sphere Parametrized surface ('Sphere') with equation (2*cos(u)*cos(v), 2*cos(v)*sin(u) + 1, 2*sin(v) - 1) sage: sphere.plot() + Graphics3d Object Note that the radius of the sphere can be negative. The surface thus obtained is equal to the sphere (or part thereof) with positive radius, @@ -378,12 +388,14 @@ def Sphere(center=(0,0,0), R=1, name="Sphere"): sage: octant1 = surfaces.Sphere(R=1); octant1 Parametrized surface ('Sphere') with equation (cos(u)*cos(v), cos(v)*sin(u), sin(v)) sage: octant1.plot((0, pi/2), (0, pi/2)) + Graphics3d Object with the first octant of the unit sphere with negative radius:: sage: octant2 = surfaces.Sphere(R=-1); octant2 Parametrized surface ('Sphere') with equation (-cos(u)*cos(v), -cos(v)*sin(u), -sin(v)) sage: octant2.plot((0, pi/2), (0, pi/2)) + Graphics3d Object """ @@ -415,6 +427,7 @@ def Torus(r=2, R=3, name="Torus"): sage: torus = surfaces.Torus(); torus Parametrized surface ('Torus') with equation ((2*cos(v) + 3)*cos(u), (2*cos(v) + 3)*sin(u), 2*sin(v)) sage: torus.plot() + Graphics3d Object """ @@ -442,6 +455,7 @@ def WhitneyUmbrella(name="Whitney's umbrella"): sage: whitney = surfaces.WhitneyUmbrella(); whitney Parametrized surface ('Whitney's umbrella') with equation (u*v, u, v^2) sage: whitney.plot() + Graphics3d Object """ diff --git a/src/sage/geometry/toric_lattice.py b/src/sage/geometry/toric_lattice.py index c45a42ca68d..06bd33dc283 100644 --- a/src/sage/geometry/toric_lattice.py +++ b/src/sage/geometry/toric_lattice.py @@ -982,6 +982,7 @@ def plot(self, **options): sage: N = ToricLattice(3) sage: N.plot() + Graphics3d Object """ if "show_lattice" not in options: # Unless user made an explicit decision, we assume that lattice @@ -1128,10 +1129,12 @@ def plot(self, **options): sage: N = ToricLattice(3) sage: sublattice = N.submodule_with_basis([(1,1,0), (3,2,1)]) sage: sublattice.plot() + Graphics3d Object Now we plot both the ambient lattice and its sublattice:: sage: N.plot() + sublattice.plot(point_color="red") + Graphics3d Object """ if "show_lattice" not in options: # Unless user made an explicit decision, we assume that lattice diff --git a/src/sage/geometry/toric_lattice_element.pyx b/src/sage/geometry/toric_lattice_element.pyx index 8148186bdf6..c8fe9b2f74c 100644 --- a/src/sage/geometry/toric_lattice_element.pyx +++ b/src/sage/geometry/toric_lattice_element.pyx @@ -414,6 +414,7 @@ cdef class ToricLatticeElement(Vector_integer_dense): sage: N = ToricLattice(3) sage: n = N(1,2,3) sage: n.plot() + Graphics3d Object """ tp = ToricPlotter(options, self.parent().degree()) tp.adjust_options() diff --git a/src/sage/geometry/toric_plotter.py b/src/sage/geometry/toric_plotter.py index d3cfa8b186f..2b3a0ff33cb 100644 --- a/src/sage/geometry/toric_plotter.py +++ b/src/sage/geometry/toric_plotter.py @@ -135,6 +135,7 @@ class ToricPlotter(SageObject): sage: fan = toric_varieties.dP6().fan() sage: fan.plot() + Graphics object consisting of 31 graphics primitives sage: print fan.plot() Graphics object consisting of 31 graphics primitives diff --git a/src/sage/geometry/triangulation/element.py b/src/sage/geometry/triangulation/element.py index 5a4a5eb5eef..ad7e296c3a5 100644 --- a/src/sage/geometry/triangulation/element.py +++ b/src/sage/geometry/triangulation/element.py @@ -24,6 +24,7 @@ sage: triang = points.triangulate(); triang (<0,1,2,5>, <0,1,3,5>, <1,3,4,5>) sage: triang.plot(axes=False) + Graphics3d Object See :mod:`sage.geometry.triangulation.point_configuration` for more details. """ @@ -65,6 +66,7 @@ def triangulation_render_2d(triangulation, **kwds): sage: points = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) sage: triang = points.triangulate() sage: triang.plot(axes=False, aspect_ratio=1) # indirect doctest + Graphics object consisting of 12 graphics primitives """ from sage.plot.all import point2d, line2d, arrow, polygon2d points = [ point.reduced_affine() for point in triangulation.point_configuration() ] @@ -128,6 +130,7 @@ def triangulation_render_3d(triangulation, **kwds): sage: points = PointConfiguration(p) sage: triang = points.triangulate() sage: triang.plot(axes=False) # indirect doctest + Graphics3d Object """ from sage.plot.plot3d.all import point3d, line3d, arrow3d, polygon3d points = [ point.reduced_affine() for point in triangulation.point_configuration() ] @@ -428,6 +431,7 @@ def plot(self, **kwds): sage: triangulation (<1,3,4>, <2,3,4>) sage: triangulation.plot(axes=False) + Graphics object consisting of 12 graphics primitives """ dim = self.point_configuration().dim() @@ -615,31 +619,31 @@ def _boundary_simplex_dictionary(self): sage: triangulation = polytopes.n_cube(2).triangulate(engine='internal') sage: triangulation._boundary_simplex_dictionary() {(0, 1): ((0, 1, 3),), + (0, 2): ((0, 2, 3),), (0, 3): ((0, 1, 3), (0, 2, 3)), (1, 3): ((0, 1, 3),), - (2, 3): ((0, 2, 3),), - (0, 2): ((0, 2, 3),)} + (2, 3): ((0, 2, 3),)} sage: triangulation = polytopes.n_cube(3).triangulate(engine='internal') sage: triangulation._boundary_simplex_dictionary() - {(1, 4, 7): ((0, 1, 4, 7), (1, 4, 5, 7)), - (1, 3, 7): ((1, 2, 3, 7),), + {(0, 1, 2): ((0, 1, 2, 7),), + (0, 1, 4): ((0, 1, 4, 7),), (0, 1, 7): ((0, 1, 2, 7), (0, 1, 4, 7)), + (0, 2, 4): ((0, 2, 4, 7),), (0, 2, 7): ((0, 1, 2, 7), (0, 2, 4, 7)), - (0, 1, 4): ((0, 1, 4, 7),), - (2, 4, 6): ((2, 4, 6, 7),), - (0, 1, 2): ((0, 1, 2, 7),), + (0, 4, 7): ((0, 1, 4, 7), (0, 2, 4, 7)), + (1, 2, 3): ((1, 2, 3, 7),), (1, 2, 7): ((0, 1, 2, 7), (1, 2, 3, 7)), - (2, 6, 7): ((2, 4, 6, 7),), - (2, 3, 7): ((1, 2, 3, 7),), + (1, 3, 7): ((1, 2, 3, 7),), (1, 4, 5): ((1, 4, 5, 7),), + (1, 4, 7): ((0, 1, 4, 7), (1, 4, 5, 7)), (1, 5, 7): ((1, 4, 5, 7),), - (4, 5, 7): ((1, 4, 5, 7),), - (0, 4, 7): ((0, 1, 4, 7), (0, 2, 4, 7)), + (2, 3, 7): ((1, 2, 3, 7),), + (2, 4, 6): ((2, 4, 6, 7),), (2, 4, 7): ((0, 2, 4, 7), (2, 4, 6, 7)), - (1, 2, 3): ((1, 2, 3, 7),), - (4, 6, 7): ((2, 4, 6, 7),), - (0, 2, 4): ((0, 2, 4, 7),)} + (2, 6, 7): ((2, 4, 6, 7),), + (4, 5, 7): ((1, 4, 5, 7),), + (4, 6, 7): ((2, 4, 6, 7),)} """ result = dict() for simplex in self: @@ -666,10 +670,20 @@ def boundary(self): sage: triangulation (<0,1,2,7>, <0,1,4,7>, <0,2,4,7>, <1,2,3,7>, <1,4,5,7>, <2,4,6,7>) sage: triangulation.boundary() - frozenset([(1, 3, 7), (4, 5, 7), (1, 2, 3), (0, 1, 2), (2, 4, 6), (2, 6, 7), - (2, 3, 7), (1, 5, 7), (0, 1, 4), (1, 4, 5), (4, 6, 7), (0, 2, 4)]) + frozenset({(0, 1, 2), + (0, 1, 4), + (0, 2, 4), + (1, 2, 3), + (1, 3, 7), + (1, 4, 5), + (1, 5, 7), + (2, 3, 7), + (2, 4, 6), + (2, 6, 7), + (4, 5, 7), + (4, 6, 7)}) sage: triangulation.interior_facets() - frozenset([(1, 4, 7), (1, 2, 7), (2, 4, 7), (0, 1, 7), (0, 4, 7), (0, 2, 7)]) + frozenset({(0, 1, 7), (0, 2, 7), (0, 4, 7), (1, 2, 7), (1, 4, 7), (2, 4, 7)}) """ return frozenset(facet for facet, bounded_simplices in self._boundary_simplex_dictionary().iteritems() @@ -692,10 +706,20 @@ def interior_facets(self): sage: triangulation (<0,1,2,7>, <0,1,4,7>, <0,2,4,7>, <1,2,3,7>, <1,4,5,7>, <2,4,6,7>) sage: triangulation.boundary() - frozenset([(1, 3, 7), (4, 5, 7), (1, 2, 3), (0, 1, 2), (2, 4, 6), (2, 6, 7), - (2, 3, 7), (1, 5, 7), (0, 1, 4), (1, 4, 5), (4, 6, 7), (0, 2, 4)]) + frozenset({(0, 1, 2), + (0, 1, 4), + (0, 2, 4), + (1, 2, 3), + (1, 3, 7), + (1, 4, 5), + (1, 5, 7), + (2, 3, 7), + (2, 4, 6), + (2, 6, 7), + (4, 5, 7), + (4, 6, 7)}) sage: triangulation.interior_facets() - frozenset([(1, 4, 7), (1, 2, 7), (2, 4, 7), (0, 1, 7), (0, 4, 7), (0, 2, 7)]) + frozenset({(0, 1, 7), (0, 2, 7), (0, 4, 7), (1, 2, 7), (1, 4, 7), (2, 4, 7)}) """ return frozenset(facet for facet, bounded_simplices in self._boundary_simplex_dictionary().iteritems() diff --git a/src/sage/geometry/triangulation/point_configuration.py b/src/sage/geometry/triangulation/point_configuration.py index 1afb3e5f12e..9074bad0b7d 100644 --- a/src/sage/geometry/triangulation/point_configuration.py +++ b/src/sage/geometry/triangulation/point_configuration.py @@ -59,6 +59,7 @@ sage: list(t) [(1, 3, 4), (2, 3, 4)] sage: t.plot(axes=False) + Graphics object consisting of 12 graphics primitives sage: list( p.triangulations() ) [(<1,3,4>, <2,3,4>), (<0,1,3>, <0,1,4>, <0,2,3>, <0,2,4>), @@ -79,6 +80,7 @@ sage: points = PointConfiguration(p) sage: triang = points.triangulate() sage: triang.plot(axes=False) + Graphics3d Object The standard example of a non-regular triangulation:: @@ -1533,7 +1535,9 @@ def bistellar_flips(self): (((<0,1,3>, <0,2,3>), (<0,1,2>, <1,2,3>)),) sage: Tpos, Tneg = pc.bistellar_flips()[0] sage: Tpos.plot(axes=False) + Graphics object consisting of 11 graphics primitives sage: Tneg.plot(axes=False) + Graphics object consisting of 11 graphics primitives The 3d analog:: @@ -1548,6 +1552,7 @@ def bistellar_flips(self): (((<0,1,3>, <0,2,3>), (<0,1,2>, <1,2,3>)),) sage: Tpos, Tneg = pc.bistellar_flips()[0] sage: Tpos.plot(axes=False) + Graphics3d Object """ flips = [] for C in self.circuits(): diff --git a/src/sage/graphs/base/graph_backends.py b/src/sage/graphs/base/graph_backends.py index 1b94cfe4497..f52ac71aa1b 100644 --- a/src/sage/graphs/base/graph_backends.py +++ b/src/sage/graphs/base/graph_backends.py @@ -664,7 +664,9 @@ def mutate(self): sage: G.edges() [(1, 2), (2, 1), (2, 3)] sage: G.edges(data=True) - [(1, 2, {'weight': 7}), (2, 1, {8: {}, 7: {}}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})] + [(1, 2, {'weight': 7}), + (2, 1, {7: {}, 8: {}}), + (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})] """ import networkx diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index cca8543e2c4..4ba7d1c6080 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -92,16 +92,16 @@ class BipartiteGraph(Graph): sage: B == G True sage: B.left - set([0, 1, 2, 3]) + {0, 1, 2, 3} sage: B.right - set([4, 5, 6]) + {4, 5, 6} sage: B = BipartiteGraph({0:[5,6], 1:[4,5], 2:[4,6], 3:[4,5,6]}) sage: B == G True sage: B.left - set([0, 1, 2, 3]) + {0, 1, 2, 3} sage: B.right - set([4, 5, 6]) + {4, 5, 6} You can specify a partition using ``partition`` argument. Note that if such graph is not bipartite, then Sage will raise an error. However, if one specifies @@ -118,7 +118,7 @@ class BipartiteGraph(Graph): sage: B = BipartiteGraph(P, partition, check=False) sage: B.left - set([0, 1, 2, 3, 4]) + {0, 1, 2, 3, 4} sage: B.show() :: @@ -458,9 +458,9 @@ def add_vertex(self, name=None, left=False, right=False): sage: G.vertices() [0, 1] sage: G.left - set([0]) + {0} sage: G.right - set([1]) + {1} TESTS: @@ -542,9 +542,9 @@ def add_vertices(self, vertices, left=False, right=False): sage: bg.add_vertices([6,7,8], right=[True, False, True]) sage: bg.add_vertices([9,10,11], right=True) sage: bg.left - set([0, 1, 2, 3, 5, 7]) + {0, 1, 2, 3, 5, 7} sage: bg.right - set([4, 6, 8, 9, 10, 11]) + {4, 6, 8, 9, 10, 11} TEST:: @@ -566,7 +566,7 @@ def add_vertices(self, vertices, left=False, right=False): ... RuntimeError: Cannot add duplicate vertex to other partition. sage: (bg.left, bg.right) - (set([0, 1, 2]), set([])) + ({0, 1, 2}, set()) """ # sanity check on partition specifiers if left and right: # also triggered if both lists are specified @@ -630,12 +630,12 @@ def delete_vertex(self, vertex, in_order=False): sage: B Bipartite cycle graph: graph on 3 vertices sage: B.left - set([2]) + {2} sage: B.edges() [(1, 2, None), (2, 3, None)] sage: B.delete_vertex(3) sage: B.right - set([1]) + {1} sage: B.edges() [(1, 2, None)] sage: B.delete_vertex(0) @@ -696,9 +696,9 @@ def delete_vertices(self, vertices): sage: B Bipartite cycle graph: graph on 2 vertices sage: B.left - set([2]) + {2} sage: B.right - set([1]) + {1} sage: B.edges() [(1, 2, None)] sage: B.delete_vertices([0]) @@ -813,7 +813,7 @@ def bipartition(self): sage: B = BipartiteGraph(graphs.CycleGraph(4)) sage: B.bipartition() - (set([0, 2]), set([1, 3])) + ({0, 2}, {1, 3}) """ return (self.left, self.right) @@ -863,6 +863,7 @@ def plot(self, *args, **kwds): sage: B = BipartiteGraph(graphs.CycleGraph(20)) sage: B.plot() + Graphics object consisting of 41 graphics primitives """ if "pos" not in kwds: kwds["pos"] = None diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 141f6b6db74..ae18624d640 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -139,12 +139,14 @@ class DiGraph(GenericGraph): sage: g = digraphs.ButterflyGraph(3) sage: g.plot() + Graphics object consisting of 81 graphics primitives You can also use the collection of pre-defined graphs, then create a digraph from them. :: sage: g = DiGraph(graphs.PetersenGraph()) sage: g.plot() + Graphics object consisting of 50 graphics primitives Calling ``Digraph`` on a graph returns the original graph in which every edge is replaced by two different edges going toward opposite directions. @@ -170,12 +172,14 @@ class DiGraph(GenericGraph): connected components with only two lines:: sage: for component in g.connected_components(): - ... g.subgraph(component).plot() + ....: g.subgraph(component).plot() + Graphics object consisting of 50 graphics primitives The same methods works for strongly connected components :: sage: for component in g.strongly_connected_components(): - ... g.subgraph(component).plot() + ....: g.subgraph(component).plot() + Graphics object consisting of 50 graphics primitives INPUT: diff --git a/src/sage/graphs/digraph_generators.py b/src/sage/graphs/digraph_generators.py index 335dcbb1179..fcdf32f0622 100644 --- a/src/sage/graphs/digraph_generators.py +++ b/src/sage/graphs/digraph_generators.py @@ -829,7 +829,19 @@ def Kautz(self, k, D, vertices = 'strings'): sage: K = digraphs.Kautz(2, 3) sage: K.is_isomorphic(digraphs.ImaseItoh(12, 2), certify = True) - (True, {'201': 5, '120': 9, '202': 4, '212': 7, '210': 6, '010': 0, '121': 8, '012': 1, '021': 2, '020': 3, '102': 10, '101': 11}) + (True, + {'010': 0, + '012': 1, + '020': 3, + '021': 2, + '101': 11, + '102': 10, + '120': 9, + '121': 8, + '201': 5, + '202': 4, + '210': 6, + '212': 7}) sage: K = digraphs.Kautz([1,'a','B'], 2) sage: K.edges() diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py index 3f2d54c9a0c..e8755ab1850 100644 --- a/src/sage/graphs/generators/families.py +++ b/src/sage/graphs/generators/families.py @@ -382,6 +382,7 @@ def BubbleSortGraph(n): sage: g = graphs.BubbleSortGraph(4); g Bubble sort: Graph on 24 vertices sage: g.plot() # long time + Graphics object consisting of 61 graphics primitives The bubble sort graph on `n = 1` symbol is the trivial graph `K_1`:: @@ -855,7 +856,7 @@ def FuzzyBallGraph(partition, q): sage: m=4; q=2; k=2 sage: g_list=[graphs.FuzzyBallGraph(p,q) for p in Partitions(m, length=k)] sage: set([g.laplacian_matrix(normalized=True).charpoly() for g in g_list]) # long time (7s on sage.math, 2011) - set([x^8 - 8*x^7 + 4079/150*x^6 - 68689/1350*x^5 + 610783/10800*x^4 - 120877/3240*x^3 + 1351/100*x^2 - 931/450*x]) + {x^8 - 8*x^7 + 4079/150*x^6 - 68689/1350*x^5 + 610783/10800*x^4 - 120877/3240*x^3 + 1351/100*x^2 - 931/450*x} """ from sage.graphs.generators.basic import CompleteGraph if len(partition)<1: @@ -1066,6 +1067,7 @@ def HyperStarGraph(n,k): sage: g = graphs.HyperStarGraph(6,3) sage: g.plot() # long time + Graphics object consisting of 51 graphics primitives REFERENCES: @@ -1320,6 +1322,7 @@ def NKStarGraph(n,k): sage: g = graphs.NKStarGraph(4,2) sage: g.plot() # long time + Graphics object consisting of 31 graphics primitives REFERENCES: @@ -1377,6 +1380,7 @@ def NStarGraph(n): sage: g = graphs.NStarGraph(4) sage: g.plot() # long time + Graphics object consisting of 61 graphics primitives REFERENCES: diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index cebe290ec57..cb63e926c1c 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -3832,7 +3832,7 @@ def ShrikhandeGraph(): sage: set([ len([x for x in G.neighbors(i) if x in G.neighbors(j)]) ....: for i in range(G.order()) ....: for j in range(i) ]) - set([2]) + {2} It is non-planar, and both Hamiltonian and Eulerian:: diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index e86e270822c..7bf7f3a2052 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1166,22 +1166,22 @@ def to_dictionary(self, edge_labels=False, multiple_edges=False): {0: {1: None, 4: None, 5: None}, 1: {0: None, 2: None, 6: None}, 2: {1: None, 3: None, 7: None}, - 3: {8: None, 2: None, 4: None}, - 4: {0: None, 9: None, 3: None}, - 5: {0: None, 8: None, 7: None}, - 6: {8: None, 1: None, 9: None}, - 7: {9: None, 2: None, 5: None}, + 3: {2: None, 4: None, 8: None}, + 4: {0: None, 3: None, 9: None}, + 5: {0: None, 7: None, 8: None}, + 6: {1: None, 8: None, 9: None}, + 7: {2: None, 5: None, 9: None}, 8: {3: None, 5: None, 6: None}, 9: {4: None, 6: None, 7: None}} sage: graphs.PetersenGraph().to_dictionary(edge_labels=True,multiple_edges=True) {0: {1: [None], 4: [None], 5: [None]}, 1: {0: [None], 2: [None], 6: [None]}, 2: {1: [None], 3: [None], 7: [None]}, - 3: {8: [None], 2: [None], 4: [None]}, - 4: {0: [None], 9: [None], 3: [None]}, - 5: {0: [None], 8: [None], 7: [None]}, - 6: {8: [None], 1: [None], 9: [None]}, - 7: {9: [None], 2: [None], 5: [None]}, + 3: {2: [None], 4: [None], 8: [None]}, + 4: {0: [None], 3: [None], 9: [None]}, + 5: {0: [None], 7: [None], 8: [None]}, + 6: {1: [None], 8: [None], 9: [None]}, + 7: {2: [None], 5: [None], 9: [None]}, 8: {3: [None], 5: [None], 6: [None]}, 9: {4: [None], 6: [None], 7: [None]}} """ @@ -13858,8 +13858,10 @@ def complement(self): sage: P = graphs.PetersenGraph() sage: P.plot() # long time + Graphics object consisting of 26 graphics primitives sage: PC = P.complement() sage: PC.plot() # long time + Graphics object consisting of 41 graphics primitives :: @@ -14151,6 +14153,7 @@ def tensor_product(self, other): sage: T.size() 10 sage: T.plot() # long time + Graphics object consisting of 21 graphics primitives :: @@ -14161,6 +14164,7 @@ def tensor_product(self, other): sage: T.size() 900 sage: T.plot() # long time + Graphics object consisting of 1101 graphics primitives TESTS: @@ -14229,6 +14233,7 @@ def lexicographic_product(self, other): sage: L = C.lexicographic_product(Z); L Graph on 10 vertices sage: L.plot() # long time + Graphics object consisting of 36 graphics primitives :: @@ -14237,6 +14242,7 @@ def lexicographic_product(self, other): sage: L = D.lexicographic_product(P); L Graph on 200 vertices sage: L.plot() # long time + Graphics object consisting of 3501 graphics primitives TESTS: @@ -14301,6 +14307,7 @@ def strong_product(self, other): sage: S = C.strong_product(Z); S Graph on 10 vertices sage: S.plot() # long time + Graphics object consisting of 36 graphics primitives :: @@ -14309,6 +14316,7 @@ def strong_product(self, other): sage: S = D.strong_product(P); S Graph on 200 vertices sage: S.plot() # long time + Graphics object consisting of 1701 graphics primitives TESTS: @@ -14378,6 +14386,7 @@ def disjunctive_product(self, other): sage: D = Z.disjunctive_product(Z); D Graph on 4 vertices sage: D.plot() # long time + Graphics object consisting of 11 graphics primitives :: @@ -14385,6 +14394,7 @@ def disjunctive_product(self, other): sage: D = C.disjunctive_product(Z); D Graph on 10 vertices sage: D.plot() # long time + Graphics object consisting of 46 graphics primitives TESTS: @@ -14574,7 +14584,7 @@ def _color_by_label(self, format='hex', as_function=False, default_color = "blac sage: G = SymmetricGroup(4).cayley_graph() sage: set(G.edge_labels()) - set([1, 2, 3]) + {1, 2, 3} We first request the coloring as a function:: @@ -14594,9 +14604,9 @@ def _color_by_label(self, format='hex', as_function=False, default_color = "blac The default output is a dictionary assigning edges to colors:: sage: G._color_by_label() - {'#00ff00': [((1,4,3,2), (1,4,3), 1), ... ((1,2)(3,4), (3,4), 1)], - '#ff0000': [((1,4,3,2), (1,4,2), 2), ... ((1,2)(3,4), (1,3,4,2), 2)], - '#0000ff': [((1,4,3,2), (1,3,2), 3), ... ((1,2)(3,4), (1,2), 3)]} + {'#0000ff': [((1,4,3,2), (1,3,2), 3), ... ((1,2)(3,4), (1,2), 3)], + '#00ff00': [((1,4,3,2), (1,4,3), 1), ... ((1,2)(3,4), (3,4), 1)], + '#ff0000': [((1,4,3,2), (1,4,2), 2), ... ((1,2)(3,4), (1,3,4,2), 2)]} sage: G._color_by_label({1: "blue", 2: "red", 3: "green"}) {'blue': [((1,4,3,2), (1,4,3), 1), ... ((1,2)(3,4), (3,4), 1)], @@ -14733,25 +14743,18 @@ def layout(self, layout = None, pos = None, dim = 2, save_pos = False, **options sage: g = digraphs.ButterflyGraph(1) sage: g.layout() - {('1', 1): [2.50..., -0.545...], - ('0', 0): [2.22..., 0.832...], + {('0', 0): [2.22..., 0.832...], + ('0', 1): [0.833..., 0.543...], ('1', 0): [1.12..., -0.830...], - ('0', 1): [0.833..., 0.543...]} - - sage: 1+1 - 2 + ('1', 1): [2.50..., -0.545...]} + sage: x = g.layout(layout = "acyclic_dummy", save_pos = True) - sage: x = {('1', 1): [41, 18], ('0', 0): [41, 90], ('1', 0): [140, 90], ('0', 1): [141, 18]} - - {('1', 1): [41, 18], ('0', 0): [41, 90], ('1', 0): [140, 90], ('0', 1): [141, 18]} - - sage: g.layout(dim = 3) - {('1', 1): [1.07..., -0.260..., 0.927...], - ('0', 0): [2.02..., 0.528..., 0.343...], + {('0', 0): [2.02..., 0.528..., 0.343...], + ('0', 1): [1.61..., 0.260..., -0.927...], ('1', 0): [0.674..., -0.528..., -0.343...], - ('0', 1): [1.61..., 0.260..., -0.927...]} - + ('1', 1): [1.07..., -0.260..., 0.927...]} + Here is the list of all the available layout options:: sage: from sage.graphs.graph_plot import layout_options @@ -14832,6 +14835,7 @@ def layout_spring(self, by_component = True, **options): 5: [1.08..., 0.946...]} sage: g = graphs.LadderGraph(7) sage: g.plot(layout = "spring") + Graphics object consisting of 34 graphics primitives """ return spring_layout_fast(self, by_component = by_component, **options) @@ -14869,6 +14873,7 @@ def layout_ranked(self, heights = None, dim = 2, spring = False, **options): 5: [1.33..., 2]} sage: g = graphs.LadderGraph(7) sage: g.plot(layout = "ranked", heights = dict( (i,[i, i+7]) for i in range(7) )) + Graphics object consisting of 34 graphics primitives """ assert heights is not None @@ -14927,10 +14932,10 @@ def layout_extend_randomly(self, pos, dim = 2): sage: H = digraphs.ButterflyGraph(1) sage: H.layout_extend_randomly({('0',0): (0,0), ('1',1): (1,1)}) - {('1', 1): (1, 1), - ('0', 0): (0, 0), + {('0', 0): (0, 0), + ('0', 1): [0.0446..., 0.332...], ('1', 0): [0.111..., 0.514...], - ('0', 1): [0.0446..., 0.332...]} + ('1', 1): (1, 1)} """ assert dim == 2 # 3d not yet implemented from sage.misc.randstate import current_randstate @@ -14966,6 +14971,7 @@ def layout_circular(self, dim = 2, **options): 5: [0.97..., -0.22...], 6: [0.78..., 0.62...]} sage: G.plot(layout = "circular") + Graphics object consisting of 22 graphics primitives """ assert dim == 2, "3D circular layout not implemented" from math import sin, cos, pi @@ -15017,9 +15023,11 @@ def layout_tree(self, tree_orientation = "down", tree_root = None, dim = 2, **op sage: G = graphs.BalancedTree(2,4) sage: G.plot(layout="tree", tree_root = 0, tree_orientation = "up") + Graphics object consisting of 62 graphics primitives sage: G = graphs.RandomTree(80) sage: G.plot(layout="tree", tree_orientation = "right") + Graphics object consisting of 160 graphics primitives TESTS:: @@ -15256,13 +15264,16 @@ def graphplot(self, **options): See http://trac.sagemath.org/15494 for details. sage: GP = g.graphplot(edge_labels=True, color_by_label=True, edge_style='dashed') sage: GP.plot() + Graphics object consisting of 22 graphics primitives We can modify the graphplot object. Notice that the changes are cumulative:: sage: GP.set_edges(edge_style='solid') sage: GP.plot() + Graphics object consisting of 22 graphics primitives sage: GP.set_vertices(talk=True) sage: GP.plot() + Graphics object consisting of 22 graphics primitives """ from sage.graphs.graph_plot import GraphPlot return GraphPlot(graph=self, options=options) @@ -15447,6 +15458,7 @@ def plot(self, **options): sage: pos = {0:[0.0, 1.5], 1:[-0.8, 0.3], 2:[-0.6, -0.8], 3:[0.6, -0.8], 4:[0.8, 0.3]} sage: g = Graph({0:[1], 1:[2], 2:[3], 3:[4], 4:[0]}) sage: g.plot(pos=pos, layout='spring', iterations=0) + Graphics object consisting of 11 graphics primitives :: @@ -15494,12 +15506,14 @@ def plot(self, **options): sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}) + Graphics object consisting of 14 graphics primitives :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}) + Graphics object consisting of 14 graphics primitives sage: t.set_edge_label(0,1,-7) sage: t.set_edge_label(0,5,3) sage: t.set_edge_label(0,5,99) @@ -15508,31 +15522,38 @@ def plot(self, **options): sage: t.set_edge_label(2,6,3/2) sage: t.set_edge_label(0,4,66) sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}, edge_labels=True) + Graphics object consisting of 20 graphics primitives :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(layout='tree') + Graphics object consisting of 14 graphics primitives :: sage: t = DiGraph('JCC???@A??GO??CO??GO??') sage: t.plot(layout='tree', tree_root=0, tree_orientation="up") + Graphics object consisting of 22 graphics primitives sage: D = DiGraph({0:[1,2,3], 2:[1,4], 3:[0]}) sage: D.plot() + Graphics object consisting of 16 graphics primitives sage: D = DiGraph(multiedges=True,sparse=True) sage: for i in range(5): ... D.add_edge((i,i+1,'a')) ... D.add_edge((i,i-1,'b')) sage: D.plot(edge_labels=True,edge_colors=D._color_by_label()) + Graphics object consisting of 34 graphics primitives sage: D.plot(edge_labels=True, color_by_label={'a':'blue', 'b':'red'}, edge_style='dashed') + Graphics object consisting of 34 graphics primitives sage: g = Graph({}, loops=True, multiedges=True,sparse=True) sage: g.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'), ... (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')]) sage: g.plot(edge_labels=True, color_by_label=True, edge_style='dashed') + Graphics object consisting of 22 graphics primitives :: @@ -15550,6 +15571,7 @@ def plot(self, **options): sage: G = DiGraph({0:{1:'a', 2:'a'}, 1:{0:'b'}, 2:{0:'c'}}) sage: p = G.plot(edge_labels=True, color_by_label={'a':'yellow', 'b':'purple'}); p + Graphics object consisting of 14 graphics primitives sage: sorted([x.options()['rgbcolor'] for x in p if isinstance(x, sage.plot.arrow.CurveArrow)]) ['black', 'purple', 'yellow', 'yellow'] """ @@ -15679,6 +15701,7 @@ def plot3d(self, bgcolor=(1,1,1), sage: G = graphs.CubeGraph(5) sage: G.plot3d(iterations=500, edge_size=None, vertex_size=0.04) # long time + Graphics3d Object We plot a fairly complicated Cayley graph:: @@ -15686,6 +15709,7 @@ def plot3d(self, bgcolor=(1,1,1), Alternating group of order 5!/2 as a permutation group sage: G = A5.cayley_graph() sage: G.plot3d(vertex_size=0.03, edge_size=0.01, vertex_colors={(1,1,1):G.vertices()}, bgcolor=(0,0,0), color_by_label=True, iterations=200) # long time + Graphics3d Object Some Tachyon examples:: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 3455bfc3492..7f5dd8fc594 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -568,11 +568,13 @@ class Graph(GenericGraph): sage: g = graphs.PetersenGraph() sage: g.plot() + Graphics object consisting of 26 graphics primitives or:: sage: g = graphs.ChvatalGraph() sage: g.plot() + Graphics object consisting of 37 graphics primitives In order to obtain more information about these graph constructors, access the documentation using the command ``graphs.RandomGNP?``. @@ -596,7 +598,8 @@ class Graph(GenericGraph): connected components with only two lines:: sage: for component in g.connected_components(): - ... g.subgraph(component).plot() + ....: g.subgraph(component).plot() + Graphics object consisting of 37 graphics primitives INPUT: @@ -3681,7 +3684,7 @@ def bipartite_sets(self): EXAMPLES:: sage: graphs.CycleGraph(4).bipartite_sets() - (set([0, 2]), set([1, 3])) + ({0, 2}, {1, 3}) sage: graphs.CycleGraph(5).bipartite_sets() Traceback (most recent call last): ... @@ -3834,6 +3837,7 @@ def coloring(self, algorithm="DLX", hex_colors=False, verbose = 0): sage: P = G.coloring(algorithm="DLX"); P [[1, 2, 3], [0, 5, 6], [4]] sage: G.plot(partition=P) + Graphics object consisting of 16 graphics primitives sage: H = G.coloring(hex_colors=True, algorithm="MILP") sage: for c in sorted(H.keys()): ... print c, H[c] @@ -3847,6 +3851,7 @@ def coloring(self, algorithm="DLX", hex_colors=False, verbose = 0): #00ff00 [1, 2, 3] #ff0000 [0, 5, 6] sage: G.plot(vertex_colors=H) + Graphics object consisting of 16 graphics primitives TESTS:: @@ -6654,6 +6659,7 @@ def two_factor_petersen(self): sage: g = graphs.CirculantGraph(24, [7, 11]) sage: cl = g.two_factor_petersen() sage: g.plot(edge_colors={'black':cl[0], 'red':cl[1]}) + Graphics object consisting of 73 graphics primitives """ self._scream_if_not_simple() diff --git a/src/sage/graphs/graph_database.py b/src/sage/graphs/graph_database.py index a2127c493b3..49dbf69f404 100644 --- a/src/sage/graphs/graph_database.py +++ b/src/sage/graphs/graph_database.py @@ -709,178 +709,178 @@ def __init__(self): sage: G = GraphDatabase() sage: G.get_skeleton() - {u'aut_grp': {u'edge_transitive': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'vertex_transitive': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'aut_grp_size': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'graph_id': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'num_orbits': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'num_fixed_points': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}}, - u'degrees': {u'graph_id': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'degrees_sd': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'max_degree': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'regular': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'average_degree': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'degree_sequence': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'min_degree': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}}, - u'spectrum': {u'max_eigenvalue': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'energy': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'spectrum': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'TEXT'}, - u'eigenvalues_sd': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'graph_id': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'min_eigenvalue': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}}, - u'misc': {u'diameter': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'vertex_connectivity': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'graph_id': {'index': False, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'num_components': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'min_vertex_cover_size': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'edge_connectivity': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'num_spanning_trees': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'induced_subgraphs': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'TEXT'}, - u'radius': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'num_cut_vertices': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'clique_number': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'independence_number': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'girth': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}}, - u'graph_data': {u'perfect': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'planar': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'graph_id': {'index': True, - 'unique': True, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'complement_graph6': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'TEXT'}, - u'num_edges': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'num_cycles': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'graph6': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'TEXT'}, - u'num_hamiltonian_cycles': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}, - u'lovasz_number': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'REAL'}, - u'eulerian': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'BOOLEAN'}, - u'num_vertices': {'index': True, - 'unique': False, - 'primary_key': False, - 'sql': u'INTEGER'}}} + {u'aut_grp': {u'aut_grp_size': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'edge_transitive': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}, + u'graph_id': {'index': False, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_fixed_points': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_orbits': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'vertex_transitive': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}}, + u'degrees': {u'average_degree': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'degree_sequence': {'index': False, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'degrees_sd': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'graph_id': {'index': False, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'max_degree': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'min_degree': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'regular': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}}, + u'graph_data': {u'complement_graph6': {'index': True, + 'primary_key': False, + 'sql': u'TEXT', + 'unique': False}, + u'eulerian': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}, + u'graph6': {'index': True, + 'primary_key': False, + 'sql': u'TEXT', + 'unique': False}, + u'graph_id': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': True}, + u'lovasz_number': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'num_cycles': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_edges': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_hamiltonian_cycles': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_vertices': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'perfect': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}, + u'planar': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}}, + u'misc': {u'clique_number': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'diameter': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'edge_connectivity': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}, + u'girth': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'graph_id': {'index': False, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'independence_number': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'induced_subgraphs': {'index': True, + 'primary_key': False, + 'sql': u'TEXT', + 'unique': False}, + u'min_vertex_cover_size': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_components': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_cut_vertices': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'num_spanning_trees': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'radius': {'index': True, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'vertex_connectivity': {'index': True, + 'primary_key': False, + 'sql': u'BOOLEAN', + 'unique': False}}, + u'spectrum': {u'eigenvalues_sd': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'energy': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'graph_id': {'index': False, + 'primary_key': False, + 'sql': u'INTEGER', + 'unique': False}, + u'max_eigenvalue': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'min_eigenvalue': {'index': True, + 'primary_key': False, + 'sql': u'REAL', + 'unique': False}, + u'spectrum': {'index': False, + 'primary_key': False, + 'sql': u'TEXT', + 'unique': False}}} """ SQLDatabase.__init__(self,dblocation) diff --git a/src/sage/graphs/graph_list.py b/src/sage/graphs/graph_list.py index f28856dc0db..e70cc6c03e9 100644 --- a/src/sage/graphs/graph_list.py +++ b/src/sage/graphs/graph_list.py @@ -289,6 +289,7 @@ def to_graphics_arrays(list, **kwds): sage: len(w) 1 sage: w[0] + Graphics Array of size 3 x 4 """ from sage.plot.plot import graphics_array from sage.graphs import graph diff --git a/src/sage/graphs/graph_plot.py b/src/sage/graphs/graph_plot.py index f287a77f252..922f46b1bf4 100644 --- a/src/sage/graphs/graph_plot.py +++ b/src/sage/graphs/graph_plot.py @@ -288,6 +288,7 @@ def set_pos(self): sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.plot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}) + Graphics object consisting of 14 graphics primitives TESTS: @@ -299,11 +300,11 @@ def set_pos(self): sage: g = graphs.FruchtGraph() sage: gp = g.graphplot() sage: set(map(type, flatten(gp._pos.values()))) - set([]) + {} sage: g = graphs.BullGraph() sage: gp = g.graphplot(save_pos=True) sage: set(map(type, flatten(gp._pos.values()))) - set([]) + {} """ self._pos = self._graph.layout(**self._options) @@ -325,8 +326,10 @@ def set_vertices(self, **vertex_options): sage: GP = g.graphplot(vertex_size=100, edge_labels=True, color_by_label=True, edge_style='dashed') sage: GP.set_vertices(talk=True) sage: GP.plot() + Graphics object consisting of 22 graphics primitives sage: GP.set_vertices(vertex_colors='pink', vertex_shape='^') sage: GP.plot() + Graphics object consisting of 22 graphics primitives """ # Handle base vertex options voptions = {} @@ -438,8 +441,10 @@ def set_edges(self, **edge_options): sage: GP = g.graphplot(vertex_size=100, edge_labels=True, color_by_label=True, edge_style='dashed') sage: GP.set_edges(edge_style='solid') sage: GP.plot() + Graphics object consisting of 22 graphics primitives sage: GP.set_edges(edge_color='black') sage: GP.plot() + Graphics object consisting of 22 graphics primitives sage: d = DiGraph({}, loops=True, multiedges=True, sparse=True) sage: d.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'), @@ -447,8 +452,10 @@ def set_edges(self, **edge_options): sage: GP = d.graphplot(vertex_size=100, edge_labels=True, color_by_label=True, edge_style='dashed') sage: GP.set_edges(edge_style='solid') sage: GP.plot() + Graphics object consisting of 24 graphics primitives sage: GP.set_edges(edge_color='black') sage: GP.plot() + Graphics object consisting of 24 graphics primitives TESTS:: @@ -804,6 +811,7 @@ def plot(self, **kwds): sage: pos = {0:[0.0, 1.5], 1:[-0.8, 0.3], 2:[-0.6, -0.8], 3:[0.6, -0.8], 4:[0.8, 0.3]} sage: g = Graph({0:[1], 1:[2], 2:[3], 3:[4], 4:[0]}) sage: g.graphplot(pos=pos, layout='spring', iterations=0).plot() + Graphics object consisting of 11 graphics primitives sage: G = Graph() sage: P = G.graphplot().plot() @@ -819,12 +827,14 @@ def plot(self, **kwds): sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.graphplot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}).plot() + Graphics object consisting of 14 graphics primitives :: sage: T = list(graphs.trees(7)) sage: t = T[3] sage: t.graphplot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}).plot() + Graphics object consisting of 14 graphics primitives sage: t.set_edge_label(0,1,-7) sage: t.set_edge_label(0,5,3) sage: t.set_edge_label(0,5,99) @@ -833,6 +843,7 @@ def plot(self, **kwds): sage: t.set_edge_label(2,6,3/2) sage: t.set_edge_label(0,4,66) sage: t.graphplot(heights={0:[0], 1:[4,5,1], 2:[2], 3:[3,6]}, edge_labels=True).plot() + Graphics object consisting of 20 graphics primitives :: @@ -855,15 +866,18 @@ def plot(self, **kwds): ... D.add_edge((i,i+1,'a')) ... D.add_edge((i,i-1,'b')) sage: D.graphplot(edge_labels=True,edge_colors=D._color_by_label()).plot() + Graphics object consisting of 34 graphics primitives sage: g = Graph({}, loops=True, multiedges=True, sparse=True) sage: g.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'), ... (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')]) sage: g.graphplot(edge_labels=True, color_by_label=True, edge_style='dashed').plot() + Graphics object consisting of 22 graphics primitives The ``edge_style`` option may be provided in the short format too:: sage: g.graphplot(edge_labels=True, color_by_label=True, edge_style='--').plot() + Graphics object consisting of 22 graphics primitives TESTS: @@ -871,6 +885,7 @@ def plot(self, **kwds): sage: g = Graph({}) sage: g.plot(title='empty graph', axes=True) + Graphics object consisting of 0 graphics primitives Check for invalid inputs:: diff --git a/src/sage/graphs/isgci.py b/src/sage/graphs/isgci.py index 3b7529d758f..9714905b184 100644 --- a/src/sage/graphs/isgci.py +++ b/src/sage/graphs/isgci.py @@ -591,7 +591,7 @@ def inclusions(self): sage: type(t) sage: t[0] - {'super': 'gc_2', 'sub': 'gc_1'} + {'sub': 'gc_1', 'super': 'gc_2'} """ self.classes() return self.inclusions() diff --git a/src/sage/groups/braid.py b/src/sage/groups/braid.py index b3a22fb01dc..238cc6d170a 100644 --- a/src/sage/groups/braid.py +++ b/src/sage/groups/braid.py @@ -382,11 +382,14 @@ def plot(self, color='rainbow', orientation='bottom-top', gap=0.05, aspect_ratio sage: B = BraidGroup(4, 's') sage: b = B([1, 2, 3, 1, 2, 1]) sage: b.plot() + Graphics object consisting of 30 graphics primitives sage: b.plot(color=["red", "blue", "red", "blue"]) + Graphics object consisting of 30 graphics primitives sage: B. = BraidGroup(3) sage: b = t^-1*s^2 sage: b.plot(orientation="left-right", color="red") + Graphics object consisting of 12 graphics primitives """ from sage.plot.bezier_path import bezier_path from sage.plot.plot import Graphics, line @@ -480,8 +483,11 @@ def plot3d(self, color='rainbow'): sage: B = BraidGroup(4, 's') sage: b = B([1, 2, 3, 1, 2, 1]) sage: b.plot3d() + Graphics3d Object sage: b.plot3d(color="red") + Graphics3d Object sage: b.plot3d(color=["red", "blue", "red", "blue"]) + Graphics3d Object """ from sage.plot.plot3d.shapes2 import bezier3d from sage.plot.colors import rainbow diff --git a/src/sage/groups/finitely_presented.py b/src/sage/groups/finitely_presented.py index df6c85ff62f..9ede34539a5 100644 --- a/src/sage/groups/finitely_presented.py +++ b/src/sage/groups/finitely_presented.py @@ -589,7 +589,7 @@ def rules(self): b^2*a^2 ---> 1 sage: k.rules() - {b^2*a^2: 1, a^3: 1} + {a^3: 1, b^2*a^2: 1} sage: k.make_confluent() sage: sorted(k.rules().items()) [(a^-2, a), (a^-1*b^-1, a*b), (a^-1*b, b^-1), (a^2, a^-1), diff --git a/src/sage/groups/perm_gps/cubegroup.py b/src/sage/groups/perm_gps/cubegroup.py index 6e557cae624..e636880c934 100644 --- a/src/sage/groups/perm_gps/cubegroup.py +++ b/src/sage/groups/perm_gps/cubegroup.py @@ -281,6 +281,7 @@ def create_poly(face, color): sage: from sage.groups.perm_gps.cubegroup import create_poly, red sage: create_poly('ur', red) + Graphics object consisting of 1 graphics primitive """ return polygon(face_polys[face], rgbcolor=color) @@ -689,7 +690,12 @@ def parse(self, mv, check=True): sage: C.parse(facets) == g True sage: faces = C.faces("L"); faces - {'right': [[25, 26, 27], [28, 0, 29], [30, 31, 32]], 'up': [[17, 2, 3], [20, 0, 5], [22, 7, 8]], 'back': [[33, 34, 6], [36, 0, 4], [38, 39, 1]], 'down': [[40, 42, 43], [37, 0, 45], [35, 47, 48]], 'front': [[41, 18, 19], [44, 0, 21], [46, 23, 24]], 'left': [[11, 13, 16], [10, 0, 15], [9, 12, 14]]} + {'back': [[33, 34, 6], [36, 0, 4], [38, 39, 1]], + 'down': [[40, 42, 43], [37, 0, 45], [35, 47, 48]], + 'front': [[41, 18, 19], [44, 0, 21], [46, 23, 24]], + 'left': [[11, 13, 16], [10, 0, 15], [9, 12, 14]], + 'right': [[25, 26, 27], [28, 0, 29], [30, 31, 32]], + 'up': [[17, 2, 3], [20, 0, 5], [22, 7, 8]]} sage: C.parse(faces) == C.parse("L") True sage: C.parse("L' R2") == C.parse("L^(-1)*R^2") @@ -1293,6 +1299,7 @@ def plot(self): sage: C = RubiksCube("R*U") sage: C.plot() + Graphics object consisting of 55 graphics primitives """ return self._group.plot_cube(self._state) @@ -1323,6 +1330,7 @@ def cubie(self, size, gap, x,y,z, colors, stickers=True): sage: C = RubiksCube("R*U") sage: C.cubie(0.15, 0.025, 0,0,0, C.colors*3) + Graphics3d Object """ sides = cubie_face_list[x,y,z] t = 2*size+gap @@ -1342,6 +1350,7 @@ def plot3d(self, stickers=True): sage: C = RubiksCube("R*U") sage: C.plot3d() + Graphics3d Object """ while len(self.colors) < 7: self.colors.append((.1, .1, .1)) diff --git a/src/sage/gsl/fft.pyx b/src/sage/gsl/fft.pyx index b3bf88221bc..75260401b4d 100644 --- a/src/sage/gsl/fft.pyx +++ b/src/sage/gsl/fft.pyx @@ -248,6 +248,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base): sage: a = FastFourierTransform(4) sage: a._plot_polar(0,2) + Graphics object consisting of 2 graphics primitives """ cdef int i @@ -285,6 +286,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base): sage: a = FastFourierTransform(4) sage: a._plot_rect(0,3) + Graphics object consisting of 3 graphics primitives """ cdef int i @@ -333,6 +335,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base): sage: a.forward_transform() sage: a.inverse_transform() sage: (a.plot()+b.plot()) + Graphics object consisting of 250 graphics primitives """ if xmin is None: @@ -410,6 +413,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base): sage: a.forward_transform() sage: a.inverse_transform() sage: (a.plot()+b.plot()) + Graphics object consisting of 250 graphics primitives sage: abs(sum([CDF(a[i])-CDF(b[i]) for i in range(125)])) < 2**-16 True @@ -422,6 +426,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base): sage: a.forward_transform() sage: a.inverse_transform() sage: (a.plot()+b.plot()) + Graphics object consisting of 256 graphics primitives """ cdef gsl_fft_complex_wavetable * wt diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py index ea7840d1a2f..bee8cde04e2 100644 --- a/src/sage/homology/chain_complex.py +++ b/src/sage/homology/chain_complex.py @@ -200,7 +200,7 @@ def ChainComplex(data=None, **kwds): sage: IZ = ChainComplex({0: identity_matrix(ZZ, 1)}) sage: IZ.differential() # the differentials in the chain complex - {0: [1], 1: [], -1: []} + {-1: [], 0: [1], 1: []} sage: IZ.differential(1).parent() Full MatrixSpace of 0 by 1 dense matrices over Integer Ring sage: mat = ChainComplex({0: matrix(ZZ, 3, 4)}).differential(1) @@ -880,15 +880,16 @@ def differential(self, dim=None): sage: D = ChainComplex({0: matrix(ZZ, 2, 2, [1,0,0,2])}) sage: D.differential() - {0: [1 0] - [0 2], 1: [], -1: []} + {-1: [], 0: [1 0] + [0 2], 1: []} sage: D.differential(0) [1 0] [0 2] sage: C = ChainComplex({0: identity_matrix(ZZ, 40)}) sage: C.differential() - {0: 40 x 40 dense matrix over Integer Ring, 1: [], - -1: 40 x 0 dense matrix over Integer Ring} + {-1: 40 x 0 dense matrix over Integer Ring, + 0: 40 x 40 dense matrix over Integer Ring, + 1: []} """ if dim is None: return copy(self._diff) diff --git a/src/sage/homology/chain_complex_homspace.py b/src/sage/homology/chain_complex_homspace.py index 3a3754be9ce..d63f9e690e7 100644 --- a/src/sage/homology/chain_complex_homspace.py +++ b/src/sage/homology/chain_complex_homspace.py @@ -25,37 +25,37 @@ sage: x Chain complex morphism from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring sage: x._matrix_dictionary - {0: [1 0 0 0 0 0 0 0 0] - [0 1 0 0 0 0 0 0 0] - [0 0 1 0 0 0 0 0 0] - [0 0 0 1 0 0 0 0 0] - [0 0 0 0 1 0 0 0 0] - [0 0 0 0 0 1 0 0 0] - [0 0 0 0 0 0 1 0 0] - [0 0 0 0 0 0 0 1 0] - [0 0 0 0 0 0 0 0 1], 1: [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - [0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] - [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0] - [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] - [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] - [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1], 2: [1 0 0 0 0 0] - [0 1 0 0 0 0] - [0 0 1 0 0 0] - [0 0 0 1 0 0] - [0 0 0 0 1 0] - [0 0 0 0 0 1], -1: [1]} + {-1: [1], 0: [1 0 0 0 0 0 0 0 0] + [0 1 0 0 0 0 0 0 0] + [0 0 1 0 0 0 0 0 0] + [0 0 0 1 0 0 0 0 0] + [0 0 0 0 1 0 0 0 0] + [0 0 0 0 0 1 0 0 0] + [0 0 0 0 0 0 1 0 0] + [0 0 0 0 0 0 0 1 0] + [0 0 0 0 0 0 0 0 1], 1: [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + [0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] + [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0] + [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] + [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] + [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1], 2: [1 0 0 0 0 0] + [0 1 0 0 0 0] + [0 0 1 0 0 0] + [0 0 0 1 0 0] + [0 0 0 0 1 0] + [0 0 0 0 0 1]} sage: S = simplicial_complexes.Sphere(2) sage: A = Hom(S,S) diff --git a/src/sage/homology/cubical_complex.py b/src/sage/homology/cubical_complex.py index f0100694107..c0dc67555ea 100644 --- a/src/sage/homology/cubical_complex.py +++ b/src/sage/homology/cubical_complex.py @@ -686,7 +686,9 @@ class :class:`Cube`, or lists or tuples suitable for conversion to sage: X.maximal_cells() {[0,0] x [2,3] x [-12,-12], [0,1] x [3,3] x [5,5], [0,1] x [2,2] x [3,3], [0,1] x [2,2] x [0,0], [0,1] x [3,3] x [6,6], [1,1] x [2,3] x [0,0], [0,1] x [2,2] x [-12,-12], [0,0] x [2,3] x [6,6], [1,1] x [2,3] x [-12,-12], [1,1] x [2,3] x [5,5], [0,1] x [2,2] x [5,5], [0,1] x [3,3] x [3,3], [1,1] x [2,3] x [3,3], [0,0] x [2,3] x [5,5], [0,1] x [3,3] x [0,0], [1,1] x [2,3] x [6,6], [0,1] x [2,2] x [6,6], [0,0] x [2,3] x [0,0], [0,0] x [2,3] x [3,3], [0,1] x [3,3] x [-12,-12]} sage: S1.cells() - {0: set([[1,1] x [2,2], [0,0] x [2,2], [1,1] x [3,3], [0,0] x [3,3]]), 1: set([[0,1] x [3,3], [1,1] x [2,3], [0,0] x [2,3], [0,1] x [2,2]]), -1: set([])} + {-1: set(), + 0: {[0,0] x [3,3], [1,1] x [3,3], [0,0] x [2,2], [1,1] x [2,2]}, + 1: {[0,1] x [2,2], [0,0] x [2,3], [1,1] x [2,3], [0,1] x [3,3]}} Chain complexes, homology, and cohomology:: @@ -886,7 +888,12 @@ def cells(self, subcomplex=None): sage: S2 = cubical_complexes.Sphere(2) sage: S2.cells()[2] - set([[1,1] x [0,1] x [0,1], [0,1] x [0,0] x [0,1], [0,1] x [1,1] x [0,1], [0,0] x [0,1] x [0,1], [0,1] x [0,1] x [1,1], [0,1] x [0,1] x [0,0]]) + {[0,1] x [0,1] x [0,0], + [0,1] x [0,1] x [1,1], + [0,0] x [0,1] x [0,1], + [0,1] x [1,1] x [0,1], + [0,1] x [0,0] x [0,1], + [1,1] x [0,1] x [0,1]} """ if subcomplex not in self._cells: if subcomplex is not None and subcomplex.dimension() > -1: @@ -942,9 +949,14 @@ def n_cubes(self, n, subcomplex=None): sage: C = cubical_complexes.Cube(3) sage: C.n_cubes(3) - set([[0,1] x [0,1] x [0,1]]) + {[0,1] x [0,1] x [0,1]} sage: C.n_cubes(2) - set([[1,1] x [0,1] x [0,1], [0,1] x [0,0] x [0,1], [0,1] x [1,1] x [0,1], [0,0] x [0,1] x [0,1], [0,1] x [0,1] x [1,1], [0,1] x [0,1] x [0,0]]) + {[0,1] x [0,1] x [0,0], + [0,1] x [0,1] x [1,1], + [0,0] x [0,1] x [0,1], + [0,1] x [1,1] x [0,1], + [0,1] x [0,0] x [0,1], + [1,1] x [0,1] x [0,1]} """ return set(self.n_cells(n, subcomplex)) diff --git a/src/sage/homology/delta_complex.py b/src/sage/homology/delta_complex.py index c661d425e91..b1346cea847 100644 --- a/src/sage/homology/delta_complex.py +++ b/src/sage/homology/delta_complex.py @@ -193,7 +193,10 @@ class DeltaComplex(GenericCellComplex): ``d``-simplices, as a list:: sage: P.cells() - {0: ((), ()), 1: ((1, 0), (1, 0), (0, 0)), 2: ((1, 0, 2), (0, 1, 2)), -1: ((),)} + {-1: ((),), + 0: ((), ()), + 1: ((1, 0), (1, 0), (0, 0)), + 2: ((1, 0, 2), (0, 1, 2))} - ``data`` may be a dictionary indexed by integers. For each integer `n`, the entry with key `n` is the list of @@ -204,7 +207,10 @@ class DeltaComplex(GenericCellComplex): ... [(1,0,2), (0, 1, 2)] ]) sage: cells_dict = P.cells() sage: cells_dict - {0: ((), ()), 1: ((1, 0), (1, 0), (0, 0)), 2: ((1, 0, 2), (0, 1, 2)), -1: ((),)} + {-1: ((),), + 0: ((), ()), + 1: ((1, 0), (1, 0), (0, 0)), + 2: ((1, 0, 2), (0, 1, 2))} sage: DeltaComplex(cells_dict) Delta complex with 2 vertices and 8 simplices sage: P == DeltaComplex(cells_dict) @@ -414,10 +420,10 @@ def subcomplex(self, data): sage: line = delta_complexes.Simplex(1) # an edge sage: line.cells() - {0: ((), ()), 1: ((0, 1),), -1: ((),)} + {-1: ((),), 0: ((), ()), 1: ((0, 1),)} sage: ends = line.subcomplex({0: (0, 1)}) sage: ends.cells() - {0: ((), ()), -1: ((),)} + {-1: ((),), 0: ((), ())} sage: line.homology(subcomplex=ends) {0: 0, 1: Z} """ @@ -512,10 +518,16 @@ def cells(self, subcomplex=None): sage: S2 = delta_complexes.Sphere(2) sage: S2.cells() - {0: ((), (), ()), 1: ((0, 1), (0, 2), (1, 2)), 2: ((0, 1, 2), (0, 1, 2)), -1: ((),)} + {-1: ((),), + 0: ((), (), ()), + 1: ((0, 1), (0, 2), (1, 2)), + 2: ((0, 1, 2), (0, 1, 2))} sage: A = S2.subcomplex({1: [0,2]}) # one edge sage: S2.cells(subcomplex=A) - {0: (None, None, None), 1: (None, (0, 2), None), 2: ((0, 1, 2), (0, 1, 2)), -1: (None,)} + {-1: (None,), + 0: (None, None, None), + 1: (None, (0, 2), None), + 2: ((0, 1, 2), (0, 1, 2))} """ cells = self._cells_dict.copy() if subcomplex is None: @@ -1282,9 +1294,9 @@ def _epi_from_standard_simplex(self, idx=-1, dim=None): sage: T = delta_complexes.Torus() sage: T._epi_from_standard_simplex()[1] - {(2, 0): 2, (1, 0): 1, (2, 1): 0} + {(1, 0): 1, (2, 0): 2, (2, 1): 0} sage: T._epi_from_standard_simplex()[0] - {(2,): 0, (0,): 0, (1,): 0} + {(0,): 0, (1,): 0, (2,): 0} """ if dim is None: dim = self.dimension() diff --git a/src/sage/homology/examples.py b/src/sage/homology/examples.py index 4dfe96b14ca..fbc59f93dc6 100644 --- a/src/sage/homology/examples.py +++ b/src/sage/homology/examples.py @@ -74,9 +74,9 @@ def matching(A, B): sage: from sage.homology.examples import matching sage: matching([1,2], [3,4]) - [set([(1, 3), (2, 4)]), set([(2, 3), (1, 4)])] + [{(1, 3), (2, 4)}, {(1, 4), (2, 3)}] sage: matching([0,2], [0]) - [set([(0, 0)]), set([(2, 0)])] + [{(0, 0)}, {(2, 0)}] """ answer = [] if len(A) == 0 or len(B) == 0: diff --git a/src/sage/homology/simplicial_complex.py b/src/sage/homology/simplicial_complex.py index b8f606664f4..655752e65dd 100644 --- a/src/sage/homology/simplicial_complex.py +++ b/src/sage/homology/simplicial_complex.py @@ -403,7 +403,7 @@ def set(self): EXAMPLES:: sage: Simplex(3).set() - frozenset([0, 1, 2, 3]) + frozenset({0, 1, 2, 3}) """ return self.__set @@ -1045,10 +1045,10 @@ def faces(self, subcomplex=None): sage: Y = SimplicialComplex([[1,2], [1,4]]) sage: Y.faces() - {0: set([(4,), (2,), (1,)]), 1: set([(1, 2), (1, 4)]), -1: set([()])} + {-1: {()}, 0: {(1,), (2,), (4,)}, 1: {(1, 2), (1, 4)}} sage: L = SimplicialComplex([[1,2]]) sage: Y.faces(subcomplex=L) - {0: set([(4,)]), 1: set([(1, 4)]), -1: set([])} + {-1: set(), 0: {(4,)}, 1: {(1, 4)}} """ # Make the subcomplex immutable if it is not if subcomplex is not None and subcomplex._is_mutable: @@ -1135,10 +1135,10 @@ def n_faces(self, n, subcomplex=None): sage: Z Simplicial complex with vertex set (1, 2, 3, 4) and facets {(1, 2, 3, 4)} sage: Z.n_faces(2) - set([(1, 3, 4), (1, 2, 3), (2, 3, 4), (1, 2, 4)]) + {(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)} sage: K = SimplicialComplex([[1,2,3], [2,3,4]]) sage: Z.n_faces(2, subcomplex=K) - set([(1, 3, 4), (1, 2, 4)]) + {(1, 2, 4), (1, 3, 4)} """ if n in self.faces(subcomplex): return self.faces(subcomplex)[n] diff --git a/src/sage/interfaces/gap.py b/src/sage/interfaces/gap.py index 075addc1ed1..c3208d9f3d2 100644 --- a/src/sage/interfaces/gap.py +++ b/src/sage/interfaces/gap.py @@ -1549,9 +1549,7 @@ def __reduce__(self): (, ()) sage: f, args = _ sage: f(*args) - Traceback (most recent call last): - ... - ValueError: The session in which this object was defined is no longer running. + ) failed: ValueError: The session in which this object was defined is no longer running.> """ return reduce_load, () # default is an invalid object @@ -1787,13 +1785,9 @@ def reduce_load(): sage: from sage.interfaces.gap import reduce_load sage: reduce_load() - Traceback (most recent call last): - ... - ValueError: The session in which this object was defined is no longer running. + ) failed: ValueError: The session in which this object was defined is no longer running.> sage: loads(dumps(gap(2))) - Traceback (most recent call last): - ... - ValueError: The session in which this object was defined is no longer running. + ) failed: ValueError: The session in which this object was defined is no longer running.> """ return GapElement(None, None) diff --git a/src/sage/interfaces/gp.py b/src/sage/interfaces/gp.py index 06aa956203e..79a6f000dce 100644 --- a/src/sage/interfaces/gp.py +++ b/src/sage/interfaces/gp.py @@ -613,9 +613,7 @@ def quit(self, verbose=False, timeout=0.25): 10 sage: gp.quit() sage: a - Traceback (most recent call last): - ... - ValueError: The pari session in which this object was defined is no longer running. + ) failed: ValueError: The pari session in which this object was defined is no longer running.> sage: gp(pi) 3.1415926535897932384626433832795028842 # 64-bit 3.141592653589793238462643383 # 32-bit diff --git a/src/sage/interfaces/qepcad.py b/src/sage/interfaces/qepcad.py index 35814ec5170..52b329b91c3 100644 --- a/src/sage/interfaces/qepcad.py +++ b/src/sage/interfaces/qepcad.py @@ -1562,7 +1562,7 @@ def __init__(self, formula, vars, qvars=[]): sage: f.formula 'x + y = 0' sage: f.vars - frozenset(['y', 'x']) + frozenset({'x', 'y'}) sage: f.qvars [] """ @@ -1629,13 +1629,13 @@ def _varset(self, p): (x, y) sage: K. = QQ[] sage: qf._varset(x) - frozenset(['x']) + frozenset({'x'}) sage: qf._varset(x*y) - frozenset(['y', 'x']) + frozenset({'x', 'y'}) sage: qf._varset(q) - frozenset(['q']) + frozenset({'q'}) sage: qf._varset(p*q) - frozenset(['q', 'p']) + frozenset({'p', 'q'}) """ try: vars = p.variables() @@ -1667,7 +1667,7 @@ def _combine_formulas(self, formulas): (x, y) sage: qf = qepcad_formula sage: qf._combine_formulas([x^2 == 0, y < 17]) - (['x^2 = 0', 'y < 17'], frozenset(['y', 'x'])) + (['x^2 = 0', 'y < 17'], frozenset({'x', 'y'})) """ formulas = map(self.atomic, formulas) formulas = map(self.atomic, formulas) @@ -1706,13 +1706,13 @@ def atomic(self, lhs, op='=', rhs=0): sage: def test_qf(qf): ....: return qf, qf.vars sage: test_qf(qf.atomic(a^2 + 17)) - (a^2 + 17 = 0, frozenset(['a'])) + (a^2 + 17 = 0, frozenset({'a'})) sage: test_qf(qf.atomic(a*b*c <= c^3)) - (a b c <= c^3, frozenset(['a', 'c', 'b'])) + (a b c <= c^3, frozenset({'a', 'b', 'c'})) sage: test_qf(qf.atomic(x+y^2, '!=', a+b)) - (y^2 + x /= a + b, frozenset(['y', 'x', 'b', 'a'])) + (y^2 + x /= a + b, frozenset({'a', 'b', 'x', 'y'})) sage: test_qf(qf.atomic(x, operator.lt)) - (x < 0, frozenset(['x'])) + (x < 0, frozenset({'x'})) """ if isinstance(lhs, qformula): return lhs diff --git a/src/sage/interfaces/quit.py b/src/sage/interfaces/quit.py index 58a087ddf2e..bd1e23ee852 100644 --- a/src/sage/interfaces/quit.py +++ b/src/sage/interfaces/quit.py @@ -102,13 +102,9 @@ def invalidate_all(): (2, 3) sage: sage.interfaces.quit.invalidate_all() sage: a - Traceback (most recent call last): - ... - ValueError: The maxima session in which this object was defined is no longer running. + ) failed: ValueError: The maxima session in which this object was defined is no longer running.> sage: b - Traceback (most recent call last): - ... - ValueError: The pari session in which this object was defined is no longer running. + ) failed: ValueError: The pari session in which this object was defined is no longer running.> However the maxima and gp sessions should still work out, though with their state reset: diff --git a/src/sage/interfaces/sage0.py b/src/sage/interfaces/sage0.py index 57d2e8c777f..d675fa1f0ba 100644 --- a/src/sage/interfaces/sage0.py +++ b/src/sage/interfaces/sage0.py @@ -503,7 +503,7 @@ def __repr__(self): EXAMPLES:: sage: sage0(4).gcd - + """ return str(self._obj.parent().eval('%s.%s'%(self._obj._name, self._name))) diff --git a/src/sage/libs/gap/element.pyx b/src/sage/libs/gap/element.pyx index d16ebea487d..3688abe562f 100644 --- a/src/sage/libs/gap/element.pyx +++ b/src/sage/libs/gap/element.pyx @@ -2524,8 +2524,8 @@ cdef class GapElement_Record(GapElement): sage: rec = libgap.eval('rec(a:=123, b:=456, Sym3:=SymmetricGroup(3))') sage: rec.sage() - {'a': 123, - 'Sym3': NotImplementedError('cannot construct equivalent Sage object',), + {'Sym3': NotImplementedError('cannot construct equivalent Sage object',), + 'a': 123, 'b': 456} """ result = dict() diff --git a/src/sage/libs/gap/libgap.pyx b/src/sage/libs/gap/libgap.pyx index bf148465862..32cdfa09753 100644 --- a/src/sage/libs/gap/libgap.pyx +++ b/src/sage/libs/gap/libgap.pyx @@ -109,7 +109,7 @@ Or get them as results of computations:: sage: rec['Sym3'] Sym( [ 1 .. 3 ] ) sage: dict(rec) - {'a': 123, 'Sym3': Sym( [ 1 .. 3 ] ), 'b': 456} + {'Sym3': Sym( [ 1 .. 3 ] ), 'a': 123, 'b': 456} The output is a Sage dictionary whose keys are Sage strings and whose Values are instances of :meth:`~sage.libs.gap.element.GapElement`. So, @@ -118,8 +118,8 @@ convert the entries into Sage objects, you should use the :meth:`~sage.libs.gap.element.GapElement.sage` method:: sage: rec.sage() - {'a': 123, - 'Sym3': NotImplementedError('cannot construct equivalent Sage object',), + {'Sym3': NotImplementedError('cannot construct equivalent Sage object',), + 'a': 123, 'b': 456} Now ``rec['a']`` is a Sage integer. We have not implemented the diff --git a/src/sage/libs/lrcalc/lrcalc.pyx b/src/sage/libs/lrcalc/lrcalc.pyx index 836844418ae..5fd37737f5a 100644 --- a/src/sage/libs/lrcalc/lrcalc.pyx +++ b/src/sage/libs/lrcalc/lrcalc.pyx @@ -27,13 +27,19 @@ Compute a product of Schur functions; return the coefficients in the Schur expansion:: sage: lrcalc.mult([2,1], [2,1]) - {[3, 3]: 1, [4, 2]: 1, [3, 1, 1, 1]: 1, [4, 1, 1]: 1, [2, 2, 2]: 1, [3, 2, 1]: 2, [2, 2, 1, 1]: 1} + {[2, 2, 1, 1]: 1, + [2, 2, 2]: 1, + [3, 1, 1, 1]: 1, + [3, 2, 1]: 2, + [3, 3]: 1, + [4, 1, 1]: 1, + [4, 2]: 1} Same product, but include only partitions with at most 3 rows. This corresponds to computing in the representation ring of gl(3):: sage: lrcalc.mult([2,1], [2,1], 3) - {[3, 3]: 1, [4, 2]: 1, [3, 2, 1]: 2, [2, 2, 2]: 1, [4, 1, 1]: 1} + {[2, 2, 2]: 1, [3, 2, 1]: 2, [3, 3]: 1, [4, 1, 1]: 1, [4, 2]: 1} We can also compute the fusion product, here for sl(3) and level 2:: @@ -43,25 +49,38 @@ We can also compute the fusion product, here for sl(3) and level 2:: Compute the expansion of a skew Schur function:: sage: lrcalc.skew([3,2,1],[2,1]) - {[3]: 1, [1, 1, 1]: 1, [2, 1]: 2} + {[1, 1, 1]: 1, [2, 1]: 2, [3]: 1} Compute the coproduct of a Schur function:: sage: lrcalc.coprod([3,2,1]) - {([2, 1, 1], [1, 1]): 1, ([3, 1, 1], [1]): 1, ([2, 1], [3]): 1, ([2, 1, 1], [2]): 1, ([3, 2, 1], []): 1, - ([3, 1], [2]): 1, ([3, 2], [1]): 1, ([2, 1], [2, 1]): 2, ([1, 1, 1], [2, 1]): 1, ([2, 2], [2]): 1, ([2, 2, 1], [1]): 1, - ([2, 2], [1, 1]): 1, ([3, 1], [1, 1]): 1} + {([1, 1, 1], [2, 1]): 1, + ([2, 1], [2, 1]): 2, + ([2, 1], [3]): 1, + ([2, 1, 1], [1, 1]): 1, + ([2, 1, 1], [2]): 1, + ([2, 2], [1, 1]): 1, + ([2, 2], [2]): 1, + ([2, 2, 1], [1]): 1, + ([3, 1], [1, 1]): 1, + ([3, 1], [2]): 1, + ([3, 1, 1], [1]): 1, + ([3, 2], [1]): 1, + ([3, 2, 1], []): 1} Multiply two Schubert polynomials:: sage: lrcalc.mult_schubert([4,2,1,3], [1,4,2,5,3]) - {[5, 4, 1, 2, 3]: 1, [5, 3, 1, 4, 2]: 1, [4, 5, 1, 3, 2]: 1, [6, 2, 1, 4, 3, 5]: 1} + {[4, 5, 1, 3, 2]: 1, + [5, 3, 1, 4, 2]: 1, + [5, 4, 1, 2, 3]: 1, + [6, 2, 1, 4, 3, 5]: 1} Same product, but include only permutations of 5 elements in the result. This corresponds to computing in the cohomology ring of Fl(5):: sage: lrcalc.mult_schubert([4,2,1,3], [1,4,2,5,3], 5) - {[5, 4, 1, 2, 3]: 1, [5, 3, 1, 4, 2]: 1, [4, 5, 1, 3, 2]: 1} + {[4, 5, 1, 3, 2]: 1, [5, 3, 1, 4, 2]: 1, [5, 4, 1, 2, 3]: 1} List all Littlewood-Richardson tableaux of skew shape `\mu/\nu`; in this example `\mu=[3,2,1]` and `\nu=[2,1]`. Specifying a third entry @@ -430,9 +449,9 @@ def mult(part1, part2, maxrows=None, level=None): sage: sorted(mult([2,1],[2,1],maxrows=2).items()) [([3, 3], 1), ([4, 2], 1)] sage: mult([2,1],[3,2,1],3) - {[3, 3, 3]: 1, [5, 2, 2]: 1, [5, 3, 1]: 1, [4, 4, 1]: 1, [4, 3, 2]: 2} + {[3, 3, 3]: 1, [4, 3, 2]: 2, [4, 4, 1]: 1, [5, 2, 2]: 1, [5, 3, 1]: 1} sage: mult([2,1],[2,1],3,3) - {[3, 3]: 1, [3, 2, 1]: 2, [2, 2, 2]: 1, [4, 1, 1]: 1} + {[2, 2, 2]: 1, [3, 2, 1]: 2, [3, 3]: 1, [4, 1, 1]: 1} sage: mult([2,1],[2,1],None,3) Traceback (most recent call last): ... diff --git a/src/sage/libs/ppl.pyx b/src/sage/libs/ppl.pyx index 2c078bd837f..ad15f8e9473 100644 --- a/src/sage/libs/ppl.pyx +++ b/src/sage/libs/ppl.pyx @@ -1939,7 +1939,11 @@ cdef class Polyhedron(_mutable_or_immutable): sage: cs.insert( 3*x+5*y<=10 ) sage: p = C_Polyhedron(cs) sage: p.maximize( x+y ) - {'sup_d': 3, 'sup_n': 10, 'bounded': True, 'maximum': True, 'generator': point(10/3, 0/3)} + {'bounded': True, + 'generator': point(10/3, 0/3), + 'maximum': True, + 'sup_d': 3, + 'sup_n': 10} Unbounded case:: @@ -1949,7 +1953,11 @@ cdef class Polyhedron(_mutable_or_immutable): sage: p.maximize( +x ) {'bounded': False} sage: p.maximize( -x ) - {'sup_d': 1, 'sup_n': 0, 'bounded': True, 'maximum': False, 'generator': closure_point(0/1)} + {'bounded': True, + 'generator': closure_point(0/1), + 'maximum': False, + 'sup_d': 1, + 'sup_n': 0} """ cdef PPL_Coefficient sup_n cdef PPL_Coefficient sup_d @@ -2010,7 +2018,11 @@ cdef class Polyhedron(_mutable_or_immutable): sage: cs.insert( 3*x+5*y<=10 ) sage: p = C_Polyhedron(cs) sage: p.minimize( x+y ) - {'minimum': True, 'bounded': True, 'inf_d': 1, 'generator': point(0/1, 0/1), 'inf_n': 0} + {'bounded': True, + 'generator': point(0/1, 0/1), + 'inf_d': 1, + 'inf_n': 0, + 'minimum': True} Unbounded case:: @@ -2018,7 +2030,11 @@ cdef class Polyhedron(_mutable_or_immutable): sage: cs.insert( x>0 ) sage: p = NNC_Polyhedron(cs) sage: p.minimize( +x ) - {'minimum': False, 'bounded': True, 'inf_d': 1, 'generator': closure_point(0/1), 'inf_n': 0} + {'bounded': True, + 'generator': closure_point(0/1), + 'inf_d': 1, + 'inf_n': 0, + 'minimum': False} sage: p.minimize( -x ) {'bounded': False} """ diff --git a/src/sage/logic/logic.py b/src/sage/logic/logic.py index 79811c94935..402be4de8b0 100644 --- a/src/sage/logic/logic.py +++ b/src/sage/logic/logic.py @@ -143,10 +143,24 @@ def truthtable(self, statement, start=0, end=-1): We can now create truthtable of rows 1 to 5:: sage: s2 = log.truthtable(s, 1, 5); s2 - [[['OPAREN', 'a', 'AND', 'b', 'OR', 'NOT', 'OPAREN', 'c', 'OR', 'a', 'CPAREN', 'CPAREN'], - {'a': 'False', 'c': 'True', 'b': 'False'}, ['a', 'b', 'c']], - ['False', 'False', 'True', 'False'], ['False', 'True', 'False', 'True'], - ['False', 'True', 'True', 'True'], ['True', 'False', 'False', 'False']] + [[['OPAREN', + 'a', + 'AND', + 'b', + 'OR', + 'NOT', + 'OPAREN', + 'c', + 'OR', + 'a', + 'CPAREN', + 'CPAREN'], + {'a': 'False', 'b': 'False', 'c': 'True'}, + ['a', 'b', 'c']], + ['False', 'False', 'True', 'False'], + ['False', 'True', 'False', 'True'], + ['False', 'True', 'True', 'True'], + ['True', 'False', 'False', 'False']] .. NOTE:: diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index dc3e1bbdf9a..305011ba062 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -228,7 +228,7 @@ cdef class Matrix(sage.structure.element.Matrix): [ x y 0] [ 0 0 2*x + y] sage: d = a.dict(); d - {(0, 1): y, (1, 2): 2*x + y, (0, 0): x} + {(0, 0): x, (0, 1): y, (1, 2): 2*x + y} Notice that changing the returned list does not change a (the list is a copy):: @@ -256,16 +256,16 @@ cdef class Matrix(sage.structure.element.Matrix): [0 1 2] [3 4 5] sage: v = a._dict(); v - {(0, 1): 1, (1, 2): 5, (1, 0): 3, (0, 2): 2, (1, 1): 4} + {(0, 1): 1, (0, 2): 2, (1, 0): 3, (1, 1): 4, (1, 2): 5} If you change a key of the dictionary, the corresponding entry of the matrix will be changed (but without clearing any caches of computing information about the matrix):: sage: v[0,1] = -2/3; v - {(0, 1): -2/3, (1, 2): 5, (1, 0): 3, (0, 2): 2, (1, 1): 4} + {(0, 1): -2/3, (0, 2): 2, (1, 0): 3, (1, 1): 4, (1, 2): 5} sage: a._dict() - {(0, 1): -2/3, (1, 2): 5, (1, 0): 3, (0, 2): 2, (1, 1): 4} + {(0, 1): -2/3, (0, 2): 2, (1, 0): 3, (1, 1): 4, (1, 2): 5} sage: a[0,1] -2/3 diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index ef3893dd0d2..fb7f574c206 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -12361,6 +12361,7 @@ cdef class Matrix(matrix1.Matrix): sage: A = matrix([[1,3,5,1],[2,4,5,6],[1,3,5,7]]) sage: A.plot() + Graphics object consisting of 1 graphics primitive Here we make a random matrix over RR and use cmap='hsv' to color the matrix elements different RGB colors (see documentation for @@ -12368,11 +12369,13 @@ cdef class Matrix(matrix1.Matrix): sage: A = random_matrix(RDF, 50) sage: plot(A, cmap='hsv') + Graphics object consisting of 1 graphics primitive Another random plot, but over GF(389):: sage: A = random_matrix(GF(389), 10) sage: A.plot(cmap='Oranges') + Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import matrix_plot return matrix_plot(self, *args, **kwds) diff --git a/src/sage/matrix/matrix_generic_sparse.pyx b/src/sage/matrix/matrix_generic_sparse.pyx index d8617c30f15..b2ff48addca 100644 --- a/src/sage/matrix/matrix_generic_sparse.pyx +++ b/src/sage/matrix/matrix_generic_sparse.pyx @@ -26,7 +26,7 @@ EXAMPLES:: sage: b[0,0] 1 sage: c.dict() - {(0, 1): x, (1, 2): x^5, (0, 0): 5, (1, 0): x^3, (0, 2): x^2, (1, 1): x^4} + {(0, 0): 5, (0, 1): x, (0, 2): x^2, (1, 0): x^3, (1, 1): x^4, (1, 2): x^5} sage: c.list() [5, x, x^2, x^3, x^4, x^5] sage: c.rows() diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx index 12a7bb2ca6b..b341691db1b 100644 --- a/src/sage/matrix/matrix_modn_sparse.pyx +++ b/src/sage/matrix/matrix_modn_sparse.pyx @@ -275,7 +275,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse): sage: MS = MatrixSpace(GF(13), 50, 50, sparse=True) sage: m = MS.random_element(density=0.002) sage: m._dict() - {(5, 25): 4, (4, 44): 7, (43, 43): 6, (26, 9): 9, (44, 38): 1} + {(4, 44): 7, (5, 25): 4, (26, 9): 9, (43, 43): 6, (44, 38): 1} TESTS:: diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 9712dedbd36..5e4156ba8cd 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -101,7 +101,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): sage: from sage.matroids.advanced import * sage: M = BasisMatroid() sage: M.groundset() - frozenset([]) + frozenset() sage: M.full_rank() 0 diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index b579e12e8c3..8b665b4e4d6 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -1659,7 +1659,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): [2, 3, 4, 5, 6] sage: M = matroids.CompleteGraphic(5) sage: M.cross_ratios() - set([]) + set() """ if hyperlines is None: hyperlines = self.flats(self.full_rank() - 2) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index b387cc4c993..1818ea20983 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -1811,9 +1811,9 @@ cdef class Matroid(SageObject): sage: M = matroids.named_matroids.Fano() sage: M.loops() - frozenset([]) + frozenset() sage: (M / ['a', 'b']).loops() - frozenset(['f']) + frozenset({'f'}) """ return self._closure(set()) @@ -2046,9 +2046,9 @@ cdef class Matroid(SageObject): sage: M = matroids.named_matroids.Fano().dual() sage: M.coloops() - frozenset([]) + frozenset() sage: (M \ ['a', 'b']).coloops() - frozenset(['f']) + frozenset({'f'}) """ return self._coclosure(set()) @@ -2641,14 +2641,13 @@ cdef class Matroid(SageObject): sage: M = matroids.named_matroids.Fano() sage: sorted([M._flags(1)]) - [[[frozenset(['a']), set(['a']), - frozenset(['c', 'b', 'e', 'd', 'g', 'f'])], [frozenset(['b']), - set(['b']), frozenset(['c', 'e', 'd', 'g', 'f'])], - [frozenset(['c']), set(['c']), frozenset(['e', 'd', 'g', 'f'])], - [frozenset(['d']), set(['d']), frozenset(['e', 'g', 'f'])], - [frozenset(['e']), set(['e']), frozenset(['g', 'f'])], - [frozenset(['f']), set(['f']), frozenset(['g'])], - [frozenset(['g']), set(['g']), frozenset([])]]] + [[[frozenset({'a'}), {'a'}, frozenset({'b', 'c', 'd', 'e', 'f', 'g'})], + [frozenset({'b'}), {'b'}, frozenset({'c', 'd', 'e', 'f', 'g'})], + [frozenset({'c'}), {'c'}, frozenset({'d', 'e', 'f', 'g'})], + [frozenset({'d'}), {'d'}, frozenset({'e', 'f', 'g'})], + [frozenset({'e'}), {'e'}, frozenset({'f', 'g'})], + [frozenset({'f'}), {'f'}, frozenset({'g'})], + [frozenset({'g'}), {'g'}, frozenset()]]] """ if r < 0: return [] @@ -3831,7 +3830,7 @@ cdef class Matroid(SageObject): sage: M = matroids.named_matroids.Fano() sage: M.modular_cut([M.groundset()]).difference( ....: [frozenset(M.groundset())]) - set([]) + set() """ final_list = set() temp_list = set([self.closure(X) for X in subsets]) # Checks validity @@ -4411,7 +4410,7 @@ cdef class Matroid(SageObject): sage: setprint(M.max_weight_independent()) {0, 1} sage: M.max_weight_coindependent(X=[], weights={}) - frozenset([]) + frozenset() """ if X is None: X = self.groundset() @@ -4493,7 +4492,7 @@ cdef class Matroid(SageObject): sage: setprint(M.max_weight_coindependent()) {0, 1, 2, 3, 4, 5} sage: M.max_weight_coindependent(X=[], weights={}) - frozenset([]) + frozenset() """ if X is None: X = self.groundset() diff --git a/src/sage/matroids/matroids_plot_helpers.py b/src/sage/matroids/matroids_plot_helpers.py index 012af2ab410..ee95bab8304 100644 --- a/src/sage/matroids/matroids_plot_helpers.py +++ b/src/sage/matroids/matroids_plot_helpers.py @@ -55,6 +55,7 @@ ....: 7: (3,3), 8: (4,0), 9: (-1,1), 10: (-2,-2)} sage: M1._cached_info={'plot_positions': pos_dict, 'plot_lineorders': None} sage: matroids_plot_helpers.geomrep(M1, sp=True) + Graphics object consisting of 22 graphics primitives """ # ***************************************************************************** diff --git a/src/sage/misc/abstract_method.py b/src/sage/misc/abstract_method.py index 52638a76c24..80b78c678b7 100644 --- a/src/sage/misc/abstract_method.py +++ b/src/sage/misc/abstract_method.py @@ -259,7 +259,8 @@ def abstract_methods_of_class(cls): ... def required2(): pass ... sage: sage.misc.abstract_method.abstract_methods_of_class(AbstractClass) - {'required': ['required1', 'required2'], 'optional': ['optional1', 'optional2']} + {'optional': ['optional1', 'optional2'], + 'required': ['required1', 'required2']} """ result = { "required" : [], diff --git a/src/sage/misc/bitset.pyx b/src/sage/misc/bitset.pyx index 111bbe21af1..e0f96427266 100644 --- a/src/sage/misc/bitset.pyx +++ b/src/sage/misc/bitset.pyx @@ -448,7 +448,7 @@ cdef class FrozenBitset: sage: list(FrozenBitset('00001' * 20)) [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99] sage: set(FrozenBitset('11011')) - set([0, 1, 3, 4]) + {0, 1, 3, 4} """ return iter(bitset_list(self._bitset)) @@ -1891,7 +1891,7 @@ cdef class Bitset(FrozenBitset): sage: a = Bitset('011' * 32) sage: a.clear() sage: set(a) - set([]) + set() """ bitset_clear(self._bitset) diff --git a/src/sage/misc/c3_controlled.pyx b/src/sage/misc/c3_controlled.pyx index fae71dfda43..b85fc06de7e 100644 --- a/src/sage/misc/c3_controlled.pyx +++ b/src/sage/misc/c3_controlled.pyx @@ -1325,9 +1325,9 @@ class HierarchyElement(object): sage: from sage.misc.c3_controlled import HierarchyElement sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) sage: HierarchyElement(1, P).all_bases() - set([1]) - sage: HierarchyElement(10, P).all_bases() - set([...]) + {1} + sage: HierarchyElement(10, P).all_bases() # random output + {10, 5, 2, 1} sage: sorted([x.value for x in HierarchyElement(10, P).all_bases()]) [1, 2, 5, 10] """ diff --git a/src/sage/misc/displayhook.py b/src/sage/misc/displayhook.py index 3878231620f..041dec81179 100644 --- a/src/sage/misc/displayhook.py +++ b/src/sage/misc/displayhook.py @@ -17,8 +17,8 @@ def __init__(self): EXAMPLES:: - sage: from sage.repl.display.python_hook import DisplayHook - sage: d = DisplayHook() + sage: from sage.repl.display.python_hook import DoctestDisplayHook + sage: d = DoctestDisplayHook() sage: d(set([1, 2, 3])) # Sage commandline output {1, 2, 3} sage: print(set([1, 2, 3])) # Plain Python output diff --git a/src/sage/misc/lazy_format.py b/src/sage/misc/lazy_format.py index 4e5e4dff589..2c583cf09de 100644 --- a/src/sage/misc/lazy_format.py +++ b/src/sage/misc/lazy_format.py @@ -36,9 +36,7 @@ class LazyFormat(str): The error only occurs upon printing:: sage: lf - Traceback (most recent call last): - ... - ValueError: Don't ever try to print me ! + ) failed: ValueError: Don't ever try to print me !> .. rubric:: Common use case: diff --git a/src/sage/misc/lazy_list.pyx b/src/sage/misc/lazy_list.pyx index 08a9e722b7d..567f1ee65ca 100644 --- a/src/sage/misc/lazy_list.pyx +++ b/src/sage/misc/lazy_list.pyx @@ -662,8 +662,8 @@ cdef class lazy_list(object): sage: from itertools import count sage: from sage.misc.lazy_list import lazy_list - sage: iter(lazy_list(count())) #random indirect doctest - + sage: iter(lazy_list(count())) + iterator of lazy list [0, 1, 2, ...] """ if self.stop == PY_SSIZE_T_MAX: return lazy_list_iterator(self) diff --git a/src/sage/misc/misc.py b/src/sage/misc/misc.py index 22918ed95b8..a1f232042b4 100644 --- a/src/sage/misc/misc.py +++ b/src/sage/misc/misc.py @@ -1728,8 +1728,8 @@ def powerset(X): You may also use subsets as an alias for powerset:: - sage: subsets([1,2,3]) # random object location in output - + sage: subsets([1,2,3]) + sage: list(subsets([1,2,3])) [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] diff --git a/src/sage/misc/preparser.py b/src/sage/misc/preparser.py index 705def82328..91b3590c183 100644 --- a/src/sage/misc/preparser.py +++ b/src/sage/misc/preparser.py @@ -314,7 +314,7 @@ def strip_string_literals(code, state=None): sage: s '[%(L1)s, %(L2)s, %(L3)s, %(L4)s]' sage: literals - {'L4': '"d\\""', 'L2': '"b"', 'L3': "'c'", 'L1': "'a'"} + {'L1': "'a'", 'L2': '"b"', 'L3': "'c'", 'L4': '"d\\""'} sage: print s % literals ['a', "b", 'c', "d\""] sage: print strip_string_literals(r'-"\\\""-"\\"-')[0] diff --git a/src/sage/misc/sage_input.py b/src/sage/misc/sage_input.py index 52733790cbe..e2fc3bd8905 100644 --- a/src/sage/misc/sage_input.py +++ b/src/sage/misc/sage_input.py @@ -3212,14 +3212,14 @@ def register_name(self, name): sage: sif = SageInputFormatter() sage: sif._names, sif._dup_names - (set([]), {}) + (set(), {}) sage: sif.register_name('x') sage: sif.register_name('y') sage: sif._names, sif._dup_names - (set(['y', 'x']), {}) + ({'x', 'y'}, {}) sage: sif.register_name('x') sage: sif._names, sif._dup_names - (set(['y', 'x']), {'x': 0}) + ({'x', 'y'}, {'x': 0}) """ if name is None: name = 'si' diff --git a/src/sage/misc/sage_timeit.py b/src/sage/misc/sage_timeit.py index 8eaa38f153a..177badd789e 100644 --- a/src/sage/misc/sage_timeit.py +++ b/src/sage/misc/sage_timeit.py @@ -55,9 +55,7 @@ class SageTimeitResult(): If the third argument is not a Python integer, a ``TypeError`` is raised:: sage: SageTimeitResult( (1, 2, 3, 4, 's') ) - Traceback (most recent call last): - ... - TypeError: * wants int + ) failed: TypeError: * wants int> """ def __init__(self, stats, series=None): @@ -152,6 +150,7 @@ def sage_timeit(stmt, globals_dict=None, preparse=None, number=0, repeat=3, prec 2.9258728027343752e-07 sage: t = stats.TimeSeries(s.series) sage: t.scale(10^6).plot_histogram(bins=20,figsize=[12,6], ymax=2) + Graphics object consisting of 20 graphics primitives The input expression can contain newlines (but doctests cannot, so diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index be9af6f0996..2af0cfd9910 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -326,7 +326,7 @@ class SageArgSpecVisitor(ast.NodeVisitor): sage: visitor.visit(ast.parse('[1,2,3]').body[0].value) [1, 2, 3] sage: visitor.visit(ast.parse("{'a':('e',2,[None,({False:True},'pi')]), 37.0:'temp'}").body[0].value) - {'a': ('e', 2, [None, ({False: True}, 'pi')]), 37.0: 'temp'} + {37.0: 'temp', 'a': ('e', 2, [None, ({False: True}, 'pi')])} sage: v = ast.parse("jc = ['veni', 'vidi', 'vici']").body[0]; v <_ast.Assign object at ...> sage: [x for x in dir(v) if not x.startswith('__')] @@ -906,7 +906,7 @@ def _sage_getargspec_from_ast(source): sage: from_ast(s) == inspect.getargspec(context['f']) True sage: set(from_ast(sms.sage_getsource(x)) == inspect.getargspec(x) for x in [factor, identity_matrix, Graph.__init__]) - set([True]) + {True} """ ast_args = ast.parse(source.lstrip()).body[0].args diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index d98ff961dee..b8bd4cc1165 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -120,9 +120,7 @@ def __init__(self, groups, base_field, is_simple=None, newform_level=None, All hell breaks loose if you try to do anything with `A`:: sage: A - Traceback (most recent call last): - ... - NotImplementedError: BUG -- lattice method must be defined in derived class + ) failed: NotImplementedError: BUG -- lattice method must be defined in derived class> All instances of this class are in the category of modular @@ -186,9 +184,7 @@ def lattice(self): sage: A = sage.modular.abvar.abvar.ModularAbelianVariety_abstract((Gamma0(37),), QQ) sage: A - Traceback (most recent call last): - ... - NotImplementedError: BUG -- lattice method must be defined in derived class + ) failed: NotImplementedError: BUG -- lattice method must be defined in derived class> """ raise NotImplementedError("BUG -- lattice method must be defined in derived class") ############################################################################# diff --git a/src/sage/modular/arithgroup/arithgroup_element.pyx b/src/sage/modular/arithgroup/arithgroup_element.pyx index f8d9deef1a0..c78ae79e151 100644 --- a/src/sage/modular/arithgroup/arithgroup_element.pyx +++ b/src/sage/modular/arithgroup/arithgroup_element.pyx @@ -415,8 +415,10 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): EXAMPLE:: sage: (SL2Z.1).__reduce__() - (Modular Group SL(2,Z), ([1 1] - [0 1],)) + (Modular Group SL(2,Z), ( + [1 1] + [0 1] + )) """ from all import SL2Z return SL2Z, (self.__x,) diff --git a/src/sage/modular/arithgroup/congroup_gammaH.py b/src/sage/modular/arithgroup/congroup_gammaH.py index 067d58f3739..b2b9b0f8fdd 100644 --- a/src/sage/modular/arithgroup/congroup_gammaH.py +++ b/src/sage/modular/arithgroup/congroup_gammaH.py @@ -573,7 +573,26 @@ def _coset_reduction_data_second_coord(G): sage: G = GammaH(240,[7,239]) sage: G._coset_reduction_data_second_coord() - {1: [1], 2: [1], 3: [1], 4: [1], 5: [1, 49], 6: [1], 48: [1, 191], 8: [1], 80: [1, 7, 49, 103], 10: [1, 49], 12: [1], 15: [1, 49], 240: [1, 7, 49, 103, 137, 191, 233, 239], 40: [1, 7, 49, 103], 20: [1, 49], 24: [1, 191], 120: [1, 7, 49, 103, 137, 191, 233, 239], 60: [1, 49, 137, 233], 30: [1, 49, 137, 233], 16: [1]} + {1: [1], + 2: [1], + 3: [1], + 4: [1], + 5: [1, 49], + 6: [1], + 8: [1], + 10: [1, 49], + 12: [1], + 15: [1, 49], + 16: [1], + 20: [1, 49], + 24: [1, 191], + 30: [1, 49, 137, 233], + 40: [1, 7, 49, 103], + 48: [1, 191], + 60: [1, 49, 137, 233], + 80: [1, 7, 49, 103], + 120: [1, 7, 49, 103, 137, 191, 233, 239], + 240: [1, 7, 49, 103, 137, 191, 233, 239]} sage: G = GammaH(1200,[-1,7]); G Congruence Subgroup Gamma_H(1200) with H generated by [7, 1199] sage: K = G._coset_reduction_data_second_coord().keys() ; K.sort() diff --git a/src/sage/modular/arithgroup/farey_symbol.pyx b/src/sage/modular/arithgroup/farey_symbol.pyx index 0bd6cb7bbbf..35bba1112f2 100644 --- a/src/sage/modular/arithgroup/farey_symbol.pyx +++ b/src/sage/modular/arithgroup/farey_symbol.pyx @@ -618,6 +618,7 @@ cdef class Farey: with pairings use the following command:: sage: FareySymbol(Gamma0(11)).fundamental_domain() + Graphics object consisting of 54 graphics primitives indicating that side 1 is paired with side 3 and side 2 is paired with side 4, see also :meth:`.paired_sides`. @@ -626,15 +627,18 @@ cdef class Farey: use the following command:: sage: FareySymbol(Gamma(3)).fundamental_domain(show_pairing=False) + Graphics object consisting of 48 graphics primitives Plot the fundamental domain of `\Gamma_0(23)` showing the left coset representatives:: sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset') + Graphics object consisting of 58 graphics primitives The same as above but with a custom linestyle:: sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset', linestyle=':', thickness='2') + Graphics object consisting of 58 graphics primitives """ from sage.plot.colors import rainbow diff --git a/src/sage/modular/modform/ambient.py b/src/sage/modular/modform/ambient.py index c83e175e591..a4e4f0cc416 100644 --- a/src/sage/modular/modform/ambient.py +++ b/src/sage/modular/modform/ambient.py @@ -369,9 +369,7 @@ def module(self): sage: M.module() Vector space of dimension 36 over Rational Field sage: M.basis() - Traceback (most recent call last): - ... - NotImplementedError: Computation of dimensions of weight 1 cusp forms spaces not implemented in general + ) failed: NotImplementedError: Computation of dimensions of weight 1 cusp forms spaces not implemented in general> """ if hasattr(self, "__module"): return self.__module try: diff --git a/src/sage/modular/modform/constructor.py b/src/sage/modular/modform/constructor.py index 5a2f49588e9..85762eee962 100644 --- a/src/sage/modular/modform/constructor.py +++ b/src/sage/modular/modform/constructor.py @@ -278,9 +278,7 @@ def ModularForms(group = 1, sage: M = ModularForms(Gamma1(57), 1); M Modular Forms space of dimension (unknown) for Congruence Subgroup Gamma1(57) of weight 1 over Rational Field sage: M.basis() - Traceback (most recent call last): - ... - NotImplementedError: Computation of dimensions of weight 1 cusp forms spaces not implemented in general + ) failed: NotImplementedError: Computation of dimensions of weight 1 cusp forms spaces not implemented in general> sage: M.cuspidal_subspace().basis() Traceback (most recent call last): ... diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index 3e26fa5879d..459221ffbfb 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -2285,19 +2285,23 @@ class of cuspidal newforms in this ambient space. sage: M = ModularSymbols(DirichletGroup(24,QQ).1,2,sign=1) sage: M.compact_newform_eigenvalues(prime_range(10),'a') - [([-1/2 -1/2] - [ 1/2 -1/2] - [ -1 1] - [ -2 0], (1, -2*a0 - 1))] + [( + [-1/2 -1/2] + [ 1/2 -1/2] + [ -1 1] + [ -2 0], (1, -2*a0 - 1) + )] sage: a = M.compact_newform_eigenvalues([1..10],'a')[0] sage: a[0]*a[1] (1, a0, a0 + 1, -2*a0 - 2, -2*a0 - 2, -a0 - 2, -2, 2*a0 + 4, -1, 2*a0 + 4) sage: M = ModularSymbols(DirichletGroup(13).0^2,2,sign=1) sage: M.compact_newform_eigenvalues(prime_range(10),'a') - [([ -zeta6 - 1] - [ 2*zeta6 - 2] - [-2*zeta6 + 1] - [ 0], (1))] + [( + [ -zeta6 - 1] + [ 2*zeta6 - 2] + [-2*zeta6 + 1] + [ 0], (1) + )] sage: a = M.compact_newform_eigenvalues([1..10],'a')[0] sage: a[0]*a[1] (1, -zeta6 - 1, 2*zeta6 - 2, zeta6, -2*zeta6 + 1, -2*zeta6 + 4, 0, 2*zeta6 - 1, -zeta6, 3*zeta6 - 3) diff --git a/src/sage/modular/modsym/relation_matrix.py b/src/sage/modular/modsym/relation_matrix.py index f7d6f47fc78..4107115c387 100644 --- a/src/sage/modular/modsym/relation_matrix.py +++ b/src/sage/modular/modsym/relation_matrix.py @@ -88,14 +88,19 @@ def modS_relations(syms): sage: syms = ManinSymbolList_gamma0(2, 4); syms Manin Symbol List of weight 4 for Gamma0(2) sage: modS_relations(syms) - set([((3, -1), (4, 1)), ((5, -1), (5, 1)), ((1, 1), (6, 1)), ((0, 1), (7, 1)), ((3, 1), (4, -1)), ((2, 1), (8, 1))]) + {((0, 1), (7, 1)), + ((1, 1), (6, 1)), + ((2, 1), (8, 1)), + ((3, -1), (4, 1)), + ((3, 1), (4, -1)), + ((5, -1), (5, 1))} :: sage: syms = ManinSymbolList_gamma0(7, 2); syms Manin Symbol List of weight 2 for Gamma0(7) sage: modS_relations(syms) - set([((3, 1), (4, 1)), ((2, 1), (7, 1)), ((5, 1), (6, 1)), ((0, 1), (1, 1))]) + {((0, 1), (1, 1)), ((2, 1), (7, 1)), ((3, 1), (4, 1)), ((5, 1), (6, 1))} Next we do an example with Gamma1:: @@ -103,7 +108,14 @@ def modS_relations(syms): sage: syms = ManinSymbolList_gamma1(3,2); syms Manin Symbol List of weight 2 for Gamma1(3) sage: modS_relations(syms) - set([((3, 1), (6, 1)), ((0, 1), (5, 1)), ((0, 1), (2, 1)), ((3, 1), (4, 1)), ((6, 1), (7, 1)), ((1, 1), (2, 1)), ((1, 1), (5, 1)), ((4, 1), (7, 1))]) + {((0, 1), (2, 1)), + ((0, 1), (5, 1)), + ((1, 1), (2, 1)), + ((1, 1), (5, 1)), + ((3, 1), (4, 1)), + ((3, 1), (6, 1)), + ((4, 1), (7, 1)), + ((6, 1), (7, 1))} """ if not isinstance(syms, manin_symbols.ManinSymbolList): raise TypeError("syms must be a ManinSymbolList") @@ -140,7 +152,30 @@ def modI_relations(syms, sign): sage: L = sage.modular.modsym.manin_symbols.ManinSymbolList_gamma1(4, 3) sage: sage.modular.modsym.relation_matrix.modI_relations(L, 1) - set([((14, 1), (20, 1)), ((0, 1), (0, -1)), ((7, 1), (7, -1)), ((9, 1), (3, -1)), ((3, 1), (9, -1)), ((16, 1), (22, 1)), ((10, 1), (4, -1)), ((1, 1), (1, -1)), ((19, 1), (19, 1)), ((8, 1), (2, -1)), ((12, 1), (12, 1)), ((20, 1), (14, 1)), ((21, 1), (15, 1)), ((5, 1), (11, -1)), ((15, 1), (21, 1)), ((22, 1), (16, 1)), ((6, 1), (6, -1)), ((2, 1), (8, -1)), ((17, 1), (23, 1)), ((4, 1), (10, -1)), ((18, 1), (18, 1)), ((11, 1), (5, -1)), ((23, 1), (17, 1)), ((13, 1), (13, 1))]) + {((0, 1), (0, -1)), + ((1, 1), (1, -1)), + ((2, 1), (8, -1)), + ((3, 1), (9, -1)), + ((4, 1), (10, -1)), + ((5, 1), (11, -1)), + ((6, 1), (6, -1)), + ((7, 1), (7, -1)), + ((8, 1), (2, -1)), + ((9, 1), (3, -1)), + ((10, 1), (4, -1)), + ((11, 1), (5, -1)), + ((12, 1), (12, 1)), + ((13, 1), (13, 1)), + ((14, 1), (20, 1)), + ((15, 1), (21, 1)), + ((16, 1), (22, 1)), + ((17, 1), (23, 1)), + ((18, 1), (18, 1)), + ((19, 1), (19, 1)), + ((20, 1), (14, 1)), + ((21, 1), (15, 1)), + ((22, 1), (16, 1)), + ((23, 1), (17, 1))} .. warning:: diff --git a/src/sage/modular/overconvergent/genus0.py b/src/sage/modular/overconvergent/genus0.py index a0095fcc9ee..f9ac34c759d 100644 --- a/src/sage/modular/overconvergent/genus0.py +++ b/src/sage/modular/overconvergent/genus0.py @@ -1602,6 +1602,7 @@ def valuation_plot(self, rmax = None): sage: o=OverconvergentModularForms(3, 0, 1/2) sage: f=o.eigenfunctions(4)[1] sage: f.valuation_plot() + Graphics object consisting of 1 graphics primitive """ if rmax is None: rmax = ZZ(self.prime())/ZZ(1 + self.prime()) return plot(self.r_ord, (0, rmax) ) diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index d430bcdfa25..caca6b2da1c 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -1981,6 +1981,7 @@ cdef class FreeModuleElement(element_Vector): # abstract base class sage: A = plot(v) sage: B = v.plot() sage: A+B # should just show one vector + Graphics object consisting of 2 graphics primitives Examples of the plot types:: @@ -1988,53 +1989,64 @@ cdef class FreeModuleElement(element_Vector): # abstract base class sage: B = plot(v, plot_type='point', color='green', size=20) sage: C = plot(v, plot_type='step') # calls v.plot_step() sage: A+B+C + Graphics object consisting of 3 graphics primitives You can use the optional arguments for :meth:`plot_step`:: sage: eps = 0.1 sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) + Graphics object consisting of 1 graphics primitive Three-dimensional examples:: sage: v = vector(RDF, (1,2,1)) sage: plot(v) # defaults to an arrow plot + Graphics3d Object :: sage: plot(v, plot_type='arrow') + Graphics3d Object :: sage: from sage.plot.plot3d.shapes2 import frame3d sage: plot(v, plot_type='point')+frame3d((0,0,0), v.list()) + Graphics3d Object :: sage: plot(v, plot_type='step') # calls v.plot_step() + Graphics object consisting of 1 graphics primitive :: sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) + Graphics object consisting of 1 graphics primitive With greater than three coordinates, it defaults to a step plot:: sage: v = vector(RDF, (1,2,3,4)) sage: plot(v) + Graphics object consisting of 1 graphics primitive One dimensional vectors are plotted along the horizontal axis of the coordinate plane:: sage: plot(vector([1])) + Graphics object consisting of 1 graphics primitive An optional start argument may also be specified by a tuple, list, or vector:: sage: u = vector([1,2]); v = vector([2,5]) sage: plot(u, start=v) + Graphics object consisting of 1 graphics primitive TESTS:: sage: u = vector([1,1]); v = vector([2,2,2]); z=(3,3,3) sage: plot(u) #test when start=None + Graphics object consisting of 1 graphics primitive :: @@ -2117,6 +2129,7 @@ cdef class FreeModuleElement(element_Vector): # abstract base class sage: eps=0.1 sage: v = vector(RDF, [sin(n*eps) for n in range(100)]) sage: v.plot_step(eps=eps, xmax=5, hue=0) + Graphics object consisting of 1 graphics primitive """ if res is None: res = self.degree() @@ -4358,9 +4371,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): This lack of bounds checking causes trouble later:: sage: v - Traceback (most recent call last): - ... - IndexError: list assignment index out of range + ) failed: IndexError: list assignment index out of range> """ if not self._is_mutable: raise ValueError("vector is immutable; please change a copy instead (use copy())") diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 3b9baaf68c4..d1a0d7a0eea 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -59,6 +59,7 @@ Since it has only two variables, we can solve it graphically:: sage: P.plot() + Graphics object consisting of 19 graphics primitives The simplex method can be applied only to :class:`problems in standard form @@ -1100,6 +1101,7 @@ def plot(self, *args, **kwds): We check that zero objective can be dealt with:: sage: LPProblem(A, b, (0, 0), ["C", "B"], variable_type=">=").plot() + Graphics object consisting of 8 graphics primitives """ FP = self.plot_feasible_set(*args, **kwds) c = self.c().n().change_ring(QQ) diff --git a/src/sage/numerical/linear_tensor.py b/src/sage/numerical/linear_tensor.py index fbbc7451a78..5b9cfd0409c 100644 --- a/src/sage/numerical/linear_tensor.py +++ b/src/sage/numerical/linear_tensor.py @@ -42,7 +42,7 @@ sage: f_scalar = (3 + b[7] + 2*b[9]); f_scalar 3 + x_0 + 2*x_1 sage: f_scalar.dict() - {0: 1.0, 1: 2.0, -1: 3.0} + {-1: 3.0, 0: 1.0, 1: 2.0} sage: f_scalar.dict()[1] 2.0 sage: f_scalar.coefficient(b[9]) diff --git a/src/sage/numerical/optimize.py b/src/sage/numerical/optimize.py index 867de8614ae..e0a5e54f894 100644 --- a/src/sage/numerical/optimize.py +++ b/src/sage/numerical/optimize.py @@ -72,6 +72,7 @@ def find_root(f, a, b, xtol=10e-13, rtol=4.5e-16, maxiter=100, full_output=False This agrees with the plot:: sage: plot(f,2,2.01) + Graphics object consisting of 1 graphics primitive """ try: return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output) diff --git a/src/sage/plot/animate.py b/src/sage/plot/animate.py index 0a0eb141766..8954bef501d 100644 --- a/src/sage/plot/animate.py +++ b/src/sage/plot/animate.py @@ -54,7 +54,9 @@ ....: return sphere((0,0,0),1,color='red',opacity=.5)+parametric_plot3d([t,x,s],(s,-1,1),(t,-1,1),color='green',opacity=.7) sage: sp = animate([sphere_and_plane(x) for x in sxrange(-1,1,.3)]) sage: sp[0] # first frame + Graphics3d Object sage: sp[-1] # last frame + Graphics3d Object sage: sp.show() # optional -- ImageMagick sage: (x,y,z) = var('x,y,z') @@ -62,6 +64,7 @@ ....: return implicit_plot3d((x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=[1,3,5], region=lambda x,y,z: x<=t or y>=t or z<=t) sage: a = animate([frame(t) for t in srange(.01,1.5,.2)]) sage: a[0] # first frame + Graphics3d Object sage: a.show() # optional -- ImageMagick If the input objects do not have a ``save_image`` method, then the diff --git a/src/sage/plot/arc.py b/src/sage/plot/arc.py index a040f7f81e3..c11e83c16af 100644 --- a/src/sage/plot/arc.py +++ b/src/sage/plot/arc.py @@ -252,6 +252,7 @@ def _render_on_subplot(self, subplot): TESTS:: sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A + Graphics object consisting of 1 graphics primitive """ import matplotlib.patches as patches from sage.plot.misc import get_matplotlib_linestyle @@ -330,19 +331,24 @@ def arc(center, r1, r2=None, angle=0.0, sector=(0.0,2*pi), **options): `(\pi/4,3*\pi/4)`:: sage: arc((0,0), 1, sector=(pi/4,3*pi/4)) + Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, sector=(0,pi/2)) + Graphics object consisting of 1 graphics primitive Plot an arc of a rotated ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, angle=pi/5, sector=(0,pi/2)) + Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse in red with a dashed linestyle:: sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="dashed", color="red") + Graphics object consisting of 1 graphics primitive sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="--", color="red") + Graphics object consisting of 1 graphics primitive The default aspect ratio for arcs is 1.0:: diff --git a/src/sage/plot/arrow.py b/src/sage/plot/arrow.py index fb7411b9c2c..3eb97ebad16 100644 --- a/src/sage/plot/arrow.py +++ b/src/sage/plot/arrow.py @@ -120,6 +120,7 @@ def _render_on_subplot(self, subplot): This function implicitly ends up rendering this arrow on a matplotlib subplot: sage: arrow(path=[[(0,1), (2,-1), (4,5)]]) + Graphics object consisting of 1 graphics primitive """ from sage.plot.misc import get_matplotlib_linestyle @@ -317,6 +318,7 @@ def _render_on_subplot(self, subplot): a matplotlib subplot:: sage: arrow((0,1), (2,-1)) + Graphics object consisting of 1 graphics primitive TESTS: @@ -444,7 +446,9 @@ def arrow(tailpoint=None, headpoint=None, **kwds): EXAMPLES:: sage: arrow((0,0), (1,1)) + Graphics object consisting of 1 graphics primitive sage: arrow((0,0,1), (1,1,1)) + Graphics3d Object """ try: return arrow2d(tailpoint, headpoint, **kwds) @@ -500,42 +504,53 @@ def arrow2d(tailpoint=None, headpoint=None, path=None, **options): A straight, blue arrow:: sage: arrow2d((1, 1), (3, 3)) + Graphics object consisting of 1 graphics primitive Make a red arrow:: sage: arrow2d((-1, -1), (2, 3), color=(1,0,0)) + Graphics object consisting of 1 graphics primitive sage: arrow2d((-1, -1), (2, 3), color='red') + Graphics object consisting of 1 graphics primitive You can change the width of an arrow:: sage: arrow2d((1, 1), (3, 3), width=5, arrowsize=15) + Graphics object consisting of 1 graphics primitive Use a dashed line instead of a solid one for the arrow:: sage: arrow2d((1, 1), (3, 3), linestyle='dashed') + Graphics object consisting of 1 graphics primitive sage: arrow2d((1, 1), (3, 3), linestyle='--') + Graphics object consisting of 1 graphics primitive A pretty circle of arrows:: sage: sum([arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) for x in [0..2*pi,step=0.1]]) + Graphics object consisting of 63 graphics primitives If we want to draw the arrow between objects, for example, the boundaries of two lines, we can use the arrowshorten option to make the arrow shorter by a certain number of points:: sage: line([(0,0),(1,0)],thickness=10)+line([(0,1),(1,1)], thickness=10)+arrow2d((0.5,0),(0.5,1), arrowshorten=10,rgbcolor=(1,0,0)) + Graphics object consisting of 3 graphics primitives If BOTH headpoint and tailpoint are None, then an empty plot is returned:: sage: arrow2d(headpoint=None, tailpoint=None) + Graphics object consisting of 0 graphics primitives We can also draw an arrow with a legend:: sage: arrow((0,0), (0,2), legend_label='up', legend_color='purple') + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: arrow2d((-2, 2), (7,1), frame=True) + Graphics object consisting of 1 graphics primitive sage: arrow2d((-2, 2), (7,1)).show(frame=True) """ from sage.plot.all import Graphics diff --git a/src/sage/plot/bar_chart.py b/src/sage/plot/bar_chart.py index 155bfd2db61..e6cf3136844 100644 --- a/src/sage/plot/bar_chart.py +++ b/src/sage/plot/bar_chart.py @@ -108,6 +108,7 @@ def _render_on_subplot(self, subplot): is executed:: sage: bar_chart([1,2,10]) + Graphics object consisting of 1 graphics primitive """ options = self.options() color = options['rgbcolor'] @@ -131,22 +132,27 @@ def bar_chart(datalist, **options): A bar_chart with blue bars:: sage: bar_chart([1,2,3,4]) + Graphics object consisting of 1 graphics primitive A bar_chart with thinner bars:: sage: bar_chart([x^2 for x in range(1,20)], width=0.2) + Graphics object consisting of 1 graphics primitive A bar_chart with negative values and red bars:: sage: bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive A bar chart with a legend (it's possible, not necessarily useful):: sage: bar_chart([-1,1,-1,1], legend_label='wave') + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0), axes=False) + Graphics object consisting of 1 graphics primitive sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0)).show(axes=False) # These are equivalent """ dl = len(datalist) diff --git a/src/sage/plot/bezier_path.py b/src/sage/plot/bezier_path.py index 27eb3c93663..82d840a3b53 100644 --- a/src/sage/plot/bezier_path.py +++ b/src/sage/plot/bezier_path.py @@ -39,6 +39,7 @@ class BezierPath(GraphicPrimitive_xydata): We use :func:`bezier_path` to actually plot Bezier curves:: sage: bezier_path([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]],linestyle="dashed") + Graphics object consisting of 1 graphics primitive """ def __init__(self, path, options): """ @@ -137,10 +138,12 @@ def plot3d(self, z=0, **kwds): sage: A = b.plot3d() sage: B = b.plot3d(z=2) sage: A+B + Graphics3d Object :: sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) + Graphics3d Object """ from sage.plot.plot3d.shapes2 import bezier3d options = self._plot3d_options() @@ -169,10 +172,12 @@ def _render_on_subplot(self, subplot): TESTS:: sage: bezier_path([[(0,1),(.5,0),(1,1)]]) + Graphics object consisting of 1 graphics primitive :: sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]]) + Graphics object consisting of 1 graphics primitive """ from matplotlib.patches import PathPatch from matplotlib.path import Path @@ -269,16 +274,19 @@ def bezier_path(path, **options): sage: path = [[(0,0),(.5,.1),(.75,3),(1,0)],[(.5,1),(.5,0)],[(.2,.5)]] sage: b = bezier_path(path, linestyle='dashed', rgbcolor='green') sage: b + Graphics object consisting of 1 graphics primitive To construct a simple curve, create a list containing a single list:: sage: path = [[(0,0),(.5,1),(1,0)]] sage: curve = bezier_path(path, linestyle='dashed', rgbcolor='green') sage: curve + Graphics object consisting of 1 graphics primitive Extra options will get passed on to :meth:`~Graphics.show`, as long as they are valid:: sage: bezier_path([[(0,1),(.5,0),(1,1)]], fontsize=50) + Graphics object consisting of 1 graphics primitive sage: bezier_path([[(0,1),(.5,0),(1,1)]]).show(fontsize=50) # These are equivalent TESTS: diff --git a/src/sage/plot/circle.py b/src/sage/plot/circle.py index 8eec2a06e97..9fb6e93134c 100644 --- a/src/sage/plot/circle.py +++ b/src/sage/plot/circle.py @@ -176,11 +176,13 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: sage: circle((0,0), 1).plot3d() + Graphics3d Object This example uses this method implicitly, but does not pass the optional parameter z to this method:: sage: sum([circle((random(),random()), random()).plot3d(z=random()) for _ in range(20)]) + Graphics3d Object These examples are explicit, and pass z to this method:: @@ -256,17 +258,20 @@ def circle(center, radius, **options): sage: c = circle((1,1), 1) sage: c + Graphics object consisting of 1 graphics primitive :: sage: c = circle((1,1), 1, rgbcolor=(1,0,0), linestyle='-.') sage: c + Graphics object consisting of 1 graphics primitive We can also use this command to plot three-dimensional circles parallel to the `xy`-plane:: sage: c = circle((1,1,3), 1, rgbcolor=(1,0,0)) sage: c + Graphics3d Object sage: type(c) @@ -292,15 +297,18 @@ def circle(center, radius, **options): This produces red fill in a blue circle:: sage: circle((2,3), 1, fill=True, edgecolor='blue') + Graphics object consisting of 1 graphics primitive This produces an all-green filled circle:: sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green') + Graphics object consisting of 1 graphics primitive The option ``hue`` overrides *all* other options, so be careful with its use. This produces a purplish filled circle:: sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green', hue=.8) + Graphics object consisting of 1 graphics primitive And circles with legends:: @@ -313,6 +321,7 @@ def circle(center, radius, **options): Extra options will get passed on to show(), as long as they are valid:: sage: circle((0, 0), 2, figsize=[10,10]) # That circle is huge! + Graphics object consisting of 1 graphics primitive :: diff --git a/src/sage/plot/colors.py b/src/sage/plot/colors.py index d6e28ea242c..0093f8a1044 100644 --- a/src/sage/plot/colors.py +++ b/src/sage/plot/colors.py @@ -864,7 +864,7 @@ def __hex__(self): sage: hex(Color(0.5, 1.0, 1.0, space='hsv')) '00ffff' sage: set([len(hex(Color(t, 1-t, t * t))) for t in srange(0, 1, 0.1)]) - set([6]) + {6} """ return self.html_color()[1:] @@ -1108,7 +1108,7 @@ def __init__(self): sage: from sage.plot.colors import ColorsDict sage: cols = ColorsDict() sage: set([(type(c), type(cols[c])) for c in cols]) - set([(, )]) + {(, )} sage: sorted(cols) ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', ...] sage: len(cols) @@ -1192,6 +1192,7 @@ def hue(h, s=1, v=1): sage: for phi in xsrange(0, 2 * pi, 1 / pi): ... p += plot(sin(x + phi), (x, -7, 7), rgbcolor = hue(phi)) sage: p + Graphics object consisting of 20 graphics primitives INPUT: diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index f8a5ae51235..fbcbb348a16 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -230,6 +230,7 @@ class ComplexPlot(GraphicPrimitive): TESTS:: sage: complex_plot(lambda x: x^2, (-5, 5), (-5, 5)) + Graphics object consisting of 1 graphics primitive """ options = self.options() x0,x1 = float(self.xrange[0]), float(self.xrange[1]) @@ -274,35 +275,43 @@ def complex_plot(f, xrange, yrange, **options): Here we plot a couple of simple functions:: sage: complex_plot(sqrt(x), (-5, 5), (-5, 5)) + Graphics object consisting of 1 graphics primitive :: sage: complex_plot(sin(x), (-5, 5), (-5, 5)) + Graphics object consisting of 1 graphics primitive :: sage: complex_plot(log(x), (-10, 10), (-10, 10)) + Graphics object consisting of 1 graphics primitive :: sage: complex_plot(exp(x), (-10, 10), (-10, 10)) + Graphics object consisting of 1 graphics primitive A function with some nice zeros and a pole:: sage: f(z) = z^5 + z - 1 + 1/z sage: complex_plot(f, (-3, 3), (-3, 3)) + Graphics object consisting of 1 graphics primitive Here is the identity, useful for seeing what values map to what colors:: sage: complex_plot(lambda z: z, (-3, 3), (-3, 3)) + Graphics object consisting of 1 graphics primitive The Riemann Zeta function:: sage: complex_plot(zeta, (-30,30), (-30,30)) + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: complex_plot(lambda z: z, (-3, 3), (-3, 3), figsize=[1,1]) + Graphics object consisting of 1 graphics primitive :: @@ -320,6 +329,10 @@ def complex_plot(f, xrange, yrange, **options): sage: R = complex_plot(h, (-10, 10), (-10, 10)) sage: S = complex_plot(exp(x)-sin(x), (-10, 10), (-10, 10)) sage: P; Q; R; S + Graphics object consisting of 1 graphics primitive + Graphics object consisting of 1 graphics primitive + Graphics object consisting of 1 graphics primitive + Graphics object consisting of 1 graphics primitive Test to make sure symbolic functions still work without declaring a variable. (We don't do this in practice because it doesn't use @@ -328,6 +341,7 @@ def complex_plot(f, xrange, yrange, **options): :: sage: complex_plot(sqrt, (-5, 5), (-5, 5)) + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics from sage.plot.misc import setup_for_eval_on_grid diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index ef47039ea21..763a71ee548 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -56,6 +56,7 @@ class ContourPlot(GraphicPrimitive): sage: x,y = var('x,y') sage: contour_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv') + Graphics object consisting of 1 graphics primitive """ def __init__(self, xy_data_array, xrange, yrange, options): """ @@ -144,6 +145,7 @@ def _render_on_subplot(self, subplot): sage: x,y = var('x,y') sage: contour_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv') + Graphics object consisting of 1 graphics primitive """ from sage.rings.integer import Integer options = self.options() @@ -319,16 +321,19 @@ def contour_plot(f, xrange, yrange, **options): sage: x,y = var('x,y') sage: contour_plot(cos(x^2+y^2), (x, -4, 4), (y, -4, 4)) + Graphics object consisting of 1 graphics primitive Here we change the ranges and add some options:: sage: x,y = var('x,y') sage: contour_plot((x^2)*cos(x*y), (x, -10, 5), (y, -5, 5), fill=False, plot_points=150) + Graphics object consisting of 1 graphics primitive An even more complicated plot:: sage: x,y = var('x,y') sage: contour_plot(sin(x^2 + y^2)*cos(x)*sin(y), (x, -4, 4), (y, -4, 4),plot_points=150) + Graphics object consisting of 1 graphics primitive Some elliptic curves, but with symbolic endpoints. In the first example, the plot is rotated 90 degrees because we switch the @@ -336,72 +341,87 @@ def contour_plot(f, xrange, yrange, **options): sage: x,y = var('x,y') sage: contour_plot(y^2 + 1 - x^3 - x, (y,-pi,pi), (x,-pi,pi)) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi)) + Graphics object consisting of 1 graphics primitive We can play with the contour levels:: sage: x,y = var('x,y') sage: f(x,y) = x^2 + y^2 sage: contour_plot(f, (-2, 2), (-2, 2)) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (-2, 2), (-2, 2), contours=2, cmap=[(1,0,0), (0,1,0), (0,0,1)]) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (-2, 2), (-2, 2), contours=(0.1, 1.0, 1.2, 1.4), cmap='hsv') + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (-2, 2), (-2, 2), contours=(1.0,), fill=False) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(x-y^2,(x,-5,5),(y,-3,3),contours=[-4,0,1]) + Graphics object consisting of 1 graphics primitive We can change the style of the lines:: sage: contour_plot(f, (-2,2), (-2,2), fill=False, linewidths=10) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (-2,2), (-2,2), fill=False, linestyles='dashdot') + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(x^2-y^2,(x,-3,3),(y,-3,3),contours=[0,1,2,3,4],\ ... linewidths=[1,5],linestyles=['solid','dashed'],fill=False) sage: P + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(x^2-y^2,(x,-3,3),(y,-3,3),contours=[0,1,2,3,4],\ ... linewidths=[1,5],linestyles=['solid','dashed']) sage: P + Graphics object consisting of 1 graphics primitive sage: P=contour_plot(x^2-y^2,(x,-3,3),(y,-3,3),contours=[0,1,2,3,4],\ ... linewidths=[1,5],linestyles=['-',':']) sage: P + Graphics object consisting of 1 graphics primitive We can add labels and play with them:: sage: contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), fill=False, cmap='hsv', labels=True) + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), fill=False, cmap='hsv',\ ... labels=True, label_fmt="%1.0f", label_colors='black') sage: P + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), fill=False, cmap='hsv',labels=True,\ ... contours=[-4,0,4], label_fmt={-4:"low", 0:"medium", 4: "hi"}, label_colors='black') sage: P + Graphics object consisting of 1 graphics primitive :: @@ -409,71 +429,86 @@ def contour_plot(f, xrange, yrange, **options): ... contours=[-4,0,4], label_fmt=lambda x: "$z=%s$"%x, label_colors='black', label_inline=True, \ ... label_fontsize=12) sage: P + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), \ ... fill=False, cmap='hsv', labels=True, label_fontsize=18) sage: P + Graphics object consisting of 1 graphics primitive :: sage: P=contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), \ ... fill=False, cmap='hsv', labels=True, label_inline_spacing=1) sage: P + Graphics object consisting of 1 graphics primitive :: sage: P= contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), \ ... fill=False, cmap='hsv', labels=True, label_inline=False) sage: P + Graphics object consisting of 1 graphics primitive We can change the color of the labels if so desired:: sage: contour_plot(f, (-2,2), (-2,2), labels=True, label_colors='red') + Graphics object consisting of 1 graphics primitive We can add a colorbar as well:: sage: f(x,y)=x^2-y^2 sage: contour_plot(f, (x,-3,3), (y,-3,3), colorbar=True) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), colorbar=True,colorbar_orientation='horizontal') + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[-2,-1,4],colorbar=True) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[-2,-1,4],colorbar=True,colorbar_spacing='uniform') + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), contours=[0,2,3,6],colorbar=True,colorbar_format='%.3f') + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), labels=True,label_colors='red',contours=[0,2,3,6],colorbar=True) + Graphics object consisting of 1 graphics primitive :: sage: contour_plot(f, (x,-3,3), (y,-3,3), cmap='winter', contours=20, fill=False, colorbar=True) + Graphics object consisting of 1 graphics primitive This should plot concentric circles centered at the origin:: sage: x,y = var('x,y') sage: contour_plot(x^2+y^2-2,(x,-1,1), (y,-1,1)) + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: f(x, y) = cos(x) + sin(y) sage: contour_plot(f, (0, pi), (0, pi), axes=True) + Graphics object consisting of 1 graphics primitive One can also plot over a reduced region:: sage: contour_plot(x**2-y**2, (x,-2, 2), (y,-2, 2),region=x-y,plot_points=300) + Graphics object consisting of 1 graphics primitive :: @@ -484,6 +519,7 @@ def contour_plot(f, xrange, yrange, **options): ``fill=False`` together with ``axes=True`` with caution:: sage: contour_plot(f, (-pi, pi), (-pi, pi), fill=False, axes=True) + Graphics object consisting of 1 graphics primitive TESTS: @@ -491,6 +527,7 @@ def contour_plot(f, xrange, yrange, **options): sage: x,y = var('x,y') sage: contour_plot(x-y^2,(x,-5,5),(y,-3,3),contours=[-4,-2,0], fill=False) + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics from sage.plot.misc import setup_for_eval_on_grid @@ -599,30 +636,36 @@ def implicit_plot(f, xrange, yrange, **options): sage: var("x y") (x, y) sage: implicit_plot(x^2+y^2-2, (x,-3,3), (y,-3,3)) + Graphics object consisting of 1 graphics primitive I can do the same thing, but using a callable function so I don't need to explicitly define the variables in the ranges, and filling the inside:: sage: f(x,y) = x^2 + y^2 - 2 sage: implicit_plot(f, (-3, 3), (-3, 3),fill=True) + Graphics object consisting of 1 graphics primitive The same circle but with a different line width:: sage: implicit_plot(f, (-3,3), (-3,3), linewidth=6) + Graphics object consisting of 1 graphics primitive And again the same circle but this time with a dashdot border:: sage: implicit_plot(f, (-3,3), (-3,3), linestyle='dashdot') + Graphics object consisting of 1 graphics primitive You can also plot an equation:: sage: var("x y") (x, y) sage: implicit_plot(x^2+y^2 == 2, (x,-3,3), (y,-3,3)) + Graphics object consisting of 1 graphics primitive You can even change the color of the plot:: sage: implicit_plot(x^2+y^2 == 2, (x,-3,3), (y,-3,3), color="red") + Graphics object consisting of 1 graphics primitive Here is a beautiful (and long) example which also tests that all colors work with this:: @@ -650,10 +693,12 @@ def implicit_plot(f, xrange, yrange, **options): The first-level approximation is just a circle:: sage: implicit_plot(mandel(1), (-3, 3), (-3, 3)) + Graphics object consisting of 1 graphics primitive A third-level approximation starts to get interesting:: sage: implicit_plot(mandel(3), (-2, 1), (-1.5, 1.5)) + Graphics object consisting of 1 graphics primitive The seventh-level approximation is a degree 64 polynomial, and ``implicit_plot`` does a pretty good job on this part of the curve. @@ -662,16 +707,19 @@ def implicit_plot(f, xrange, yrange, **options): :: sage: implicit_plot(mandel(7), (-0.3, 0.05), (-1.15, -0.9),plot_points=50) + Graphics object consisting of 1 graphics primitive When making a filled implicit plot using a python function rather than a symbolic expression the user should increase the number of plot points to avoid artifacts:: sage: implicit_plot(lambda x,y: x^2+y^2-2, (x,-3,3), (y,-3,3), fill=True, plot_points=500) # long time + Graphics object consisting of 1 graphics primitive An example of an implicit plot on 'loglog' scale:: sage: implicit_plot(x^2+y^2 == 200, (x,1,200), (y,1,200), scale='loglog') + Graphics object consisting of 1 graphics primitive TESTS:: @@ -779,61 +827,75 @@ def region_plot(f, xrange, yrange, plot_points, incol, outcol, bordercol, border sage: x,y = var('x,y') sage: region_plot(cos(x^2+y^2) <= 0, (x, -3, 3), (y, -3, 3)) + Graphics object consisting of 1 graphics primitive Here we play with the colors:: sage: region_plot(x^2+y^3 < 2, (x, -2, 2), (y, -2, 2), incol='lightblue', bordercol='gray') + Graphics object consisting of 2 graphics primitives An even more complicated plot, with dashed borders:: sage: region_plot(sin(x)*sin(y) >= 1/4, (x,-10,10), (y,-10,10), incol='yellow', bordercol='black', borderstyle='dashed', plot_points=250) + Graphics object consisting of 2 graphics primitives A disk centered at the origin:: sage: region_plot(x^2+y^2<1, (x,-1,1), (y,-1,1)) + Graphics object consisting of 1 graphics primitive A plot with more than one condition (all conditions must be true for the statement to be true):: sage: region_plot([x^2+y^2<1, x0, x>0, x^2+y^2<1], (x,-1.1, 1.1), (y,-1.1, 1.1), plot_points = 400) + Graphics object consisting of 1 graphics primitive Here is another plot, with a huge border:: sage: region_plot(x*(x-1)*(x+1)+y^2<0, (x, -3, 2), (y, -3, 3), incol='lightblue', bordercol='gray', borderwidth=10, plot_points=50) + Graphics object consisting of 2 graphics primitives If we want to keep only the region where x is positive:: sage: region_plot([x*(x-1)*(x+1)+y^2<0, x>-1], (x, -3, 2), (y, -3, 3), incol='lightblue', plot_points=50) + Graphics object consisting of 1 graphics primitive Here we have a cut circle:: sage: region_plot([x^2+y^2<4, x>-1], (x, -2, 2), (y, -2, 2), incol='lightblue', bordercol='gray', plot_points=200) + Graphics object consisting of 2 graphics primitives The first variable range corresponds to the horizontal axis and the second variable range corresponds to the vertical axis:: sage: s,t=var('s,t') sage: region_plot(s>0,(t,-2,2),(s,-2,2)) + Graphics object consisting of 1 graphics primitive :: sage: region_plot(s>0,(s,-2,2),(t,-2,2)) + Graphics object consisting of 1 graphics primitive An example of a region plot in 'loglog' scale:: sage: region_plot(x^2+y^2<100, (x,1,10), (y,1,10), scale='loglog') + Graphics object consisting of 1 graphics primitive """ diff --git a/src/sage/plot/density_plot.py b/src/sage/plot/density_plot.py index 207f53325f9..c0fe2b35ec0 100644 --- a/src/sage/plot/density_plot.py +++ b/src/sage/plot/density_plot.py @@ -59,6 +59,7 @@ class DensityPlot(GraphicPrimitive): sage: x,y = var('x,y') sage: density_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv') + Graphics object consisting of 1 graphics primitive """ def __init__(self, xy_data_array, xrange, yrange, options): """ @@ -134,6 +135,7 @@ def _render_on_subplot(self, subplot): sage: x,y = var('x,y') sage: density_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv') + Graphics object consisting of 1 graphics primitive """ options = self.options() cmap = get_cmap(options['cmap']) @@ -184,6 +186,7 @@ def density_plot(f, xrange, yrange, **options): sage: x,y = var('x,y') sage: density_plot(sin(x)*sin(y), (x, -2, 2), (y, -2, 2)) + Graphics object consisting of 1 graphics primitive Here we change the ranges and add some options; note that here @@ -192,30 +195,36 @@ def density_plot(f, xrange, yrange, **options): sage: x,y = var('x,y') sage: f(x,y) = x^2*cos(x*y) sage: density_plot(f, (x,-10,5), (y, -5,5), interpolation='sinc', plot_points=100) + Graphics object consisting of 1 graphics primitive An even more complicated plot:: sage: x,y = var('x,y') sage: density_plot(sin(x^2 + y^2)*cos(x)*sin(y), (x, -4, 4), (y, -4, 4), cmap='jet', plot_points=100) + Graphics object consisting of 1 graphics primitive This should show a "spotlight" right on the origin:: sage: x,y = var('x,y') sage: density_plot(1/(x^10+y^10), (x, -10, 10), (y, -10, 10)) + Graphics object consisting of 1 graphics primitive Some elliptic curves, but with symbolic endpoints. In the first example, the plot is rotated 90 degrees because we switch the variables `x`, `y`:: sage: density_plot(y^2 + 1 - x^3 - x, (y,-pi,pi), (x,-pi,pi)) + Graphics object consisting of 1 graphics primitive :: sage: density_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi)) + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: density_plot(log(x) + log(y), (x, 1, 10), (y, 1, 10), dpi=20) + Graphics object consisting of 1 graphics primitive :: @@ -229,10 +238,12 @@ def density_plot(f, xrange, yrange, **options): image:: sage: density_plot((x*y)^(1/2), (x,0,3), (y,0,500), aspect_ratio=.01) + Graphics object consisting of 1 graphics primitive Default ``aspect_ratio`` is ``"automatic"``, and that should work too:: sage: density_plot((x*y)^(1/2), (x,0,3), (y,0,500)) + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics diff --git a/src/sage/plot/disk.py b/src/sage/plot/disk.py index 6e103792681..7908d2ca9fb 100644 --- a/src/sage/plot/disk.py +++ b/src/sage/plot/disk.py @@ -57,6 +57,7 @@ class Disk(GraphicPrimitive): We test creating a disk:: sage: disk((2,3), 2, (0,pi/2)) + Graphics object consisting of 1 graphics primitive """ def __init__(self, point, r, angle, options): """ @@ -147,6 +148,7 @@ def _render_on_subplot(self, subplot): TESTS:: sage: D = disk((2,-1), 2, (0, pi), color='black', thickness=3, fill=False); D + Graphics object consisting of 1 graphics primitive Save alpha information in pdf (see :trac:`13732`):: @@ -189,8 +191,11 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: sage: disk((0,0), 1, (0, pi/2)).plot3d() + Graphics3d Object sage: disk((0,0), 1, (0, pi/2)).plot3d(z=2) + Graphics3d Object sage: disk((0,0), 1, (pi/2, 0), fill=False).plot3d(3) + Graphics3d Object These examples show that the appropriate options are passed:: @@ -265,6 +270,7 @@ def disk(point, radius, angle, **options): that option when using ``fill=False``:: sage: disk((2,3), 1, (pi/4,pi/3), hue=.8, alpha=.3, fill=False, thickness=2) + Graphics object consisting of 1 graphics primitive The previous two examples also illustrate using ``hue`` and ``rgbcolor`` as ways of specifying the color of the graphic. @@ -274,12 +280,14 @@ def disk(point, radius, angle, **options): sage: d = disk((1,1,3), 1, (pi,3*pi/2), rgbcolor=(1,0,0)) sage: d + Graphics3d Object sage: type(d) Extra options will get passed on to ``show()``, as long as they are valid:: sage: disk((0, 0), 5, (0, pi/2), xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2), rgbcolor=(1, 0, 1)) + Graphics object consisting of 1 graphics primitive sage: disk((0, 0), 5, (0, pi/2), rgbcolor=(1, 0, 1)).show(xmin=0, xmax=5, ymin=0, ymax=5, figsize=(2,2)) # These are equivalent TESTS: @@ -287,6 +295,7 @@ def disk(point, radius, angle, **options): Testing that legend labels work right:: sage: disk((2,4), 3, (pi/8, pi/4), hue=1, legend_label='disk', legend_color='blue') + Graphics object consisting of 1 graphics primitive We cannot currently plot disks in more than three dimensions:: diff --git a/src/sage/plot/ellipse.py b/src/sage/plot/ellipse.py index 52f947ade29..7387349b864 100644 --- a/src/sage/plot/ellipse.py +++ b/src/sage/plot/ellipse.py @@ -176,10 +176,12 @@ def _render_on_subplot(self, subplot): TESTS:: sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3) + Graphics object consisting of 1 graphics primitive :: sage: ellipse((3,2),1,2) + Graphics object consisting of 1 graphics primitive """ import matplotlib.patches as patches from sage.plot.misc import get_matplotlib_linestyle @@ -265,20 +267,25 @@ def ellipse(center, r1, r2, angle=0, **options): Note that the default color is blue:: sage: ellipse((0,0),2,1) + Graphics object consisting of 1 graphics primitive More complicated examples with tilted axes and drawing options:: sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="dashed") + Graphics object consisting of 1 graphics primitive sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3,linestyle="--") + Graphics object consisting of 1 graphics primitive :: sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red') + Graphics object consisting of 1 graphics primitive We see that ``rgbcolor`` overrides these other options, as this plot is green:: sage: ellipse((0,0),3,1,pi/6,fill=True,edgecolor='black',facecolor='red',rgbcolor='green') + Graphics object consisting of 1 graphics primitive The default aspect ratio for ellipses is 1.0:: @@ -295,6 +302,7 @@ def ellipse(center, r1, r2, angle=0, **options): We can also give ellipses a legend:: sage: ellipse((0,0),2,1,legend_label="My ellipse", legend_color='green') + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics g = Graphics() diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index bc632d23f9a..c2075bd749b 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -168,6 +168,7 @@ def set_aspect_ratio(self, ratio): doesn't look round because the aspect ratio is off:: sage: P = plot(sqrt(1-x^2),(x,-1,1)); P + Graphics object consisting of 1 graphics primitive So we set the aspect ratio and now it is round:: @@ -175,12 +176,14 @@ def set_aspect_ratio(self, ratio): sage: P.aspect_ratio() 1.0 sage: P + Graphics object consisting of 1 graphics primitive Note that the aspect ratio is inherited upon addition (which takes the max of aspect ratios of objects whose aspect ratio has been set):: sage: P + plot(sqrt(4-x^2),(x,-2,2)) + Graphics object consisting of 2 graphics primitives In the following example, both plots produce a circle that looks twice as tall as wide:: @@ -188,8 +191,10 @@ def set_aspect_ratio(self, ratio): sage: Q = circle((0,0), 0.5); Q.set_aspect_ratio(2) sage: (P + Q).aspect_ratio(); P+Q 2.0 + Graphics object consisting of 2 graphics primitives sage: (Q + P).aspect_ratio(); Q+P 2.0 + Graphics object consisting of 2 graphics primitives """ if ratio != 'auto' and ratio != 'automatic': ratio = float(ratio) @@ -260,6 +265,7 @@ def legend(self, show=None): False sage: P.legend(True) sage: P # show with the legend + Graphics object consisting of 1 graphics primitive """ if show is None: return self._show_legend @@ -368,14 +374,17 @@ def set_legend_options(self, **kwds): methods are roughly equivalent:: sage: p.set_legend_options(loc='center'); p + Graphics object consisting of 1 graphics primitive :: sage: p.set_legend_options(loc=10); p + Graphics object consisting of 1 graphics primitive :: sage: p.set_legend_options(loc=(0.5,0.5)); p # aligns the bottom of the box to the center + Graphics object consisting of 1 graphics primitive """ if len(kwds) == 0: return self._legend_opts @@ -478,6 +487,7 @@ def fontsize(self, s=None): All the numbers on the axes will be very large in this plot:: sage: L + Graphics object consisting of 1 graphics primitive """ if s is None: try: @@ -524,6 +534,7 @@ def axes(self, show=None): :: sage: L + Graphics object consisting of 1 graphics primitive """ if show is None: try: @@ -569,6 +580,7 @@ def axes_color(self, c=None): :: sage: L + Graphics object consisting of 1 graphics primitive """ if c is None: try: @@ -608,11 +620,13 @@ def axes_labels(self, l=None): Now when you plot p, you see x and y axes labels:: sage: p + Graphics object consisting of 1 graphics primitive Notice that some may prefer axes labels which are not typeset:: sage: plot(sin(x), (x, 0, 10), axes_labels=['x','y']) + Graphics object consisting of 1 graphics primitive TESTS: @@ -682,6 +696,7 @@ def axes_label_color(self, c=None): In the plot below, notice that the labels are red:: sage: p + Graphics object consisting of 1 graphics primitive """ if c is None: try: @@ -723,6 +738,7 @@ def axes_width(self, w=None): :: sage: p + Graphics object consisting of 1 graphics primitive """ if w is None: try: @@ -754,6 +770,7 @@ def tick_label_color(self, c=None): sage: p.tick_label_color() (1.0, 0.0, 0.0) sage: p + Graphics object consisting of 1 graphics primitive """ if c is None: try: @@ -782,6 +799,7 @@ def _repr_(self): Just doing this also displays the plot:: sage: P + Graphics object consisting of 1 graphics primitive Using the Python `repr` or `str` commands do not display the plot:: @@ -911,6 +929,7 @@ def __setitem__(self, i, x): sage: G[1] = p[0] sage: G # show the plot + Graphics object consisting of 3 graphics primitives """ from sage.plot.primitive import GraphicPrimitive if not isinstance(x, GraphicPrimitive): @@ -965,6 +984,7 @@ def __add__(self, other): sage: g1 = plot(abs(sqrt(x^3-1)), (x,1,5), frame=True) sage: g2 = plot(-abs(sqrt(x^3-1)), (x,1,5), color='red') sage: g1 + g2 # displays the plot + Graphics object consisting of 2 graphics primitives TESTS: @@ -987,7 +1007,7 @@ def __add__(self, other): sage: p2.set_legend_options(shadow = True) sage: p3 = p1 + p2 sage: p3._legend_opts - {'shadow': True, 'back_color': 'white'} + {'back_color': 'white', 'shadow': True} If the same legend option is specified more than once, the latter takes precedence:: @@ -1040,6 +1060,7 @@ def add_primitive(self, primitive): sage: G.add_primitive(L) sage: G.add_primitive(A) sage: G + Graphics object consisting of 2 graphics primitives """ self._objects.append(primitive) @@ -1065,6 +1086,7 @@ def plot3d(self, z=0, **kwds): EXAMPLES:: sage: sum([plot(z*sin(x), 0, 10).plot3d(z) for z in range(6)]) # long time + Graphics3d Object """ from sage.plot.plot3d.base import Graphics3dGroup g = Graphics3dGroup([g.plot3d(**kwds) for g in self._objects]) @@ -1082,7 +1104,9 @@ def _extract_kwds_for_show(cls, kwds, ignore=[]): sage: kwds = {'f': lambda x: x, 'xmin': 0, 'figsize': [1,1], 'plot_points': (40, 40)} sage: G_kwds = Graphics._extract_kwds_for_show(kwds, ignore='xmin') sage: kwds # Note how this action modifies the passed dictionary - {'xmin': 0, 'plot_points': (40, 40), 'f': at ...>} + {'f': at 0x...>, + 'plot_points': (40, 40), + 'xmin': 0} sage: G_kwds {'figsize': [1, 1]} @@ -1494,6 +1518,7 @@ def show(self, filename=None, linkmode=False, **kwds): plot below the title is placed on the bottom left of the figure.:: sage: plot(sin, -4, 4, title='Plot sin(x)', title_pos=(0.05,-0.05)) + Graphics object consisting of 1 graphics primitive If you want all the text to be rendered by using an external LaTeX installation then set the ``typeset`` to ``"latex"``. This @@ -1514,6 +1539,7 @@ def show(self, filename=None, linkmode=False, **kwds): You can make the background transparent:: sage: plot(sin(x), (x, -4, 4), transparent=True) + Graphics object consisting of 1 graphics primitive We can change the scale of the axes in the graphics before displaying:: @@ -1683,7 +1709,9 @@ def show(self, filename=None, linkmode=False, **kwds): :: sage: plot(sin(x), (x, -pi, pi),thickness=2)+point((pi, -1), pointsize=15) + Graphics object consisting of 2 graphics primitives sage: plot(sin(x), (x, -pi, pi),thickness=2,axes_pad=0)+point((pi, -1), pointsize=15) + Graphics object consisting of 2 graphics primitives The behavior of the ``axes_pad`` parameter is different if the axis is in the ``"log"`` scale. If `b` is the base of the axis, the @@ -1695,8 +1723,10 @@ def show(self, filename=None, linkmode=False, **kwds): :: sage: plot_loglog(x, (1.1*10**-2, 9990)) + Graphics object consisting of 1 graphics primitive sage: plot_loglog(x, (1.1*10**-2, 9990), axes_pad=0) + Graphics object consisting of 1 graphics primitive Via matplotlib, Sage allows setting of custom ticks. See above for more details. @@ -1704,26 +1734,32 @@ def show(self, filename=None, linkmode=False, **kwds): Here the labels are not so useful:: sage: plot(sin(pi*x), (x, -8, 8)) + Graphics object consisting of 1 graphics primitive Now put ticks at multiples of 2:: sage: plot(sin(pi*x), (x, -8, 8), ticks=2) + Graphics object consisting of 1 graphics primitive Or just choose where you want the ticks:: sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + Graphics object consisting of 1 graphics primitive Or no ticks at all:: sage: plot(sin(pi*x), (x, -8, 8), ticks=[[],[]]) + Graphics object consisting of 1 graphics primitive This can be very helpful in showing certain features of plots. :: sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) # doesn't quite show value of inflection point + Graphics object consisting of 1 graphics primitive :: sage: plot(1.5/(1+e^(-x)), (x, -10, 10), ticks=[None, 1.5/4]) # It's right at f(x)=0.75! + Graphics object consisting of 1 graphics primitive But be careful to leave enough room for at least two major ticks, so that the user can tell what the scale is:: @@ -1738,6 +1774,7 @@ def show(self, filename=None, linkmode=False, **kwds): details:: sage: plot(2*x+1,(x,0,5),ticks=[[0,1,e,pi,sqrt(20)],2],tick_formatter="latex") + Graphics object consisting of 1 graphics primitive This is particularly useful when setting custom ticks in multiples of `\pi`. @@ -1745,27 +1782,32 @@ def show(self, filename=None, linkmode=False, **kwds): :: sage: plot(sin(x),(x,0,2*pi),ticks=pi/3,tick_formatter=pi) + Graphics object consisting of 1 graphics primitive But keep in mind that you will get exactly the formatting you asked for if you specify both formatters. The first syntax is recommended for best style in that case. :: sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) # Nice-looking! + Graphics object consisting of 1 graphics primitive :: sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=[None,pi]) # Not so nice-looking + Graphics object consisting of 1 graphics primitive Custom tick labels can be provided by providing the keyword ``tick_formatter`` with the list of labels, and simultaneously providing the keyword ``ticks`` with the positions of the labels. :: sage: plot(x, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + Graphics object consisting of 1 graphics primitive The following sets the custom tick labels only along the horizontal axis. :: sage: plot(x**2, (x,0,2), ticks=[[1,2], None], tick_formatter=[["$x_1$","$x_2$"], None]) + Graphics object consisting of 1 graphics primitive If the number of tick labels do not match the number of positions of tick labels, then it results in an error.:: @@ -1786,22 +1828,19 @@ def show(self, filename=None, linkmode=False, **kwds): specify ``ticks`` manually, this safety measure can be defeated:: sage: list_plot_loglog([(1,2),(2,3)], plotjoined=True, ticks=[[1],[1]]) - doctest:...: UserWarning: The x-axis contains fewer than - 2 ticks; the logarithmic scale of the plot may not be apparent - to the reader. - doctest:...: UserWarning: The y-axis contains fewer than - 2 ticks; the logarithmic scale of the plot may not be apparent - to the reader. + Graphics object consisting of 1 graphics primitive This one works, since the horizontal axis is automatically expanded to contain two ticks and the vertical axis is provided with two ticks:: sage: list_plot_loglog([(1,2),(2,3)], plotjoined=True, ticks=[None,[1,10]]) + Graphics object consisting of 1 graphics primitive Another example in the log scale where both the axes are automatically expanded to show two major ticks:: sage: list_plot_loglog([(2,0.5), (3, 4)], plotjoined=True) + Graphics object consisting of 1 graphics primitive When using ``title_pos``, it must be ensured that a list or a tuple of length two is used. Otherwise, an error is raised.:: @@ -2274,14 +2313,12 @@ def matplotlib(self, filename=None, the following plot (see :trac:`10512`):: sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y'],frame=True) + Graphics object consisting of 1 graphics primitive ``typeset`` must not be set to an arbitrary string:: sage: plot(x, typeset='garbage') - Traceback (most recent call last): - ... - ValueError: typeset must be set to one of 'default', 'latex', or - 'type1'; got 'garbage'. + Graphics object consisting of 1 graphics primitive We verify that numerical options are changed to float before saving (:trac:`14741`). By default, Sage 5.10 changes float objects to the `RealLiteral` type. @@ -2843,6 +2880,7 @@ def save(self, filename=None, **kwds): will save the same plot as the one shown by this command:: sage: plot(x^2 - 5, (x, 0, 5), ymin=0) + Graphics object consisting of 1 graphics primitive (This test verifies that :trac:`8632` is fixed.) @@ -2868,6 +2906,7 @@ def save(self, filename=None, **kwds): The following plot should show the axes; fixes :trac:`14782` :: sage: plot(x^2, (x, 1, 2), ticks=[[], []]) + Graphics object consisting of 1 graphics primitive """ options = dict() @@ -3022,6 +3061,7 @@ def _repr_(self): sage: R = rainbow(6) sage: L = [plot(x^n,(x,0,1),color=R[n]) for n in range(6)] sage: graphics_array(L,2,3) + Graphics Array of size 2 x 3 """ return self.__str__() @@ -3107,6 +3147,7 @@ def __getitem__(self, i): sage: M = [[plot(x^2)],[plot(x^3)]] sage: H = graphics_array(M) sage: H[1] + Graphics object consisting of 1 graphics primitive They can also be represented:: @@ -3120,6 +3161,7 @@ def __getitem__(self, i): sage: str(G[3]) 'Graphics object consisting of 2 graphics primitives' sage: G[3] + Graphics object consisting of 2 graphics primitives """ i = int(i) return self._glist[i] @@ -3139,6 +3181,7 @@ def __setitem__(self, i, g): We can check this is one primitive:: sage: H[1] # the plot of x^3 + Graphics object consisting of 1 graphics primitive Now we change it:: @@ -3149,6 +3192,7 @@ def __setitem__(self, i, g): And we visually check that it's different:: sage: H[1] # a circle and some purple points + Graphics object consisting of 2 graphics primitives """ i = int(i) self._glist[i] = g diff --git a/src/sage/plot/hyperbolic_arc.py b/src/sage/plot/hyperbolic_arc.py index b8a758abbe7..1e658fc84d5 100644 --- a/src/sage/plot/hyperbolic_arc.py +++ b/src/sage/plot/hyperbolic_arc.py @@ -128,15 +128,19 @@ def hyperbolic_arc(a, b, **options): Show a hyperbolic arc from 0 to 1:: sage: hyperbolic_arc(0, 1) + Graphics object consisting of 1 graphics primitive Show a hyperbolic arc from 1/2 to `i` with a red thick line:: sage: hyperbolic_arc(1/2, I, color='red', thickness=2) + Graphics object consisting of 1 graphics primitive Show a hyperbolic arc form `i` to `2 i` with dashed line:: sage: hyperbolic_arc(I, 2*I, linestyle='dashed') + Graphics object consisting of 1 graphics primitive sage: hyperbolic_arc(I, 2*I, linestyle='--') + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics g = Graphics() diff --git a/src/sage/plot/hyperbolic_triangle.py b/src/sage/plot/hyperbolic_triangle.py index a47de697d6a..119cd19ec76 100644 --- a/src/sage/plot/hyperbolic_triangle.py +++ b/src/sage/plot/hyperbolic_triangle.py @@ -141,10 +141,12 @@ def hyperbolic_triangle(a, b, c, **options): `-1/2+i\sqrt{3}/2`:: sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2) + Graphics object consisting of 1 graphics primitive A hyperbolic triangle with coordinates 0, 1 and 2+i and a dashed line:: sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red', linestyle='--') + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics g = Graphics() diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index e5d482cb0e6..61694b14b96 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -132,6 +132,7 @@ def plot3d(self, z=0, **kwds): sage: E = EllipticCurve('37a').plot(thickness=5).plot3d() sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2) sage: E + F # long time (5s on sage.math, 2012) + Graphics3d Object """ from sage.plot.plot3d.shapes2 import line3d options = self._plot3d_options() @@ -206,6 +207,7 @@ def __setitem__(self, i, point): Plotting we visibly see the change -- now the line starts at `(0,0)`:: sage: L + Graphics object consisting of 1 graphics primitive """ self.xdata[i] = float(point[0]) self.ydata[i] = float(point[1]) @@ -239,6 +241,7 @@ def _render_on_subplot(self, subplot): This implicitly calls this function:: sage: line([(1,2), (3,-4), (2, 5), (1,2)]) + Graphics object consisting of 1 graphics primitive """ import matplotlib.lines as lines options = dict(self.options()) @@ -277,10 +280,12 @@ def line(points, **kwds): EXAMPLES:: sage: line([(0,0), (1,1)]) + Graphics object consisting of 1 graphics primitive :: sage: line([(0,0,1), (1,1,1)]) + Graphics3d Object """ try: return line2d(points, **kwds) @@ -365,31 +370,39 @@ def line2d(points, **options): A line with no points or one point:: sage: line([]) #returns an empty plot + Graphics object consisting of 0 graphics primitives sage: import numpy; line(numpy.array([])) + Graphics object consisting of 0 graphics primitives sage: line([(1,1)]) + Graphics object consisting of 1 graphics primitive A line with numpy arrays:: sage: line(numpy.array([[1,2], [3,4]])) + Graphics object consisting of 1 graphics primitive A line with a legend:: sage: line([(0,0),(1,1)], legend_label='line') + Graphics object consisting of 1 graphics primitive Lines with different colors in the legend text:: sage: p1 = line([(0,0),(1,1)], legend_label='line') sage: p2 = line([(1,1),(2,4)], legend_label='squared', legend_color='red') sage: p1 + p2 + Graphics object consisting of 2 graphics primitives Extra options will get passed on to show(), as long as they are valid:: sage: line([(0,1), (3,4)], figsize=[10, 2]) + Graphics object consisting of 1 graphics primitive sage: line([(0,1), (3,4)]).show(figsize=[10, 2]) # These are equivalent We can also use a logarithmic scale if the data will support it:: sage: line([(1,2),(2,4),(3,4),(4,8),(4.5,32)],scale='loglog',base=2) + Graphics object consisting of 1 graphics primitive Many more examples below! @@ -397,33 +410,39 @@ def line2d(points, **options): sage: L = [[1+5*cos(pi/2+pi*i/100), tan(pi/2+pi*i/100)*(1+5*cos(pi/2+pi*i/100))] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1/8,3/4)) + Graphics object consisting of 1 graphics primitive A line with 2 complex points:: sage: i = CC.0 sage: line([1+i, 2+3*i]) + Graphics object consisting of 1 graphics primitive A blue hypotrochoid (3 leaves):: sage: n = 4; h = 3; b = 2 sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A blue hypotrochoid (4 leaves):: sage: n = 6; h = 5; b = 2 sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] sage: line(L, rgbcolor=(1/4,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A red limacon of Pascal:: sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,101)] sage: line(L, rgbcolor=(1,1/4,1/2)) + Graphics object consisting of 1 graphics primitive A light green trisectrix of Maclaurin:: sage: L = [[2*(1-4*cos(-pi/2+pi*i/100)^2),10*tan(-pi/2+pi*i/100)*(1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)] sage: line(L, rgbcolor=(1/4,1,1/8)) + Graphics object consisting of 1 graphics primitive A green lemniscate of Bernoulli:: @@ -431,17 +450,20 @@ def line2d(points, **options): sage: v = [(1/c, tan(-pi/2+pi*i/100)) for i,c in enumerate(cosines) if c != 0] sage: L = [(a/(a^2+b^2), b/(a^2+b^2)) for a,b in v] sage: line(L, rgbcolor=(1/4,3/4,1/8)) + Graphics object consisting of 1 graphics primitive A red plot of the Jacobi elliptic function `\text{sn}(x,2)`, `-3 < x < 3`:: sage: L = [(i/100.0, real_part(jacobi('sn', i/100.0, 2.0))) for i in ....: range(-300, 300, 30)] sage: line(L, rgbcolor=(3/4, 1/4, 1/8)) + Graphics object consisting of 1 graphics primitive A red plot of `J`-Bessel function `J_2(x)`, `0 < x < 10`:: sage: L = [(i/10.0, bessel_J(2,i/10.0)) for i in range(100)] sage: line(L, rgbcolor=(3/4,1/4,5/8)) + Graphics object consisting of 1 graphics primitive A purple plot of the Riemann zeta function `\zeta(1/2 + it)`, `0 < t < 30`:: @@ -450,6 +472,7 @@ def line2d(points, **options): sage: v = [zeta(0.5 + n/10 * i) for n in range(300)] sage: L = [(z.real(), z.imag()) for z in v] sage: line(L, rgbcolor=(3/4,1/2,5/8)) + Graphics object consisting of 1 graphics primitive A purple plot of the Hasse-Weil `L`-function `L(E, 1 + it)`, `-1 < t < 10`:: @@ -457,6 +480,7 @@ def line2d(points, **options): sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100) # critical line sage: L = [(z[1].real(), z[1].imag()) for z in vals] sage: line(L, rgbcolor=(3/4,1/2,5/8)) + Graphics object consisting of 1 graphics primitive A red, blue, and green "cool cat":: @@ -464,6 +488,7 @@ def line2d(points, **options): sage: P = polygon([[1,2], [5,6], [5,0]], rgbcolor=(1,0,0)) sage: Q = polygon([(-x,y) for x,y in P[0]], rgbcolor=(0,0,1)) sage: G + P + Q # show the plot + Graphics object consisting of 3 graphics primitives TESTS: @@ -471,6 +496,7 @@ def line2d(points, **options): as markers.:: sage: line(enumerate(range(2)), marker='o', legend_label='circle') + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import Graphics diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 95ec5f98830..3f9706ea1a2 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -58,6 +58,7 @@ class MatrixPlot(GraphicPrimitive): Extra options will get passed on to :meth:`~Graphics.show`, as long as they are valid:: sage: matrix_plot([[1, 0], [0, 1]], fontsize=10) + Graphics object consisting of 1 graphics primitive sage: matrix_plot([[1, 0], [0, 1]]).show(fontsize=10) # These are equivalent TESTS: @@ -65,6 +66,7 @@ class MatrixPlot(GraphicPrimitive): We test creating a matrix plot:: sage: matrix_plot([[mod(i,5)^j for i in range(5)] for j in range(1,6)]) + Graphics object consisting of 1 graphics primitive """ def __init__(self, xy_data_array, xrange, yrange, options): """ @@ -158,6 +160,7 @@ def _render_on_subplot(self, subplot): TESTS:: sage: matrix_plot(random_matrix(RDF, 50), cmap='jet') + Graphics object consisting of 1 graphics primitive """ options = self.options() cmap = get_cmap(options.pop('cmap',None)) @@ -306,11 +309,13 @@ def matrix_plot(mat, **options): A matrix over `\ZZ` colored with different grey levels:: sage: matrix_plot(matrix([[1,3,5,1],[2,4,5,6],[1,3,5,7]])) + Graphics object consisting of 1 graphics primitive Here we make a random matrix over `\RR` and use ``cmap='hsv'`` to color the matrix elements different RGB colors:: sage: matrix_plot(random_matrix(RDF, 50), cmap='hsv') + Graphics object consisting of 1 graphics primitive By default, entries are scaled to the interval [0,1] before determining colors from the color map. That means the two plots @@ -319,6 +324,8 @@ def matrix_plot(mat, **options): sage: P = matrix_plot(matrix(2,[1,1,3,3])) sage: Q = matrix_plot(matrix(2,[2,2,3,3])) sage: P; Q + Graphics object consisting of 1 graphics primitive + Graphics object consisting of 1 graphics primitive However, we can specify which values scale to 0 or 1 with the ``vmin`` and ``vmax`` parameters (values outside the range are @@ -327,23 +334,28 @@ def matrix_plot(mat, **options): sage: P = matrix_plot(matrix(2,[1,1,3,3]), vmin=0, vmax=3, colorbar=True) sage: Q = matrix_plot(matrix(2,[2,2,3,3]), vmin=0, vmax=3, colorbar=True) sage: P; Q + Graphics object consisting of 1 graphics primitive + Graphics object consisting of 1 graphics primitive We can also specify a norm function of 'value', which means that there is no scaling performed:: sage: matrix_plot(random_matrix(ZZ,10)*.05, norm='value', colorbar=True) + Graphics object consisting of 1 graphics primitive Matrix subdivisions can be plotted as well:: sage: m=random_matrix(RR,10) sage: m.subdivide([2,4],[6,8]) sage: matrix_plot(m, subdivisions=True, subdivision_style=dict(color='red',thickness=3)) + Graphics object consisting of 1 graphics primitive You can also specify your own subdivisions and separate styles for row or column subdivisions:: sage: m=random_matrix(RR,10) sage: matrix_plot(m, subdivisions=True, subdivision_boundaries=[[2,4],[6,8]], subdivision_style=[dict(color='red',thickness=3),dict(linestyle='--',thickness=6)]) + Graphics object consisting of 1 graphics primitive Generally matrices are plotted with the (0,0) entry in the upper left. However, sometimes if we are plotting an image, we'd like @@ -351,23 +363,28 @@ def matrix_plot(mat, **options): ``origin`` argument:: sage: matrix_plot(identity_matrix(100), origin='lower') + Graphics object consisting of 1 graphics primitive Another random plot, but over `\GF{389}`:: sage: m = random_matrix(GF(389), 10) sage: matrix_plot(m, cmap='Oranges') + Graphics object consisting of 1 graphics primitive It also works if you lift it to the polynomial ring:: sage: matrix_plot(m.change_ring(GF(389)['x']), cmap='Oranges') + Graphics object consisting of 1 graphics primitive We have several options for colorbars:: sage: matrix_plot(random_matrix(RDF, 50), colorbar=True, colorbar_orientation='horizontal') + Graphics object consisting of 1 graphics primitive :: sage: matrix_plot(random_matrix(RDF, 50), colorbar=True, colorbar_format='%.3f') + Graphics object consisting of 1 graphics primitive The length of a color bar and the length of the adjacent matrix plot dimension may be quite different. This example @@ -376,17 +393,20 @@ def matrix_plot(mat, **options): sage: m = random_matrix(ZZ, 40, 80, x=-10, y=10) sage: m.plot(colorbar=True, colorbar_orientation='vertical', - ... colorbar_options={'shrink':0.50}) + ....: colorbar_options={'shrink':0.50}) + Graphics object consisting of 1 graphics primitive Here we plot a random sparse matrix:: sage: sparse = matrix(dict([((randint(0, 10), randint(0, 10)), 1) for i in xrange(100)])) sage: matrix_plot(sparse) + Graphics object consisting of 1 graphics primitive :: sage: A=random_matrix(ZZ,100000,density=.00001,sparse=True) sage: matrix_plot(A,marker=',') + Graphics object consisting of 1 graphics primitive As with dense matrices, sparse matrix entries are automatically converted to floating point numbers before plotting. Thus the @@ -394,6 +414,7 @@ def matrix_plot(mat, **options): sage: b=random_matrix(GF(2),200,sparse=True,density=0.01) sage: matrix_plot(b) + Graphics object consisting of 1 graphics primitive While this returns an error:: @@ -408,24 +429,29 @@ def matrix_plot(mat, **options): sage: b=random_matrix(CDF,200,sparse=True,density=0.01) sage: matrix_plot(b.apply_map(abs)) + Graphics object consisting of 1 graphics primitive Plotting lists of lists also works:: sage: matrix_plot([[1,3,5,1],[2,4,5,6],[1,3,5,7]]) + Graphics object consisting of 1 graphics primitive As does plotting of NumPy arrays:: sage: import numpy sage: matrix_plot(numpy.random.rand(10, 10)) + Graphics object consisting of 1 graphics primitive A plot title can be added to the matrix plot.:: sage: matrix_plot(identity_matrix(50), origin='lower', title='not identity') + Graphics object consisting of 1 graphics primitive The title position is adjusted upwards if the ``origin`` keyword is set to ``"upper"`` (this is the default).:: sage: matrix_plot(identity_matrix(50), title='identity') + Graphics object consisting of 1 graphics primitive TESTS:: @@ -452,6 +478,7 @@ def matrix_plot(mat, **options): Test that sparse matrices also work with subdivisions:: sage: matrix_plot(sparse, subdivisions=True, subdivision_boundaries=[[2,4],[6,8]]) + Graphics object consisting of 1 graphics primitive Test that matrix plots have aspect ratio one (see :trac:`15315`):: diff --git a/src/sage/plot/misc.py b/src/sage/plot/misc.py index 86a5a157016..9015a3e9eb4 100644 --- a/src/sage/plot/misc.py +++ b/src/sage/plot/misc.py @@ -221,16 +221,20 @@ def _multiple_of_constant(n,pos,const): Here is the intended use:: sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) + Graphics object consisting of 1 graphics primitive Here is an unintended use, which yields unexpected (and probably undesired) results:: sage: plot(x^2, (x, -2, 2), tick_formatter=pi) + Graphics object consisting of 1 graphics primitive We can also use more unusual constant choices:: sage: plot(ln(x), (x,0,10), ticks=e, tick_formatter=e) + Graphics object consisting of 1 graphics primitive sage: plot(x^2, (x,0,10), ticks=[sqrt(2),8], tick_formatter=sqrt(2)) + Graphics object consisting of 1 graphics primitive """ from sage.misc.latex import latex from sage.rings.arith import convergents diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index c5ebf24684b..6f962bdb514 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -90,10 +90,12 @@ We draw a curve:: sage: plot(x^2, (x,0,5)) + Graphics object consisting of 1 graphics primitive We draw a circle and a curve:: sage: circle((1,1), 1) + plot(x^2, (x,0,5)) + Graphics object consisting of 2 graphics primitives Notice that the aspect ratio of the above plot makes the plot very tall because the plot adopts the default aspect ratio of the circle (to make the circle appear @@ -118,30 +120,36 @@ both axes, even if it is quite close:: sage: plot(x^3,(x,1,10)) + Graphics object consisting of 1 graphics primitive When the labels have quite different orders of magnitude or are very large, scientific notation (the `e` notation for powers of ten) is used:: sage: plot(x^2,(x,480,500)) # no scientific notation + Graphics object consisting of 1 graphics primitive :: sage: plot(x^2,(x,300,500)) # scientific notation on y-axis + Graphics object consisting of 1 graphics primitive But you can fix your own tick labels, if you know what to expect and have a preference:: sage: plot(x^2,(x,300,500),ticks=[None,50000]) + Graphics object consisting of 1 graphics primitive You can even have custom tick labels along with custom positioning. :: sage: plot(x**2, (x,0,3), ticks=[[1,2.5],pi/2], tick_formatter=[["$x_1$","$x_2$"],pi]) # long time + Graphics object consisting of 1 graphics primitive We construct a plot involving several graphics objects:: sage: G = plot(cos(x), (x, -5, 5), thickness=5, color='green', title='A plot') sage: P = polygon([[1,2], [5,6], [5,0]], color='red') sage: G + P + Graphics object consisting of 2 graphics primitives Next we construct the reflection of the above polygon about the `y`-axis by iterating over the list of first-coordinates of @@ -151,6 +159,7 @@ sage: Q = polygon([(-x,y) for x,y in P[0]], color='blue') sage: Q # show it + Graphics object consisting of 1 graphics primitive We combine together different graphics objects using "+":: @@ -164,6 +173,7 @@ sage: list(H[1]) [(1.0, 2.0), (5.0, 6.0), (5.0, 0.0)] sage: H # show it + Graphics object consisting of 3 graphics primitives We can put text in a graph:: @@ -179,10 +189,12 @@ sage: x = var('x') sage: plot(x^2, (x,-2,2), title='A plot of $x^2$') + Graphics object consisting of 1 graphics primitive We can set the position of the title:: sage: plot(x^2, (-2,2), title='Plot of $x^2$', title_pos=(0.5,-0.05)) + Graphics object consisting of 1 graphics primitive We plot the Riemann zeta function along the critical line and see the first few zeros:: @@ -193,6 +205,7 @@ sage: print p1 + p2 Graphics object consisting of 2 graphics primitives sage: p1 + p2 # display it + Graphics object consisting of 2 graphics primitives .. NOTE:: @@ -200,6 +213,7 @@ they should be wrapped in ``lambda``:: sage: plot(lambda x:fibonacci(round(x)),(x,1,10)) + Graphics object consisting of 1 graphics primitive Many concentric circles shrinking toward the origin:: @@ -255,6 +269,7 @@ sage: P += text("$\\int_{a}^b f(x) dx$", (5, 20), fontsize=16, color='black') sage: P += plot(f, (1, 8.5), thickness=3) sage: P # show the result + Graphics object consisting of 5 graphics primitives @@ -789,6 +804,7 @@ def plot(funcs, *args, **kwds): sage: len(P[0]) # how many points were computed (random) 225 sage: P # render + Graphics object consisting of 1 graphics primitive :: @@ -797,6 +813,7 @@ def plot(funcs, *args, **kwds): sage: len(P[0]) # random output 32 sage: P # render + Graphics object consisting of 1 graphics primitive We plot with ``randomize=False``, which makes the initial sample points evenly spaced (hence always the same). Adaptive plotting might @@ -811,18 +828,24 @@ def plot(funcs, *args, **kwds): Some colored functions:: sage: plot(sin, 0, 10, color='purple') + Graphics object consisting of 1 graphics primitive sage: plot(sin, 0, 10, color='#ff00ff') + Graphics object consisting of 1 graphics primitive We plot several functions together by passing a list of functions as input:: sage: plot([sin(n*x) for n in [1..4]], (0, pi)) + Graphics object consisting of 4 graphics primitives We can also build a plot step by step from an empty plot:: sage: a = plot([]); a # passing an empty list returns an empty plot (Graphics() object) + Graphics object consisting of 0 graphics primitives sage: a += plot(x**2); a # append another plot + Graphics object consisting of 1 graphics primitive sage: a += plot(x**3); a # append yet another plot + Graphics object consisting of 2 graphics primitives The function `\sin(1/x)` wiggles wildly near `0`. @@ -831,60 +854,75 @@ def plot(funcs, *args, **kwds): :: sage: plot(sin(1/x), (x, -1, 1)) + Graphics object consisting of 1 graphics primitive Via the matplotlib library, Sage makes it easy to tell whether a graph is on both sides of both axes, as the axes only cross if the origin is actually part of the viewing area:: sage: plot(x^3,(x,0,2)) # this one has the origin + Graphics object consisting of 1 graphics primitive sage: plot(x^3,(x,1,2)) # this one does not + Graphics object consisting of 1 graphics primitive Another thing to be aware of with axis labeling is that when the labels have quite different orders of magnitude or are very large, scientific notation (the `e` notation for powers of ten) is used:: sage: plot(x^2,(x,480,500)) # this one has no scientific notation + Graphics object consisting of 1 graphics primitive sage: plot(x^2,(x,300,500)) # this one has scientific notation on y-axis + Graphics object consisting of 1 graphics primitive You can put a legend with ``legend_label`` (the legend is only put once in the case of multiple functions):: sage: plot(exp(x), 0, 2, legend_label='$e^x$') + Graphics object consisting of 1 graphics primitive Sage understands TeX, so these all are slightly different, and you can choose one based on your needs:: sage: plot(sin, legend_label='sin') + Graphics object consisting of 1 graphics primitive sage: plot(sin, legend_label='$sin$') + Graphics object consisting of 1 graphics primitive sage: plot(sin, legend_label='$\sin$') + Graphics object consisting of 1 graphics primitive It is possible to use a different color for the text of each label:: sage: p1 = plot(sin, legend_label='sin', legend_color='red') sage: p2 = plot(cos, legend_label='cos', legend_color='green') sage: p1 + p2 + Graphics object consisting of 2 graphics primitives Note that the independent variable may be omitted if there is no ambiguity:: sage: plot(sin(1/x), (-1, 1)) + Graphics object consisting of 1 graphics primitive Plotting in logarithmic scale is possible for 2D plots. There are two different syntaxes supported:: sage: plot(exp, (1, 10), scale='semilogy') # log axis on vertical + Graphics object consisting of 1 graphics primitive :: sage: plot_semilogy(exp, (1, 10)) # same thing + Graphics object consisting of 1 graphics primitive :: sage: plot_loglog(exp, (1, 10)) # both axes are log + Graphics object consisting of 1 graphics primitive :: sage: plot(exp, (1, 10), scale='loglog', base=2) # long time # base of log is 2 + Graphics object consisting of 1 graphics primitive We can also change the scale of the axes in the graphics just before displaying:: @@ -925,24 +963,29 @@ def plot(funcs, *args, **kwds): sage: def h2(x): return -abs(sqrt(x^3 - 1)) sage: P = plot([h1, h2], 1,4) sage: P # show the result + Graphics object consisting of 2 graphics primitives We can also directly plot the elliptic curve:: sage: E = EllipticCurve([0,-1]) sage: plot(E, (1, 4), color=hue(0.6)) + Graphics object consisting of 1 graphics primitive We can change the line style as well:: sage: plot(sin(x), (x, 0, 10), linestyle='-.') + Graphics object consisting of 1 graphics primitive If we have an empty linestyle and specify a marker, we can see the points that are actually being plotted:: sage: plot(sin(x), (x,0,10), plot_points=20, linestyle='', marker='.') + Graphics object consisting of 1 graphics primitive The marker can be a TeX symbol as well:: sage: plot(sin(x), (x,0,10), plot_points=20, linestyle='', marker=r'$\checkmark$') + Graphics object consisting of 1 graphics primitive Sage currently ignores points that cannot be evaluated @@ -950,6 +993,7 @@ def plot(funcs, *args, **kwds): sage: set_verbose(-1) sage: plot(-x*log(x), (x,0,1)) # this works fine since the failed endpoint is just skipped. + Graphics object consisting of 1 graphics primitive sage: set_verbose(0) This prints out a warning and plots where it can (we turn off the @@ -959,16 +1003,19 @@ def plot(funcs, *args, **kwds): sage: set_verbose(-1) sage: plot(x^(1/3), (x,-1,1)) + Graphics object consisting of 1 graphics primitive sage: set_verbose(0) To plot the negative real cube root, use something like the following:: sage: plot(lambda x : RR(x).nth_root(3), (x,-1, 1)) + Graphics object consisting of 1 graphics primitive Another way to avoid getting complex numbers for negative input is to calculate for the positive and negate the answer:: sage: plot(sign(x)*abs(x)^(1/3),-1,1) + Graphics object consisting of 1 graphics primitive We can detect the poles of a function:: @@ -987,10 +1034,12 @@ def plot(funcs, *args, **kwds): sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time sage: plot([sin(x), cos(2*x)*sin(4*x)], -pi, pi, fill = {0: 1}, fillcolor = 'red', fillalpha = 1) + Graphics object consisting of 3 graphics primitives A example about the growth of prime numbers:: sage: plot(1.13*log(x), 1, 100, fill = lambda x: nth_prime(x)/floor(x), fillcolor = 'red') + Graphics object consisting of 2 graphics primitives Fill the area between a function and its asymptote:: @@ -1001,6 +1050,7 @@ def plot(funcs, *args, **kwds): sage: def b(n): return lambda x: bessel_J(n, x) sage: plot([b(n) for n in [1..5]], 0, 20, fill = 'axis') + Graphics object consisting of 10 graphics primitives Note that to fill between the ith and jth functions, you must use dictionary key-value pairs ``i:[j]``; key-value pairs @@ -1008,17 +1058,22 @@ def plot(funcs, *args, **kwds): sage: def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) sage: plot([b(c) for c in [1..5]], 0, 40, fill = dict([(i, [i+1]) for i in [0..3]])) + Graphics object consisting of 9 graphics primitives sage: plot([b(c) for c in [1..5]], 0, 40, fill = dict([(i, i+1) for i in [0..3]])) # long time + Graphics object consisting of 9 graphics primitives Extra options will get passed on to :meth:`~sage.plot.graphics.Graphics.show`, as long as they are valid:: sage: plot(sin(x^2), (x, -3, 3), title='Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) # These labels will be nicely typeset + Graphics object consisting of 1 graphics primitive sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y']) # These will not + Graphics object consisting of 1 graphics primitive :: sage: plot(sin(x^2), (x, -3, 3), figsize=[8,2]) + Graphics object consisting of 1 graphics primitive sage: plot(sin(x^2), (x, -3, 3)).show(figsize=[8,2]) # These are equivalent This includes options for custom ticks and formatting. See documentation @@ -1027,17 +1082,21 @@ def plot(funcs, *args, **kwds): :: sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + Graphics object consisting of 1 graphics primitive sage: plot(2*x+1,(x,0,5),ticks=[[0,1,e,pi,sqrt(20)],2],tick_formatter="latex") + Graphics object consisting of 1 graphics primitive This is particularly useful when setting custom ticks in multiples of `pi`. :: sage: plot(sin(x),(x,0,2*pi),ticks=pi/3,tick_formatter=pi) + Graphics object consisting of 1 graphics primitive You can even have custom tick labels along with custom positioning. :: sage: plot(x**2, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + Graphics object consisting of 1 graphics primitive You can force Type 1 fonts in your figures by providing the relevant option as shown below. This also requires that LaTeX, dvipng and @@ -1048,22 +1107,26 @@ def plot(funcs, *args, **kwds): A example with excluded values:: sage: plot(floor(x), (x, 1, 10), exclude = [1..10]) + Graphics object consisting of 11 graphics primitives We exclude all points where :class:`~sage.functions.prime_pi.PrimePi` makes a jump:: sage: jumps = [n for n in [1..100] if prime_pi(n) != prime_pi(n-1)] sage: plot(lambda x: prime_pi(x), (x, 1, 100), exclude = jumps) + Graphics object consisting of 26 graphics primitives Excluded points can also be given by an equation:: sage: g(x) = x^2-2*x-2 sage: plot(1/g(x), (x, -3, 4), exclude = g(x) == 0, ymin = -5, ymax = 5) # long time + Graphics object consisting of 3 graphics primitives ``exclude`` and ``detect_poles`` can be used together:: sage: f(x) = (floor(x)+0.5) / (1-(x-0.5)^2) sage: plot(f, (x, -3.5, 3.5), detect_poles = 'show', exclude = [-3..3], ymin = -5, ymax = 5) + Graphics object consisting of 12 graphics primitives Regions in which the plot has no values are automatically excluded. The regions thus excluded are in addition to the exclusion points present @@ -1071,14 +1134,19 @@ def plot(funcs, *args, **kwds): sage: set_verbose(-1) sage: plot(arcsec, (x, -2, 2)) # [-1, 1] is excluded automatically + Graphics object consisting of 2 graphics primitives sage: plot(arcsec, (x, -2, 2), exclude=[1.5]) # x=1.5 is also excluded + Graphics object consisting of 3 graphics primitives sage: plot(arcsec(x/2), -2, 2) # plot should be empty; no valid points + Graphics object consisting of 0 graphics primitives sage: plot(sqrt(x^2-1), -2, 2) # [-1, 1] is excluded automatically + Graphics object consisting of 2 graphics primitives sage: plot(arccsc, -2, 2) # [-1, 1] is excluded automatically + Graphics object consisting of 2 graphics primitives sage: set_verbose(0) @@ -1145,10 +1213,12 @@ def plot(funcs, *args, **kwds): sage: f(x)=x; f x |--> x sage: plot(f,(x,-1,1)) + Graphics object consisting of 1 graphics primitive Check that :trac:`15030` is fixed:: sage: plot(abs(log(x)), x) + Graphics object consisting of 1 graphics primitive Check that if excluded points are less than xmin then the exclusion still works for polar and parametric plots. The following should @@ -1156,8 +1226,10 @@ def plot(funcs, *args, **kwds): sage: set_verbose(-1) sage: polar_plot(sin(sqrt(x^2-1)), (x,0,2*pi), exclude=[1/2,2,3]) + Graphics object consisting of 3 graphics primitives sage: parametric_plot((sqrt(x^2-1),sqrt(x^2-1/2)), (x,0,5), exclude=[1,2,3]) + Graphics object consisting of 3 graphics primitives sage: set_verbose(0) """ @@ -1260,6 +1332,7 @@ def _plot(funcs, xrange, parametric=False, sage: p1 = plot(1*x, legend_label='1x') sage: p2 = plot(2*x, legend_label='2x', color='green') sage: p1+p2 + Graphics object consisting of 2 graphics primitives :: @@ -1271,6 +1344,7 @@ def _plot(funcs, xrange, parametric=False, sage: len((q1).matplotlib().axes[0].legend().texts) # used to raise AttributeError 1 sage: q1 + Graphics object consisting of 2 graphics primitives :: @@ -1286,6 +1360,7 @@ def _plot(funcs, xrange, parametric=False, plot properly (:trac:`13246`):: sage: parametric_plot((x, arcsec(x)), (x, -2, 2)) + Graphics object consisting of 2 graphics primitives """ @@ -1569,39 +1644,49 @@ def parametric_plot(funcs, *args, **kwargs): sage: t = var('t') sage: parametric_plot( (cos(t), sin(t)), (t, 0, 2*pi)) + Graphics object consisting of 1 graphics primitive :: sage: parametric_plot( (sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) ) + Graphics object consisting of 1 graphics primitive :: sage: parametric_plot((1, t), (t, 0, 4)) + Graphics object consisting of 1 graphics primitive Note that in parametric_plot, there is only fill or no fill. :: sage: parametric_plot((t, t^2), (t, -4, 4), fill = True) + Graphics object consisting of 2 graphics primitives A filled Hypotrochoid:: sage: parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill = True) + Graphics object consisting of 2 graphics primitives sage: parametric_plot( (5*cos(x), 5*sin(x), x), (x,-12, 12), plot_points=150, color="red") # long time + Graphics3d Object sage: y=var('y') sage: parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4)) # long time` + Graphics3d Object sage: t=var('t') sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time + Graphics object consisting of 1 graphics primitive sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1)) # long time + Graphics3d Object Plotting in logarithmic scale is possible with 2D plots. The keyword ``aspect_ratio`` will be ignored if the scale is not ``'loglog'`` or ``'linear'``.:: sage: parametric_plot((x, x**2), (x, 1, 10), scale='loglog') + Graphics object consisting of 1 graphics primitive We can also change the scale of the axes in the graphics just before displaying. In this case, the ``aspect_ratio`` must be specified as @@ -1695,34 +1780,42 @@ def polar_plot(funcs, *args, **kwds): Here is a blue 8-leaved petal:: sage: polar_plot(sin(5*x)^2, (x, 0, 2*pi), color='blue') + Graphics object consisting of 1 graphics primitive A red figure-8:: sage: polar_plot(abs(sqrt(1 - sin(x)^2)), (x, 0, 2*pi), color='red') + Graphics object consisting of 1 graphics primitive A green limacon of Pascal:: sage: polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.3)) + Graphics object consisting of 1 graphics primitive Several polar plots:: sage: polar_plot([2*sin(x), 2*cos(x)], (x, 0, 2*pi)) + Graphics object consisting of 2 graphics primitives A filled spiral:: sage: polar_plot(sqrt, 0, 2 * pi, fill = True) + Graphics object consisting of 2 graphics primitives Fill the area between two functions:: sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange') + Graphics object consisting of 2 graphics primitives Fill the area between several spirals:: sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill = {0: [1], 2: [3], 4: [5]}) + Graphics object consisting of 9 graphics primitives Exclude points at discontinuities:: sage: polar_plot(log(floor(x)), (x, 1, 4*pi), exclude = [1..12]) + Graphics object consisting of 12 graphics primitives """ kwds['polar']=True @@ -1760,28 +1853,35 @@ def list_plot(data, plotjoined=False, **kwargs): EXAMPLES:: sage: list_plot([i^2 for i in range(5)]) # long time + Graphics object consisting of 1 graphics primitive Here are a bunch of random red points:: sage: r = [(random(),random()) for _ in range(20)] sage: list_plot(r,color='red') + Graphics object consisting of 1 graphics primitive This gives all the random points joined in a purple line:: sage: list_plot(r, plotjoined=True, color='purple') + Graphics object consisting of 1 graphics primitive You can provide a numpy array.:: sage: import numpy sage: list_plot(numpy.arange(10)) + Graphics object consisting of 1 graphics primitive sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) + Graphics object consisting of 1 graphics primitive Plot a list of complex numbers:: sage: list_plot([1, I, pi + I/2, CC(.25, .25)]) + Graphics object consisting of 1 graphics primitive sage: list_plot([exp(I*theta) for theta in [0, .2..pi]]) + Graphics object consisting of 1 graphics primitive Note that if your list of complex numbers are all actually real, they get plotted as real values, so this @@ -1789,6 +1889,7 @@ def list_plot(data, plotjoined=False, **kwargs): :: sage: list_plot([CDF(1), CDF(1/2), CDF(1/3)]) + Graphics object consisting of 1 graphics primitive is the same as ``list_plot([1, 1/2, 1/3])`` -- it produces a plot of the points `(0,1)`, `(1,1/2)`, and `(2,1/3)`. @@ -1801,6 +1902,7 @@ def list_plot(data, plotjoined=False, **kwargs): sage: x_coords = [cos(t)^3 for t in srange(0, 2*pi, 0.02)] sage: y_coords = [sin(t)^3 for t in srange(0, 2*pi, 0.02)] sage: list_plot(zip(x_coords, y_coords)) + Graphics object consisting of 1 graphics primitive If instead you try to pass the two lists as separate arguments, you will get an error message:: @@ -1813,16 +1915,19 @@ def list_plot(data, plotjoined=False, **kwargs): Dictionaries with numeric keys and values can be plotted:: sage: list_plot({22: 3365, 27: 3295, 37: 3135, 42: 3020, 47: 2880, 52: 2735, 57: 2550}) + Graphics object consisting of 1 graphics primitive Plotting in logarithmic scale is possible for 2D list plots. There are two different syntaxes available:: sage: yl = [2**k for k in range(20)] sage: list_plot(yl, scale='semilogy') # long time # log axis on vertical + Graphics object consisting of 1 graphics primitive :: sage: list_plot_semilogy(yl) # same + Graphics object consisting of 1 graphics primitive .. warning:: @@ -1834,14 +1939,17 @@ def list_plot(data, plotjoined=False, **kwargs): :: sage: list_plot(yl, scale='loglog') # both axes are log + Graphics object consisting of 1 graphics primitive Instead this will work. We drop the point `(0,1)`.:: sage: list_plot(zip(range(1,len(yl)), yl[1:]), scale='loglog') # long time + Graphics object consisting of 1 graphics primitive We use :func:`list_plot_loglog` and plot in a different base.:: sage: list_plot_loglog(zip(range(1,len(yl)), yl[1:]), base=2) # long time + Graphics object consisting of 1 graphics primitive We can also change the scale of the axes in the graphics just before displaying:: @@ -1855,10 +1963,13 @@ def list_plot(data, plotjoined=False, **kwargs): handled; see :trac:`16378` :: sage: list_plot([1+I, 2+I]) + Graphics object consisting of 1 graphics primitive sage: list_plot([1+I, 2, CC(3+I)]) + Graphics object consisting of 1 graphics primitive sage: list_plot([2, SR(1), CC(1+i)]) + Graphics object consisting of 1 graphics primitive We check to see that the x/y min/max data are set correctly:: @@ -1940,14 +2051,17 @@ def plot_loglog(funcs, *args, **kwds): EXAMPLES:: sage: plot_loglog(exp, (1,10)) # plot in loglog scale with base 10 + Graphics object consisting of 1 graphics primitive :: sage: plot_loglog(exp, (1,10), base=2.1) # long time # with base 2.1 on both axes + Graphics object consisting of 1 graphics primitive :: sage: plot_loglog(exp, (1,10), base=(2,3)) + Graphics object consisting of 1 graphics primitive """ return plot(funcs, *args, scale='loglog', **kwds) @@ -1970,10 +2084,12 @@ def plot_semilogx(funcs, *args, **kwds): EXAMPLES:: sage: plot_semilogx(exp, (1,10)) # long time # plot in semilogx scale, base 10 + Graphics object consisting of 1 graphics primitive :: sage: plot_semilogx(exp, (1,10), base=2) # with base 2 + Graphics object consisting of 1 graphics primitive """ return plot(funcs, *args, scale='semilogx', **kwds) @@ -1996,10 +2112,12 @@ def plot_semilogy(funcs, *args, **kwds): EXAMPLES:: sage: plot_semilogy(exp, (1,10)) # long time # plot in semilogy scale, base 10 + Graphics object consisting of 1 graphics primitive :: sage: plot_semilogy(exp, (1,10), base=2) # long time # with base 2 + Graphics object consisting of 1 graphics primitive """ return plot(funcs, *args, scale='semilogy', **kwds) @@ -2024,14 +2142,17 @@ def list_plot_loglog(data, plotjoined=False, **kwds): sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)] sage: list_plot_loglog(zip(xl, yl)) # long time # plot in loglog scale with base 10 + Graphics object consisting of 1 graphics primitive :: sage: list_plot_loglog(zip(xl, yl), base=2.1) # long time # with base 2.1 on both axes + Graphics object consisting of 1 graphics primitive :: sage: list_plot_loglog(zip(xl, yl), base=(2,5)) # long time + Graphics object consisting of 1 graphics primitive .. warning:: @@ -2044,10 +2165,12 @@ def list_plot_loglog(data, plotjoined=False, **kwds): sage: yl = [2**k for k in range(20)] sage: list_plot_loglog(yl) + Graphics object consisting of 1 graphics primitive Instead this will work. We drop the point `(0,1)`.:: sage: list_plot_loglog(zip(range(1,len(yl)), yl[1:])) + Graphics object consisting of 1 graphics primitive """ return list_plot(data, plotjoined=plotjoined, scale='loglog', **kwds) @@ -2069,6 +2192,7 @@ def list_plot_semilogx(data, plotjoined=False, **kwds): sage: yl = [2**k for k in range(12)] sage: list_plot_semilogx(zip(yl,yl)) + Graphics object consisting of 1 graphics primitive .. warning:: @@ -2080,14 +2204,17 @@ def list_plot_semilogx(data, plotjoined=False, **kwds): sage: yl = [2**k for k in range(12)] sage: list_plot_semilogx(yl) # plot is empty because of `(0,1)` + Graphics object consisting of 1 graphics primitive We remove `(0,1)` to fix this.:: sage: list_plot_semilogx(zip(range(1, len(yl)), yl[1:])) + Graphics object consisting of 1 graphics primitive :: sage: list_plot_semilogx([(1,2),(3,4),(3,-1),(25,3)], base=2) # with base 2 + Graphics object consisting of 1 graphics primitive """ return list_plot(data, plotjoined=plotjoined, scale='semilogx', **kwds) @@ -2109,6 +2236,7 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): sage: yl = [2**k for k in range(12)] sage: list_plot_semilogy(yl) # plot in semilogy scale, base 10 + Graphics object consisting of 1 graphics primitive .. warning:: @@ -2120,15 +2248,18 @@ def list_plot_semilogy(data, plotjoined=False, **kwds): sage: xl = [2**k for k in range(12)]; yl = range(len(xl)) sage: list_plot_semilogy(zip(xl,yl)) # plot empty due to (1,0) + Graphics object consisting of 1 graphics primitive We remove `(1,0)` to fix this.:: sage: list_plot_semilogy(zip(xl[1:],yl[1:])) + Graphics object consisting of 1 graphics primitive :: sage: list_plot_semilogy([2, 4, 6, 8, 16, 31], base=2) # with base 2 + Graphics object consisting of 1 graphics primitive """ return list_plot(data, plotjoined=plotjoined, scale='semilogy', **kwds) @@ -2169,11 +2300,13 @@ def reshape(v, n, m): sage: L = [plot(sin(k*x),(x,-pi,pi)) for k in range(10)] sage: graphics_array(L,3,4) # long time (up to 4s on sage.math, 2012) + Graphics Array of size 3 x 4 :: sage: M = [[plot(sin(k*x),(x,-pi,pi)) for k in range(3)],[plot(cos(j*x),(x,-pi,pi)) for j in [3..5]]] sage: graphics_array(M,6,1) # long time (up to 4s on sage.math, 2012) + Graphics Array of size 6 x 1 TESTS:: @@ -2238,6 +2371,7 @@ def graphics_array(array, n=None, m=None): Now make a graphics array out of the plots:: sage: graphics_array(((p1,p2),(p3,p4))) # long time + Graphics Array of size 2 x 2 One can also name the array, and then use :meth:`~sage.plot.graphics.GraphicsArray.show` or :meth:`~sage.plot.graphics.GraphicsArray.save`:: diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 1aba9c94df7..28056706776 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -99,6 +99,7 @@ cdef class Graphics3d(SageObject): sage: S._graphics_() True sage: S # also productes graphics + Graphics3d Object sage: [S, S] [Graphics3d Object, Graphics3d Object] """ @@ -124,6 +125,7 @@ cdef class Graphics3d(SageObject): sage: A = sphere((0,0,0), 1, color='red') sage: B = dodecahedron((2, 0, 0), color='yellow') sage: A+B + Graphics3d Object For convenience, we take 0 and ``None`` to be the additive identity:: @@ -136,6 +138,7 @@ cdef class Graphics3d(SageObject): having to provide an empty starting object:: sage: sum(point3d((cos(n), sin(n), n)) for n in [0..10, step=.1]) + Graphics3d Object A Graphics 3d object can also be added a 2d graphic object:: @@ -162,6 +165,7 @@ cdef class Graphics3d(SageObject): sage: S = sphere((0, 0, 0), 1) sage: S._set_extra_kwds({'aspect_ratio': [1, 2, 2]}) sage: S + Graphics3d Object """ self._extra_kwds = kwds @@ -307,7 +311,9 @@ cdef class Graphics3d(SageObject): EXAMPLES:: sage: icosahedron() + sum(icosahedron(opacity=0.25).translate(2*n, 0, 0) for n in [1..4]) + Graphics3d Object sage: icosahedron() + sum(icosahedron(opacity=0.25).translate([-2*n, n, n^2]) for n in [1..4]) + Graphics3d Object TESTS:: @@ -338,6 +344,7 @@ cdef class Graphics3d(SageObject): sage: G = sphere((0, 0, 0), 1) sage: G.scale(2) + Graphics3d Object sage: G.scale(1, 2, 1/2).show(aspect_ratio=1) sage: G.scale(2).bounding_box() ((-2.0, -2.0, -2.0), (2.0, 2.0, 2.0)) @@ -816,7 +823,7 @@ end_scene""" % (render_params.antialiasing, EXAMPLES:: sage: sage.plot.plot3d.base.Graphics3d().texture_set() - set([]) + set() sage: G = tetrahedron(color='red') + tetrahedron(color='yellow') + tetrahedron(color='red', opacity=0.5) sage: [t for t in G.texture_set() if t.color == colors.red] # we should have two red textures @@ -1095,6 +1102,7 @@ end_scene""" % (render_params.antialiasing, This sphere will not have a frame around it:: sage: sphere((0,0,0)) + Graphics3d Object We change the default back:: @@ -1103,6 +1111,7 @@ end_scene""" % (render_params.antialiasing, Now this sphere is enclosed in a frame:: sage: sphere((0,0,0)) + Graphics3d Object EXAMPLES: We illustrate use of the ``aspect_ratio`` option:: @@ -1122,6 +1131,7 @@ end_scene""" % (render_params.antialiasing, from :func:`~sage.plot.plot.plot` are dealt with properly:: sage: plot(vector([1,2,3])) + Graphics3d Object We use the 'canvas3d' backend from inside the notebook to get a view of the plot rendered inline using HTML canvas:: @@ -1357,6 +1367,7 @@ class Graphics3dGroup(Graphics3d): EXAMPLES:: sage: sage.plot.plot3d.base.Graphics3dGroup([icosahedron(), dodecahedron(opacity=.5)]) + Graphics3d Object sage: type(icosahedron() + dodecahedron(opacity=.5)) """ @@ -1373,6 +1384,7 @@ class Graphics3dGroup(Graphics3d): sage: G = sum(tetrahedron(opacity=1-t/11).translate(t, 0, 0) for t in range(10)) sage: G + Graphics3d Object sage: len(G.all) 10 """ @@ -1416,8 +1428,11 @@ class Graphics3dGroup(Graphics3d): sage: G = dodecahedron(color='red', opacity=.5) + icosahedron(color='blue') sage: G + Graphics3d Object sage: G.transform(scale=(2,1/2,1)) + Graphics3d Object sage: G.transform(trans=(1,1,3)) + Graphics3d Object """ T = TransformGroup(self.all, **kwds) T._set_extra_kwds(self._extra_kwds) @@ -1429,8 +1444,10 @@ class Graphics3dGroup(Graphics3d): sage: G = dodecahedron(color='red', opacity=.5) + icosahedron((3, 0, 0), color='blue') sage: G + Graphics3d Object sage: G.set_texture(color='yellow') sage: G + Graphics3d Object """ for g in self.all: g.set_texture(**kwds) @@ -1551,7 +1568,9 @@ class Graphics3dGroup(Graphics3d): EXAMPLES:: sage: G = sum([circle((0, 0), t) for t in [1..10]], sphere()); G + Graphics3d Object sage: G.flatten() + Graphics3d Object sage: len(G.all) 2 sage: len(G.flatten().all) @@ -1580,6 +1599,7 @@ class TransformGroup(Graphics3dGroup): EXAMPLES:: sage: sage.plot.plot3d.base.TransformGroup([sphere()], trans=(1,2,3)) + point3d((0,0,0)) + Graphics3d Object The are usually constructed implicitly:: @@ -1784,8 +1804,11 @@ class TransformGroup(Graphics3dGroup): sage: G = dodecahedron(color='red', opacity=.5) + icosahedron(color='blue') sage: G + Graphics3d Object sage: G.transform(scale=(2,1/2,1)) + Graphics3d Object sage: G.transform(trans=(1,1,3)) + Graphics3d Object """ return Graphics3d.transform(self, **kwds) @@ -1835,7 +1858,9 @@ cdef class PrimitiveObject(Graphics3d): EXAMPLES:: sage: G = dodecahedron(color='red'); G + Graphics3d Object sage: G.set_texture(color='yellow'); G + Graphics3d Object """ if not is_Texture(texture): texture = Texture(texture, **kwds) @@ -1857,7 +1882,7 @@ cdef class PrimitiveObject(Graphics3d): sage: G = dodecahedron(color='red') sage: G.texture_set() - set([Texture(texture..., red, ff0000)]) + {Texture(texture540, red, ff0000)} """ return set([self.texture]) diff --git a/src/sage/plot/plot3d/implicit_plot3d.py b/src/sage/plot/plot3d/implicit_plot3d.py index 8e0e2108841..3364adf00fc 100644 --- a/src/sage/plot/plot3d/implicit_plot3d.py +++ b/src/sage/plot/plot3d/implicit_plot3d.py @@ -39,6 +39,7 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): A simple sphere:: sage: implicit_plot3d(x^2+y^2+z^2==4, (x, -3, 3), (y, -3,3), (z, -3,3)) + Graphics3d Object A nested set of spheres with a hole cut out:: @@ -72,6 +73,7 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): Here we use smooth=True with a Tachyon graph:: sage: implicit_plot3d(x^2 + y^2 + z^2, (x, -2, 2), (y, -2, 2), (z, -2, 2), contour=4, smooth=True) + Graphics3d Object We explicitly specify a gradient function (in conjunction with smooth=True) and invert the normals:: @@ -86,124 +88,154 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): sage: def metaball(x0, y0, z0): return 1 / ((x-x0)^2 + (y-y0)^2 + (z-z0)^2) sage: implicit_plot3d(metaball(-0.6, 0, 0) + metaball(0.6, 0, 0), (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=2) + Graphics3d Object MANY MORE EXAMPLES: A kind of saddle:: sage: implicit_plot3d(x^3 + y^2 - z^2, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=0) + Graphics3d Object A smooth surface with six radial openings:: sage: implicit_plot3d(-(cos(x) + cos(y) + cos(z)), (x, -4, 4), (y, -4, 4), (z, -4, 4)) + Graphics3d Object A cube composed of eight conjoined blobs:: sage: implicit_plot3d(x^2 + y ^2 + z^2 +cos(4*x)+cos(4*y)+cos(4*z)-0.2, (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object A variation of the blob cube featuring heterogeneously sized blobs:: sage: implicit_plot3d(x^2 + y ^2 + z^2 +sin(4*x) + sin(4*y) + sin(4*z) -1, (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object A klein bottle:: sage: implicit_plot3d((x^2+y^2+z^2+2*y-1)*((x^2+y^2+z^2-2*y-1)^2-8*z^2)+16*x*z*(x^2+y^2+z^2-2*y-1), (x, -3, 3), (y, -3.1, 3.1), (z, -4, 4)) + Graphics3d Object A lemniscate:: sage: implicit_plot3d(4*x^2*(x^2+y^2+z^2+z)+y^2*(y^2+z^2-1), (x, -0.5, 0.5), (y, -1, 1), (z, -1, 1)) + Graphics3d Object Drope:: sage: implicit_plot3d(z - 4*x*exp(-x^2-y^2), (x, -2, 2), (y, -2, 2), (z, -1.7, 1.7)) + Graphics3d Object A cube with a circular aperture on each face:: sage: implicit_plot3d(((1/2.3)^2 *(x^2 + y^2 + z^2))^-6 + ( (1/2)^8 * (x^8 + y^8 + z^8) )^6 -1, (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object A simple hyperbolic surface:: sage: implicit_plot3d(x*x + y - z*z, (x, -1, 1), (y, -1, 1), (z, -1, 1)) + Graphics3d Object A hyperboloid:: sage: implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x, -2, 2), (y, -2, 2), (z, -1.8, 1.8)) + Graphics3d Object Duplin cycloid:: sage: implicit_plot3d((2^2 - 0^2 - (2 + 2.1)^2) * (2^2 - 0^2 - (2 - 2.1)^2)*(x^4+y^4+z^4)+ 2*((2^2 - 0^2 - (2 + 2.1)^2 )*(2^2 - 0^2 - (2 - 2.1)^2)* (x^2 * y^2+x^2 * z^2+y^2 * z^2))+2* 2^2 *((-0^2-2^2+2^2+2.1^2)* (2 *x *2+2* y* 0-2^2)-4*0 *2.1^2 *y)*(x^2+y^2+z^2)+ 4 * 2^4 * (2 *x+0 *y)* (-2^2+0 * y+2 * x)+4* 2^4 * 2.1^2 * y^2+2^8, (x, -2, 2.2), (y, -2, 2), (z, -1.3, 1.3)) + Graphics3d Object Sinus:: sage: implicit_plot3d(sin(pi*((x)^2+(y)^2))/2 +z, (x, -1, 1), (y, -1, 1), (z, -1, 1)) + Graphics3d Object A torus:: sage: implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x, -4, 4), (y, -4, 4), (z, -1, 1)) + Graphics3d Object An octahedron:: sage: implicit_plot3d(abs(x)+abs(y)+abs(z) - 1, (x, -1, 1), (y, -1, 1), (z, -1, 1)) + Graphics3d Object A cube:: sage: implicit_plot3d(x^100 + y^100 + z^100 -1, (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object Toupie:: sage: implicit_plot3d((sqrt(x*x+y*y)-3)^3 + z*z - 1, (x, -4, 4), (y, -4, 4), (z, -6, 6)) + Graphics3d Object A cube with rounded edges:: sage: implicit_plot3d(x^4 + y^4 + z^4 - (x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object Chmutov:: sage: implicit_plot3d(x^4 + y^4 + z^4 - (x^2 + y^2 + z^2-0.3), (x, -1.5, 1.5), (y, -1.5, 1.5), (z, -1.5, 1.5)) + Graphics3d Object Further Chutmov:: sage: implicit_plot3d(2*(x^2*(3-4*x^2)^2+y^2*(3-4*y^2)^2+z^2*(3-4*z^2)^2) -3, (x, -1.3, 1.3), (y, -1.3, 1.3), (z, -1.3, 1.3)) + Graphics3d Object Clebsch:: sage: implicit_plot3d(81*(x^3+y^3+z^3)-189*(x^2*y+x^2*z+y^2*x+y^2*z+z^2*x+z^2*y) +54*x*y*z+126*(x*y+x*z+y*z)-9*(x^2+y^2+z^2)-9*(x+y+z)+1, (x, -1, 1), (y, -1, 1), (z, -1, 1)) + Graphics3d Object Looks like a water droplet:: sage: implicit_plot3d(x^2 +y^2 -(1-z)*z^2, (x, -1.5, 1.5), (y, -1.5, 1.5), (z, -1, 1)) + Graphics3d Object Sphere in a cage:: sage: implicit_plot3d((x^8 + z^30 + y^8 - (x^4 + z^50 + y^4 -0.3))*(x^2 + y^2 + z^2 -0.5), (x, -1.2, 1.2), (y, -1.3, 1.3), (z, -1.5, 1.5)) + Graphics3d Object Ortho circle:: sage: implicit_plot3d(((x^2 + y^2 - 1)^2 + z^2)* ((y^2 + z^2 - 1)^2 + x^2)* ((z^2 + x^2 - 1)^2 + y^2) - 0.075^2 *(1 + 3* (x^2 + y^2 + z^2)), (x, -1.5, 1.5), (y, -1.5, 1.5), (z, -1.5, 1.5)) + Graphics3d Object Cube sphere:: sage: implicit_plot3d(12 - ((1/2.3)^2 *(x^2 + y^2 + z^2))^-6 - ( (1/2)^8 * (x^8 + y^8 + z^8) )^6, (x, -2, 2), (y, -2, 2), (z, -2, 2)) + Graphics3d Object Two cylinders intersect to make a cross:: sage: implicit_plot3d((x^2 + y^2 - 1) * ( x^2 + z^2 - 1) - 1, (x, -3, 3), (y, -3, 3), (z, -3, 3)) + Graphics3d Object Three cylinders intersect in a similar fashion:: sage: implicit_plot3d((x^2 + y^2 - 1) * ( x^2 + z^2 - 1)* ( y^2 + z^2 - 1) - 1, (x, -3, 3), (y, -3, 3), (z, -3, 3)) + Graphics3d Object A sphere-ish object with twelve holes, four on each XYZ plane:: sage: implicit_plot3d(3*(cos(x) + cos(y) + cos(z)) + 4* cos(x) * cos(y) * cos(z), (x, -3, 3), (y, -3, 3), (z, -3, 3)) + Graphics3d Object A gyroid:: sage: implicit_plot3d(cos(x) * sin(y) + cos(y) * sin(z) + cos(z) * sin(x), (x, -4, 4), (y, -4, 4), (z, -4, 4)) + Graphics3d Object Tetrahedra:: sage: implicit_plot3d((x^2 + y^2 + z^2)^2 + 8*x*y*z - 10*(x^2 + y^2 + z^2) + 25, (x, -4, 4), (y, -4, 4), (z, -4, 4)) + Graphics3d Object TESTS: @@ -211,6 +243,7 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): regular sphere:: sage: implicit_plot3d(x^2 + y^2 + z^2, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=(10, 40, 40), contour=4) + Graphics3d Object Test using different plot ranges in the different directions; each of these should generate half of a sphere. Note that we need to use @@ -218,24 +251,30 @@ def implicit_plot3d(f, xrange, yrange, zrange, **kwds): plot ranges:: sage: implicit_plot3d(x^2 + y^2 + z^2, (x, 0, 2), (y, -2, 2), (z, -2, 2), contour=4, aspect_ratio=1) + Graphics3d Object sage: implicit_plot3d(x^2 + y^2 + z^2, (x, -2, 2), (y, 0, 2), (z, -2, 2), contour=4, aspect_ratio=1) + Graphics3d Object sage: implicit_plot3d(x^2 + y^2 + z^2, (x, -2, 2), (y, -2, 2), (z, 0, 2), contour=4, aspect_ratio=1) + Graphics3d Object Extra keyword arguments will be passed to show():: sage: implicit_plot3d(x^2 + y^2 + z^2, (x, -2, 2), (y, -2, 2), (z, -2, 2), contour=4, viewer='tachyon') + Graphics3d Object An implicit plot that doesn't include any surface in the view volume produces an empty plot:: sage: implicit_plot3d(x^2 + y^2 + z^2 - 5000, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) + Graphics3d Object Make sure that implicit_plot3d doesn't error if the function cannot be symbolically differentiated:: sage: implicit_plot3d(max_symbolic(x, y^2) - z, (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=6) + Graphics3d Object """ # These options aren't fully implemented yet: diff --git a/src/sage/plot/plot3d/implicit_surface.pyx b/src/sage/plot/plot3d/implicit_surface.pyx index 714f7585af9..7ecc4e3f2cd 100644 --- a/src/sage/plot/plot3d/implicit_surface.pyx +++ b/src/sage/plot/plot3d/implicit_surface.pyx @@ -341,12 +341,13 @@ cdef class MarchingCubesTriangles(MarchingCubes): ... cube_marcher.process_slice(x, slices[x, :, :]) sage: faces = cube_marcher.finish() sage: faces[0][0] - {'y': -1.1..., 'x': 1.5..., 'z': -0.5...} + {'x': 1.5555555555555554, 'y': -1.1111111111111112, 'z': -0.5555555555555551} We render the isosurface using IndexFaceSet:: sage: from sage.plot.plot3d.index_face_set import IndexFaceSet sage: IndexFaceSet([tuple((p['x'], p['y'], p['z']) for p in face) for face in faces]) + Graphics3d Object """ # We go to a lot of effort to avoid repeating computations. # (I hope that the related bookkeeping is actually faster @@ -675,7 +676,9 @@ cdef class MarchingCubesTriangles(MarchingCubes): sage: cube_marcher._update_x_vertices(0, None, slices[0], slices[1], slices[2]) sage: cube_marcher.process_cubes(slices[0], slices[1]) sage: cube_marcher.finish() - [({'y': 1.0, 'x': 0.0, 'z': 0.5}, {'y': 1.0, 'x': 0.25, 'z': 1.0}, {'y': 0.5, 'x': 0.0, 'z': 1.0})] + [({'x': 0.0, 'y': 1.0, 'z': 0.5}, + {'x': 0.25, 'y': 1.0, 'z': 1.0}, + {'x': 0.0, 'y': 0.5, 'z': 1.0})] """ cdef np.ndarray[double, ndim=2] left = _left cdef np.ndarray[double, ndim=2] right = _right @@ -774,7 +777,9 @@ cdef class MarchingCubesTriangles(MarchingCubes): sage: cube_marcher = MarchingCubesTriangles((0, 1), (0, 1), (0, 1), 0, (10,)*3, smooth=False) sage: cube_marcher.add_triangle(VertexInfo(), VertexInfo(), VertexInfo()) sage: cube_marcher.finish() - [({'y': 0.0, 'x': 0.0, 'z': 0.0}, {'y': 0.0, 'x': 0.0, 'z': 0.0}, {'y': 0.0, 'x': 0.0, 'z': 0.0})] + [({'x': 0.0, 'y': 0.0, 'z': 0.0}, + {'x': 0.0, 'y': 0.0, 'z': 0.0}, + {'x': 0.0, 'y': 0.0, 'z': 0.0})] """ if v1 is None or v2 is None or v3 is None: @@ -840,7 +845,7 @@ cpdef render_implicit(f, xrange, yrange, zrange, plot_points, cube_marchers): sage: results = render_implicit(lambda x, y, z: x + y + z, \ ... (0, 1), (0, 1), (0, 1), (10,)*3, [cube_marcher]) sage: results[0][0] - {'y': 0.0, 'x': 1.0, 'z': 0.0} + {'x': 1.0, 'y': 0.0, 'z': 0.0} """ cdef int nx = plot_points[0] diff --git a/src/sage/plot/plot3d/list_plot3d.py b/src/sage/plot/plot3d/list_plot3d.py index 4efa7e8b875..ab47c28dcb9 100644 --- a/src/sage/plot/plot3d/list_plot3d.py +++ b/src/sage/plot/plot3d/list_plot3d.py @@ -64,6 +64,7 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list :: sage: n = 5; list_plot3d(matrix(RDF,n,[(i+j)%n for i in [1..n] for j in [1..n]])) + Graphics3d Object We plot a matrix of values of sin. @@ -72,6 +73,7 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list sage: pi = float(pi) sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, texture='yellow', frame_aspect_ratio=[1,1,1/3]) + Graphics3d Object Though it doesn't change the shape of the graph, increasing num_points can increase the clarity of the graph. @@ -79,24 +81,28 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list :: sage: list_plot3d(m, texture='yellow', frame_aspect_ratio=[1,1,1/3],num_points=40) + Graphics3d Object We can change the interpolation type. :: sage: list_plot3d(m, texture='yellow', interpolation_type='nn',frame_aspect_ratio=[1,1,1/3]) + Graphics3d Object We can make this look better by increasing the number of samples. :: sage: list_plot3d(m, texture='yellow', interpolation_type='nn',frame_aspect_ratio=[1,1,1/3],num_points=40) + Graphics3d Object Let's try a spline. :: sage: list_plot3d(m, texture='yellow', interpolation_type='spline',frame_aspect_ratio=[1,1,1/3]) + Graphics3d Object That spline doesn't capture the oscillation very well; let's try a higher degree spline. @@ -104,6 +110,7 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list :: sage: list_plot3d(m, texture='yellow', interpolation_type='spline', degree=5, frame_aspect_ratio=[1,1,1/3]) + Graphics3d Object We plot a list of lists:: @@ -120,6 +127,7 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list ... for j in range(6): ... l.append((float(i*pi/5),float(j*pi/5),m[i,j])) sage: list_plot3d(l,texture='yellow') + Graphics3d Object Note that the points do not have to be regularly sampled. For example:: @@ -128,20 +136,24 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list ... for j in range(-5,5): ... l.append((normalvariate(0,1),normalvariate(0,1),normalvariate(0,1))) sage: list_plot3d(l,interpolation_type='nn',texture='yellow',num_points=100) + Graphics3d Object TESTS: We plot 0, 1, and 2 points:: sage: list_plot3d([]) + Graphics3d Object :: sage: list_plot3d([(2,3,4)]) + Graphics3d Object :: sage: list_plot3d([(0,0,1), (2,3,4)]) + Graphics3d Object However, if two points are given with the same x,y coordinates but different z coordinates, an exception will be raised:: @@ -218,6 +230,7 @@ def list_plot3d_matrix(m, texture, **kwds): We plot a matrix that illustrates summation modulo `n`:: sage: n = 5; list_plot3d(matrix(RDF,n,[(i+j)%n for i in [1..n] for j in [1..n]])) # indirect doctest + Graphics3d Object The interpolation type for matrices is 'linear'; for other types use other :func:`list_plot3d` input types. @@ -227,7 +240,9 @@ def list_plot3d_matrix(m, texture, **kwds): sage: pi = float(pi) sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, texture='yellow', frame_aspect_ratio=[1,1,1/3]) # indirect doctest + Graphics3d Object sage: list_plot3d(m, texture='yellow', interpolation_type='linear') # indirect doctest + Graphics3d Object """ from parametric_surface import ParametricSurface f = lambda i,j: (i,j,float(m[int(i),int(j)])) @@ -336,10 +351,12 @@ def list_plot3d_tuples(v,interpolation_type, texture, **kwds): sage: pi = float(pi) sage: m = matrix(RDF, 6, [sin(i^2 + j^2) for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, texture='yellow', interpolation_type='linear', num_points=5) # indirect doctest + Graphics3d Object :: sage: list_plot3d(m, texture='yellow', interpolation_type='spline',frame_aspect_ratio=[1,1,1/3]) + Graphics3d Object :: @@ -348,6 +365,7 @@ def list_plot3d_tuples(v,interpolation_type, texture, **kwds): :: sage: list_plot3d([(1,2,3),(0,1,3),(2,1,4),(1,0,-2)], texture='yellow', num_points=50) + Graphics3d Object """ from matplotlib import delaunay import numpy diff --git a/src/sage/plot/plot3d/parametric_plot3d.py b/src/sage/plot/plot3d/parametric_plot3d.py index 9a2d0f19b23..07e34c38c1e 100644 --- a/src/sage/plot/plot3d/parametric_plot3d.py +++ b/src/sage/plot/plot3d/parametric_plot3d.py @@ -82,6 +82,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ :: sage: parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20)) + Graphics3d Object Note above the lambda function, which creates a callable Python function that sends `u` to `u/10`. @@ -93,6 +94,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: u = var('u') sage: parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20)) + Graphics3d Object #. We draw a parametric surface using 3 Python functions (defined using lambda): @@ -101,6 +103,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) sage: parametric_plot3d(f, (0, 2*pi), (-pi, pi)) + Graphics3d Object #. The surface, but with a mesh: @@ -108,6 +111,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: u, v = var('u,v') sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi), mesh=True) + Graphics3d Object #. The same surface, but where the defining functions are symbolic: @@ -116,6 +120,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: u, v = var('u,v') sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi)) + Graphics3d Object We increase the number of plot points, and make the surface green and transparent: @@ -123,6 +128,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ :: sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi), color='green', opacity=0.1, plot_points=[30,30]) + Graphics3d Object We call the space curve function but with polynomials instead of @@ -132,33 +138,39 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: R. = RDF[] sage: parametric_plot3d( (t, t^2, t^3), (t, 0, 3) ) + Graphics3d Object Next we plot the same curve, but because we use (0, 3) instead of (t, 0, 3), each polynomial is viewed as a callable function of one variable:: sage: parametric_plot3d( (t, t^2, t^3), (0, 3) ) + Graphics3d Object We do a plot but mix a symbolic input, and an integer:: sage: t = var('t') sage: parametric_plot3d( (1, sin(t), cos(t)), (t, 0, 3) ) + Graphics3d Object We specify a boundary style to show us the values of the function at its extrema:: sage: u, v = var('u,v') - sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, pi), (v, 0, pi), \ - ... boundary_style={"color": "black", "thickness": 2}) + sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, pi), (v, 0, pi), + ....: boundary_style={"color": "black", "thickness": 2}) + Graphics3d Object We can plot vectors:: sage: x,y=var('x,y') sage: parametric_plot3d(vector([x-y,x*y,x*cos(y)]), (x,0,2), (y,0,2)) + Graphics3d Object sage: t=var('t') sage: p=vector([1,2,3]) sage: q=vector([2,-1,2]) sage: parametric_plot3d(p*t+q, (t, 0, 2)) + Graphics3d Object Any options you would normally use to specify the appearance of a curve are @@ -174,6 +186,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: p1 = parametric_plot3d(f1, (u,0,2*pi), (v,0,2*pi), texture="red") sage: p2 = parametric_plot3d(f2, (u,0,2*pi), (v,0,2*pi), texture="blue") sage: p1 + p2 + Graphics3d Object A cylindrical Star of David:: @@ -182,6 +195,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: f_y = cos(u)*sin(v)*(abs(cos(3*v/4))^500 + abs(sin(3*v/4))^500)^(-1/260)*(abs(cos(4*u/4))^200 + abs(sin(4*u/4))^200)^(-1/200) sage: f_z = sin(u)*(abs(cos(4*u/4))^200 + abs(sin(4*u/4))^200)^(-1/200) sage: parametric_plot3d([f_x, f_y, f_z], (u, -pi, pi), (v, 0, 2*pi)) + Graphics3d Object Double heart:: @@ -190,6 +204,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: f_y = ( abs(v) - abs(u) - abs(tanh((1/sqrt(2))*u)/(1/sqrt(2))) - abs(tanh((1/sqrt(2))*v)/(1/sqrt(2))) )*cos(v) sage: f_z = sin(u)*(abs(cos(4*u/4))^1 + abs(sin(4*u/4))^1)^(-1/1) sage: parametric_plot3d([f_x, f_y, f_z], (u, 0, pi), (v, -pi, pi)) + Graphics3d Object Heart:: @@ -198,6 +213,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: f_y = sin(u) *(4*sqrt(1-v^2)*sin(abs(u))^abs(u)) sage: f_z = v sage: parametric_plot3d([f_x, f_y, f_z], (u, -pi, pi), (v, -1, 1), frame=False, color="red") + Graphics3d Object Green bowtie:: @@ -206,6 +222,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: f_y = sin(u) / (sqrt(2) + cos(v)) sage: f_z = cos(u) / (1 + sqrt(2)) sage: parametric_plot3d([f_x, f_y, f_z], (u, -pi, pi), (v, -pi, pi), frame=False, color="green") + Graphics3d Object Boy's surface http://en.wikipedia.org/wiki/Boy's_surface @@ -216,6 +233,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = 2/3* (cos(u)* sin(2*v) - sqrt(2)* sin(u)* sin(v))* cos(u) / (sqrt(2) - sin(2*u)* sin(3*v)) sage: fz = sqrt(2)* cos(u)* cos(u) / (sqrt(2) - sin(2*u)* sin(3*v)) sage: parametric_plot3d([fx, fy, fz], (u, -2*pi, 2*pi), (v, 0, pi), plot_points = [90,90], frame=False, color="orange") # long time -- about 30 seconds + Graphics3d Object Maeder's_Owl (pretty but can't find an internet reference):: @@ -224,6 +242,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = -v *sin(u) - 0.5* v^2 * sin(2* u) sage: fz = 4 *v^1.5 * cos(3 *u / 2) / 3 sage: parametric_plot3d([fx, fy, fz], (u, -2*pi, 2*pi), (v, 0, 1),plot_points = [90,90], frame=False, color="purple") + Graphics3d Object Bracelet:: @@ -232,6 +251,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = 0.2*cos(2*pi*u) *3*cos(2*pi*v) sage: fz = (2 + 0.2*sin(2*pi*u))*cos(pi*v) sage: parametric_plot3d([fx, fy, fz], (u, 0, pi/2), (v, 0, 3*pi/4), frame=False, color="gray") + Graphics3d Object Green goblet @@ -242,6 +262,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = sin(u)*cos(2*v) sage: fz = sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, pi), frame=False, color="green") + Graphics3d Object Funny folded surface - with square projection:: @@ -250,6 +271,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = sin(u)*cos(2*v) sage: fz = sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="green") + Graphics3d Object Surface of revolution of figure 8:: @@ -258,6 +280,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = sin(u)*sin(2*v) sage: fz = sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="green") + Graphics3d Object Yellow Whitney's umbrella http://en.wikipedia.org/wiki/Whitney_umbrella:: @@ -267,6 +290,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = u sage: fz = v^2 sage: parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -1, 1), frame=False, color="yellow") + Graphics3d Object Cross cap http://en.wikipedia.org/wiki/Cross-cap:: @@ -275,6 +299,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (1+cos(v))*sin(u) sage: fz = -tanh((2/3)*(u-pi))*sin(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="red") + Graphics3d Object Twisted torus:: @@ -283,6 +308,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (3+sin(v)+cos(u))*sin(2*v) sage: fz = sin(u)+2*cos(v) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="red") + Graphics3d Object Four intersecting discs:: @@ -291,6 +317,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = -v*sin(u) -0.5*v^2*sin(2*u) sage: fz = 4* v^1.5 *cos(3* u / 2) / 3 sage: parametric_plot3d([fx, fy, fz], (u, 0, 4*pi), (v, 0,2*pi), frame=False, color="red", opacity=0.7) + Graphics3d Object Steiner surface/Roman's surface (see http://en.wikipedia.org/wiki/Roman_surface and @@ -301,6 +328,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (sin(u) * sin(2 * v)) sage: fz = (cos(u) * sin(2 * v)) sage: parametric_plot3d([fx, fy, fz], (u, -pi/2, pi/2), (v, -pi/2,pi/2), frame=False, color="red") + Graphics3d Object Klein bottle? (see http://en.wikipedia.org/wiki/Klein_bottle):: @@ -309,6 +337,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (4+2*(1-cos(v)/2)*cos(u))*sin(v) sage: fz = -2*(1-cos(v)/2) * sin(u) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="green") + Graphics3d Object A Figure 8 embedding of the Klein bottle (see http://en.wikipedia.org/wiki/Klein_bottle):: @@ -318,6 +347,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (2 + cos(v/2)* sin(u) - sin(v/2)* sin(2 *u))* sin(v) sage: fz = sin(v/2)* sin(u) + cos(v/2) *sin(2* u) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="red") + Graphics3d Object Enneper's surface (see http://en.wikipedia.org/wiki/Enneper_surface):: @@ -327,6 +357,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = v -v^3/3 + v*u^2 sage: fz = u^2 - v^2 sage: parametric_plot3d([fx, fy, fz], (u, -2, 2), (v, -2, 2), frame=False, color="red") + Graphics3d Object Henneberg's surface (see http://xahlee.org/surface/gallery_m.html) @@ -338,6 +369,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = 2*sinh(u)*sin(v) +(2/3)*sinh(3*u)*sin(3*v) sage: fz = 2*cosh(2*u)*cos(2*v) sage: parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -pi/2, pi/2), frame=False, color="red") + Graphics3d Object Dini's spiral @@ -348,6 +380,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = sin(u)*sin(v) sage: fz = (cos(v)+log(tan(v/2))) + 0.2*u sage: parametric_plot3d([fx, fy, fz], (u, 0, 12.4), (v, 0.1, 2),frame=False, color="red") + Graphics3d Object Catalan's surface (see http://xahlee.org/surface/catalan/catalan.html):: @@ -357,6 +390,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = 1-cos(u)*cosh(v) sage: fz = 4*sin(1/2*u)*sinh(v/2) sage: parametric_plot3d([fx, fy, fz], (u, -pi, 3*pi), (v, -2, 2), frame=False, color="red") + Graphics3d Object A Conchoid:: @@ -364,11 +398,13 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: k = 1.2; k_2 = 1.2; a = 1.5 sage: f = (k^u*(1+cos(v))*cos(u), k^u*(1+cos(v))*sin(u), k^u*sin(v)-a*k_2^u) sage: parametric_plot3d(f, (u,0,6*pi), (v,0,2*pi), plot_points=[40,40], texture=(0,0.5,0)) + Graphics3d Object A Mobius strip:: sage: u,v = var("u,v") sage: parametric_plot3d([cos(u)*(1+v*cos(u/2)), sin(u)*(1+v*cos(u/2)), 0.2*v*sin(u/2)], (u,0, 4*pi+0.5), (v,0, 0.3),plot_points=[50,50]) + Graphics3d Object A Twisted Ribbon @@ -376,31 +412,37 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: u, v = var('u,v') sage: parametric_plot3d([3*sin(u)*cos(v), 3*sin(u)*sin(v), cos(v)], (u,0, 2*pi), (v, 0, pi),plot_points=[50,50]) + Graphics3d Object An Ellipsoid:: sage: u, v = var('u,v') sage: parametric_plot3d([3*sin(u)*cos(v), 2*sin(u)*sin(v), cos(u)], (u,0, 2*pi), (v, 0, 2*pi),plot_points=[50,50], aspect_ratio=[1,1,1]) + Graphics3d Object A Cone:: sage: u, v = var('u,v') sage: parametric_plot3d([u*cos(v), u*sin(v), u], (u, -1, 1), (v, 0, 2*pi+0.5), plot_points=[50,50]) + Graphics3d Object A Paraboloid:: sage: u, v = var('u,v') sage: parametric_plot3d([u*cos(v), u*sin(v), u^2], (u, 0, 1), (v, 0, 2*pi+0.4), plot_points=[50,50]) + Graphics3d Object A Hyperboloid:: sage: u, v = var('u,v') sage: plot3d(u^2-v^2, (u, -1, 1), (v, -1, 1), plot_points=[50,50]) + Graphics3d Object A weird looking surface - like a Mobius band but also an O:: sage: u, v = var('u,v') sage: parametric_plot3d([sin(u)*cos(u)*log(u^2)*sin(v), (u^2)^(1/6)*(cos(u)^2)^(1/4)*cos(v), sin(v)], (u, 0.001, 1), (v, -pi, pi+0.2), plot_points=[50,50]) + Graphics3d Object A heart, but not a cardioid (for my wife):: @@ -417,6 +459,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (sinh(v)*sin(3*u))/(1+cosh(u)*cosh(v)) sage: fz = (cosh(v)*sinh(u))/(1+cosh(u)*cosh(v)) sage: parametric_plot3d([fx, fy, fz], (u, -pi, pi), (v, -pi, pi), plot_points = [50,50], frame=False, color="red") + Graphics3d Object A Helicoid (lines through a helix, http://en.wikipedia.org/wiki/Helix):: @@ -426,6 +469,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = -sinh(v)*cos(u) sage: fz = 3*u sage: parametric_plot3d([fx, fy, fz], (u, -pi, pi), (v, -pi, pi), plot_points = [50,50], frame=False, color="red") + Graphics3d Object Kuen's surface (http://virtualmathmuseum.org/Surface/kuen/kuen.html):: @@ -434,6 +478,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (2*(sin(u) - u*cos(u))*sin(v))/(1+ u^2*sin(v)^2) sage: fz = log(tan(1/2 *v)) + (2*cos(v))/(1+ u^2*sin(v)^2) sage: parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0.01, pi-0.01), plot_points = [50,50], frame=False, color="green") + Graphics3d Object A 5-pointed star:: @@ -441,6 +486,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = cos(u)*sin(v)*(abs(cos(1*u/4))^0.5 + abs(sin(1*u/4))^0.5)^(-1/0.3)*(abs(cos(5*v/4))^1.7 + abs(sin(5*v/4))^1.7)^(-1/0.1) sage: fz = sin(u)*(abs(cos(1*u/4))^0.5 + abs(sin(1*u/4))^0.5)^(-1/0.3) sage: parametric_plot3d([fx, fy, fz], (u, -pi/2, pi/2), (v, 0, 2*pi), plot_points = [50,50], frame=False, color="green") + Graphics3d Object A cool self-intersecting surface (Eppener surface?):: @@ -448,6 +494,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = v - v^3/3 + v*u^2 sage: fz = u^2 - v^2 sage: parametric_plot3d([fx, fy, fz], (u, -25, 25), (v, -25, 25), plot_points = [50,50], frame=False, color="green") + Graphics3d Object The breather surface (http://en.wikipedia.org/wiki/Breather_surface):: @@ -456,6 +503,7 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ sage: fy = (2*sqrt(0.84)*cosh(0.4*u)*(-(sqrt(0.84)*sin(v)*cos(sqrt(0.84)*v)) + cos(v)*sin(sqrt(0.84)*v)))/(0.4*((sqrt(0.84)*cosh(0.4*u))^2 + (0.4*sin(sqrt(0.84)*v))^2)) sage: fz = -u + (2*0.84*cosh(0.4*u)*sinh(0.4*u))/(0.4*((sqrt(0.84)*cosh(0.4*u))^2 + (0.4*sin(sqrt(0.84)*v))^2)) sage: parametric_plot3d([fx, fy, fz], (u, -13.2, 13.2), (v, -37.4, 37.4), plot_points = [90,90], frame=False, color="green") + Graphics3d Object TESTS:: @@ -469,12 +517,15 @@ def parametric_plot3d(f, urange, vrange=None, plot_points="automatic", boundary_ From Trac #2858:: sage: parametric_plot3d((u,-u,v), (u,-10,10),(v,-10,10)) + Graphics3d Object sage: f(u)=u; g(v)=v^2; parametric_plot3d((g,f,f), (-10,10),(-10,10)) + Graphics3d Object From Trac #5368:: sage: x, y = var('x,y') sage: plot3d(x*y^2 - sin(x), (x,-1,1), (y,-1,1)) + Graphics3d Object """ # TODO: @@ -552,11 +603,13 @@ def _parametric_plot3d_curve(f, urange, plot_points, **kwds): callable Python function that sends `u` to `u/10`:: sage: parametric_plot3d( (sin, cos, lambda u: u/10), (0, 20)) # indirect doctest + Graphics3d Object Now we do the same thing with symbolic expressions:: sage: u = var('u') sage: parametric_plot3d( (sin(u), cos(u), u/10), (u, 0, 20)) + Graphics3d Object """ from sage.plot.misc import setup_for_eval_on_grid g, ranges = setup_for_eval_on_grid(f, [urange], plot_points) @@ -609,11 +662,13 @@ def _parametric_plot3d_surface(f, urange, vrange, plot_points, boundary_style, * sage: f = (lambda u,v: cos(u), lambda u,v: sin(u)+cos(v), lambda u,v: sin(v)) sage: parametric_plot3d(f, (0, 2*pi), (-pi, pi)) # indirect doctest + Graphics3d Object Now we do the same thing with symbolic expressions:: sage: u, v = var('u,v') sage: parametric_plot3d((cos(u), sin(u) + cos(v), sin(v)), (u, 0, 2*pi), (v, -pi, pi), mesh=True) + Graphics3d Object """ from sage.plot.misc import setup_for_eval_on_grid g, ranges = setup_for_eval_on_grid(f, [urange,vrange], plot_points) diff --git a/src/sage/plot/plot3d/parametric_surface.pyx b/src/sage/plot/plot3d/parametric_surface.pyx index 87f1c90022b..ea958357cc0 100644 --- a/src/sage/plot/plot3d/parametric_surface.pyx +++ b/src/sage/plot/plot3d/parametric_surface.pyx @@ -266,12 +266,14 @@ cdef class ParametricSurface(IndexFaceSet): sage: D = dodecahedron() sage: D.dual() + Graphics3d Object But any enclosed surface should work:: sage: from sage.plot.plot3d.shapes import Torus sage: T = Torus(1, .2) sage: T.dual() + Graphics3d Object sage: T.is_enclosed() True @@ -644,8 +646,11 @@ class MobiusStrip(ParametricSurface): sage: from sage.plot.plot3d.parametric_surface import MobiusStrip sage: M = MobiusStrip(3,3); M # Same width and radius, roughly + Graphics3d Object sage: N = MobiusStrip(7,3,2); N # two twists, lots of open area in the middle + Graphics3d Object sage: O = MobiusStrip(5,1,plot_points=200,color='red'); O # keywords get passed to plot3d + Graphics3d Object """ ParametricSurface.__init__(self, **kwds) diff --git a/src/sage/plot/plot3d/platonic.py b/src/sage/plot/plot3d/platonic.py index deb0ac98b19..78f95ffd4db 100644 --- a/src/sage/plot/plot3d/platonic.py +++ b/src/sage/plot/plot3d/platonic.py @@ -21,6 +21,7 @@ Display nice faces only:: sage: icosahedron().stickers(['red','blue'], .075, .1) + Graphics3d Object AUTHORS: @@ -75,14 +76,17 @@ def index_face_set(face_list, point_list, enclosed, **kwds): Verify that these are working and passing on keywords:: sage: tetrahedron(center=(2,0,0),size=2,color='red') + Graphics3d Object :: sage: dodecahedron(center=(2,0,0),size=2,color='red') + Graphics3d Object :: sage: icosahedron(center=(2,0,0),size=2,color='red') + Graphics3d Object """ if 'center' in kwds: center = kwds['center'] @@ -119,6 +123,7 @@ def prep(G, center, size, kwds): and that keywords are passed (see Trac #10796):: sage: octahedron(center=(2,0,0),size=2,color='red') + Graphics3d Object """ if size != 1: G = G.scale(size) @@ -147,26 +152,32 @@ def tetrahedron(center=(0,0,0), size=1, **kwds): EXAMPLES: A default colored tetrahedron at the origin:: sage: tetrahedron() + Graphics3d Object A transparent green tetrahedron in front of a solid red one:: sage: tetrahedron(opacity=0.8, color='green') + tetrahedron((-2,1,0),color='red') + Graphics3d Object A translucent tetrahedron sharing space with a sphere:: sage: tetrahedron(color='yellow',opacity=0.7) + sphere(r=.5, color='red') + Graphics3d Object A big tetrahedron:: sage: tetrahedron(size=10) + Graphics3d Object A wide tetrahedron:: sage: tetrahedron(aspect_ratio=[1,1,1]).scale((4,4,1)) + Graphics3d Object A red and blue tetrahedron touching noses:: sage: tetrahedron(color='red') + tetrahedron((0,0,-2)).scale([1,1,-1]) + Graphics3d Object A Dodecahedral complex of 5 tetrahedrons (a more elaborate examples from Peter Jipsen):: @@ -228,39 +239,48 @@ def cube(center=(0,0,0), size=1, color=None, frame_thickness=0, frame_color=None A simple cube:: sage: cube() + Graphics3d Object A red cube:: sage: cube(color="red") + Graphics3d Object A transparent grey cube that contains a red cube:: sage: cube(opacity=0.8, color='grey') + cube(size=3/4) + Graphics3d Object A transparent colored cube:: sage: cube(color=['red', 'green', 'blue'], opacity=0.5) + Graphics3d Object A bunch of random cubes:: sage: v = [(random(), random(), random()) for _ in [1..30]] sage: sum([cube((10*a,10*b,10*c), size=random()/3, color=(a,b,c)) for a,b,c in v]) + Graphics3d Object Non-square cubes (boxes):: sage: cube(aspect_ratio=[1,1,1]).scale([1,2,3]) + Graphics3d Object sage: cube(color=['red', 'blue', 'green'],aspect_ratio=[1,1,1]).scale([1,2,3]) + Graphics3d Object And one that is colored:: - sage: cube(color=['red', 'blue', 'green', 'black', 'white', 'orange'], \ - aspect_ratio=[1,1,1]).scale([1,2,3]) + sage: cube(color=['red', 'blue', 'green', 'black', 'white', 'orange'], + ....: aspect_ratio=[1,1,1]).scale([1,2,3]) + Graphics3d Object A nice translucent color cube with a frame:: - sage: c = cube(color=['red', 'blue', 'green'], frame=False, frame_thickness=2, \ - frame_color='brown', opacity=0.8) + sage: c = cube(color=['red', 'blue', 'green'], frame=False, frame_thickness=2, + ....: frame_color='brown', opacity=0.8) sage: c + Graphics3d Object A raytraced color cube with frame and transparency:: @@ -310,7 +330,8 @@ def octahedron(center=(0,0,0), size=1, **kwds): EXAMPLES:: sage: octahedron((1,4,3), color='orange') + \ - octahedron((0,2,1), size=2, opacity=0.6) + ....: octahedron((0,2,1), size=2, opacity=0.6) + Graphics3d Object """ if 'aspect_ratio' not in kwds: kwds['aspect_ratio'] = [1,1,1] @@ -338,11 +359,13 @@ def dodecahedron(center=(0,0,0), size=1, **kwds): EXAMPLES: A plain Dodecahedron:: sage: dodecahedron() + Graphics3d Object A translucent dodecahedron that contains a black sphere:: sage: dodecahedron(color='orange', opacity=0.8) + \ - sphere(size=0.5, color='black') + ....: sphere(size=0.5, color='black') + Graphics3d Object CONSTRUCTION: This is how we construct a dodecahedron. We let one point be `Q = (0,1,0)`. @@ -441,13 +464,15 @@ def icosahedron(center=(0,0,0), size=1, **kwds): EXAMPLES:: sage: icosahedron() + Graphics3d Object Two icosahedrons at different positions of different sizes. :: sage: icosahedron((-1/2,0,1), color='orange') + \ - icosahedron((2,0,1), size=1/2, aspect_ratio=[1,1,1]) + ....: icosahedron((2,0,1), size=1/2, aspect_ratio=[1,1,1]) + Graphics3d Object """ if 'aspect_ratio' not in kwds: kwds['aspect_ratio'] = [1,1,1] diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index 9ac8777716d..ab0538c2350 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -41,6 +41,7 @@ Or, we plot a very simple function indeed:: sage: plot3d(pi, (-1,1), (-1,1)) + Graphics3d Object AUTHORS: @@ -232,6 +233,7 @@ def to_cartesian(self, func, params=None): sage: import scipy.interpolate sage: f=scipy.interpolate.RectBivariateSpline(v_phi,v_theta,m_r) sage: spherical_plot3d(f,(0,2*pi),(0,pi)) + Graphics3d Object """ from sage.symbolic.expression import is_Expression @@ -423,12 +425,14 @@ class Spherical(_Coordinates): azimuth and the inclination (in that order):: sage: plot3d(phi * theta, (theta, 0, pi), (phi, 0, 1), transformation=T) + Graphics3d Object We next graph the function where the inclination angle is constant:: sage: S=Spherical('inclination', ['radius', 'azimuth']) sage: r,theta=var('r,theta') sage: plot3d(3, (r,0,3), (theta, 0, 2*pi), transformation=S) + Graphics3d Object See also :func:`spherical_plot3d` for more examples of plotting in spherical coordinates. @@ -478,6 +482,7 @@ class SphericalElevation(_Coordinates): azimuth and the elevation (in that order):: sage: plot3d(phi * theta, (theta, 0, pi), (phi, 0, 1), transformation=T) + Graphics3d Object We next graph the function where the elevation angle is constant. This should be compared to the similar example for the ``Spherical`` coordinate @@ -486,12 +491,14 @@ class SphericalElevation(_Coordinates): sage: SE=SphericalElevation('elevation', ['radius', 'azimuth']) sage: r,theta=var('r,theta') sage: plot3d(3, (r,0,3), (theta, 0, 2*pi), transformation=SE) + Graphics3d Object Plot a sin curve wrapped around the equator:: sage: P1=plot3d( (pi/12)*sin(8*theta), (r,0.99,1), (theta, 0, 2*pi), transformation=SE, plot_points=(10,200)) sage: P2=sphere(center=(0,0,0), size=1, color='red', opacity=0.3) sage: P1+P2 + Graphics3d Object Now we graph several constant elevation functions alongside several constant inclination functions. This example illustrates the difference between the @@ -556,12 +563,14 @@ class Cylindrical(_Coordinates): radius and the azimuth (in that order):: sage: plot3d(9-r^2, (r, 0, 3), (theta, 0, pi), transformation=T) + Graphics3d Object We next graph the function where the radius is constant:: sage: S=Cylindrical('radius', ['azimuth', 'height']) sage: theta,z=var('theta, z') sage: plot3d(3, (theta,0,2*pi), (z, -2, 2), transformation=S) + Graphics3d Object See also :func:`cylindrical_plot3d` for more examples of plotting in cylindrical coordinates. @@ -689,34 +698,42 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): EXAMPLES: We plot a 3d function defined as a Python function:: sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2)) + Graphics3d Object We plot the same 3d function but using adaptive refinement:: sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True) + Graphics3d Object Adaptive refinement but with more points:: sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True, initial_depth=5) + Graphics3d Object We plot some 3d symbolic functions:: sage: var('x,y') (x, y) sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2)) + Graphics3d Object sage: plot3d(sin(x*y), (x, -pi, pi), (y, -pi, pi)) + Graphics3d Object We give a plot with extra sample points:: sage: var('x,y') (x, y) sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=200) + Graphics3d Object sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=[10,100]) + Graphics3d Object A 3d plot with a mesh:: sage: var('x,y') (x, y) sage: plot3d(sin(x-y)*y*cos(x),(x,-3,3),(y,-3,3), mesh=True) + Graphics3d Object Two wobby translucent planes:: @@ -724,6 +741,7 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): sage: P = plot3d(x+y+sin(x*y), (x,-10,10),(y,-10,10), opacity=0.87, color='blue') sage: Q = plot3d(x-2*y-cos(x*y),(x,-10,10),(y,-10,10),opacity=0.3,color='red') sage: P + Q + Graphics3d Object We draw two parametric surfaces and a transparent plane:: @@ -731,16 +749,19 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): sage: P = plot3d(lambda x,y: 4 - x^3 - y^2, (-2,2), (-2,2), color='green') sage: Q = plot3d(lambda x,y: x^3 + y^2 - 4, (-2,2), (-2,2), color='orange') sage: L + P + Q + Graphics3d Object We draw the "Sinus" function (water ripple-like surface):: sage: x, y = var('x y') sage: plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1)) + Graphics3d Object Hill and valley (flat surface with a bump and a dent):: sage: x, y = var('x y') sage: plot3d( 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2)) + Graphics3d Object An example of a transformation:: @@ -752,6 +773,7 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): sage: cylindrical(r,theta,z)=[r*cos(theta),r*sin(theta),z] sage: plot3d(3,(theta,0,pi/2),(z,0,pi/2),transformation=cylindrical) + Graphics3d Object Many more examples of transformations:: @@ -891,6 +913,7 @@ def plot3d_adaptive(f, x_range, y_range, color="automatic", sage: from sage.plot.plot3d.plot3d import plot3d_adaptive sage: x,y=var('x,y'); plot3d_adaptive(sin(x*y), (x,-pi,pi), (y,-pi,pi), initial_depth=5) + Graphics3d Object """ if initial_depth >= max_depth: max_depth = initial_depth @@ -954,12 +977,14 @@ def spherical_plot3d(f, urange, vrange, **kwds): sage: f=u*v; urange=(u,0,pi); vrange=(v,0,pi) sage: T = (r*cos(u)*sin(v), r*sin(u)*sin(v), r*cos(v), [u,v]) sage: plot3d(f, urange, vrange, transformation=T) + Graphics3d Object or equivalently:: sage: T = Spherical('radius', ['azimuth', 'inclination']) sage: f=lambda u,v: u*v; urange=(u,0,pi); vrange=(v,0,pi) sage: plot3d(f, urange, vrange, transformation=T) + Graphics3d Object INPUT: @@ -975,6 +1000,7 @@ def spherical_plot3d(f, urange, vrange, **kwds): sage: x,y=var('x,y') sage: spherical_plot3d(2,(x,0,2*pi),(y,0,pi)) + Graphics3d Object The real and imaginary parts of a spherical harmonic with `l=2` and `m=1`:: @@ -993,6 +1019,7 @@ def spherical_plot3d(f, urange, vrange, **kwds): sage: x,y=var('x,y') sage: spherical_plot3d((2+cos(2*x))*(y+1),(x,0,2*pi),(y,0,pi),rgbcolor=(1,.1,.1)) + Graphics3d Object Some random figures: @@ -1000,6 +1027,7 @@ def spherical_plot3d(f, urange, vrange, **kwds): sage: x,y=var('x,y') sage: spherical_plot3d(1+sin(5*x)/5,(x,0,2*pi),(y,0,pi),rgbcolor=(1,0.5,0),plot_points=(80,80),opacity=0.7) + Graphics3d Object :: @@ -1017,12 +1045,14 @@ def cylindrical_plot3d(f, urange, vrange, **kwds): sage: f=u*v; urange=(u,0,pi); vrange=(v,0,pi) sage: T = (r*cos(u), r*sin(u), v, [u,v]) sage: plot3d(f, urange, vrange, transformation=T) + Graphics3d Object or equivalently:: sage: T = Cylindrical('radius', ['azimuth', 'height']) sage: f=lambda u,v: u*v; urange=(u,0,pi); vrange=(v,0,pi) sage: plot3d(f, urange, vrange, transformation=T) + Graphics3d Object INPUT: @@ -1042,12 +1072,14 @@ def cylindrical_plot3d(f, urange, vrange, **kwds): sage: theta,z=var('theta,z') sage: cylindrical_plot3d(2,(theta,0,3*pi/2),(z,-2,2)) + Graphics3d Object Some random figures: :: sage: cylindrical_plot3d(cosh(z),(theta,0,2*pi),(z,-2,2)) + Graphics3d Object :: @@ -1070,10 +1102,12 @@ def axes(scale=1, radius=None, **kwds): sage: from sage.plot.plot3d.plot3d import axes sage: S = axes(6, color='black'); S + Graphics3d Object :: sage: T = axes(2, .5); T + Graphics3d Object """ if radius is None: radius = scale/100.0 diff --git a/src/sage/plot/plot3d/plot_field3d.py b/src/sage/plot/plot3d/plot_field3d.py index 6058d653499..74b59d4f2a5 100644 --- a/src/sage/plot/plot3d/plot_field3d.py +++ b/src/sage/plot/plot3d/plot_field3d.py @@ -52,17 +52,24 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, sage: x,y,z=var('x y z') sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi)) + Graphics3d Object sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),colors=['red','green','blue']) + Graphics3d Object sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),colors='red') + Graphics3d Object sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),plot_points=4) + Graphics3d Object sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),plot_points=[3,5,7]) + Graphics3d Object sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),center_arrows=True) + Graphics3d Object TESTS: This tests that :trac:`2100` is fixed in a way compatible with this command:: sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),center_arrows=True,aspect_ratio=(1,2,1)) + Graphics3d Object """ (ff,gg,hh), ranges = setup_for_eval_on_grid(functions, [xrange, yrange, zrange], plot_points) xpoints, ypoints, zpoints = [srange(*r, include_endpoint=True) for r in ranges] diff --git a/src/sage/plot/plot3d/shapes.pyx b/src/sage/plot/plot3d/shapes.pyx index e6a86c5f748..152d8fedfc5 100644 --- a/src/sage/plot/plot3d/shapes.pyx +++ b/src/sage/plot/plot3d/shapes.pyx @@ -126,6 +126,7 @@ class Box(IndexFaceSet): sage: from sage.plot.plot3d.shapes import Box sage: Box(10, 1, 1) + Box(1, 10, 1) + Box(1, 1, 10) + Graphics3d Object """ if isinstance(size[0], (tuple, list)): size = validate_frame_size(size[0]) @@ -227,10 +228,12 @@ cdef class Cone(ParametricSurface): We may omit the base:: sage: Cone(1, 1, closed=False) + Graphics3d Object A spiky plot of the sine function:: sage: sum(Cone(.1, sin(n), color='yellow').translate(n, sin(n), 0) for n in [0..10, step=.1]) + Graphics3d Object A Christmas tree:: @@ -317,6 +320,7 @@ cdef class Cylinder(ParametricSurface): We may omit the base:: sage: Cylinder(1, 1, closed=False) + Graphics3d Object Some gears:: @@ -332,6 +336,7 @@ cdef class Cylinder(ParametricSurface): sage: from sage.plot.plot3d.shapes import Cylinder sage: Cylinder(1, 1, color='red') + Graphics3d Object """ ParametricSurface.__init__(self, **kwds) self.radius = radius @@ -565,27 +570,33 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * The default arrow:: sage: arrow3d((0,0,0), (1,1,1), 1) + Graphics3d Object A fat arrow:: sage: arrow3d((0,0,0), (1,1,1), radius=0.1) + Graphics3d Object A green arrow:: sage: arrow3d((0,0,0), (1,1,1), color='green') + Graphics3d Object A fat arrow head:: sage: arrow3d((2,1,0), (1,1,1), color='green', head_radius=0.3, aspect_ratio=[1,1,1]) + Graphics3d Object Many arrow arranged in a circle (flying spears?):: sage: sum([arrow3d((cos(t),sin(t),0),(cos(t),sin(t),1)) for t in [0,0.3,..,2*pi]]) + Graphics3d Object Change the width of the arrow. (Note: for an arrow that scales with zoom, please consider the 'line3d' function with the option 'arrow_head=True'):: sage: arrow3d((0,0,0), (1,1,1), width=1) + Graphics3d Object TESTS: @@ -615,7 +626,7 @@ def arrow3d(start, end, width=1, radius=None, head_radius=None, head_len=None, * sage: arrow3d((0,0,0), (1,1,1), thickness=1) doctest:...: DeprecationWarning: use the option 'width' instead of 'thickness' See http://trac.sagemath.org/7154 for details. - + Graphics3d Object """ if radius is None: radius = width/50.0 @@ -652,6 +663,7 @@ cdef class Sphere(ParametricSurface): sage: from sage.plot.plot3d.shapes import Sphere sage: Sphere(3) + Graphics3d Object Plot with aspect_ratio=1 to see it unsquashed:: @@ -669,6 +681,7 @@ cdef class Sphere(ParametricSurface): sage: from sage.plot.plot3d.shapes import Sphere sage: Sphere(3) + Graphics3d Object """ ParametricSurface.__init__(self, **kwds) self.radius = radius @@ -873,8 +886,10 @@ class Text(PrimitiveObject): sage: from sage.plot.plot3d.shapes import Text sage: Text("Just a lonely label.") + Graphics3d Object sage: pts = [(RealField(10)^3).random_element() for k in range(20)] sage: sum(Text(str(P)).translate(P) for P in pts) + Graphics3d Object """ def __init__(self, string, **kwds): """ diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index 25e5652df65..42421caf0a4 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -74,20 +74,24 @@ def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): A line in 3-space:: sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)]) + Graphics3d Object The same line but red:: sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)], color='red') + Graphics3d Object The points of the line provided as a numpy array:: sage: import numpy sage: line3d(numpy.array([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)])) + Graphics3d Object A transparent thick green line and a little blue line:: - sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, \ - color='green') + line3d([(0,1,0), (1,0,2)]) + sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, + ....: color='green') + line3d([(0,1,0), (1,0,2)]) + Graphics3d Object A Dodecahedral complex of 5 tetrahedrons (a more elaborate example from Peter Jipsen):: @@ -126,8 +130,11 @@ def line3d(points, thickness=1, radius=None, arrow_head=False, **kwds): list, such as iterators and such (see :trac:`10478`):: sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)])) + Graphics3d Object sage: line3d((x, x^2, x^3) for x in range(5)) + Graphics3d Object sage: from itertools import izip; line3d(izip([2,3,5,7], [11, 13, 17, 19], [-1, -2, -3, -4])) + Graphics3d Object """ points = list(points) if len(points) < 2: @@ -209,12 +216,14 @@ def bezier3d(path, **options): sage: path = [[(0,0,0),(.5,.1,.2),(.75,3,-1),(1,1,0)],[(.5,1,.2),(1,.5,0)],[(.7,.2,.5)]] sage: b = bezier3d(path, color='green') sage: b + Graphics3d Object To construct a simple curve, create a list containing a single list:: sage: path = [[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]] sage: curve = bezier3d(path, thickness=5, color='blue') sage: curve + Graphics3d Object """ import parametric_plot3d as P3D from sage.modules.free_module_element import vector @@ -260,15 +269,18 @@ def polygon3d(points, **options): A simple triangle:: sage: polygon3d([[0,0,0], [1,2,3], [3,0,0]]) + Graphics3d Object Some modern art -- a random polygon:: sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)] sage: polygon3d(v) + Graphics3d Object A bent transparent green triangle:: sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7) + Graphics3d Object """ from sage.plot.plot3d.index_face_set import IndexFaceSet return IndexFaceSet([range(len(points))], points, **options) @@ -297,11 +309,13 @@ def frame3d(lower_left, upper_right, **kwds): sage: from sage.plot.plot3d.shapes2 import frame3d sage: frame3d([1,3,2],vector([2,5,4]),color='red') + Graphics3d Object This is usually used for making an actual plot:: sage: y = var('y') sage: plot3d(sin(x^2+y^2),(x,0,pi),(y,0,pi)) + Graphics3d Object """ x0,y0,z0 = lower_left x1,y1,z1 = upper_right @@ -355,6 +369,7 @@ def frame_labels(lower_left, upper_right, sage: from sage.plot.plot3d.shapes2 import frame_labels sage: frame_labels([1,2,3],[4,5,6],[1,2,3],[4,5,6]) + Graphics3d Object This is usually used for making an actual plot:: @@ -446,20 +461,24 @@ def ruler(start, end, ticks=4, sub_ticks=4, absolute=False, snap=False, **kwds): sage: from sage.plot.plot3d.shapes2 import ruler sage: R = ruler([1,2,3],vector([2,3,4])); R + Graphics3d Object A ruler with some options:: sage: R = ruler([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); R + Graphics3d Object The keyword ``snap`` makes the ticks not necessarily coincide with the ruler:: sage: ruler([1,2,3],vector([1,2,4]),snap=True) + Graphics3d Object The keyword ``absolute`` makes a huge ruler in one of the axis directions:: sage: ruler([1,2,3],vector([1,2,4]),absolute=True) + Graphics3d Object TESTS:: @@ -551,10 +570,12 @@ def ruler_frame(lower_left, upper_right, ticks=4, sub_ticks=4, **kwds): sage: from sage.plot.plot3d.shapes2 import ruler_frame sage: F = ruler_frame([1,2,3],vector([2,3,4])); F + Graphics3d Object A ruler frame with some options:: sage: F = ruler_frame([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); F + Graphics3d Object """ return ruler(lower_left, (upper_right[0], lower_left[1], lower_left[2]), ticks=ticks, sub_ticks=sub_ticks, absolute=True, **kwds) \ + ruler(lower_left, (lower_left[0], upper_right[1], lower_left[2]), ticks=ticks, sub_ticks=sub_ticks, absolute=True, **kwds) \ @@ -580,21 +601,25 @@ def sphere(center=(0,0,0), size=1, **kwds): EXAMPLES: A simple sphere:: sage: sphere() + Graphics3d Object Two spheres touching:: sage: sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1]) + Graphics3d Object Spheres of radii 1 and 2 one stuck into the other:: - sage: sphere(color='orange') + sphere(color=(0,0,0.3), \ - center=(0,0,-2),size=2,opacity=0.9) + sage: sphere(color='orange') + sphere(color=(0,0,0.3), + ....: center=(0,0,-2),size=2,opacity=0.9) + Graphics3d Object We draw a transparent sphere on a saddle. :: sage: u,v = var('u v') sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2)) sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle + Graphics3d Object TESTS:: @@ -631,19 +656,23 @@ def text3d(txt, x_y_z, **kwds): We write the word Sage in red at position (1,2,3):: sage: text3d("Sage", (1,2,3), color=(0.5,0,0)) + Graphics3d Object We draw a multicolor spiral of numbers:: - sage: sum([text3d('%.1f'%n, (cos(n),sin(n),n), color=(n/2,1-n/2,0)) \ - for n in [0,0.2,..,8]]) + sage: sum([text3d('%.1f'%n, (cos(n),sin(n),n), color=(n/2,1-n/2,0)) + ....: for n in [0,0.2,..,8]]) + Graphics3d Object Another example:: sage: text3d("Sage is really neat!!",(2,12,1)) + Graphics3d Object And in 3d in two places:: sage: text3d("Sage is...",(2,12,1), color=(1,0,0)) + text3d("quite powerful!!",(4,10,0), color=(0,0,1)) + Graphics3d Object """ (x, y, z) = x_y_z if 'color' not in kwds and 'rgbcolor' not in kwds: @@ -671,6 +700,7 @@ class Point(PrimitiveObject): keywords are correctly used:: sage: point3d((4,3,2),size=2,color='red',opacity=.5) + Graphics3d Object """ def __init__(self, center, size=1, **kwds): """ @@ -784,10 +814,12 @@ class Line(PrimitiveObject): sage: from sage.plot.plot3d.shapes2 import Line sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], arrow_head=True) + Graphics3d Object Smooth angles less than 90 degrees:: sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=0) + Graphics3d Object """ def __init__(self, points, thickness=5, corner_cutoff=.5, arrow_head=False, **kwds): """ @@ -1015,6 +1047,7 @@ def point3d(v, size=5, **kwds): EXAMPLES:: sage: sum([point3d((i,i^2,i^3), size=5) for i in range(10)]) + Graphics3d Object We check to make sure this works with vectors and other iterables:: @@ -1031,13 +1064,16 @@ def point3d(v, size=5, **kwds): We check to make sure the options work:: sage: point3d((4,3,2),size=20,color='red',opacity=.5) + Graphics3d Object numpy arrays can be provided as input:: sage: import numpy sage: point3d(numpy.array([1,2,3])) + Graphics3d Object sage: point3d(numpy.array([[1,2,3], [4,5,6], [7,8,9]])) + Graphics3d Object """ if len(v) == 3: diff --git a/src/sage/plot/plot3d/texture.py b/src/sage/plot/plot3d/texture.py index af41ad69267..2a33d15afbf 100644 --- a/src/sage/plot/plot3d/texture.py +++ b/src/sage/plot/plot3d/texture.py @@ -11,7 +11,7 @@ Initially, we have no textures set:: sage: sage.plot.plot3d.base.Graphics3d().texture_set() - set([]) + set() However, one can access these textures in the following manner:: @@ -28,6 +28,7 @@ sage: t.opacity 0.500000000000000 sage: T # should be translucent + Graphics3d Object AUTHOR: diff --git a/src/sage/plot/plot_field.py b/src/sage/plot/plot_field.py index b01beb87622..0ea97fad579 100644 --- a/src/sage/plot/plot_field.py +++ b/src/sage/plot/plot_field.py @@ -164,16 +164,19 @@ def plot_vector_field(f_g, xrange, yrange, **options): sage: x,y = var('x y') sage: plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3)) + Graphics object consisting of 1 graphics primitive :: sage: plot_vector_field(( y, (cos(x)-2)*sin(x)), (x,-pi,pi), (y,-pi,pi)) + Graphics object consisting of 1 graphics primitive Plot a gradient field:: sage: u,v = var('u v') sage: f = exp(-(u^2+v^2)) sage: plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2), color='blue') + Graphics object consisting of 1 graphics primitive Plot two orthogonal vector fields:: @@ -186,15 +189,18 @@ def plot_vector_field(f_g, xrange, yrange, **options): sage: x,y = var('x,y') sage: plot_vector_field( (-x/sqrt(x^2+y^2), -y/sqrt(x^2+y^2)), (x, -10, 10), (y, -10, 10)) + Graphics object consisting of 1 graphics primitive :: sage: x,y = var('x,y') sage: plot_vector_field( (-x/sqrt(x+y), -y/sqrt(x+y)), (x, -10, 10), (y, -10, 10)) + Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: plot_vector_field((x, y), (x, -2, 2), (y, -2, 2), xmax=10) + Graphics object consisting of 1 graphics primitive sage: plot_vector_field((x, y), (x, -2, 2), (y, -2, 2)).show(xmax=10) # These are equivalent """ (f, g) = f_g @@ -236,15 +242,18 @@ def plot_slope_field(f, xrange, yrange, **kwds): sage: capacity = 3 # thousand sage: growth_rate = 0.7 # population increases by 70% per unit of time sage: plot_slope_field(growth_rate*(1-y/capacity)*y, (x,0,5), (y,0,capacity*2)) + Graphics object consisting of 1 graphics primitive Plot a slope field involving sin and cos:: sage: x,y = var('x y') sage: plot_slope_field(sin(x+y)+cos(x+y), (x,-3,3), (y,-3,3)) + Graphics object consisting of 1 graphics primitive Plot a slope field using a lambda function:: sage: plot_slope_field(lambda x,y: x+y, (-2,2), (-2,2)) + Graphics object consisting of 1 graphics primitive TESTS: @@ -255,6 +264,7 @@ def plot_slope_field(f, xrange, yrange, **kwds): sage: import numpy # bump warnings up to errors for testing purposes sage: old_err = numpy.seterr('raise') sage: plot_slope_field(sin(x+y)+cos(x+y), (x,-3,3), (y,-3,3)) + Graphics object consisting of 1 graphics primitive sage: dummy_err = numpy.seterr(**old_err) """ slope_options = {'headaxislength': 0, 'headlength': 1e-9, 'pivot': 'middle'} diff --git a/src/sage/plot/point.py b/src/sage/plot/point.py index 7d9dad47c61..9c09914e9e3 100644 --- a/src/sage/plot/point.py +++ b/src/sage/plot/point.py @@ -7,6 +7,7 @@ sage: P = E(0,0) sage: def get_points(n): return sum([point(list(i*P)[:2], size=3) for i in range(-n,n) if i != 0 and (i*P)[0] < 3]) sage: sum([get_points(15*n).plot3d(z=n) for n in range(1,10)]) + Graphics3d Object """ #***************************************************************************** @@ -62,6 +63,7 @@ class Point(GraphicPrimitive_xydata): We test creating a point:: sage: point((3,3)) + Graphics object consisting of 1 graphics primitive """ def __init__(self, xdata, ydata, options): """ @@ -258,6 +260,7 @@ def _render_on_subplot(self,subplot): the points are red:: sage: point(((1,1), (2,2), (3,3)), rgbcolor=hue(1), size=30) + Graphics object consisting of 1 graphics primitive """ options = self.options() @@ -302,22 +305,27 @@ def point(points, **kwds): EXAMPLES:: sage: point((1,2)) + Graphics object consisting of 1 graphics primitive :: sage: point((1,2,3)) + Graphics3d Object :: sage: point([(0,0), (1,1)]) + Graphics object consisting of 1 graphics primitive :: sage: point([(0,0,1), (1,1,1)]) + Graphics3d Object Extra options will get passed on to show(), as long as they are valid:: sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True) + Graphics object consisting of 1 graphics primitive sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True) # These are equivalent """ try: @@ -355,16 +363,20 @@ def point2d(points, **options): A purple point from a single tuple or coordinates:: sage: point((0.5, 0.5), rgbcolor=hue(0.75)) + Graphics object consisting of 1 graphics primitive Points with customized markers and edge colors:: sage: r = [(random(), random()) for _ in range(10)] sage: point(r, marker='d', markeredgecolor='red', size=20) + Graphics object consisting of 1 graphics primitive Passing an empty list returns an empty plot:: sage: point([]) + Graphics object consisting of 0 graphics primitives sage: import numpy; point(numpy.array([])) + Graphics object consisting of 0 graphics primitives If you need a 2D point to live in 3-space later, this is possible:: @@ -382,43 +394,52 @@ def point2d(points, **options): Here are some random larger red points, given as a list of tuples:: sage: point(((0.5, 0.5), (1, 2), (0.5, 0.9), (-1, -1)), rgbcolor=hue(1), size=30) + Graphics object consisting of 1 graphics primitive And an example with a legend:: sage: point((0,0), rgbcolor='black', pointsize=40, legend_label='origin') + Graphics object consisting of 1 graphics primitive The legend can be colored:: sage: P = points([(0,0),(1,0)], pointsize=40, legend_label='origin', legend_color='red') sage: P + plot(x^2,(x,0,1), legend_label='plot', legend_color='green') + Graphics object consisting of 2 graphics primitives Extra options will get passed on to show(), as long as they are valid:: sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True) + Graphics object consisting of 1 graphics primitive sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True) # These are equivalent For plotting data, we can use a logarithmic scale, as long as we are sure not to include any nonpositive points in the logarithmic direction:: sage: point([(1,2),(2,4),(3,4),(4,8),(4.5,32)],scale='semilogy',base=2) + Graphics object consisting of 1 graphics primitive Since Sage Version 4.4 (:trac:`8599`), the size of a 2d point can be given by the argument ``size`` instead of ``pointsize``. The argument ``pointsize`` is still supported:: sage: point((3,4), size=100) + Graphics object consisting of 1 graphics primitive :: sage: point((3,4), pointsize=100) + Graphics object consisting of 1 graphics primitive We can plot a single complex number:: sage: point(CC(1+I), pointsize=100) + Graphics object consisting of 1 graphics primitive We can also plot a list of complex numbers:: sage: point([CC(I), CC(I+1), CC(2+2*I)], pointsize=100) + Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import xydata_from_point_list diff --git a/src/sage/plot/polygon.py b/src/sage/plot/polygon.py index 1bb07019762..5a4e29f8007 100644 --- a/src/sage/plot/polygon.py +++ b/src/sage/plot/polygon.py @@ -53,10 +53,12 @@ class Polygon(GraphicPrimitive_xydata): We test creating polygons:: sage: polygon([(0,0), (1,1), (0,1)]) + Graphics object consisting of 1 graphics primitive :: sage: polygon([(0,0,1), (1,1,1), (2,0,1)]) + Graphics3d Object """ def __init__(self, xdata, ydata, options): """ @@ -186,6 +188,7 @@ def plot3d(self, z=0, **kwds): A pentagon:: sage: polygon([(cos(t), sin(t)) for t in srange(0, 2*pi, 2*pi/5)]).plot3d() + Graphics3d Object Showing behavior of the optional parameter z:: @@ -262,11 +265,14 @@ def polygon(points, **options): EXAMPLES:: sage: polygon([(0,0), (1,1), (0,1)]) + Graphics object consisting of 1 graphics primitive sage: polygon([(0,0,1), (1,1,1), (2,0,1)]) + Graphics3d Object Extra options will get passed on to show(), as long as they are valid:: sage: polygon([(0,0), (1,1), (0,1)], axes=False) + Graphics object consisting of 1 graphics primitive sage: polygon([(0,0), (1,1), (0,1)]).show(axes=False) # These are equivalent """ try: @@ -292,66 +298,79 @@ def polygon2d(points, **options): We create a purple-ish polygon:: sage: polygon2d([[1,2], [5,6], [5,0]], rgbcolor=(1,0,1)) + Graphics object consisting of 1 graphics primitive By default, polygons are filled in, but we can make them without a fill as well:: sage: polygon2d([[1,2], [5,6], [5,0]], fill=False) + Graphics object consisting of 1 graphics primitive In either case, the thickness of the border can be controlled:: sage: polygon2d([[1,2], [5,6], [5,0]], fill=False, thickness=4, color='orange') + Graphics object consisting of 1 graphics primitive Some modern art -- a random polygon, with legend:: sage: v = [(randrange(-5,5), randrange(-5,5)) for _ in range(10)] sage: polygon2d(v, legend_label='some form') + Graphics object consisting of 1 graphics primitive A purple hexagon:: sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] sage: polygon2d(L, rgbcolor=(1,0,1)) + Graphics object consisting of 1 graphics primitive A green deltoid:: sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)),2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] sage: polygon2d(L, rgbcolor=(1/8,3/4,1/2)) + Graphics object consisting of 1 graphics primitive A blue hypotrochoid:: sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100),6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] sage: polygon2d(L, rgbcolor=(1/8,1/4,1/2)) + Graphics object consisting of 1 graphics primitive Another one:: sage: n = 4; h = 5; b = 2 sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] sage: polygon2d(L, rgbcolor=(1/8,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A purple epicycloid:: sage: m = 9; b = 1 sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100),m*sin(pi*i/100)-b*sin((m/b)*pi*i/100)] for i in range(200)] sage: polygon2d(L, rgbcolor=(7/8,1/4,3/4)) + Graphics object consisting of 1 graphics primitive A brown astroid:: sage: L = [[cos(pi*i/100)^3,sin(pi*i/100)^3] for i in range(200)] sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) + Graphics object consisting of 1 graphics primitive And, my favorite, a greenish blob:: sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), sin(pi*i/100)*(1+sin(pi*i/50))] for i in range(200)] sage: polygon2d(L, rgbcolor=(1/8, 3/4, 1/2)) + Graphics object consisting of 1 graphics primitive This one is for my wife:: sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)] sage: polygon2d(L, rgbcolor=(1,1/4,1/2)) + Graphics object consisting of 1 graphics primitive One can do the same one with a colored legend label:: sage: polygon2d(L, color='red', legend_label='For you!', legend_color='red') + Graphics object consisting of 1 graphics primitive Polygons have a default aspect ratio of 1.0:: diff --git a/src/sage/plot/primitive.py b/src/sage/plot/primitive.py index a8ece59c546..ac1c7e7acd2 100644 --- a/src/sage/plot/primitive.py +++ b/src/sage/plot/primitive.py @@ -129,9 +129,11 @@ def set_zorder(self, zorder): 2 sage: Q = line([(-2,-4), (3,5)], thickness=4,zorder=1,hue=.5) sage: P+Q # blue line on top + Graphics object consisting of 2 graphics primitives sage: q=Q[0] sage: q.set_zorder(3) sage: P+Q # teal line on top + Graphics object consisting of 2 graphics primitives sage: q.options()['zorder'] 3 """ diff --git a/src/sage/plot/scatter_plot.py b/src/sage/plot/scatter_plot.py index 80c8a2fd233..7a35b16b8ff 100644 --- a/src/sage/plot/scatter_plot.py +++ b/src/sage/plot/scatter_plot.py @@ -121,10 +121,12 @@ def _render_on_subplot(self, subplot): EXAMPLES:: sage: scatter_plot([[0,1],[2,2],[4.3,1.1]], marker='s') + Graphics object consisting of 1 graphics primitive :: sage: scatter_plot([[n,n] for n in range(5)]) + Graphics object consisting of 1 graphics primitive """ from matplotlib.pyplot import scatter options = self.options() @@ -162,10 +164,12 @@ def scatter_plot(datalist, **options): EXAMPLES:: sage: scatter_plot([[0,1],[2,2],[4.3,1.1]], marker='s') + Graphics object consisting of 1 graphics primitive Extra options will get passed on to :meth:`~Graphics.show`, as long as they are valid:: sage: scatter_plot([(0, 0), (1, 1)], markersize=100, facecolor='green', ymax=100) + Graphics object consisting of 1 graphics primitive sage: scatter_plot([(0, 0), (1, 1)], markersize=100, facecolor='green').show(ymax=100) # These are equivalent """ import numpy diff --git a/src/sage/plot/step.py b/src/sage/plot/step.py index 442d8c577dc..27285d073cc 100644 --- a/src/sage/plot/step.py +++ b/src/sage/plot/step.py @@ -39,13 +39,16 @@ def plot_step_function(v, vertical_lines=True, **kwds): We plot the prime counting function:: sage: plot_step_function([(i,prime_pi(i)) for i in range(20)]) + Graphics object consisting of 1 graphics primitive sage: plot_step_function([(i,sin(i)) for i in range(5,20)]) + Graphics object consisting of 1 graphics primitive We pass in many options and get something that looks like "Space Invaders":: sage: v = [(i,sin(i)) for i in range(5,20)] sage: plot_step_function(v, vertical_lines=False, thickness=30, rgbcolor='purple', axes=False) + Graphics object consisting of 14 graphics primitives """ from plot import line # make sorted copy of v (don't change in place, since that would be rude). diff --git a/src/sage/plot/text.py b/src/sage/plot/text.py index cfbf84f6887..89c78590575 100644 --- a/src/sage/plot/text.py +++ b/src/sage/plot/text.py @@ -30,6 +30,7 @@ class Text(GraphicPrimitive): We test creating some text:: sage: text("I like Fibonacci",(3,5)) + Graphics object consisting of 1 graphics primitive """ def __init__(self, string, point, options): """ @@ -155,6 +156,7 @@ def _render_on_subplot(self, subplot): sage: t1 = text("Hello",(1,1), vertical_alignment="top", fontsize=30, rgbcolor='black') sage: t2 = text("World", (1,1), horizontal_alignment="left",fontsize=20, zorder=-1) sage: t1 + t2 # render the sum + Graphics object consisting of 2 graphics primitives """ options = self.options() opts = {} @@ -207,28 +209,34 @@ def text(string, xy, **options): EXAMPLES:: sage: text("Sage is really neat!!",(2,12)) + Graphics object consisting of 1 graphics primitive The same text in larger font and colored red:: sage: text("Sage is really neat!!",(2,12),fontsize=20,rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive Same text but guaranteed to be in the lower left no matter what:: sage: text("Sage is really neat!!",(0,0), axis_coords=True, horizontal_alignment='left') + Graphics object consisting of 1 graphics primitive Same text rotated around the left, bottom corner of the text:: sage: text("Sage is really neat!!",(0,0), rotation=45.0, horizontal_alignment='left', vertical_alignment='bottom') + Graphics object consisting of 1 graphics primitive Same text oriented vertically:: sage: text("Sage is really neat!!",(0,0), rotation="vertical") + Graphics object consisting of 1 graphics primitive You can also align text differently:: sage: t1 = text("Hello",(1,1), vertical_alignment="top") sage: t2 = text("World", (1,0.5), horizontal_alignment="left") sage: t1 + t2 # render the sum + Graphics object consisting of 2 graphics primitives You can save text as part of PDF output:: @@ -245,6 +253,7 @@ def text(string, xy, **options): Extra options will get passed on to show(), as long as they are valid:: sage: text("MATH IS AWESOME", (0, 0), fontsize=40, axes=False) + Graphics object consisting of 1 graphics primitive sage: text("MATH IS AWESOME", (0, 0), fontsize=40).show(axes=False) # These are equivalent """ try: diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py index a28a22de408..80a533d2490 100644 --- a/src/sage/repl/interpreter.py +++ b/src/sage/repl/interpreter.py @@ -288,7 +288,7 @@ def __init__(self, *args, **kwds): sage: shell = interface_shell_embed(maxima) sage: ift = shell.prefilter_manager.transformers[0] sage: ift.temporary_objects - set([]) + set() sage: ift._sage_import_re.findall('sage(a) + maxima(b)') ['a', 'b'] """ @@ -357,7 +357,7 @@ def transform(self, line, continue_prompt): sage: ift.transform(r'sage(a)+4', False) 'sage.misc.all.logstr("""8""")' sage: ift.temporary_objects - set([]) + set() sage: shell = interface_shell_embed(gap) sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, prefilter_manager=shell.prefilter_manager) sage: ift.transform('2+2', False) diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index 9e2f6abce2c..d2e0b57d303 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -254,10 +254,12 @@ cdef class ComplexIntervalFieldElement(sage.structure.element.FieldElement): EXAMPLES:: sage: sum(plot(CIF(RIF(1/k, 1/k), RIF(-k, k))) for k in [1..10]) + Graphics object consisting of 20 graphics primitives Exact and nearly exact points are still visible:: sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1)) + Graphics object consisting of 6 graphics primitives A demonstration that `z \mapsto z^2` acts chaotically on `|z|=1`:: @@ -268,6 +270,7 @@ cdef class ComplexIntervalFieldElement(sage.structure.element.FieldElement): ... g += z.plot(color=(1./(40-i), 0, 1)) ... sage: g + Graphics object consisting of 80 graphics primitives """ from sage.plot.polygon import polygon2d x, y = self.real(), self.imag() diff --git a/src/sage/rings/complex_number.pyx b/src/sage/rings/complex_number.pyx index 71637e64e5a..378b2dc0a3b 100644 --- a/src/sage/rings/complex_number.pyx +++ b/src/sage/rings/complex_number.pyx @@ -1223,11 +1223,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: z = CC(0,1) sage: plot(z) + Graphics object consisting of 1 graphics primitive or the more direct:: sage: z = CC(0,1) sage: z.plot() + Graphics object consisting of 1 graphics primitive """ return sage.plot.point.point2d((self.real(), self.imag()), **kargs) diff --git a/src/sage/rings/finite_rings/finite_field_ext_pari.py b/src/sage/rings/finite_rings/finite_field_ext_pari.py index 8ffed50f16f..0c9f666cd0a 100644 --- a/src/sage/rings/finite_rings/finite_field_ext_pari.py +++ b/src/sage/rings/finite_rings/finite_field_ext_pari.py @@ -82,7 +82,7 @@ class FiniteField_ext_pari(FiniteField_generic): The following is a native Python set:: sage: set(k) - set([0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2]) + {0, a + 1, a + 2, a, 1, 2*a + 1, 2*a + 2, 2*a, 2} And the following is a Sage set:: diff --git a/src/sage/rings/fraction_field_FpT.pyx b/src/sage/rings/fraction_field_FpT.pyx index 9b72b4b2af8..65d63818d16 100644 --- a/src/sage/rings/fraction_field_FpT.pyx +++ b/src/sage/rings/fraction_field_FpT.pyx @@ -408,7 +408,7 @@ cdef class FpTElement(RingElement): sage: hash(K(5)) 5 sage: set([1, t, 1/t, t, t, 1/t, 1+1/t, t/t]) - set([1, 1/t, t, (t + 1)/t]) + {1, 1/t, t, (t + 1)/t} sage: a = (t+1)/(t^2-1); hash(a) == hash((a.numer(),a.denom())) True """ diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 565ac5d49f4..ca49d4d7960 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -1108,7 +1108,10 @@ def dict(self): sage: m2 = 1/2*t0^12*t1^29*t2^46*t3^6 - 1/4*t0^39*t1^5*t2^23*t3^30 + M.O(100) sage: s = m + m2 sage: s.dict() - {(1, 15, 0, 48): 2/3, (15, 21, 28, 5): -1, (12, 29, 46, 6): 1/2, (39, 5, 23, 30): -1/4} + {(1, 15, 0, 48): 2/3, + (12, 29, 46, 6): 1/2, + (15, 21, 28, 5): -1, + (39, 5, 23, 30): -1/4} """ out_dict = {} for j in self._bg_value.coefficients(): @@ -1199,9 +1202,9 @@ def coefficients(self): Multivariate Power Series Ring in s, t over Integer Ring sage: f = 1 + t + s + s*t + R.O(3) sage: f.coefficients() - {s*t: 1, 1: 1, s: 1, t: 1} + {s*t: 1, t: 1, s: 1, 1: 1} sage: (f^2).coefficients() - {t^2: 1, 1: 1, t: 2, s*t: 4, s^2: 1, s: 2} + {t^2: 1, s*t: 4, s^2: 1, t: 2, s: 2, 1: 1} sage: g = f^2 + f - 2; g 3*s + 3*t + s^2 + 5*s*t + t^2 + O(s, t)^3 diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index 6d9c044c670..e4eb18ab4d1 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -2040,8 +2040,8 @@ def residues(self): EXAMPLES:: sage: K.=NumberField(x^2+1) - sage: res = K.ideal(2).residues(); res # random address - xmrange_iter([[0, 1], [0, 1]], at 0xa252144>) + sage: res = K.ideal(2).residues(); res + xmrange_iter([[0, 1], [0, 1]], at 0x...>) sage: list(res) [0, i, 1, i + 1] sage: list(K.ideal(2+i).residues()) @@ -2103,8 +2103,8 @@ def invertible_residues(self, reduce=True): EXAMPLES:: sage: K.=NumberField(x^2+1) - sage: ires = K.ideal(2).invertible_residues(); ires # random address - + sage: ires = K.ideal(2).invertible_residues(); ires + xmrange_iter([[0, 1]], at 0x...>) sage: list(ires) [1, -i] sage: list(K.ideal(2+i).invertible_residues()) diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index d19b3f7f67e..b79cf9f7872 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -212,9 +212,7 @@ def __init__(self, base, polynomial, name, sage: l. = k.extension(x^2 + 3/5) doctest:...: UserWarning: PARI only handles integral absolute polynomials. Computations in this field might trigger PARI errors sage: b - Traceback (most recent call last): - ... - PariError: incorrect type in core2partial (t_FRAC) + ) failed: sage.libs.pari.gen.PariError: incorrect type in core2partial (t_FRAC)> However, if the polynomial is linear, rational coefficients should work:: diff --git a/src/sage/rings/padics/padic_base_generic.py b/src/sage/rings/padics/padic_base_generic.py index 8641a0fe0e8..48ff3ef2418 100644 --- a/src/sage/rings/padics/padic_base_generic.py +++ b/src/sage/rings/padics/padic_base_generic.py @@ -353,8 +353,11 @@ def plot(self, max_points=2500, **args): EXAMPLES:: sage: Zp(3).plot() + Graphics object consisting of 1 graphics primitive sage: Zp(5).plot(max_points=625) + Graphics object consisting of 1 graphics primitive sage: Zp(23).plot(rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive """ if 'pointsize' not in args: args['pointsize'] = 1 diff --git a/src/sage/rings/polynomial/cyclotomic.pyx b/src/sage/rings/polynomial/cyclotomic.pyx index 571c9d253fe..6003d5a9e18 100644 --- a/src/sage/rings/polynomial/cyclotomic.pyx +++ b/src/sage/rings/polynomial/cyclotomic.pyx @@ -63,7 +63,7 @@ def cyclotomic_coeffs(nn, sparse=None): sage: cyclotomic_coeffs(30) [1, 1, 0, -1, -1, -1, 0, 1, 1] sage: cyclotomic_coeffs(10^5) - {0: 1, 10000: -1, 40000: 1, 30000: -1, 20000: 1} + {0: 1, 10000: -1, 20000: 1, 30000: -1, 40000: 1} sage: R = QQ['x'] sage: R(cyclotomic_coeffs(30)) x^8 + x^7 - x^5 - x^4 - x^3 + x + 1 diff --git a/src/sage/rings/polynomial/groebner_fan.py b/src/sage/rings/polynomial/groebner_fan.py index aa6f4431cfc..c70cc91bc88 100644 --- a/src/sage/rings/polynomial/groebner_fan.py +++ b/src/sage/rings/polynomial/groebner_fan.py @@ -1482,7 +1482,13 @@ def _gfan_stats(self): sage: R. = PolynomialRing(QQ) sage: G = R.ideal([y^3 - x^2, y^2 - 13*x]).groebner_fan() sage: G._gfan_stats() - {'Number of reduced Groebner bases': 3, 'Number of variables': 2, 'Maximal number of terms in Groebner basis': 6, 'Minimal total degree of a Groebner basis': 2, 'Maximal total degree of a Groebner basis': 4, 'Maximal number of polynomials in Groebner basis': 3, 'Dimension of homogeneity space': 0} + {'Dimension of homogeneity space': 0, + 'Maximal number of polynomials in Groebner basis': 3, + 'Maximal number of terms in Groebner basis': 6, + 'Maximal total degree of a Groebner basis': 4, + 'Minimal total degree of a Groebner basis': 2, + 'Number of reduced Groebner bases': 3, + 'Number of variables': 2} """ try: return self.__stats diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b46fd54301b..20aeec77dfc 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -389,7 +389,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial_generic): sage: f = (x^3 + y/t^3)^3 + t^2; f y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2 sage: f.dict() - {0: x^9, -6: 3*x^3*y^2, 2: 1, -3: 3*x^6*y, -9: y^3} + {-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1} """ return dict(zip(self.exponents(), self.coefficients())) diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 478bae602b4..605b9f05d4c 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -472,7 +472,7 @@ cdef class MPolynomial(CommutativeRingElement): sage: t,s = R.gens() sage: x,y,z = R.base_ring().gens() sage: (x+y+2*z*s+3*t)._mpoly_dict_recursive(['z','t','s']) - {(1, 0, 1): 2, (0, 1, 0): 3, (0, 0, 0): x + y} + {(0, 0, 0): x + y, (0, 1, 0): 3, (1, 0, 1): 2} TESTS:: diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 29811853111..98ab533e69e 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -937,12 +937,16 @@ def plot(self, singular=singular_default): sage: R. = PolynomialRing(QQ,2) sage: I = R.ideal([y^3 - x^2]) sage: I.plot() # cusp + Graphics object consisting of 1 graphics primitive sage: I = R.ideal([y^2 - x^2 - 1]) sage: I.plot() # hyperbola + Graphics object consisting of 1 graphics primitive sage: I = R.ideal([y^2 + x^2*(1/4) - 1]) sage: I.plot() # ellipse + Graphics object consisting of 1 graphics primitive sage: I = R.ideal([y^2-(x^2-1)*(x-2)]) sage: I.plot() # elliptic curve + Graphics object consisting of 1 graphics primitive Implicit plotting in 3-d:: @@ -3282,7 +3286,13 @@ def __lt__(self, other): We test to make sure that pickling works with the cached Groebner basis:: sage: loads(dumps(I)).__getstate__() - (Monoid of ideals of Multivariate Polynomial Ring in x, y over Finite Field of size 32003, {'_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Finite Field of size 32003, '_cache__groebner_basis': {}, 'groebner_basis': Pickle of the cached method "groebner_basis", 'gens': Pickle of the cached method "gens", '_Ideal_generic__gens': (x^2 + x, y), '_gb_by_ordering': {'degrevlex': [x^2 + x, y]}}) + (Monoid of ideals of Multivariate Polynomial Ring in x, y over Finite Field of size 32003, + {'_Ideal_generic__gens': (x^2 + x, y), + '_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Finite Field of size 32003, + '_cache__groebner_basis': {}, + '_gb_by_ordering': {'degrevlex': [x^2 + x, y]}, + 'gens': Pickle of the cached method "gens", + 'groebner_basis': Pickle of the cached method "groebner_basis"}) """ # first check the type @@ -4303,32 +4313,38 @@ def plot(self, *args, **kwds): sage: R. = PolynomialRing(QQ,2) sage: I = R.ideal([y^3 - x^2]) sage: I.plot() # cusp + Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 - x^2 - 1]) sage: I.plot((x,-3, 3), (y, -2, 2)) # hyperbola + Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 + x^2*(1/4) - 1]) sage: I.plot() # ellipse + Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2-(x^2-1)*(x-2)]) sage: I.plot() # elliptic curve + Graphics object consisting of 1 graphics primitive :: sage: f = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2) sage: I = R.ideal(f) sage: I.plot() # the Singular logo + Graphics object consisting of 1 graphics primitive This used to be trac #5267:: sage: I = R.ideal([-x^2*y+1]) sage: I.plot() + Graphics object consisting of 1 graphics primitive AUTHORS: diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 3b6cbdbe84c..9077b7d8317 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -2889,7 +2889,7 @@ cdef class MPolynomial_libsingular(sage.rings.polynomial.multi_polynomial.MPolyn sage: R. = QQ[] sage: f=2*x*y^3*z^2 + 1/7*x^2 + 2/3 sage: f.dict() - {(1, 3, 2): 2, (0, 0, 0): 2/3, (2, 0, 0): 1/7} + {(0, 0, 0): 2/3, (1, 3, 2): 2, (2, 0, 0): 1/7} """ cdef poly *p cdef ring *r = self._parent_ring diff --git a/src/sage/rings/polynomial/pbori.pyx b/src/sage/rings/polynomial/pbori.pyx index a109209fad1..e1154b4ed14 100644 --- a/src/sage/rings/polynomial/pbori.pyx +++ b/src/sage/rings/polynomial/pbori.pyx @@ -998,7 +998,7 @@ cdef class BooleanPolynomialRing(MPolynomialRing_generic): sage: B. = BooleanPolynomialRing() sage: B.gens_dict() - {'a': a, 'c': c, 'b': b, 'd': d} + {'a': a, 'b': b, 'c': c, 'd': d} """ if self._gens_dict is not None: return self._gens_dict @@ -5114,7 +5114,7 @@ class BooleanPolynomialIdeal(MPolynomialIdeal): sage: R. = BooleanPolynomialRing() sage: I = ideal( [ x*y*z + x*z + y + 1, x+y+z+1 ] ) sage: I.variety() - [{y: 1, z: 0, x: 0}, {y: 1, z: 1, x: 1}] + [{z: 0, y: 1, x: 0}, {z: 1, y: 1, x: 1}] TESTS: @@ -5132,7 +5132,8 @@ class BooleanPolynomialIdeal(MPolynomialIdeal): x1*x2 + x1*x6 + x2*x4 + x2*x5 + x2*x6 + x3*x6 + x4*x6 + x5*x6 + x5] sage: I = R.ideal( polys ) sage: I.variety() - [{x6: 0, x5: 0, x4: 0, x2: 0, x3: 0, x1: 0}, {x6: 1, x5: 0, x4: 0, x2: 1, x3: 1, x1: 1}] + [{x6: 0, x5: 0, x4: 0, x3: 0, x2: 0, x1: 0}, + {x6: 1, x5: 0, x4: 0, x3: 1, x2: 1, x1: 1}] sage: R = PolynomialRing(GF(2), 6, ['x%d'%(i+1) for i in range(6)], order='lex') sage: I = R.ideal( polys ) diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index 9c6e11cb394..67b55368a87 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -707,7 +707,7 @@ cdef class NCPolynomialRing_plural(Ring): sage: H.relations() {z*x: x*z + 2*x, z*y: y*z - 2*y} sage: H.relations(add_commutative=True) - {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y} + {y*x: x*y, z*x: x*z + 2*x, z*y: y*z - 2*y} """ if add_commutative: @@ -2151,7 +2151,7 @@ cdef class NCPolynomial_plural(RingElement): sage: f = (2*x*y^3*z^2 + (7)*x^2 + (3)) sage: f.dict() - {(0, 0, 0): 3, (2, 0, 0): 7, (1, 2, 3): 2} + {(0, 0, 0): 3, (1, 2, 3): 2, (2, 0, 0): 7} """ cdef poly *p cdef ring *r diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index c117f44f29e..cdb713e767a 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -179,7 +179,7 @@ cdef class PolyDict: sage: from sage.rings.polynomial.polydict import PolyDict sage: f = PolyDict({(2,3):2, (1,2):3, (2,1):4}) sage: f.dict() - {(1, 2): 3, (2, 3): 2, (2, 1): 4} + {(1, 2): 3, (2, 1): 4, (2, 3): 2} """ return self.__repn.copy() @@ -1533,7 +1533,7 @@ cdef class ETuple: sage: e = ETuple([1,0,2]) sage: f = ETuple([0,0,1]) sage: e.common_nonzero_positions(f) - set([0, 2]) + {0, 2} sage: e.common_nonzero_positions(f,sort=True) [0, 2] """ diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index d0fd6219c7d..4e9e8c8138b 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -274,8 +274,10 @@ cdef class Polynomial(CommutativeAlgebraElement): sage: x = polygen(GF(389)) sage: plot(x^2 + 1, rgbcolor=(0,0,1)) + Graphics object consisting of 1 graphics primitive sage: x = polygen(QQ) sage: plot(x^2 + 1, rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive """ R = self.base_ring() from sage.plot.all import plot, point, line @@ -2426,7 +2428,7 @@ cdef class Polynomial(CommutativeAlgebraElement): {} sage: f = 7*x^5 + x^2 - 2*x - 3 sage: f._mpoly_dict_recursive() - {(0,): -3, (1,): -2, (5,): 7, (2,): 1} + {(0,): -3, (1,): -2, (2,): 1, (5,): 7} """ if not self: return {} diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index bc12254b22c..561644bd30e 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -118,10 +118,10 @@ def dict(self): sage: f = 5 + w^1997 - w^10000; f 7*w^10000 + w^1997 + 5 sage: d = f.dict(); d - {0: 5, 10000: 7, 1997: 1} + {0: 5, 1997: 1, 10000: 7} sage: d[0] = 10 sage: f.dict() - {0: 5, 10000: 7, 1997: 1} + {0: 5, 1997: 1, 10000: 7} """ return dict(self.__coeffs) diff --git a/src/sage/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py index e4a5f11d34a..70e03c9038d 100644 --- a/src/sage/rings/polynomial/toy_buchberger.py +++ b/src/sage/rings/polynomial/toy_buchberger.py @@ -314,11 +314,11 @@ def update(G,B,h): sage: R. = PolynomialRing(QQ,3) sage: set_verbose(0) sage: update(set(),set(),x*y*z) - (set([x*y*z]), set([])) + ({x*y*z}, set()) sage: G,B = update(set(),set(),x*y*z-1) sage: G,B = update(G,B,x*y^2-1) sage: G,B - (set([x*y*z - 1, x*y^2 - 1]), set([(x*y^2 - 1, x*y*z - 1)])) + ({x*y*z - 1, x*y^2 - 1}, {(x*y^2 - 1, x*y*z - 1)}) """ R = h.parent() @@ -410,7 +410,7 @@ def inter_reduction(Q): sage: from sage.rings.polynomial.toy_buchberger import inter_reduction sage: inter_reduction(set()) - set([]) + set() :: diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py index dc617c48af9..818c7e5263b 100644 --- a/src/sage/rings/polynomial/toy_d_basis.py +++ b/src/sage/rings/polynomial/toy_d_basis.py @@ -316,8 +316,10 @@ def update(G,B,h): sage: B = set([]) sage: h = x^2*y - x^2 + y - 3 sage: update(G,B,h) - (set([3*x^2 + 7, 2*y + 1, x^2*y - x^2 + y - 3, x^3 - y^2 + 7*x - y + 1]), - set([(x^2*y - x^2 + y - 3, x^3 - y^2 + 7*x - y + 1), (x^2*y - x^2 + y - 3, 3*x^2 + 7), (x^2*y - x^2 + y - 3, 2*y + 1)])) + ({2*y + 1, 3*x^2 + 7, x^2*y - x^2 + y - 3, x^3 - y^2 + 7*x - y + 1}, + {(x^2*y - x^2 + y - 3, 2*y + 1), + (x^2*y - x^2 + y - 3, 3*x^2 + 7), + (x^2*y - x^2 + y - 3, x^3 - y^2 + 7*x - y + 1)}) """ R = h.parent() LCM = R.monomial_lcm diff --git a/src/sage/rings/semirings/non_negative_integer_semiring.py b/src/sage/rings/semirings/non_negative_integer_semiring.py index 131d63dc1e8..3a3b19e200f 100644 --- a/src/sage/rings/semirings/non_negative_integer_semiring.py +++ b/src/sage/rings/semirings/non_negative_integer_semiring.py @@ -41,6 +41,7 @@ class NonNegativeIntegerSemiring(NonNegativeIntegers): sage: G Looped multi-digraph on 9 vertices sage: G.plot() + Graphics object consisting of 48 graphics primitives This is the Hasse diagram of the divisibility order on ``NN``. diff --git a/src/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py b/src/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py index 7b743f98931..80919a1a99e 100644 --- a/src/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py +++ b/src/sage/rings/universal_cyclotomic_field/universal_cyclotomic_field.py @@ -935,7 +935,7 @@ def zumbroich_basis_indices(self, n): sage: UCF = UniversalCyclotomicField() sage: UCF.zumbroich_basis_indices(8) - set([(8, 1), (8, 3), (8, 0), (8, 2)]) + {(8, 1), (8, 3), (8, 0), (8, 2)} """ return ZumbroichBasisIndices().indices(n) @@ -957,10 +957,10 @@ def zumbroich_basis(self,n): sage: UCF = UniversalCyclotomicField() sage: UCF.zumbroich_basis(8) - set([E(8)^3, 1, E(4), E(8)]) + {E(8)^3, E(4), E(8), 1} sage: UCF.zumbroich_basis(9) - set([E(9)^2, E(3)^2, E(9)^5, E(9)^4, E(3), E(9)^7]) + {E(9)^5, E(9)^4, E(3)^2, E(3), E(9)^7, E(9)^2} """ return set(self.gen(n,k) for n,k in self.zumbroich_basis_indices(n)) @@ -2047,11 +2047,11 @@ def indices(self, n, m=1): sage: from sage.rings.universal_cyclotomic_field.universal_cyclotomic_field import ZumbroichBasisIndices sage: ZumbroichBasisIndices().indices(6) - set([(6, 4), (6, 2)]) + {(6, 4), (6, 2)} sage: ZumbroichBasisIndices().indices(12) - set([(12, 7), (12, 4), (12, 11), (12, 8)]) + {(12, 7), (12, 4), (12, 11), (12, 8)} sage: ZumbroichBasisIndices().indices(24) - set([(24, 19), (24, 8), (24, 17), (24, 16), (24, 14), (24, 1), (24, 22), (24, 11)]) + {(24, 19), (24, 8), (24, 17), (24, 16), (24, 14), (24, 1), (24, 22), (24, 11)} """ if not n%m == 0: raise ValueError('%s does not divide %s.'%(m,n)) diff --git a/src/sage/sandpiles/sandpile.py b/src/sage/sandpiles/sandpile.py index 4d410d4856c..e612c9eeac9 100644 --- a/src/sage/sandpiles/sandpile.py +++ b/src/sage/sandpiles/sandpile.py @@ -2284,7 +2284,9 @@ def __setitem__(self, key, item): sage: c.equivalent_recurrent() {1: 1, 2: 1} sage: c.__dict__ - {'_sandpile': Digraph on 3 vertices, '_equivalent_recurrent': [{1: 1, 2: 1}, {1: 2, 2: 1}], '_vertices': [1, 2]} + {'_equivalent_recurrent': [{1: 1, 2: 1}, {1: 2, 2: 1}], + '_sandpile': Digraph on 3 vertices, + '_vertices': [1, 2]} NOTES: @@ -4700,7 +4702,19 @@ def grid_sandpile(m,n): sage: G = grid_sandpile(3,4) sage: G.dict() - {(1, 2): {(1, 1): 1, (1, 3): 1, 'sink': 1, (2, 2): 1}, (3, 2): {(3, 3): 1, (3, 1): 1, 'sink': 1, (2, 2): 1}, (1, 3): {(1, 2): 1, (2, 3): 1, 'sink': 1, (1, 4): 1}, (3, 3): {(2, 3): 1, (3, 2): 1, (3, 4): 1, 'sink': 1}, (3, 1): {(3, 2): 1, 'sink': 2, (2, 1): 1}, (1, 4): {(1, 3): 1, (2, 4): 1, 'sink': 2}, (2, 4): {(2, 3): 1, (3, 4): 1, 'sink': 1, (1, 4): 1}, (2, 3): {(3, 3): 1, (1, 3): 1, (2, 4): 1, (2, 2): 1}, (2, 1): {(1, 1): 1, (3, 1): 1, 'sink': 1, (2, 2): 1}, (2, 2): {(1, 2): 1, (3, 2): 1, (2, 3): 1, (2, 1): 1}, (3, 4): {(2, 4): 1, (3, 3): 1, 'sink': 2}, (1, 1): {(1, 2): 1, 'sink': 2, (2, 1): 1}, 'sink': {}} + {'sink': {}, + (1, 1): {'sink': 2, (1, 2): 1, (2, 1): 1}, + (1, 2): {'sink': 1, (1, 1): 1, (1, 3): 1, (2, 2): 1}, + (1, 3): {'sink': 1, (1, 2): 1, (1, 4): 1, (2, 3): 1}, + (1, 4): {'sink': 2, (1, 3): 1, (2, 4): 1}, + (2, 1): {'sink': 1, (1, 1): 1, (2, 2): 1, (3, 1): 1}, + (2, 2): {(1, 2): 1, (2, 1): 1, (2, 3): 1, (3, 2): 1}, + (2, 3): {(1, 3): 1, (2, 2): 1, (2, 4): 1, (3, 3): 1}, + (2, 4): {'sink': 1, (1, 4): 1, (2, 3): 1, (3, 4): 1}, + (3, 1): {'sink': 2, (2, 1): 1, (3, 2): 1}, + (3, 2): {'sink': 1, (2, 2): 1, (3, 1): 1, (3, 3): 1}, + (3, 3): {'sink': 1, (2, 3): 1, (3, 2): 1, (3, 4): 1}, + (3, 4): {'sink': 2, (2, 4): 1, (3, 3): 1}} sage: G.group_order() 4140081 sage: G.invariant_factors() @@ -4792,7 +4806,29 @@ def aztec_sandpile(n): EXAMPLES:: sage: aztec_sandpile(2) - {'sink': {(3/2, 1/2): 2, (-1/2, -3/2): 2, (-3/2, 1/2): 2, (1/2, 3/2): 2, (1/2, -3/2): 2, (-3/2, -1/2): 2, (-1/2, 3/2): 2, (3/2, -1/2): 2}, (1/2, 3/2): {(-1/2, 3/2): 1, (1/2, 1/2): 1, 'sink': 2}, (1/2, 1/2): {(1/2, -1/2): 1, (3/2, 1/2): 1, (1/2, 3/2): 1, (-1/2, 1/2): 1}, (-3/2, 1/2): {(-3/2, -1/2): 1, 'sink': 2, (-1/2, 1/2): 1}, (-1/2, -1/2): {(-3/2, -1/2): 1, (1/2, -1/2): 1, (-1/2, -3/2): 1, (-1/2, 1/2): 1}, (-1/2, 1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, (-1/2, 3/2): 1, (1/2, 1/2): 1}, (-3/2, -1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, 'sink': 2}, (3/2, 1/2): {(1/2, 1/2): 1, (3/2, -1/2): 1, 'sink': 2}, (-1/2, 3/2): {(1/2, 3/2): 1, 'sink': 2, (-1/2, 1/2): 1}, (1/2, -3/2): {(1/2, -1/2): 1, (-1/2, -3/2): 1, 'sink': 2}, (3/2, -1/2): {(3/2, 1/2): 1, (1/2, -1/2): 1, 'sink': 2}, (1/2, -1/2): {(1/2, -3/2): 1, (-1/2, -1/2): 1, (1/2, 1/2): 1, (3/2, -1/2): 1}, (-1/2, -3/2): {(-1/2, -1/2): 1, 'sink': 2, (1/2, -3/2): 1}} + {'sink': {(-3/2, -1/2): 2, + (-3/2, 1/2): 2, + (-1/2, -3/2): 2, + (-1/2, 3/2): 2, + (1/2, -3/2): 2, + (1/2, 3/2): 2, + (3/2, -1/2): 2, + (3/2, 1/2): 2}, + (-3/2, -1/2): {'sink': 2, (-3/2, 1/2): 1, (-1/2, -1/2): 1}, + (-3/2, 1/2): {'sink': 2, (-3/2, -1/2): 1, (-1/2, 1/2): 1}, + (-1/2, -3/2): {'sink': 2, (-1/2, -1/2): 1, (1/2, -3/2): 1}, + (-1/2, -1/2): {(-3/2, -1/2): 1, + (-1/2, -3/2): 1, + (-1/2, 1/2): 1, + (1/2, -1/2): 1}, + (-1/2, 1/2): {(-3/2, 1/2): 1, (-1/2, -1/2): 1, (-1/2, 3/2): 1, (1/2, 1/2): 1}, + (-1/2, 3/2): {'sink': 2, (-1/2, 1/2): 1, (1/2, 3/2): 1}, + (1/2, -3/2): {'sink': 2, (-1/2, -3/2): 1, (1/2, -1/2): 1}, + (1/2, -1/2): {(-1/2, -1/2): 1, (1/2, -3/2): 1, (1/2, 1/2): 1, (3/2, -1/2): 1}, + (1/2, 1/2): {(-1/2, 1/2): 1, (1/2, -1/2): 1, (1/2, 3/2): 1, (3/2, 1/2): 1}, + (1/2, 3/2): {'sink': 2, (-1/2, 3/2): 1, (1/2, 1/2): 1}, + (3/2, -1/2): {'sink': 2, (1/2, -1/2): 1, (3/2, 1/2): 1}, + (3/2, 1/2): {'sink': 2, (1/2, 1/2): 1, (3/2, -1/2): 1}} sage: Sandpile(aztec_sandpile(2),'sink').group_order() 4542720 @@ -4999,7 +5035,14 @@ def glue_graphs(g,h,glue_g,glue_h): sage: glue_y = {0: 1, 1: 2, 3: 1} sage: z = glue_graphs(x,y,glue_x,glue_y) sage: z - {0: {}, 'y2': {'y1': 2}, 'y1': {0: 2}, 'x2': {'x0': 1, 'x1': 1}, 'x3': {'x2': 1, 'x0': 1, 'x1': 1}, 'y3': {0: 1, 'y2': 1}, 'x1': {'x0': 1}, 'x0': {0: 1, 'x3': 2, 'y3': 1, 'x1': 1, 'y1': 2}} + {0: {}, + 'x0': {0: 1, 'x1': 1, 'x3': 2, 'y1': 2, 'y3': 1}, + 'x1': {'x0': 1}, + 'x2': {'x0': 1, 'x1': 1}, + 'x3': {'x0': 1, 'x1': 1, 'x2': 1}, + 'y1': {0: 2}, + 'y2': {'y1': 2}, + 'y3': {0: 1, 'y2': 1}} sage: S = Sandpile(z,0) sage: S.h_vector() [1, 6, 17, 31, 41, 41, 31, 17, 6, 1] diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 7bbdd3f28c4..c0af421b5ff 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -268,7 +268,7 @@ def cm_orders(h, proof=None): sage: len(v) 29 sage: set([hilbert_class_polynomial(D*f^2).degree() for D,f in v]) - set([2]) + {2} Any degree up to 100 is implemented, but may be prohibitively slow:: diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 94dcde76c9d..71b4cc0e554 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -2492,16 +2492,21 @@ def plot(self, xmin=None, xmax=None, components='both', **args): sage: E = EllipticCurve([0,-1]) sage: plot(E, rgbcolor=hue(0.7)) + Graphics object consisting of 1 graphics primitive sage: E = EllipticCurve('37a') sage: plot(E) + Graphics object consisting of 2 graphics primitives sage: plot(E, xmin=25,xmax=26) + Graphics object consisting of 2 graphics primitives With #12766 we added the components keyword:: sage: E.real_components() 2 sage: E.plot(components='bounded') + Graphics object consisting of 1 graphics primitive sage: E.plot(components='unbounded') + Graphics object consisting of 1 graphics primitive If there is only one component then specifying components='bounded' raises a ValueError:: diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 33fc8023302..c3294bcd1e8 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -624,6 +624,7 @@ def plot(self, **args): sage: E = EllipticCurve('389a') sage: P = E([-1,1]) sage: P.plot(pointsize=30, rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive """ if self.is_zero(): return plot.text("$\\infty$", (-3, 3), **args) diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 8987c7512de..8c2357c5756 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -4517,6 +4517,7 @@ def isogeny_graph(self, order=None): 7 Elliptic Curve defined by y^2 + x*y = x^3 - 7930*x - 296725 over Rational Field 8 Elliptic Curve defined by y^2 + x*y = x^3 - 130000*x - 18051943 over Rational Field sage: G.plot(edge_labels=True) + Graphics object consisting of 23 graphics primitives """ return self.isogeny_class(order=order).graph() diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index ed00c1716bc..25437584155 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -2523,7 +2523,9 @@ def plot(self, *args, **kwds): EXAMPLES:: sage: heegner_points(389,-7,5).plot(pointsize=50, rgbcolor='red') + Graphics object consisting of 12 graphics primitives sage: heegner_points(53,-7,15).plot(pointsize=50, rgbcolor='purple') + Graphics object consisting of 48 graphics primitives """ return sum(z.plot(*args, **kwds) for z in self) @@ -2855,6 +2857,7 @@ def plot(self, **kwds): EXAMPLES:: sage: heegner_point(389,-7,1).plot(pointsize=50) + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import point return point(CDF(self.tau()), **kwds) @@ -4110,6 +4113,7 @@ def plot(self, prec=53, *args, **kwds): sage: E = EllipticCurve('37a'); P = E.heegner_point(-11).kolyvagin_point() sage: P.plot(prec=30, pointsize=50, rgbcolor='red') + E.plot() + Graphics object consisting of 3 graphics primitives """ if self.conductor() != 1: raise NotImplementedError diff --git a/src/sage/schemes/elliptic_curves/lseries_ell.py b/src/sage/schemes/elliptic_curves/lseries_ell.py index 02b13587f5d..09afaebf817 100644 --- a/src/sage/schemes/elliptic_curves/lseries_ell.py +++ b/src/sage/schemes/elliptic_curves/lseries_ell.py @@ -245,6 +245,7 @@ def zeros(self, n): sage: a = E.lseries().zeros(20) # long time sage: point([(1,x) for x in a]) # graph (long time) + Graphics object consisting of 1 graphics primitive AUTHOR: -- Uses Rubinstein's L-functions calculator. diff --git a/src/sage/schemes/elliptic_curves/period_lattice_region.pyx b/src/sage/schemes/elliptic_curves/period_lattice_region.pyx index 606622ad0ac..7ff2c91e60b 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice_region.pyx +++ b/src/sage/schemes/elliptic_curves/period_lattice_region.pyx @@ -67,10 +67,12 @@ cdef class PeriodicRegion: sage: from sage.schemes.elliptic_curves.period_lattice_region import PeriodicRegion sage: S = PeriodicRegion(CDF(2), CDF(2*I), np.zeros((4, 4))) sage: S.plot() + Graphics object consisting of 1 graphics primitive sage: data = np.zeros((4, 4)) sage: data[1,1] = True sage: S = PeriodicRegion(CDF(2), CDF(2*I+1), data) sage: S.plot() + Graphics object consisting of 5 graphics primitives """ if data.dtype is not np.int8: data = data.astype(np.int8) @@ -262,13 +264,16 @@ cdef class PeriodicRegion: sage: data[1,1] = True sage: S = PeriodicRegion(CDF(1), CDF(I + 1/2), data) sage: S.plot() + Graphics object consisting of 5 graphics primitives sage: S.expand().plot() + Graphics object consisting of 13 graphics primitives sage: S.expand().data array([[1, 1, 1, 0], [1, 1, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=int8) sage: S.expand(corners=False).plot() + Graphics object consisting of 13 graphics primitives sage: S.expand(corners=False).data array([[0, 1, 0, 0], [1, 1, 1, 0], @@ -307,7 +312,9 @@ cdef class PeriodicRegion: sage: data[1:4,1:4] = True sage: S = PeriodicRegion(CDF(1), CDF(I + 1/2), data) sage: S.plot() + Graphics object consisting of 13 graphics primitives sage: S.contract().plot() + Graphics object consisting of 5 graphics primitives sage: S.contract().data.sum() 1 sage: S.contract().contract().is_empty() @@ -382,8 +389,11 @@ cdef class PeriodicRegion: sage: data[3, 3] = True sage: S = PeriodicRegion(CDF(1), CDF(I + 1/2), data) sage: S.plot() + Graphics object consisting of 29 graphics primitives sage: (S / 2).plot() + Graphics object consisting of 57 graphics primitives sage: (S / 3).plot() + Graphics object consisting of 109 graphics primitives sage: (S / 2 / 3) == (S / 6) == (S / 3 / 2) True @@ -614,6 +624,7 @@ cdef class PeriodicRegion: sage: S.innermost_point() 0.375 + 0.25*I sage: S.plot() + point(S.innermost_point()) + Graphics object consisting of 24 graphics primitives """ if self.is_empty(): from sage.categories.sets_cat import EmptySetError @@ -640,6 +651,7 @@ cdef class PeriodicRegion: sage: data[3, 3] = True sage: S = PeriodicRegion(CDF(1), CDF(I + 1/2), data) sage: plot(S) + plot(S.expand(), rgbcolor=(1, 0, 1), thickness=2) + Graphics object consisting of 46 graphics primitives """ from sage.all import line dw1, dw2 = self.ds() diff --git a/src/sage/schemes/generic/homset.py b/src/sage/schemes/generic/homset.py index 86547dd06db..c9904b91217 100644 --- a/src/sage/schemes/generic/homset.py +++ b/src/sage/schemes/generic/homset.py @@ -154,9 +154,10 @@ def create_key_and_extra_args(self, X, Y, category=None, base=ZZ, sage: key (..., ..., Category of schemes over Integer Ring, False) sage: extra - {'Y': Affine Space of dimension 2 over Rational Field, - 'X': Affine Space of dimension 3 over Rational Field, - 'base_ring': Integer Ring, 'check': False} + {'X': Affine Space of dimension 3 over Rational Field, + 'Y': Affine Space of dimension 2 over Rational Field, + 'base_ring': Integer Ring, + 'check': False} """ if is_CommutativeRing(X): X = AffineScheme(X) diff --git a/src/sage/schemes/hyperelliptic_curves/invariants.py b/src/sage/schemes/hyperelliptic_curves/invariants.py index 17ff90b9791..8174bcf778b 100644 --- a/src/sage/schemes/hyperelliptic_curves/invariants.py +++ b/src/sage/schemes/hyperelliptic_curves/invariants.py @@ -144,15 +144,42 @@ def ubs(f): sage: from sage.schemes.hyperelliptic_curves.invariants import ubs sage: x = QQ['x'].0 sage: ubs(x^6 + 1) - {'A': 2, 'C': -2/9, 'B': 2/3, 'D': 0, 'f': x^6 + h^6, 'i': 2*x^2*h^2, 'Delta': -2/3*x^2*h^2, 'y1': 0, 'y3': 0, 'y2': 0} + {'A': 2, + 'B': 2/3, + 'C': -2/9, + 'D': 0, + 'Delta': -2/3*x^2*h^2, + 'f': x^6 + h^6, + 'i': 2*x^2*h^2, + 'y1': 0, + 'y2': 0, + 'y3': 0} sage: R. = QQ[] sage: ubs(u^6 + v^6) - {'A': 2, 'C': -2/9, 'B': 2/3, 'D': 0, 'f': u^6 + v^6, 'i': 2*u^2*v^2, 'Delta': -2/3*u^2*v^2, 'y1': 0, 'y3': 0, 'y2': 0} + {'A': 2, + 'B': 2/3, + 'C': -2/9, + 'D': 0, + 'Delta': -2/3*u^2*v^2, + 'f': u^6 + v^6, + 'i': 2*u^2*v^2, + 'y1': 0, + 'y2': 0, + 'y3': 0} sage: R. = GF(31)[] sage: ubs(t^6 + 2*t^5 + t^2 + 3*t + 1) - {'A': 0, 'C': -15, 'B': -12, 'D': -15, 'f': t^6 + 2*t^5*h + t^2*h^4 + 3*t*h^5 + h^6, 'i': -4*t^4 + 10*t^3*h + 2*t^2*h^2 - 9*t*h^3 - 7*h^4, 'Delta': -10*t^4 + 12*t^3*h + 7*t^2*h^2 - 5*t*h^3 + 2*h^4, 'y1': 4*t^2 - 10*t*h - 13*h^2, 'y3': 4*t^2 - 4*t*h - 9*h^2, 'y2': 6*t^2 - 4*t*h + 2*h^2} + {'A': 0, + 'B': -12, + 'C': -15, + 'D': -15, + 'Delta': -10*t^4 + 12*t^3*h + 7*t^2*h^2 - 5*t*h^3 + 2*h^4, + 'f': t^6 + 2*t^5*h + t^2*h^4 + 3*t*h^5 + h^6, + 'i': -4*t^4 + 10*t^3*h + 2*t^2*h^2 - 9*t*h^3 - 7*h^4, + 'y1': 4*t^2 - 10*t*h - 13*h^2, + 'y2': 6*t^2 - 4*t*h + 2*h^2, + 'y3': 4*t^2 - 4*t*h - 9*h^2} """ ub = Ueberschiebung if f.parent().ngens() == 1: diff --git a/src/sage/schemes/plane_curves/affine_curve.py b/src/sage/schemes/plane_curves/affine_curve.py index 40e68c09e71..acc13a6354c 100644 --- a/src/sage/schemes/plane_curves/affine_curve.py +++ b/src/sage/schemes/plane_curves/affine_curve.py @@ -207,6 +207,7 @@ def plot(self, *args, **kwds): sage: R. = QQ[] sage: C = Curve(x^3 - y^2) sage: C.plot() + Graphics object consisting of 1 graphics primitive A 5-nodal curve of degree 11. This example also illustrates some of the optional arguments:: @@ -214,12 +215,14 @@ def plot(self, *args, **kwds): sage: R. = ZZ[] sage: C = Curve(32*x^2 - 2097152*y^11 + 1441792*y^9 - 360448*y^7 + 39424*y^5 - 1760*y^3 + 22*y - 1) sage: C.plot((x, -1, 1), (y, -1, 1), plot_points=400) + Graphics object consisting of 1 graphics primitive A line over `\mathbf{RR}`:: sage: R. = RR[] sage: C = Curve(R(y - sqrt(2)*x)) sage: C.plot() + Graphics object consisting of 1 graphics primitive """ I = self.defining_ideal() return I.plot(*args, **kwds) diff --git a/src/sage/schemes/plane_curves/projective_curve.py b/src/sage/schemes/plane_curves/projective_curve.py index fc8110b39b9..52bf99cb7b7 100644 --- a/src/sage/schemes/plane_curves/projective_curve.py +++ b/src/sage/schemes/plane_curves/projective_curve.py @@ -225,19 +225,25 @@ def plot(self, *args, **kwds): sage: R. = QQ[] sage: C = Curve(x^3 - y^2*z) sage: C.plot() + Graphics object consisting of 1 graphics primitive The other affine patches of the same curve:: sage: C.plot(patch=0) + Graphics object consisting of 1 graphics primitive sage: C.plot(patch=1) + Graphics object consisting of 1 graphics primitive An elliptic curve:: sage: E = EllipticCurve('101a') sage: C = Curve(E) sage: C.plot() + Graphics object consisting of 1 graphics primitive sage: C.plot(patch=0) + Graphics object consisting of 1 graphics primitive sage: C.plot(patch=1) + Graphics object consisting of 1 graphics primitive A hyperelliptic curve:: @@ -245,8 +251,11 @@ def plot(self, *args, **kwds): sage: f = 4*x^5 - 30*x^3 + 45*x - 22 sage: C = HyperellipticCurve(f) sage: C.plot() + Graphics object consisting of 1 graphics primitive sage: C.plot(patch=0) + Graphics object consisting of 1 graphics primitive sage: C.plot(patch=1) + Graphics object consisting of 1 graphics primitive """ # if user hasn't specified a favourite affine patch, take the # one avoiding "infinity", i.e. the one corresponding to the diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index ad97fa89c9c..b8137b521dc 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1021,8 +1021,14 @@ def rational_points_dictionary(self): sage: P1=ProjectiveSpace(GF(7),1,'x') sage: P1.rational_points_dictionary() - {(1 : 0): 7, (0 : 1): 0, (1 : 1): 1, (2 : 1): 2, (3 : 1): 3, (4 : 1): 4, - (5 : 1): 5, (6 : 1): 6} + {(0 : 1): 0, + (1 : 0): 7, + (1 : 1): 1, + (2 : 1): 2, + (3 : 1): 3, + (4 : 1): 4, + (5 : 1): 5, + (6 : 1): 6} """ n = self.dimension_relative() R = self.base_ring() diff --git a/src/sage/schemes/toric/morphism.py b/src/sage/schemes/toric/morphism.py index 15695d9f64b..84f8a5b61ba 100644 --- a/src/sage/schemes/toric/morphism.py +++ b/src/sage/schemes/toric/morphism.py @@ -646,7 +646,7 @@ def _reverse_ray_map(self): sage: P1 = P2_112.orbit_closure(Cone([(1,0)])) sage: f = P1.embedding_morphism() sage: f._ray_map - {N(0, 1): (1), N(1, 0): (0), N(-1, -2): (-2)} + {N(-1, -2): (-2), N(0, 1): (1), N(1, 0): (0)} sage: f._reverse_ray_map() {N(-2): 2, N(1): 1} """ @@ -1946,7 +1946,7 @@ def _image_ray_multiplicity(self, fiber_ray): N(1, -3) (9, 2) N(-1, 2) (11, 1) sage: f._ray_index_map - {N(0, 1): 5, N(-3, 4): 10, N(-1, 2): 11, N(1, 0): 4, N(2, -6): 9} + {N(-3, 4): 10, N(-1, 2): 11, N(0, 1): 5, N(1, 0): 4, N(2, -6): 9} """ try: image_ray_index = self._ray_index_map[fiber_ray] diff --git a/src/sage/schemes/toric/variety.py b/src/sage/schemes/toric/variety.py index ab86ed62910..32b9810c9c2 100644 --- a/src/sage/schemes/toric/variety.py +++ b/src/sage/schemes/toric/variety.py @@ -1549,6 +1549,7 @@ def plot(self, **options): sage: X = toric_varieties.Cube_deformation(4) sage: X.plot() + Graphics3d Object """ if "ray_label" not in options: gens = self.coordinate_ring().gens() diff --git a/src/sage/schemes/toric/weierstrass.py b/src/sage/schemes/toric/weierstrass.py index bf99858f27b..0b1fa66da80 100644 --- a/src/sage/schemes/toric/weierstrass.py +++ b/src/sage/schemes/toric/weierstrass.py @@ -275,9 +275,16 @@ def Newton_polytope_vars_coeffs(polynomial, variables): sage: p = (a30*x^3 + a21*x^2*y + a12*x*y^2 + a03*y^3 + a20*x^2*z + ....: a11*x*y*z + a02*y^2*z + a10*x*z^2 + a01*y*z^2 + a00*z^3) sage: p_data = Newton_polytope_vars_coeffs(p, [x,y,z]); p_data - {(2, 1, 0): a21, (0, 3, 0): a03, (1, 0, 2): a10, (0, 2, 1): a02, - (0, 1, 2): a01, (3, 0, 0): a30, (2, 0, 1): a20, (1, 2, 0): a12, - (1, 1, 1): a11, (0, 0, 3): a00} + {(0, 0, 3): a00, + (0, 1, 2): a01, + (0, 2, 1): a02, + (0, 3, 0): a03, + (1, 0, 2): a10, + (1, 1, 1): a11, + (1, 2, 0): a12, + (2, 0, 1): a20, + (2, 1, 0): a21, + (3, 0, 0): a30} sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: polytope = LatticePolytope_PPL(p_data.keys()); polytope diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index d289cc69e86..93f395bd537 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -725,7 +725,7 @@ def __getstate__(self): sage: from sage.sets.family import FiniteFamily sage: f = FiniteFamily({3: 'a'}) sage: f.__getstate__() - {'keys': None, 'dictionary': {3: 'a'}} + {'dictionary': {3: 'a'}, 'keys': None} """ return {'dictionary': self._dictionary, 'keys': self._keys} diff --git a/src/sage/sets/finite_set_map_cy.pyx b/src/sage/sets/finite_set_map_cy.pyx index 7b59d7ea0d2..705bddf9025 100644 --- a/src/sage/sets/finite_set_map_cy.pyx +++ b/src/sage/sets/finite_set_map_cy.pyx @@ -79,7 +79,7 @@ cpdef fibers(f, domain): sage: fibers(lambda x: 1, []) {} sage: fibers(lambda x: x^2, [-1, 2, -3, 1, 3, 4]) - {16: {4}, 1: {1, -1}, 4: {2}, 9: {3, -3}} + {1: {1, -1}, 4: {2}, 9: {3, -3}, 16: {4}} sage: fibers(lambda x: 1, [-1, 2, -3, 1, 3, 4]) {1: {1, 2, 3, 4, -3, -1}} sage: fibers(lambda x: 1, [1,1,1]) @@ -108,7 +108,7 @@ def fibers_args(f, domain, *args, **opts): sage: from sage.sets.finite_set_map_cy import fibers_args sage: fibers_args(operator.pow, [-1, 2, -3, 1, 3, 4], 2) - {16: {4}, 1: {1, -1}, 4: {2}, 9: {3, -3}} + {1: {1, -1}, 4: {2}, 9: {3, -3}, 16: {4}} """ return fibers(lambda x: f(x, *args, **opts), domain) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index a4f85a03098..01b156be2b3 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -780,7 +780,7 @@ def set(self): sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} sage: X.set() - set([0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]) + {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} sage: type(X.set()) sage: type(X) @@ -799,13 +799,13 @@ def frozenset(self): sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} sage: s = X.set(); s - set([0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]) + {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} sage: hash(s) Traceback (most recent call last): ... TypeError: unhashable type: 'set' sage: s = X.frozenset(); s - frozenset([0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]) + frozenset({0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}) sage: hash(s) -1390224788 # 32-bit 561411537695332972 # 64-bit diff --git a/src/sage/stats/distributions/discrete_gaussian_integer.pyx b/src/sage/stats/distributions/discrete_gaussian_integer.pyx index 553eba6a4a3..d844191f891 100644 --- a/src/sage/stats/distributions/discrete_gaussian_integer.pyx +++ b/src/sage/stats/distributions/discrete_gaussian_integer.pyx @@ -268,6 +268,7 @@ cdef class DiscreteGaussianDistributionIntegerSampler(SageObject): sage: D = DiscreteGaussianDistributionIntegerSampler(17.0) sage: S = [D() for _ in range(2^16)] sage: list_plot([(v,S.count(v)) for v in set(S)]) # long time + Graphics object consisting of 1 graphics primitive These generators cache random bits for performance reasons. Hence, resetting the seed of the PRNG might not have the expected outcome. You can flush this cache with diff --git a/src/sage/stats/distributions/discrete_gaussian_lattice.py b/src/sage/stats/distributions/discrete_gaussian_lattice.py index fd81eedaed3..b8fbab0803e 100644 --- a/src/sage/stats/distributions/discrete_gaussian_lattice.py +++ b/src/sage/stats/distributions/discrete_gaussian_lattice.py @@ -131,6 +131,7 @@ class DiscreteGaussianDistributionLatticeSampler(SageObject): sage: S = [D() for _ in range(2^12)] sage: l = [vector(v.list() + [S.count(v)]) for v in set(S)] sage: list_plot3d(l, point_list=True, interploation='nn') + Graphics3d Object REFERENCES: diff --git a/src/sage/stats/hmm/distributions.pyx b/src/sage/stats/hmm/distributions.pyx index eb7fd181af9..93f7bcf6557 100644 --- a/src/sage/stats/hmm/distributions.pyx +++ b/src/sage/stats/hmm/distributions.pyx @@ -134,6 +134,7 @@ cdef class Distribution: sage: P = hmm.GaussianMixtureDistribution([(.2,-10,.5),(.6,1,1),(.2,20,.5)]) sage: P.plot(-10,30) + Graphics object consisting of 1 graphics primitive """ from sage.plot.all import plot return plot(self.prob, *args, **kwds) diff --git a/src/sage/stats/hmm/hmm.pyx b/src/sage/stats/hmm/hmm.pyx index 1bd1a2e95a0..68786ec7da2 100644 --- a/src/sage/stats/hmm/hmm.pyx +++ b/src/sage/stats/hmm/hmm.pyx @@ -136,6 +136,7 @@ cdef class HiddenMarkovModel: sage: G.edges() [(0, 0, 0.3), (0, 2, 0.7), (1, 2, 1.0), (2, 0, 0.5), (2, 1, 0.5)] sage: G.plot() + Graphics object consisting of 11 graphics primitives """ cdef int i, j m = self.transition_matrix() @@ -291,6 +292,7 @@ cdef class DiscreteHiddenMarkovModel(HiddenMarkovModel): sage: m.sample(10) [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] sage: m.graph().plot() + Graphics object consisting of 6 graphics primitives A 3-state model that happens to always outputs 'b':: diff --git a/src/sage/stats/intlist.pyx b/src/sage/stats/intlist.pyx index b62bc5a7ce2..1cdcb919f0b 100644 --- a/src/sage/stats/intlist.pyx +++ b/src/sage/stats/intlist.pyx @@ -514,7 +514,9 @@ cdef class IntList: EXAMPLES:: sage: stats.IntList([3,7,19,-2]).plot() + Graphics object consisting of 1 graphics primitive sage: stats.IntList([3,7,19,-2]).plot(color='red',pointsize=50,points=True) + Graphics object consisting of 1 graphics primitive """ return self.time_series().plot(*args, **kwds) @@ -527,6 +529,7 @@ cdef class IntList: EXAMPLES:: sage: stats.IntList([1..15]).plot_histogram() + Graphics object consisting of 50 graphics primitives """ return self.time_series().plot_histogram(*args, **kwds) diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 4aeb73887c1..19e53a41a56 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -726,8 +726,6 @@ cdef class CoercionModel_cache_maps(CoercionModel): The operator can be any callable:: - set Rational Field Integer Ring at 0xc0b2270> None None - (Rational Field, Rational Field) sage: R. = ZZ['x'] sage: cm.bin_op(x^2-1, x+1, gcd) x + 1 diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx index b8e5b8f621f..696c7ec1824 100644 --- a/src/sage/structure/coerce_dict.pyx +++ b/src/sage/structure/coerce_dict.pyx @@ -306,7 +306,7 @@ cdef class MonoDict: [(-15, 3), ('a', 1), ('ab', 2)] sage: # the following seems to be more consistent sage: set(L.iteritems()) - set([('a', 1), ('ab', 2), (-15, 3)]) + {(-15, 3), ('a', 1), ('ab', 2)} sage: del L[c] sage: sorted(L.iteritems()) [('a', 1), ('ab', 2)] diff --git a/src/sage/structure/coerce_maps.pyx b/src/sage/structure/coerce_maps.pyx index 4598b717a7a..0e2f424f54d 100644 --- a/src/sage/structure/coerce_maps.pyx +++ b/src/sage/structure/coerce_maps.pyx @@ -447,8 +447,8 @@ cdef class CCallableConvertMap_class(Map): Conversion via c call 'any name' map: From: Integer Ring To: Integer Ring - sage: test_CCallableConvertMap(ZZ, None) # random address - Conversion via c call at 0xc339000 map: + sage: test_CCallableConvertMap(ZZ, None) + Conversion via c call at 0x... map: From: Integer Ring To: Integer Ring """ diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 2511476155c..596c49989f9 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -380,7 +380,10 @@ cdef class Element(sage_object.SageObject): sage: R. = QQ[] sage: i = ideal(x^2 - y^2 + 1) sage: i.__getstate__() - (Monoid of ideals of Multivariate Polynomial Ring in x, y over Rational Field, {'_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Rational Field, '_Ideal_generic__gens': (x^2 - y^2 + 1,), '_gb_by_ordering': {}}) + (Monoid of ideals of Multivariate Polynomial Ring in x, y over Rational Field, + {'_Ideal_generic__gens': (x^2 - y^2 + 1,), + '_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Rational Field, + '_gb_by_ordering': {}}) """ return (self._parent, self.__dict__) diff --git a/src/sage/structure/proof/all.py b/src/sage/structure/proof/all.py index b094a501090..9e94a8d8f09 100644 --- a/src/sage/structure/proof/all.py +++ b/src/sage/structure/proof/all.py @@ -137,12 +137,22 @@ def all(t = None): EXAMPLES: sage: proof.all() - {'polynomial': True, 'other': True, 'elliptic_curve': True, 'number_field': True, 'linear_algebra': True, 'arithmetic': True} + {'arithmetic': True, + 'elliptic_curve': True, + 'linear_algebra': True, + 'number_field': True, + 'other': True, + 'polynomial': True} sage: proof.number_field(False) sage: proof.number_field() False sage: proof.all() - {'polynomial': True, 'other': True, 'elliptic_curve': True, 'number_field': False, 'linear_algebra': True, 'arithmetic': True} + {'arithmetic': True, + 'elliptic_curve': True, + 'linear_algebra': True, + 'number_field': False, + 'other': True, + 'polynomial': True} sage: proof.number_field(True) sage: proof.number_field() True diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index a680e9636d4..39b8cd69043 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -6560,6 +6560,7 @@ cdef class Expression(CommutativeRingElement): sage: SR(0.4).arccos() 1.15927948072741 sage: plot(lambda x: SR(x).arccos(), -1,1) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: @@ -6611,6 +6612,7 @@ cdef class Expression(CommutativeRingElement): sage: SR(0.5).arctan() 0.463647609000806 sage: plot(lambda x: SR(x).arctan(), -20,20) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: @@ -6882,6 +6884,7 @@ cdef class Expression(CommutativeRingElement): sage: maxima('tanh(1.0)') 0.7615941559557649 sage: plot(lambda x: SR(x).tanh(), -1, 1) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: @@ -7161,6 +7164,7 @@ cdef class Expression(CommutativeRingElement): sage: math.log(0.5) -0.6931471805599453 sage: plot(lambda x: SR(x).log(), 0.1,10) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: @@ -7467,6 +7471,7 @@ cdef class Expression(CommutativeRingElement): sage: math.exp(0.5) 1.6487212707001282 sage: plot(lambda x: (SR(x).exp() - SR(-x).exp())/2 - SR(x).sinh(), -1, 1) + Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: @@ -9847,16 +9852,19 @@ cdef class Expression(CommutativeRingElement): This displays a straight line:: sage: sin(2).plot((x,0,3)) + Graphics object consisting of 1 graphics primitive This draws a red oscillatory curve:: sage: sin(x^2).plot((x,0,2*pi), rgbcolor=(1,0,0)) + Graphics object consisting of 1 graphics primitive Another plot using the variable theta:: sage: var('theta') theta sage: (cos(theta) - erf(theta)).plot((theta,-2*pi,2*pi)) + Graphics object consisting of 1 graphics primitive A very thick green plot with a frame:: @@ -9865,6 +9873,7 @@ cdef class Expression(CommutativeRingElement): You can embed 2d plots in 3d space as follows:: sage: plot(sin(x^2), (x,-pi, pi), thickness=2).plot3d(z = 1) + Graphics3d Object A more complicated family:: @@ -9874,6 +9883,7 @@ cdef class Expression(CommutativeRingElement): A plot involving the floor function:: sage: plot(1.0 - x * floor(1/x), (x,0.00001,1.0)) + Graphics object consisting of 1 graphics primitive Sage used to allow symbolic functions with "no arguments"; this no longer works:: @@ -9886,11 +9896,13 @@ cdef class Expression(CommutativeRingElement): You should evaluate the function first:: sage: plot(2*sin(x), -4, 4) + Graphics object consisting of 1 graphics primitive TESTS:: sage: f(x) = x*(1 - x) sage: plot(f,0,1) + Graphics object consisting of 1 graphics primitive """ from sage.symbolic.callable import is_CallableSymbolicExpression from sage.symbolic.ring import is_SymbolicVariable @@ -9953,6 +9965,7 @@ cdef class Expression(CommutativeRingElement): sage: abs((I*10+1)^4) 10201 sage: plot(s) + Graphics object consisting of 1 graphics primitive Check that :trac:`15030` is fixed:: @@ -9960,6 +9973,7 @@ cdef class Expression(CommutativeRingElement): 3.52985761682672 sage: f = function('f', evalf_func=lambda self,x,parent: I*x) sage: plot(abs(f(x)), 0,5) + Graphics object consisting of 1 graphics primitive """ from sage.ext.fast_callable import fast_callable return fast_callable(self, vars=vars, expect_one_var=True) diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index 52716d5e819..8a93b5d58d2 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -1393,6 +1393,7 @@ def arithmetic(self, ex, operator): sage: (x^7)._fast_callable_(etb) ipow(v_0, 7) sage: f(x)=1/pi/x; plot(f,2,3) + Graphics object consisting of 1 graphics primitive """ # This used to convert the operands first. Doing it this way # instead gives a chance to notice powers with an integer diff --git a/src/sage/tests/book_stein_ent.py b/src/sage/tests/book_stein_ent.py index 41d3e10e846..900e7bd13c3 100644 --- a/src/sage/tests/book_stein_ent.py +++ b/src/sage/tests/book_stein_ent.py @@ -48,6 +48,7 @@ sage: prime_pi(3000000) 216816 sage: plot(prime_pi, 1,1000, rgbcolor=(0,0,1)) +Graphics object consisting of 1 graphics primitive sage: P = plot(Li, 2,10000, rgbcolor='purple') sage: Q = plot(prime_pi, 2,10000, rgbcolor='black') sage: R = plot(sqrt(x)*log(x),2,10000,rgbcolor='red') @@ -157,6 +158,7 @@ sage: log(19683.0) / log(3.0) 9.00000000000000 sage: plot(log, 0.1,10, rgbcolor=(0,0,1)) +Graphics object consisting of 1 graphics primitive sage: p = 53 sage: R = Integers(p) sage: a = R.multiplicative_generator() @@ -164,6 +166,7 @@ sage: G = plot(point(v,pointsize=50,rgbcolor=(0,0,1))) sage: H = plot(line(v,rgbcolor=(0.5,0.5,0.5))) sage: G + H +Graphics object consisting of 2 graphics primitives sage: q = 93450983094850938450983409623 sage: q.is_prime() True @@ -512,6 +515,7 @@ Elliptic Curve defined by y^2 = x^3 + x over Finite Field of size 37 sage: E.plot(pointsize=45) +Graphics object consisting of 1 graphics primitive sage: E = EllipticCurve([-5,4]) sage: P = E([1,0]); Q = E([0,2]) sage: P + Q diff --git a/src/sage/tests/french_book/calculus_doctest.py b/src/sage/tests/french_book/calculus_doctest.py index f48b3e521af..59406d3b596 100644 --- a/src/sage/tests/french_book/calculus_doctest.py +++ b/src/sage/tests/french_book/calculus_doctest.py @@ -327,6 +327,7 @@ Sage example in ./calculus.tex, line 914:: sage: plot(u(x), x, 1, 40) + Graphics object consisting of 1 graphics primitive Sage example in ./calculus.tex, line 929:: diff --git a/src/sage/tests/french_book/integration_doctest.py b/src/sage/tests/french_book/integration_doctest.py index 659399b9441..438c267f0fe 100644 --- a/src/sage/tests/french_book/integration_doctest.py +++ b/src/sage/tests/french_book/integration_doctest.py @@ -14,6 +14,7 @@ sage: N(integrate(f, x, 1, 3)) 0.035860294991267694 sage: plot(f, 1, 3, fill='axis') + Graphics object consisting of 2 graphics primitives Sage example in ./integration.tex, line 103:: @@ -175,6 +176,7 @@ Sage example in ./integration.tex, line 801:: sage: plot(f, 0, 100) + Graphics object consisting of 1 graphics primitive Sage example in ./integration.tex, line 838:: diff --git a/src/sage/tests/french_book/mpoly.py b/src/sage/tests/french_book/mpoly.py index 4a32c91b0f5..0220323ba97 100644 --- a/src/sage/tests/french_book/mpoly.py +++ b/src/sage/tests/french_book/mpoly.py @@ -144,8 +144,7 @@ Sage example in ./mpoly.tex, line 401:: sage: set(pt[zz].minpoly() for pt in V[:-1]) - set([x^16 + x^15 + x^14 + x^13 + x^12 + x^11 + x^10 + x^9 + - x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1]) + {x^16 + x^15 + x^14 + x^13 + x^12 + x^11 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1} Sage example in ./mpoly.tex, line 413:: @@ -283,6 +282,7 @@ Sage example in ./mpoly.tex, line 906:: sage: env.change_ring(QQ[x,y]).plot() + Graphics object consisting of 1 graphics primitive Sage example in ./mpoly.tex, line 933:: diff --git a/src/sage/tests/french_book/recequadiff.py b/src/sage/tests/french_book/recequadiff.py index c78d266cc03..6deec70d9e8 100755 --- a/src/sage/tests/french_book/recequadiff.py +++ b/src/sage/tests/french_book/recequadiff.py @@ -123,6 +123,7 @@ Sage example in ./recequadiff.tex, line 396:: sage: plot(solve(ed, y)[0].subs_expr(c == 2).rhs(), x, -3, 3) + Graphics object consisting of 1 graphics primitive Sage example in ./recequadiff.tex, line 408:: @@ -130,6 +131,7 @@ sage: for k in range(1,20,2): ... P += plot(solve(ed, y)[0].subs_expr(c==1+k/4).rhs(), x, -3, 3) sage: P + Graphics object consisting of 11 graphics primitives Sage example in ./recequadiff.tex, line 426:: @@ -139,6 +141,7 @@ ... f = solve(ed,y)[j].subs_expr(c==2+0.25*k).rhs() ... P += plot(f, x, -3, 3) sage: P + Graphics object consisting of 10 graphics primitives Sage example in ./recequadiff.tex, line 472:: @@ -179,6 +182,7 @@ sage: for k in range(-19,19,2): ... P += plot(y(x).subs_expr(c == 1/k), x, 0, 3) sage: P + Graphics object consisting of 19 graphics primitives Sage example in ./recequadiff.tex, line 567:: diff --git a/src/sage_setup/clean.py b/src/sage_setup/clean.py index 780ee475df9..70160c068e3 100644 --- a/src/sage_setup/clean.py +++ b/src/sage_setup/clean.py @@ -41,12 +41,12 @@ def _remove(file_set, module_base, to_remove): sage: files = set(['a/b/c.py', 'a/b/d.py', 'a/b/c.pyx']) sage: _remove(files, 'a.b', ['c.py', 'd.py']) sage: files - set(['a/b/c.pyx']) + {'a/b/c.pyx'} sage: files = set(['a/b/c.py', 'a/b/d.py', 'a/b/c.pyx']) sage: _remove(files, 'a.b.c', ['.py', '.pyx']) sage: files - set(['a/b/d.py']) + {'a/b/d.py'} """ path = os.path.join(*module_base.split('.')) for filename in to_remove: diff --git a/src/sage_setup/find.py b/src/sage_setup/find.py index 0edcfa3b664..56c4d6f76ad 100644 --- a/src/sage_setup/find.py +++ b/src/sage_setup/find.py @@ -101,7 +101,7 @@ def installed_files_by_module(site_packages, modules=('sage',)): sage: site_packages = getsitepackages()[0] sage: files_by_module = installed_files_by_module(site_packages) sage: files_by_module['sage.structure.sage_object'] - set(['sage/structure/sage_object.so']) + {'sage/structure/sage_object.so'} sage: sorted(files_by_module['sage.structure']) ['sage/structure/__init__.py', 'sage/structure/__init__.pyc'] From 1a2b1cf1af28d2ab5307e6bf3247756e06d65821 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 14:55:06 +0100 Subject: [PATCH 05/13] Add IPython formatting to the reference manual --- src/doc/en/reference/repl/index.rst | 28 ++++++++++++++++++++++++++- src/sage/repl/display/fancy_repr.py | 27 ++++++++++++++++++++------ src/sage/repl/display/formatter.py | 13 ++++++------- src/sage/repl/display/pretty_print.py | 10 +++++++++- src/sage/repl/display/util.py | 6 ++++-- src/sage/structure/sage_object.pyx | 14 ++++++++++---- 6 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/doc/en/reference/repl/index.rst b/src/doc/en/reference/repl/index.rst index 2c6d30b2a75..ce69372295d 100644 --- a/src/doc/en/reference/repl/index.rst +++ b/src/doc/en/reference/repl/index.rst @@ -1,6 +1,14 @@ The Sage Command Line ===================== +The Sage Read-Eval-Print-Loop (REPL) is based on IPython. In this +document, you'll find how the IPython integration works. You should +also be familiar with the documentation for IPython. + +For more details about using the Sage command line, see the Sage +tutorial. + + .. toctree:: :maxdepth: 2 @@ -13,6 +21,24 @@ The Sage Command Line sage/repl/interpreter sage/repl/ipython_extension -For more details about how to use the Sage command line once it starts up, see the Sage tutorial and the documentation for IPython. + +Pretty Printing +--------------- + +In addition to making input nicer, we also modify how results are +printed. This again builds on how IPython formats output. Technically, +this works using a modified displayhook in Python. + +.. toctree:: + :maxdepth: 2 + + sage/repl/display/formatter + sage/repl/display/pretty_print + sage/repl/display/fancy_repr + sage/repl/display/util + sage/repl/display/python_hook + + + .. include:: ../footer.txt diff --git a/src/sage/repl/display/fancy_repr.py b/src/sage/repl/display/fancy_repr.py index ad3d6189393..eea7060be71 100644 --- a/src/sage/repl/display/fancy_repr.py +++ b/src/sage/repl/display/fancy_repr.py @@ -28,7 +28,10 @@ class ObjectReprABC(object): """ The abstract base class of an object representer. + + .. automethod:: __call__ """ + def __repr__(self): """ Return string representation. @@ -46,7 +49,7 @@ def __repr__(self): return('{0} pretty printer'.format(self.__class__.__name__)) def __call__(self, obj, p, cycle): - """ + r""" Format object. INPUT: @@ -112,6 +115,8 @@ def __init__(self): sage: from sage.repl.display.fancy_repr import SomeIPythonRepr sage: SomeIPythonRepr() SomeIPythonRepr pretty printer + + .. automethod:: __call__ """ type_repr = _type_pprinters.copy() del type_repr[types.TypeType] @@ -156,10 +161,12 @@ def __call__(self, obj, p, cycle): class LargeMatrixHelpRepr(ObjectReprABC): """ Representation including help for large Sage matrices + + .. automethod:: __call__ """ def __call__(self, obj, p, cycle): - """ + r""" Format matrix. INPUT: @@ -212,10 +219,12 @@ def __call__(self, obj, p, cycle): class PlainPythonRepr(ObjectReprABC): """ The ordinary Python representation + + .. automethod:: __call__ """ def __call__(self, obj, p, cycle): - """ + r""" Format matrix. INPUT: @@ -255,10 +264,12 @@ def __call__(self, obj, p, cycle): class AsciiArtRepr(ObjectReprABC): """ Ascii Art representation + + .. automethod:: __call__ """ def __call__(self, obj, p, cycle): - """ + r""" Return ascii art format. INPUT: @@ -290,10 +301,12 @@ def __call__(self, obj, p, cycle): class TypesetRepr(ObjectReprABC): """ Typeset representation + + .. automethod:: __call__ """ def __call__(self, obj, p, cycle): - """ + r""" Return typeset format. INPUT: @@ -327,10 +340,12 @@ def __call__(self, obj, p, cycle): class TallListRepr(ObjectReprABC): """ Special representation for lists with tall entries (e.g. matrices) + + .. automethod:: __call__ """ def __call__(self, obj, p, cycle): - """ + r""" Format list/tuple. INPUT: diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py index 8d7e4f41339..9162e87b1f9 100644 --- a/src/sage/repl/display/formatter.py +++ b/src/sage/repl/display/formatter.py @@ -16,7 +16,7 @@ ] This facility uses :meth:`_repr_` (and a simple string) to try do a nice read -format (see :meth:`sage.structure.parent._repr_option` for details). +format (see :meth:`sage.structure.parent.Parent._repr_option` for details). With this displayhook there exists an other way for displaying object and more generally, all sage expression as an ASCII art object:: @@ -46,10 +46,9 @@ , 4 , 4 ] sage: shell.run_cell('%display simple') -This other facility uses a simple `AsciiArt` object (see -:class:`sage.misc.ascii_art.AsciiArt` and -:meth:`sage.structure.parent._ascii_art_`). -""" +This other facility uses a simple +:class:`~sage.misc.ascii_art.AsciiArt` object (see and +:meth:`sage.structure.sage_object.SageObject._ascii_art_`). """ #***************************************************************************** # Copyright (C) 2014 Volker Braun @@ -78,10 +77,10 @@ def __init__(self, *args, **kwds): In particular, it has the following two features: - correctly print lists of matrices or other objects (see - :meth:`sage.structure.parent._repr_option`), + :meth:`sage.structure.parent.Parent._repr_option`), - print ASCII art objects (like expressions) (see - :meth:`sage.structure.parent._ascii_art_`). + :meth:`sage.structure.sage_object.SageObject._ascii_art_`). EXAMPLES:: diff --git a/src/sage/repl/display/pretty_print.py b/src/sage/repl/display/pretty_print.py index 7c5651c7760..3648b40efc2 100644 --- a/src/sage/repl/display/pretty_print.py +++ b/src/sage/repl/display/pretty_print.py @@ -45,7 +45,7 @@ class SagePrettyPrinter(PrettyPrinter): ) def toplevel(self): - """ + r""" Return whether we are currently at the top level. OUTPUT: @@ -159,6 +159,9 @@ def pretty(self, obj): class AsciiArtPrettyPrinter(SagePrettyPrinter): + """ + Pretty printer returning ASCII art + """ pretty_repr = ( AsciiArtRepr(), @@ -166,6 +169,11 @@ class AsciiArtPrettyPrinter(SagePrettyPrinter): class TypesetPrettyPrinter(SagePrettyPrinter): + """ + Pretty printer returning typeset html + + This is also used in the emacs-mode. + """ pretty_repr = ( TypesetRepr(), diff --git a/src/sage/repl/display/util.py b/src/sage/repl/display/util.py index 6de8c031eb1..13b86d92a49 100644 --- a/src/sage/repl/display/util.py +++ b/src/sage/repl/display/util.py @@ -16,9 +16,11 @@ #***************************************************************************** -class _TallListFormatter(object): +class TallListFormatter(object): """ Special representation for lists with tall entries (e.g. matrices) + + .. automethod:: __call__ """ # This is used to wrap lines when printing "tall" lists. @@ -160,4 +162,4 @@ def __call__(self, the_list): return output -format_list = _TallListFormatter() +format_list = TallListFormatter() diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index 4c4646697cc..0a53458bc1d 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -27,6 +27,15 @@ cdef process(s): cdef class SageObject: + """ + Base class for all (user-visible) objects in Sage + + Every object that can end up being returned to the user should + inherit from :class:`SageObject`. + + .. automethod:: _ascii_art_ + .. automethod:: _cache_key + """ ####################################################################### # Textual representation code @@ -161,10 +170,7 @@ cdef class SageObject: you must override this method. Unlike :meth:`_repr_`, which is sometimes used for the hash key, the output of :meth:`_ascii_art_` may depend on settings and is allowed to - change during runtime. For example, - :meth:`~sage.combinat.tableau.Tableau.set_ascii_art` can be - used to switch the ASCII art of tableaux between different - mathematical conventions. + change during runtime. OUTPUT: From 48a2320912986874f4580d22fea71ab3299a9963 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 15:20:15 +0100 Subject: [PATCH 06/13] Also call graphics.show() in doctest mode --- src/sage/plot/graphics.py | 8 ++++- src/sage/plot/plot3d/base.pyx | 2 +- src/sage/repl/display/formatter.py | 47 ++++++++++++++++++++++++++++ src/sage/repl/display/python_hook.py | 4 +-- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index c2075bd749b..e66b8812265 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -1828,6 +1828,10 @@ def show(self, filename=None, linkmode=False, **kwds): specify ``ticks`` manually, this safety measure can be defeated:: sage: list_plot_loglog([(1,2),(2,3)], plotjoined=True, ticks=[[1],[1]]) + doctest:...: UserWarning: The x-axis contains fewer than 2 ticks; + the logarithmic scale of the plot may not be apparent to the reader. + doctest:...: UserWarning: The y-axis contains fewer than 2 ticks; + the logarithmic scale of the plot may not be apparent to the reader. Graphics object consisting of 1 graphics primitive This one works, since the horizontal axis is automatically expanded @@ -2318,7 +2322,9 @@ def matplotlib(self, filename=None, ``typeset`` must not be set to an arbitrary string:: sage: plot(x, typeset='garbage') - Graphics object consisting of 1 graphics primitive + doctest:...: FormatterWarning: Exception in text/plain formatter: + typeset must be set to one of 'default', 'latex', or 'type1'; got 'garbage'. + None We verify that numerical options are changed to float before saving (:trac:`14741`). By default, Sage 5.10 changes float objects to the `RealLiteral` type. diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 28056706776..83f255a82bb 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -1882,7 +1882,7 @@ cdef class PrimitiveObject(Graphics3d): sage: G = dodecahedron(color='red') sage: G.texture_set() - {Texture(texture540, red, ff0000)} + {Texture(texture..., red, ff0000)} """ return set([self.texture]) diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py index 9162e87b1f9..348e00132a2 100644 --- a/src/sage/repl/display/formatter.py +++ b/src/sage/repl/display/formatter.py @@ -236,6 +236,51 @@ def __call__(self, obj): return stream.getvalue() +class SageDoctestTextFormatter(SagePlainTextFormatter): + + @warn_format_error + def __call__(self, obj): + """ + Display ``obj``. + + For doctests, we both + + * Print the textual representation. This makes it clear in the + documentation that the command returns graphics. + + * Run ``show()`` on graphics objects, to test that it + correctly generates graphics. Note that, in + ``DOCTEST_MODE``, the ``show()`` method will save graphics + to temporary files but not launch a viewer. + + INPUT: + + - ``obj`` -- anything. + + OUTPUT: + + String. The plain text representation. + + EXAMPLES:: + + sage: class FooGraphics(SageObject): + ....: def _graphics_(self): + ....: print('showing graphics') + ....: return True + ....: def _repr_(self): + ....: return 'Textual representation' + sage: from sage.repl.display.formatter import SageDoctestTextFormatter + sage: fmt = SageDoctestTextFormatter() + sage: fmt(FooGraphics()) + showing graphics + 'Textual representation' + """ + from sage.structure.sage_object import SageObject + if isinstance(obj, SageObject) and hasattr(obj, '_graphics_'): + obj._graphics_() # ignore whether there actually is graphics + return super(SageDoctestTextFormatter, self).__call__(obj) + + class SageConsoleTextFormatter(SagePlainTextFormatter): @warn_format_error @@ -266,6 +311,8 @@ def __call__(self, obj): ....: def _graphics_(self): ....: print('showing graphics') ....: return True + ....: def _repr_(self): + ....: return 'Textual representation' sage: from sage.repl.display.formatter import SageConsoleTextFormatter sage: fmt = SageConsoleTextFormatter() sage: fmt(FooGraphics()) diff --git a/src/sage/repl/display/python_hook.py b/src/sage/repl/display/python_hook.py index e695b4f7f42..f9d0ce8b417 100644 --- a/src/sage/repl/display/python_hook.py +++ b/src/sage/repl/display/python_hook.py @@ -20,7 +20,7 @@ import __builtin__ -from sage.repl.display.formatter import SagePlainTextFormatter +from sage.repl.display.formatter import SageDoctestTextFormatter class DoctestDisplayHook(object): @@ -38,7 +38,7 @@ def __init__(self): sage: print(set([1, 2, 3])) # Plain Python output set([1, 2, 3]) """ - self.formatter = SagePlainTextFormatter() + self.formatter = SageDoctestTextFormatter() def __call__(self, obj): """ From fbf83ebb7a7d32d64be6551c4d1866bb1e1dba7c Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 15:41:32 +0100 Subject: [PATCH 07/13] Show output of the lonely generic_graph doctest --- src/sage/graphs/generic_graph.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 7bf7f3a2052..9bb73b07d15 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -14748,7 +14748,12 @@ def layout(self, layout = None, pos = None, dim = 2, save_pos = False, **options ('1', 0): [1.12..., -0.830...], ('1', 1): [2.50..., -0.545...]} - sage: x = g.layout(layout = "acyclic_dummy", save_pos = True) + sage: g.layout(layout = "acyclic_dummy", save_pos = True) + {('0', 0): [0.33..., 0], + ('0', 1): [0.33..., 1], + ('1', 0): [0.67..., 0], + ('1', 1): [0.67..., 1]} + sage: g.layout(dim = 3) {('0', 0): [2.02..., 0.528..., 0.343...], ('0', 1): [1.61..., 0.260..., -0.927...], From a9271f0de704f3919b58e0b22afa9d38a39c47d1 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 15:58:05 +0100 Subject: [PATCH 08/13] Fix doctests that have dictionary keys without stable order --- src/doc/de/tutorial/programming.rst | 8 +++- .../tutorial-programming-python.rst | 47 ++++++++++++------- src/doc/en/tutorial/programming.rst | 8 +++- src/doc/fr/tutorial/programming.rst | 8 +++- src/doc/ru/tutorial/programming.rst | 8 +++- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/doc/de/tutorial/programming.rst b/src/doc/de/tutorial/programming.rst index dc0c57526ce..9b17219ce61 100644 --- a/src/doc/de/tutorial/programming.rst +++ b/src/doc/de/tutorial/programming.rst @@ -500,8 +500,10 @@ ob ein Element zu der Menge gehört oder nicht, sehr schnell geht. :: sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {1, 19, 'a'} + sage: X == set(['a', 1, 1, 19]) + True sage: Y {2/3, 1} sage: 'a' in X @@ -520,8 +522,10 @@ verwenden. Zum Beispiel, :: sage: X = Set([1,19,'a']); Y = Set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {'a', 1, 19} + sage: X == Set(['a', 1, 1, 19]) + True sage: Y {1, 2/3} sage: X.intersection(Y) diff --git a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst index fbce406be26..2f73009ff84 100644 --- a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst +++ b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst @@ -703,9 +703,9 @@ There are several ways to define dictionaries. One method is to use braces, ``{}``, with comma-separated entries given in the form *key:value*:: - sage: d = {3:17, "key":[4,1,5,2,3], (3,1,2):"goo", 3/2 : 17} + sage: d = {3:17, 0.5:[4,1,5,2,3], 0:"goo", 3/2 : 17} sage: d - {3/2: 17, 3: 17, 'key': [4, 1, 5, 2, 3], (3, 1, 2): 'goo'} + {0: 'goo', 0.500000000000000: [4, 1, 5, 2, 3], 3/2: 17, 3: 17} A second method is to use the constructor :class:`dict` which admits a list (or actually any iterable) of 2-tuples *(key, value)*:: @@ -732,7 +732,7 @@ Dictionaries behave as lists and tuples for several important operations. sage: d[10]='a' sage: d - {3/2: 17, 3: 17, 10: 'a', 'key': [4, 1, 5, 2, 3], (3, 1, 2): 'goo'} + {0: 'goo', 0.500000000000000: [4, 1, 5, 2, 3], 3/2: 17, 3: 17, 10: 'a'} A dictionary can have the same value multiple times, but each key must only appear once and must be immutable:: @@ -763,33 +763,48 @@ updates the dictionary from another dictionary:: :: - sage: d.update( {10 : 'newvalue', 20: 'newervalue', 3: 14, 'a':[1,2,3]} ) + sage: d.update({10 : 'newvalue', 20: 'newervalue', 3: 14, 0.5:[1,2,3]}) sage: d - {3: 14, 10: 'newvalue', 20: 'newervalue', 'a': [1, 2, 3]} + {0.500000000000000: [1, 2, 3], 3: 14, 10: 'newvalue', 20: 'newervalue'} -We can iterate through the *keys*, or *values*, or both, of a dictionary:: - sage: d = {10 : 'newvalue', 20: 'newervalue', 3: 14, 'a':[1,2,3]} +We can iterate through the *keys*, or *values*, or both, of a +dictionary. Note that, internally, there is no sorting of keys +done. In general, the order of keys/values will depend on memory +locations can and will differ between different computers and / or +repeated runs on the same computer. However, Sage sort the dictionary +entries by key when printing the dictionary specifically to make the +docstrings more reproducible. However, the Python methods ``keys()`` +and ``values()`` do not sort for you. If you want your output to be +reproducable, then you have to sort it first just like in the examples +below:: + + sage: d = {10 : 'newvalue', 20: 'newervalue', 3: 14, 0.5:(1,2,3)} :: - sage: [key for key in d] - ['a', 10, 3, 20] + sage: sorted([key for key in d]) + [0.500000000000000, 3, 10, 20] :: - sage: [key for key in d.iterkeys()] - ['a', 10, 3, 20] + sage: d.keys() # random order + [0.500000000000000, 10, 3, 20] + sage: sorted(d.keys()) + [0.500000000000000, 3, 10, 20] :: - sage: [value for value in d.itervalues()] - [[1, 2, 3], 'newvalue', 14, 'newervalue'] - + sage: d.values() # random order + [(1, 2, 3), 'newvalue', 14, 'newervalue'] + sage: set(d.values()) == set([14, (1, 2, 3), 'newvalue', 'newervalue']) + True :: - sage: [(key, value) for key, value in d.iteritems()] - [('a', [1, 2, 3]), (10, 'newvalue'), (3, 14), (20, 'newervalue')] + sage: d.items() # random order + [(0.500000000000000, (1, 2, 3)), (10, 'newvalue'), (3, 14), (20, 'newervalue')] + sage: sorted([(key, value) for key, value in d.items()]) + [(0.500000000000000, (1, 2, 3)), (3, 14), (10, 'newvalue'), (20, 'newervalue')] **Exercise:** Consider the following directed graph. diff --git a/src/doc/en/tutorial/programming.rst b/src/doc/en/tutorial/programming.rst index bf334166d3b..b9c63df97aa 100644 --- a/src/doc/en/tutorial/programming.rst +++ b/src/doc/en/tutorial/programming.rst @@ -482,8 +482,10 @@ or not, along with standard set-theoretic operations. :: sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {1, 19, 'a'} + sage: X == set(['a', 1, 1, 19]) + True sage: Y {2/3, 1} sage: 'a' in X @@ -501,8 +503,10 @@ example, :: sage: X = Set([1,19,'a']); Y = Set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {'a', 1, 19} + sage: X == Set(['a', 1, 1, 19]) + True sage: Y {1, 2/3} sage: X.intersection(Y) diff --git a/src/doc/fr/tutorial/programming.rst b/src/doc/fr/tutorial/programming.rst index a9588f9f34e..5bacc3387ab 100644 --- a/src/doc/fr/tutorial/programming.rst +++ b/src/doc/fr/tutorial/programming.rst @@ -498,8 +498,10 @@ ensemblistes usuelles. :: sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {1, 19, 'a'} + sage: X == set(['a', 1, 1, 19]) + True sage: Y {2/3, 1} sage: 'a' in X @@ -517,8 +519,10 @@ supplémentaires utiles à Sage. Pour créer un ensemble Sage, on utilise :: sage: X = Set([1,19,'a']); Y = Set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {'a', 1, 19} + sage: X == Set(['a', 1, 1, 19]) + True sage: Y {1, 2/3} sage: X.intersection(Y) diff --git a/src/doc/ru/tutorial/programming.rst b/src/doc/ru/tutorial/programming.rst index 4ef166d9853..ae07c8d7622 100644 --- a/src/doc/ru/tutorial/programming.rst +++ b/src/doc/ru/tutorial/programming.rst @@ -466,8 +466,10 @@ http://docs.python.org/lib/typesmapping.html) произвольным объе :: sage: X = set([1,19,'a']); Y = set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {1, 19, 'a'} + sage: X == set(['a', 1, 1, 19]) + True sage: Y {2/3, 1} sage: 'a' in X @@ -485,8 +487,10 @@ http://docs.python.org/lib/typesmapping.html) произвольным объе :: sage: X = Set([1,19,'a']); Y = Set([1,1,1, 2/3]) - sage: X + sage: X # random sort order {'a', 1, 19} + sage: X == Set(['a', 1, 1, 19]) + True sage: Y {1, 2/3} sage: X.intersection(Y) From 3922ed548e74761576035cb56ef693d2f17ee3dd Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 19:05:39 +0100 Subject: [PATCH 09/13] Reduce doctest precision --- .../thematic_tutorials/tutorial-programming-python.rst | 1 + src/sage/graphs/generic_graph.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst index 2f73009ff84..8299d749751 100644 --- a/src/doc/en/thematic_tutorials/tutorial-programming-python.rst +++ b/src/doc/en/thematic_tutorials/tutorial-programming-python.rst @@ -799,6 +799,7 @@ below:: [(1, 2, 3), 'newvalue', 14, 'newervalue'] sage: set(d.values()) == set([14, (1, 2, 3), 'newvalue', 'newervalue']) True + :: sage: d.items() # random order diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 9bb73b07d15..1d13dabaccf 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -14748,11 +14748,11 @@ def layout(self, layout = None, pos = None, dim = 2, save_pos = False, **options ('1', 0): [1.12..., -0.830...], ('1', 1): [2.50..., -0.545...]} - sage: g.layout(layout = "acyclic_dummy", save_pos = True) - {('0', 0): [0.33..., 0], - ('0', 1): [0.33..., 1], - ('1', 0): [0.67..., 0], - ('1', 1): [0.67..., 1]} + sage: g.layout(layout="acyclic_dummy", save_pos=True) + {('0', 0): [0.3..., 0], + ('0', 1): [0.3..., 1], + ('1', 0): [0.6..., 0], + ('1', 1): [0.6..., 1]} sage: g.layout(dim = 3) {('0', 0): [2.02..., 0.528..., 0.343...], From b362aa6c4ee2db82dc49ab42d52042cf9a46074a Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 19:57:37 +0100 Subject: [PATCH 10/13] Display trailing newline in __repr__() output --- .../bij_abstract_class.py | 6 +++++- .../rigged_configurations/bij_type_D.py | 12 +++++++++-- .../rigged_configuration_element.py | 8 +++++-- src/sage/repl/display/fancy_repr.py | 21 ++++++++++++++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/sage/combinat/rigged_configurations/bij_abstract_class.py b/src/sage/combinat/rigged_configurations/bij_abstract_class.py index b7a2622272e..b99ec3a10fc 100644 --- a/src/sage/combinat/rigged_configurations/bij_abstract_class.py +++ b/src/sage/combinat/rigged_configurations/bij_abstract_class.py @@ -458,7 +458,11 @@ def next_state(self, height): sage: bijection.next_state(0) 5 sage: bijection.cur_partitions - [(/), (/), (/), (/)] + [(/) + , (/) + , (/) + , (/) + ] """ def _update_vacancy_numbers(self, a): diff --git a/src/sage/combinat/rigged_configurations/bij_type_D.py b/src/sage/combinat/rigged_configurations/bij_type_D.py index 89d6fb5af93..a191ed3e0df 100644 --- a/src/sage/combinat/rigged_configurations/bij_type_D.py +++ b/src/sage/combinat/rigged_configurations/bij_type_D.py @@ -691,10 +691,18 @@ def doubling_map(self): sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[],[],[1]])) sage: bijection.cur_partitions - [(/), (/), (/), -1[ ]-1] + [(/) + , (/) + , (/) + , -1[ ]-1 + ] sage: bijection.doubling_map() sage: bijection.cur_partitions - [(/), (/), (/), -2[ ][ ]-2] + [(/) + , (/) + , (/) + , -2[ ][ ]-2 + ] """ # Skip the first column since it is a spinor for i in range(1, len(self.cur_dims)): diff --git a/src/sage/combinat/rigged_configurations/rigged_configuration_element.py b/src/sage/combinat/rigged_configurations/rigged_configuration_element.py index b1874200e40..0dcaff495b4 100644 --- a/src/sage/combinat/rigged_configurations/rigged_configuration_element.py +++ b/src/sage/combinat/rigged_configurations/rigged_configuration_element.py @@ -469,8 +469,12 @@ def nu(self): sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]]) sage: RC(partition_list=[[2], [2,2], [2], [2]]).nu() - [0[ ][ ]0, -2[ ][ ]-2 - -2[ ][ ]-2, 2[ ][ ]2, -2[ ][ ]-2] + [0[ ][ ]0 + , -2[ ][ ]-2 + -2[ ][ ]-2 + , 2[ ][ ]2 + , -2[ ][ ]-2 + ] """ return list(self) diff --git a/src/sage/repl/display/fancy_repr.py b/src/sage/repl/display/fancy_repr.py index eea7060be71..ad25172caf3 100644 --- a/src/sage/repl/display/fancy_repr.py +++ b/src/sage/repl/display/fancy_repr.py @@ -246,6 +246,25 @@ def __call__(self, obj, p, cycle): sage: pp = PlainPythonRepr() sage: pp.format_string(type(1)) "" + + Do not swallow a trailing newline at the end of the output of + a custom representer. Note that it is undesirable to have a + trailing newline, and if we don't display it you can't fix + it:: + + sage: class Newline(object): + ....: def __repr__(self): + ....: return 'newline\n' + sage: n = Newline() + sage: pp.format_string(n) + 'newline\n' + sage: pp.format_string([n, n, n]) + '[newline\n, newline\n, newline\n]' + sage: [n, n, n] + [newline + , newline + , newline + ] """ klass = _safe_getattr(obj, '__class__', None) or type(obj) klass_repr = _safe_getattr(klass, '__repr__', None) @@ -254,7 +273,7 @@ def __call__(self, obj, p, cycle): else: # A user-provided repr. Find newlines and replace them with p.break_() output = _safe_repr(obj) - for idx, output_line in enumerate(output.splitlines()): + for idx, output_line in enumerate(output.split('\n')): if idx: p.break_() p.text(output_line) From 7de159aef22abafd93bfccd8557065c7d802031f Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Fri, 19 Sep 2014 22:58:13 +0100 Subject: [PATCH 11/13] Fix more random test failures --- src/sage/combinat/crystals/alcove_path.py | 10 +++++++--- src/sage/plot/plot3d/implicit_surface.pyx | 2 +- src/sage/structure/coerce_dict.pyx | 12 ++++++------ src/sage/structure/formal_sum.py | 6 +++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/sage/combinat/crystals/alcove_path.py b/src/sage/combinat/crystals/alcove_path.py index 05e8ad3ca5d..a155b76943f 100644 --- a/src/sage/combinat/crystals/alcove_path.py +++ b/src/sage/combinat/crystals/alcove_path.py @@ -812,10 +812,14 @@ def _folding_data(self, i): :: - sage: C=crystals.AlcovePaths(['A',2],[1,1]) - sage: x=C( () ).f(1) - sage: x._folding_data(2) + sage: C = crystals.AlcovePaths(['A',2],[1,1]) + sage: x = C( () ).f(1) + sage: fd = x._folding_data(2); fd # # random output {(alpha[2], 0): 1, (alpha[1] + alpha[2], 1): 1, 'infinity': 1} + sage: fd['infinity'] + 1 + sage: fd.values() + [1, 1, 1] """ Parent = self.parent() diff --git a/src/sage/plot/plot3d/implicit_surface.pyx b/src/sage/plot/plot3d/implicit_surface.pyx index 7ecc4e3f2cd..536dfc9a1c9 100644 --- a/src/sage/plot/plot3d/implicit_surface.pyx +++ b/src/sage/plot/plot3d/implicit_surface.pyx @@ -341,7 +341,7 @@ cdef class MarchingCubesTriangles(MarchingCubes): ... cube_marcher.process_slice(x, slices[x, :, :]) sage: faces = cube_marcher.finish() sage: faces[0][0] - {'x': 1.5555555555555554, 'y': -1.1111111111111112, 'z': -0.5555555555555551} + {'x': 1.555555555555..., 'y': -1.111111111111..., 'z': -0.555555555555...} We render the isosurface using IndexFaceSet:: diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx index 696c7ec1824..3cf2ae13b39 100644 --- a/src/sage/structure/coerce_dict.pyx +++ b/src/sage/structure/coerce_dict.pyx @@ -278,13 +278,13 @@ cdef class MonoDict: sage: from sage.structure.coerce_dict import MonoDict sage: L = MonoDict() - sage: a = 'a'; b = 'ab'; c = -15 + sage: a = 'a'; b = 'ab'; c = '-15' sage: L[a] = 1 sage: L[b] = 2 sage: L[c] = 3 The key is expected to be a unique object. Hence, the item stored for ``c`` - can not be obtained by providing another equal number:: + can not be obtained by providing another equal string:: sage: L[a] 1 @@ -292,10 +292,10 @@ cdef class MonoDict: 2 sage: L[c] 3 - sage: L[-15] + sage: L['-15'] Traceback (most recent call last): ... - KeyError: -15 + KeyError: '-15' Not all features of Python dictionaries are available, but iteration over the dictionary items is possible:: @@ -303,10 +303,10 @@ cdef class MonoDict: sage: # for some reason the following failed in "make ptest" sage: # on some installations, see #12313 for details sage: sorted(L.iteritems()) # random layout - [(-15, 3), ('a', 1), ('ab', 2)] + [('-15', 3), ('a', 1), ('ab', 2)] sage: # the following seems to be more consistent sage: set(L.iteritems()) - {(-15, 3), ('a', 1), ('ab', 2)} + {('-15', 3), ('a', 1), ('ab', 2)} sage: del L[c] sage: sorted(L.iteritems()) [('a', 1), ('ab', 2)] diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index 52d173cdbdd..f2c79bb57e0 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -198,15 +198,15 @@ def _get_action_(self, other, op, self_is_left): """ EXAMPLES:: - sage: A = FormalSums(RR).get_action(RR); A # indirect doctest + sage: A = FormalSums(RR); A.get_action(RR) # indirect doctest Right scalar multiplication by Real Field with 53 bits of precision on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision - sage: A = FormalSums(ZZ).get_action(QQ); A + sage: A = FormalSums(ZZ); A.get_action(QQ) Right scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field with precomposition on left by Conversion map: From: Abelian Group of all Formal Finite Sums over Integer Ring To: Abelian Group of all Formal Finite Sums over Rational Field - sage: A = FormalSums(QQ).get_action(ZZ); A + sage: A = FormalSums(QQ); A.get_action(ZZ) Right scalar multiplication by Integer Ring on Abelian Group of all Formal Finite Sums over Rational Field """ if op is operator.mul and isinstance(other, Parent): From c00964da4655d7580277c3d4aba1e0a51b06b78e Mon Sep 17 00:00:00 2001 From: Vincent Delecroix <20100.delecroix@gmail.com> Date: Wed, 24 Sep 2014 18:16:54 +0200 Subject: [PATCH 12/13] trac #17013: fix Python C API declaration --- src/sage/combinat/words/word_char.pyx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sage/combinat/words/word_char.pyx b/src/sage/combinat/words/word_char.pyx index b3c4a9f8cb6..f622b2816f1 100644 --- a/src/sage/combinat/words/word_char.pyx +++ b/src/sage/combinat/words/word_char.pyx @@ -30,7 +30,7 @@ cdef extern from "Python.h": # get numbers from Python slice int PySlice_GetIndicesEx(object slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, - Py_ssize_t *slicelength) + Py_ssize_t *slicelength) except -1 # the maximum value of a size_t cdef size_t SIZE_T_MAX = -( 1) @@ -320,18 +320,21 @@ cdef class WordDatatype_char(WordDatatype): sage: w = W([randint(0,3) for _ in range(20)]) sage: list(w) == [w[i] for i in range(len(w))] True + + sage: w['foo':'bar'] + Traceback (most recent call last): + ... + TypeError: slice indices must be integers or None or have an __index__ method """ cdef Py_ssize_t i, start, stop, step, slicelength cdef unsigned char * data cdef size_t j,k if PySlice_Check(key): # here the key is a slice - if PySlice_GetIndicesEx(key, + PySlice_GetIndicesEx(key, self._length, &start, &stop, &step, - &slicelength) < 0: - return # this automatically raise an error because - # PySlice_GetIndices already did the job + &slicelength) if step == 1: return self._new_c(self._data+start, stop-start, self) data = sage_malloc(slicelength * sizeof(unsigned char)) From 3070715a7f656326260a9ef6635884e69fa0136f Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Sat, 27 Sep 2014 01:05:17 +0100 Subject: [PATCH 13/13] fix another doctest --- src/sage/rings/finite_rings/finite_field_ext_pari.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/finite_rings/finite_field_ext_pari.py b/src/sage/rings/finite_rings/finite_field_ext_pari.py index 0c9f666cd0a..215b4570f40 100644 --- a/src/sage/rings/finite_rings/finite_field_ext_pari.py +++ b/src/sage/rings/finite_rings/finite_field_ext_pari.py @@ -82,7 +82,7 @@ class FiniteField_ext_pari(FiniteField_generic): The following is a native Python set:: sage: set(k) - {0, a + 1, a + 2, a, 1, 2*a + 1, 2*a + 2, 2*a, 2} + {0, 1, 2, a, 2*a, a + 1, 2*a + 1, a + 2, 2*a + 2} And the following is a Sage set::