r/AskComputerScience • • 3d ago

ELI5: If AI is non-deterministic, how is it able to solve complex math proofs?

Admittedly, I'm not sure if I'm even phrasing the question correctly, apologies if I am not. But I hope it makes enough sense...?

Thank you!

Edit: By AI, i meant LLM. Apologies, y'all are really smart. LOL! Just came here to learn.

37 Upvotes

73 comments sorted by

44

u/Te-We 3d ago edited 3d ago

Apart from the other correct answers, you can also consider the following: A human mathematician is random in almost the same way. If you give a skilled human mathematician a moderately difficult task, they will sit down, scribble some formulas and with a 99,9% they will end up with the correct solution. However, on the way they might scratch their head at random times and there might be a 5% probability that they spill their coffee. Sometimes they might have to add two numbers as an in-between step. Probably they can do it, but with with 10% probability they will mess up. But if the mathematician messed up, they can simply double-check and re-do the computation.

2

u/greatrudini 3d ago

Thank you!! This helps!

1

u/Initial_Business2340 3d ago edited 2d ago

I’d like to also add that these systems are not nondeterministic in the sense that they fully randomly pull from the distribution modeled by their training data at the time.

They’re now reinforced on goals, which means that some output tokens are more likely to occur now than the ones coming from the original model of their training data.

Instead, they’re forced to “reason” (output intermediate tokens on the way to solving a problem). We can do this because some problems have verifiable answers - like math. That means we can just tell the model when it’s wrong. The exact process of how that “reinforcement” happens is more technical.

But all you need to know is that the output tokens associated with getting problems right with also correct intermediate steps are more likely to occur.

So imagine it as nondeterministic system that has a tendency to output well-thought out responses, with a strong incentive for all kinds of goal-completion (math, cybersecurity, puzzles, coding, biotech, etc.)

Beyond just that, there’s also the whole “helpful assistant” persona. The models don’t start that way, they’re reinforced super heavily, so their output distribution leans towards that “style.”

The probability distribution is kinda dependent on many many factors; it’s not fully random

13

u/No-Newspaper-7693 3d ago

I find the answer to "how does AI overcome <some problem>" is almost always "humans have to overcome the same problem, and AI basically does it the same way we do"

1

u/Ok-Alps4101 1d ago

Well, yes, because the AI training is basically "I'll show you how I do it and you try to repeat it. If you don't repeat it precisely enough, I'll rewire your brain so that the next time you'll get closer to the way I do it. Repeat." If you do this on millions or billions of test samples and repeat it several times, it will basically learn everything you show it and from that it's able to generalize to something it didn't see before.

-5

u/farsightxr20 3d ago

It's the fact that reddit hates to admit, because it almost requires admitting that AI is broadly capable of everything we are.

1

u/AML86 3d ago

Why would anyone admit that?

1

u/LucasTab 18h ago

No it does not lol

20

u/dontwantgarbage 3d ago

I mean, humans are non-deterministic and we solve all sorts of complex problems.

If I give you a map and say “color this using only four colors so that no two adjacent countries have the same color”, and then give you the exact same map tomorrow, there’s a good chance that the two colorings will be different.

1

u/greatrudini 3d ago

Wow. Awesome. Thank you!!

5

u/pdpi 3d ago

It doesn't "solve" proofs, it writes them.

Your initial setup is the Lean proof assistant, and a problem statement written in Lean that you write yourself. You then throw stuff at Lean and ask it if that is a proof for that statement you're trying to prove.

From that initial setup, you "just" need to find a way to generate that "stuff" that could be a proof. You could use dice to create random strings of text, and, given enough time, you might actually get lucky and generate a valid proof randomly like that. While LLMs are still random, their randomness is much more targeted.

1

u/greatrudini 3d ago

Ohh! Thank you!! This helps a lot! Much appreciated.

8

u/__aSquidsBody__ 3d ago

The non determinism is bounded, for all intents and purposes. If you ask an LLM to write you an essay explaining why George Washington wore a wig, it probably isn’t going to output a chocolate chip cookie recipe. You can predict that with certainty even though you cannot predict the exact words it’ll pick for the George Washington essay.

As for the math, i am not an AI employee or researcher, so i don’t know for sure, but i believe there is behavior similar to internal looping, i.e AI produces an answer, but then it re-reads its answer and edits it, and re-reads it again, and so on. Theres “reasoning” in there.

I also believe that the language models are rewarded thinking mathematically. What I mean is that the weights are actively edited if they get a math problem right during training.

Edit: wording

1

u/greatrudini 3d ago

Thank you for the example! HA! That helps!

7

u/VirtuteECanoscenza 3d ago

