2
$\begingroup$

I want to construct polynomials (or just function) $f_n$ from $f_{n-1}$ using mathematica. For some kind of reason, I didn't manage to do this. So basically something like a recurrence table, but for function.

I do have it for sagemath, so perhaps if possible, I'd like somehow to convert that to mathematical. I have something like this

def T(x,y,n): 
return x if n == 0 else x^2*T(y^2*x,2y+4,n-1)

In fact my function is actually more complicated, but just to give an example. Is there a way to write the analogue of this in mathematica?

Thank you

$\endgroup$
1
  • 2
    $\begingroup$ Just to get you started T[x_, y_, n_] := 0 /; n == 0 $\endgroup$
    – yarchik
    Commented Dec 1, 2021 at 23:33

2 Answers 2

2
$\begingroup$

Try this:

T[x_, y_, n_?IntegerQ] /; n >= 0 := If[n === 0, x, Expand[x^2*T[y^2*x, 2 y + 4, n - 1]]]

Test:

T[x, y, 0]
(*x*)
T[x, y, 1]
(*x^3 y^2*)
T[x, y, 2]
(*16 x^5 y^6 + 16 x^5 y^7 + 4 x^5 y^8*)
T[x, y, 3]
(*589824 x^7 y^10 + 2162688 x^7 y^11 + 3457024 x^7 y^12 + 3145728 x^7 y^13 + 1781760 x^7 y^14 + 643072 x^7 y^15 + 144384 x^7 y^16 + 18432 x^7 y^17 + 1024 x^7 y^18*)
$\endgroup$
1
  • 1
    $\begingroup$ Oh wauw, had no idea this was possible. Thanks! $\endgroup$ Commented Dec 2, 2021 at 1:07
5
$\begingroup$

To include memorization

Clear[T]

T[x_, y_, 0] = x;
T[x_, y_, n_Integer?Positive] := 
  T[x, y, n] = x^2*T[y^2*x, 2 y + 4, n - 1] // Simplify;

The first several:

T[x, y, #] & /@ Range[0, 5]//Column

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.