Joe Riel

9660 Reputation

23 Badges

20 years, 17 days

MaplePrimes Activity


These are replies submitted by Joe Riel

No typo.  This corresponds to the modification Alejandro made (above).

Realizing that this is merely an example, what you really want to be able to do is

superalgsubs(exp(q*Pi/5)=alpha, exp(2*q*Pi/5));
                                                 2
                                            alpha

I had assumed that 5 was in the denominator to enforce a match, that is, the reduced fraction must include a 5 (that you included only elements 1 through 4 in the original sequence suggested that interpretation). Apparently that wasn't your intent.  Rather you didn't want to match purely syntactically, but also algebraically.  Part of the difficulty with designing a matcher is that sometimes we want it to match purely on syntax, other times we want it to have some algebraic smarts.  Note that none of the solutions offered match the case i=0, which reduces to exp(0)=1.

Yes, but the reality is that n::integer/5 is never going to match anything.  It is analogous to using `n::integer + 3' and hoping that it will match some integer.  It won't.  Maple's matchers don't (as a rule) do more than match syntax.  I think we can see that this is the case for integer addition or multiplication.  For division it is not so apparent since we (the user) can see the desired target in the denominator.  However, Maple integer fractions are of type atomic so ...

That doesn't preclude one from creating a more sophisticated matcher that would translate, say, n::integer/5 into a conditional match that does what you want, but I suspect that a general approach would be difficult.

In your example, suppose that exp(q*Pi) appeared.  Mathematically, n=5 matches that, but I suspect you would not want it to match.   How would your hypothetical matcher deal with that?

Thanks for demonstrating the use of conditional; I recall reading of its existence but haven't ever used it. Actually, I'm not sure I've ever used applyrule before, so this should increase my awareness.  Because we've restricted n, one can safely use denom here to make the code a bit more friendly

seq(applyrule(conditional(exp((n::imaginary(fraction))*Pi), _denom(n)=5)=alpha^(5/I*n),exp(i/5*I*Pi)),i=1..4);

Note that the test for equality works fine despite the caveat in the applyrule help page:

... the condition has to be unevaluated or in inert form: use an `_` in front of every name, for example, _type(a,.freeof(x)) and it is not possible to use `=` or `<>`.

If that didn't work, one can do either _Testzero(_denom(n)-5) or _type(_denom(n),5).

This fails because pattern matching won't 'split' a base type (not sure the correct terminology).  You could get it to work by using x::imaginary(fraction) in the pattern match and then removing the imaginary unit and scaling by five, however, what you would really like is to be able to provide an additional test to ensure that x has a denominator of 5.  That can be done, if crudely, with

seq(applyrule(exp(x::And(imaginary(fraction),`satisfies`(x -> denom(x/I)=5))*Pi)=alpha^(x/I*5)
              ,exp(i/5*I*Pi)),i=1..4);   
                                                 2       3       4
                                     alpha, alpha , alpha , alpha


The map function works over other structures than Vectors; it is a fundamental Maple command (as is seq).  Note that when mapping over an rtable (of which a Vector is specific type, as is a Matrix) with numeric values, you can use the 'evalhf' option for greater speed.  The 'inplace' option can also be used, to reduce memory usage. Check out the help page for map for details.

V := Vector(100, i -> i^2, datatype=float[8]):
map[evalhf](ln, V);

The map function works over other structures than Vectors; it is a fundamental Maple command (as is seq).  Note that when mapping over an rtable (of which a Vector is specific type, as is a Matrix) with numeric values, you can use the 'evalhf' option for greater speed.  The 'inplace' option can also be used, to reduce memory usage. Check out the help page for map for details.

V := Vector(100, i -> i^2, datatype=float[8]):
map[evalhf](ln, V);

Thanks.  I wasn't thinking of the hackware package (pointto), but in retrospect that makes sense.  I like the use of typematch here, very neat.

That can more simply be done by converting to a name,

eq:= 7*x = 14:
isolate(subsindets(eq, integer, convert, name), x);
                                                    14
                                               x = ----
                                                    7

The downside is that one cannot necessarily evaluate the resulting expression.  However, in this case you can invert the process,
subsindets(%, name, parse);
                                                 x = 2

 

That can more simply be done by converting to a name,

eq:= 7*x = 14:
isolate(subsindets(eq, integer, convert, name), x);
                                                    14
                                               x = ----
                                                    7

The downside is that one cannot necessarily evaluate the resulting expression.  However, in this case you can invert the process,
subsindets(%, name, parse);
                                                 x = 2

 

Kudos to both Jacques and Alejandro. I always enjoy reading and learning from their contributions.

str := "sin(4*x)+cos(2*x)";
                                      str := "sin(4*x)+cos(2*x)"

y := parse(str);
                                       y := sin(4 x) + cos(2 x)

diff(y,x);
                                        4 cos(4 x) - 2 sin(2 x)
 

I enter Maple code by using the "Formatted" format. The only tricky part is figuring out how to apply this to just one section.  If you type the code in manually, then select the format, you need to use shift-enter at the end of each line when typing.

I enter Maple code by using the "Formatted" format. The only tricky part is figuring out how to apply this to just one section.  If you type the code in manually, then select the format, you need to use shift-enter at the end of each line when typing.

First 143 144 145 146 147 148 149 Last Page 145 of 195