Contents    Page-10    Prev    Next    Page+10    Index   

Solving Equations with Patterns

Solving equations by writing code to construct new equations is somewhat difficult. However, doing it with patterns is easy. All we need is a list of transformations, from given equation to new equation:


( ( (= ?x (+ ?y ?z))  (= (- ?x ?y) ?z) )
  ( (= ?x (+ ?y ?z))  (= (- ?x ?z) ?y) )
  ... )

To solve an equation, the base cases will be the same as before. If the rhs is a list, simply try every pattern, in a loop, until either one pattern works (success) or the end of the list of patterns is reached (failure).