'Lawful' finite supports #
This file defines the Lawful subtype, which consists of Unlawful polynomials
where all stored coefficients are guaranteed to be non-zero. This provides a canonical
representation (similar to Finsupp) and is the primary representation used for
computable multivariate polynomials.
Main definitions #
CPoly.Lawful n R: The subtype ofUnlawful n Rwith no zero coefficients.
The subtype of polynomials with no zero coefficients.
Equations
- CPoly.Lawful n R = { p : CPoly.Unlawful n R // p.isNoZeroCoef }
Instances For
instance
CPoly.instGetElemLawfulCMvMonomialMemUnlawfulValIsNoZeroCoef
{n : ℕ}
{R : Type}
[Zero R]
:
GetElem (Lawful n R) (CMvMonomial n) R fun (lp : Lawful n R) (m : CMvMonomial n) => m ∈ ↑lp
Equations
- CPoly.instGetElemLawfulCMvMonomialMemUnlawfulValIsNoZeroCoef = { getElem := fun (lp : CPoly.Lawful n R) (m : CPoly.CMvMonomial n) (h : m ∈ ↑lp) => (↑lp)[m] }
instance
CPoly.instGetElem?LawfulCMvMonomialMemUnlawfulValIsNoZeroCoef
{n : ℕ}
{R : Type}
[Zero R]
:
GetElem? (Lawful n R) (CMvMonomial n) R fun (lp : Lawful n R) (m : CMvMonomial n) => m ∈ ↑lp
Equations
- One or more equations did not get rendered due to their size.
instance
CPoly.instMembershipCMvMonomialLawful
{n : ℕ}
{R : Type}
[Zero R]
:
Membership (CMvMonomial n) (Lawful n R)
Equations
- CPoly.instMembershipCMvMonomialLawful = { mem := fun (lp : CPoly.Lawful n R) (m : CPoly.CMvMonomial n) => m ∈ ↑lp }
instance
CPoly.instLawfulGetElemLawfulCMvMonomialMem
{n : ℕ}
{R : Type}
[Zero R]
:
LawfulGetElem (Lawful n R) (CMvMonomial n) R fun (lp : Lawful n R) (m : CMvMonomial n) => m ∈ lp
@[simp]
theorem
CPoly.Lawful.mem_iff_cast
{n : ℕ}
{R : Type}
[Zero R]
{p : Lawful n R}
{x : CMvMonomial n}
:
def
CPoly.Lawful.fromUnlawful
{n : ℕ}
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
(p : Unlawful n R)
:
Lawful n R
Convert an Unlawful polynomial to a Lawful one by filtering out zero coefficients.
Equations
- CPoly.Lawful.fromUnlawful p = ⟨Std.ExtTreeMap.filter (fun (x : CPoly.CMvMonomial n) (c : R) => c != 0) p, ⋯⟩
Instances For
Equations
- CPoly.Lawful.instOfNat_zero = { ofNat := CPoly.Lawful.C 0 }
@[simp]
theorem
CPoly.Lawful.not_mem_zero
{n : ℕ}
{R : Type}
[Zero R]
{x : CMvMonomial n}
[BEq R]
[LawfulBEq R]
:
x ∉ 0
Equations
- CPoly.Lawful.instAdd = { add := CPoly.Lawful.add }
theorem
CPoly.Lawful.grind_add_skip_aggressive
{n : ℕ}
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
[Add R]
{p₁ p₂ : Lawful n R}
:
p₁ + p₂ = fromUnlawful (Std.ExtTreeMap.mergeWith (fun (x : CMvMonomial n) (c₁ c₂ : R) => c₁ + c₂) ↑p₁ ↑p₂)
Note to self: This goes too far.
instance
CPoly.Lawful.instNatPowOfNatCastOfAddOfMul
{n : ℕ}
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
[NatCast R]
[Add R]
[Mul R]
:
Equations
- CPoly.Lawful.instNatPowOfNatCastOfAddOfMul = { pow := fun (e : CPoly.Lawful n R) (b : ℕ) => CPoly.Lawful.npow b e }
Check if a polynomial is a non-zero constant.
Equations
- p.NZConst = (Std.ExtTreeMap.size ↑p = 1 ∧ Std.ExtTreeMap.contains (↑p) CPoly.CMvMonomial.zero = true)
Instances For
Equations
- CPoly.Lawful.instNeg = { neg := CPoly.Lawful.neg }
instance
CPoly.Lawful.instDecidableEq
{n : ℕ}
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
[DecidableEq R]
:
DecidableEq (Lawful n R)
Equations
- x.instDecidableEq y = if h : Std.ExtTreeMap.toList ↑x = Std.ExtTreeMap.toList ↑y then isTrue ⋯ else isFalse ⋯
The $i$-th variable as a polynomial.
Equations
Instances For
def
CPoly.Lawful.liftPoly
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
{n₁ n₂ : ℕ}
(f : Lawful (max n₁ n₂) R → Lawful (max n₁ n₂) R → Lawful (max n₁ n₂) R)
(p₁ : Lawful n₁ R)
(p₂ : Lawful n₂ R)
:
Lift a binary polynomial operation to handle polynomials with different numbers of variables.
Equations
- CPoly.Lawful.liftPoly f p₁ p₂ = Function.uncurry f (p₁.align p₂)
Instances For
@[instance 100]
instance
CPoly.Lawful.instHAddMaxNatOfAdd
{R : Type}
[Zero R]
[BEq R]
[LawfulBEq R]
{n₁ n₂ : ℕ}
[Add R]
:
Equations
- CPoly.Lawful.instHAddMaxNatOfAdd = { hAdd := fun (p₁ : CPoly.Lawful n₁ R) (p₂ : CPoly.Lawful n₂ R) => CPoly.Lawful.liftPoly (fun (x1 x2 : CPoly.Lawful (max n₁ n₂) R) => x1 + x2) p₁ p₂ }