# Ticket #12415: 12415_doctest_review.patch

File 12415_doctest_review.patch, 24.1 KB (added by jdemeyer, 9 years ago)
• ## doc/en/tutorial/interfaces.rst

```# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1360957832 -3600
# Node ID e93a74429ba284fd1a8de375d12fd5b4914b8124
# Parent  5173e5d858897ac023e1fca0f8c8dcaec7fe1147
Further fixes for the new doctesting framework

diff --git a/doc/en/tutorial/interfaces.rst b/doc/en/tutorial/interfaces.rst```
 a Finally, we give an example of using Sage to plot using ``openmath``. Many of these were modified from the Maxima reference manual. A 2D plot of several functions (do not type the ``...``): A 2D plot of several functions (do not type the ``...``):: :: sage: maxima.plot2d('[cos(7*x),cos(23*x)^4,sin(13*x)^3]','[x,0,1]',\ ...   '[plot_format,openmath]') # not tested sage: maxima.plot2d('[cos(7*x),cos(23*x)^4,sin(13*x)^3]','[x,0,1]',  # not tested ....:     '[plot_format,openmath]') A "live" 3D plot which you can move with your mouse (do not type the ``...``): the ``...``):: :: sage: maxima.plot3d ("2^(-u^2 + v^2)", "[u, -3, 3]", "[v, -2, 2]",  # not tested ....:     '[plot_format, openmath]') sage: maxima.plot3d("atan(-x^2 + y^3/4)", "[x, -4, 4]", "[y, -4, 4]",  # not tested ....:     "[grid, 50, 50]",'[plot_format, openmath]') sage: maxima.plot3d ("2^(-u^2 + v^2)", "[u, -3, 3]", "[v, -2, 2]",\ ...   '[plot_format, openmath]') # not tested sage: maxima.plot3d("atan(-x^2 + y^3/4)", "[x, -4, 4]", "[y, -4, 4]",\ ...   "[grid, 50, 50]",'[plot_format, openmath]') # not tested The next plot is the famous Möbius strip (do not type the ``...``):: The next plot is the famous Möbius strip (do not type the ``...``): sage: maxima.plot3d("[cos(x)*(3 + y*cos(x/2)), sin(x)*(3 + y*cos(x/2)), y*sin(x/2)]",  # not tested ....:     "[x, -4, 4]", "[y, -4, 4]", '[plot_format, openmath]') :: The next plot is the famous Klein bottle (do not type the ``...``):: sage: maxima.plot3d("[cos(x)*(3 + y*cos(x/2)), sin(x)*(3 + y*cos(x/2)),\ ...   y*sin(x/2)]", "[x, -4, 4]", "[y, -4, 4]",\ ...   '[plot_format, openmath]') # not tested The next plot is the famous Klein bottle (do not type the ``...``): :: sage: maxima("expr_1: 5*cos(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)+ 3.0)\ ...   - 10.0") sage: maxima("expr_1: 5*cos(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)+ 3.0) - 10.0") 5*cos(x)*(sin(x/2)*sin(2*y)+cos(x/2)*cos(y)+3.0)-10.0 sage: maxima("expr_2: -5*sin(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)+ 3.0)") -5*sin(x)*(sin(x/2)*sin(2*y)+cos(x/2)*cos(y)+3.0) sage: maxima("expr_3: 5*(-sin(x/2)*cos(y) + cos(x/2)*sin(2*y))") 5*(cos(x/2)*sin(2*y)-sin(x/2)*cos(y)) sage: maxima.plot3d ("[expr_1, expr_2, expr_3]", "[x, -%pi, %pi]",\ ...   "[y, -%pi, %pi]", "['grid, 40, 40]",\ ...   '[plot_format, openmath]') # not tested sage: maxima.plot3d ("[expr_1, expr_2, expr_3]", "[x, -%pi, %pi]",  # not tested ....:     "[y, -%pi, %pi]", "['grid, 40, 40]", '[plot_format, openmath]')
• ## sage/calculus/test_sympy.py

