Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Nice demonstration of Maple manipulation. A few minor comments. Here's a slight change to the breakApart procedure; it does the same thing, but marginally simpler and maybe a little clearer. I added the type declaration to expr to ensure that the input is a product, otherwise the result is incorrect.
breakApart := proc(expr::`*`, dep_var, const_name)
local dep_term, indep_term, cons_eq;
    (dep_term, indep_term) := selectremove(depends, [op](expr), ep_var);
    dep_term   := `*`(op(dep_term));
    indep_term := `*`(op(indep_term));
    cons_eq := (const_name = indep_term);
    return (cons_eq
            ,const_name*dep_term);
end proc:
The choice of the parameter name dep_var seems strange; I'd consider that the independent variable---maybe my memory is hazy on standard terminology. When computing intz_factor (in the subsequent computation) it is nicer to use applyop to factor the chosen term then to manually split and recombine the sum:
intz_factor := applyop(factor, 1, intz_collect);
The simplification of sinh/cosh to tanh can be handled slightly easier using
eval(intz_subs1, sinh=cosh*tanh);
This also eliminates the need for the subsequent collect.
As long as they never FAIL, you shouldn't have a problem 8-)
As long as they never FAIL, you shouldn't have a problem 8-)
FAIL or true;
              true
FAIL and false;
              false
false implies FAIL;
               true
etc.
FAIL or true;
              true
FAIL and false;
              false
false implies FAIL;
               true
etc.
The statement
P := v[1]^3 - 1, v[2]^4 + 1;
assigns P an expression sequence of two polynomials, not a list. While Maple has some ability to deal with expression sequences, they are not quite as easy to work with as lists. Specifically, passing an expression sequence as an argument to a procedure is a bit tricky because Maple typically expands the sequence so each item appears as a separate argument. There are ways around that, but the easiest way is to make P an actual list:
P := [ v[1]^3 -1, v[2]^4 + 1 ];
A problem with your routine is that the assignment to the variable v causes v to be implicitly declared local to the procedure. That means it does not equal the v used in the global variable P. There are a few ways to handle this. The simplest is to explictly declare v to be global. Then you could do
f1 := proc(P)
global v;
   eval(P, v=[1,2,3]);
end proc:
f(P);
          [0, 17]
That works, however, making v global may not be desireable. Another possibility is to make v a parameter.
f2 := proc(P,v)
local x;
   x := [1,2,3];
   eval(P, v=x);
end proc:
f2(P,v);
             [0,17]
The statement
P := v[1]^3 - 1, v[2]^4 + 1;
assigns P an expression sequence of two polynomials, not a list. While Maple has some ability to deal with expression sequences, they are not quite as easy to work with as lists. Specifically, passing an expression sequence as an argument to a procedure is a bit tricky because Maple typically expands the sequence so each item appears as a separate argument. There are ways around that, but the easiest way is to make P an actual list:
P := [ v[1]^3 -1, v[2]^4 + 1 ];
A problem with your routine is that the assignment to the variable v causes v to be implicitly declared local to the procedure. That means it does not equal the v used in the global variable P. There are a few ways to handle this. The simplest is to explictly declare v to be global. Then you could do
f1 := proc(P)
global v;
   eval(P, v=[1,2,3]);
end proc:
f(P);
          [0, 17]
That works, however, making v global may not be desireable. Another possibility is to make v a parameter.
f2 := proc(P,v)
local x;
   x := [1,2,3];
   eval(P, v=x);
end proc:
f2(P,v);
             [0,17]
I could, but that's what the help pages are for; see linalg[norm] for an explanation. I'll take the easy way and just give examples, the progression should be clear.
with(linalg):
v := vector([a,b,c,d]):
norm(v,1);
            abs(a)+abs(b)+abs(c)
norm(v,2);
           sqrt(abs(a)^2+abs(b)^2+abs(c)^2)
norm(v,3);
           (|a|^3+|b|^3+|c|^3)^(1/3)
norm(v,4);
           (|a|^4+|b|^4+|c|^4)^(1/4)
norm(v,infinity);
            max(abs(a), abs(b), abs(c))
norm(v,frobenius);
            sqrt(abs(a)^2+abs(b)^2+abs(c)^2)
If you are wondering why sometimes |a| is displayed as abs(a) above, that's what was pasted in when copying from Standard Maple. They mean the same thing.
I could, but that's what the help pages are for; see linalg[norm] for an explanation. I'll take the easy way and just give examples, the progression should be clear.
with(linalg):
v := vector([a,b,c,d]):
norm(v,1);
            abs(a)+abs(b)+abs(c)
norm(v,2);
           sqrt(abs(a)^2+abs(b)^2+abs(c)^2)
