search


Equality and The Substitution Principle
Mon Mar 05 00:00:00 UTC 2018

Equality and the Substituion Principle are two important and closely related ideas. Einstein used these ideas to reason about gravity and formulate the General Theory of Relativity

The Substitution Principle says if two things are equal then those things can substitute for each other. This idea is so simple it borders on the obvious. Discovering this idea is what got me through high school algebra despite having terrible math teachers. At the time, I did not know it had a name. Keep the idea of equality and the substitution principle in mind when you're studying algebra and higher level mathematics because it will help you understand

So what does it mean for two things to be equal? It depends on the problem or system you're modeling and sometimes it is up to you to define what it means. The concept of equality can be generalized to the concept of Isomorphism or sometimes homomorphism depending on your domain and context

What does this have to do with programming? Functions are evaluated using the substitution principle. It means symbols are replaced with values. Let's illustrate with an example.

(defn square [x] (* x x)) (square 3)

When we are evaluating (square 3), 3 is substitued for the symbol x in the function definition. Then in the body of the function, we apply the substitution principle again and replace all occurance of x with 3 which gives us this expression (* 3 3). Since there's no other unknown symbols the function evaluates (* 3 3) which gives 9.

Sometimes we are not substituting a symbol with a simple value but code block that evaulates to an value. We will see this later. Everything in clojure is an expression meaning everything evaluates to some value. Clojure has no statements. Even control structures are expressions