Skip to content

Commit

Permalink
chore: add decidability assumptions where needed for the statement (#…
Browse files Browse the repository at this point in the history
…11157)

The general policy in mathlib is to include decidability assumptions on a theorem if and only if they are used in its statement. @fpvandoorn has been working on a linter to detect cases which violate the backwards direction of that policy. (i.e. cases where `Classical.propDecidable` appears in a theorem's statement.) I've started going through [the output of that linter](https://gist.github.com/fpvandoorn/05cca028139e98bded9874169a1332d5) and this PR contains fixes for the two files I've finished so far.

[Zulip thread about the linter](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/prop.20decidable.20linter/near/424101789)
  • Loading branch information
timotree3 committed Mar 15, 2024
1 parent aae7c58 commit ef2b6f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
49 changes: 25 additions & 24 deletions Mathlib/Algebra/DirectLimit.lean
Expand Up @@ -290,10 +290,8 @@ end Totalize

variable [DirectedSystem G fun i j h => f i j h]

open scoped Classical

theorem toModule_totalize_of_le {x : DirectSum ι G} {i j : ι} (hij : i ≤ j)
(hx : ∀ k ∈ x.support, k ≤ i) :
theorem toModule_totalize_of_le [∀ i (k : G i), Decidable (k ≠ 0)] {x : DirectSum ι G} {i j : ι}
(hij : i ≤ j) (hx : ∀ k ∈ x.support, k ≤ i) :
DirectSum.toModule R ι (G j) (fun k => totalize G f k j) x =
f i j hij (DirectSum.toModule R ι (G i) (fun k => totalize G f k i) x) := by
rw [← @DFinsupp.sum_single ι G _ _ _ x]
Expand All @@ -304,8 +302,8 @@ theorem toModule_totalize_of_le {x : DirectSum ι G} {i j : ι} (hij : i ≤ j)
totalize_of_le (hx k hk), totalize_of_le (le_trans (hx k hk) hij), DirectedSystem.map_map]
#align module.direct_limit.to_module_totalize_of_le Module.DirectLimit.toModule_totalize_of_le

theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : DirectSum ι G}
(H : (Submodule.Quotient.mk x : DirectLimit G f) = (0 : DirectLimit G f)) :
theorem of.zero_exact_aux [∀ i (k : G i), Decidable (k ≠ 0)] [Nonempty ι] [IsDirected ι (· ≤ ·)]
{x : DirectSum ι G} (H : (Submodule.Quotient.mk x : DirectLimit G f) = (0 : DirectLimit G f)) :
∃ j,
(∀ k ∈ x.support, k ≤ j) ∧
DirectSum.toModule R ι (G j) (fun i => totalize G f i j) x = (0 : G j) :=
Expand Down Expand Up @@ -344,6 +342,7 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : DirectS
⟨i, fun k hk => hi k (DirectSum.support_smul _ _ hk), by simp [LinearMap.map_smul, hxi]⟩
#align module.direct_limit.of.zero_exact_aux Module.DirectLimit.of.zero_exact_aux

open Classical in
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact [IsDirected ι (· ≤ ·)] {i x} (H : of R ι G f i x = 0) :
Expand Down Expand Up @@ -668,17 +667,15 @@ theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit

section OfZeroExact

open scoped Classical

