Zulip Chat Archive

Stream: Is there code for X?

Topic: GaussianRat


Geoffrey Irving (Jan 12 2024 at 16:45):

Do we have Q[i]\mathbb{Q}[i] (the rational equivalent of GaussianInt)?

Geoffrey Irving (Jan 12 2024 at 16:45):

Oops, seems I don't know the syntax for inline latex (fixed).

Ruben Van de Velde (Jan 12 2024 at 16:45):

Double dollars

Johan Commelin (Jan 12 2024 at 16:47):

Not in mathlib, afaik. But the VU (A'dam) project had quad_ring for quadratic number fields.

Geoffrey Irving (Jan 12 2024 at 16:48):

I'll just spell it out as tuples for now; I need only a tiny bit of it.

Eric Wieser (Jan 12 2024 at 16:52):

CliffordAlgebra (-.sq : QuadraticForm ℚ ℚ), but it's computationally awful :upside_down:

Geoffrey Irving (Jan 12 2024 at 16:54):

I think ℚ × ℚ is easier for the moment. Mostly I want to take linear combinations. :)

Eric Wieser (Jan 12 2024 at 16:55):

Also discussed here:

Eric Wieser said:

A question for the community: is it time to merge some subset of docs#ZSqrtd and docs#Complex and docs#GaussianInt and docs#Unitization and docs#TrivSqZeroExt into a single structure that would work here too for Q[d]\mathbb{Q}[\sqrt{d}]?

Riccardo Brasca (Jan 12 2024 at 17:05):

I think that independently of the spell we choose we want a characteristic predicate rather than an explicit definition.

Kevin Buzzard (Jan 12 2024 at 17:38):

Well that will raise an interesting question because these objects have a nontrivial automorphism so are not the solution to a (certain kind of) universal problem. You can be isomorphic to Q(i)\mathbb{Q}(i) in two ways, and for all most of the other characteristic predicates we have (e.g. localisations in algebra, and limits/colimits in category theory) they are characterising something rigid (i.e. no nontrivial automorphisms).

Kevin Buzzard (Jan 12 2024 at 17:39):

You can do the ugly thing and choose an ii but this is like choosing a basis -- this is breaking symmetry and proving certain theorems will be harder.

Geoffrey Irving (Jan 12 2024 at 18:03):

The type class could pick out i.

Adam Topaz (Jan 12 2024 at 18:04):

Riccardo Brasca said:

I think that independently of the spell we choose we want a characteristic predicate rather than an explicit definition.

+1 for this (and similarly for everything else in mathlib)

Adam Topaz (Jan 12 2024 at 18:05):

I'm starting to think more and more that literally everything we define should have a "characteristic predicate" of some sort

Johan Commelin (Jan 12 2024 at 18:14):

@Kevin Buzzard We already have a predicate for algebraic closures, right?

Adam Topaz (Jan 12 2024 at 18:15):

docs#IsAlgebraicClosure

Kevin Buzzard (Jan 12 2024 at 18:16):

That's a 404 but you might be right (I changed "all" to "most" :-) )

Adam Topaz (Jan 12 2024 at 18:16):

I guess we have IsAlgebraic and AlgebraicallyClosed

Kevin Buzzard (Jan 12 2024 at 18:20):

The issue will be that the proposition isGaussianRat will be a proposition but it won't be as useful as you think (e.g. you won't be able to get a map to the complexes because you'll have to choose an ii) and isPointedGaussianRatwill involve a choice so won't be a Prop and there will be a risk of diamonds.

Adam Topaz (Jan 12 2024 at 18:22):

But something can surely be done since you can characterize the Gaussian rats as the unique extension of $$\Q$$ of degree 2 which contains some element whose square is 1-1.

Michael Stoll (Jan 12 2024 at 18:22):

Why should Q(i)\mathbb{Q}(i) get preferential treatment among all nontrivial number fields? (Also, we do have CylcotomicField 4 Rat.)

Adam Topaz (Jan 12 2024 at 18:22):

It shouldn't.

Michael Stoll (Jan 12 2024 at 18:23):

So there should be predicates for each other number field as well? :smile:

Adam Topaz (Jan 12 2024 at 18:23):

I'm claiming that the answer is yes, for the explicit number fields

Michael Stoll (Jan 12 2024 at 18:24):

What is an "explicit number field"?

Adam Topaz (Jan 12 2024 at 18:24):

I knew you were going to ask that :)

