Skip to content

Commit

Permalink
fix(data/{finsupp,polynomial,mv_polynomial}/basic): add missing decid…
Browse files Browse the repository at this point in the history
…able arguments (#7309)

Lemmas with an `ite` in their conclusion should not use `classical.dec` or similar, instead inferring an appropriate decidability instance from their context. This eliminates a handful of converts elsewhere.

The linter in #6485 should eventually find these automatically.
  • Loading branch information
eric-wieser committed Apr 21, 2021
1 parent 120be3d commit f2984d5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/data/finsupp/basic.lean
Expand Up @@ -198,8 +198,8 @@ def single (a : α) (b : M) : α →₀ M :=
{ exact ⟨λ H _, h H.symm, λ H, (H rfl).elim⟩ }
end

lemma single_apply : single a b a' = if a = a' then b else 0 :=
rfl
lemma single_apply [decidable (a = a')] : single a b a' = if a = a' then b else 0 :=
by convert rfl

lemma single_eq_indicator : ⇑(single a b) = set.indicator {a} (λ _, b) :=
by { ext, simp [single_apply, set.indicator, @eq_comm _ a] }
Expand Down
9 changes: 5 additions & 4 deletions src/data/mv_polynomial/basic.lean
Expand Up @@ -303,7 +303,8 @@ The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coeffic
def support (p : mv_polynomial σ R) : finset (σ →₀ ℕ) :=
p.support

lemma support_monomial : (monomial s a).support = if a = 0 thenelse {s} := rfl
lemma support_monomial [decidable (a = 0)] : (monomial s a).support = if a = 0 thenelse {s} :=
by convert rfl

lemma support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
Expand Down Expand Up @@ -371,11 +372,11 @@ by simp [monomial_eq]

@[simp] lemma coeff_monomial (m n) (a) :
coeff m (monomial n a : mv_polynomial σ R) = if n = m then a else 0 :=
by convert single_apply
single_apply

@[simp] lemma coeff_C (m) (a) :
coeff m (C a : mv_polynomial σ R) = if 0 = m then a else 0 :=
by convert single_apply
single_apply

lemma coeff_X_pow (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : mv_polynomial σ R) = if single i k = m then 1 else 0 :=
Expand Down Expand Up @@ -413,7 +414,7 @@ begin
convert this.symm using 1; clear this,
{ rw [coeff],
iterate 2 { rw sum_apply, apply finset.sum_congr rfl, intros, dsimp only },
convert single_apply },
exact single_apply },
symmetry,
-- We are now ready to show that both sums are equal using `finset.sum_bij_ne_zero`.
apply finset.sum_bij_ne_zero (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)) _ _, (x.1, x.2)),
Expand Down
2 changes: 1 addition & 1 deletion src/data/polynomial/basic.lean
Expand Up @@ -149,7 +149,7 @@ def coeff (p : polynomial R) : ℕ → R := @coe_fn (ℕ →₀ R) _ p
@[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial R) = f := rfl

lemma coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 :=
by { dsimp [monomial, coeff], rw finsupp.single_apply, congr }
finsupp.single_apply

@[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial R) n = 0 := rfl

Expand Down
3 changes: 2 additions & 1 deletion src/linear_algebra/basis.lean
Expand Up @@ -128,7 +128,8 @@ lemma is_basis.repr_eq_single {i} : hv.repr (v i) = finsupp.single i 1 :=
by apply hv.1.repr_eq_single; simp

@[simp]
lemma is_basis.repr_self_apply (i j : ι) : hv.repr (v i) j = if i = j then 1 else 0 :=
lemma is_basis.repr_self_apply (i j : ι) [decidable (i = j)] :
hv.repr (v i) j = if i = j then 1 else 0 :=
by rw [hv.repr_eq_single, finsupp.single_apply]

lemma is_basis.repr_eq_iff {f : M →ₗ[R] (ι →₀ R)} :
Expand Down
4 changes: 1 addition & 3 deletions src/linear_algebra/dual.lean
Expand Up @@ -233,9 +233,7 @@ h.to_dual_apply_right i v
(h.dual_basis_is_basis.to_dual _).comp (h.to_dual B) = eval K V :=
begin
refine h.ext (λ i, h.dual_basis_is_basis.ext (λ j, _)),
suffices : @ite K _ (classical.prop_decidable _) 1 0 = @ite K _ (de j i) 1 0,
by simpa [h.dual_basis_is_basis.to_dual_apply_left, h.dual_basis_repr, h.to_dual_apply_right],
split_ifs; refl
simp [h.dual_basis_is_basis.to_dual_apply_left, h.dual_basis_repr, h.to_dual_apply_right],
end

omit de
Expand Down

0 comments on commit f2984d5

Please sign in to comment.