Zulip Chat Archive

Stream: Is there code for X?

Topic: Computational sum_four_squares


Trebor Huang (Dec 19 2021 at 10:18):

Do we have algorithms that decompose a number into the sum of four squares?

The current proof of that theorem seems to use classical logic, but since everything in the proof involves a finite range of objects, I think the classical axioms can be gotton rid of, right?

Thomas Browning (Dec 19 2021 at 10:22):

It's a finite search, so it should be too hard to write a slow algorithm.

Eric Wieser (Dec 19 2021 at 10:36):

Removing the classical axioms won't make it "computational" in any meaningful way - you need to convert it into a def for that

Kevin Buzzard (Dec 19 2021 at 12:20):

What does the fact that a proof exists have to do with writing an algorithm to come up with these numbers? Aren't these two distinct questions?

Eric Wieser (Dec 19 2021 at 12:35):

Well, a proof that the thing you're trying to calculate exists is a nice thing to have before wasting time on an algorithm to calculate something that doesn't

Kevin Buzzard (Dec 19 2021 at 12:49):

Sure but you can get that proof from Wikipedia. Its formalisation doesn't help, it's an independent thing, is what I'm suggesting.

Stuart Presnell (Dec 19 2021 at 13:10):

Well, a constructive mathematician might expect a term of the type ∀ n : ℕ, ∃ a b c d : ℕ, a^2 + b^2 + c^2 + d^2 = n to be a function that takes an n : ℕ as input and returns a quadruple a b c d : ℕ and a proof that they satisfy the equation. So from that perspective a proof and an algorithm are just the same, and so you might guess that it's the use of classical reasoning that lets you say "I can prove that a b c d : ℕ exist without working out what they are".

Eric Wieser (Dec 19 2021 at 13:19):

But that's not what ∃ x, p x means in lean, you want { x // p x} for that

Stuart Presnell (Dec 19 2021 at 13:23):

Sure, but I suspect this distinction trips up newcomers a lot and may have been at play in this question

Kevin Buzzard (Dec 19 2021 at 13:39):

The constructive mathematicians have gone off to use Coq and Agda a long time ago

Trebor Huang (Dec 19 2021 at 15:05):

Generally proofs may not directly reveal a program. But given that here the search space is just the integers in [0, p-1]^4, we can easily write a program that enumerates them, and the non-computational proof can then be used to prove that the search always yields a value, I think?

Eric Wieser (Dec 19 2021 at 15:19):

I don't think it's worth mathlib having the algorithm unless we have a less naive algorithm!

Eric Wieser (Dec 19 2021 at 15:19):

Perhaps we should have a version of docs#nat.find for docs#enumerable types like 4-tuples of nat

Eric Wieser (Dec 19 2021 at 15:20):

Which would be the API for the dumb algorithm

Yaël Dillies (Dec 19 2021 at 15:21):

You can just use lex ℕ (lex ℕ (lex ℕ ℕ)).

Eric Wieser (Dec 19 2021 at 15:32):

How does that help without the enumerable version of find?

Eric Wieser (Dec 19 2021 at 15:33):

ℕ × ℕ × ℕ × ℕ already has an enumerable instance

Yaël Dillies (Dec 19 2021 at 15:33):

Ah, that assumed an enumerablt version of nat.find, which is pretty easy to bodge together anyway.

Ruben Van de Velde (Dec 19 2021 at 15:33):

Well yes, but the enumerating program will work regardless of the proof - you certainly don't need it to be constructive or even be formalized

Eric Wieser (Dec 19 2021 at 15:34):

My point is that if we had the tools to easily build such enumeration programs in a single line from an existential, then mathlib wouldn't need to provide the programs themselves

Yaël Dillies (Dec 19 2021 at 15:36):

Note that, unless we have bootstrapping problems, one possibility is to straight up generalize nat.find to take in an enumerable instance.

Eric Wieser (Dec 19 2021 at 15:47):

It's in core so that's a bad option

Eric Wieser (Dec 19 2021 at 15:47):

Better would be to just add encodable.find next to docs#encodable

Eric Wieser (Dec 19 2021 at 15:48):

But it might exist already

Kevin Buzzard (Dec 19 2021 at 16:05):

The non-naive algorithms I know involve factoring, so if we want a non-naive algorithm then probably we first want a non-naive factoring algorithm. Fortunately we have tons of theorems about number fields :D

Eric Rodriguez (Dec 19 2021 at 16:17):

gnfs in lean when? ;b

Kevin Buzzard (Dec 19 2021 at 16:23):

The serious answer is to wait until Lean 4. Of course nothing needs verifying in this algorithm; who cares if it's bug-free, if it factors, it factors.


Last updated: Dec 20 2023 at 11:08 UTC