r/learnmath • u/sophomoric-- New User • 8h ago
How to fix the brain damage caused by programming?
I was coding professionally before I learnt algebra at school, so a = b is forever first an assignment to me, and not a relation.
The problem is that computers compute; they evaluate arithmetic. They really are a form of "adding machine". [yes, you can code algorithms, and there's symbolic math computation (e.g. sympy), but most programming languages evaluate expressions]
Arithmetic vs relation (over the reals) is a bit like a point vs a line in geometry. A line is an infinite in length, and infinitesimal up close. It comprises infinite points in large and small scales.
A relation over the reals is a single object, with an infinite number of pairs at both scales.
So... I undsrstand this, but I really don't think about it correctly. My intuition is wrong. How can I fix this?
Maybe it is partly because it is just hard?
8
u/strange-the-quark New User 8h ago edited 8h ago
Just think about it as a == b. Cause that's exactly what it is. x == y is all points in the xy plane for which this expression evaluates to true. Imagine the plane as a big table of data, each point an entry, and x == y as a predicate filter. What remains after the filter are all the entries that satisfy the predicate, and they happen to form a 45 degree line through the origin.
y == x * x is similarly a subset of the plane for which the expression evaluates to true, but this time it's in the shape of a parabola.
Cured? :)
9
u/Breki_ New User 8h ago
Its worrying how little math professional programmers know
2
u/strange-the-quark New User 8h ago
It was already pretty bad before LLMs, now it's only gonna get worse. Not true of everyone of course, but probably true of most in the "enterprise software" business.
4
u/Fabulous-Possible758 New User 8h ago
If you’ve done object oriented or functional programming it’s a little easier. The trick is you can think of it in both ways. `==` is a function which returns a Boolean value, but it’s also a set relation defined by x,y ∈ == iff `==(x, y)` is true. The key point is there are multiple ways to talk about the same object. A lot of math kind of relies on just knowing which way you’re supposed to be looking at it at the time, but that will hopefully be clear if you’re studying from a textbook.
3
u/irriconoscibile New User 8h ago
Honestly I'm struggling to understand exactly what you're trying to say, and I don't get your analogy with lines and points. In math sometimes we use := when we want the lhs to be defined by the rhs. So semantically there's :=, and the typical = which in the programming world is often written ==. Nothing more to add I think.
1
u/strange-the-quark New User 8h ago
In programming we use = to denote assignment (and sometimes :=), so we can write things like x = x + 1, which in math don't exactly make sense, except when interpreted as a contradiction.
To programmers, this means something like x_new = x_old + 1
1
u/irriconoscibile New User 7h ago
Yes! But isn't that what I basically said? :)
2
u/strange-the-quark New User 7h ago
No, from what I understood, you said in math := is sometimes used to denote equality by definition; this is different from assignment in programming, so I'm just saying there's a 3rd concept involved, and that this might be what's tripping up the OP.
Cause when introducing definitions, one typically doesn't define the meaning of a symbol, use it for a while, then re-define the meaning of the same symbol arbitrarily many times after.
I think the points and lines analogy is about the OP having trouble conceptualizing relations as objects in their own right, as they think in terms of computing individual numerical values.
1
5
2
u/flat5 New User 8h ago
Equal sign actually has several subtly different meanings even if you don't include assignment against them. It could mean "always equal", you call that an identity, it could mean "equal for some values of unknowns", you call that an equation.
Just keep working with it to gain fluency and intuition.
Your analogy about lines and points was a little weird and didn't convey much for me.
1
u/sophomoric-- New User 6h ago
arithmetic expressions have only one value (in programming, anyway) - like a point.
a relation is a concept with many values - like a line. Well, I guess it's more the domain. For real values, there are infinitely many in the ways I said.
It's not simply a problem of reading a symbol - it is that a relation is a much deeper concept than a single value.
2
u/Brightlinger MS in Math 8h ago
For what it's worth, the use of = to indicate assignment in many programming languages is kind of just a mistake, and probably should have used the symbol << or something instead, but the convention is too widespread to easily change. I've had CS profs who make a point to read a=b out loud as "a gets b" to mitigate this.
If that is the way you're used to using =, certainly it will take some un-learning of habits. That's fine. You have little intuition for math simply because you haven't learned much math, and that will fix itself as you do more math.
2
u/strange-the-quark New User 8h ago
Some (less widely used or old) programming languages use := or <-
2
u/Ilovecatsss2026 New User 8h ago
Hm well you know what an equivalence relation is which puts you ahead of introductory algebra, or possibly one of the introductory students who actually reads their text instead of just paying a hundred bucks to rent it and never opening the pdf...
2
u/hallerz87 New User 8h ago
I'm not sure what you're even trying to say. I can understand that seeing the = sign in different contexts could be confusing, but not sure what infinite points and lines has to do with this?
1
1
u/DavidG1310 New User 8h ago
Mathematician and amateur programmer here: In programming "a=a*2" reads as "set the value of a the result of the right side" In algebra, it reads "a is a number that satisfies that is equal to itself times 2".
The key is that in algebra it means a condition or restriction that must be satisfied. Depending on the condition may be infinite posible valued of a, only a few, or one or none at all. In the case "a=a*2" the only possible number a that satisfies this equation is 0, so a=0 (reads "that unknown number a must be equal to 0") It is not hard and your brain has no damage. It just requires a little time to assimilate.
1
u/ZerinoWhellie New User 8h ago
You can probably benefit from studying equations again, since I think your gripe is with the = sign meaning different things. Most likely a matter of “can you get used to this meaning a different thing”, much like thinking of the word “battery”, is it an electrical battery for a device or the one from “assault and battery”?
Same thing happens backwards, mathematicians with no programming experience will look at a = a + b and say either “b is obviously 0” or “wait, that’s illegal”, I myself went a bit through that, tho I am a fast learner.
In case you need some “training wheels”, you can probably replace = with ==. Programming a == b is the same as mathematics a = b, if you want to procceed they must have the same value.
1
1
1
u/iOSCaleb 🧮 8h ago edited 7h ago
> My intuition is wrong. How can I fix this?
User name checks out.
Accept that like words, symbols can have different meanings in different contexts, and having learned one meaning first doesn’t excuse you from learning others.
Nobody claims “brain damage” because they learned about mathematical equality before they learned about assignment. Why is learning about assignment before equality different?
Also: baloney. Students learn about mathematical equality starting in kindergarten. If you weren’t raised by dingoes you’ve seen `=` in a mathematical context thousands of times.
> Maybe it is partly because it is just hard?
It is not. The = symbol itself was created to convey equality. It’s inventor, Robert Recorde, said that no two things could be more equal that the two parallel lines that form the symbol.
1
u/Bounded_sequencE New User 8h ago
Translate logic into computer code instead. For example, write == instead of "=" to ensure you immediately understand you deal with equality, not assignment.
1
u/Chrispykins 4h ago
People have already mentioned that a == b has the exact properties in most programming languages that 'a = b' has in math, but I think this maybe sidesteps the main issue.
Mainly, in programming the expression a == b is not a relation, it's an operation just like everything else in programming. So == is actually a binary operator which takes in two values and returns a boolean.
I think to understand the distinction here, we have to understand how variables are treated differently in math vs programming. In programming, a variable is just a segment of memory which can take on any binary value. How to interpret that binary value is determined by the type of the variable. Some types have values defined for every possible binary value that could be in the memory, others don't. A boolean type, for instance, can only be either true or false, and it's up to the programming language to decide which binary values are interpreted as true, which are interpreted as false and which are undefined.
In math, on the other hand, a variable is defined by which set it varies over. An integer is just any element from the set {... -2, -1, 0, 1, 2, ...}. Thus if I say "x is an integer", I just mean it could be any element in that set. A relation therefore is just a set which combines two sets together.
If I say that x and y are integers and they satisfy x = y, I am forming a new set which consists of pairs of integers (x, y). When we look at the set of all such pairs of integers, we can lay it out like a grid:
{ .., (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1),
(-2, 0), (-1, 0), (0, 0), (1, 0), (2, 0),
(-2, -1), (-1, -1), (0, -1), (1, -1), (2, -1), ... }
Then the relation x = y is a subset of this grid where the first number in a pair is equal to the second number:
{..., (-2, -2), (-1, -1), (0, 0), (1, 1), (2, 2), ...}
In terms of programming, you could imagine having two arrays of every possible int, these two arrays are the variables x and y in math terms. The relation x = y is then basically iterating over every value in both arrays to create tuples and any time the two numbers are equal you put the tuple into another array. This new array is the relation 'x = y', the set of all pairs which satisfy the relation.
12
u/jsdodgers New User 8h ago
this post is frightening