Skip to content

Commit

Permalink
chore(data/finsupp): drop finsupp.module and vector_space (#3009)
Browse files Browse the repository at this point in the history
These instances are not needed as `module` and `vector_space` are abbreviations for `semimodule`.

Also add two bundled versions of `eval`: as `add_monoid_hom` and as `linear_map`.
  • Loading branch information
urkud committed Jun 11, 2020
1 parent cf0c6b8 commit ce48b6b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
30 changes: 22 additions & 8 deletions src/data/finsupp.lean
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ instance : add_monoid (α →₀ β) :=
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }

instance (a : α) : is_add_monoid_hom (λ g : α →₀ β, g a) :=
{ map_add := λ _ _, add_apply, map_zero := zero_apply }
/-- Evaluation of a function `f : α →₀ β` at a point as an additive monoid homomorphism. -/
def eval_add_hom (a : α) : (α →₀ β) →+ β := ⟨λ g, g a, zero_apply, λ _ _, add_apply⟩

@[simp] lemma eval_add_hom_apply (a : α) (g : α →₀ β) : eval_add_hom a g = g a := rfl

lemma single_add_erase {a : α} {f : α →₀ β} : single a (f a) + f.erase a = f :=
ext $ λ a',
Expand Down Expand Up @@ -670,7 +672,7 @@ instance [add_comm_group β] : add_comm_group (α →₀ β) :=
@[simp] lemma sum_apply [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β} {a₂ : α} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(f.support.sum_hom (λf : α →₀ β, f a₂)).symm
(eval_add_hom a₂ : (α →₀ β) →+ _).map_sum _ _

lemma support_sum [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → (α →₀ β)} :
Expand Down Expand Up @@ -1406,13 +1408,25 @@ instance [semiring γ] [add_comm_monoid β] [semimodule γ β] : semimodule γ (
zero_smul := λ x, ext $ λ _, zero_smul _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }

instance [ring γ] [add_comm_group β] [module γ β] : module γ (α →₀ β) :=
{ ..finsupp.semimodule α β }
variables {α β} (γ)

/-- Evaluation at point as a linear map. This version assumes that the codomain is a semimodule
over some semiring. See also `leval`. -/
def leval' [semiring γ] [add_comm_monoid β] [semimodule γ β] (a : α) :
(α →₀ β) →ₗ[γ] β :=
⟨λ g, g a, λ _ _, add_apply, λ _ _, rfl⟩

@[simp] lemma coe_leval' [semiring γ] [add_comm_monoid β] [semimodule γ β] (a : α) (g : α →₀ β) :
leval' γ a g = g a :=
rfl

variable {γ}

/-- Evaluation at point as a linear map. This version assumes that the codomain is a semiring. -/
def leval [semiring β] (a : α) : (α →₀ β) →ₗ[β] β := leval' β a

instance [field γ] [add_comm_group β] [vector_space γ β] : vector_space γ (α →₀ β) :=
{ ..finsupp.module α β }
@[simp] lemma coe_leval [semiring β] (a : α) (g : α →₀ β) : leval a g = g a := rfl

