Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage.{calculus,functions,numerical,symbolic}: Docstring/doctest cosmetics, # needs #37715

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/calculus/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def integral(f, *args, **kwds):
symbolically::

sage: f(x) = 1/(sqrt(2*pi)) * e^(-x^2/2)
sage: P = plot(f, -4, 4, hue=0.8, thickness=2)
sage: P.show(ymin=0, ymax=0.4)
sage: P = plot(f, -4, 4, hue=0.8, thickness=2) # needs sage.plot
sage: P.show(ymin=0, ymax=0.4) # needs sage.plot
sage: numerical_integral(f, -4, 4) # random output
(0.99993665751633376, 1.1101527003413533e-14)
sage: integrate(f, x)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/calculus/interpolators.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def polygon_spline(pts):
sage: ps = polygon_spline(pts)
sage: fx = lambda x: ps.value(x).real
sage: fy = lambda x: ps.value(x).imag
sage: show(parametric_plot((fx, fy), (0, 2*pi))) # needs sage.plot
sage: show(parametric_plot((fx, fy), (0, 2*pi))) # needs sage.plot sage.symbolic
sage: m = Riemann_Map([lambda x: ps.value(real(x))],
....: [lambda x: ps.derivative(real(x))], 0)
sage: show(m.plot_colored() + m.plot_spiderweb()) # needs sage.plot

Polygon approximation of a circle::

sage: # needs sage.symbolic
sage: pts = [e^(I*t / 25) for t in range(25)]
sage: ps = polygon_spline(pts)
sage: ps.derivative(2)
Expand Down
35 changes: 19 additions & 16 deletions src/sage/calculus/riemann.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,15 @@ cdef class Riemann_Map:
sage: m = Riemann_Map([f], [fprime], 0)
sage: sz = m.get_szego(boundary=0)
sage: points = m.get_szego(absolute_value=True)
sage: list_plot(points)
sage: list_plot(points) # needs sage.plot
Graphics object consisting of 1 graphics primitive

Extending the points by a spline::

sage: s = spline(points)
sage: s(3*pi / 4)
0.0012158...
sage: plot(s,0,2*pi) # plot the kernel
sage: plot(s,0,2*pi) # plot the kernel # needs sage.plot
Graphics object consisting of 1 graphics primitive

The unit circle with a small hole::
Expand Down Expand Up @@ -483,7 +483,7 @@ 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: points = m.get_theta_points()
sage: list_plot(points)
sage: list_plot(points) # needs sage.plot
Graphics object consisting of 1 graphics primitive

Extending the points by a spline::
Expand Down Expand Up @@ -740,12 +740,12 @@ cdef class Riemann_Map:

Default plot::

sage: m.plot_boundaries()
sage: m.plot_boundaries() # needs sage.plot
Graphics object consisting of 1 graphics primitive

Big blue collocation points::

sage: m.plot_boundaries(plotjoined=False, rgbcolor=[0,0,1], thickness=6)
sage: m.plot_boundaries(plotjoined=False, rgbcolor=[0,0,1], thickness=6) # needs sage.plot
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.all import list_plot
Expand Down Expand Up @@ -905,17 +905,18 @@ cdef class Riemann_Map:

Default plot::

sage: m.plot_spiderweb()
sage: m.plot_spiderweb() # needs sage.plot
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)
sage: m.plot_spiderweb(spokes=4, circles=1, pts=400, # needs sage.plot
....: 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)
sage: m.plot_spiderweb(rgbcolor=[1,0,0], thickness=3) # needs sage.plot
Graphics object consisting of 21 graphics primitives

To generate the unit circle map, it's helpful to see what the
Expand All @@ -924,7 +925,7 @@ cdef class Riemann_Map:
sage: f(t) = e^(I*t)
sage: fprime(t) = I*e^(I*t)
sage: m = Riemann_Map([f], [fprime], 0, 1000)
sage: m.plot_spiderweb()
sage: m.plot_spiderweb() # needs sage.plot
Graphics object consisting of 21 graphics primitives