I would argue that it should be easier for it to find proofs being non deterministic.

I mean: 

  1. Lean is basically an oracle that tells you if your proof is valid
  2. You can "just" try randomly and check with the Oracle.

The non deterministic nature of the model may help in trying out paths that a human would disregard or not see. 

So a little bit of "hallucination" is good to cover the search space and exit local minima 

1

u/greatrudini 3d ago

Awesome! Thank you!!

4

u/0bArcane 3d ago

Humans are not-deterministic and we can solve complex math problems.

LLMS can call deterministic tools (like lean) to verify the proof it came up with. That's done through what is called a "harness", sort-of operating system for an LLM. A harness (simplified) is a loop around an LLM that allows the LLM to use its output to call external functions (e.g. open a file, load a webpage, execute a program etc).

Stochastic algorithms can get deterministic results. For example, some quick sort implementations choose the pivot element at random. That randomness affects runtime, but the result is always a sorted list. No matter which path was taken.

I hope this answers at least part of your questions. I am honestly not sure what exactly you are asking.

1

u/greatrudini 3d ago

It does! Thank you!!

You know how they say "there are no stupid question"? I think i discovered one. Ha! Regardless, your answer does help to add missing context.

1

u/hibikir_40k 3d ago

Yeah this is the step that is easier to grasp when you do numerical methods. You could create quite a few non deterministic steps in something that attempts optimization, and still end up finding very good answers due to iteration. this goes from something as simple as finding minimums on a function, to a traditional mechanistic model being trained. You just need some kind of verification system that is objective.

People would be surprised to hear that, thanks to multiprocessing, a whole lot of software we use every day, like many compilers, are not deterministic, but that doesn't mean the output is wrong, or that doesn't satisfy all constraints.

3

u/tango_telephone 3d ago

LLMs are deterministic, we introduce randomness on purpose via an entropy parameter. When LLMs work through a formal mathematical proof, they are using a tool like LEAN to formalize the proof. LEAN is like a programming language for writing math proofs.

In the same way LLMs excel at writing code, especially in strict languages that catch their errors, LLMs are also good at writing math proofs. It is the same process.

1

u/greatrudini 3d ago

Thank you!!!

1

u/Splash_Attack 3d ago

LLMs are deterministic, we introduce randomness on purpose via an entropy parameter.

This is a correct answer, but like a lot of things there's a one-layer-deeper answer. In theory, LLMs are deterministic. On ideal hardware they would be.

But it's actually extraordinarily difficult to make that theoretical determinism ceiling true in practice. Process variation, environmental conditions, memory allocation, and how it all interacts together with computational load.

This isn't an LLM specific problem. Hardware isn't 100% deterministic when you're pushing it to the edge of its capabilities. LLMs just happen to be a case where we push GPUs to the edge of their capabilities regularly.

1

u/Thick-Protection-458 3d ago

But it's actually extraordinarily difficult to make that theoretical determinism ceiling true in practice. Process variation, environmental conditions, memory allocation, and how it all interacts together with computational load.

And even if we do so - it is still imperfect heuristic. Even if deterministic one.

Like it will make errors (human will make them too, even if due to very different reasons). Just same input will lead to same error.

1

u/Splash_Attack 3d ago

Just same input will lead to same error.

No, you misunderstand, the factors I listed:

Process variation, environmental conditions, memory allocation, and how it all interacts together with computational load.

mean that the same input can lead to different outcomes, even when you're trying to make it be perfectly deterministic.

In order to get true determinism you would need to:

  • Always run on the same hardware.
  • Have that hardware always allocate resources in the exact same way (this costs performance).
  • Always have a perfectly controlled physical environment.
  • Always have a perfectly steady supply voltage.
  • Be completely shielded from any incident cosmic radiation.
  • Run the hardware at a level where a real-terms critical path violation is impossible no matter the load on the hardware (this costs performance).

Among other things. Determinism is incompatible with the model of running on compute clusters. Just think of the first point - your request isn't running an a physical GPU, but distributed over several and not the same ones each time.

Process variation in the GPUs alone means that you cannot guarantee that the same input will give you the same output twice. Erroneous or not.

The errors I mean are errors within the hardware during the inference, and are usually stochastic and probabilistic. Not "errors" as in, undesirable inference results.

2

u/peter9477 3d ago

Is there any reason to assume randomness is required in order to "solve a complex math proof"?

2

u/greatrudini 3d ago

This reply broke my brain..... HAHA! Thank you!

1

u/againey 3d ago

It broke my brain too, because it seems that they interpreted your original post as asking the exact opposite of what it seems to me to clearly ask.

