(I assume this was inspired by <a href="https://news.ycombinator.com/item?id=16803874" rel="nofollow">https://news.ycombinator.com/item?id=16803874</a>)<p>The use of ‘=’ for assignment in programming languages comes, not directly from mathematics, but indirectly from the use of mathematics in science and engineering. As an example, consider the formula for kinetic energy, commonly written<p><pre><code> 𝑚𝑣²
𝐾 = ───
2
</code></pre>
Why isn't it written 2<i>K</i>=<i>m</i><i>v</i>², which expresses the same mathematical equality in a smaller, simpler form? Or any of the other equivalent rearrangements? It's because formulas have a convention, where the LHS is a single term naming the value you <i>want</i>, and the RHS contains the terms for values you <i>have</i>. That is, a formula doesn't just state an equality, it states a <i>method for calculating</i> something. That usage predates programming, and was explicitly copied by early programming languages like For[<i>mula</i>]tran[<i>slator</i>] that were designed for scientific & engineering calculations.
Some more food for thought on the meaning of =, from Girard's "Proofs and Types" [0]:<p>> There is a standard procedure for multiplication, which yields for the inputs 27 and 37 the result 999. What can we say about that?
A first attempt is to say that we have an equality "27 x 37 = 999". This equality makes sense in the mainstream of mathematics by saying that the two sides denote the same integer [...] but it misses the essential point:
There is a finite computation process which shows that the denotations are equal.<p>> [...] if the two things we have were <i>the same</i> then we would never feel the need to state their equality. Concretely we ask a question, 27 x 37, and get an answer, 999. The two expressions have different senses and we must do something (make a proof or a calculation, or at least look in an encyclopedia) to show that these two <i>senses</i> have the same <i>denotation</i>.<p>[0]: <a href="http://www.paultaylor.eu/stable/prot.pdf" rel="nofollow">http://www.paultaylor.eu/stable/prot.pdf</a>
I agree that “=“ as interpreted by people doing math requires context, but in most situations they are able to translate it into a “correct” or formal notion of equality. For example, translating on the fly these ad hoc notions of equality into precise notions of equality in first order logic and/or set theory. For example,<p><pre><code> f(x) = 2x + 3
</code></pre>
Might be translate into something like,<p><pre><code> For all x in the domain of f, f(x) = 2x + 3
</code></pre>
Or maybe further,<p><pre><code> f = { (x, y) in Cartesian product of domain and codomain | y = 2x + 3 }
</code></pre>
Where equality is, I think, strictly defined here as set equality.<p>The articles other point in this example is that we might way “when x = 2, f(x) = 7.” Claiming that x is used both as an indeterminate value and a concrete value. Again, I think the ambiguity is resolved when translate using the correct quantifies, something like “for all x in the domain of f, if x = 2, then f(x) = 7.”<p>Or perhaps you might claim, “there exists an x in the domain of f such that f(x) = 7.” The important point being that the function f is formally NOT the formula f(x) = 2x + 3, but a particular set of ordered pairs, of which you can make formal statements about in first order logic.<p>Another example used was<p><pre><code> A = {n^2 | n = 1, 2, ... 100}
</code></pre>
But again this is just “syntactic sugar” that a reader would translate into perhaps<p><pre><code> A = { n^2 | n in {1, 2, ..., 100}}</code></pre>
Fully agreed, though to nitpick:<p>> <i>Rather than precisely say, f(2) = 7, we say that for x=2, f(x) = 7. So x is simultaneously an indeterminate input and a concrete value</i><p>This seems like a perfectly by-the-book piece of second-order logic with two equality predicates.<p>i.e., the statement asserts that if you look at the space of all possible values for x, then for each value where the predicate "x = 2" holds, the other predicate "f(x) = 7" will also hold. It happens there is only a single value that will satisfy "x = 2", but that's not the equality's problem.<p>So both = signs really <i>are</i> equality here.
I noticed this recently when I was trying to define a note-taking syntax for my math classes. I thought it would be smart to use := for definitions and = for equality, but then I was frustrated when = didn't always mean equals in the same way, and some things didn't really fit into either category. I ended up just giving up and switching back to abusing = in all situations. I think math has a really cool human aspect, it's very rigorous but also relies on the fact that your notes/proofs/whatevers are going to be read by a person.
The author itself admits in the postscript that he has embellished a bit the article, but allow me to take it at its face value: to me, it seems that the article confuses mathematics with its notation (and the same for computer science, but at this level CS is just a branch of mathematics). All the funny stuff he goes on describing follow from this confusion. When a mathematician does mathematics, they have very well defined concepts for "equality", "equality up to some equivalent relation" (my preferred: "equality up to diffeomorphisms that are isotopic to the identity") and so on. However notation is chosen saving on clarity and conciseness, sometimes at the expense of the direct mapping with underlying mathematical concepts. Thus in some case the sign "=" is meant to mean equality (in a certain sense), in some other cases it is not.<p>Computer languages make no exception: they are nothing else than formalisms to express computations. As for every other formalism, the meaning of signs is chosen to be what appears most comfortable in that context by the formalism designer. The statement "x = x+1" has very different interpretations depending on whether you consider it written in C or in standard polynomial equation theory; but in both cases there is a well known meaning for it. In exactly the same way the word "case" has different meaning depending on whether your are reading in English or in Italian.
There are few more examples that come to mind, like statements about intervals (π = 3.14 ± 0.01) and the usual notation for modular arithmetic; 3 * 3 = 1 (mod 4).<p>Oh, and the wonderful notation for integrals, ∫ 2x dx = x² + C
This. It's even more obvious in linear algebra where mathematicians routinely start with the premise "Ax = b", even if there is no solution x that would satisfy the equation exactly.
Operators in mathematics are overloaded in a very similar way to operators in computer science (in languages that permit overloading).<p>I think the author hints toward a good point: there is no use arguing over the meaning of "=" in a general sense, because the meaning is contextual.<p>I think this whole discussion is merely indicative of inexperience on the part of computer scientists attempting to navigate mathematics.
Interestingly, when using mathematics to describe the semantics of programming languages (say, operational structural semantics for an imperative language), the assignment tends to use an arrow, i.e.<p>S[ x ↦ V ]<p>indicates that the new state is equal to old state S, but with variable x now bound to value V.
I remember thinking the same thing after reading <a href="https://www.hillelwayne.com/post/equals-as-assignment/" rel="nofollow">https://www.hillelwayne.com/post/equals-as-assignment/</a><p>Math symbols and expressions are inconsistent just like regular languages. But, unlike math, other languages don't claim to be consistent.<p>It's not surprising that John von Neumann said "in mathematics you don't understand things. You just get used to them." - I've never heard a software developer say this about coding.<p>For example, I did not enjoy integrals at school because of the 'dx' at the end which means 'with respect to x' but which actually looks like a multiplication (* d * x).<p>I think that the reason why I never got deep into math is because the language of math is too inconsistent and has too many logical shortcuts and I can't operate in such environment.
All these discussions of "=" are missing the point.<p>The notation "x = x + 1" is awful because at lhs x denotes a reference to an integer while at rhs x denotes the value hold by the reference. If you know C, it is similar to the difference between an integer pointer *x and an integer x. As an illustration, here are two programs that are doing the same thing, one in C and one in Haskell.<p><pre><code> #include <stdio.h>
int main() {
int x = 0;
x = x + 1;
printf("%d\n", x);
return 0;
}
import Data.IORef
main :: IO ()
main = do
xref <- newIORef 0
x1 <- readIORef xref
writeIORef xref (x1 + 1)
x2 <- readIORef xref
print x2</code></pre>
Geometry distinguishes between equivalence and value. An "angle" isn't its degrees, but the geometric figure (two rays or segments meeting at an end-point of each). It's the <i>measure</i> of the angle that is the degrees.<p>You don't say "angles are equal" - you say they are <i>congruent</i>. It's their <i>measures</i> that are "equal".<p>Although congruency implies measure equality, it doesn't really mean that, but that the shapes are the same (can be rotated/translated to coincide).
I agree with the thoughts on the = sign but I'm not so sure about mutations.<p>> If mutation is so great, why do mathematicians use recursion so much? Huh? Huh?<p>> Well, I’ve got two counterpoints. The first is that the goal here is to reason about the sequence, not to describe it in a way that can be efficiently carried out by a computer.<p>Most high level languages try to avoid making the programmer describe the most efficient way to handle variables. The idea is to describe your algorithms and how they connect and allow the compiler (or interpreter) to figure out how to use registers etc to implement it. Of course that ideal breaks down sometimes but most high level programmers don't normally need to stress the low level details too much.<p>> My second point is that mathematical notation is so flexible and adaptable that it doesn’t need mutation the same way programming languages need it. In mathematics we have no stack overflows, no register limits or page swaps, no limitations on variable names or memory allocation, our brains do the continuation passing for us, and we can rewrite history ad hoc and pile on abstractions as needed to achieve a particular goal.<p>It's true that there's a limit to abstractions even the highest level languages can make if they want to remain general purpose. However I think languages can handle immutable variables as a default.<p>That's not to say I agree that programming should always follow mathematical notation. But I also don't think it's a bad ideal in many cases.
Alan Kay had a good answer on quora for this.<p><i>Let me confess that I’ve not read every answer. But the ones that I did read were all very concerned with “squaring” etc.<p>The simplest answer — and I think the reason many people have difficulty with both arithmetic and especially algebra — is that you need to deeply internalize just what the “=” sign symbolizes and asserts: that there is the very same number on each side.<p>In other words don’t be distracted by the symbols and operations. One way to think about this is that “a number is all the ways you can make it” (i.e. it can be thought of as “processes” (an infinite number of them) as well as a “value”).<p>This means whatever you can do to any number can be done on both sides of the “=” because there is just the same number underneath the gobblydegook on both sides.<p>This is what “=” actually means. And it’s why algebra is actually quite easy rather than mysterious or difficult.</i> [0]<p>[0] <a href="http://qr.ae/TU1SxJ" rel="nofollow">http://qr.ae/TU1SxJ</a>
Think about the equation<p>x + 3 = 1<p>Typically we write that the solution is "x = –2". This to me is the most abusive form of usage for "=" in mathematics. The solution to the equation is –2. The solution to the equation x = –2 is also –2.<p>Solving the equation x = –2 is very easy. We can solve it just by looking at the equation. What we are really doing when solving an equation is transforming the original equation into a simpler equation with the same solution set. Tt gets tedious to write this all out so we just say things like "the solution is x = -2" when we've transformed the original equation to x = –2. This is weird because x is not the number -2. x is a variable that can assume a myriad of values. The only value of x that solves the equation is –2.<p>As the article states the abuse of the = sign in mathematics is rampant. We do it mostly without realizing it. In this sense mathematical language mimics human languages. All human languages are prone to abuse of rules and to shifting with the times.<p>The notation in mathematics, while much more precise than spoken human languages, is abused frequently and the purpose is to make things cognitively easier. The ancient Greeks didn't have symbols for numbers and in their mathematics they wrote everything out in Greek. This makes it very hard to do tedious calculations. Using symbols in lieu of writing out all the minutia makes doing math easier provided you learn the contextual meaning of the symbols. Over the centuries symbols have been introduced as a shorthand for complex ideas/objects/operations. If you want everything precisely stated then reading Principia Mathematica ought to cure you of this desire. Mathematics is written by humans for humans.<p>Code is written by humans for computers and hence the notation needs to be rigorously defined in the language you are using and why your code needs to be commented.
Lisp has many flavors of "equal":<p><pre><code> =
eq
eql
equal
equalp
string=
...
</code></pre>
Because equivalence mean many things in both the mathematical and programming world.
Jeremy – I’m a mega fan of your work.<p>But think going deeper into this is quite fun<p>Your post goes to the point at the heart of philsophical number theory.<p>What does equality mean ?<p>Yup – you got functinal equivalence, isomorphism, and temporary assignment of values.<p>But I think you could prove – that all these types of equality – are “instances” of “different implementations” of “equivalence.<p>They are no more equivalent than 1 = 1 is equivalent.<p>I.e. 1 = 1 means I think we can define a bijective “counting function” that proves there’s the “same number” of “elemetns” in the “sets”<p>I think (not sure) – if you define – counting fucntion / same number / elements / sets differently – you get the differing definitions of equivalence you enumerate.<p>The interesting thing for me is that 1 = 1 is defined clear in 4 of peano’s axioms<p><a href="https://en.wikipedia.org/wiki/Peano_axioms#Formulation" rel="nofollow">https://en.wikipedia.org/wiki/Peano_axioms#Formulation</a><p>And you could mentally – try to develop different (and potentially) – more powerful notions of “equivalence” – with differing axioms<p>A final point… the prevalence of several “similar” concepts of equivalence in computer science – may point to an underlying “platonic idea” of equivalence – that either exists dormant in the world awaiting for us to discover it; or is a useful “technologocial” construct – that has accelerated “progress”
I have an engineers understanding of higher maths - overly general and very patchy. Short of taking an undergraduate math course, are there any resources to help me parse math notation? For example, while brushing up on endogeneity/exogeneity, E[B'|X] = 0 completely threw me - I had to search Google for the use cases of a bar/pipe aka latex vert/mid. I usually lose interest in a paper if I get stuck trying to decode the syntax.
> The usual way to get half an apple is to chop one into "two equal parts". Of course, the parts are actually NOT EQUAL - if they were, there would be only one part! They are merely ISOMORPHIC.<p>- John Baez ( <a href="http://math.ucr.edu/home/baez/week147.html" rel="nofollow">http://math.ucr.edu/home/baez/week147.html</a> )
Humans are compilers of math.<p>'=', like number, means that concept, regardless of instantiation.<p>Beyond that note, I don't see the value in listing all the ways you could interpret notation.<p>Maybe you would also find it entertaining to list all the ways a program can interpret a binary string?
When you say 'i=0', what you mean is that that is the base case, and the sigma specifies a bunch of other cases.<p>i_1 =/= i_2.<p>As xg15 noted, it's perfectly fine to say (x=2) => (x + 3 = 5). The problem the first example really addresses is that in mathematics, the namespaces are loosely defined, but in programming they aren't. 'i' can mean several things at once, and it doesn't really matter because those things never really interact in the same context. In programming, you need to specify the name 'i' every time you want to reference it, so it's important that you have a stricter namespace rule.
One can at least say that in formal ZFC the symbol "=" has exactly one interpretation. And it's this interpretation that people talking about Haskell are referring to.
Aren't we all taught to write "y = 3" as the answer to algebra questions? That's how I always thought of it, not as assignment, but as a declaration of truth.
When I learnt programming, i was confused by x=x+1;<p>After I understood what it really meant, I wondered why they didn’t use some other symbol to capture this semantic. Say something like x <- x+1 ; Which implies assignment rather than equality - That way this would be unambiguous and I feel is more clear. I now guess the choice of using ‘=‘ was probably an attempt at making a (compromised) choice given the limited symbols that were available back when High level languages were first written?
Minor note:<p><i>> A = { n^2 : n = 1, 2, …, 100 }</i><p><i>> In Python, or interpreting the expression literally, the value of n would be a tuple, producing a type error. (In Javascript, it produces 2.[link] How could it be Javascript if it didn’t?)</i><p>That linked JS code uses ^, which is xor, not pow. Math.pow([], 2) = NaN. Or maybe that was the joke and it flew completely over my head.
I don't mean to be rude cause this seems like a really interesting and well researched article, but my question is what an I gonna gain by reading it