Items tagged with recursion

This is reduced from another forum.

restart;
e1 := 12*g^2+12*h^2+4*i^2+3*j^2=684;
e2 :=  12*l^2+12*m^2+4*n^2+3*o^2=684;
e3 := 12*q^2+12*r^2+4*s^2+3*t^2=172;
e4 := 12*v^2+12*w^2+4*x^2+3*y^2=108;
e5 := 12*g*l+12*h*m+4*n*i+3*j*o=-84;
e6 := 12*g*q+12*h*r+4*s*i+3*j*t=-84;
e7 := 12*g*v+12*h*w+4*x*i+3*j*y=-84;
e8 := 12*l*q+12*m*r+4*n*s+3*o*t=-84;
e9 := 12*l*v+12*m*w+4*n*x+3*o*y=-84;
e10 := 12*q*v+12*r*w+4*s*x+3*y*t=-84;
e11 := g+h+i+j=-1;
e12 := l+m+n+o=-1;
e13 := q+r+s+t=-1;
e14 := v+w+x+y=-1;
e15 := h*i+m*n+3*s*r+4*x*w=-21;
e16 := g*i+l*n+3*s*q+4*x*v=-21;
e17 := i+n+3*s+4*x=-3;
e18 := g*h+m*l+3*q*r+4*w*v=-7;
e19 := h+m+3*r+4*w=-1;
e20 := g+l+3*q+4*v=-1;
e21 := i*j+o*n+3*s*t+4*x*y=-84;
e22 := j*h+o*m+3*r*t+4*y*w=-28;
e23 := j*g+o*l+3*q*t+4*y*v=-28;
e24 := j+o+3*t+4*y=-4;
e25 := j^2+o^2+3*t^2+4*y^2=144;
e26 := i^2+n^2+3*s^2+4*x^2=129;
e27 := h^2+m^2+3*r^2+4*w^2=57;
e28 := g^2+l^2+3*q^2+4*r^2=57;

eqset := {e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15,
          e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28};
for s in eqset do print(s) end do;

Error, too many levels of recursion

If I then do

S := {1,2,3,6,3,6,8,2,3,6};

for s in S do print(s) end do;

Then,

for s in eqset do print(s) end do;

has the correct output.

What am I doing wrong?

Tom Dean

I was trying to write a procedure that would compute a simple linear equation using the Extended Euclidean Algorithm. I was thinking of a procedure like the following:

solveEeaMatrix := proc (a::list, b::list) 
 local c::list;  
 c := a -iquo(a[1],b[1])*b;  
 print(c);  
 while (c[1] <> gcd(a[1],b[1]) do 
 ...

I am basically stuck at this part as

1) I don't know how to setup a multi-dimensional array that could dynamically grow(as a possible solution).

2) I can't come up with a recursive function that could possibly take care of this.

In short, if I am given for example an equation like: 84*x+203*y = 14

I will transform it into 2 linear equation as follow:
row0 := [203, 0, 1] row1 := [84, 1, 0] Subsequently, I will perform the following:

c := a -iquo(a[1],b[1])*b;  

Where aand b are both lists and arguments of the procedure and cbeing another list and a local variable.

But I don't know how to do the following programmatically:

row3 := row1-iquo(row1[1], row2[1])*row2;
row4 := row2-iquo(row2[1], row3[1])*row3;
row5 := row3-iquo(row3[1], row4[1])*row4;
and so on ...                  

Any hint would be appreciated.

Please Sir/Ma, I'm trying to generate a recurrent relations of this series and I try to use "if" "else" condition but I didn't get it right. Any one with useful suggestions. Appreciate 

 

restart;
Y[0] := A; Y[1] := B;
if k = a then delta(k-a) := 1 else 0 end if;
                               0
for k from 0 to 10 do Y[k+2] := solve(add(delta(i-1)*(k-i+1)*(k-i+2)*Y[k-i+2], i = 0 .. k)+add((delta(i)-delta(i-1))*(k-i+1)*Y[k-i+1], i = 0 .. k)+lambda*Y[k] = 0, Y[k+2]) end do;
y := sum(Y[j]*x^j, j = 0 .. 10);
 

I copy a program from a book and try to run it, but when i try to run it return:

too many levels of recursion

Here is my program:

Hope every one can help me solve this problem. Thank!

In Maple V, Release 4 (1996):

 

T:=table():
i:=1:N:=5000;

for i from i to N  
do
   T[i]:=T[i+1]:
   T[i+1]:=1;
   eval(T[1]);
od:
print(i);

for i from i to N  
do
   T[i]:=T[i+1]:
   T[i+1]:=1;
   eval(T[1]);
od:
print(i);

I receive this output:

N := 5000
Error, too many levels of recursion
3607
5001