You seemed to originally assume that randomness interferes with solving a complex math proof and it is determinism that is required, so why would someone then ask about the assumptions that make one think that randomness is required?

But maybe they just read too fast and overlooked the "non-" prefix before "deterministic". It happens to the best of us sometimes. 🤷

2

u/KnirpJr 3d ago

It would be easier to answer this question if you could explain where the confusion comes from.

But stochastic algorithms find exact answers to things all the time, you yourself could probably come up with a toy example, say an algorithm incorporating randomness to sort a list.

If by AI you mean an LLM, how exactly they work so well and can find such solutions is a mystery beyond just randomness, one can come up with a great many advantages Llms have and learn about how they work, but their particular effectiveness doesn’t have a satisfying answer as far as I know.

Other automated proof systems use many other interesting techniques, heuristic searches for example tend to benefit from some randomness, being able to take different “paths” over multiple runs or “shaking” their way out of local extrema.

As a general principle randomness doesn’t imply structureless or completely blind, look into some mathematical statistics and probability theory and indeed at transformers themselves.

2

u/greatrudini 3d ago

Thank you!!

3

u/Plus_Comment6547 3d ago

The same way that humans are able to solve complex math-proofs despite being non-deterministic

1

u/TheAncientGeek 3d ago

What would be the problem? Do you think everything is solvable by a detrministic algorithm.

1

u/norabrownie 2h ago

dude no way. some math stuff like undecidable problems straight up needs that wiggle room, same as us

1

u/r2k-in-the-vortex 3d ago

No it is deterministic, exact same input will give the exact same output every time. What you can't expect from LLM is a "correct" answer to your prompt. It's a text predictor at the end of the day and predictions are never ground truth.

But you don't need LLM to reliably output correct proofs, it's sufficient to sometimes output correct steps of proofs, if you have a external proof checker to validate each step and reject incorrect steps. Lean is completely conventionally programmed system to check proofs, you just get LLM to manipulate that to produce effectively proofs.

1

u/OppieT 3d ago

Maybe the LLM asks Wolfram Alpha for answers to math problems?

1

u/Ordinary_Variable 3d ago

I wonder if very precise prompts can nullify the non-deterministic logic in the loop. I could write up an equation. A non-deterministic function given a very carefully crafted input could give a deterministic output.

The prompt would have to depend on the specific function. In this case, the specific model you are using. The same prompt given to a different model wouldn't necessarily give a deterministic reply.

1

u/tmanred 3d ago

Its non determinism is its strength. If it was deterministic it would search for the same wrong answer every time. Because it is non deterministic it can “randomly” with some guardrails search different options and see if they work or not. It needs that non deterministic ability to even have different paths to try. 

As others have said humans are also non deterministic. Think about how you think through a problem. I bet if you really observe yourself closely you will see yourself think up “wrong” answers all the time but quickly discard them until you find the right idea. 

If you ever have a thought process like “Will this work? No. Will that work? No. How about this? Yes that will work.” Then you have basically done a non deterministic search in your brain without realizing it. 

1

u/an0th3rbrick 3d ago

it's a bit like brute-forcing a password. because you can check the proof you can keep coming up with "predictions" and then check them. obviously it's not completely random because the LLM is trained on relevant math and has a human guiding it. it allows for generating and checking ideas way faster than a human.

1

u/Toothpick_Brody 3d ago edited 3d ago

Lean. It’s because of Lean. I think some of the answers on here are missing the point. Without a theorem prover like Lean, LLMs go astray and do incorrect math, due to this non-determinism you mentioned (there is both non-determinism across separate runs, but also during tokenization of words; two identical words may get different tokenizations). But their non-determinism is also their strength. It’s what makes them so versatile.

Lean allows an LLM to convert its non-deterministic, informal output into formal math. A formal language is one that is unambiguous, like a programming language or mathematical logic. An informal language is basically any other kind of communication, including regular LLM output. Informal languages aren’t appropriate for rigorous math because you can use them to make ambiguous arguments.

Now, technically, you could call an LLM deterministic since everything you run on a computer is eventually deterministic. But LLMs are not deterministic in the same way a compiler (for example) is, so I believe that misses the point.

2

u/jumpmanzero 3d ago

LLMs go astray and do incorrect math, due to this non-determinism you mentioned.

The two things have nothing to do with each other. You can trigger an LLM with a set seed, and have it always return the same answer. That answer has the same chance of being right or wrong as it would with any other seed. Randomness isn't where the wrong comes in.

1

u/Toothpick_Brody 3d ago

Tokenization is non-deterministic. Two identical words in different spots might receive different tokenizations. (I should clarify this maybe)

1