A multiply connected region with corners. We set ``min_mag`` higher
Expand All @@ -934,8 +935,10 @@ cdef class Riemann_Map:
sage: z1 = lambda t: ps.value(t); z1p = lambda t: ps.derivative(t)
sage: z2(t) = -2+exp(-I*t); z2p(t) = -I*exp(-I*t)
sage: z3(t) = 2+exp(-I*t); z3p(t) = -I*exp(-I*t)
sage: m = Riemann_Map([z1,z2,z3],[z1p,z2p,z3p],0,ncorners=4) # long time
sage: p = m.plot_spiderweb(withcolor=True,plot_points=500, thickness = 2.0, min_mag=0.1) # long time
sage: m = Riemann_Map([z1,z2,z3], [z1p,z2p,z3p], 0, # long time
....: ncorners=4)
sage: p = m.plot_spiderweb(withcolor=True, plot_points=500, # long time, needs sage.plot
....: thickness=2.0, min_mag=0.1)
"""
from sage.plot.complex_plot import ComplexPlot
from sage.plot.all import list_plot, Graphics
Expand Down Expand Up @@ -1028,17 +1031,17 @@ cdef class Riemann_Map:
sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
sage: m = Riemann_Map([f], [fprime], 0)
sage: m.plot_colored()
sage: m.plot_colored() # needs sage.plot
Graphics object consisting of 1 graphics primitive

Plot zoomed in on a specific spot::

sage: m.plot_colored(plot_range=[0,1,.25,.75])
sage: m.plot_colored(plot_range=[0,1,.25,.75]) # needs sage.plot
Graphics object consisting of 1 graphics primitive

High resolution plot::

sage: m.plot_colored(plot_points=1000) # long time (29s on sage.math, 2012)
sage: m.plot_colored(plot_points=1000) # long time (29s on sage.math, 2012), needs sage.plot
Graphics object consisting of 1 graphics primitive

To generate the unit circle map, it's helpful to see what the
Expand All @@ -1047,7 +1050,7 @@ cdef class Riemann_Map:
sage: f(t) = e^(I*t)
sage: fprime(t) = I*e^(I*t)
sage: m = Riemann_Map([f], [fprime], 0, 1000)
sage: m.plot_colored()
sage: m.plot_colored() # needs sage.plot
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.complex_plot import ComplexPlot
Expand Down Expand Up @@ -1081,7 +1084,7 @@ cdef comp_pt(clist, loop=True):
sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
sage: m = Riemann_Map([f], [fprime], 0)
sage: m.plot_spiderweb()
sage: m.plot_spiderweb() # needs sage.plot
Graphics object consisting of 21 graphics primitives
"""
list2 = [(c.real, c.imag) for c in clist]
Expand Down
6 changes: 5 additions & 1 deletion src/sage/calculus/transforms/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,15 @@ def dft(self, chi=None):
Indexed sequence: [6, 0, 0, 0, 0, 0]
indexed by [0, 1, 2, 3, 4, 5]

sage: # needs sage.groups
sage: # needs sage.combinat sage.groups
sage: G = SymmetricGroup(3)
sage: J = G.conjugacy_classes_representatives()
sage: s = IndexedSequence([1,2,3], J) # 1,2,3 are the values of a class fcn on G
sage: s.dft() # the "scalar-valued Fourier transform" of this class fcn
Indexed sequence: [8, 2, 2]
indexed by [(), (1,2), (1,2,3)]

sage: # needs sage.rings.number_field
sage: J = AbelianGroup(2, [2,3], names='ab')
sage: s = IndexedSequence([1,2,3,4,5,6], J)
sage: s.dft() # the precision of output is somewhat random and architecture dependent.
Expand All @@ -311,6 +313,8 @@ def dft(self, chi=None):
-0.00000000000000976996261670137 - 0.0000000000000159872115546022*I,
-0.00000000000000621724893790087 - 0.0000000000000106581410364015*I]
indexed by Multiplicative Abelian group isomorphic to C2 x C3

sage: # needs sage.groups sage.rings.number_field
sage: J = CyclicPermutationGroup(6)
sage: s = IndexedSequence([1,2,3,4,5,6], J)
sage: s.dft() # the precision of output is somewhat random and architecture dependent.
Expand Down
17 changes: 9 additions & 8 deletions src/sage/calculus/transforms/fft.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base):
EXAMPLES::

sage: a = FastFourierTransform(4)
sage: a._plot_polar(0,2) # needs sage.plot
sage: a._plot_polar(0,2) # needs sage.plot sage.symbolic
Graphics object consisting of 2 graphics primitives

