<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, How do I use recursion and get Maple fast?</title>
    <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Wed, 10 Jun 2026 18:51:37 GMT</lastBuildDate>
    <pubDate>Wed, 10 Jun 2026 18:51:37 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, How do I use recursion and get Maple fast?</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, How do I use recursion and get Maple fast?</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast</link>
    </image>
    <item>
      <title>Avoid recursion...</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#answer66076</link>
      <itunes:summary>&lt;p&gt;...like the plague.&lt;/p&gt;
&lt;p&gt;Just do a simple loop:&lt;/p&gt;
&lt;p&gt;restart:&lt;br /&gt;
P:=15000:E[1]:=1:&lt;br /&gt;
for n from 1 to 20 do&amp;nbsp; E[n+1]:=E[n]+E[n]*(P-E[n])/P*10.0&amp;nbsp; od;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;...like the plague.&lt;/p&gt;
&lt;p&gt;Just do a simple loop:&lt;/p&gt;
&lt;p&gt;restart:&lt;br /&gt;
P:=15000:E[1]:=1:&lt;br /&gt;
for n from 1 to 20 do&amp;nbsp; E[n+1]:=E[n]+E[n]*(P-E[n])/P*10.0&amp;nbsp; od;&lt;/p&gt;</description>
      <guid>66076</guid>
      <pubDate>Mon, 11 May 2009 21:37:33 Z</pubDate>
      <itunes:author>Thomas
 Unger
</itunes:author>
      <author>Thomas
 Unger
</author>
    </item>
    <item>
      <title>option remember</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#answer66075</link>
      <itunes:summary>&lt;p&gt;Note that you can simplify the rhs&lt;/p&gt;
&lt;pre&gt;
&amp;gt; simplify( E(x+1)=E(x)+(E(x)*(P-E(x)))/P*10 );
                                   E(x) (-11 P + 10 E(x))
                      E(x + 1) = - ----------------------
                                             P
&lt;/pre&gt;
&lt;p&gt;Suppose that you construct a procedure that computes E(x), and which does so by calling E(x-1).&lt;/p&gt;
&lt;pre&gt;
&amp;gt; simplify( E(x)=E(x-1)+(E(x-1)*(P-E(x-1)))/P*10 );
                             E(x - 1) (-11 P + 10 E(x - 1))
                    E(x) = - ------------------------------
                                           P
&lt;/pre&gt;
&lt;p&gt;You should probably first see whether the rsolve command can do anything nice with it.&lt;/p&gt;
&lt;p&gt;If not, then construct procedure E by with &lt;b&gt;`option remember`&lt;/b&gt; so that each separate inner invocation of E(x-1) does not needlessly duplicate each others' subcomputations. (You want to avoid unnecessary growth of the computation tree.)&lt;/p&gt;
&lt;pre&gt;
&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;    -E(x-1)*(-11*P+10*E(x-1))/P;
&amp;gt; end proc:
&amp;gt; E(1):=1:
&lt;/pre&gt;
&lt;p&gt;Now observe how the length of the exact results grows, and how the computation time grows.&lt;/p&gt;
&lt;pre&gt;
&amp;gt; for i from 10 to 18 do
&amp;gt; st:=time():
&amp;gt; print([length(E(i)), time()-st]);
&amp;gt; end do:
                                  [3270, 0.]

                                  [6541, 0.]

                                [13080, 0.004]

                                [26159, 0.008]

                                [52316, 0.020]

                                [104630, 0.080]

                                [209260, 0.292]

                                [418520, 1.128]

                                [837038, 4.345]
&lt;/pre&gt;
&lt;p&gt;Deduce how long the result for E(20) would be, and how much time it would take to compute it.&lt;/p&gt;
&lt;p&gt;Try it all again, but with evalf(...) around the inside of the E procedure. Try it also without the &lt;b&gt;option remember&lt;/b&gt;, and find the timings and lengths for i=1..6, and make inferences.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Note that you can simplify the rhs&lt;/p&gt;
&lt;pre&gt;
&amp;gt; simplify( E(x+1)=E(x)+(E(x)*(P-E(x)))/P*10 );
                                   E(x) (-11 P + 10 E(x))
                      E(x + 1) = - ----------------------
                                             P