norm(v,3);
           (|a|^3+|b|^3+|c|^3)^(1/3)
norm(v,4);
           (|a|^4+|b|^4+|c|^4)^(1/4)
norm(v,infinity);
            max(abs(a), abs(b), abs(c))
norm(v,frobenius);
            sqrt(abs(a)^2+abs(b)^2+abs(c)^2)
If you are wondering why sometimes |a| is displayed as abs(a) above, that's what was pasted in when copying from Standard Maple. They mean the same thing.
About a year ago I wrote a package that generates Maple help pages (.mws format files that Maple can convert to help pages) from a markup language patterned after the roff formatter. For example, to generate the equivalent of the ?sum help page I can use a file that starts out like the following
.ignore -*- nroff -*-
.defmacro \add={#\ht:add#}
.defmacro \sum={#sum#}
.defmacro \Sum={#Sum#}

.To \[sum\]
.Al \[Sum\]

.Ti \[sum\] - definite and indefinite symbolic summation
.Ti \[Sum\] - inert form of sum

.CallSeq
.li _
sum(#f#, #k#)  sum(#f#, #k#=#m#..#n#)  sum(#f#, #k#=#alpha#)  sum(#f#, #k#=#expr#)
.li _
Sum(#f#, #k#)  Sum(#f#, #k#=#m#..#n#)  Sum(#f#, #k#=#alpha#)  Sum(#f#, #k#=#expr#)


.Parameters
.pmax alpha
.pa f     - expression
.pa k     - name; summation index
.pa m,n   - integers or arbitrary expressions 
.pa alpha - RootOf expression 
.pa expr  - expression not containing k

.Description

.li *
The \sum command (#\def:sum#) is for #\i:symbolic# summation.  It is
used to compute a closed form for an indefinite or definite sum.  A
typical example is #sum(k,k=0..n-1)#, which returns #n^2/2-n/2#.  To
add a finite sequence of values, rather than compute a formula, use
the \add command.  For example, #add(k,k=0..9)# returns 45.  Although
the \sum command can often be used to compute explicit sums, it is
strongly recommended that the \add command be used in programs if an
explicit sum is needed, in particular, when summing over all elements
of a list, array, Matrix, or similar data structure.  For more details
and examples, see the "Comparison of Sum and Add" section below.
To make it portable it is written in Maple. However, I've never got around to finishing this package. I've also seen better ways to handle this, and so have been reluctant to do any further development or to release it.
What's wrong with what you did? The odeplot gives what you want, right? It works find on maple 10.
What's wrong with what you did? The odeplot gives what you want, right? It works find on maple 10.
I named it maplev-mode rather than maple-mode mainly to avoid conflict with another emacs package for maple. I update the keywords and syntax with each release of Maple (there are options for setting the particular release, however, in most cases, using the latest suffices). For help on Maple libraries, start with ?library. Note that the mode was written for GNU Emacs, not Xemacs. There are some problems using it with Xemacs; I've occasionally attempted to make it compatible with both, but have never completely suceeded. Also, the mode that interacts with command line Maple (cmaple-mode) needs a rewrite; it uses a crude handshaking technique because that was all I could get to work with Maple and Emacs on a Windows box. I've since demonstrated that a much better technique is possible on Linux (and possibly on Windows, I haven't used it for awhile), but haven't yet got around to implementing it. Its on my list of things to do.
Editors are a personal choice. I use emacs, with the maplev-mode, which does both syntax highlighting as well as indenting and has links to the Maple help system, mint (the syntax checker) and command line maple. Its available at my home page, www.k-online.com/~joer. There is a maple "mode" (don't know the term) for vim, with highlighting, I don't know what other features it has. So far as style, I've used both a single, large file (Emacs has a folding mode which makes this practical) as well as multiple smaller files. When I first starting Maple programming (quite a while ago) I used the read command to load the source file. Now I frequently use Make files that create a Maple archive (library) from the source. For some of my projects I use the noweb system of literate programming, with that Make files are almost a given; they build the archives as well as the documentation (typeset source code).
A few caveats with that approach. First, monomials must be handled separately, otherwise bad things will happen (consider the monomials 1, x^2, and a*x^2, each exhibits a different wrong result). Second, using degree requires collecting, otherwise it can return FAIL. Finally, and this isn't a bug here but just a general warning, using mod can occasionally lead to errors if we assume the result must be nonnegative and mod has been replaced with mods (rather than modp); mod is an environmental variable. Using modp directly avoids that possibility. However, testing for the result to be zero, as you did, is safe. Thus, don't do something like j mod 3 = 2. Use either (j-2) mod 3 = 0 or modp(j,3) = 2.
First 184 185 186 187 188 189 190 Last Page 186 of 195