Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge #16746 (Improvements to the Sage displayhook)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbraun committed Sep 20, 2014
2 parents 3c42208 + 7de159a commit b02f820
Show file tree
Hide file tree
Showing 320 changed files with 4,492 additions and 1,583 deletions.
8 changes: 3 additions & 5 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ usage_advanced() {
echo " -btp <N> [...] -- build and test parallel, options like -tp below"
echo " -btnew [...] -- build and test modified files, options like -tnew"
echo " -fixdoctests <file.py> [output_file] [--long]"
echo " -- writes a new version of file.py to output_file"
echo " (defaults: to file.py.out) that will pass the doctests."
echo " With the optional --long argument the long time tests"
echo " are also checked."
echo " A patch for the new file is printed to stdout."
echo " -- replace failing doctests with the actual output. With"
echo " optional output_file: redirect there. With the --long"
echo " option: include #long time tests."
echo " -startuptime [module] -- display how long each component of Sage takes to"
echo " start up; optionally specify a module to get more"
echo " details about that particular module"
Expand Down
42 changes: 25 additions & 17 deletions src/bin/sage-fixdoctests
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ AUTHORS::
"""

import os, sys, difflib
import subprocess
from optparse import OptionParser
from sage.misc.temporary_file import tmp_dir

Expand All @@ -25,15 +26,15 @@ Creates a file <source file>.out that passes the doctests (modulo any raised exc
parser = OptionParser(usage=usage)
parser.add_option('-l','--long',dest='long', action="store_true", default=False)

options,args = parser.parse_args()
options, args = parser.parse_args()

if not (len(args) in [1,2]) :
print usage
sys.exit(1)

# set input and output files
test_file=args[0]
test_output=args[1] if len(args)==2 else test_file+'.out'
test_file = args[0]
test_output = args[1] if len(args)==2 else test_file
try:
with open(test_file,'r') as src:
src_in = src.read()
Expand All @@ -43,7 +44,7 @@ except IOError:
sys.exit(1)

# put the output of the test into sage's temporary directory
doc_out=tmp_dir()+'.tmp'
doc_out = tmp_dir()+'.tmp'
os.system('sage -t %s %s > %s'%('--long' if options.long else '', test_file, doc_out))

doc_out = open(doc_out).read()
Expand Down Expand Up @@ -114,17 +115,24 @@ for block in doctests:
src_in_lines[line_num+i] = None


# We're done, so (try and) create and write the output file
while True:
try:
open(test_output,'w').write('\n'.join( line for line in src_in_lines if line is not None ))
break
except IOError:
test_output = raw_input('Cannot write to %s. Please give a new filename: ' % test_output)

# ...and print a diff of the old and new files to stdout
with open(test_file,'r') as src:
with open(test_output,'r') as output:
sys.stdout.writelines(line for line in difflib.unified_diff(src.readlines(),output.readlines()))

# Overwrite the source (or whatever output file was specified on the command line)
with open(test_output, 'w') as out:
for line in src_in_lines:
if line is None:
continue
out.write(line)
out.write('\n')


# Show summary of changes
if test_file != test_output:
print('The fixed doctests have been saved as {0}.'.format(test_output))
else:
from sage.env import SAGE_ROOT
relative = os.path.relpath(test_output, SAGE_ROOT)
print relative
if relative.startswith('..'):
print('Fixed source file is not part of Sage.')
else:
subprocess.call(['git', 'diff', relative], cwd=SAGE_ROOT)

10 changes: 10 additions & 0 deletions src/doc/de/thematische_anleitungen/sage_gymnasium.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -648,19 +651,22 @@ 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
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
===========
Expand Down Expand Up @@ -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
Expand All @@ -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
========
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/doc/de/tutorial/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,18 @@ 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])
sage: X # random sort order
{1, 19, 'a'}
sage: X == set(['a', 1, 1, 19])
True
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
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/doc/de/tutorial/tour_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand All @@ -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.
Expand All @@ -61,6 +63,7 @@ können geplottet, differenziert und integriert werden.
sage: type(g)
<type 'sage.symbolic.expression.Expression'>
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,
Expand All @@ -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
Expand All @@ -89,9 +93,11 @@ werden.
sage: type(sin)
<class 'sage.functions.trig.Function_sin'>
sage: plot(sin, 0, 2)
Graphics object consisting of 1 graphics primitive
sage: type(sin(x))
<type 'sage.symbolic.expression.Expression'>
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.
Expand Down Expand Up @@ -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.

Expand Down
21 changes: 18 additions & 3 deletions src/doc/de/tutorial/tour_plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:

Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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
----------------------
Expand All @@ -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`
Expand All @@ -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
Expand All @@ -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:

Expand All @@ -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 <http://de.wikipedia.org/wiki/Kreuzhaube>`__:

Expand All @@ -209,7 +221,8 @@ Die `Kreuz-Kappe <http://de.wikipedia.org/wiki/Kreuzhaube>`__:
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:

Expand All @@ -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 <http://de.wikipedia.org/wiki/Lemniskate>`__:

Expand All @@ -229,3 +243,4 @@ Die `Lemniskate <http://de.wikipedia.org/wiki/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
2 changes: 2 additions & 0 deletions src/doc/en/bordeaux_2008/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/doc/en/constructions/calculus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down
Loading

0 comments on commit b02f820

Please sign in to comment.