Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Depending on how you created your procedures, you could change the second argument of the seq call to
p in remove(type, {anames('procedure')}, 'protected')
That won't work, alas, if your procedures are exports of a module with option 'package'; that causes the exports to be protected. If that was the case, though, you could just use the package exports, {exports(pkgname)} in the seq.
How 'bout this hack:
SummaryRememberTables := proc()
local p,lst;
    for lst in sort([seq([p,length(op(4,eval(p)))]
                         , p in anames('procedure'))]
                    , (a,b) -> evalb(a[2] > b[2])) do

        if lst[2]=1 then break end if;
        printf("%20a  %-d\n", lst[]);
    end do;
end proc:

f1 := proc(x) option remember; x end proc:
f2 := proc(x) option remember; (x,x^2) end proc:

for i to 100 do
    f1(i);
    f2(i);
end do:

SummaryRememberTables();
                  f2  1437
                  f1  779
The trick is showing motion. A featureless spinning sphere will not appear to be rotating. Here is a way to show a single line of meridian (actually two opposing lines) rotating, using animate
plots[animate](plots[spacecurve], [[1,theta,phi],phi=0..2*Pi, coords=spherical], theta=0..Pi, frames=20);
You'd need to project that onto a fixed sphere, with mesh lines turned off.
Arrghh. Originally I posted
subs(true=false, proc() do true end do end proc);
To make the puzzle a bit harder---a little misdirection---I changed the do loop but didn't actually test it; had I done so I would have used your form, which doesn't give away the trick. Oh well. In case anyone wonders, every loop includes an implict `while condition'. Normally it is set to true and is not displayed. However, the subs command forces this true to false. Without the counter, Maple's automatic simplifier detects that this loop can be eliminated. If Maple's auto-simplifier were a bit more clever, it could replace
for i to 3 while false do ... end do
with
i := 1
.
This works. I used the observation that the globe is created with 24 sections.
with(plots):
with(plottools):
globe := sphere([0,0,0], 1):
n := 10:
plt[0] := globe:
for i to n-1 do
    plt[i] := rotate(plt[i-1],0,0,1/n*2*Pi/24);
end do:
display([seq(plt[i], i=0..n-1)], insequence=true, style=patch, scaling=constrained, axes=none);
Toggle the one-shot/loop button (labeled with opposing arrows) to loop mode, then run. It turns. The colors, however, don't advance. That could be done with a lot more frames; it might be better to change to grayscale.
Had I selected the leaf colors, it would have been the "natural" progression: green, yellow, red, black? Being a Southern Californian, I haven't observed the actual progression of color of a Maple leaf. As they wither, is there a usual progression? Or do some leaves turn one shade and others another? That seems unlikely.
Speaking of leaves, we'll have to ping Will to create another milestone. 800 might have been the logical progression, but 1000 is nice looking and not so far off.
it was about the shortest thing I could think of that was allowable and would not interfere with any normal operation of 'use'. The underscore by itself is a valid name, though I don't recommend using it. It is equivalent to `a=0' but with underscore instead of an a. I suppose `_=%' looks weirder... You sure it wasn't eval(%,O=0), the lhs being the capital Oh. That is a cheap way to eliminate an 'order' term that has escaped from a series. Because Jacques was quicker (posted one minute earlier), I'll take the liberty to edit this. Here's an example of using the `O' trick to convert a truncated series to an exact series:
series(sin(x),x);
                              1  3    1   5    / 6\
                          x - - x  + --- x  + O\x /
                              6      120           
eval(%, O=0);
                                  1  3    1   5
                              x - - x  + --- x 
                                  6      120   
Also, to further expand on Jacques' point about literal numbers acting as functions that evaluate to themselves, note that I, which is usually the imaginary unit, does the same thing, as does any complex number, so I(3), for example, evaluates to I.
Note that the return value of parse with these constructions is, I think, the last evaluated statement. However, the following gives an interesting output display (note the missing 'statement' option to parse):
f := parse("use _=0 in x := 23 end use");
                   f := x := 23
f,x;
                    23, 23
f is actually assigned an assignment statement which, at top-level, is fully evaluated. Inside a procedure it won't be, so:
proc() local f; f := parse("use _=0 in x := 23: end"); dismantle(f) end(); 
ASSIGN(3)
   NAME(4): x
   INTPOS(2): 23
I see that the use is doing nothing here. That is,
parse("x:=23");
does the same thing.
Simpler would be `to 1 do ... end do'. Slightly longer, but possibly clearer, is `if true then ... end if'. A module could be used, but you have to declare globals.
You are correct. However, frequently there won't be a difference, since there is a monotonic mapping between the immediate integers and their addresses (hence small integers are sorted by value); that is, addressof(n) = 2*n+1 for -M ≤ n ≤ M, M = kernelopts('maximmediate'). For 32 bit machines, M = 2^30-1. Thanks for pointing out the membertype procedure; I was not aware of it.
You are correct. However, frequently there won't be a difference, since there is a monotonic mapping between the immediate integers and their addresses (hence small integers are sorted by value); that is, addressof(n) = 2*n+1 for -M ≤ n ≤ M, M = kernelopts('maximmediate'). For 32 bit machines, M = 2^30-1. Thanks for pointing out the membertype procedure; I was not aware of it.
That was the point of my reply. With Maple, one rarely wants to use print in a procedure (there are exceptions). Use the procedure I suggested in a previous post. If the sets already appear in a list, then use map to apply it to each element of the list:
map(smallest_integer, [ {a,b,1}, {2,3}, {Pi,4} ]);
That was the point of my reply. With Maple, one rarely wants to use print in a procedure (there are exceptions). Use the procedure I suggested in a previous post. If the sets already appear in a list, then use map to apply it to each element of the list:
map(smallest_integer, [ {a,b,1}, {2,3}, {Pi,4} ]);
One could just use lprint, though I wouldn't say it was better. Better to just return the sequence, at least that way it can be further processed.
First 162 163 164 165 166 167 168 Last Page 164 of 195