`diff --git a/sage/calculus/test_sympy.py b/sage/calculus/test_sympy.py`
 a sage: f = e.series(x, 0, 10); f 1 + 3*x**2/2 + 11*x**4/8 + 241*x**6/240 + 8651*x**8/13440 + O(x**10) And the pretty-printer:: And the pretty-printer.  Since unicode characters aren't working on some archictures, we disable it:: sage: from sympy.printing import pprint_use_unicode sage: prev_use = pprint_use_unicode(False) sage: pprint(e) 1 ─────── 3 1 ------- 3 cos (x) sage: pprint(f) 2       4        6         8 3⋅x    11⋅x    241⋅x    8651⋅x 1 + ──── + ───── + ────── + ─────── + O(x**10) 2       8      240      13440 2       4        6         8 3*x    11*x    241*x    8651*x 1 + ---- + ----- + ------ + ------- + O(x**10) 2       8      240      13440 sage: pprint_use_unicode(prev_use) False And the functionality to convert from sympy format to Sage format::
• ## sage/categories/groups.py

`diff --git a/sage/categories/groups.py b/sage/categories/groups.py`
 a sage: Groups().example() General Linear Group of degree 4 over Rational Field """ from sage.rings.rational_field import QQ from sage.rings.rational_field import QQ from sage.groups.matrix_gps.general_linear import GL return GL(4,QQ)
• ## sage/combinat/partition_algebra.py

`diff --git a/sage/combinat/partition_algebra.py b/sage/combinat/partition_algebra.py`
 a 132 sage: P3.first() #random {{1, 2, 3, -1, -3, -2}} {{1, 2, 3, -1, -3, -2}} sage: P3.last() #random {{-1}, {-2}, {3}, {1}, {-3}, {2}} sage: P3.random_element() #random
• ## sage/interfaces/tachyon.py

`diff --git a/sage/interfaces/tachyon.py b/sage/interfaces/tachyon.py`
 a - John E. Stone """ #***************************************************************************** #       Copyright (C) 2006 John E. Stone # #  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 sage.misc.pager import pager from sage.misc.misc import tmp_filename from sage.misc.sagedoc import format import os import sys class TachyonRT: """ sage: import os sage: t(tgen.str(), outfile = os.devnull) tachyon ... Tachyon Parallel/Multiprocessor Ray Tracer... """ modelfile = tmp_filename(ext='.dat') open(modelfile,'w').write(model) if verbose: print cmd # One should always flush before system() sys.stdout.flush() sys.stderr.flush() os.system(cmd) def usage(self, use_pager=True):
• ## sage/libs/lcalc/lcalc_Lfunction.pyx

`diff --git a/sage/libs/lcalc/lcalc_Lfunction.pyx b/sage/libs/lcalc/lcalc_Lfunction.pyx`
 a sage: L._print_data_to_standard_output() # tol 1e-15 ----------------------------------------------- Name of L_function: Name of L_function: number of dirichlet coefficients = 5 coefficients are periodic b[1] = 1 sage: L._print_data_to_standard_output() # tol 1e-15 ----------------------------------------------- Name of L_function: Name of L_function: number of dirichlet coefficients = 5 coefficients are periodic b[1] = 1 sage: L._print_data_to_standard_output() # tol 1e-15 ----------------------------------------------- Name of L_function: Name of L_function: number of dirichlet coefficients = 5 coefficients are periodic b[1] = (1,0)
• ## sage/libs/mwrank/interface.py

