ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 15 Dec 2022 11:06:06 +0100Simplify_full() and collect() togetherhttps://ask.sagemath.org/question/65355/simplify_full-and-collect-together/Dear all,
I am a novice with sagemath, and I use only a very small subset of its functionalities. I need to simplify the following expression, without using definitions:
var('c,f')
p_star_1 = ( (c+1)*f^2 - (2*c +1)*f - c - f ) / 2*(f^2-*2*f-1)
Here, I report the output of ``` p_star_1```, which in the real program is ```p_star_1 = something.simplify_full() ```.
I would like to express this as:
p_star_1 = c/2 + (2-f)*(1+ f)/(2*(1+2*f-f^2))
But using ``` collect.(c) ``` is not sufficient! How can I do this?
EDIT: I corrected the expression again, sorry.Boyko_BuThu, 15 Dec 2022 11:06:06 +0100https://ask.sagemath.org/question/65355/How to find a short form of recursive defined sequences?https://ask.sagemath.org/question/48820/how-to-find-a-short-form-of-recursive-defined-sequences/Hi, I'm new to sagemath.
Is there any way to so calculate/solve/find a short version of a recursive defined sequence?
E.g. I have a sequence like: (Fibonacci)
def f(n):
if n == 0:
return 0
if n == 1:
return 1
if n == 2:
return 1
else:
return f(n-1)+f(n-2)
How can I compute a short form of $f_n$?
-----
In this example case $f_n$ would be:
$f_n=\frac{1}{\sqrt{5}} (\frac{1+\sqrt{5}}{2})^n - \frac{1}{\sqrt{5}} (\frac{1-\sqrt{5}}{2})^n$
-----
Edit:
Thanks to Emmanuel I found how to solve those equations in pdf:
from sympy import Function,rsolve
from sympy.abc import n
u = Function('u')
f = u(n-1)+u(n-2)-u(n)
rsolve(f, u(n), {u(0):0,u(1):1})
-sqrt(5)*(1/2 - sqrt(5)/2)**n/5 + sqrt(5)*(1/2 + sqrt(5)/2)**n/5maanWed, 20 Nov 2019 17:33:55 +0100https://ask.sagemath.org/question/48820/