Adam Topaz (Jan 12 2024 at 18:24):

And I don't have an answer

Michael Stoll (Jan 12 2024 at 18:25):

Q(23)\mathbb{Q}(\sqrt[3]{2}), Q(3+5)\mathbb{Q}(\sqrt{\sqrt{3}+5}), ...

Adam Topaz (Jan 12 2024 at 18:26):

I guess given some field KK and some irreducible poly ff you could make a characteristic predicate for an extension of KK generated by a root of ff.

Michael Stoll (Jan 12 2024 at 18:27):

"There exists a Q\mathbb{Q}-algebra isomorphism with Q[X]/f\mathbb{Q}[X]/\langle f \rangle".

Adam Topaz (Jan 12 2024 at 18:28):

Yeah something like that

Adam Topaz (Jan 12 2024 at 18:29):

But then the point is that given a field with such an instance the only things you will ever be able to say about such a field must be compatible with that algebra iso, and you couldn’t use any other implementation details

Junyan Xu (Jan 12 2024 at 18:48):

docs#IsAdjoinRoot is apparently not well known enough ...

Adam Topaz (Jan 12 2024 at 18:50):

But that has data!

Adam Topaz (Jan 12 2024 at 18:50):

so it does "choose a basis"

Adam Topaz (Jan 12 2024 at 18:51):

I'm sure now Kevin will contest the use of "Is" in "IsAdjointRoot"

Kevin Buzzard (Jan 12 2024 at 19:34):

Yes I think it's a great shame that there are type-valued declarations called Is..., with IsROrC being the canonical one I complain about.

Yaël Dillies (Jan 12 2024 at 20:24):

Kevin Buzzard said:

You can do the ugly thing and choose an $i$ but this is like choosing a basis -- this is breaking symmetry and proving certain theorems will be harder.

Okay but you could have a type synonym OtherC which has an IsROrC instance where I := -I. Similarly, you could have synonyms which change the non-canonical choice of basis.

Kevin Buzzard (Jan 12 2024 at 20:35):

Yes but these ideas which people have about this topic just sound to me like it's 1900 and people are saying "you don't need vector spaces, you can just use R^n and carry around matrices". Yes you can do this, I'm just saying it's a lousy idea! However I've never managed to explicitly give an example of this because we're nowhere near the part of the Langlands philosophy where you see the issues in lean yet.

Basically I'm going to come back to this later and do IsROrC the way I want to do it but only when I need it which might be in quite a long time

Adam Topaz (Jan 12 2024 at 20:46):

"IsRorC done right"

Andrew Yang (Jan 12 2024 at 20:50):

What about Polynomial.IsSplittingField ℚ K (Polynomial.X ^ 2 + 1) using docs#Polynomial.IsSplittingField

Junyan Xu (Jan 12 2024 at 21:32):

We can in fact characterize an algebraic extension (not necessarily normal) by the set of polynomials in the base field that have a root in it, or equivalently by the set of minimal polynomials of its elements over the base field, but those are not finite amounts of data. See I.M.Isaacs, Roots of Polynomials in Algebraic Extensions of Fields.
image.png
image.png

Junyan Xu (Jan 12 2024 at 21:32):