`diff --git a/sage/libs/mwrank/interface.py b/sage/libs/mwrank/interface.py`
 a Looking for quartics with I = 48, J = -432 Looking for Type 2 quartics: Trying positive a from 1 up to 1 (square a first...) (1,0,-6,4,1)        --trivial (1,0,-6,4,1)        --trivial Trying positive a from 1 up to 1 (...then non-square a) Finished looking for Type 2 quartics. Looking for Type 1 quartics: Trying positive a from 1 up to 2 (square a first...) (1,0,0,4,4) --nontrivial...(x:y:z) = (1 : 1 : 0) (1,0,0,4,4) --nontrivial...(x:y:z) = (1 : 1 : 0) Point = [0:0:1] height = 0.051111408239968840235886099756942021609538202280854 height = 0.0511114082399688402358 Rank of B=im(eps) increases to 1 (The previous point is on the egg) Exiting search for Type 1 quartics after finding one which is globally soluble. Mordell rank contribution from B=im(eps) = 1 Selmer  rank contribution from A=ker(eps) = 0 Sha     rank contribution from A=ker(eps) = 0 Searching for points (bound = 8)...done: found points of rank 1 and regulator 0.051111408239968840235886099756942021609538202280854 found points which generate a subgroup of rank 1 and regulator 0.0511114082399688402358 Processing points found during 2-descent...done: now regulator = 0.051111408239968840235886099756942021609538202280854 Saturating (bound = -1)...done: points were already saturated. now regulator = 0.0511114082399688402358 Saturating (with bound = -1)...done: points were already saturated. """ self.__verbose = verbose 375.42919921875 sage: EQ.saturate(2)  # points were not 2-saturated saturating basis...Saturation index bound = 93 WARNING: saturation at primes p > 2 will not be done; WARNING: saturation at primes p > 2 will not be done; ... Gained index 2 New regulator =  93.857300720636393209 93.8572998046875 sage: EQ.saturate(3)  # points were not 3-saturated saturating basis...Saturation index bound = 46 WARNING: saturation at primes p > 3 will not be done; WARNING: saturation at primes p > 3 will not be done; ... Gained index 3 New regulator =  10.4285889689595992455 10.4285888671875 sage: EQ.saturate(5)  # points were not 5-saturated saturating basis...Saturation index bound = 15 WARNING: saturation at primes p > 5 will not be done; WARNING: saturation at primes p > 5 will not be done; ... Gained index 5 New regulator =  0.417143558758383969818 sage: EQ.saturate()   # points are now saturated saturating basis...Saturation index bound = 3 Checking saturation at [ 2 3 ] Checking 2-saturation Checking 2-saturation Points were proved 2-saturated (max q used = 11) Checking 3-saturation Checking 3-saturation Points were proved 3-saturated (max q used = 13) done (True, 1, '[ ]') sage: EQ.saturate(2)  # points were not 2-saturated saturating basis...Saturation index bound = 93 WARNING: saturation at primes p > 2 will not be done; WARNING: saturation at primes p > 2 will not be done; ... Gained index 2 New regulator =  93.857300720636393209 sage: EQ.saturate(3)  # points were not 3-saturated saturating basis...Saturation index bound = 46 WARNING: saturation at primes p > 3 will not be done; WARNING: saturation at primes p > 3 will not be done; ... Gained index 3 New regulator =  10.4285889689595992455 sage: EQ.saturate(5)  # points were not 5-saturated saturating basis...Saturation index bound = 15 WARNING: saturation at primes p > 5 will not be done; WARNING: saturation at primes p > 5 will not be done; ... Gained index 5 New regulator =  0.417143558758383969818 sage: EQ.saturate()   # points are now saturated saturating basis...Saturation index bound = 3 Checking saturation at [ 2 3 ] Checking 2-saturation Checking 2-saturation Points were proved 2-saturated (max q used = 11) Checking 3-saturation Checking 3-saturation Points were proved 3-saturated (max q used = 13) done (True, 1, '[ ]') sage: EQ.saturate() saturating basis...Saturation index bound = 3 Checking saturation at [ 2 3 ] Checking 2-saturation Checking 2-saturation Points were proved 2-saturated (max q used = 11) Checking 3-saturation Checking 3-saturation Points were proved 3-saturated (max q used = 13) done (True, 1, '[ ]') The preceding command produces the following output as a side-effect.  It proves that the index of the points in their saturation is at most 3, then proves saturation at 2 and at 3, by reducing the points modulo all primes of good reduction up to 11, respectively 13:: saturating basis...Saturation index bound = 3 Checking saturation at [ 2 3 ] Checking 2-saturation Points were proved 2-saturated (max q used = 11) Checking 3-saturation Points were proved 3-saturated (max q used = 13) done Note the output of the preceding command: it proves that the index of the points in their saturation is at most 3, then proves saturation at 2 and at 3, by reducing the points modulo all primes of good reduction up to 11, respectively 13. """ ok, index, unsat = self.__mw.saturate(int(max_prime), odd_primes_only) return bool(ok), int(str(index)), unsat