variables {α β}
lemma support_smul {R:semiring γ} [add_comm_monoid β] [semimodule γ β] {b : γ} {g : α →₀ β} :
(b • g).support ⊆ g.support :=
λ a, by simp only [smul_apply', mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
Expand Down
6 changes: 0 additions & 6 deletions src/data/monoid_algebra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ finsupp.has_scalar
instance [semiring k] : semimodule k (monoid_algebra k G) :=
finsupp.semimodule G k

instance [ring k] : module k (monoid_algebra k G) :=
finsupp.module G k

lemma single_one_comm [comm_semiring k] [monoid G] (r : k) (f : monoid_algebra k G) :
single 1 r * f = f * single 1 r :=
by { ext, rw [single_one_mul_apply, mul_single_one_apply, mul_comm] }
Expand Down Expand Up @@ -582,9 +579,6 @@ finsupp.has_scalar
instance [semiring k] : semimodule k (add_monoid_algebra k G) :=
finsupp.semimodule G k

instance [ring k] : module k (add_monoid_algebra k G) :=
finsupp.module G k

instance [comm_semiring k] [add_monoid G] : algebra k (add_monoid_algebra k G) :=
{ to_fun := single 0,
map_one' := rfl,
Expand Down
10 changes: 3 additions & 7 deletions src/data/mv_polynomial.lean
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ instance decidable_eq_mv_polynomial [decidable_eq σ] [decidable_eq α] :
decidable_eq (mv_polynomial σ α) := finsupp.decidable_eq
instance : comm_semiring (mv_polynomial σ α) := add_monoid_algebra.comm_semiring
instance : inhabited (mv_polynomial σ α) := ⟨0
instance : has_scalar α (mv_polynomial σ α) := add_monoid_algebra.has_scalar
instance : semimodule α (mv_polynomial σ α) := add_monoid_algebra.semimodule
instance : algebra α (mv_polynomial σ α) := add_monoid_algebra.algebra

/-- the coercion turning an `mv_polynomial` into the function which reports the coefficient of a given monomial -/
def coeff_coe_to_fun : has_coe_to_fun (mv_polynomial σ α) :=
Expand Down Expand Up @@ -894,8 +897,6 @@ variable [comm_ring α]
variables {p q : mv_polynomial σ α}

instance : comm_ring (mv_polynomial σ α) := add_monoid_algebra.comm_ring
instance : has_scalar α (mv_polynomial σ α) := finsupp.has_scalar
instance : module α (mv_polynomial σ α) := finsupp.module (σ →₀ ℕ) α

instance C.is_ring_hom : is_ring_hom (C : α → mv_polynomial σ α) :=
by apply is_ring_hom.of_semiring
Expand Down Expand Up @@ -1032,11 +1033,6 @@ end total_degree
section aeval

/-- The algebra of multivariate polynomials. -/
-- FIXME this causes a deterministic timeout with `-T50000` (but `-T60000` seems okay)
instance mv_polynomial (R : Type u) [comm_ring R] (σ : Type v) : algebra R (mv_polynomial σ R) :=
{ commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, (mv_polynomial.C_mul' c p).symm,
.. ring_hom.of mv_polynomial.C, .. mv_polynomial.module }

variables (R : Type u) (A : Type v) (f : σ → A)
variables [comm_ring R] [comm_ring A] [algebra R A]
Expand Down
2 changes: 0 additions & 2 deletions src/data/polynomial.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ end comm_semiring
section comm_ring
variables [comm_ring R] {p q : polynomial R}
instance : comm_ring (polynomial R) := add_monoid_algebra.comm_ring
instance : module R (polynomial R) := add_monoid_algebra.module

variable (R)
def lcoeff (n : ℕ) : polynomial R →ₗ[R] R :=
Expand Down Expand Up @@ -2154,7 +2153,6 @@ end integral_domain

section field
variables [field R] {p q : polynomial R}
instance : vector_space R (polynomial R) := finsupp.vector_space _ _

lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_is_unit,
Expand Down
3 changes: 0 additions & 3 deletions src/field_theory/mv_polynomial.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace mv_polynomial
universes u v
variables {σ : Type u} {α : Type v}

instance [field α] : vector_space α (mv_polynomial σ α) :=
finsupp.vector_space _ _

section
variables (σ α) [field α] (m : ℕ)
def restrict_total_degree : submodule α (mv_polynomial σ α) :=
Expand Down
11 changes: 7 additions & 4 deletions test/library_search/ring_theory.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ set_option trace.silence_library_search true
example {α : Type} [euclidean_domain α] {S : ideal α} {x y : α} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S :=
by library_search -- exact mod_mem_iff hy

variables {R : Type} [comm_ring R] [decidable_eq R]
variables {I : ideal (polynomial R)}
-- The next test timeouts for an unknown reason, disabled.
-- See https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Tests.20fail

example {m n : ℕ} (H : m ≤ n) : I.leading_coeff_nth m ≤ I.leading_coeff_nth n :=
by library_search -- exact ideal.leading_coeff_nth_mono I H
-- variables {R : Type} [comm_ring R] [decidable_eq R]
-- variables {I : ideal (polynomial R)}

-- example {m n : ℕ} (H : m ≤ n) : I.leading_coeff_nth m ≤ I.leading_coeff_nth n :=
-- by library_search -- exact ideal.leading_coeff_nth_mono I H

0 comments on commit ce48b6b

Please sign in to comment.