apelloni

20 Reputation

One Badge

2 years, 224 days

MaplePrimes Activity


These are questions asked by apelloni

I was looking for rewriting some expression in simpler forms and ened up getting wrong values from maple

Is something wrong on how I'm using it or is this a bug ?

This is the code with the output:

> NumericStatus(invalid_operation=false):
> simplify(sum(
>         (A-B)
>         *(-1+combinat:-binomial(N-2,i))
>         *(A)^(i)
>         *(B)^(N-2-i)
>     ,i=0..N-2));
                                                    (N - 1)    (N - 1)
                                                   B        - A



> NumericStatus(invalid_operation);
                                                          false

 

This is the wrong answer, is missing the part with the binomial, somehow its set to zero but the NumericStatus is still telling that everythig is fine.
It has not issues when one replaces the N-2 with N,

> simplify(sum(
>         (A-B)
>         *(-1+combinat:-binomial(N,i))
>         *(A)^(i)
>         *(B)^(N-i)
>     ,i=0..N));
                                          (N + 1)    (N + 1)                  N
                                         B        - A        + (A - B) (A + B)

> NumericStatus(invalid_operation);
                                                          false

 

If I drop the (-1) in front I get the right contribution from the binomial regardless of using N or N-2

> simplify(sum(
>         (A-B)
>         *(combinat:-binomial(N-2,i))
>         *(A)^(i)
>         *(B)^(N-2-i)
>     ,i=0..N-2));
                                                   /A + B\N          N
                                                   |-----|  (A - B) B
                                                   \  B  /
                                                   -------------------
                                                               2
                                                        (A + B)

> NumericStatus(invalid_operation);
                                                          false

which is equal to (A+B)^(N-2)*(A-B)

If I use assume(N>2) it still gives the same result but this time is flagged ad an invalid operation (which is not supposed to).
Interesting enough also if I set assume(N>0) in the second example gives me invalid_operation=true but return the correct result.

I'm wondering if there is an equivalent implementation of the Mathematica Cases.

Usually, if I want to find all the occurrences of a specific pattern at any level in my expression I would use 
Cases[<expression>,<pattern>,Infinity]

For example, if I have 
expr = {sin[x]/(sin[2-x]+1)-12,sin[x/2]^2}
Then
Cases[expr,sin[_],Infinity]
will return 
{sin[x],sin[2-x],sin[x/2]}

Is there a way to achieve the same with Maple?

Page 1 of 1