• ## sage/libs/mwrank/mwrank.pyx

`diff --git a/sage/libs/mwrank/mwrank.pyx b/sage/libs/mwrank/mwrank.pyx`
 a sage: EQ.process([494, -5720, 6859]) # 3 times another point sage: EQ.saturate(sat_bd=2) Saturation index bound = 10 WARNING: saturation at primes p > 2 will not be done; WARNING: saturation at primes p > 2 will not be done; points may be unsaturated at primes between 2 and index bound Failed to saturate MW basis at primes [ ] (0, 1, '[ ]') Sha     rank contribution from A=ker(eps) = 0 sage: D2.saturate() Searching for points (bound = 8)...done: found points of rank 3 found points which generate a subgroup of rank 3 and regulator 0.417143558758383969817119544618093396749810106098479 Processing points found during 2-descent...done: now regulator = 0.417143558758383969817119544618093396749810106098479 Sha     rank contribution from A=ker(eps) = 0 sage: D2.saturate() Searching for points (bound = 8)...done: found points of rank 3 found points which generate a subgroup of rank 3 and regulator 0.417143558758383969817119544618093396749810106098479 Processing points found during 2-descent...done: now regulator = 0.417143558758383969817119544618093396749810106098479 sage: D2.saturate() Searching for points (bound = 8)...done: found points of rank 3 found points which generate a subgroup of rank 3 and regulator 0.417143558758383969817119544618093396749810106098479 Processing points found during 2-descent...done: now regulator = 0.417143558758383969817119544618093396749810106098479
• ## sage/misc/cython.py

`diff --git a/sage/misc/cython.py b/sage/misc/cython.py`
 a sage: f.write(s) sage: f.close() sage: cython_create_local_so('hello.spyx') Compiling hello.spyx... sage: sys.path.append('.') sage: import hello sage: hello.hello()
• ## sage/misc/interpreter.py

`diff --git a/sage/misc/interpreter.py b/sage/misc/interpreter.py`
 a sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) != 0 True sage: shell.system_raw('R --version') R version ... sage: status = shell.user_ns['_exit_code'] sage: os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0 True
• ## sage/misc/preparser.py

`diff --git a/sage/misc/preparser.py b/sage/misc/preparser.py`
 a EXAMPLES: Note that .py files are *not* preparsed:: sage: t=tmp_filename(ext='.py'); open(t,'w').write("print 'hi',2/3; z=-2/9") sage: sage.misc.preparser.load(t,globals()) Note that ``.py`` files are *not* preparsed:: sage: t = tmp_filename(ext='.py') sage: open(t,'w').write("print 'hi', 2/3; z = -2/7") sage: z = 1 sage: sage.misc.preparser.load(t, globals()) hi 0 sage: z -1 A .sage file *is* preparsed:: sage: t=tmp_filename(ext='.sage'); open(t,'w').write("print 'hi',2/3; s=-2/7") sage: sage.misc.preparser.load(t,globals()) A ``.sage`` file *is* preparsed:: sage: t = tmp_filename(ext='.sage') sage: open(t,'w').write("print 'hi', 2/3; z = -2/7") sage: z = 1 sage: sage.misc.preparser.load(t, globals()) hi 2/3 sage: s sage: z -2/7 Cython files are *not* preparsed:: sage: t=tmp_filename(ext='.pyx'); open(t,'w').write("print 'hi',2/3; z=-2/9") sage: z=0; sage.misc.preparser.load(t,globals()) sage: t = tmp_filename(ext='.pyx') sage: open(t,'w').write("print 'hi', 2/3; z = -2/7") sage: z = 1 sage: sage.misc.preparser.load(t, globals()) Compiling ... hi 0 sage: z -1
• ## sage/misc/session.pyx

