Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update examples to work with latest Lean nightly #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions axioms_and_computation.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ private theorem mem_swap {a : α} :
private theorem mem_respects
: {p₁ p₂ : α × α} → (a : α) → p₁ ~ p₂ → mem_fn a p₁ = mem_fn a p₂
| (a₁, a₂), (b₁, b₂), a, Or.inl ⟨a₁b₁, a₂b₂⟩ => by simp_all
| (a₁, a₂), (b₁, b₂), a, Or.inr ⟨a₁b₂, a₂b₁⟩ => by simp_all; apply mem_swap
| (a₁, a₂), (b₁, b₂), a, Or.inr ⟨a₁b₂, a₂b₁⟩ => by simp_all; rw [mem_swap]

def mem (a : α) (u : UProd α) : Prop :=
Quot.liftOn u (fun p => mem_fn a p) (fun p₁ p₂ e => mem_respects a e)
Expand Down Expand Up @@ -1100,10 +1100,11 @@ theorem linv_comp_self {f : α → β} [Inhabited α]
have ex : ∃ a₁ : α, f a₁ = f a := ⟨a, rfl⟩
have feq : f (choose ex) = f a := choose_spec ex
calc linv f (f a)
_ = choose ex := dif_pos ex
_ = choose ex := by simp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an error where dif_pos's implicit arguments were not being found (namely the Decidable instance and the else branch). This lemma is really designed to be used with simp rather than directly, and simp solves the goal.

_ = a := inj feq
```


From a classical point of view, ``linv`` is a function. From a
constructive point of view, it is unacceptable; because there is no
way to implement such a function in general, the construction is not
Expand Down
4 changes: 2 additions & 2 deletions propositions_and_proofs.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ constant of such a type.
# proof : p
#check Proof -- Proof : Prop → Type

axiom and_comm (p q : Prop) : Proof (Implies (And p q) (And q p))
axiom and_commutative (p q : Prop) : Proof (Implies (And p q) (And q p))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have and_comm in scope by default. I chose to rename it here, rather than secretly stick it in a namespace, because I want code bits to work if people type them in.

On the other hand, the hidden Proof structure is not present, so this is a very weak argument for this solution. Happy to do the other one if you'd prefer.


variable (p q : Prop)
#check and_comm p q -- Proof (Implies (And p q) (And q p))
#check and_commutative p q -- Proof (Implies (And p q) (And q p))
```

In addition to axioms, however, we would also need rules to build new
Expand Down
28 changes: 9 additions & 19 deletions quantifiers_and_equality.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,40 +477,30 @@ of the `Trans` type class. Type classes are introduced later, but the following
small example demonstrates how to extend the `calc` notation using new `Trans` instances.

```lean
def divides (x y : Nat) : Prop :=
def Divides (x y : Nat) : Prop :=
∃ k, k*x = y

def divides_trans (h₁ : divides x y) (h₂ : divides y z) : divides x z :=
def Divides_trans (h₁ : Divides x y) (h₂ : Divides y z) : Divides x z :=
let ⟨k₁, d₁⟩ := h₁
let ⟨k₂, d₂⟩ := h₂
⟨k₁ * k₂, by rw [Nat.mul_comm k₁ k₂, Nat.mul_assoc, d₁, d₂]⟩

def divides_mul (x : Nat) (k : Nat) : divides x (k*x) :=
def Divides_mul (x : Nat) (k : Nat) : Divides x (k*x) :=
⟨k, rfl⟩

instance : Trans divides divides divides where
trans := divides_trans
instance : Trans Divides Divides Divides where
trans := Divides_trans

example (h₁ : divides x y) (h₂ : y = z) : divides x (2*z) :=
example (h₁ : Divides x y) (h₂ : y = z) : Divides x (2*z) :=
calc
divides x y := h₁
Divides x y := h₁
_ = z := h₂
divides _ (2*z) := divides_mul ..
Divides _ (2*z) := Divides_mul ..
Comment on lines +480 to +498
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a rename to more closely follow Lean 4 conventions while I was here


infix:50 " ∣ " => divides

example (h₁ : divides x y) (h₂ : y = z) : divides x (2*z) :=
calc
x ∣ y := h₁
_ = z := h₂
_ ∣ 2*z := divides_mul ..
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This notation is now built-in, and they were conflicting. It didn't seem to be worth a longer aside in the text to save this, so I deleted it.

```

The example above also makes it clear that you can use `calc` even if you
do not have an infix notation for your relation. Finally we remark that
the vertical bar `∣` in the example above is the unicode one. We use
unicode to make sure we do not overload the ASCII `|` used in the
`match .. with` expression.
do not have an infix notation for your relation.

With ``calc``, we can write the proof in the last section in a more
natural and perspicuous way.
Expand Down
Loading