Contents    Page-10    Prev    Next    Page+10    Index   

Optimization by Patterns


(def optpatterns
  '( ((+ ?x 0)          ?x )
     ((* ?x 0)          0 )
     ((* ?x 1)          ?x )
     ((- (- ?x ?y))     (- ?y ?x) )
     ((- 1 1)           0 )
     ... ))

While humans are unlikely to write code such as x + 0, symbolic computations such as symbolic differentiation and automatic programming by substitution into design patterns can often generate such expressions.


deriv:  (deriv2 (+ (expt x 2) (+ (* 3 x) 6)) x)

  der:  (+ (+ (* 2 (+ (* (expt x (- 2 1)) 0)
        (* 1 (* (- 2 1) (* (expt x (- (- 2 1)
        1)) 1))))) (* (* (expt x (- 2 1)) 1) 0))
        (+ (+ (+ (* 3 0) (* 1 0))
        (+ (* x 0) (* 0 1))) 0))

  opt:  2