&lt;/pre&gt;
&lt;p&gt;Suppose that you construct a procedure that computes E(x), and which does so by calling E(x-1).&lt;/p&gt;
&lt;pre&gt;
&amp;gt; simplify( E(x)=E(x-1)+(E(x-1)*(P-E(x-1)))/P*10 );
                             E(x - 1) (-11 P + 10 E(x - 1))
                    E(x) = - ------------------------------
                                           P
&lt;/pre&gt;
&lt;p&gt;You should probably first see whether the rsolve command can do anything nice with it.&lt;/p&gt;
&lt;p&gt;If not, then construct procedure E by with &lt;b&gt;`option remember`&lt;/b&gt; so that each separate inner invocation of E(x-1) does not needlessly duplicate each others' subcomputations. (You want to avoid unnecessary growth of the computation tree.)&lt;/p&gt;
&lt;pre&gt;
&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;    -E(x-1)*(-11*P+10*E(x-1))/P;
&amp;gt; end proc:
&amp;gt; E(1):=1:
&lt;/pre&gt;
&lt;p&gt;Now observe how the length of the exact results grows, and how the computation time grows.&lt;/p&gt;
&lt;pre&gt;
&amp;gt; for i from 10 to 18 do
&amp;gt; st:=time():
&amp;gt; print([length(E(i)), time()-st]);
&amp;gt; end do:
                                  [3270, 0.]

                                  [6541, 0.]

                                [13080, 0.004]

                                [26159, 0.008]

                                [52316, 0.020]

                                [104630, 0.080]

                                [209260, 0.292]

                                [418520, 1.128]

                                [837038, 4.345]
&lt;/pre&gt;
&lt;p&gt;Deduce how long the result for E(20) would be, and how much time it would take to compute it.&lt;/p&gt;
&lt;p&gt;Try it all again, but with evalf(...) around the inside of the E procedure. Try it also without the &lt;b&gt;option remember&lt;/b&gt;, and find the timings and lengths for i=1..6, and make inferences.&lt;/p&gt;</description>
      <guid>66075</guid>
      <pubDate>Mon, 11 May 2009 21:38:52 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>recursion</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#answer66078</link>
      <itunes:summary>&lt;p&gt;I used your post to try to solve my equation, but Maple evaluate a lot of time (I take 2 hours, and no result are shown), so what can I do? &lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I used your post to try to solve my equation, but Maple evaluate a lot of time (I take 2 hours, and no result are shown), so what can I do? &lt;/p&gt;</description>
      <guid>66078</guid>
      <pubDate>Mon, 11 May 2009 22:42:08 Z</pubDate>
      <itunes:author>pichulonco90</itunes:author>
      <author>pichulonco90</author>
    </item>
    <item>
      <title>sketchy way</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#answer66085</link>
      <itunes:summary>&lt;pre&gt;
P:=15000:
&amp;gt; S:=proc(n) option remember;
&amp;gt; local r;
&amp;gt; if n &amp;lt; 11 then 
&amp;gt;&amp;nbsp;&amp;nbsp; -S(n-1)*(-11*P+10*S(n-1))/P;
&amp;gt; elif n &amp;lt; 20 then # ignore small constant 
&amp;gt;&amp;nbsp;&amp;nbsp; -S(n-1)*S(n-1)/1500;
&amp;gt; else
&amp;gt;&amp;nbsp;&amp;nbsp; r:= evalf(S(n-1));
&amp;gt;&amp;nbsp;&amp;nbsp; -1/1500*r*r;
&amp;gt; end if;
&amp;gt; end proc:
&amp;gt; S(1):=1:

That is exact for small n and gives a small error beyond, since
10*Q(10)/P ~ -.2280046013e18 has much more decimal places

