soegaard / racket-cas

Simple computer algebra system
62 stars 10 forks source link

Formatting - missing multiplication #30

Open soegaard opened 6 months ago

soegaard commented 6 months ago
image image
soegaard commented 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$"
soegaard commented 6 months ago

Problemet løst ved at erstatte (sqr x) med (expt x 2).