Joe Riel

9660 Reputation

23 Badges

20 years, 21 days

MaplePrimes Activity


These are replies submitted by Joe Riel

R :=(1/d[0])*(c[0,1,0,2] - c[3,0,4,0]) + (5*c[0,1,0,2] - e[1]*c[3,0,4,0]):
vars := indets(R, 'specindex(nonnegint,c)');
                    vars := {c[0, 1, 0, 2], c[3, 0, 4, 0]}

collect(R, vars);
           / 1      \                 /   1         \
           |---- + 5| c[0, 1, 0, 2] + |- ---- - e[1]| c[3, 0, 4, 0]
           \d[0]    /                 \  d[0]       /

If you get this a lot, it might be because you are using sum where you should/could be using add

While it could be done, it would break a lot of code.  It is frequently useful to know the last counter value after exiting from a loop.  Consider, for example

  for i while f(i) < 0 do end do;

When (and if) the loop exits, the value of i is the value that caused the exit. If i were local to the loop, then we would have to do

  cnt := 1: for i while f(i) < 0 do cnt := i; end do; 

or something similar.

An interesting alternative would be to have a finally clause for a loop.  Then one could do

  for i while f(i) < 0 do finally cnt := i; end do;

Yes, however, reassigning the for-loop counter before the for-loop does not help here, which was my point.  If you need to reassign the variable after the loop, then do so.  Of course, in the simple example above you would be better served with the add procedure, which does not require resetting the variable, in place of the sum, which does.

 

Please show an example where a loop counter must be cleared.  Here is what I was referring:

i := 23:
for i to 3 do i end do;
                                  1
                                  2
                                  3
 

By "loop counter" I mean the 'for' variable (i, above).  At the exit of the loop i is assigned 4, but its value prior to entering the loop has no effect on the loop counter (unless that value is used in the 'from' or 'to' fields).

FYI I have requested (submitted a bug report) for evaln to be explicitly mentioned in the table help page. Currently there is a link to it there, in the See Also section, however, that does not suffice. Note that arrays (no capital) are deprecated, so do not expect to see that help page, array(deprecated), modified in the future.

Note that you do not need to clear variables used as loop counters, at least not for the loop.

I think the following does what you want.

A := array(1..3, [a,b,c]):
for i to 2 do A[i] := evaln(A[i]); end do:
print(A);

                           [A[1], A[2], c]
 

Not having an example, it wasn't clear to me what the user really wanted. On reflection, though I suspect that he would prefer to be able to use any subscripted name, in any order, in both the formal parameter list and the body of the code.  My "suggestion" only addresses the latter, with all the restrictions mentioned.

 

Not having an example, it wasn't clear to me what the user really wanted. On reflection, though I suspect that he would prefer to be able to use any subscripted name, in any order, in both the formal parameter list and the body of the code.  My "suggestion" only addresses the latter, with all the restrictions mentioned.

 

A nit. The element x[0] is, indeed, a Maple name.  However, it is not a symbol, which is what is required for formal parameters.  One could use `x[0]`, but it won't be pretty.

A nit. The element x[0] is, indeed, a Maple name.  However, it is not a symbol, which is what is required for formal parameters.  One could use `x[0]`, but it won't be pretty.

If you want to see the computations of inner loops, then you have to increase the value of printlevel.  In this case,

printlevel := 2:
for i to 2 do
   for j to 2 do
        f(i,j)
   end do;
end do;
                                    f(1, 1)
                                    f(1, 2)
                                    f(2, 1)
                                    f(2, 2)


See the help page for subsop, third bullet, second sentence

  A speci of 0 is allowed only for function, indexed expression, and series exprs. 

Note that neutral operators are represented as functions,

dismantle(x &* y);

FUNCTION(3)
   NAME(4): `&*`
   EXPSEQ(3)
      NAME(4): x
      NAME(4): y

When Maple creates the procedure f36 := x -> x^(2/5), it uses the definition of ^ at that time.  To see this do

restart;
f := x -> x^(2/5):
use RealDomain in g := x -> x^(2/5); end use:
eval(f);
                                                           (2/5)
                                                     x -> x

eval(g);
                                             x -> RealDomain:-`^`(x, 2/5)

The solution is as shown above, create the procedure when RealDomain is 'active'.  You can then use it outside RealDomain, that is,
plot(g, -1..1);

does what you want.

The usual way to create an n-ary operator from a binary operator is with the foldl and foldr commands.  For example

with(groups):
e1 := [[1,2,3]]:  e2 := [[4,6],[2,3]]:
foldl(mulperms, e1, e2, e1) = mulperms(mulperms(e1,e2),e1);
                                         [[2, 3], [4, 6]] = [[2, 3], [4, 6]]

The usual way to create an n-ary operator from a binary operator is with the foldl and foldr commands.  For example

with(groups):
e1 := [[1,2,3]]:  e2 := [[4,6],[2,3]]:
foldl(mulperms, e1, e2, e1) = mulperms(mulperms(e1,e2),e1);
                                         [[2, 3], [4, 6]] = [[2, 3], [4, 6]]
First 133 134 135 136 137 138 139 Last Page 135 of 195