The following functions that operate on trees should be recursive. Some useful functions that you may need are provided in the file cs378.clj, and you will need some of your functions from the last assignment.
(findpath 'a 'b) = nil (findpath 'a 'a) = () (findpath 'a '(a)) = (first) (findpath 'gold '(rocks gold (monster))) = (rest first)
(follow '(rest first) '(rocks gold (monster))) = gold
(corresp 'light '((my eyes) (have seen (the light))) '((my ears) (have heard (the music)))) ==> music
(solve '(= f (* m a)) 'f) => (= f (* m a))
(solve '(= (* m a) f) 'f) => (= f (* m a))
(solve '(= x (- y z)) 'y) (solve '(= (- y x) z) 'y) ; first try: nil (solve '(= (+ x z) y) 'y) ; second try: succeeds => (= y (+ x z))
Demonstrate that you can solve the following equations for any of their variables. These equations are defined in the file.
(= s (* 0.5 (* a (expt t 2)))) (= s (+ s0 (* v t))) (= a (/ f m)) (= v (* a t)) (= f (/ (* m v) t)) (= f (/ (* m (expt v 2)) r)) (= h (- h0 (* 4.94 (expt t 2)))) (= c (sqrt (+ (expt a 2) (expt b 2)))) (= v (* v0 (- 1 (exp (/ (- t) (* r c))))))
Define a function (solveit equations var values) where equations is a list of equations, var is a variable whose value is desired, and values is an association list of variables with known values. Search the list equations to find an equation that relates exactly these variables; a function set= is provided. Solve the equation for the desired variable and evaluate the solved equation to find its value.
(solveit formulas 'm '((f 10.0) (a 2.0))) => 5.0Use the equations in formulas to solve the following problems: