1 | initial version |
instead of symbolic functions, you could just use a (recursive) Python function:
def f(n):
if n == 0:
return lambda a,b : a*b
else:
return lambda a,b : a + b * f(n-1)(a+b, a-b)
Then you can do:
sage: f(0)(2,3)
6
sage: f(3)(x, x+1)
(8*(2*x + 1)*(x + 1) + 1)*(x + 1) + x
sage: solve(f(3)(x, x+1)==1, x)
[x == -1/2*(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3)*(I*sqrt(3) + 1) - 1/144*(I*sqrt(3) - 1)/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6, x == -1/2*(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3)*(-I*sqrt(3) + 1) + 1/144*(I*sqrt(3) + 1)/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6, x == (1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 1/72/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6]
For the latter, if you want algrbraic numbers, you can define x
not to be just a symbol (leading to f(3)(x, x+1)
being a symbolic expression) but a polynomial indeterminate:
sage: R.<x> = ZZ[]
sage: (f(3)(x, x+1)-1).roots() # no integrer root
[]
sage: (f(3)(x, x+1)-1).roots(QQbar)
[(-0.3779244420252417?, 1),
(-1.061037778987380? - 0.4440885163776650?*I, 1),
(-1.061037778987380? + 0.4440885163776650?*I, 1)]
2 | No.2 Revision |
instead of symbolic functions, you could just use a (recursive) Python function:
def f(n):
if n == 0:
return lambda a,b : a*b
else:
return lambda a,b : a + b * f(n-1)(a+b, a-b)
Then you can do:
sage: f(0)(2,3)
6
sage: f(3)(x, x+1)
(8*(2*x + 1)*(x + 1) + 1)*(x + 1) + x
sage: solve(f(3)(x, x+1)==1, x)
[x == -1/2*(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3)*(I*sqrt(3) + 1) - 1/144*(I*sqrt(3) - 1)/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6, x == -1/2*(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3)*(-I*sqrt(3) + 1) + 1/144*(I*sqrt(3) + 1)/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6, x == (1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 1/72/(1/288*sqrt(89)*sqrt(3) + 49/864)^(1/3) - 5/6]
For the latter, if you want algrbraic numbers, you can define x
not to be just a symbol (leading to f(3)(x, x+1)
being a symbolic expression) but a polynomial indeterminate:
sage: R.<x> = ZZ[]
sage: (f(3)(x, x+1)-1).roots() # no integrer root
[]
sage: (f(3)(x, x+1)-1).roots(QQbar)
x+1)-1).roots(QQbar) # 3 algebraic roots, each with multiplicity 1
[(-0.3779244420252417?, 1),
(-1.061037778987380? - 0.4440885163776650?*I, 1),
(-1.061037778987380? + 0.4440885163776650?*I, 1)]