Open soegaard opened 6 months ago
(define (tree-replace t x y)
; replace all occurences of x with y in the tree t
(def (tr t) (tree-replace t x y))
(cond
[(equal? t x) y]
[(list? t) (map tr t)]
[else t]))
(let ([a -4] [b -1] [c 5] [d -9] [x 'x] [y 'y])
(tex (tree-replace (tree-replace `(+ (* ,a (sqr ,x)) (* ,b (sqr ,y)) (* ,c x y) (* ,d x))
'x 2)
'y 5)))
> (let ([a -4] [b -1] [c 5] [d -9] [x 'x] [y 'y])
(tex (tree-replace (tree-replace `(+ (* ,a (sqr ,x)) (* ,b (sqr ,y)) (* ,c x y) (* ,d x))
'x 2)
'y 5)))
"$-42^{2}-5^{2}+5\\cdot 2\\cdot 5-9\\cdot 2$"
Problemet løst ved at erstatte (sqr x)
med (expt x 2)
.