Skip to content
Mike Anderson edited this page Jun 27, 2013 · 10 revisions

Purpose of this page it to collect a few "typical" use cases:

Rearranging a symbolic expression

User has an expression in terms of one symbol, would like to rearrange it to express it in terms of another symbol:

(def E (ex (= y (/ x y))))

(rearrange [x] E)
=> (= x (* y y))

Computing the derivative of an expression

User has an expression with several variables (come of which may be constants). The user would like to get a new expression which is the derivative of the first:

(def E (ex (+ (* (+ 1 a) x x) (* (+ b c) x) a)))

(derivative [x] E)
=> (+ (* 2 (+ 1 a) x) (+ b c))

Solving an equation for a specific value

User has an expression representing an equation, would like to solve for values of a variable that satisfy the equation

(def E (ex (= [x y z] [z 2 x]))) 

(solve [y] E)
=> (2)

(solve [x] E)
=> undetermined

Note: need to think about possibility for zero or multiple solutions?

Parsing an equation from a string

User has a string version of an expression, in standard mathematical infix notation. User would like to convert this to a Clojure / expresso expression

(def E (ex-parse "2*x^2 + 3*y + z")
=> (+ (* 2 x x) (* 3 y) z)

Substitution of multiple values

User has an expression, and would like to substitute in a set of values / other expressions. Useful for parametric substitutions etc.

(def E (ex (+ (* x x) (* y y)))

(substitute E {'x (ex (cos t)) , 'y (ex (sin t))}
=> (+ (* (cos t) (cos t)) (* (sin t) (sin t)))
Clone this wiki locally