Re: How to make and apply rules dynamically?



Thanks alot Robert,
You are right! Its better to apply all the rules altogether as there is no
effect if pattern does not match. But there is one problem I am facing in
this:
if rule is x(I,J)*x(K,L)
then it does not apply to x(i1,j1)*r(j1)*x(k1,l1).
How should I deal with this?
Regards
Dileep
> On 2/6/06, dp2 at cise.ufl.edu <dp2 at cise.ufl.edu> wrote:
>
>
>> I am trying make rules in the program dynamically from a pre-defined
>> list and applying all the rules one by one to the input expression. e.g.
>> I have predefined list: [x(I,L) = r(L), x(I, L)*x(J, K)) = r(L)*d(L,
>> K),.....]
>> Now when there is an input expression like
>> sum(x(t,u)*y(t),t,1,n)*sum(x(e,f)*x(g,h)*z(h),h,1,n); I need to first
>> search from the predefined list what to apply on the expression and
>> then make rules accordingly from them and then at the end apply all the
>> rules made.
>>
>> I have been able to figure out what rule to apply from the list. I now
>> know how to apply rule on the expression. But for handling dynamic
>> thingie I have following problems:
>> 1) How to define rule names dynamically.
>> 2) How to apply rules using apply1 passing it the LIST of rules. Since
>> we don't know how many rules will be there. Should I use the loop to do
>> that?
>
> OK, here are some answers to the questions which you've asked.
>
>
> (1) the concat function returns a symbol by smashing together
> its arguments. maybe s.t. like concat ('myrule, k); where k is an integer.
>  or, heck, just call ?gensym(); which returns a random symbol name.
>
> (2) apply (function_name, argument_list); calls function_name after
> evaluating argument_list. so you can write apply (apply1, cons (expr,
> rule_list)); to get the effect of apply1 (expr, rule_list[1], ...,
> rule_list[n]);
>
> but i still wonder what you're trying to do. in particular i wonder why
> you're choosing rules from a list. if you call apply1 (expr, rule1, rule2,
> rule3); and some of the rules don't match expr, they are ignored and have
> no effect.
>
> hth robert dodier
>
>