nTst:=16;
&amp;gt; S(nTst): evalf(%);
&amp;gt; Q(nTst): evalf(%);
&amp;gt; Q(nTst) - S(nTst): evalf[1000](%): evalf(%);

Now solve recurrence for ignoring '11'

&amp;gt; f(n)=-f(n-1)*f(n-1)/q;
&amp;gt; rsolve({%}, f(k));
&amp;gt; simplify(%) assuming (k::posint, 0 &amp;lt; q, f10 &amp;lt; 0);
&amp;gt; #simplify(%, symbolic);
&amp;gt; #eval(%, k=0);
&amp;gt; #eval(%%, k=1);
&amp;gt; #eval(%%%, k=2);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2 )&amp;nbsp; (-2&amp;nbsp; + 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -f(0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q

Then the following equals S and is fast, error see above,
f(0) stands for S(10)

&amp;gt; T:=proc(n) option remember;
&amp;gt; local r, f0,q;
&amp;gt; q:=10/P;
&amp;gt; if n &amp;lt; 11 then 
&amp;gt;&amp;nbsp;&amp;nbsp; -T(n-1)*(-11+T(n-1)/1500);
&amp;gt; else
&amp;gt;&amp;nbsp;&amp;nbsp; f0:= T(10);
&amp;gt;&amp;nbsp;&amp;nbsp; r:= f0*q;
&amp;gt;&amp;nbsp;&amp;nbsp; -r^(2^(n - 10))/q;
&amp;gt; end if;
&amp;gt; end proc:
&amp;gt; T(1):=1:

A test:

&amp;gt; nTst:=19;
&amp;gt; Sn:=S(nTst): evalf(%);
&amp;gt; -(S(nTst-2)/1500)^(2^(2)) * 1500: evalf(%);
&amp;gt; Sn+(S(10)/1500)^(2^(nTst-10)) * 1500;: evalf(%);
&amp;gt; Tn:=T(nTst): 
&amp;gt; Sn - Tn; #evalf(%);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0

Hope I have not an index-shifting error in it (test it, all n).

Modify using evalf for lager n.

In case of trouble upload your sheet, after copying above to it.
&lt;/pre&gt;</itunes:summary>
      <description>&lt;pre&gt;
P:=15000:
&amp;gt; S:=proc(n) option remember;
&amp;gt; local r;
&amp;gt; if n &amp;lt; 11 then 
&amp;gt;&amp;nbsp;&amp;nbsp; -S(n-1)*(-11*P+10*S(n-1))/P;
&amp;gt; elif n &amp;lt; 20 then # ignore small constant 
&amp;gt;&amp;nbsp;&amp;nbsp; -S(n-1)*S(n-1)/1500;
&amp;gt; else
&amp;gt;&amp;nbsp;&amp;nbsp; r:= evalf(S(n-1));
&amp;gt;&amp;nbsp;&amp;nbsp; -1/1500*r*r;
&amp;gt; end if;
&amp;gt; end proc:
&amp;gt; S(1):=1:

That is exact for small n and gives a small error beyond, since
10*Q(10)/P ~ -.2280046013e18 has much more decimal places

nTst:=16;
&amp;gt; S(nTst): evalf(%);
&amp;gt; Q(nTst): evalf(%);
&amp;gt; Q(nTst) - S(nTst): evalf[1000](%): evalf(%);

Now solve recurrence for ignoring '11'

&amp;gt; f(n)=-f(n-1)*f(n-1)/q;
&amp;gt; rsolve({%}, f(k));
&amp;gt; simplify(%) assuming (k::posint, 0 &amp;lt; q, f10 &amp;lt; 0);
&amp;gt; #simplify(%, symbolic);
&amp;gt; #eval(%, k=0);
&amp;gt; #eval(%%, k=1);
&amp;gt; #eval(%%%, k=2);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2 )&amp;nbsp; (-2&amp;nbsp; + 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -f(0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; q

Then the following equals S and is fast, error see above,
f(0) stands for S(10)

