hex

7.8. The Mathlib correspondence🔗

Everything above is executable and Mathlib-free. HexPolyTheory connects it to Mathlib: every Hex.DensePoly corresponds to a Mathlib Polynomial with the same coefficients. The two transfer maps go each way.

🔗def
HexPolyTheory.toPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Hex.DensePoly R) : Polynomial R
HexPolyTheory.toPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Hex.DensePoly R) : Polynomial R

Interpret a normalized dense coefficient array as a Mathlib polynomial.

🔗def
HexPolyTheory.ofPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Polynomial R) : Hex.DensePoly R
HexPolyTheory.ofPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Polynomial R) : Hex.DensePoly R

Rebuild a normalized dense polynomial from the coefficients of a Mathlib polynomial.

They are mutually inverse:

🔗theorem
HexPolyTheory.toPolynomial_ofPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Polynomial R) : HexPolyTheory.toPolynomial (HexPolyTheory.ofPolynomial p) = p
HexPolyTheory.toPolynomial_ofPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Polynomial R) : HexPolyTheory.toPolynomial (HexPolyTheory.ofPolynomial p) = p

Converting a Mathlib polynomial into the executable representation and back recovers the original: HexPolyTheory.toPolynomial is a left inverse of HexPolyTheory.ofPolynomial.

🔗theorem

Converting an executable polynomial into a Mathlib polynomial and back recovers the original: HexPolyTheory.ofPolynomial is a left inverse of HexPolyTheory.toPolynomial.

HexPolyTheory.toPolynomial is a degree-preserving ring homomorphism. Addition, multiplication, and the degree transfer:

🔗theorem

HexPolyTheory.toPolynomial commutes with polynomial addition.

🔗theorem

HexPolyTheory.toPolynomial commutes with polynomial multiplication.

🔗theorem
HexPolyTheory.natDegree_toPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Hex.DensePoly R) : (HexPolyTheory.toPolynomial p).natDegree = p.natDegree
HexPolyTheory.natDegree_toPolynomial.{u} {R : Type u} [Semiring R] [DecidableEq R] (p : Hex.DensePoly R) : (HexPolyTheory.toPolynomial p).natDegree = p.natDegree

HexPolyTheory.toPolynomial transports the executable degree to Mathlib's natDegree, with the zero polynomial mapping to 0.

The maps and laws bundle into a ring equivalence, and divisibility transfers through it:

🔗def
HexPolyTheory.equiv.{u} {R : Type u} [Semiring R] [DecidableEq R] : Hex.DensePoly R ≃+* Polynomial R
HexPolyTheory.equiv.{u} {R : Type u} [Semiring R] [DecidableEq R] : Hex.DensePoly R ≃+* Polynomial R

The executable dense-polynomial representation is ring-equivalent to Mathlib polynomials.

🔗theorem
HexPolyTheory.toPolynomial_dvd_iff.{u} {R : Type u} [Semiring R] [DecidableEq R] {p q : Hex.DensePoly R} : HexPolyTheory.toPolynomial p ∣ HexPolyTheory.toPolynomial q ↔ p ∣ q
HexPolyTheory.toPolynomial_dvd_iff.{u} {R : Type u} [Semiring R] [DecidableEq R] {p q : Hex.DensePoly R} : HexPolyTheory.toPolynomial p ∣ HexPolyTheory.toPolynomial q ↔ p ∣ q

HexPolyTheory.toPolynomial both preserves and reflects divisibility: executable polynomials divide one another exactly when their Mathlib images do.