Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@acer subsindets isn't necessarily what you want; it will flatten lists that it shouldn't.  Consider the list

L := [ f([a,[b,c]]) ]:

The lists inside the inert function f should not be flattened, but will be because subsindets flattens all lists inside the expression.

While not ideal, here is a non-recursive approach to flattening nested lists.

flat2 := proc(L)
local a, fL;
    fL := L;
    while ormap(type, fL, list) do
        fL := [seq(`if`(a::list,op(a),a), a in fL)];
    end do;
    fL;
end proc:

@acer subsindets isn't necessarily what you want; it will flatten lists that it shouldn't.  Consider the list

L := [ f([a,[b,c]]) ]:

The lists inside the inert function f should not be flattened, but will be because subsindets flattens all lists inside the expression.

While not ideal, here is a non-recursive approach to flattening nested lists.

flat2 := proc(L)
local a, fL;
    fL := L;
    while ormap(type, fL, list) do
        fL := [seq(`if`(a::list,op(a),a), a in fL)];
    end do;
    fL;
end proc:

Here's a puzzle.  Implement a recursive flatten that doesn't use a conditional expression (no if's).

Here's a puzzle.  Implement a recursive flatten that doesn't use a conditional expression (no if's).

Here is a short, though somewhat less efficient, centroid operator:

centroid := `+`@op/nops:
centroid([[x1,y1],[x2,y2],[x3,y3]]);
                                x3     x2     x1    y3     y2     y1
                               [---- + ---- + ----, ---- + ---- + ----]
                                 3      3      3     3      3      3


Maybe you could post what you have tried, or a simplification of it. In case it wasn't clear, using replacing solve with fsolve won't allow the compiler to be used---I suggested merely as a way to speed up the code without compilation.  A Maple procedure can be compiled only if it can be reduced to code that doesn't have to call back into the Maple library.  So commands like solve and fsolve are not usable in the compiler.  

Maybe you could post what you have tried, or a simplification of it. In case it wasn't clear, using replacing solve with fsolve won't allow the compiler to be used---I suggested merely as a way to speed up the code without compilation.  A Maple procedure can be compiled only if it can be reduced to code that doesn't have to call back into the Maple library.  So commands like solve and fsolve are not usable in the compiler.  

The total derivative has more than one meaning.  Do you mean the gradient?  But that is vector-valued so I don't see how to assign a sign to it.

@jakubi Blame, hardly.  Thanks for pointing out the issue---and thanks to Will for pursuing it

Eliminating the sqrt will give a modest improvent.

Eliminating the sqrt will give a modest improvent.

Presumably, though after four years certainty is impossible.  Maybe the translation to the new format mucked-up my response [grasping at straws].

Presumably, though after four years certainty is impossible.  Maybe the translation to the new format mucked-up my response [grasping at straws].

@Will Yes, I noticed that when asking about inserting hyperlinks the other day.  I'll have to retrain myself to enter the Title first; normally I do that at the end.

That [put the entire thing in a module ... ] is what I would most likely do. Part of that assumes that when complete you'll have something that you want to save to a library so that it can be reused. Note that global variables are evaluated differently than local variables inside Maple; global variables are fully evaluated with each use. 

First 87 88 89 90 91 92 93 Last Page 89 of 195