## reduce-algebra-developers

 [Reduce-algebra-developers] Differentiation rule for new function From: abpetrov - 2014-08-23 11:58:03 Attachments: Message as HTML ```Hi, I need to define differentiation rule for new function - asum for indexed variable a(i). I did it with rule DerivNew: off lower; operator a\$ operator asum; DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( a(i), {{i, 1, 10}}, df, a(i1)) }\$ let DerivNew\$ where asum_trans some transformation function. But when I did df( asum( a(i), {{i, 1, 10}}), a(i1)); I received 0. Why this rule don't works. P.S. It is simplified example, really asum and asum_trans are defined in new packet . But I think the main picture the same. Best regards, Petrov Alexander. ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: Rainer Schöpf - 2014-08-23 12:30:27 ```On Sat, 23 Aug 2014 at 13:31 -0000, abpetrov wrote: > Hi, > I need to define differentiation rule for new function - asum for > indexed variable a(i). > I did it with rule DerivNew: > > off lower; > operator a\$ > operator asum; > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( > a(i), {{i, 1, 10}}, df, a(i1)) }\$ > let DerivNew\$ > > where asum_trans some transformation function. > But when I did > > df( asum( a(i), {{i, 1, 10}}), a(i1)); > > I received 0. > > Why this rule don't works. a(i) and a(i1) are independent of each other. You have to either declare depend a(i),a(i1); or write the rule as DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans(a(i), {{i, 1, 10}}, df, a(i1)) }\$ Also note that lower is not a Reduce switch. Regards Rainer ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: abpetrov - 2014-08-24 18:18:02 ```You are right, If I will differentiate function. But I did some substitution with the help of the rule. I did not any real differentiation: DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( asum( a(i), {{i, 1, 10}}), df, a(i1)) }\$ In realization of function asum_trans is not any real differentiation, only some operations with lists: if smember('df, opt) then begin % expression = (asum f(...), {ind},{functionals}) lstOperands := get_asum_expression( expression); %(.....) dfVar := nth( opt, 2 ); % variable for df dfFunctional := cons('list, list('df, dfVar)); lstIndexes := get_asum_indexes( expression ); lstFunctionals := get_asum_functionals( expression ); if null( lstFunctionals ) then lstFunctionals := list('list, dfFunctional) else lstFunctionals := append(lstFunctionals, list(dfFunctional)); result := list('asum, lstOperands, lstIndexes, lstFunctionals); end; I don't understand result with 0. About switch "lower". It is works with csl-version of Reduce, it is the same as input_case for psl-Reduce, see http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.DEB.2.02.1112122155020.1584%40localhost6.localdomain6&forum_name=reduce-algebra-developers 23.08.2014 12:30, Rainer Schöpf пишет: > On Sat, 23 Aug 2014 at 13:31 -0000, abpetrov wrote: > > > Hi, > > I need to define differentiation rule for new function - asum for > > indexed variable a(i). > > I did it with rule DerivNew: > > > > off lower; > > operator a\$ > > operator asum; > > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( > > a(i), {{i, 1, 10}}, df, a(i1)) }\$ > > let DerivNew\$ > > > > where asum_trans some transformation function. > > But when I did > > > > df( asum( a(i), {{i, 1, 10}}), a(i1)); > > > > I received 0. > > > > Why this rule don't works. > > a(i) and a(i1) are independent of each other. You have to either declare > > depend a(i),a(i1); > > or write the rule as > > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans(a(i), {{i, 1, 10}}, df, a(i1)) }\$ > > Also note that lower is not a Reduce switch > . > > Regards > Rainer > ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: Rainer Schöpf - 2014-08-26 16:45:05 ```On Mon, 25 Aug 2014 at 00:19 -0000, abpetrov wrote: > You are right, If I will differentiate function. But I did some > substitution with the help of the rule. > I did not any real differentiation: > > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( asum( a(i), {{i, 1, 10}}), df, a(i1)) }\$ But you used the df operator. A substitution rule like the above is tried _after_ the standard differentiation. Since the latter returns 0, the rule doesn't apply. You could use your own operator in place of df, but then you need to define all properties like linearity or the product rule. It's much simpler to modify your rule, as I suggested in my last mail message. > About switch "lower". It is works with csl-version of Reduce, it is the > same as input_case for psl-Reduce, If you are aware of the incompatibility, then everything is fine. Regards, Rainer ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: abpetrov - 2014-08-26 18:50:35 ```Excuse me, next rule works for all x let df( asum( a(i), {{i, 1, 10}}), x) = asum_trans( asum( a(i), {{i, 1, 10}}), df, x) ; thank you for your discussion with best regards Petrov Alexandr ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: abpetrov - 2014-08-26 17:57:07 ```I tried this rule with generalization DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ let DerivNew\$ df( asum( a(i), {{i, 1, 10}}), a(i1)); the result is 0 too. Also I tried more general rule DerivNew := { df (asum(~~f(~~y)), ~~x) => asum_trans( asum(f(y)), df, x) }\$ with the same result. I am not sure that operator df applied before that rule, in this case I can not extend differentiation table with new functions. Of course, it is necessary to check this in sources. About lower. I agree with you about the incompatibility, but I don't like when variables can be written without good style with lower- and uppercase letters. It is bad to read that program in my opinion. I think the difference in one operator it is not so bad. 26.08.2014 16:44, Rainer Schöpf пишет: > On Mon, 25 Aug 2014 at 00:19 -0000, abpetrov wrote: > > > You are right, If I will differentiate function. But I did some > > substitution with the help of the rule. > > I did not any real differentiation: > > > > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(i1)) => asum_trans( asum( a(i), {{i, 1, 10}}), df, a(i1)) }\$ > > But you used the df operator. A substitution rule like the above is tried > _after_ the standard differentiation. Since the latter returns 0, the rule > doesn't apply. > > You could use your own operator in place of df, but then you need to define > all properties like linearity or the product rule. > > It's much simpler to modify your rule, as I suggested in my last mail message. > > > About switch "lower". It is works with csl-version of Reduce, it is the > > same as input_case for psl-Reduce, > > If you are aware of the incompatibility, then everything is fine. > > Regards, > Rainer > ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: Rainer Schöpf - 2014-08-31 08:26:39 ```On Tue, 26 Aug 2014 at 23:58 -0000, abpetrov wrote: > I tried this rule with generalization > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( > asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ > let DerivNew\$ > df( asum( a(i), {{i, 1, 10}}), a(i1)); > > the result is 0 too. > Also I tried more general rule > DerivNew := { df (asum(~~f(~~y)), ~~x) => asum_trans( asum(f(y)), df, x) }\$ > > with the same result. > > I am not sure that operator df applied before that rule, in this case I > can not > extend differentiation table with new functions. Of course, it is > necessary to check this in sources. You are right. I was mistaken. A rule for partial derivative df(f(~x,~y),~x) => g(x) is tried first, but a more complicated rule like df(f(~x,2*~x),~x) => g(x) is tried after normal differentiation. Regards, Rainer ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: Rainer Schöpf - 2014-08-27 05:49:17 ```On Tue, 26 Aug 2014 at 23:58 -0000, abpetrov wrote: > I tried this rule with generalization > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( > asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ > let DerivNew\$ > df( asum( a(i), {{i, 1, 10}}), a(i1)); > > the result is 0 too. When I try the following lines in a freshly started Reduce, I get: -------------------------------------------------------------------------- 1: operator asum,a; 2: DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( 2: asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ 3: let DerivNew\$ 4: df( asum( a(i), {{i, 1, 10}}), a(i1)); Declare asum_trans operator ? (Y or N) ?y asum_trans(asum(a(i),{{i,1,10}},df,a(i1))) -------------------------------------------------------------------------- Reduce remembers expressions it has simplified and uses the last result. Maybe that's what happens to you? However, when you add a rule, it should forget the saved results. This could be a bug. Can you please send a complete list of your input/output so that I can reproduce it? Regards, Rainer ```
 Re: [Reduce-algebra-developers] Differentiation rule for new function From: abpetrov - 2014-08-27 18:15:45 ```I tried to reproduce 0 with simplified version of my packet: module asum; put('asum,'simpfn,'simp!-asum); symbolic procedure simp!-asum u; begin scalar r; r := cons( 'asum, revlis u); return mksq( r, 1); end; symbolic procedure asum_trans!*(u); asum_trans(reval car u, revlis cdr u); put('asum_trans, 'psopfn, 'asum_trans!*)\$ symbolic procedure asum_trans( expression, options); begin return expression end; endmodule; end; The sequences of operators is : operator a; DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ let DerivNew\$ df( asum( a(i), {{i, 1, 10}}), a(i1)); And I can not reproduce 0. It was my mistake. Expressions has too many brackets! Thank you Best regards Petrov Alexander. 27.08.2014 05:48, Rainer Schöpf пишет: > On Tue, 26 Aug 2014 at 23:58 -0000, abpetrov wrote: > > > I tried this rule with generalization > > DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( > > asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ > > let DerivNew\$ > > df( asum( a(i), {{i, 1, 10}}), a(i1)); > > > > the result is 0 too. > > When I try the following lines in a freshly started Reduce, I get: > > -------------------------------------------------------------------------- > 1: operator asum,a; > > 2: DerivNew := { df( asum( a(i), {{i, 1, 10}}), a(~i1)) => asum_trans( > 2: asum( a(i), {{i, 1, 10}}, df, a(i1))) }\$ > > 3: let DerivNew\$ > > 4: df( asum( a(i), {{i, 1, 10}}), a(i1)); > > Declare asum_trans operator ? (Y or N) > > ?y > > asum_trans(asum(a(i),{{i,1,10}},df,a(i1))) > -------------------------------------------------------------------------- > > Reduce remembers expressions it has simplified and uses the last result. Maybe > that's what happens to you? > > However, when you add a rule, it should forget the saved results. This could be > a bug. Can you please send a complete list of your input/output so that I can > reproduce it? > > Regards, > Rainer > > > ```