Skip to content

Commit 840619d

Browse files
committed
chore(Data): process porting notes (#28975)
Deal with a few porting notes in the Data folder. Also a couple style fixes that I noticed while going through everything. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
1 parent 08662f5 commit 840619d

File tree

14 files changed

+20
-58
lines changed

14 files changed

+20
-58
lines changed

Mathlib/Data/FP/Basic.lean

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,11 @@ unsafe def nextUpPos (e m) (v : ValidFinite e m) : Float :=
148148

149149
@[nolint docBlame]
150150
unsafe def nextDnPos (e m) (v : ValidFinite e m) : Float :=
151-
match m with
151+
match h : m with
152152
| 0 => nextUpPos _ _ Float.Zero.valid
153153
| Nat.succ m' =>
154-
-- Porting note: was `m'.size = m.size`
155-
if ss : m'.size = m'.succ.size then
156-
Float.finite false e m' (by unfold ValidFinite at *; rw [ss]; exact v)
154+
if ss : m'.size = m.size then
155+
Float.finite false e m' (by subst h; unfold ValidFinite at *; rw [ss]; exact v)
157156
else
158157
if h : e = emin then Float.finite false emin m' lcProof
159158
else Float.finite false e.pred (2 * m' + 1) lcProof

Mathlib/Data/Fin/Tuple/Basic.lean

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,6 @@ section InsertNth
763763

764764
variable {α : Fin (n + 1) → Sort*} {β : Sort*}
765765

766-
/- Porting note: Lean told me `(fun x x_1 ↦ α x)` was an invalid motive, but disabling
767-
automatic insertion and specifying that motive seems to work. -/
768766
/-- Define a function on `Fin (n + 1)` from a value on `i : Fin (n + 1)` and values on each
769767
`Fin.succAbove i j`, `j : Fin n`. This version is elaborated as eliminator and works for
770768
propositions, see also `Fin.insertNth` for a version without an `@[elab_as_elim]`
@@ -774,9 +772,8 @@ def succAboveCases {α : Fin (n + 1) → Sort u} (i : Fin (n + 1)) (x : α i)
774772
(p : ∀ j : Fin n, α (i.succAbove j)) (j : Fin (n + 1)) : α j :=
775773
if hj : j = i then Eq.rec x hj.symm
776774
else
777-
if hlt : j < i then @Eq.recOn _ _ (fun x _ ↦ α x) _ (succAbove_castPred_of_lt _ _ hlt) (p _)
778-
else @Eq.recOn _ _ (fun x _ ↦ α x) _ (succAbove_pred_of_lt _ _ <|
779-
(Fin.lt_or_lt_of_ne hj).resolve_left hlt) (p _)
775+
if hlt : j < i then (succAbove_castPred_of_lt _ _ hlt) ▸ (p _)
776+
else (succAbove_pred_of_lt _ _ <| (Fin.lt_or_lt_of_ne hj).resolve_left hlt) ▸ (p _)
780777

781778
-- This is a duplicate of `Fin.exists_fin_succ` in Core. We should upstream the name change.
782779
alias forall_iff_succ := forall_fin_succ
@@ -906,20 +903,14 @@ theorem insertNth_right_injective {p : Fin (n + 1)} (x : α p) :
906903
Function.Injective (insertNth p x) :=
907904
insertNth_injective2.right _
908905

909-
/- Porting note: Once again, Lean told me `(fun x x_1 ↦ α x)` was an invalid motive, but disabling
910-
automatic insertion and specifying that motive seems to work. -/
911906
theorem insertNth_apply_below {i j : Fin (n + 1)} (h : j < i) (x : α i)
912907
(p : ∀ k, α (i.succAbove k)) :
913-
i.insertNth x p j = @Eq.recOn _ _ (fun x _ ↦ α x) _
914-
(succAbove_castPred_of_lt _ _ h) (p <| j.castPred _) := by
908+
i.insertNth x p j = succAbove_castPred_of_lt _ _ h ▸ (p <| j.castPred _) := by
915909
rw [insertNth, succAboveCases, dif_neg (Fin.ne_of_lt h), dif_pos h]
916910

917-
/- Porting note: Once again, Lean told me `(fun x x_1 ↦ α x)` was an invalid motive, but disabling
918-
automatic insertion and specifying that motive seems to work. -/
919911
theorem insertNth_apply_above {i j : Fin (n + 1)} (h : i < j) (x : α i)
920912
(p : ∀ k, α (i.succAbove k)) :
921-
i.insertNth x p j = @Eq.recOn _ _ (fun x _ ↦ α x) _
922-
(succAbove_pred_of_lt _ _ h) (p <| j.pred _) := by
913+
i.insertNth x p j = succAbove_pred_of_lt _ _ h ▸ (p <| j.pred _) := by
923914
rw [insertNth, succAboveCases, dif_neg (Fin.ne_of_gt h), dif_neg (Fin.lt_asymm h)]
924915

925916
theorem insertNth_zero (x : α 0) (p : ∀ j : Fin n, α (succAbove 0 j)) :

Mathlib/Data/Finset/Card.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@ def strongInduction {p : Finset α → Sort*} (H : ∀ s, (∀ t ⊂ s, p t) →
814814
strongInduction H t
815815
termination_by s => #s
816816

817-
@[nolint unusedHavesSuffices] -- Porting note: false positive
818817
theorem strongInduction_eq {p : Finset α → Sort*} (H : ∀ s, (∀ t ⊂ s, p t) → p s)
819818
(s : Finset α) : strongInduction H s = H s fun t _ => strongInduction H t := by
820819
rw [strongInduction]
@@ -824,7 +823,6 @@ theorem strongInduction_eq {p : Finset α → Sort*} (H : ∀ s, (∀ t ⊂ s, p
824823
def strongInductionOn {p : Finset α → Sort*} (s : Finset α) :
825824
(∀ s, (∀ t ⊂ s, p t) → p s) → p s := fun H => strongInduction H s
826825

827-
@[nolint unusedHavesSuffices] -- Porting note: false positive
828826
theorem strongInductionOn_eq {p : Finset α → Sort*} (s : Finset α)
829827
(H : ∀ s, (∀ t ⊂ s, p t) → p s) :
830828
s.strongInductionOn H = H s fun t _ => t.strongInductionOn H := by
@@ -872,7 +870,6 @@ def strongDownwardInduction {p : Finset α → Sort*} {n : ℕ}
872870
strongDownwardInduction H t ht
873871
termination_by s => n - #s
874872

875-
@[nolint unusedHavesSuffices] -- Porting note: false positive
876873
theorem strongDownwardInduction_eq {p : Finset α → Sort*}
877874
(H : ∀ t₁, (∀ {t₂ : Finset α}, #t₂ ≤ n → t₁ ⊂ t₂ → p t₂) → #t₁ ≤ n → p t₁)
878875
(s : Finset α) :
@@ -886,7 +883,6 @@ def strongDownwardInductionOn {p : Finset α → Sort*} (s : Finset α)
886883
#s ≤ n → p s :=
887884
strongDownwardInduction H s
888885

889-
@[nolint unusedHavesSuffices] -- Porting note: false positive
890886
theorem strongDownwardInductionOn_eq {p : Finset α → Sort*} (s : Finset α)
891887
(H : ∀ t₁, (∀ {t₂ : Finset α}, #t₂ ≤ n → t₁ ⊂ t₂ → p t₂) → #t₁ ≤ n → p t₁) :
892888
s.strongDownwardInductionOn H = H s fun {t} ht _ => t.strongDownwardInductionOn H ht := by

Mathlib/Data/List/Defs.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ end foldIdxM
114114

115115
section mapIdxM
116116

117+
-- This could be relaxed to `Applicative` but is `Monad` to match `List.mapIdxM`.
117118
variable {m : Type v → Type w} [Monad m]
118119

119120
/-- Auxiliary definition for `mapIdxM'`. -/

Mathlib/Data/List/Indexes.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ end MapIdx
4747

4848
section MapIdxM'
4949

50-
-- Porting note: `[Applicative m] [LawfulApplicative m]` replaced by [Monad m] [LawfulMonad m]
5150
variable {m : Type u → Type v} [Monad m] [LawfulMonad m]
5251

5352
theorem mapIdxMAux'_eq_mapIdxMGo {α} (f : ℕ → α → m PUnit) (as : List α) (arr : Array PUnit) :

Mathlib/Data/List/Permutation.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ theorem mem_permutationsAux_of_perm :
305305
theorem mem_permutations {s t : List α} : s ∈ permutations t ↔ s ~ t :=
306306
⟨perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutationsAux_of_perm⟩
307307

308-
-- Porting note: temporary theorem to solve diamond issue
309-
private theorem DecEq_eq [DecidableEq α] :
310-
List.instBEq = @instBEqOfDecidableEq (List α) instDecidableEqList :=
311-
congr_arg BEq.mk <| by
312-
funext l₁ l₂
313-
change (l₁ == l₂) = _
314-
rw [Bool.eq_iff_iff, @beq_iff_eq _ (_), decide_eq_true_iff]
315-
316308
theorem perm_permutations'Aux_comm (a b : α) (l : List α) :
317309
(permutations'Aux a l).flatMap (permutations'Aux b) ~
318310
(permutations'Aux b l).flatMap (permutations'Aux a) := by
@@ -399,6 +391,14 @@ theorem get_permutations'Aux (s : List α) (x : α) (n : ℕ)
399391
(permutations'Aux x s).get ⟨n, hn⟩ = s.insertIdx n x := by
400392
simp [getElem_permutations'Aux]
401393

394+
-- Porting note: temporary theorem to solve diamond issue
395+
private theorem DecEq_eq [DecidableEq α] :
396+
List.instBEq = @instBEqOfDecidableEq (List α) instDecidableEqList :=
397+
congr_arg BEq.mk <| by
398+
funext l₁ l₂
399+
change (l₁ == l₂) = _
400+
rw [Bool.eq_iff_iff, @beq_iff_eq _ (_), decide_eq_true_iff]
401+
402402
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
403403
count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
404404
induction' l with y l IH generalizing x

Mathlib/Data/List/ToFinsupp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ theorem toFinsupp_concat_eq_toFinsupp_add_single {R : Type*} [AddZeroClass R] (x
120120
theorem toFinsupp_eq_sum_mapIdx_single {R : Type*} [AddMonoid R] (l : List R)
121121
[DecidablePred (getD l · 00)] :
122122
toFinsupp l = (l.mapIdx fun n r => Finsupp.single n r).sum := by
123-
/- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: `induction` fails to substitute `l = []` in
123+
/- Porting note: `induction` fails to substitute `l = []` in
124124
`[DecidablePred (getD l · 0 ≠ 0)]`, so we manually do some `revert`/`intro` as a workaround -/
125125
revert l; intro l
126126
induction l using List.reverseRecOn with

Mathlib/Data/Multiset/Powerset.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ variable {α : Type*}
2020

2121
/-! ### powerset -/
2222

23-
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: Write a more efficient version
23+
-- TODO: Write a more efficient version (this is slightly slower due to the `map (↑)`).
2424
/-- A helper function for the powerset of a multiset. Given a list `l`, returns a list
2525
of sublists of `l` as multisets. -/
2626
def powersetAux (l : List α) : List (Multiset α) :=
@@ -68,7 +68,6 @@ theorem powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux l
6868
powersetAux_perm_powersetAux'.trans <|
6969
(powerset_aux'_perm p).trans powersetAux_perm_powersetAux'.symm
7070

71-
--Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): slightly slower implementation due to `map ofList`
7271
/-- The power set of a multiset. -/
7372
def powerset (s : Multiset α) : Multiset (Multiset α) :=
7473
Quot.liftOn s

Mathlib/Data/NNReal/Defs.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,6 @@ end Set
883883
namespace Real
884884

885885
/-- The absolute value on `ℝ` as a map to `ℝ≥0`. -/
886-
-- Porting note (kmill): `pp_nodot` has no affect here
887-
-- unless RFC https://github.com/leanprover/lean4/issues/6178 leads to dot notation pp for CoeFun
888886
@[pp_nodot]
889887
def nnabs : ℝ →*₀ ℝ≥0 where
890888
toFun x := ⟨|x|, abs_nonneg x⟩

Mathlib/Data/Num/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
599599
have := cmp_to_nat m n
600600
-- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required.
601601
revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;>
602-
simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this]
602+
simp [show m ≠ n from fun e => by rw [e] at this; exact lt_irrefl _ this]
603603

604604
@[simp, norm_cast]
605605
theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : PosNum} :

0 commit comments

Comments
 (0)