Chapter 2 · Logic

And, or

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 22 · Concept

p ∧ q needs a proof of each

In this lesson you prove "and" and "or", and use them as hypotheses. Some proofs have two goals at once.

p ∧ q means p and q: it holds when both hold. Type ∧ as \and, or /\ in ASCII.

On the goal p ∧ q, constructor leaves two goals: case left with ⊢ p, then case right with ⊢ q.

theorem both (p q : Prop) (hp : p) (hq : q) : p ∧ q := by
  constructor
  · exact hp
  · exact hq
#print both
theorem both_again (p q : Prop) (h : p ∧ q) : p ∧ q := by
  obtain ⟨hp, hq⟩ := h
  exact ⟨hp, hq⟩
theorem and_swap (p q : Prop) (h : p ∧ q) : q ∧ p := by
  exact ⟨h.1, h.2⟩
theorem pick (p q r : Prop) (h : p ∧ q) (hr : r) : r ∧ p := by
  sorry
theorem or_swap (p q : Prop) : p ∨ q → q ∨ p := by
  intro h
  cases h with
  | inl hp =>
    right
    exact hp
  | inr hq =>
    left
    exact hq
theorem either (p q r : Prop) (hpr : p → r) (hqr : q → r)
    (h : p ∨ q) : r := by
  sorry
example (p q : Prop) (h : p ∨ (p ∧ q)) : p ∨ p ∧ q := by
  exact h
theorem mix (p q : Prop) (h : p ∨ p ∧ q) : p := by
  sorry
theorem distrib (p q r : Prop) :
    p ∧ (q ∨ r) → p ∧ q ∨ p ∧ r := by
  sorry
theorem three (p q r : Prop) : p ∨ q ∨ r → r ∨ q ∨ p := by
  sorry
Terminal
Step 1 of 10See both goals closed

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)