formal
stringlengths 41
427k
| informal
stringclasses 1
value |
---|---|
Int.emod_emod ** a b : Int ⊢ a % b % b = a % b ** conv => rhs; rw [← emod_add_ediv a b, add_mul_emod_self_left] ** Qed | |
Int.sub_emod ** a b n : Int ⊢ (a - b) % n = (a % n - b % n) % n ** apply (emod_add_cancel_right b).mp ** a b n : Int ⊢ (a - b + b) % n = (a % n - b % n + b) % n ** rw [Int.sub_add_cancel, ← Int.add_emod_emod, Int.sub_add_cancel, emod_emod] ** Qed | |
Int.ediv_emod_unique ** a b r q : Int h : 0 < b ⊢ a / b = q ∧ a % b = r ↔ r + b * q = a ∧ 0 ≤ r ∧ r < b ** constructor ** case mp a b r q : Int h : 0 < b ⊢ a / b = q ∧ a % b = r → r + b * q = a ∧ 0 ≤ r ∧ r < b ** intro ⟨rfl, rfl⟩ ** case mp a b r q : Int h : 0 < b ⊢ a % b + b * (a / b) = a ∧ 0 ≤ a % b ∧ a % b < b ** exact ⟨emod_add_ediv a b, emod_nonneg _ (Int.ne_of_gt h), emod_lt_of_pos _ h⟩ ** case mpr a b r q : Int h : 0 < b ⊢ r + b * q = a ∧ 0 ≤ r ∧ r < b → a / b = q ∧ a % b = r ** intro ⟨rfl, hz, hb⟩ ** case mpr a b r q : Int h : 0 < b hz : 0 ≤ r hb : r < b ⊢ (r + b * q) / b = q ∧ (r + b * q) % b = r ** constructor ** case mpr.left a b r q : Int h : 0 < b hz : 0 ≤ r hb : r < b ⊢ (r + b * q) / b = q ** rw [Int.add_mul_ediv_left r q (Int.ne_of_gt h), ediv_eq_zero_of_lt hz hb] ** case mpr.left a b r q : Int h : 0 < b hz : 0 ≤ r hb : r < b ⊢ 0 + q = q ** simp [Int.zero_add] ** case mpr.right a b r q : Int h : 0 < b hz : 0 ≤ r hb : r < b ⊢ (r + b * q) % b = r ** rw [add_mul_emod_self_left, emod_eq_of_lt hz hb] ** Qed | |
Int.mul_ediv_mul_of_pos ** a b c : Int this : ∀ (m k : Nat) (b : Int), ↑(succ m) * b / (↑(succ m) * ↑k) = b / ↑k m k : Nat H : 0 < ↑(succ m) ⊢ ↑(succ m) * b / (↑(succ m) * -↑k) = b / -↑k ** rw [Int.mul_neg, Int.ediv_neg, Int.ediv_neg] ** a b c : Int this : ∀ (m k : Nat) (b : Int), ↑(succ m) * b / (↑(succ m) * ↑k) = b / ↑k m k : Nat H : 0 < ↑(succ m) ⊢ -(↑(succ m) * b / (↑(succ m) * ↑k)) = -(b / ↑k) ** apply congrArg Neg.neg ** a b c : Int this : ∀ (m k : Nat) (b : Int), ↑(succ m) * b / (↑(succ m) * ↑k) = b / ↑k m k : Nat H : 0 < ↑(succ m) ⊢ ↑(succ m) * b / (↑(succ m) * ↑k) = b / ↑k ** apply this ** a b✝ c : Int H : 0 < a m k : Nat b : Int n : Nat ⊢ ↑(succ m) * -[n+1] / (↑(succ m) * ↑0) = -[n+1] / ↑0 ** rw [Int.ofNat_zero, Int.mul_zero, Int.ediv_zero, Int.ediv_zero] ** a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ (succ m * n + m) / (succ m * succ k) = n / succ k ** apply Nat.div_eq_of_lt_le ** case lo a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ n / succ k * (succ m * succ k) ≤ succ m * n + m ** refine Nat.le_trans ?_ (Nat.le_add_right _ _) ** case lo a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ n / succ k * (succ m * succ k) ≤ succ m * n ** rw [← Nat.mul_div_mul_left _ _ m.succ_pos] ** case lo a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ succ m * n / (succ m * succ k) * (succ m * succ k) ≤ succ m * n ** apply Nat.div_mul_le_self ** case hi a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ succ m * n + m < succ (n / succ k) * (succ m * succ k) ** show m.succ * n.succ ≤ _ ** case hi a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ succ m * succ n ≤ succ (n / succ k) * (succ m * succ k) ** rw [Nat.mul_left_comm] ** case hi a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ succ m * succ n ≤ succ m * (succ (n / succ k) * succ k) ** apply Nat.mul_le_mul_left ** case hi.h a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ succ n ≤ succ (n / succ k) * succ k ** apply (Nat.div_lt_iff_lt_mul k.succ_pos).1 ** case hi.h a b✝ c : Int H : 0 < a m k✝ : Nat b : Int n k : Nat ⊢ n / succ k < succ (n / succ k) ** apply Nat.lt_succ_self ** Qed | |
Int.mul_ediv_mul_of_pos_left ** a b c : Int H : 0 < b ⊢ a * b / (c * b) = a / c ** rw [Int.mul_comm, Int.mul_comm c, mul_ediv_mul_of_pos _ _ H] ** Qed | |
Int.mul_emod_mul_of_pos ** a b c : Int H : 0 < a ⊢ a * b % (a * c) = a * (b % c) ** rw [emod_def, emod_def, mul_ediv_mul_of_pos _ _ H, Int.mul_sub, Int.mul_assoc] ** Qed | |
Int.lt_ediv_add_one_mul_self ** a b : Int H : 0 < b ⊢ a < (a / b + 1) * b ** rw [Int.add_mul, Int.one_mul, Int.mul_comm] ** a b : Int H : 0 < b ⊢ a < b * (a / b) + b ** exact Int.lt_add_of_sub_left_lt <| Int.emod_def .. ▸ emod_lt_of_pos _ H ** Qed | |
Int.natAbs_div_le_natAbs ** a b : Int n : Nat ⊢ natAbs (a / -↑n) ≤ natAbs a ** rw [Int.ediv_neg, natAbs_neg] ** a b : Int n : Nat ⊢ natAbs (a / ↑n) ≤ natAbs a ** apply aux ** Qed | |
Int.mul_div_cancel_of_mod_eq_zero ** a b : Int H : mod a b = 0 ⊢ b * div a b = a ** have := mod_add_div a b ** a b : Int H : mod a b = 0 this : mod a b + b * div a b = a ⊢ b * div a b = a ** rwa [H, Int.zero_add] at this ** Qed | |
Int.div_mul_cancel_of_mod_eq_zero ** a b : Int H : mod a b = 0 ⊢ div a b * b = a ** rw [Int.mul_comm, mul_div_cancel_of_mod_eq_zero H] ** Qed | |
Int.mul_ediv_cancel_of_emod_eq_zero ** a b : Int H : a % b = 0 ⊢ b * (a / b) = a ** have := emod_add_ediv a b ** a b : Int H : a % b = 0 this : a % b + b * (a / b) = a ⊢ b * (a / b) = a ** rwa [H, Int.zero_add] at this ** Qed | |
Int.ediv_mul_cancel_of_emod_eq_zero ** a b : Int H : a % b = 0 ⊢ a / b * b = a ** rw [Int.mul_comm, mul_ediv_cancel_of_emod_eq_zero H] ** Qed | |
Int.dvd_trans ** a✝ d e : Int ⊢ a✝ * d * e = a✝ * (d * e) ** rw [Int.mul_assoc] ** Qed | |
Int.neg_dvd ** a b : Int ⊢ -a ∣ b ↔ a ∣ b ** constructor <;> exact fun ⟨k, e⟩ =>
⟨-k, by simp [e, Int.neg_mul, Int.mul_neg, Int.neg_neg]⟩ ** a b : Int x✝ : a ∣ b k : Int e : b = a * k ⊢ b = -a * -k ** simp [e, Int.neg_mul, Int.mul_neg, Int.neg_neg] ** Qed | |
Int.dvd_neg ** a b : Int ⊢ a ∣ -b ↔ a ∣ b ** constructor <;> exact fun ⟨k, e⟩ =>
⟨-k, by simp [← e, Int.neg_mul, Int.mul_neg, Int.neg_neg]⟩ ** a b : Int x✝ : a ∣ b k : Int e : b = a * k ⊢ -b = a * -k ** simp [← e, Int.neg_mul, Int.mul_neg, Int.neg_neg] ** Qed | |
Int.dvd_add ** a✝ d e : Int ⊢ a✝ * d + a✝ * e = a✝ * (d + e) ** rw [Int.mul_add] ** Qed | |
Int.dvd_sub ** a✝ d e : Int ⊢ a✝ * d - a✝ * e = a✝ * (d - e) ** rw [Int.mul_sub] ** Qed | |
Int.dvd_add_left ** a b c : Int H : a ∣ c h : a ∣ b + c ⊢ a ∣ b ** have := Int.dvd_sub h H ** a b c : Int H : a ∣ c h : a ∣ b + c this : a ∣ b + c - c ⊢ a ∣ b ** rwa [Int.add_sub_cancel] at this ** Qed | |
Int.natAbs_dvd_natAbs ** a b : Int ⊢ natAbs a ∣ natAbs b ↔ a ∣ b ** refine ⟨fun ⟨k, hk⟩ => ?_, fun ⟨k, hk⟩ => ⟨natAbs k, hk.symm ▸ natAbs_mul a k⟩⟩ ** a b : Int x✝ : natAbs a ∣ natAbs b k : Nat hk : natAbs b = natAbs a * k ⊢ a ∣ b ** rw [← natAbs_ofNat k, ← natAbs_mul, natAbs_eq_natAbs_iff] at hk ** a b : Int x✝ : natAbs a ∣ natAbs b k : Nat hk : b = a * ↑k ∨ b = -(a * ↑k) ⊢ a ∣ b ** cases hk <;> subst b ** case inl a : Int k : Nat x✝ : natAbs a ∣ natAbs (a * ↑k) ⊢ a ∣ a * ↑k ** apply Int.dvd_mul_right ** case inr a : Int k : Nat x✝ : natAbs a ∣ natAbs (-(a * ↑k)) ⊢ a ∣ -(a * ↑k) ** rw [← Int.mul_neg] ** case inr a : Int k : Nat x✝ : natAbs a ∣ natAbs (-(a * ↑k)) ⊢ a ∣ a * -↑k ** apply Int.dvd_mul_right ** Qed | |
Int.dvd_natAbs ** a b : Int e : b = ↑(natAbs b) ⊢ a ∣ ↑(natAbs b) ↔ a ∣ b ** rw [← e] ** a b : Int e : b = -↑(natAbs b) ⊢ a ∣ ↑(natAbs b) ↔ a ∣ b ** rw [← Int.dvd_neg, ← e] ** Qed | |
Int.ofNat_dvd_left ** n : Nat z : Int ⊢ ↑n ∣ z ↔ n ∣ natAbs z ** rw [← natAbs_dvd_natAbs, natAbs_ofNat] ** Qed | |
Int.ofNat_dvd_right ** n : Nat z : Int ⊢ z ∣ ↑n ↔ natAbs z ∣ n ** rw [← natAbs_dvd_natAbs, natAbs_ofNat] ** Qed | |
Int.dvd_antisymm ** a b : Int H1 : 0 ≤ a H2 : 0 ≤ b ⊢ a ∣ b → b ∣ a → a = b ** rw [← natAbs_of_nonneg H1, ← natAbs_of_nonneg H2] ** a b : Int H1 : 0 ≤ a H2 : 0 ≤ b ⊢ ↑(natAbs a) ∣ ↑(natAbs b) → ↑(natAbs b) ∣ ↑(natAbs a) → ↑(natAbs a) = ↑(natAbs b) ** rw [ofNat_dvd, ofNat_dvd, ofNat_inj] ** a b : Int H1 : 0 ≤ a H2 : 0 ≤ b ⊢ natAbs a ∣ natAbs b → natAbs b ∣ natAbs a → natAbs a = natAbs b ** apply Nat.dvd_antisymm ** Qed | |
Int.dvd_sub_of_emod_eq ** a b c : Int h : a % b = c ⊢ b ∣ a - c ** have hx : (a % b) % b = c % b := by
rw [h] ** a b c : Int h : a % b = c hx : a % b % b = c % b ⊢ b ∣ a - c ** rw [Int.emod_emod, ← emod_sub_cancel_right c, Int.sub_self, zero_emod] at hx ** a b c : Int h : a % b = c hx : (a - c) % b = 0 ⊢ b ∣ a - c ** exact dvd_of_emod_eq_zero hx ** a b c : Int h : a % b = c ⊢ a % b % b = c % b ** rw [h] ** Qed | |
Int.mul_div_cancel' ** a b : Int H : a ∣ b ⊢ a * div b a = b ** rw [Int.mul_comm, Int.div_mul_cancel H] ** Qed | |
Int.mul_ediv_cancel' ** a b : Int H : a ∣ b ⊢ a * (b / a) = b ** rw [Int.mul_comm, Int.ediv_mul_cancel H] ** Qed | |
Int.mul_div_assoc ** a c d : Int cz : c = 0 ⊢ div (a * (c * d)) c = a * div (c * d) c ** simp [cz, Int.mul_zero] ** a c d : Int cz : ¬c = 0 ⊢ div (a * (c * d)) c = a * div (c * d) c ** rw [Int.mul_left_comm, Int.mul_div_cancel_left _ cz, Int.mul_div_cancel_left _ cz] ** Qed | |
Int.mul_ediv_assoc ** a c d : Int cz : c = 0 ⊢ a * (c * d) / c = a * (c * d / c) ** simp [cz, Int.mul_zero] ** a c d : Int cz : ¬c = 0 ⊢ a * (c * d) / c = a * (c * d / c) ** rw [Int.mul_left_comm, Int.mul_ediv_cancel_left _ cz, Int.mul_ediv_cancel_left _ cz] ** Qed | |
Int.mul_ediv_assoc' ** b a c : Int h : c ∣ a ⊢ a * b / c = a / c * b ** rw [Int.mul_comm, Int.mul_ediv_assoc _ h, Int.mul_comm] ** Qed | |
Int.div_dvd_div ** a b c : Int az : a = 0 ⊢ div (a * b) a ∣ div (a * b * c) a ** simp [az] ** a b c : Int az : ¬a = 0 ⊢ div (a * b) a ∣ div (a * b * c) a ** rw [Int.mul_div_cancel_left _ az, Int.mul_assoc, Int.mul_div_cancel_left _ az] ** a b c : Int az : ¬a = 0 ⊢ b ∣ b * c ** apply Int.dvd_mul_right ** Qed | |
Int.eq_mul_of_div_eq_right ** a b c : Int H1 : b ∣ a H2 : div a b = c ⊢ a = b * c ** rw [← H2, Int.mul_div_cancel' H1] ** Qed | |
Int.eq_mul_of_ediv_eq_right ** a b c : Int H1 : b ∣ a H2 : a / b = c ⊢ a = b * c ** rw [← H2, Int.mul_ediv_cancel' H1] ** Qed | |
Int.div_eq_of_eq_mul_right ** a b c : Int H1 : b ≠ 0 H2 : a = b * c ⊢ div a b = c ** rw [H2, Int.mul_div_cancel_left _ H1] ** Qed | |
Int.ediv_eq_of_eq_mul_right ** a b c : Int H1 : b ≠ 0 H2 : a = b * c ⊢ a / b = c ** rw [H2, Int.mul_ediv_cancel_left _ H1] ** Qed | |
Int.eq_mul_of_div_eq_left ** a b c : Int H1 : b ∣ a H2 : div a b = c ⊢ a = c * b ** rw [Int.mul_comm, Int.eq_mul_of_div_eq_right H1 H2] ** Qed | |
Int.eq_mul_of_ediv_eq_left ** a b c : Int H1 : b ∣ a H2 : a / b = c ⊢ a = c * b ** rw [Int.mul_comm, Int.eq_mul_of_ediv_eq_right H1 H2] ** Qed | |
Int.div_eq_of_eq_mul_left ** a b c : Int H1 : b ≠ 0 H2 : a = c * b ⊢ a = b * c ** rw [Int.mul_comm, H2] ** Qed | |
Int.ediv_eq_of_eq_mul_left ** a b c : Int H1 : b ≠ 0 H2 : a = c * b ⊢ a = b * c ** rw [Int.mul_comm, H2] ** Qed | |
Int.eq_zero_of_div_eq_zero ** d n : Int h : d ∣ n H : div n d = 0 ⊢ n = 0 ** rw [← Int.mul_div_cancel' h, H, Int.mul_zero] ** Qed | |
Int.eq_zero_of_ediv_eq_zero ** d n : Int h : d ∣ n H : n / d = 0 ⊢ n = 0 ** rw [← Int.mul_ediv_cancel' h, H, Int.mul_zero] ** Qed | |
Int.neg_ediv_of_dvd ** b c : Int ⊢ -(b * c) / b = -(b * c / b) ** if bz : b = 0 then simp [bz] else
rw [Int.neg_mul_eq_mul_neg, Int.mul_ediv_cancel_left _ bz, Int.mul_ediv_cancel_left _ bz] ** b c : Int bz : b = 0 ⊢ -(b * c) / b = -(b * c / b) ** simp [bz] ** b c : Int bz : ¬b = 0 ⊢ -(b * c) / b = -(b * c / b) ** rw [Int.neg_mul_eq_mul_neg, Int.mul_ediv_cancel_left _ bz, Int.mul_ediv_cancel_left _ bz] ** Qed | |
Int.div_left_inj ** a b d : Int hda : d ∣ a hdb : d ∣ b h : div a d = div b d ⊢ a = b ** rw [← Int.mul_div_cancel' hda, ← Int.mul_div_cancel' hdb, h] ** Qed | |
Int.ediv_left_inj ** a b d : Int hda : d ∣ a hdb : d ∣ b h : a / d = b / d ⊢ a = b ** rw [← Int.mul_ediv_cancel' hda, ← Int.mul_ediv_cancel' hdb, h] ** Qed | |
Int.div_sign ** x✝ : Int n✝ : Nat ⊢ div x✝ (sign ↑(succ n✝)) = x✝ * sign ↑(succ n✝) ** simp [sign, Int.mul_one] ** x✝ : Int ⊢ div x✝ (sign 0) = x✝ * sign 0 ** simp [sign, Int.mul_zero] ** x✝ : Int a✝ : Nat ⊢ div x✝ (sign -[a✝+1]) = x✝ * sign -[a✝+1] ** simp [sign, Int.mul_neg, Int.mul_one] ** Qed | |
Int.ediv_sign ** x✝ : Int n✝ : Nat ⊢ x✝ / sign ↑(succ n✝) = x✝ * sign ↑(succ n✝) ** simp [sign, Int.mul_one] ** x✝ : Int ⊢ x✝ / sign 0 = x✝ * sign 0 ** simp [sign, Int.mul_zero] ** x✝ : Int a✝ : Nat ⊢ x✝ / sign -[a✝+1] = x✝ * sign -[a✝+1] ** simp [sign, Int.mul_neg, Int.mul_one] ** Qed | |
Fin.ite_val ** n : Nat c : Prop inst✝ : Decidable c x : c → Fin n y : ¬c → Fin n ⊢ ↑(if h : c then x h else y h) = if h : c then ↑(x h) else ↑(y h) ** by_cases c <;> simp [*] ** Qed | |
Fin.dite_val ** n : Nat c : Prop inst✝ : Decidable c x y : Fin n ⊢ ↑(if c then x else y) = if c then ↑x else ↑y ** by_cases c <;> simp [*] ** Qed | |
Fin.rev_rev ** n : Nat i : Fin n ⊢ ↑(rev (rev i)) = ↑i ** rw [val_rev, val_rev, ← Nat.sub_sub, Nat.sub_sub_self (by exact i.2), Nat.add_sub_cancel] ** n : Nat i : Fin n ⊢ ↑i + 1 ≤ n ** exact i.2 ** Qed | |
Fin.rev_inj ** n : Nat i j : Fin n h : rev i = rev j ⊢ i = j ** simpa using congrArg rev h ** Qed | |
Fin.rev_eq ** n a : Nat i : Fin (n + 1) h : n = a + ↑i ⊢ rev i = { val := a, isLt := (_ : a < Nat.succ n) } ** ext ** case h n a : Nat i : Fin (n + 1) h : n = a + ↑i ⊢ ↑(rev i) = ↑{ val := a, isLt := (_ : a < Nat.succ n) } ** dsimp ** case h n a : Nat i : Fin (n + 1) h : n = a + ↑i ⊢ n + 1 - (↑i + 1) = a ** conv => lhs; congr; rw [h] ** case h n a : Nat i : Fin (n + 1) h : n = a + ↑i ⊢ a + ↑i + 1 - (↑i + 1) = a ** rw [Nat.add_assoc, Nat.add_sub_cancel] ** Qed | |
Fin.val_add_one_of_lt ** n : Nat i : Fin (Nat.succ n) h : i < last n ⊢ ↑(i + 1) = ↑i + 1 ** match n with
| 0 => cases h
| n+1 => rw [val_add, val_one, Nat.mod_eq_of_lt (by exact Nat.succ_lt_succ h)] ** n : Nat i : Fin (Nat.succ 0) h : i < last 0 ⊢ ↑(i + 1) = ↑i + 1 ** cases h ** n✝ n : Nat i : Fin (Nat.succ (n + 1)) h : i < last (n + 1) ⊢ ↑(i + 1) = ↑i + 1 ** rw [val_add, val_one, Nat.mod_eq_of_lt (by exact Nat.succ_lt_succ h)] ** n✝ n : Nat i : Fin (Nat.succ (n + 1)) h : i < last (n + 1) ⊢ ↑i + 1 < Nat.succ (n + 1) ** exact Nat.succ_lt_succ h ** Qed | |
Fin.last_add_one ** n : Nat ⊢ last (n + 1) + 1 = 0 ** ext ** case h n : Nat ⊢ ↑(last (n + 1) + 1) = ↑0 ** rw [val_add, val_zero, val_last, val_one, Nat.mod_self] ** Qed | |
Fin.val_add_one ** n : Nat i : Fin (n + 1) ⊢ ↑(i + 1) = if i = last n then 0 else ↑i + 1 ** match Nat.eq_or_lt_of_le (le_last i) with
| .inl h => cases Fin.eq_of_val_eq h; simp
| .inr h => simpa [Fin.ne_of_lt h] using val_add_one_of_lt h ** n : Nat i : Fin (n + 1) h : ↑i = ↑(last n) ⊢ ↑(i + 1) = if i = last n then 0 else ↑i + 1 ** cases Fin.eq_of_val_eq h ** case refl n : Nat h : ↑(last n) = ↑(last n) ⊢ ↑(last n + 1) = if last n = last n then 0 else ↑(last n) + 1 ** simp ** n : Nat i : Fin (n + 1) h : ↑i < ↑(last n) ⊢ ↑(i + 1) = if i = last n then 0 else ↑i + 1 ** simpa [Fin.ne_of_lt h] using val_add_one_of_lt h ** Qed | |
Fin.add_one_pos ** n : Nat i : Fin (n + 1) h : i < last n ⊢ 0 < i + 1 ** match n with
| 0 => cases h
| n+1 =>
rw [Fin.lt_def, val_last, ← Nat.add_lt_add_iff_right 1] at h
rw [Fin.lt_def, val_add, val_zero, val_one, Nat.mod_eq_of_lt h]
exact Nat.zero_lt_succ _ ** n : Nat i : Fin (0 + 1) h : i < last 0 ⊢ 0 < i + 1 ** cases h ** n✝ n : Nat i : Fin (n + 1 + 1) h : i < last (n + 1) ⊢ 0 < i + 1 ** rw [Fin.lt_def, val_last, ← Nat.add_lt_add_iff_right 1] at h ** n✝ n : Nat i : Fin (n + 1 + 1) h : ↑i + 1 < n + 1 + 1 ⊢ 0 < i + 1 ** rw [Fin.lt_def, val_add, val_zero, val_one, Nat.mod_eq_of_lt h] ** n✝ n : Nat i : Fin (n + 1 + 1) h : ↑i + 1 < n + 1 + 1 ⊢ 0 < ↑i + 1 ** exact Nat.zero_lt_succ _ ** Qed | |
Fin.val_succ ** n : Nat j : Fin n ⊢ ↑(succ j) = ↑j + 1 ** cases j ** case mk n val✝ : Nat isLt✝ : val✝ < n ⊢ ↑(succ { val := val✝, isLt := isLt✝ }) = ↑{ val := val✝, isLt := isLt✝ } + 1 ** simp [Fin.succ] ** Qed | |
Fin.succ_pos ** n : Nat a : Fin n ⊢ 0 < succ a ** simp [Fin.lt_def, Nat.succ_pos] ** Qed | |
Fin.succ_inj ** n : Nat a b : Fin n ⊢ succ a = succ b ↔ a = b ** refine ⟨fun h => ext ?_, congrArg _⟩ ** n : Nat a b : Fin n h : succ a = succ b ⊢ ↑a = ↑b ** apply Nat.le_antisymm <;> exact succ_le_succ_iff.1 (h ▸ Nat.le_refl _) ** Qed | |
Fin.mk_succ_pos ** n i : Nat h : i < n ⊢ 0 < { val := Nat.succ i, isLt := (_ : i + 1 < n + 1) } ** rw [lt_def, val_zero] ** n i : Nat h : i < n ⊢ 0 < ↑{ val := Nat.succ i, isLt := (_ : i + 1 < n + 1) } ** exact Nat.succ_pos i ** Qed | |
Fin.one_lt_succ_succ ** n : Nat a : Fin n ⊢ 1 < succ (succ a) ** let n+1 := n ** n✝ n : Nat a : Fin (n + 1) ⊢ 1 < succ (succ a) ** rw [← succ_zero_eq_one, succ_lt_succ_iff] ** n✝ n : Nat a : Fin (n + 1) ⊢ 0 < succ a ** exact succ_pos a ** Qed | |
Fin.add_one_lt_iff ** n : Nat k : Fin (n + 2) ⊢ k + 1 < k ↔ k = last (n + 1) ** simp only [lt_def, val_add, val_last, ext_iff] ** n : Nat k : Fin (n + 2) ⊢ (↑k + ↑1) % (n + 2) < ↑k ↔ ↑k = n + 1 ** let ⟨k, hk⟩ := k ** n : Nat k✝ : Fin (n + 2) k : Nat hk : k < n + 2 ⊢ (↑{ val := k, isLt := hk } + ↑1) % (n + 2) < ↑{ val := k, isLt := hk } ↔ ↑{ val := k, isLt := hk } = n + 1 ** match Nat.eq_or_lt_of_le (Nat.le_of_lt_succ hk) with
| .inl h => cases h; simp [Nat.succ_pos]
| .inr hk' => simp [Nat.ne_of_lt hk', Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.le_succ] ** n : Nat k✝ : Fin (n + 2) k : Nat hk : k < n + 2 h : k = n + 1 ⊢ (↑{ val := k, isLt := hk } + ↑1) % (n + 2) < ↑{ val := k, isLt := hk } ↔ ↑{ val := k, isLt := hk } = n + 1 ** cases h ** case refl n : Nat k : Fin (n + 2) hk : n + 1 < n + 2 ⊢ (↑{ val := n + 1, isLt := hk } + ↑1) % (n + 2) < ↑{ val := n + 1, isLt := hk } ↔ ↑{ val := n + 1, isLt := hk } = n + 1 ** simp [Nat.succ_pos] ** n : Nat k✝ : Fin (n + 2) k : Nat hk : k < n + 2 hk' : k < n + 1 ⊢ (↑{ val := k, isLt := hk } + ↑1) % (n + 2) < ↑{ val := k, isLt := hk } ↔ ↑{ val := k, isLt := hk } = n + 1 ** simp [Nat.ne_of_lt hk', Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.le_succ] ** Qed | |
Fin.lt_add_one_iff ** n : Nat k : Fin (n + 1) ⊢ k < k + 1 ↔ k < last n ** rw [← Decidable.not_iff_not] ** n : Nat k : Fin (n + 1) ⊢ ¬k < k + 1 ↔ ¬k < last n ** simp ** Qed | |
Fin.castLE_zero ** n m : Nat h : Nat.succ n ≤ Nat.succ m ⊢ castLE h 0 = 0 ** simp [ext_iff] ** Qed | |
Fin.castLE_succ ** m n : Nat h : m + 1 ≤ n + 1 i : Fin m ⊢ castLE h (succ i) = succ (castLE (_ : m ≤ n) i) ** simp [ext_iff] ** Qed | |
Fin.castLE_castLE ** k m n : Nat km : k ≤ m mn : m ≤ n i : Fin k ⊢ ↑(castLE mn (castLE km i)) = ↑(castLE (_ : k ≤ n) i) ** simp only [coe_castLE] ** Qed | |
Fin.cast_last ** n n' : Nat h : n + 1 = n' + 1 ⊢ ↑(cast h (last n)) = ↑(last n') ** rw [coe_cast, val_last, val_last, Nat.succ.inj h] ** Qed | |
Fin.castAdd_lt ** m n : Nat i : Fin m ⊢ ↑(castAdd n i) < m ** simp ** Qed | |
Fin.succ_cast_eq ** n n' : Nat i : Fin n h : n = n' ⊢ Nat.succ n = Nat.succ n' ** rw [h] ** Qed | |
Fin.castSucc_lt_succ ** n : Nat i : Fin n ⊢ ↑(castSucc i) < ↑(succ i) ** simp only [coe_castSucc, val_succ, Nat.lt_succ_self] ** Qed | |
Fin.le_castSucc_iff ** n : Nat i : Fin (n + 1) j : Fin n ⊢ i ≤ castSucc j ↔ i < succ j ** simpa [lt_def, le_def] using Nat.succ_le_succ_iff.symm ** Qed | |
Fin.succ_eq_last_succ ** n : Nat i : Fin (Nat.succ n) ⊢ succ i = last (n + 1) ↔ i = last n ** rw [← succ_last, succ_inj] ** Qed | |
Fin.castSucc_inj ** n : Nat a b : Fin n ⊢ castSucc a = castSucc b ↔ a = b ** simp [ext_iff] ** Qed | |
Fin.castSucc_pos ** n : Nat i : Fin (n + 1) h : 0 < i ⊢ 0 < castSucc i ** simpa [lt_def] using h ** Qed | |
Fin.castSucc_eq_zero_iff ** n : Nat a : Fin (n + 1) ⊢ castSucc a = 0 ↔ a = 0 ** simp [ext_iff] ** Qed | |
Fin.castSucc_fin_succ ** n : Nat j : Fin n ⊢ castSucc (succ j) = succ (castSucc j) ** simp [Fin.ext_iff] ** Qed | |
Fin.coeSucc_eq_succ ** n : Nat a : Fin n ⊢ castSucc a + 1 = succ a ** cases n ** case zero a : Fin Nat.zero ⊢ castSucc a + 1 = succ a ** exact a.elim0 ** case succ n✝ : Nat a : Fin (Nat.succ n✝) ⊢ castSucc a + 1 = succ a ** simp [ext_iff, add_def, Nat.mod_eq_of_lt (Nat.succ_lt_succ a.is_lt)] ** Qed | |
Fin.lt_succ ** n : Nat a : Fin n ⊢ castSucc a < succ a ** rw [castSucc, lt_def, coe_castAdd, val_succ] ** n : Nat a : Fin n ⊢ ↑a < ↑a + 1 ** exact Nat.lt_succ_self a.val ** Qed | |
Fin.natAdd_zero ** n : Nat ⊢ natAdd 0 = cast (_ : n = 0 + n) ** ext ** case h.h n : Nat x✝ : Fin n ⊢ ↑(natAdd 0 x✝) = ↑(cast (_ : n = 0 + n) x✝) ** simp ** Qed | |
Fin.succ_pred ** n : Nat h : 0 < n + 1 hi : { val := 0, isLt := h } ≠ 0 ⊢ succ (pred { val := 0, isLt := h } hi) = { val := 0, isLt := h } ** simp only [mk_zero, ne_eq, not_true] at hi ** Qed | |
Fin.pred_succ ** n : Nat i : Fin n h : succ i ≠ 0 ⊢ pred (succ i) h = i ** cases i ** case mk n val✝ : Nat isLt✝ : val✝ < n h : succ { val := val✝, isLt := isLt✝ } ≠ 0 ⊢ pred (succ { val := val✝, isLt := isLt✝ }) h = { val := val✝, isLt := isLt✝ } ** rfl ** Qed | |
Fin.pred_eq_iff_eq_succ ** n : Nat i : Fin (n + 1) hi : i ≠ 0 j : Fin n h : pred i hi = j ⊢ i = succ j ** simp only [← h, Fin.succ_pred] ** n : Nat i : Fin (n + 1) hi : i ≠ 0 j : Fin n h : i = succ j ⊢ pred i hi = j ** simp only [h, Fin.pred_succ] ** Qed | |
Fin.pred_le_pred_iff ** n : Nat a b : Fin (Nat.succ n) ha : a ≠ 0 hb : b ≠ 0 ⊢ pred a ha ≤ pred b hb ↔ a ≤ b ** rw [← succ_le_succ_iff, succ_pred, succ_pred] ** Qed | |
Fin.pred_lt_pred_iff ** n : Nat a b : Fin (Nat.succ n) ha : a ≠ 0 hb : b ≠ 0 ⊢ pred a ha < pred b hb ↔ a < b ** rw [← succ_lt_succ_iff, succ_pred, succ_pred] ** Qed | |
Fin.pred_inj ** n : Nat isLt✝ : 0 < n + 1 x✝¹ : Fin (n + 1) ha : { val := 0, isLt := isLt✝ } ≠ 0 x✝ : x✝¹ ≠ 0 ⊢ pred { val := 0, isLt := isLt✝ } ha = pred x✝¹ x✝ ↔ { val := 0, isLt := isLt✝ } = x✝¹ ** simp only [mk_zero, ne_eq, not_true] at ha ** n i : Nat isLt✝¹ : i + 1 < n + 1 isLt✝ : 0 < n + 1 x✝ : { val := i + 1, isLt := isLt✝¹ } ≠ 0 hb : { val := 0, isLt := isLt✝ } ≠ 0 ⊢ pred { val := i + 1, isLt := isLt✝¹ } x✝ = pred { val := 0, isLt := isLt✝ } hb ↔ { val := i + 1, isLt := isLt✝¹ } = { val := 0, isLt := isLt✝ } ** simp only [mk_zero, ne_eq, not_true] at hb ** n i : Nat hi : i + 1 < n + 1 j : Nat hj : j + 1 < n + 1 ha : { val := i + 1, isLt := hi } ≠ 0 hb : { val := j + 1, isLt := hj } ≠ 0 ⊢ pred { val := i + 1, isLt := hi } ha = pred { val := j + 1, isLt := hj } hb ↔ { val := i + 1, isLt := hi } = { val := j + 1, isLt := hj } ** simp [ext_iff] ** Qed | |
Fin.succRecOn_zero ** motive : (n : Nat) → Fin n → Sort u_1 zero : (n : Nat) → motive (n + 1) 0 succ : (n : Nat) → (i : Fin n) → motive n i → motive (Nat.succ n) (Fin.succ i) n : Nat ⊢ succRecOn 0 zero succ = zero n ** cases n <;> rfl ** Qed | |
Fin.succRecOn_succ ** motive : (n : Nat) → Fin n → Sort u_1 zero : (n : Nat) → motive (n + 1) 0 succ : (n : Nat) → (i : Fin n) → motive n i → motive (Nat.succ n) (Fin.succ i) n : Nat i : Fin n ⊢ succRecOn (Fin.succ i) zero succ = succ n i (succRecOn i zero succ) ** cases i ** case mk motive : (n : Nat) → Fin n → Sort u_1 zero : (n : Nat) → motive (n + 1) 0 succ : (n : Nat) → (i : Fin n) → motive n i → motive (Nat.succ n) (Fin.succ i) n val✝ : Nat isLt✝ : val✝ < n ⊢ succRecOn (Fin.succ { val := val✝, isLt := isLt✝ }) zero succ = succ n { val := val✝, isLt := isLt✝ } (succRecOn { val := val✝, isLt := isLt✝ } zero succ) ** rfl ** Qed | |
Fin.fin_two_eq_of_eq_zero_iff ** ⊢ ∀ {a b : Fin 2}, (a = 0 ↔ b = 0) → a = b ** simp [forall_fin_two] ** Qed | |
Fin.reverseInduction_last ** n : Nat motive : Fin (n + 1) → Sort u_1 zero : motive (last n) succ : (i : Fin n) → motive (Fin.succ i) → motive (castSucc i) ⊢ reverseInduction zero succ (last n) = zero ** rw [reverseInduction] ** n : Nat motive : Fin (n + 1) → Sort u_1 zero : motive (last n) succ : (i : Fin n) → motive (Fin.succ i) → motive (castSucc i) ⊢ (if hi : last n = last n then _root_.cast (_ : motive (last n) = motive (last n)) zero else let j := { val := ↑(last n), isLt := (_ : ↑(last n) < n) }; succ j (reverseInduction zero succ (Fin.succ j))) = zero ** simp ** n : Nat motive : Fin (n + 1) → Sort u_1 zero : motive (last n) succ : (i : Fin n) → motive (Fin.succ i) → motive (castSucc i) ⊢ _root_.cast (_ : motive (last n) = motive (last n)) zero = zero ** rfl ** Qed | |
Fin.reverseInduction_castSucc ** n : Nat motive : Fin (n + 1) → Sort u_1 zero : motive (last n) succ : (i : Fin n) → motive (Fin.succ i) → motive (castSucc i) i : Fin n ⊢ reverseInduction zero succ (castSucc i) = succ i (reverseInduction zero succ (Fin.succ i)) ** rw [reverseInduction, dif_neg (Fin.ne_of_lt (Fin.castSucc_lt_last i))] ** n : Nat motive : Fin (n + 1) → Sort u_1 zero : motive (last n) succ : (i : Fin n) → motive (Fin.succ i) → motive (castSucc i) i : Fin n ⊢ (let j := { val := ↑(castSucc i), isLt := (_ : ↑(castSucc i) < n) }; succ j (reverseInduction zero succ (Fin.succ j))) = succ i (reverseInduction zero succ (Fin.succ i)) ** rfl ** Qed | |
Fin.addCases_left ** m n : Nat motive : Fin (m + n) → Sort u_1 left : (i : Fin m) → motive (castAdd n i) right : (i : Fin n) → motive (natAdd m i) i : Fin m ⊢ addCases left right (castAdd n i) = left i ** rw [addCases, dif_pos (castAdd_lt _ _)] ** m n : Nat motive : Fin (m + n) → Sort u_1 left : (i : Fin m) → motive (castAdd n i) right : (i : Fin n) → motive (natAdd m i) i : Fin m ⊢ (_ : castAdd n (castLT (castAdd n i) (_ : ↑(castAdd n i) < m)) = castAdd n i) ▸ left (castLT (castAdd n i) (_ : ↑(castAdd n i) < m)) = left i ** rfl ** Qed | |
Fin.mul_one ** n : Nat k : Fin (n + 1) ⊢ k * 1 = k ** match n with
| 0 => exact Subsingleton.elim (α := Fin 1) ..
| n+1 => simp [ext_iff, mul_def, Nat.mod_eq_of_lt (is_lt k)] ** n : Nat k : Fin (0 + 1) ⊢ k * 1 = k ** exact Subsingleton.elim (α := Fin 1) .. ** n✝ n : Nat k : Fin (n + 1 + 1) ⊢ k * 1 = k ** simp [ext_iff, mul_def, Nat.mod_eq_of_lt (is_lt k)] ** Qed | |
Fin.mul_comm ** n : Nat a b : Fin n ⊢ ↑(a * b) = ↑(b * a) ** rw [mul_def, mul_def, Nat.mul_comm] ** Qed | |
Fin.mul_zero ** n : Nat k : Fin (n + 1) ⊢ k * 0 = 0 ** simp [ext_iff, mul_def] ** Qed | |
Fin.zero_mul ** n : Nat k : Fin (n + 1) ⊢ 0 * k = 0 ** simp [ext_iff, mul_def] ** Qed | |
String.utf8Len_append ** cs₁ cs₂ : List Char ⊢ utf8Len (cs₁ ++ cs₂) = utf8Len cs₁ + utf8Len cs₂ ** induction cs₁ <;> simp [*, Nat.add_right_comm] ** Qed | |
String.utf8Len_reverseAux ** cs₁ cs₂ : List Char ⊢ utf8Len (List.reverseAux cs₁ cs₂) = utf8Len cs₁ + utf8Len cs₂ ** induction cs₁ generalizing cs₂ <;> simp [*, ← Nat.add_assoc, Nat.add_right_comm] ** Qed | |
String.utf8Len_eq_zero ** l : List Char ⊢ utf8Len l = 0 ↔ l = [] ** cases l <;> simp [Nat.ne_of_gt add_csize_pos] ** Qed | |
String.Pos.valid_endPos ** s : String ⊢ s.data ++ [] = s.data ** simp ** Qed | |
String.Pos.Valid.le_endPos ** cs cs' : List Char ⊢ { byteIdx := utf8ByteSize.go cs } ≤ endPos { data := cs ++ cs' } ** simp [Nat.le_add_right] ** Qed | |
String.utf8GetAux_add_right_cancel ** s : List Char i p n : Nat ⊢ utf8GetAux s { byteIdx := i + n } { byteIdx := p + n } = utf8GetAux s { byteIdx := i } { byteIdx := p } ** apply utf8InductionOn s ⟨i⟩ ⟨p⟩ (motive := fun s i =>
utf8GetAux s ⟨i.byteIdx + n⟩ ⟨p + n⟩ = utf8GetAux s i ⟨p⟩) <;>
simp [utf8GetAux] ** case ind s : List Char i p n : Nat ⊢ ∀ (c : Char) (cs : List Char) (i : Pos), ¬i = { byteIdx := p } → utf8GetAux cs { byteIdx := i.byteIdx + csize c + n } { byteIdx := p + n } = utf8GetAux cs (i + c) { byteIdx := p } → (if { byteIdx := i.byteIdx + n } = { byteIdx := p + n } then c else utf8GetAux cs ({ byteIdx := i.byteIdx + n } + c) { byteIdx := p + n }) = if i = { byteIdx := p } then c else utf8GetAux cs (i + c) { byteIdx := p } ** intro c cs ⟨i⟩ h ih ** case ind s : List Char i✝ p n : Nat c : Char cs : List Char i : Nat h : ¬{ byteIdx := i } = { byteIdx := p } ih : utf8GetAux cs { byteIdx := { byteIdx := i }.byteIdx + csize c + n } { byteIdx := p + n } = utf8GetAux cs ({ byteIdx := i } + c) { byteIdx := p } ⊢ (if { byteIdx := { byteIdx := i }.byteIdx + n } = { byteIdx := p + n } then c else utf8GetAux cs ({ byteIdx := { byteIdx := i }.byteIdx + n } + c) { byteIdx := p + n }) = if { byteIdx := i } = { byteIdx := p } then c else utf8GetAux cs ({ byteIdx := i } + c) { byteIdx := p } ** simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ ** case ind s : List Char i✝ p n : Nat c : Char cs : List Char i : Nat ih : utf8GetAux cs { byteIdx := { byteIdx := i }.byteIdx + csize c + n } { byteIdx := p + n } = utf8GetAux cs ({ byteIdx := i } + c) { byteIdx := p } h : ¬i = p ⊢ (if i + n = p + n then c else utf8GetAux cs { byteIdx := i + n + csize c } { byteIdx := p + n }) = if i = p then c else utf8GetAux cs { byteIdx := i + csize c } { byteIdx := p } ** simp [Nat.add_right_cancel_iff, h] ** case ind s : List Char i✝ p n : Nat c : Char cs : List Char i : Nat ih : utf8GetAux cs { byteIdx := { byteIdx := i }.byteIdx + csize c + n } { byteIdx := p + n } = utf8GetAux cs ({ byteIdx := i } + c) { byteIdx := p } h : ¬i = p ⊢ utf8GetAux cs { byteIdx := i + n + csize c } { byteIdx := p + n } = utf8GetAux cs { byteIdx := i + csize c } { byteIdx := p } ** rw [Nat.add_right_comm] ** case ind s : List Char i✝ p n : Nat c : Char cs : List Char i : Nat ih : utf8GetAux cs { byteIdx := { byteIdx := i }.byteIdx + csize c + n } { byteIdx := p + n } = utf8GetAux cs ({ byteIdx := i } + c) { byteIdx := p } h : ¬i = p ⊢ utf8GetAux cs { byteIdx := i + csize c + n } { byteIdx := p + n } = utf8GetAux cs { byteIdx := i + csize c } { byteIdx := p } ** exact ih ** Qed | |
String.utf8GetAux?_of_valid ** cs cs' : List Char i p : Nat hp : i + utf8Len cs = p ⊢ utf8GetAux? (cs ++ cs') { byteIdx := i } { byteIdx := p } = List.head? cs' ** match cs, cs' with
| [], [] => rfl
| [], c::cs' => simp [← hp, utf8GetAux?]
| c::cs, cs' =>
simp [utf8GetAux?]; rw [if_neg]
case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize
refine utf8GetAux?_of_valid cs cs' ?_
simpa [Nat.add_assoc, Nat.add_comm] using hp ** cs cs' : List Char i p : Nat hp : i + utf8Len [] = p ⊢ utf8GetAux? ([] ++ []) { byteIdx := i } { byteIdx := p } = List.head? [] ** rfl ** cs cs'✝ : List Char i p : Nat c : Char cs' : List Char hp : i + utf8Len [] = p ⊢ utf8GetAux? ([] ++ c :: cs') { byteIdx := i } { byteIdx := p } = List.head? (c :: cs') ** simp [← hp, utf8GetAux?] ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ utf8GetAux? (c :: cs ++ cs') { byteIdx := i } { byteIdx := p } = List.head? cs' ** simp [utf8GetAux?] ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ (if { byteIdx := i } = { byteIdx := p } then some c else utf8GetAux? (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p }) = List.head? cs' ** rw [if_neg] ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ utf8GetAux? (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p } = List.head? cs' case hnc cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ ¬{ byteIdx := i } = { byteIdx := p } ** case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ utf8GetAux? (cs ++ cs') ({ byteIdx := i } + c) { byteIdx := p } = List.head? cs' ** refine utf8GetAux?_of_valid cs cs' ?_ ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ { byteIdx := i }.byteIdx + csize c + utf8Len cs = p ** simpa [Nat.add_assoc, Nat.add_comm] using hp ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ ¬{ byteIdx := i } = { byteIdx := p } ** simp [← hp, Pos.ext_iff] ** cs✝ cs'✝ : List Char i p : Nat c : Char cs cs' : List Char hp : i + utf8Len (c :: cs) = p ⊢ ¬i = i + (utf8Len cs + csize c) ** exact ne_self_add_add_csize ** Qed |