`diff --git a/sage/misc/session.pyx b/sage/misc/session.pyx`
 a - creates a file EXAMPLES: For testing, we use a temporary file, that will be removed as soon as Sage is left. Of course, for permanently saving your session, you should choose a permanent file.:: you should choose a permanent file. :: sage: a = 5 sage: tmp_f = tmp_filename() 5 We illustrate what happens when one of the variables is a function.:: sage: f = lambda x : x^2 sage: save_session(tmp_f) sage: save_session(tmp_f, verbose=True) sage: g = cython_lambda('double x', 'x*x + 1.5') sage: save_session(tmp_f, verbose=True) Saving... Not saving g: g is a function, method, class or type ... """
• ## sage/modular/modform/cuspidal_submodule.py

`diff --git a/sage/modular/modform/cuspidal_submodule.py b/sage/modular/modform/cuspidal_submodule.py`
 a O(q^1) """ pass #def _repr_(self): #    A = self.ambient_module() #    return "Cuspidal subspace of dimension %s of Modular Forms space with character %s and weight %s over %s"%(self.dimension(), self.character(), self.weight(), self.base_ring()) def _convert_matrix_from_modsyms(symbs, T):
• ## sage/numerical/backends/glpk_backend.pyx

`diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx`
 a sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3) sage: p.set_objective([2, 5]) sage: p.write_mps(os.path.join(SAGE_TMP, "lp_problem.mps"), 2) Writing problem data to... 17 records were written """ glp_write_mps(self.lp, modern, NULL,  filename) sage: import sage.numerical.backends.glpk_backend as backend sage: p.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_only) sage: p.print_ranges() ... glp_print_ranges: optimal basic solution required 1 sage: p.solve() 0 sage: p.print_ranges() Write sensitivity analysis report to... GLPK ... - SENSITIVITY ANALYSIS REPORT                                                                         Page   1 Problem: Problem: Objective:  7.5 (MAXimum) No. Row name     St      Activity         Slack   Lower bound       Activity      Obj coef  Obj value at Limiting Marginal   Upper bound          range         range   break point variable ------ ------------ -- ------------- ------------- -------------  ------------- ------------- ------------- ------------ 1              NU       3.00000        .               -Inf         .           -2.50000        . 1              NU       3.00000        .               -Inf         .           -2.50000        . 2.50000       3.00000           +Inf          +Inf          +Inf GLPK ... - SENSITIVITY ANALYSIS REPORT                                                                         Page   2 Problem: Problem: Objective:  7.5 (MAXimum) No. Column name  St      Activity      Obj coef   Lower bound       Activity      Obj coef  Obj value at Limiting End of report 0 """ from sage.misc.all import SAGE_TMP
• ## sage/numerical/mip.pyx

`diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx`
 a sage: b = p.get_backend() sage: b.solver_parameter("simplex_or_intopt", "simplex_only") sage: b.solver_parameter("verbosity_simplex", "GLP_MSG_ALL") sage: p.solve() # tol 0.00001 sage: p.solve()  # tol 0.00001 GLPK Simplex Optimizer, v4.44 2 rows, 2 columns, 4 non-zeros *     0: obj =   7.000000000e+00  infeas =  0.000e+00 (0) *     2: obj =   9.400000000e+00  infeas =  0.000e+00 (0) OPTIMAL SOLUTION FOUND 9.4 """ return self._backend
• ## sage/schemes/toric/variety.py

`diff --git a/sage/schemes/toric/variety.py b/sage/schemes/toric/variety.py`
 a # -*- coding: utf-8 -*- r""" Toric varieties
• ## sage/structure/parent_old.pyx

`diff --git a/sage/structure/parent_old.pyx b/sage/structure/parent_old.pyx`
 a sage: MatrixSpace(GF(3), 1, 1).list() [[0], [1], [2]] sage: DirichletGroup(3).list() [Dirichlet character modulo 3 of conductor 1 mapping 2 |--> 1, [Dirichlet character modulo 3 of conductor 1 mapping 2 |--> 1, Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1] sage: K = GF(7^6,'a') sage: K.list()[:10] # long time