Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 6f9cb03

Browse files
committed
chore(*): make more transitive relations available to calc (#12860)
Fixed as many possible declarations to have the correct argument order, as per [Zulip](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/calc.20with.20.60.E2.89.83*.60). Golfed some random ones while I was at it.
1 parent a85958c commit 6f9cb03

17 files changed

Lines changed: 82 additions & 50 deletions

File tree

src/algebra/divisibility.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ exists.elim H₁ H₂
5555

5656
local attribute [simp] mul_assoc mul_comm mul_left_comm
5757

58-
@[trans] theorem dvd_trans (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c :=
59-
match h₁, h₂ with
60-
| ⟨d, (h₃ : b = a * d)⟩, ⟨e, (h₄ : c = b * e)⟩ :=
61-
⟨d * e, show c = a * (d * e), by simp [h₃, h₄]⟩
62-
end
58+
@[trans] theorem dvd_trans : a ∣ b → b ∣ c → a ∣ c
59+
| ⟨d, h₁⟩ ⟨e, h₂⟩ := ⟨d * e, h₁ ▸ h₂.trans $ mul_assoc a d e⟩
6360

6461
alias dvd_trans ← has_dvd.dvd.trans
6562

src/analysis/asymptotics/asymptotic_equivalent.lean

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import analysis.normed_space.ordered
99
/-!
1010
# Asymptotic equivalence
1111
12-
In this file, we define the relation `is_equivalent u v l`, which means that `u-v` is little o of
12+
In this file, we define the relation `is_equivalent l u v`, which means that `u-v` is little o of
1313
`v` along the filter `l`.
1414
1515
Unlike `is_[oO]` relations, this one requires `u` and `v` to have the same codomain `β`. While the
@@ -18,7 +18,7 @@ definition only requires `β` to be a `normed_group`, most interesting propertie
1818
1919
## Notations
2020
21-
We introduce the notation `u ~[l] v := is_equivalent u v l`, which you can use by opening the
21+
We introduce the notation `u ~[l] v := is_equivalent l u v`, which you can use by opening the
2222
`asymptotics` locale.
2323
2424
## Main results
@@ -47,6 +47,11 @@ If `β` is a `normed_linear_ordered_field` :
4747
- If `u ~[l] v`, we have `tendsto u l at_top ↔ tendsto v l at_top`
4848
(see `is_equivalent.tendsto_at_top_iff`)
4949
50+
## Implementation Notes
51+
52+
Note that `is_equivalent` takes the parameters `(l : filter α) (u v : α → β)` in that order.
53+
This is to enable `calc` support, as `calc` requires that the last two explicit arguments are `u v`.
54+
5055
-/
5156

5257
namespace asymptotics
@@ -60,9 +65,9 @@ variables {α β : Type*} [normed_group β]
6065

6166
/-- Two functions `u` and `v` are said to be asymptotically equivalent along a filter `l` when
6267
`u x - v x = o(v x)` as x converges along `l`. -/
63-
def is_equivalent (u v : α → β) (l : filter α) := is_o (u - v) v l
68+
def is_equivalent (l : filter α) (u v : α → β) := is_o (u - v) v l
6469

65-
localized "notation u ` ~[`:50 l:50 `] `:0 v:50 := asymptotics.is_equivalent u v l" in asymptotics
70+
localized "notation u ` ~[`:50 l:50 `] `:0 v:50 := asymptotics.is_equivalent l u v" in asymptotics
6671

6772
variables {u v w : α → β} {l : filter α}
6873

@@ -87,7 +92,8 @@ end
8792
@[symm] lemma is_equivalent.symm (h : u ~[l] v) : v ~[l] u :=
8893
(h.is_o.trans_is_O h.is_O_symm).symm
8994

90-
@[trans] lemma is_equivalent.trans (huv : u ~[l] v) (hvw : v ~[l] w) : u ~[l] w :=
95+
@[trans] lemma is_equivalent.trans {l : filter α} {u v w : α → β}
96+
(huv : u ~[l] v) (hvw : v ~[l] w) : u ~[l] w :=
9197
(huv.is_o.trans_is_O hvw.is_O).triangle hvw.is_o
9298

9399
lemma is_equivalent.congr_left {u v w : α → β} {l : filter α} (huv : u ~[l] v)

src/analysis/convex/extreme.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ is_extreme.refl 𝕜 A
7171
@[trans] protected lemma is_extreme.trans (hAB : is_extreme 𝕜 A B) (hBC : is_extreme 𝕜 B C) :
7272
is_extreme 𝕜 A C :=
7373
begin
74-
use subset.trans hBC.1 hAB.1,
75-
rintro x₁ hx₁A x₂ hx₂A x hxC hx,
74+
refine ⟨subset.trans hBC.1 hAB.1, λ x₁ hx₁A x₂ hx₂A x hxC hx, _⟩,
7675
obtain ⟨hx₁B, hx₂B⟩ := hAB.2 x₁ hx₁A x₂ hx₂A x (hBC.1 hxC) hx,
7776
exact hBC.2 x₁ hx₁B x₂ hx₂B x hxC hx,
7877
end

src/analysis/special_functions/polynomials.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ lemma is_equivalent_at_top_lead :
4343
begin
4444
by_cases h : P = 0,
4545
{ simp [h] },
46-
{ conv_lhs
46+
{ conv_rhs
4747
{ funext,
4848
rw [polynomial.eval_eq_sum_range, sum_range_succ] },
4949
exact is_equivalent.refl.add_is_o (is_o.sum $ λ i hi, is_o.const_mul_left

src/combinatorics/colex.lean

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,20 @@ instance [has_lt α] : is_irrefl (finset.colex α) (<) :=
131131
⟨λ A h, exists.elim h (λ _ ⟨_,a,b⟩, a b)⟩
132132

133133
@[trans]
134-
lemma lt_trans [linear_order α] {a b c : finset.colex α} :
135-
a < b → b < c → a < c :=
134+
lemma lt_trans [linear_order α] {a b c : finset.colex α} : a < b → b < c → a < c :=
136135
begin
137136
rintros ⟨k₁, k₁z, notinA, inB⟩ ⟨k₂, k₂z, notinB, inC⟩,
138137
cases lt_or_gt_of_ne (ne_of_mem_of_not_mem inB notinB),
139-
{ refine ⟨k₂, _, by rwa k₁z h, inC⟩,
140-
intros x hx,
138+
{ refine ⟨k₂, λ x hx, _, by rwa k₁z h, inC⟩,
141139
rw ← k₂z hx,
142140
apply k₁z (trans h hx) },
143-
{ refine ⟨k₁, _, notinA, by rwa ← k₂z h⟩,
144-
intros x hx,
141+
{ refine ⟨k₁, λ x hx, _, notinA, by rwa ← k₂z h⟩,
145142
rw k₁z hx,
146143
apply k₂z (trans h hx) }
147144
end
148145

149146
@[trans]
150-
lemma le_trans [linear_order α] (a b c : finset.colex α) :
151-
a ≤ b → b ≤ c → a ≤ c :=
147+
lemma le_trans [linear_order α] (a b c : finset.colex α) : a ≤ b → b ≤ c → a ≤ c :=
152148
λ AB BC, AB.elim (λ k, BC.elim (λ t, or.inl (lt_trans k t)) (λ t, t ▸ AB)) (λ k, k.symm ▸ BC)
153149

154150
instance [linear_order α] : is_trans (finset.colex α) (<) := ⟨λ _ _ _, colex.lt_trans⟩

src/computability/tm_computable.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ structure evals_to {σ : Type*} (f : σ → option σ) (a : σ) (b : option σ)
9292
(steps : ℕ)
9393
(evals_in_steps : ((flip bind f)^[steps] a) = b)
9494

95+
-- note: this cannot currently be used in `calc`, as the last two arguments must be `a` and `b`.
96+
-- If this is desired, this argument order can be changed, but this spelling is I think the most
97+
-- natural, so there is a trade-off that needs to be made here. A notation can get around this.
9598
/-- A "proof" of the fact that `f` eventually reaches `b` in at most `m` steps when repeatedly
9699
evaluated on `a`, remembering the number of steps it takes. -/
97100
structure evals_to_in_time {σ : Type*} (f : σ → option σ) (a : σ) (b : option σ) (m : ℕ)
@@ -113,8 +116,8 @@ structure evals_to_in_time {σ : Type*} (f : σ → option σ) (a : σ) (b : opt
113116
⟨evals_to.refl f a, le_refl 0
114117

115118
/-- Transitivity of `evals_to_in_time` in the sum of the numbers of steps. -/
116-
@[trans] def evals_to_in_time.trans {σ : Type*} (f : σ → option σ) (a : σ) (b : σ) (c : option σ)
117-
(m₁ : ) (m₂ : ) (h₁ : evals_to_in_time f a b m₁) (h₂ : evals_to_in_time f b c m₂) :
119+
@[trans] def evals_to_in_time.trans {σ : Type*} (f : σ → option σ) (m₁ : ) (m₂ : )
120+
(a : σ) (b : σ) (c : option σ) (h₁ : evals_to_in_time f a b m₁) (h₂ : evals_to_in_time f b c m₂) :
118121
evals_to_in_time f a c (m₂ + m₁) :=
119122
⟨evals_to.trans f a b c h₁.to_evals_to h₂.to_evals_to, add_le_add h₂.steps_le_m h₁.steps_le_m⟩
120123

src/computability/turing_machine.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def blank_extends {Γ} [inhabited Γ] (l₁ l₂ : list Γ) : Prop :=
7171

7272
@[trans] theorem blank_extends.trans {Γ} [inhabited Γ] {l₁ l₂ l₃ : list Γ} :
7373
blank_extends l₁ l₂ → blank_extends l₂ l₃ → blank_extends l₁ l₃ :=
74-
by rintro ⟨i, rfl⟩ ⟨j, rfl⟩; exact ⟨i+j, by simp [list.repeat_add]⟩
74+
by { rintro ⟨i, rfl⟩ ⟨j, rfl⟩, exact ⟨i+j, by simp [list.repeat_add]⟩ }
7575

7676
theorem blank_extends.below_of_le {Γ} [inhabited Γ] {l l₁ l₂ : list Γ} :
7777
blank_extends l l₁ → blank_extends l l₂ →

src/data/list/rotate.lean

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,8 @@ lemma is_rotated_comm : l ~r l' ↔ l' ~r l :=
368368
@[simp] protected lemma is_rotated.forall (l : list α) (n : ℕ) : l.rotate n ~r l :=
369369
is_rotated.symm ⟨n, rfl⟩
370370

371-
@[trans] lemma is_rotated.trans {l'' : list α} (h : l ~r l') (h' : l' ~r l'') :
372-
l ~r l'' :=
373-
begin
374-
obtain ⟨n, rfl⟩ := h,
375-
obtain ⟨m, rfl⟩ := h',
376-
rw rotate_rotate,
377-
use (n + m)
378-
end
371+
@[trans] lemma is_rotated.trans : ∀ {l l' l'' : list α}, l ~r l' → l' ~r l'' → l ~r l''
372+
| _ _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ := ⟨n + m, by rw [rotate_rotate]⟩
379373

380374
lemma is_rotated.eqv : equivalence (@is_rotated α) :=
381375
mk_equivalence _ is_rotated.refl (λ _ _, is_rotated.symm) (λ _ _ _, is_rotated.trans)

src/data/set/basic.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ funext (assume x, propext (h x))
177177
theorem ext_iff {s t : set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t :=
178178
⟨λ h x, by rw h, ext⟩
179179

180-
@[trans] theorem mem_of_mem_of_subset {x : α} {s t : set α}
181-
(hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx
180+
@[trans] theorem mem_of_mem_of_subset {x : α} {s t : set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx
182181

183182
lemma forall_in_swap {p : α → β → Prop} :
184183
(∀ (a ∈ s) b, p a b) ↔ ∀ b (a ∈ s), p a b :=
@@ -228,8 +227,7 @@ lemma ssubset_def : s ⊂ t = (s ⊆ t ∧ ¬ t ⊆ s) := rfl
228227
@[refl] theorem subset.refl (a : set α) : a ⊆ a := assume x, id
229228
theorem subset.rfl {s : set α} : s ⊆ s := subset.refl s
230229

231-
@[trans] theorem subset.trans {a b c : set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c :=
232-
assume x h, bc (ab h)
230+
@[trans] theorem subset.trans {a b c : set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := λ x h, bc $ ab h
233231

234232
@[trans] theorem mem_of_eq_of_mem {x y : α} {s : set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
235233
hx.symm ▸ h

src/data/sym/sym2.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ attribute [refl] rel.refl
6060
@[symm] lemma rel.symm {x y : α × α} : rel α x y → rel α y x :=
6161
by rintro ⟨_, _⟩; constructor
6262

63-
@[trans] lemma rel.trans {x y z : α × α} : rel α x yrel α y z rel α x z :=
64-
by { intros a b, cases_matching* rel _ _ _; apply rel.refl <|> apply rel.swap }
63+
@[trans] lemma rel.trans {x y z : α × α} (a : rel α x y) (b : rel α y z) : rel α x z :=
64+
by { cases_matching* rel _ _ _; apply rel.refl <|> apply rel.swap }
6565

6666
lemma rel.is_equivalence : equivalence (rel α) := by tidy; apply rel.trans; assumption
6767

0 commit comments

Comments
 (0)