corywalker / expreduce

An experimental computer algebra system written in Go
MIT License
389 stars 26 forks source link

Order in which rules get applied #104

Open cekdahl opened 7 years ago

cekdahl commented 7 years ago

The order in which rules get applied is different than in Wolfram Language in two notable cases. I think both of them should be fixed. Mathematica:

{a, b} /. {a -> b, b -> c, c -> d}
(* Out: {b, c} *)

Expreduce:

{a, b} /. {a -> b, b -> c, c -> d}
(* Out: {d, d} *)

When expreduce has applied the first replacement rule it continues to apply the subsequent replacement rules to the replaced parts. Replaced parts should preferably be impervious to subsequent replacement rules.

Then there is this, in Mathematica:

h[f, g] /. {f -> b, h[f, g] -> a}
(* Out: a *)

Note that it tries to replace the expression at the top level first before it moves on to lower levels. This is how I think expreduce should also proceed, level by level. Currently it proceeds rule by rule:

h[f, g] /. {f -> b, h[f, g] -> a}
(* Out: h[b, g] *)

h[f, g] /. {h[f, g] -> a, f -> b}
(* Out: a *)
cekdahl commented 7 years ago

This issue is related to #37