Zulip Chat Archive

Stream: maths

Topic: Difficulty of formalizing a polynomial in Lean4


Brisal (Oct 16 2025 at 07:58):

Hello! I want to formalize the following Polynomial:
(x^(-3) + x^(-2) + ... + x^2 + x^3) ^ 4

This is my #mwe

import Mathlib
def I := Finset.Icc (-3 : ) 3

noncomputable def tset : Polynomial  :=
   i  I, if (0 : )  i then Polynomial.X ^ (i.toNat)
  else (1 / Polynomial.X) ^ ((-i).toNat)

Is it right? Or maybe it has another way to formalize this.

Brisal (Oct 16 2025 at 08:02):

Maybe it should ues PowerSeries? :thinking:

Yaël Dillies (Oct 16 2025 at 08:03):

Indeed! This is not a polynomial

Brisal (Oct 16 2025 at 08:14):

Yaël Dillies said:

Indeed! This is not a polynomial

I'm really sorry, but I'm not quite sure how to formalize this. Could you please write an example for this one?

Kevin Buzzard (Oct 16 2025 at 08:16):

It's impossible to formlize "the polynomial (x^(-3) + x^(-2) + ... + x^2 + x^3) ^ 4" because that's not a polynomial (the x3x^{-3} term is not allowed in a polynomial, by definition of polynomial). So you have to formalize something else. There are power series, Hahn series, rational functions, meromorphic functions and even occasionally-junk-valued functions all called (x^(-3) + x^(-2) + ... + x^2 + x^3) ^ 4 but until you say what the question is very precisely, it's difficult to answer it.

Kevin Buzzard (Oct 16 2025 at 08:19):

A theorem prover is an extremely pedantic thing. Even if you were to come here asking how to formalize 37, there would be the same question: do you mean the natural number 37, the integer 37, the real number 37, the p-adic number 37, the quaternion 37 etc etc.

In fact one of the subquestions here is: when you say x2x^2 you really mean 1×x21\times x^2. Which 1 is that?

Brisal (Oct 16 2025 at 08:23):

Kevin Buzzard said:

It's impossible to formlize "the polynomial (x^(-3) + x^(-2) + ... + x^2 + x^3) ^ 4" because that's not a polynomial (the x3x^{-3} term is not allowed in a polynomial, by definition of polynomial). So you have to formalize something else. There are power series, Hahn series, rational functions, meromorphic functions and even occasionally-junk-valued functions all called (x^(-3) + x^(-2) + ... + x^2 + x^3) ^ 4 but until you say what the question is very precisely, it's difficult to answer it.

I indeed didn't state the requirements clearly. Actually, I'm formalizing an exercise problem:

"Build a generating function for $a_{r}$, the number of integer solutions to e_1 + e_2 + e_3 + e_4 = r, -3 \leq e_j \leq 3."

The answer is $x^{-3} + x^{-2} + \cdots + x^2 + x^3)^4.

Kevin Buzzard (Oct 16 2025 at 08:26):

Can I ask you another question? Can you build a generating function for brb_{r}, where brb_{r} is always 37? What would your answer to that be?

Brisal (Oct 16 2025 at 08:30):

Kevin Buzzard said:

Can I ask you another question? Can you build a generating function for brb_{r}, where brb_{r} is always 37? What would your answer to that be?

Like

PowerSeries.mk (fun _ => (37 : ))

? Not for sure.

Philippe Duchon (Oct 16 2025 at 08:32):

If you want to take formal finite sums of integer powers of an indeterminate (which looks like this is what you want to do), Mathlib has LaurentPolynomial (of course power series by themselves won't do the trick). It also has LaurentSeries (finite support in the negative integers).

I don't think Mathlib has very good support for generating functions (in the enumerative combinatorics sense) at the moment, even when the solutions are "just" power series; going with negative exponents is only making it more complex.

Brisal (Oct 16 2025 at 08:34):

Philippe Duchon said:

If you want to take formal finite sums of integer powers of an indeterminate (which looks like this is what you want to do), Mathlib has LaurentPolynomial (of course power series by themselves won't do the trick). It also has LaurentSeries (finite support in the negative integers).

I don't think Mathlib has very good support for generating functions (in the enumerative combinatorics sense) at the moment, even when the solutions are "just" power series; going with negative exponents is only making it more complex.

I got that. I fact I've tried to use LaurentPolynomial and LaurentSeries to solve this problem., but finally I found that is difficult.

Kenny Lau (Oct 16 2025 at 08:51):

Risal said:

Like

PowerSeries.mk (fun _ => (37 : ))

? Not for sure.

why R?

Brisal (Oct 16 2025 at 08:59):

Kenny Lau said:

Risal said:

Like

PowerSeries.mk (fun _ => (37 : ))

? Not for sure.

why R?

I'm more accustomed to adding R, so this works: PowerSeries.mk (fun _ => 37)

Kenny Lau (Oct 16 2025 at 11:03):

the point of Kevin's question is to ask you what type 37 should be, and in your new answer you've left out its type

Aaron Liu (Oct 16 2025 at 11:06):

well the default is Nat

Riccardo Brasca (Oct 16 2025 at 11:10):

@Risal what we are trying to say is that the problem here is mathematical before being about Lean. You say you are interested in x3+x2+x^{-3} + x^{-2} + \cdots: but what kind of object is this for you? We don't want a super precise answer (Lean will want this, but we can help), but you cannot say "it's a polynomial", as polynomials don't have monomial of negative degree. You may want:

Eric Wieser (Oct 16 2025 at 11:11):

docs#LaurentPolynomial indeed seems like a good fit here

Kevin Buzzard (Oct 16 2025 at 11:12):

Another point is this (which I was going to get to later). I wanted to let rr be an integer, because that seems to be what's happening in the original question. So the answer to my question must be something like nZ37xn\sum_{n\in\Z}37x^n. But the original question has a ^4 in which means that the target type must have exponentiation by a positive natural. But what the heck does (nZ37xn)4(\sum_{n\in\Z}37x^n)^4 mean? This involves non-convergent sums 37+37+37+37+... .

Weiyi Wang (Oct 16 2025 at 12:21):

Philippe Duchon said:

I don't think Mathlib has very good support for generating functions (in the enumerative combinatorics sense) at the moment, even when the solutions are "just" power series; going with negative exponents is only making it more complex.

On a related note, I started working on some of these in #30567

Brisal (Oct 17 2025 at 06:50):

Thank for everyone's advice. I'm going to learn how to formalize it in Laurent ploynomials,

Brisal (Oct 17 2025 at 06:53):

Riccardo Brasca said:

Risal what we are trying to say is that the problem here is mathematical before being about Lean. You say you are interested in x3+x2+x^{-3} + x^{-2} + \cdots: but what kind of object is this for you? We don't want a super precise answer (Lean will want this, but we can help), but you cannot say "it's a polynomial", as polynomials don't have monomial of negative degree. You may want:

Thank you for your help. In fact, I am indeed unfamiliar with the mathematics in this field. I will look into it.

Timothy Chow (Oct 18 2025 at 11:51):

In enumerative combinatorics, one is usually interested in a formal power series ring such as

Q[[x]]\mathbb{Q}[[x]]

or maybe a formal Laurent series ring when (as here) one wants negative exponents. But one complication is that when the coefficients don't grow too fast, one often wants to treat the series as a holomorphic function, and apply complex-analytic techniques to estimate the growth rate of the coefficients. Of course all this is overkill for the original question which involves only a Laurent polynomial, but maybe one should be prepared for the possibility that the next few exercises will involve power series.


Last updated: Dec 20 2025 at 21:32 UTC