Can You explain this occurence, as well as the following one:

In Maple V, Release 4 (1996):

 

T:=table():
i:=1:N:=5000;

for i from i to N  
do
  T[i]:=T[i+1]:
  eval(T[1]);
od:
print(i);
 
for i from i to N  
do
  T[i]:=T[i+1]:
  eval(T[1]);
od:
print(i);;

gives:

N := 5000
Error, too many levels of recursion
3607
Error, too many levels of recursion
3607

How does one control allowance for recursion depth?

Is there a way to apply op to an expression and get back every possible operand and the corresponding list value?  I sometimes don't know how far to go with a list of inputs to get what I want.

Hi, I'm new to Maple and I have to produce a recursive procedure with the nomenclature Puis:=proc(X,n::integer) which calculates X^n with:

for n<0   ->   1/(X^(-n))

for n=0  ->   1

for n being an even integer   ->   X^(n/2) * X^(n/2)

for n being an odd integer   ->   X*X^(n-1)

The procedure I produced is:

Puis:=proc(X,n::integer)
option remember;
if n<0 then Puis(X,-n);
elif n=0 then 1;
elif rem(n,2,x)=0 then Puis(X,n);
else X*Puis(X,n-1);
end if;
end proc;

 

i don't have any eror up to this point, but when I try to evaluate, only Puis(4,0) works

Puis(4,-1);
Error, (in content) too many levels of recursion
Puis(4,0);
                               1
Puis(4,3);
Error, (in content) too many levels of recursion
Puis(4,4);
Error, (in content) too many levels of recursion

 

I was wondering what was wrong with my procedure, I changed the 1/(X^(-n)) with X^n and X^(n/2)*X^(n/2) for X^n because it is equivalent. I think I should put some sort of initial value to limit the recursion, but with that kind of function i really don't know how. I also tried with the X^(n/2)*X^(n/2) for the even numbers, but it says Puis expects its 2nd argument, n, to be of type integer, but received 1/2.

 

Given the sequence defined by the recursive relation a[n+1] = r*a[n](1-a[n])
You need to use the procedure iterate.
Throughout this problem you should choose initial values in the interval 0<a0<1.
(a) Let r=3/2. Calculate a moderate number of terms in the sequence (between 10 and 20). Does the sequence appear to be converging? If so to what value? Does the limit depend upon your choice of initial value? Plot the terms you have calculated
(b) Let r=2.8. Calculate a moderate number of terms in the sequence (between 10 and 20). Does the sequence appear to be converging? If so to what value? Does the limit
depend upon your choice of initial value? Plot the terms you have calculated How does this sequence differ from that in part (a).
(c) Let r=3.2. Calculate a moderate number of terms in the sequence (between 10 and 20). Show that the sequence does not appear to converging. Plot the terms you have calculated and describe how the sequence behaves in this case.
(d) Consider intermediate values between 2.8 and 3.2 to determine more precisely where the transition in behaviour takes place. Provide a few plots (no more than 4) showing the values you have investigated.
(e) Consider the values of r in the range 3.43<r<3.46. Determine as accurately as you can the value of r for which the period of oscillation doubles.
(f) As r increase further period doubling occurs. Try to find the when the sequence appears to oscillate between 8 values.
(g) Let r =3.65 and calculate a considerable number of terms (at least a few hundred) and plot your values.
(h) For r=3.65 choose a0=0.3 and then a0=0.301. Find and plot some terms in the sequence for each initial value. Determine how long the terms in the two sequences remain close together and when they begin to depart significantly from each other.

 

Hello,
I have defined a function f (x, e, y).  I give values of n: = i * h as follows:

f (x (n), w (n), t) = w * t * x;
n: = i * h;
r (n) = n;
Then I need to do this operation:
w (n) = w (n) + r (n);

w(n):=15; r(n):=30;

w(n):=w(n)+r(n);

w(n);
Error, (in w) too many levels of recursion.

How i can operate?.

Regards.

 

 

> coth;
                                    coth
> restart;
> c := 0;
                                      0
> w := -2*mu;
                                    -2 mu
> a[-1] := 0;
                                      0
> a[0] := mu*lambda*sqrt(-6*a);
                                            (1/2)
                            mu lambda (-6 a)     
> a[1] := (6*(mu*lambda^2+1))/sqrt(-6*a);
                               /         2    \
                             6 \mu lambda  + 1/
                             ------------------
                                      (1/2)    
                                (-6 a)         
> b[-1] := 0;
                                      0
> b[0] := 0;
                                      0
> b[1] := 0;
                                      0
> xi := x+w*t;
                                 x - 2 mu t
> P := sqrt(-mu)*coth(A+sqrt(-mu)*xi);
                     (1/2)     /         (1/2)             \
                (-mu)      coth\A + (-mu)      (x - 2 mu t)/