u/BasedGrandpa69 3d ago

this is still deterministic. because the two identical words now mean different things. with a set seed, the ai can still output the same answer for any given prompt.

1

u/Toothpick_Brody 3d ago

Yes, but all computations are deterministic in this way, so the comparison loses its meaning

1

u/Embarrassed_Range356 3d ago

LLMs are deterministic in the sense that Same input -> same output every time unless you intentionally change the parameters so that it doesnt pick the next likely token.

Whats probabilistic is exactly that, its still picking the next token on what is most likely to be correct. But because it can review its outputs, it can go into a loop of seeing what was tried, what happened, and iterating on picking the next likely approach based on data.

Id argue humans do the same thing, and there is no better alternative. Unless you alrea know how a problem is solved, you can only attempt your best approach at solving it.

Moreover, you can see basic logic and deductions as being things with 99.99999999% -100% likelihood of being true. So if the training data sees something fit if p then q, p= true then q= true for example a billion times itll learn that with such high confidence that its never going to mistake it

1

u/NomaTyx 3d ago

people have already explained that LLMs are deterministic, but non deterministic just means the output is not the same every time. For an oversimplification, there is an infinite number of correct solutions, and the randomness selects one of them at random and outputs it. The solution is still correct but the correct one was determined randomly

1

u/Vitztlampaehecatl 3d ago

Because with the existence of Lean, math can be expressed as code. Code, unlike AI, is deterministic. So what you do is you get a whole bunch of AI instances to act effectively as well-trained monkeys on very fast typewriters and have them keep writing code and checking it until they come up with a working solution. 

1

u/AskRedditOG 3d ago

AI is deterministic. Not sure why you think it's not. They have pseudorandomness built into the weights to prevent them from falling into non-optimal outputs, but they're ultimately deterministic systems. 

AI image generation is a prime example of this. If you use the same settings, models, and seed, you will always get the same output. 

1

u/CallinCthulhu 3d ago edited 3d ago

Flip the question.

Humans are non-deterministic and can solve complex math proofs, ergo determinism is not a pre-requisite for the reasoning required.

Also LLMs are somewhat deterministic, ish, given no temperature adjustment and identical context windows they will generate the same probabilities for the next token. (Let’s ignore the floating point and hardware shenanigans that break this on occasion)

1

u/Paxtian 3d ago

At least some LLMs have the ability to recognize, "Oh, this is a deterministic problem, I might hallucinate," so they'll call an external tool or build one, if one isn't available, and use that tool to get the answer. When I learned that, i had a momentary freak out.

1

u/RandomLettersJDIKVE 3d ago

AI models being non-deterministic is kinda over stated. The transformer model itself is fully deterministic. The model outputs a sequence of word embeddings that need to be converted to words. That conversion has randomness added to it. There's a 'temperature' parameter on the model that controls how random the word choice is.

1

u/Traveling-Techie 3d ago

Humans are non-deterministic and we can do math proofs.

1

u/flat5 3d ago

I would turn the question around: why do you think non-determinism would be an impediment for solving complex math proofs?

1

u/editor_of_the_beast 3d ago

The math proofs that AI are creating are in a checkable programming language, so it doesn’t matter how they were created. They can be checked.

1

u/green_meklar 3d ago

You can ask the same thing about humans, who are also non-deterministic.

It turns out that in both cases, the system is deterministic enough to statistically clear up its own mistakes and eventually produce a correct output.

1

u/ParseTree 2d ago

the theorem prover harness - lean! the secret sauce to the monkey brain gaining zen wisdom (this is too much overselling math -- I think math should actually be considered as something that is extremely complicated conceptually in contrast to say the most complex pieces of code in the world)

LLMs produce a lot of mass gunks with the lean checking each step whether it makes "rigorous sense"

1

u/Turbulent-Sign-6067 2d ago

AI just like a human uses both trial and error together with intelligence. Not every step needs to be perfect. Errors and creativity are also conceptually related.

1

u/shadow-knight-cz 2d ago

Because of verifiable end goal like a proof in lean.

Also humans are non deterministic as well.

1

u/signeduptomuteantis 1d ago edited 1d ago

it is my assumption that the determinism is delegated to the lean compiler. but I'd rather have someone else confirm or falsify this assumption.

Which would mean that a million moneys on typewriters producing lean source gated by a deterministic checker could prove the Riemann hypothesis

1

u/ImaginaryAd2289 5h ago

Just like people doing math. You can be a bit random coming at a problem, but once you see the solution, a part of your job is to write the proof down in a totally logical, non-stochastic form. Or think of a card game. You might discard randomly among a set of cards you want to get rid of, but your actual goal is to win. And the winner will be decided by a rigid scoring rule, applied completely logically. So your actions are stochastic but the outcome is purely logical and the calculation of all the players’ scores is totally deterministic.

