Skip to content

standard form of expression

mikera edited this page Apr 19, 2013 · 2 revisions

standart form

For any serious expression manipulation it is beneficial to have a standard (canonical) form of an expression.

  • unnest operators | (+ 1 (+ 2 3)) => (+ 1 2 3)
  • group symbols and numbers together | (+ 1 x 2 y 3 z) => (+ x y z 1 2 3)
  • calculate non-symbol subexpressions (+ x 2 (* 4 5)) => (+ x 22)

mikera: I suggest constants are automatically put first and combined e.g.

  • (+ 1 3 x y) => (+ 4 x y)
  • (* x 3) => (* 3 x)

Doing this should make subsequent expansion / manipulation easier: it means that in standard form you just need to check the first argument to see if there is a numerical constant involved.

Clone this wiki locally