> u := a[0]+a[1]*P/(1+lambda*P)+a[-1]*(1+lambda*P)/P+b[0]*sqrt(sigma*(1+P^2/mu))/P+b[1]*sqrt(sigma*(1+P^2/mu))+b[-1]*sqrt(sigma*(1+P^2/mu))/P^2;
                 (1/2)
 mu lambda (-6 a)     

           /         2    \      (1/2)     /         (1/2)             \   
         6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   
    + ---------------------------------------------------------------------
            (1/2) /                (1/2)     /         (1/2)             \\
      (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//
> Diff(u, t)+a*u^2*(Diff(u, x))+Diff(u, `$`(x, 3));
/    /                     
| d  |                (1/2)
|--- |mu lambda (-6 a)     
| dt |                     
\    \                     

          /         2    \      (1/2)     /         (1/2)             \   \\     /          
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||     |          
   + ---------------------------------------------------------------------|| + a |mu lambda
           (1/2) /                (1/2)     /         (1/2)             \\||     |          
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////     \          

        (1/2)
  (-6 a)     

          /         2    \      (1/2)     /         (1/2)             \   \   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   |   
   + ---------------------------------------------------------------------|^2
           (1/2) /                (1/2)     /         (1/2)             \\|   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)///   

  /    /                     
  | d  |                (1/2)
  |--- |mu lambda (-6 a)     
  | dx |                     
  \    \                     

          /         2    \      (1/2)     /         (1/2)             \   \\   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||   
   + ---------------------------------------------------------------------|| +
           (1/2) /                (1/2)     /         (1/2)             \\||   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////   

  / 3 /                     
  |d  |                (1/2)
  |-- |mu lambda (-6 a)     
  |   |                     
  \   \                     

          /         2    \      (1/2)     /         (1/2)             \   \\
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   ||
   + ---------------------------------------------------------------------||
           (1/2) /                (1/2)     /         (1/2)             \\||
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)////
> value(%);
                          /                                     2\      
     /         2    \   2 |        /         (1/2)             \ |      
  12 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /      
--------------------------------------------------------------------- -
      (1/2) /                (1/2)     /         (1/2)             \\   