1

u/Gravbar 4h ago edited 4h ago

To be clear, neural networks are deterministic. LLMs are neural networks, and the non-determinism comes from the sampling. the llm runs to get the probability of the next word given context, and then when it finishes, adds that prediction to context and repeats. If it took the most probable next word at each step, it could only ever give one response, so they have it pick a random response weighted by the probabilities it predicted, which may have been tuned to encourage more or less variation from the input data. The most probable next words are still very probable given context though, and so even being non-deterministic it's still limited in how much it can vary given the context it has.

Solving the math proofs in another issue entirely. From what I'm aware of, there's a ton of hand holding that has to be done by experienced mathematicians to lead the LLM to a solution. This can include a condition that the tool outputs into LEAN which is a language for proving mathematics by compiling it. If it can't compile there's a mistake in the proof. So to some extent, if you can break down a big problem into a series of steps and ask it to solve each of the steps, providing certain possibilities for how the solution might be found for each step, and then you gave it enough time and told an agent to keep trying until the LEAN code compiles, and then after each sub problem is solved you repeat this process for the next one, you should be able to solve a more complex math problem. That said, for non-millenium prize problems, the amount of expert guidance has dropped significantly. If you have 10k agents tasked with this constantly failing to solve it by a number of methods, that continue with unlimited resources until the LEAN compiles you can prove something very complex.

1

u/CandiceWoo 3h ago

ai is not nondeterministic. its complicated

0

u/patrlim1 3d ago

LLMs are deterministic. Their output is made random through a "temperature" variable.

LLMs take the current context window of tokens, basically some number of words, and predict the likelihoods for every word they know of to be the next one. Their output is always the same for any given input. With a temperature of 0, AKA no randomization, they will always choose the most likely word. With a higher temperature they have a larger chance to choose less likely words

3

u/Kant-fan 3d ago

I mean technically temperature just modifies the probabilities. For T=0 it's actually undefined because you can't devide by zero. Sampling is what makes it non-deterministic.

1

u/jumpmanzero 3d ago

Modern frontier models are running on complex mounds of hardware that's typically doing many things at once, so they're awkward to make predictable in practice because it's a composition of a lot of "stuff".

But in general, randomness is not baked into an LLMs. APIs (eg. from OpenAI) typically used to have a random seed you could pass in to get consistent answers; I don't think they do anymore, but again that's just a practical problem given that their architecture is complicated. Certainly on a small local model, you can absolutely get the same answer every time (though usually you wouldn't); there's nothing about the process that's, like, inherently non-deterministic.

1

u/Gravbar 4h ago

temperature changes the scale of probability, making less likely tokens more likely or the reverse. Temperature is quite literally when you divide your model outputs (logits) by some float before applying the softmax function. With only temperature added, the LLM is still deterministic (because division is deterministic). The randomness in LLMs comes from taking the next token from the distribution it outputs instead of taking the most likely token.

0

u/CallinCthulhu 3d ago

If they are running on the same hardware and environment, floating point representation variances can affect outcomes. As can other inputs to the system.

But to be a physicist for a bit, we can pretend the “friction” is zero here.

1

u/patrlim1 3d ago

Floating point is deterministic. You don't know what you're talking about.

3

u/ohyonghao 3d ago

floating point is deterministic but it is not associative. (A + B) + C may not equal A + (B + C). GPU's are running in massive parallel processing and the order in which they complete are essentially random. This can lead to differences because of rounding and representation errors.

1

u/CallinCthulhu 3d ago

https://arxiv.org/abs/2408.05148

Anything else you need education about. I’ll be here all day

2

u/johndcochran 3d ago

Jumping in. Your response has nothing to do with floating point being deterministic or not. Breaking the associative property has nothing to do with determinism. So, you may want to see about your education. Seems you've failed basic English and Math.

1

u/CallinCthulhu 3d ago

Fair I responded to a straw man, with an actual study backing my claim. I never said floating point is non-deterministic if you actually READ my comments before deciding to jump in.

0

u/[deleted] 3d ago

[deleted] — view deleted comment

0

u/thesnootbooper9000 3d ago

No, this is why we run the proofs through a fully deterministic and carefully audited proof checking tool that only uses symbolic reasoning, and don't accept any result that doesn't pass.

-1

u/greatrudini 3d ago edited 3d ago

Thank you!!

Edit: Why is my 'thank you' getting down voted? LOL! I appreciate the reply. Hell if I know if it's right or not. That's why I posted the question to begin with...