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

Commit aa9339a

Browse files
EmmanuelCharpentierslel
authored andcommitted
Half_angle : code (not yet commented).
1 parent 7282b2b commit aa9339a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/sage/symbolic/expression.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,6 +5712,13 @@ cdef class Expression(CommutativeRingElement):
57125712
from sage.symbolic.expression_conversions import SubstituteFunction
57135713
return SubstituteFunction(self, original, new)()
57145714

5715+
def half_angle(self):
5716+
"""
5717+
TODO
5718+
"""
5719+
from sage.symbolic.expression_conversions import HalfAngle
5720+
return HalfAngle(self)()
5721+
57155722
def substitution_delayed(self, pattern, replacement):
57165723
"""
57175724
Replace all occurrences of pattern by the result of replacement.

src/sage/symbolic/expression_conversions.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,44 @@ def derivative(self, ex, operator):
23752375
else:
23762376
return operator(*[self(_) for _ in ex.operands()])
23772377

2378+
# Half_angle transformation. Sometimes useful in integration
2379+
2380+
class HalfAngle(ExpressionTreeWalker):
2381+
# Code executed once at first class reference : create canned formulae.
2382+
from sage.functions.hyperbolic import sinh, cosh, sech, csch, tanh, coth
2383+
from sage.functions.trig import sin, cos, sec, csc, tan, cot
2384+
from sage.rings.integer import Integer
2385+
from sage.calculus.var import function
2386+
from sage.symbolic.ring import SR
2387+
x = SR.var("x")
2388+
HalvesDict = {
2389+
sin: Integer(2)*tan(Integer(1)/Integer(2)*x)/(tan(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1)).function(x),
2390+
cos: -(tan(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1))/(tan(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1)).function(x),
2391+
tan: -Integer(2)*tan(Integer(1)/Integer(2)*x)/(tan(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1)).function(x),
2392+
csc: Integer(1)/Integer(2)*(tan(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1))/tan(Integer(1)/Integer(2)*x).function(x),
2393+
sec: -(tan(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1))/(tan(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1)).function(x),
2394+
cot: -Integer(1)/Integer(2)*(tan(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1))/tan(Integer(1)/Integer(2)*x).function(x),
2395+
sinh: -Integer(2)*tanh(Integer(1)/Integer(2)*x)/(tanh(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1)).function(x),
2396+
cosh: -(tanh(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1))/(tanh(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1)).function(x),
2397+
tanh: Integer(2)*tanh(Integer(1)/Integer(2)*x)/(tanh(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1)).function(x),
2398+
csch: -Integer(1)/Integer(2)*(tanh(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1))/tanh(Integer(1)/Integer(2)*x).function(x),
2399+
sech: -(tanh(Integer(1)/Integer(2)*x)**Integer(2) - Integer(1))/(tanh(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1)).function(x),
2400+
coth: Integer(1)/Integer(2)*(tanh(Integer(1)/Integer(2)*x)**Integer(2) + Integer(1))/tanh(Integer(1)/Integer(2)*x).function(x)
2401+
}
2402+
Halves = list(HalvesDict.keys())
2403+
def __init__(self, ex):
2404+
"""
2405+
TODO
2406+
"""
2407+
self.ex = ex
2408+
def composition(self, ex, op):
2409+
"""
2410+
TODO
2411+
"""
2412+
if op in self.Halves:
2413+
return self.HalvesDict.get(op)(*[self(_) for _ in ex.operands()])
2414+
return super(HalfAngle, self).composition(ex, op)
2415+
23782416
class HoldRemover(ExpressionTreeWalker):
23792417
def __init__(self, ex, exclude=None):
23802418
"""

0 commit comments

Comments
 (0)