(-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   

                                                                         /   
                                    1                                    |   
  ---------------------------------------------------------------------- \12
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                                           /
  /         2    \      (1/2)     /         (1/2)             \          2 |
  \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda mu  \1

                                      2\\     /                     
         /         (1/2)             \ ||     |                (1/2)
   - coth\A + (-mu)      (x - 2 mu t)/ // + a |mu lambda (-6 a)     
                                              |                     
                                              \                     

          /         2    \      (1/2)     /         (1/2)             \   \   
        6 \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/   |   
   + ---------------------------------------------------------------------|^2
           (1/2) /                (1/2)     /         (1/2)             \\|   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)///   

  /                           /                                     2\       
  |       /         2    \    |        /         (1/2)             \ |       
  |     6 \mu lambda  + 1/ mu \1 - coth\A + (-mu)      (x - 2 mu t)/ /       
  |- --------------------------------------------------------------------- +
  |        (1/2) /                (1/2)     /         (1/2)             \\   
  |  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   
  \                                                                          

                                                                         /      
                                    1                                    |  /   
  ---------------------------------------------------------------------- \6 \mu
                                                                       2        
        (1/2) /                (1/2)     /         (1/2)             \\         
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//         

                                                                      /
        2    \      (1/2)     /         (1/2)             \           |
  lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda mu \1

                                         \
                                      2\\|
         /         (1/2)             \ |||
   - coth\A + (-mu)      (x - 2 mu t)/ //|
                                         |
                                         |
                                         /

                                                                       2     
                               /                                     2\      
          /         2    \   2 |        /         (1/2)             \ |      
       12 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /      
   - --------------------------------------------------------------------- +
           (1/2) /                (1/2)     /         (1/2)             \\   
     (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//   

                                                                        /       
                                    1                                   |   /   
  --------------------------------------------------------------------- \24 \mu
        (1/2) /                (1/2)     /         (1/2)             \\         
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//         

                                                    2 /
        2    \   2     /         (1/2)             \  |
  lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  \1

                                      2\\   
         /         (1/2)             \ ||   
   - coth\A + (-mu)      (x - 2 mu t)/ // +

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \84
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

  /         2    \   2     /         (1/2)             \
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/

                                          2                  \
  /                                     2\                   |
  |        /         (1/2)             \ |       (1/2)       |
  \1 - coth\A + (-mu)      (x - 2 mu t)/ /  (-mu)      lambda/

                                                                     3           
                             /                                     2\            
        /         2    \   3 |        /         (1/2)             \ |        2   
     36 \mu lambda  + 1/ mu  \1 - coth\A + (-mu)      (x - 2 mu t)/ /  lambda    
   - ------------------------------------------------------------------------- +
                                                                           3     
            (1/2) /                (1/2)     /         (1/2)             \\      
      (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \36
                                                                       4     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

  /         2    \      (1/2)     /         (1/2)             \       3   3
  \mu lambda  + 1/ (-mu)      coth\A + (-mu)      (x - 2 mu t)/ lambda  mu  

                                          3\   
  /                                     2\ |   
  |        /         (1/2)             \ | |   
  \1 - coth\A + (-mu)      (x - 2 mu t)/ / / +

                                                                         /   
                                                                         |   
                                    1                                    |   
  ---------------------------------------------------------------------- \72
                                                                       3     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                        2         
  /         2    \   3     /         (1/2)             \        2
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  lambda  

                                          2\   
  /                                     2\ |   
  |        /         (1/2)             \ | |   
  \1 - coth\A + (-mu)      (x - 2 mu t)/ / / -

                                                                         /   
                                    1                                    |   
  ---------------------------------------------------------------------- \24
                                                                       2     
        (1/2) /                (1/2)     /         (1/2)             \\      
  (-6 a)      \1 + lambda (-mu)      coth\A + (-mu)      (x - 2 mu t)//      

                                                        3        /
  /         2    \   2     /         (1/2)             \         |
  \mu lambda  + 1/ mu  coth\A + (-mu)      (x - 2 mu t)/  lambda \1

                                      2\           \
         /         (1/2)             \ |      (1/2)|
   - coth\A + (-mu)      (x - 2 mu t)/ / (-mu)     /
> simplify(%);
Error, (in simplify/tools/_zn) too many levels of recursion
>
>
>
>
pls help

for a to z1/T1 do ics[a*T1] := [g0(0, a*T1) = r, g0(1, a*T1) = s] end, this loop runs correctly for T1:=1, but gives the too many levels of recursion error for T1<1. In this loop i am inserting equations g0 in a list ics.

Please consider this code:

restart;

with(DEtools):

test:=(diff(x(t),t,t))+(diff(a(t),t,t))=0;

FirstOrderSys := convertsys(test, [], x(t), t, y, yp );

When it is executed Maple says: Error, (in is/internal) too many levels of recursion

Now if i change just the letter a to, say, p (a(t)->p(t)) like this:

restart;

with(DEtools):

test:=(diff(x(t),t,t))+(diff(p(t),t,t))=0;

FirstOrderSys := convertsys(test, [], x(t), t, y, yp );

Lo and Behold! Suddenly Maple gives the answer:

/ d / d \\ / d / d \\ |--- |--- x(t)|| + |--- |--- p(t)|| = 0 \ dt \ dt // \ dt \ dt // [[ d / d \] [[yp[1] = y[2], yp[2] = ---- |--- p(t)|], [[ dt \ dt /] [ d ] ] [y[1] = x(t), y[2] = --- x(t)], undefined, []] [ dt ] ]

Why is that so? I don't see how one letter makes this difference. I have learned Maple on my own, so maybe I have missed something?

During a lengthy computation of mine - done using a well established and scientifically sensible external package - I get a Too many level of recursion error in PDEtools/NumerDenom.

Since it has always worked fine for simpler computation with the exact same code, I am wondering whether, with a bigger bound of the level of recursion, the computation could be succesful.

Which is the max level of recursion than maple allows?

Is it possibile to manually (at one's own risk) raise it, in the same line as raising, for instance, stacklimits kernel option?

I am doing some lengthy computation using the externally developed (and published in academic journals) package 'Janet' to compute the compatibility conditions of an overdetermined set of linear PDEs.

At some point in the process (for a set of equations rather, but not SO, complicated) the procedure gives the error

in (PDEtools/NumerDenom) too many level of recursion

 

I have contacted the developer of the packages and he told me that he never directly calls PDEtools functions, so he deems that that call is made by some more standard maple command (such as simplify).

I could not find any documentation of NumerDenom function, to try and understand what might be the problem (my set of equations has some extremely 'bad' fractions, but I hope this is not that naive)

How does NumerDenom works, and where is it called by 'standard' maple command?

Thank you all.

I have a nice family of functions of the form:

W:=(p,n,mu,w)->sum(w[k] * (n-k)* mu(n-k),k=1..n)

which can be evaluated for different p's using the operator mu*diff(...,mu)

The recursion begins with p=0 and proceeds using mu*diff(W(p,n,mu,w),mu) = W(p+1,n,mu,w).

Can anybody implement this procedure in Maple

Thank you 

1 2 3 Page 1 of 3