variable (f' : ∀ i j, i ≤ j → G i →+* G j)

variable [DirectedSystem G fun i j h => f' i j h]

variable (G f)

theorem of.zero_exact_aux2 {x : FreeCommRing (Σi, G i)} {s t} (hxs : IsSupported x s) {j k}
(hj : ∀ z : Σi, G i, z ∈ s → z.1 ≤ j) (hk : ∀ z : Σi, G i, z ∈ t → z.1k) (hjk : j ≤ k)
(hst : s ⊆ t) :
theorem of.zero_exact_aux2 {x : FreeCommRing (Σi, G i)} {s t} [DecidablePred (· ∈ s)]
[DecidablePred (· ∈ t)] (hxs : IsSupported x s) {j k} (hj : ∀ z : Σi, G i, z ∈ s → z.1j)
(hk : ∀ z : Σi, G i, z ∈ t → z.1 ≤ k) (hjk : j ≤ k) (hst : s ⊆ t) :
f' j k hjk (lift (fun ix : s => f' ix.1.1 j (hj ix ix.2) ix.1.2) (restriction s x)) =
lift (fun ix : t => f' ix.1.1 k (hk ix ix.2) ix.1.2) (restriction t x) := by
refine' Subring.InClosure.recOn hxs _ _ _ _
Expand Down Expand Up @@ -711,12 +708,15 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
= (0 : DirectLimit G fun i j h => f' i j h)) :
∃ j s, ∃ H : ∀ k : Σ i, G i, k ∈ s → k.1 ≤ j,
IsSupported x s ∧
lift (fun ix : s => f' ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) := by
∀ [DecidablePred (· ∈ s)],
lift (fun ix : s => f' ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) := by
have := Classical.decEq
refine' span_induction (Ideal.Quotient.eq_zero_iff_mem.1 H) _ _ _ _
· rintro x (⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩)
· refine'
⟨j, {⟨i, x⟩, ⟨j, f' i j hij x⟩}, _,
isSupported_sub (isSupported_of.2 <| Or.inr rfl) (isSupported_of.2 <| Or.inl rfl), _⟩
isSupported_sub (isSupported_of.2 <| Or.inr rfl) (isSupported_of.2 <| Or.inl rfl),
fun [_] => _⟩
· rintro k (rfl | ⟨rfl | _⟩)
exact hij
rfl
Expand All @@ -727,7 +727,7 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
rw [this]
exact sub_self _
exacts [Or.inl rfl, Or.inr rfl]
· refine' ⟨i, {⟨i, 1⟩}, _, isSupported_sub (isSupported_of.2 rfl) isSupported_one, _⟩
· refine' ⟨i, {⟨i, 1⟩}, _, isSupported_sub (isSupported_of.2 rfl) isSupported_one, fun [_] => _⟩
· rintro k (rfl | h)
rfl
-- Porting note: the Lean3 proof contained `rw [restriction_of]`, but this
Expand All @@ -739,7 +739,7 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
isSupported_sub (isSupported_of.2 <| Or.inl rfl)
(isSupported_add (isSupported_of.2 <| Or.inr <| Or.inl rfl)
(isSupported_of.2 <| Or.inr <| Or.inr rfl)),
_⟩
fun [_] => _⟩
· rintro k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩) <;> rfl
· rw [(restriction _).map_sub, (restriction _).map_add, restriction_of, restriction_of,
restriction_of, dif_pos, dif_pos, dif_pos, RingHom.map_sub,
Expand All @@ -752,7 +752,7 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
⟨i, {⟨i, x * y⟩, ⟨i, x⟩, ⟨i, y⟩}, _,
isSupported_sub (isSupported_of.2 <| Or.inl rfl)
(isSupported_mul (isSupported_of.2 <| Or.inr <| Or.inl rfl)
(isSupported_of.2 <| Or.inr <| Or.inr rfl)), _⟩
(isSupported_of.2 <| Or.inr <| Or.inr rfl)), fun [_] => _⟩
· rintro k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩) <;> rfl
· rw [(restriction _).map_sub, (restriction _).map_mul, restriction_of, restriction_of,
restriction_of, dif_pos, dif_pos, dif_pos, RingHom.map_sub,
Expand All @@ -764,10 +764,10 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
-- Porting note: was
--exacts [sub_self _, Or.inl rfl, Or.inr (Or.inr rfl), Or.inr (Or.inl rfl)]
· refine' Nonempty.elim (by infer_instance) fun ind : ι => _
refine' ⟨ind, ∅, fun _ => False.elim, isSupported_zero, _⟩
refine' ⟨ind, ∅, fun _ => False.elim, isSupported_zero, fun [_] => _⟩
-- Porting note: `RingHom.map_zero` was `(restriction _).map_zero`
rw [RingHom.map_zero, (FreeCommRing.lift _).map_zero]
· rintro x y ⟨i, s, hi, hxs, ihs⟩ ⟨j, t, hj, hyt, iht⟩
· intro x y ⟨i, s, hi, hxs, ihs⟩ ⟨j, t, hj, hyt, iht⟩
obtain ⟨k, hik, hjk⟩ := exists_ge_ge i j
have : ∀ z : Σi, G i, z ∈ s ∪ t → z.1 ≤ k := by
rintro z (hz | hz)
Expand All @@ -776,9 +776,9 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
refine'
⟨k, s ∪ t, this,
isSupported_add (isSupported_upwards hxs <| Set.subset_union_left s t)
(isSupported_upwards hyt <| Set.subset_union_right s t), _⟩
(isSupported_upwards hyt <| Set.subset_union_right s t), fun [_] => _⟩
· -- Porting note: was `(restriction _).map_add`
rw [RingHom.map_add, (FreeCommRing.lift _).map_add, ←
classical rw [RingHom.map_add, (FreeCommRing.lift _).map_add, ←
of.zero_exact_aux2 G f' hxs hi this hik (Set.subset_union_left s t), ←
of.zero_exact_aux2 G f' hyt hj this hjk (Set.subset_union_right s t), ihs,
(f' i k hik).map_zero, iht, (f' j k hjk).map_zero, zero_add]
Expand All @@ -793,21 +793,22 @@ theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCom
refine'
⟨k, ↑s ∪ t, this,
isSupported_mul (isSupported_upwards hxs <| Set.subset_union_left (↑s) t)
(isSupported_upwards hyt <| Set.subset_union_right (↑s) t), _⟩
(isSupported_upwards hyt <| Set.subset_union_right (↑s) t), fun [_] => _⟩
-- Porting note: RingHom.map_mul was `(restriction _).map_mul`
rw [RingHom.map_mul, (FreeCommRing.lift _).map_mul, ←
classical rw [RingHom.map_mul, (FreeCommRing.lift _).map_mul, ←
of.zero_exact_aux2 G f' hyt hj this hjk (Set.subset_union_right (↑s) t), iht,
(f' j k hjk).map_zero, mul_zero]
#align ring.direct_limit.of.zero_exact_aux Ring.DirectLimit.of.zero_exact_aux

/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact [IsDirected ι (· ≤ ·)] {i x} (hix : of G (fun i j h => f' i j h) i x = 0) :
∃ (j : _) (hij : i ≤ j), f' i j hij x = 0 :=
∃ (j : _) (hij : i ≤ j), f' i j hij x = 0 := by
haveI : Nonempty ι := ⟨i⟩
let ⟨j, s, H, hxs, hx⟩ := of.zero_exact_aux hix
have hixs : (⟨i, x⟩ : Σi, G i) ∈ s := isSupported_of.1 hxs
⟨j, H ⟨i, x⟩ hixs, by rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx⟩
classical specialize @hx _
exact ⟨j, H ⟨i, x⟩ hixs, by classical rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx⟩
#align ring.direct_limit.of.zero_exact Ring.DirectLimit.of.zero_exact

end OfZeroExact
Expand Down
3 changes: 1 addition & 2 deletions Mathlib/Algebra/GCDMonoid/Div.lean
Expand Up @@ -70,12 +70,11 @@ end Int

namespace Polynomial

open scoped Classical
open Polynomial

noncomputable section

variable {K : Type*} [Field K]
variable {K : Type*} [Field K] [DecidableEq K]

/-- Given a nonempty Finset `s` and a function `f` from `s` to `K[X]`, if `d = s.gcd f`,
then the `gcd` of `(f i) / d` is equal to `1`. -/
Expand Down

0 comments on commit ef2b6f2

Please sign in to comment.