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

Commit e913bee

Browse files
committed
Trac #10038: reviewer changes.
1 parent 751776b commit e913bee

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

src/sage/symbolic/expression.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5713,8 +5713,8 @@ cdef class Expression(CommutativeRingElement):
57135713
return SubstituteFunction(self, original, new)()
57145714

57155715
def exponentialize(self):
5716-
"""
5717-
Returns this symbolic expression with all circular and hyperbolic
5716+
r"""
5717+
Return this symbolic expression with all circular and hyperbolic
57185718
functions replaced by their respective exponential
57195719
expressions.
57205720
@@ -5734,18 +5734,18 @@ cdef class Expression(CommutativeRingElement):
57345734
sage: tanh(x).exponentialize()
57355735
-(e^(-x) - e^x)/(e^(-x) + e^x)
57365736
5737-
TESTS::
5737+
TESTS:
57385738
5739-
Check that ``u(x).exponentialize().demoivre(force=True)``
5740-
is identity.
5739+
Check that ``u(x).exponentialize().demoivre(force=True)``
5740+
is identity::
57415741
57425742
sage: x = SR.var("x")
57435743
sage: all([bool(u(x).exponentialize().demoivre(force=True) == u(x))
57445744
....: for u in (sin, cos, tan, csc, sec, cot,
57455745
....: sinh, cosh, tanh, csch, sech, coth)])
57465746
True
57475747
5748-
Check that differentiation and exponentialization commute:
5748+
Check that differentiation and exponentialization commute::
57495749
57505750
sage: x = SR.var("x")
57515751
sage: all([bool(u(x).diff(x).exponentialize() ==
@@ -5758,8 +5758,8 @@ cdef class Expression(CommutativeRingElement):
57585758
return Exponentialize(self)()
57595759

57605760
def demoivre(self, force=False):
5761-
"""
5762-
Returns this symbolic expression with complex exponentials
5761+
r"""
5762+
Return this symbolic expression with complex exponentials
57635763
(optionally all exponentials) replaced by (at least partially)
57645764
trigonometric/hyperbolic expressions.
57655765
@@ -5775,10 +5775,10 @@ cdef class Expression(CommutativeRingElement):
57755775
sage: exp(x).demoivre(force=True)
57765776
cosh(x) + sinh(x)
57775777
5778-
TESTS::
5778+
TESTS:
57795779
5780-
Check that de Moivre transformation correctly commutes
5781-
with differentiation:
5780+
Check that de Moivre transformation correctly commutes
5781+
with differentiation::
57825782
57835783
sage: x = SR.var("x")
57845784
sage: f = function("f")

src/sage/symbolic/expression_conversions.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,7 @@ def derivative(self, ex, operator):
23762376
return operator(*[self(_) for _ in ex.operands()])
23772377

23782378
class Exponentialize(ExpressionTreeWalker):
2379-
# Implementation note : this code is executed once at first
2379+
# Implementation note: this code is executed once at first
23802380
# reference in the code using it, therefore avoiding rebuilding
23812381
# the same canned results dictionary at each call.
23822382
from sage.functions.hyperbolic import sinh, cosh, sech, csch, tanh, coth
@@ -2387,7 +2387,7 @@ class Exponentialize(ExpressionTreeWalker):
23872387
from sage.rings.integer import Integer
23882388
from sage.symbolic.ring import SR
23892389
from sage.calculus.var import function
2390-
half = Integer(1)/Integer(2)
2390+
half = Integer(1) / Integer(2)
23912391
two = Integer(2)
23922392
x = SR.var("x")
23932393
CircDict = {
@@ -2405,26 +2405,29 @@ class Exponentialize(ExpressionTreeWalker):
24052405
coth: (-(exp(-x) + exp(x))/(exp(-x) - exp(x))).function(x)
24062406
}
24072407
Circs = list(CircDict.keys())
2408+
24082409
def __init__(self, ex):
24092410
"""
24102411
A class that walks a symbolic expression tree and replace circular
24112412
and hyperbolic functions by their respective exponential
24122413
expressions.
24132414
2414-
EXAMPLES ::
2415+
EXAMPLES::
24152416
24162417
sage: from sage.symbolic.expression_conversions import Exponentialize
24172418
sage: d=Exponentialize(sin(x))
24182419
sage: d(sin(x))
24192420
-1/2*I*e^(I*x) + 1/2*I*e^(-I*x)
24202421
sage: d(cosh(x))
24212422
1/2*e^(-x) + 1/2*e^x
2422-
24232423
"""
24242424
self.ex = ex
2425+
24252426
def composition(self, ex, op):
2426-
"""
2427-
EXAMPLES ::
2427+
r"""
2428+
Return the composition of ``self`` with ``ex`` by ``op``.
2429+
2430+
EXAMPLES::
24282431
24292432
sage: x = SR.var("x")
24302433
sage: from sage.symbolic.expression_conversions import Exponentialize
@@ -2441,14 +2444,15 @@ def composition(self, ex, op):
24412444

24422445
class DeMoivre(ExpressionTreeWalker):
24432446
def __init__(self, ex, force=False):
2444-
"""
2447+
r"""
24452448
A class that walks a symbolic expression tree and replaces
24462449
occurences of complex exponentials (optionally, all
24472450
exponentials) by their respective trigonometric expressions.
24482451
2449-
INPUT::
2452+
INPUT:
24502453
2451-
- ``force`` -- Boolean (default is False) : replace ``exp(x)`` with ``cosh(x) + sinh(x)``.
2454+
- ``force`` -- boolean (default: ``False``); replace `\exp(x)`
2455+
with `\cosh(x) + \sinh(x)`
24522456
24532457
EXAMPLES::
24542458
@@ -2459,10 +2463,12 @@ def __init__(self, ex, force=False):
24592463
(cos(b) + I*sin(b))*e^a
24602464
"""
24612465
self.ex = ex
2462-
self.force=force
2466+
self.force = force
24632467

24642468
def composition(self, ex, op):
24652469
"""
2470+
Return the composition of ``self`` with ``ex`` by ``op``.
2471+
24662472
EXAMPLES::
24672473
24682474
sage: x, a, b = SR.var('x, a, b')
@@ -2473,15 +2479,16 @@ def composition(self, ex, op):
24732479
sage: s.composition(q, q.operator())
24742480
(cos(b) + I*sin(b))*e^a
24752481
"""
2476-
from sage.functions.hyperbolic import sinh, cosh
24772482
from sage.functions.log import exp
2478-
from sage.functions.trig import sin, cos
2479-
from sage.rings.imaginary_unit import I
2480-
from sage.symbolic.ring import SR
24812483
if op is not exp:
24822484
# return super(DeMoivre, self).composition(ex, op)
2483-
return op(*[self(_) for _ in ex.operands()])
2484-
arg=self(ex.operands()[0])()
2485+
return op(*[self(oper) for oper in ex.operands()])
2486+
2487+
from sage.rings.imaginary_unit import I
2488+
from sage.symbolic.ring import SR
2489+
from sage.functions.hyperbolic import sinh, cosh
2490+
from sage.functions.trig import sin, cos
2491+
arg = self(ex.operands()[0])()
24852492
w0, w1 = (SR.wild(u) for u in range(2))
24862493
D = arg.match(w0 + I*w1)
24872494
if D is not None:

0 commit comments

Comments
 (0)