"""
Expand Down Expand Up @@ -304,9 +304,9 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base):

- ``style`` -- Style of the plot, options are ``"rect"`` or ``"polar"``

- ``rect`` -- height represents real part, color represents
- ``"rect"`` -- height represents real part, color represents
imaginary part.
- ``polar`` -- height represents absolute value, color
- ``"polar"`` -- height represents absolute value, color
represents argument.

- ``xmin`` -- The lower bound of the slice to plot. 0 by default.
Expand All @@ -319,21 +319,22 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base):

EXAMPLES::

sage: # needs sage.plot
sage: a = FastFourierTransform(16)
sage: for i in range(16): a[i] = (random(),random())
sage: A = plot(a) # needs sage.plot
sage: B = plot(a, style='polar') # needs sage.plot
sage: type(A) # needs sage.plot
sage: A = plot(a)
sage: B = plot(a, style='polar') # needs sage.symbolic
sage: type(A)
<class 'sage.plot.graphics.Graphics'>
sage: type(B) # needs sage.plot
sage: type(B) # needs sage.symbolic
<class 'sage.plot.graphics.Graphics'>
sage: a = FastFourierTransform(125)
sage: b = FastFourierTransform(125)
sage: for i in range(1, 60): a[i]=1
sage: for i in range(1, 60): b[i]=1
sage: a.forward_transform()
sage: a.inverse_transform()
sage: a.plot() + b.plot() # needs sage.plot
sage: a.plot() + b.plot()
Graphics object consisting of 250 graphics primitives

"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _evalf_(self, x, parent=None, algorithm=None):

sage: gp.set_real_precision(59) # random # needs sage.libs.pari
38
sage: print(gp.eval("1 - erfc(1)")); print(erf(1).n(200)) # needs sage.libs.pari
sage: print(gp.eval("1 - erfc(1)")); print(erf(1).n(200)) # needs mpmath sage.libs.pari
0.84270079294971486934122063508260925929606699796630290845994
0.84270079294971486934122063508260925929606699796630290845994

Expand Down
4 changes: 2 additions & 2 deletions src/sage/functions/exp_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ def exponential_integral_1(x, n=0):

EXAMPLES::

sage: # needs sage.libs.pari
sage: # needs sage.libs.pari sage.rings.real_mpfr
sage: exponential_integral_1(2)
0.0489005107080611
sage: exponential_integral_1(2, 4) # abs tol 1e-18
Expand Down Expand Up @@ -1519,7 +1519,7 @@ def exponential_integral_1(x, n=0):
....: if e >= c:
....: print("exponential_integral_1(%s, %s)[%s] with precision %s has error of %s >= %s"%(a, n, i, prec, e, c))

ALGORITHM: use the PARI C-library function ``eint1``.
ALGORITHM: use the PARI C-library function :pari:`eint1`.

REFERENCE:

Expand Down
29 changes: 15 additions & 14 deletions src/sage/functions/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def __init__(self):
EXAMPLES::

sage: from sage.functions.gamma import gamma1
sage: gamma1(CDF(0.5, 14)) # needs sage.libs.pari
sage: gamma1(CDF(0.5, 14)) # needs sage.libs.pari sage.rings.complex_double
-4.0537030780372815e-10 - 5.773299834553605e-10*I
sage: gamma1(CDF(I)) # needs sage.libs.pari sage.symbolic
sage: gamma1(CDF(I)) # needs sage.libs.pari sage.rings.complex_double sage.symbolic
-0.15494982830181067 - 0.49801566811835607*I

Recall that `\Gamma(n)` is `n-1` factorial::
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self):
1*x^(-2) + (-2*euler_gamma)*x^(-1)
+ (2*euler_gamma^2 + 1/6*pi^2) + Order(x)

To prevent automatic evaluation use the ``hold`` argument::
To prevent automatic evaluation, use the ``hold`` argument::

sage: gamma1(1/2, hold=True) # needs sage.symbolic
gamma(1/2)
Expand Down Expand Up @@ -138,9 +138,9 @@ def __init__(self):
Infinity
sage: (-1.).gamma() # needs sage.rings.real_mpfr
NaN
sage: CC(-1).gamma() # needs sage.libs.pari
sage: CC(-1).gamma() # needs sage.libs.pari sage.rings.real_mpfr
Infinity
sage: RDF(-1).gamma()
sage: RDF(-1).gamma() # needs sage.rings.real_mpfr
NaN
sage: CDF(-1).gamma() # needs sage.libs.pari sage.rings.complex_double
Infinity
Expand Down Expand Up @@ -691,9 +691,9 @@ def gamma(a, *args, **kwds):

::

sage: gamma(CDF(I)) # needs sage.libs.pari sage.symbolic
sage: gamma(CDF(I)) # needs sage.libs.pari sage.rings.complex_double sage.symbolic
-0.15494982830181067 - 0.49801566811835607*I
sage: gamma(CDF(0.5, 14)) # needs sage.libs.pari
sage: gamma(CDF(0.5, 14)) # needs sage.libs.pari sage.rings.complex_double
-4.0537030780372815e-10 - 5.773299834553605e-10*I

Use ``numerical_approx`` to get higher precision from
Expand Down Expand Up @@ -721,7 +721,8 @@ def gamma(a, *args, **kwds):
sage: gamma(i) # needs sage.rings.number_field sage.symbolic
Traceback (most recent call last):
...
TypeError: cannot coerce arguments: no canonical coercion from Number Field in i with defining polynomial x^2 + 1 to Symbolic Ring
TypeError: cannot coerce arguments: no canonical coercion
from Number Field in i with defining polynomial x^2 + 1 to Symbolic Ring

.. SEEALSO::

Expand Down Expand Up @@ -1004,9 +1005,9 @@ def __init__(self):

INPUT:

- ``p`` - number or symbolic expression
- ``p`` -- number or symbolic expression

- ``q`` - number or symbolic expression
- ``q`` -- number or symbolic expression


OUTPUT: number or symbolic expression (if input is symbolic)
Expand All @@ -1016,18 +1017,18 @@ def __init__(self):
sage: # needs sage.symbolic
sage: beta(3, 2)
1/12
sage: beta(3,1)
sage: beta(3, 1)
1/3
sage: beta(1/2, 1/2)
beta(1/2, 1/2)
sage: beta(-1,1)
sage: beta(-1, 1)
-1
sage: beta(-1/2,-1/2)
sage: beta(-1/2, -1/2)
0
sage: ex = beta(x/2, 3)
sage: set(ex.operands()) == set([1/2*x, 3])
True
sage: beta(.5,.5)
sage: beta(.5, .5)
3.14159265358979
sage: beta(1, 2.0+I)
0.400000000000000 - 0.200000000000000*I
Expand Down
Loading
Loading