(program

(define  expand (a) (tree (peval a)))

(definen id (exp!) (cons 'id (mapcar eval exp!)))
(define const1 (x) 1)
(derive id const1)

(define sec (x) {1/cos(x)})
(define csc (x) {1/sin(x)})
(define cot (x) {1/tan(x)})

(define sec (x) {1/cos(x)})
(define csc (x) {1/sin(x)})
(define cot (x) {1/tan(x)})

(derive sin cos)
(define dcos (x) {-sin(x)})
(derive cos dcos)
(derive exp exp)
(define dsqrt (x) {1/(2*sqrt(x))})
(derive sqrt dsqrt)
(define dln (x) {1/x})
(derive ln dln)
(define dtan (x) {sec(x)^2})
(derive tan dtan)
(define dcot (x) {-csc(x)^2})
(derive cot dcot)
(define dsec (x) {sec(x)*tan(x)})
(derive sec dsec)
(define dcsc (x) {-csc(x)*cot(x)})
(derive csc dcsc)
(define datan (x) {1/(1+x^2)})
(derive atan datan)

(define dasin (x) {1/sqrt(1-x^2)})
(derive asin dasin)

(define dacos (x) {-1/sqrt(1-x^2)})
(derive acos dacos)
(derive sinh cosh)
(derive cosh sinh)
(define dtanh (x) {1/cosh(x)^2})
(derive tanh dtanh)

(make pi 3.14159265)
(make e 2.71828182)

(definen dif (expr!) 
  (loop (expr (setexact foo (eval (car expr!))) varr! (cdr expr!) varr nil)
        (until (null varr!))
        (next varr (car varr!))
        (next expr (tree (peval (diff expr varr))))
        (next varr! (cdr varr!))
        (result (expand expr))
  )
)

(define simplify (expr varr)
(make answer (eval (subst expr 'expr varr 'varr '(pass 7 (simpit 'expr varr)))))
)

(define solver (expr varr)
(program 
  (make expr (subst '- 'equal expr))
  (make expr (tree (peval (eval expr ))))
  (make answer (eval (subst expr 'expr varr 'varr '(pass 8 (solvit 'expr varr)))) )
 )
)


(definen solve (!p!) (let (expr (car !p!) varr (cadr !p!))
  (make expr (subst '- 'equal (subst - '== expr)))
  (make expr (tree (peval (eval expr ))))
  (make answer (eval (subst expr 'expr varr 'varr '(pass 8 (solvit 'expr varr)))) )
 )
)

(define installsimplerules (ruleset)
  (eval (subst ruleset 'rs '(pass 7 (installrulelist rs)))))

(define installsolverules (ruleset)
  (eval (subst ruleset 'rs '(pass 8 (installrulelist rs)))))

(define constant (a f) (and (not (equal a f)) (equal a (subst nil f a))))
(definen int (p) (cons 'int (setexact foo (mapcar 'eval p))  ))
(define cbrt (x) (if {and(numberp(x),x<0)} then {-(x^(1/3))} else {x^(1/3)}))

(definen factor (!p!) (let (expr (car !p!))
(make answer (eval (subst expr 'expr '(pass 7 (factorit 'expr)))))
)
)



)


 
 
 
 