&amp;gt; T:=proc(n) option remember;
&amp;gt; local r, f0,q;
&amp;gt; q:=10/P;
&amp;gt; if n &amp;lt; 11 then 
&amp;gt;&amp;nbsp;&amp;nbsp; -T(n-1)*(-11+T(n-1)/1500);
&amp;gt; else
&amp;gt;&amp;nbsp;&amp;nbsp; f0:= T(10);
&amp;gt;&amp;nbsp;&amp;nbsp; r:= f0*q;
&amp;gt;&amp;nbsp;&amp;nbsp; -r^(2^(n - 10))/q;
&amp;gt; end if;
&amp;gt; end proc:
&amp;gt; T(1):=1:

A test:

&amp;gt; nTst:=19;
&amp;gt; Sn:=S(nTst): evalf(%);
&amp;gt; -(S(nTst-2)/1500)^(2^(2)) * 1500: evalf(%);
&amp;gt; Sn+(S(10)/1500)^(2^(nTst-10)) * 1500;: evalf(%);
&amp;gt; Tn:=T(nTst): 
&amp;gt; Sn - Tn; #evalf(%);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0

Hope I have not an index-shifting error in it (test it, all n).

Modify using evalf for lager n.

In case of trouble upload your sheet, after copying above to it.
&lt;/pre&gt;</description>
      <guid>66085</guid>
      <pubDate>Wed, 13 May 2009 00:17:44 Z</pubDate>
      <itunes:author>Axel Vogt</itunes:author>
      <author>Axel Vogt</author>
    </item>
    <item>
      <title>note</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#comment66077</link>
      <itunes:summary>&lt;p&gt;It may be worth noting, for the benefit of the understand of the OP, that the use of 10.0 will bring about floating-point arithmetic (similar to using evalf). Also, the use of [] table references will have pretty much the same effect as using procedure calls with option remember.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;It may be worth noting, for the benefit of the understand of the OP, that the use of 10.0 will bring about floating-point arithmetic (similar to using evalf). Also, the use of [] table references will have pretty much the same effect as using procedure calls with option remember.&lt;/p&gt;</description>
      <guid>66077</guid>
      <pubDate>Mon, 11 May 2009 21:41:16 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>hm</title>
      <link>http://www.mapleprimes.com/questions/37377-How-Do-I-Use-Recursion-And-Get-Maple-Fast?ref=Feed:MaplePrimes:How do I use recursion and get Maple fast?:Comments#comment66079</link>
      <itunes:summary>&lt;pre&gt;
&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;   -E(x-1)*(-11*P+10*E(x-1))/P;
&amp;gt; end proc:
&amp;gt; E(1):=1:
&amp;gt; kernelopts(printbytes=false):
&amp;gt; st:=time(): length(E(20)); time()-st;
                                    3348149

                                    92.177

&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;   evalf( -E(x-1)*(-11*P+10*E(x-1))/P );
&amp;gt; end proc:
&amp;gt; E(1):=1:
&amp;gt; st:=time(): E(20); time()-st;
                                             17778
                             -0.5132751215 10

                                      0.
&lt;/pre&gt;</itunes:summary>
      <description>&lt;pre&gt;
&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;   -E(x-1)*(-11*P+10*E(x-1))/P;
&amp;gt; end proc:
&amp;gt; E(1):=1:
&amp;gt; kernelopts(printbytes=false):
&amp;gt; st:=time(): length(E(20)); time()-st;
                                    3348149

                                    92.177

&amp;gt; restart:
&amp;gt; P:=15000:
&amp;gt; E:=proc(x) option remember;
&amp;gt;   evalf( -E(x-1)*(-11*P+10*E(x-1))/P );
&amp;gt; end proc:
&amp;gt; E(1):=1:
&amp;gt; st:=time(): E(20); time()-st;
                                             17778
                             -0.5132751215 10

                                      0.
&lt;/pre&gt;</description>
      <guid>66079</guid>
      <pubDate>Mon, 11 May 2009 23:12:19 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
  </channel>
</rss>