Back to the original question: the simplest concrete model is probably AdjoinRoot ℚ (X^2+1), which is simpler than both SplittingField (how docs#CyclotomicField is defined) and CliffordAlgebra.

If the focus is on computability we should introduce something like docs#Zsqrtd but in a more general form. docs#ZSqrtd and docs#Complex are both homogeneous products, i.e. of the form R × R (but packaged as a structure). The other two examples docs#Unitization and docs#TrivSqZeroExt that Eric gave are heterogeneous products (also allow different universes).

For computing with number fields, rings and finite fields it's probably more important to generalize the former two from R × R to Fin n → R, and generalize the polynomials X^2-d and X^2+1 to arbitrary monic polynomials. The addition already comes with Fin n → R and the multiplication can be easily defined computably like this, but I didn't go on to prove it's isomorphic to AdjoinRoot as an R-algebra. As I remarked there, even though you can characterize finite fields as splitting fields of X^p^n-X or just by the cardinality p^n, for concrete computations you'd still choose a primitive polynomial Fin n → 𝔽_p .

Kevin Buzzard (Jan 12 2024 at 21:34):

If there really is a need for concrete quadratic stuff then perhaps one should just define R[X]/(X2+aX+b)R[X]/(X^2+aX+b) as a function of RR, aa and bb as re, im : R with the induced +,- and *.

Kevin Buzzard (Jan 12 2024 at 21:35):

I am slightly concerned that this is just making another way to do something we can already do though

Michael Stoll (Jan 12 2024 at 21:36):

That would also be convenient for working with hyperelliptic curves, for example.

Junyan Xu (Jan 12 2024 at 21:40):

Projective coordinates for elliptic curves #8485 originally used the "structure with three fields" design but David changed it to Fin 3 → R by my request, because there's already a Units R-action on it that you'd quotient by, and it's easier to connect to MvPolynomial.

Michael Stoll (Jan 12 2024 at 21:41):

I think it does make sense to have a representation for quadratic rings and fields that is convenient to use with concrete examples, as they tend to occur quite a bit more frequently in applications than more general extensions.

Junyan Xu (Jan 12 2024 at 21:41):

If you make a structure re, im : R you need to manually put the +,- instances, and I wouldn't call the * induced.

Michael Stoll (Jan 12 2024 at 21:42):

You possibly could use the isomorphism with Fin 2 \to R to transport the structure?

Junyan Xu (Jan 12 2024 at 21:43):

as they tend to occur quite a bit more frequently in applications than more general extensions.

If that's the case then it's better to follow Eric's suggestion to unify all four.

Junyan Xu (Jan 12 2024 at 21:44):

Yeah, it would be reasonable to define the AdjoinRoot algebra structure on Fin n → R generally and transport to R x R in the special case of quadratic rings.

Andrew Yang (Jan 12 2024 at 21:48):

If we are fine with choosing a root why not just use AdjoinRoot and define re and im as b.basis.repr · 0 and b.basis.repr · 1 where b is some docs#AdjoinRoot.powerBasis

Junyan Xu (Jan 12 2024 at 21:50):

AdjoinRoot is defined using Polynomial, so I don't think anything that goes through it can be computable ... (I guess it's a more subtle question whether the kernel could reduce results of operations to a normal form, though.)

Andrew Yang (Jan 12 2024 at 21:52):

Do we really care about computable computable? I thought having a good set of simp lemmas and/or tactics is the computable we care about.

Geoffrey Irving (Jan 12 2024 at 22:00):

The thread has diverged a fair ways, but in my actual use case I do need it to be fully computational. But I'm also happy with just tuples for now, and in general I'm okay if computational needs define their own types with noncomputable isomorphisms into the mathematical structures for proving theorems.

Junyan Xu (Jan 12 2024 at 22:09):

In that case you can take a look at Formalized Class Group Computations and Integral Points on Mordell Elliptic Curves by @Anne Baanen @Alex J. Best et al. The code is here and they actually took the "structure with two fields approach" rather than Fin 2 → R :melting_face:
image.png

Junyan Xu (Jan 12 2024 at 22:16):

Do we really care about computable computable? I thought having a good set of simp lemmas and/or tactics is the computable we care about.

It's nice to be able to prove identities in ℕ, ℤ, and ℚ by rfl, and it would be nice to extend this to finite extensions of them. There are occasionally talks about proofs by reflection too ... I realize that Fin n → R doesn't quite serve this goal (unlike R × R) because rfl won't do funext and fin_cases, but by decide probably works. AdjoinRoot is a quotient type and certainly doesn't reduce the representative to something of lower degree, but I realize you can probably put a DecidableEq instance on it to make by decide work too.

Edit: I think the instance can be constructed computably (if the monic polynomial p you mod by has a computable support and if the ring has DecidableEq), but would require you redefine modByMonic in a computable way (but you can do that within your decision algorithm). Once the polynomials are reduced to degree < n := natDegree p you can just compare the first n coefficients. The problem is that this instance won't be able to decide an equality between terms that involve polynomial multiplication, because a coefficient of a product of polynomials is a sum over a Finset constructed from the supports, and if the supports are noncomputable (e.g. from an earlier addition or multiplication step) then the coefficient won't reduce. So unless we redefine polynomial multiplication in a computable way (for your specific ring with DecidableEq, or use the DFinsupp approach) the instance won't be of much use.

Junyan Xu (Feb 12 2024 at 09:26):

I'd like to report here that I developed a framework that allows computing polynomial operations and deciding properties by kernel reduction (rfl) using typeclasses as opposed to meta-programming, but I haven't got time to implement computations in AdjoinRoot following this approach yet. Details are in this thread


Last updated: May 02 2025 at 03:31 UTC