Skip to content

Instantly share code, notes, and snippets.

@fffej
Created July 24, 2009 20:49
Show Gist options
  • Save fffej/154542 to your computer and use it in GitHub Desktop.
Save fffej/154542 to your computer and use it in GitHub Desktop.
(defn isolate
"Isolate the lone x in e on the left-hand side of e"
[e x]
(dbg :student (format "e=%s x=%s" e x))
(cond
;; X = A ==> X = n
(= (:lhs e) x) e
;; A = f(X) ==> f(X) = A
(in-exp x (:rhs e)) (isolate (mk-exp (:rhs e) '= (:lhs e)) x)
;; f(X) * A = B ==> f(X) = B / A
(in-exp x (:lhs (:lhs e))) (isolate (mk-exp (:lhs (:lhs e))
'=
(mk-exp (:rhs e)
(inverse-op (:op (:lhs e)))
(:rhs (:lhs e))))
x)
;; A * f(X) = B ==> f(x) = B / A
(commutative? (:op (:lhs e))) (isolate (mk-exp (:rhs (:lhs e))
'=
(mk-exp (:rhs e)
(inverse-op (:op (:lhs e)))
(:lhs (:lhs e))))
x)
;; A / f(X) = B ==> f(x) = A / B
:else (isolate (mk-exp (:rhs (:lhs e))
'=
(mk-exp (:lhs (:lhs e))
(:op (:lhs e))
(:rhs e)))
x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment