From: Richard F. <fa...@be...> - 2014-06-29 21:18:08
|
Thanks for finding/fixing this. Interestingly, if the correctness of the rule seems to depend on the alphabetic order of the terms in the integrand. Thus changing it from delta(u)* fn(u) to gdelta(u)*fn(u) makes it work. I hope your fix works even in this case ... (matchdeclare (u, atom, fn, symbolp), defrule (ddint21, 'integrate(gdelta(u)*fn(u), u, minf, inf), fn(0)) ); RJF (who put this code in Macsyma in the late 1960's, but doesn't necessary recognize what's in there anymore.. postscript The commercial Macsyma code apparently has a rewritten match-compiler) The code it generates looks like this (LAMBDA (TEMP-8) (MATCH-PROG ($FN $U TEMP-9 TEMP-10 TEMP-11 TEMP-12 TEMP-13 TEMP-14) (DECLARE (SPECIAL $FN $U)) (WHEN (ATOM TEMP-8) (MATCH-FAIL)) (UNLESS (EQUAL (CAAR TEMP-8) (QUOTE %INTEGRATE)) (MATCH-FAIL)) (SETQ TEMP-9 (CDR TEMP-8)) (UNLESS (= (LENGTH TEMP-9) 4) (MATCH-FAIL)) (SETQ TEMP-10 TEMP-9) (SETQ TEMP-11 (NTH 1 TEMP-10)) (IF ($ATOM TEMP-11) (MSETQ $U TEMP-11) (MATCH-FAIL)) (SETQ TEMP-11 (NTH 0 TEMP-10)) (LET ((*INHIBIT-USER-RULES* T)) (SETQ TEMP-11 (SRATSIMP (M/ TEMP-11 (MEVAL (QUOTE (($DELTA SIMP) $U))))))) (WHEN (ATOM TEMP-11) (MATCH-FAIL)) (IF ($SYMBOLP (CAAR TEMP-11)) (MSETQ $FN (CAAR TEMP-11)) (MATCH-FAIL)) (SETQ TEMP-12 (CDR TEMP-11)) (UNLESS (= (LENGTH TEMP-12) 1) (MATCH-FAIL)) (SETQ TEMP-13 TEMP-12) (SETQ TEMP-14 (NTH 0 TEMP-13)) (UNLESS (ALIKE1 TEMP-14 (MEVAL-WITHOUT-RULES (QUOTE $U))) (MATCH-FAIL)) (SETQ TEMP-11 (NTH 2 TEMP-10)) (UNLESS (ALIKE1 TEMP-11 (MEVAL-WITHOUT-RULES (QUOTE $MINF))) (MATCH-FAIL)) (SETQ TEMP-11 (NTH 3 TEMP-10)) (UNLESS (ALIKE1 TEMP-11 (MEVAL-WITHOUT-RULES (QUOTE $INF))) (MATCH-FAIL)) (RETURN (MEVAL (QUOTE (($FN SIMP) 0)))))) It took a little work (via tracing) to get this code, since Macsyma routinely runs it through the lisp compiler. Maxima could do the same as part of the defrule and/or defmatch code. Macsyma does not seem to have the same bug, but seems to have the general defect that it doesn't match things in the right order for the user. At least that's what it seems to me from scanning the code. That is, what the user probably intends is the following. Given the expression integrate(delta(z)*foo(z),z,minf,inf) 1. Look for a non-atom with a header, 'integrate. if you've found it, continue else fail 2. Look for presence of 4 arguments. If yes, continue else fail 3. Check that arg 2 is a symbol. locally bind it to u. That is u:z . else fail ;********important, not done so early by matcher********** 4. check that arg3 and 4 are minf and inf respectively else fail 5. Let temp = arg 1 / delta(u). 6. [several steps...] Does temp look like fn(u)? If yes, everything matches and return fn(0) else fail. Even this much improved protocol is wrong, though. Even if it probably reflects what the user sort of meant. For example, integrate(delta(z)*foo(a,z),z,minf,inf) should probably return foo(a,0) but it won't. neither will this work... integrate(delta(z)* foo(z)*bar(z),z,minf,inf) or integrate(delta(z)*foo(bar(z)), ... etc etc etc. So let's face it: this rule-directed approach has a fair amount to dis-recommend its use for this task. How about a little program that might be applied in appropriate circumstances, perhaps detected by pattern matching or not, but the pattern just feeds into an algorithm like this. integrate_deltaprod_minf_inf( integrand, u):= 1. See if the integrand can be arranged to be a product of delta (f1(u)) * f2(f1(u)) where f1(minf) is minf and f1(inf) is inf. (true if f1(u)=u or u^3, say) 2. Make sure that f2(f1(u)) does not contain any delta terms that depend on u, and then return f2(f1(0)). Step1 can be accomplished by making a list of all delta() items, using division to find what is left over, and calling that f2. Note that there is a big advantage to knowing what u is BEFORE looking for delta(u). By the way, didn't someone already write a package for integrating delta stuff? Um, finally, none of this comment on integration is meant to indicate that it is ok for the pattern code to have bugs. Thanks for finding/fixing bugs! RJF On 6/29/2014 1:28 PM, Robert Dodier wrote: > On 2014-06-29, Dimiter Prodanov <dim...@gm...> wrote: > >> (matchdeclare (u, atom, fn, symbolp), >> defrule (ddint21, 'integrate(delta(u)*fn(u), u, minf, inf), fn(0)) >> ); > OK, I've fixed this bug and pushed it as commit 2919edf1. > > Now I get: > > (%i1) matchdeclare (u, atom, fn, symbolp) $ > (%i2) defrule (ddint21, 'integrate(delta(u)*fn(u), u, minf, inf), fn(0)) $ > (%i3) ddint21 ('integrate (delta(x) * foo(x), x, minf, inf)); > (%o3) foo(0) > > best > > Robert Dodier > > > ------------------------------------------------------------------------------ > Open source business process management suite built on Java and Eclipse > Turn processes into business applications with Bonita BPM Community Edition > Quickly connect people, data, and systems into organized workflows > Winner of BOSSIE, CODIE, OW2 and Gartner awards > http://p.sf.net/sfu/Bonitasoft > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss |