You need to re-think about computing with algebraic expressions, pattern
matching, and substitution.
substitution:
internally, the expression a*b looks (something like) (* a b)
the expression -a*b looks like (* -1 a b).
The subexpression (* a b) occurs nowhere in (* -1 a b), so a syntactic
substitution will not work.
if you want to substitute something for -a*b, you will have to mention that.
ratsubst() is a more powerful program in some ways, and will pick out
factors differently.
try it.
matching:
a pattern variable k, declared to be true, can match many things.
For example, the pattern k*x can match 3*x with k=3. It can match x
with k=1.
It can match y with k=y/x.
The pattern (k+1)*x could match THE SAME THINGS. 3*x with k=2. for
example.
Is this what you want?
Try some much simpler examples to see if you can match matching work.
Look at the
documentation.
giovanni gherdovich wrote:
>Hello dear Fateman,
>thankyou for your reply.
>
>
>
>>Did you use matchdeclare to set up any pattern
>>variables?
>>
>>
>
>If you mean something like
>
>matchdeclare([n,k],true);
>defrule(h,(k+1)*binomial(n,k+1),(n-k)*binomal(n,k));
>
>yes, I tried it but
>apply1( -(k+1)*binomial(n,k+1)/(2*(n-k)*2^n) ,h);
>doesn't work. Actually, I didn't find any example
>where the use of matchdeclare change the things.
>Maybe I didn't understand the behavior of
>matchdeclare.
>
>
>
>>If not, perhaps you should just use subst, and not
>>rules at all. In that
>>case you will have to find exact subexpressions to
>>substitute for.
>>
>>
>
>I tried
>subst(
> (k+1)*binomial(n,k+1),
> (n-k)*binomial(n,k),
> -(k+1)*binomial(n,k+1)/(2*(n-k)*2^n) );
>but still doesn't work.
>
It works the way it was intended. There is no occurrence of
(n-k)*binomial(n,k) anywhere in the 3rd argument.
>I tried to change expression to simplify, and it seems
>that the only thing Maxima can do is apply the rule
>to expressions with *only* the pattern I ask for!
>I mean:
>on -(k+1)*binomial(n,k+1)/(2*(n-k)*2^n) doesn't work,
>on -(k+1)*binomial(n,k+1) doesn't work,
>if I close the pattern in brackets like
>-((k+1)*binomial(n,k+1)) it doesn't work (i really
>don't understand it), it works only at
>(k+1)*binomial(n,k+1)....
>
Adding brackets does nothing.
>
>I find really strange that if the pattern is a*b,
>expression like -(a*b) or a*b/c or a*b*c
>doesn't match.
>
Try ratsubst.
>
>
>
>>Or else consider looking for a pattern like
>>A*binomial(B,C) and change it to
>>something that you would prefer, based on some
>>relationship among A,B, and
>>C.
>>In this case, A would match
>>-(k+1)*(n-k)^(-1)*2^(-1-n), B would match n, C
>>would match k+1.
>>
>>
>
>I would like to don't ask for the exact pattern that
>occur in the example I posted, I prefer to use only
>these two rules:
>
>BOTTOM STEP:
>(k + 1) binomial(n, k + 1) -> (n - k) binomial(n, k)
>TOP STEP:
>(n+1-k) binomial(n+1,k) -> (n + 1) binomial(n,k)
>
If you match A*binomial(B,C) you can then pick out the cases you have
in mind.
Your pattern matching requires exponential work, in general, if you have
variables n, k.
If you have constants n, k, then your expressions must match exactly
syntactically. No fiddling around
with signs etc.
>
>I do that in order to fix time by time a little bug
>I found in the behavior of the command nusum.
>The problem is that when I ask to nusum wich
>sequence can telescope, for instance,
>
>a(k) := 1/2^(n+1) * binomial(n,k) * (2*k-n-1)/(n+1-k)
>
>I get like answer this:
>
>f(k) := -(k+1) * binomial(n,k+1) / (2*(n-k)*2^n)
>
>It seems not bad, but if I want to check with a
>teorem prover like HOL that
>
>a(k) = f(k) - f(k-1)
>
>I crash my head against the fact that on the right
>hand side I have a singularity only in k=n+1, while
>on the left hand side I have TWO singularities,
>in k=n and in k=n+1.
>But these singularity are just "virtual", because if
>I apply the rules I told, f(k) become
>-binomial(n,k)/2^(n+1).
>This fact happens very often, so I'm looking for a
>general policy to handle it, and I should avoid
>very "ad hoc" solutions.
>
Perhaps you should change the way nusum works??
>
>Best regards
>Giovanni Gherdovich
>
>
>Chiacchiera con i tuoi amici in tempo reale!
> http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
>
>