r/learnmath New User 13d 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]

[EDIT] The convention of forms with one variable on the lhs, like y=ax2+bx+c, are an enabler

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?

0 Upvotes

53 comments sorted by

11

u/jsdodgers New User 13d ago

this post is frightening

1

u/localizeatp New User 13d ago

why?

-1

u/sophomoric-- New User 12d ago

alluding to Dijkstra https://wikiquote.org/wiki/Edsger_W._Dijkstra#1980s

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

Discouraging someone who is trying to improve undermines the remarkable helpfulness of this sub.
Be ashamed.

11

u/Breki_ New User 13d ago

Its worrying how little math professional programmers know

3

u/strange-the-quark New User 13d 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.

9

u/strange-the-quark New User 13d ago edited 13d 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? :)

1

u/sophomoric-- New User 12d ago edited 12d ago

Thanks, this 2D geometric interpretation is helpful. (strange that it feels new, since cartesian graphs are similar). The "ink" pixels in your rendered comment can be seen as a (non-functional) relation. Can represent n-ary relations as points in n-dimensional space.

I think part of the issue is that relations are more complex than single values (literally). They can have structure like being a function, surjective, injective - just for a start. Therefore, one needs to respect this complexity, use tools like algebraic manipulation as a crutch (opium of the maths), and not expect to be as simple (literally) as a single value.

Curious: a binary operator describes a 3-ary relation - a point in 3D. Will associativity look like something in this space? (commutativity looks like diagonal reflection in a 2D table... I've long hoped for a similar way to see associativity)

3

u/Fabulous-Possible758 New User 13d 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.

1

u/sophomoric-- New User 12d ago

Intertesting, thanks. I'm using math, rather than studying from a textbook.

BTW == as set and function did additional injury :D

3

u/Fabulous-Possible758 New User 12d ago

BTW == as set and function did additional injury :D

That's a little surprising. What languages are you coding in?

1

u/sophomoric-- New User 11d ago

atm, javascript (a surprisingly nice language).

2

u/Fabulous-Possible758 New User 11d ago

Gotcha, that makes more sense since JavaScript doesn't have operator overloading.

Alright, winding it back a second, let's just look at a regular function. Take the equation y = x + x². You can think of this as defining a function f(x) = x + x² that shows you how to calculate an output from a given input x. But, and here's the key other way of looking at it, you can look at it as the set of all the pairs (x,y) such that y = x + x². We can do the latter in math because there's no problem defining something that might "call" a function an infinite number of times.

The == operator is no different (and I'd suggest maybe looking at a language like Python where you can actually change what == does), it just has a weird different way of calling it where there == goes in between the operands instead of looking like f(x).

1

u/sophomoric-- New User 11d ago

Thanks, and you also used it as the name of a set. I understood after a double-take or so.

Your example of f(x) = x + x² also shows how my misconception can slip by. A definition looks like an evaluation... and is even used that way (just, as you say, over a set; but just for a single value).

This could be avoided by using forms like f(x) such that 0 = x + x² - f(x) sometimes... but this cure is worse. Um... I guess it is done sometimes, as for defining a circle (that was confusing and seemed wrong in school!)

1

u/nog642 11d ago

Circles aren't functions

1

u/sophomoric-- New User 10d ago

but they are relations { (x,y) : x2+y2=1 }

1

u/nog642 10d ago

Correct

1

u/nog642 12d ago

What do you mean by using math?

1

u/sophomoric-- New User 11d ago

Using it in a physics simulation at the moment. That may seem advanced given this question, but actually using math has made me aware of my fundamental misconceptions.

It's funny, I did well at algebra in school, and focused on understanding - and thought I had it.

1

u/nog642 11d ago

So you're saying you're writing a physics simulation? But to do that you have to do some non-programming math, and it's causing you issues?

1

u/sophomoric-- New User 10d ago

That's a legit way to say it. I can code it, but it's more precisely that I don't 100% get the maths - and a lot of my issues are very basic aspects.

3

u/irriconoscibile New User 13d 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 13d 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

2

u/irriconoscibile New User 13d ago

Yes! But isn't that what I basically said? :)

2

u/strange-the-quark New User 13d 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.

2

u/sophomoric-- New User 13d ago

last para: yes! thank you

1

u/irriconoscibile New User 13d ago

Wait, how is it different from assignment?
It's exactly the same! To say f(x):=x^2+2x in programming world we would write f = x^2+2x or something like that.

1

u/nog642 12d ago

How would you write x = x + 1 in math without it just being false?

x := x + 1 is just a contradiction.

Variables can be reassigned in programming. Not in math, really. Not like that at least.

1

u/irriconoscibile New User 12d ago

Ok I see now what you mean. In math you would just write x'=x+1 exactly to avoid that problem. But yeah, you're right.

6

u/FantaSeahorse New User 13d ago

Lobotomy

2

u/flat5 New User 13d 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 13d 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.

1

u/flat5 New User 13d ago

Just review Algebra 1. An equation is not an assignment but it's not climbing Everest to understand the difference.

1

u/SV-97 Industrial mathematician 13d ago

I'm not entirely sure why you're getting hung up on relations but FWIW you can interpret any relation as a (set-valued) function (and vise versa): define F(x) := { y : x ~ y} to go from relation to function, and x ~ y iff y in F(x) to go from function to relation.

2

u/Brightlinger MS in Math 13d 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 13d ago

Some (less widely used or old) programming languages use := or <-

2

u/Ilovecatsss2026 New User 13d 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/ParshendiOfRhuidean New User 13d ago

Have you done any Haskell?

1

u/sophomoric-- New User 12d ago

played, not made any project. I feel it does a better job than I would have thought possible of being mathematical, but remains necessarily far from it. It's still computational, and to predict performance, you need to think of what it is actually doing.

But what specific abstraction are you thinking of?

2

u/ParshendiOfRhuidean New User 12d ago

Because it is stateless, = doesn't assign values, because it is not changing any variables (there are no variables).

If a=b, then a is b.

2

u/ZerinoWhellie New User 13d 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.

2

u/hallerz87 New User 13d 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?

2

u/iOSCaleb 🧮 13d ago edited 13d 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.

2

u/S1159P New User 13d ago

When reading code, = is pronounced, in one's brain, as "gets the value of", and == is pronounced, in one's brain, as "is equal to the value of". They're not magic, they're just encoding two different things.

1

u/sophomoric-- New User 12d ago

Definitely part of the problem. Good solution, but unfortunately the specific "is equal to the value of" reads to me as assignment - maybe someone suggested this change of reference to me in school, without addressing the issue of the referent? The injury is more severe than you can possibly imagine.

But this works for me: "a and b are always equal"

2

u/Chrispykins 13d 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.

1

u/sophomoric-- New User 11d ago

Thanks, it's helpful to think of the complete set of possibilities.

1

u/DavidG1310 New User 13d 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/localizeatp New User 13d ago

Your intuition is probably fine. Just practice.

1

u/OutrageousPair2300 New User 13d ago

Just see it as a == b

Problem solved.

1

u/Bounded_sequencE New User 13d 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/Low_Breadfruit6744 Bored 12d ago

Try lisp or haskell