       Re: comparing rewite rules

• To: mathgroup at smc.vnet.net
• Subject: [mg78386] Re: comparing rewite rules
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 29 Jun 2007 05:56:26 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f5vsg8\$l2f\$1@smc.vnet.net>

```dbsearch04 at yahoo.com wrote:
> Hello Mathematica UG:
>
> I input these 2 simple rewrite rule sets into Mathematica V5:
>
> - {yy -> 4, y -> 3}
>
> - {y -> 3, yy -> 4}
>
> I just want to compare these 2 simple rules for equality. I tried:
>
> - define each one and use % == %% (this just gives: {yy -> 4, y -> 3}
>  == {y -> 3, yy -> 4} )
> - making a symbol for each rule set and using ==, such as rul0 ==
> rul1,
>  it just echoes my input
>
> I also tried to replace the rules in an expression. If the replaced
> result evaluates to a simple expression, it is OK but, it still fails
> sometime when Mathematica reorders expressions, such as when x-1 becomes -1 +
> x
>
> Is it possible to determine in my code that 2 "rule lists" are the
> same?
>
> Of course, in the general case, I will have many more rules than just
> these 2 small lists (e.g. Solve[] output).
>
> Thanks in advance.
>
> Regards..Roger

In Mathematica, lists are ordered and comparisons are done element by
element according to their indices. Therefore,

In:= {1, 2} == {2, 1}

Out= False

whereas

In:= {1, 2} == {1, 2}

Out= True

In other words, a list is not a set (in the mathematical meaning of the
term). Hence you must sort your lists of rules before comparison.

Note that, since you are comparing expression, testing their sameness
(*SameQ* or triple equal sign ===) may be more appropriate.

In:= myRule1 = {yy -> 4, y -> 3};
myRule2 = {y -> 3, yy -> 4};

In:= myRule1 === myRule2

Out= False

In:= Sort[myRule1] === Sort[myRule2]

Out= True

Regards,
Jean-Marc

```

• Prev by Date: Re: How to save/export a Manipulate[...] run to a movie file?
• Next by Date: Re: [Mathematica 6] Integrate strange result
• Previous by thread: Re: comparing rewite rules
• Next by thread: Mathematica 5.0 Registration Conundrum