reorganise world Implication
parent
966db8a159
commit
420f913e69
@ -0,0 +1,12 @@
|
||||
import TestGame.Levels.Implication.L01_Intro
|
||||
import TestGame.Levels.Implication.L02_Revert
|
||||
import TestGame.Levels.Implication.L03_Apply
|
||||
import TestGame.Levels.Implication.L04_Apply
|
||||
import TestGame.Levels.Implication.L05_Apply
|
||||
import TestGame.Levels.Implication.L06_Iff
|
||||
import TestGame.Levels.Implication.L07_Rw
|
||||
import TestGame.Levels.Implication.L08_Iff
|
||||
import TestGame.Levels.Implication.L09_Iff
|
||||
import TestGame.Levels.Implication.L10_Apply
|
||||
import TestGame.Levels.Implication.L11_Rw
|
||||
import TestGame.Levels.Implication.L12_Summary
|
||||
@ -0,0 +1,40 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
set_option tactic.hygienic false
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 1
|
||||
|
||||
Title "Intro"
|
||||
|
||||
Introduction
|
||||
"
|
||||
## Implikationen
|
||||
|
||||
In diesem Kapitel lernst du Implikation ($\\Rightarrow$) und Genau-dann-wenn
|
||||
($\\Leftrightarrow$) kennen.
|
||||
Dazu lernst du, wie man bereits bewiesene Sätze verwendet.
|
||||
|
||||
Seien `(A B : Prop)` zwei logische Aussagen. Eine Implikation $A \\Rightarrow B$ schreibt
|
||||
man in Lean als `A → B` (`\\to`).
|
||||
|
||||
Wenn das Goal eine Implikation $A \\Rightarrow B$ ist, kann man mit
|
||||
`intro ha` annehmen, dass $A$ wahr ist. Dann muss man $B$ beweisen.
|
||||
"
|
||||
|
||||
Statement
|
||||
"Wenn $B$ wahr ist, dann ist die Implikation $A \\Rightarrow (A ∧ B)$ wahr."
|
||||
(A B : Prop) (hb : B) : A → (A ∧ B) := by
|
||||
intro hA
|
||||
constructor
|
||||
assumption
|
||||
assumption
|
||||
|
||||
Hint (A : Prop) (B : Prop) (hb : B) : A → (A ∧ B) =>
|
||||
"Mit `intro ha` kann man annehmen, dass $A$ wahr ist. danach muss man $A \\land B$ zeigen."
|
||||
|
||||
Message (A : Prop) (B : Prop) (ha : A) (hb : B) : (A ∧ B) =>
|
||||
"Jetzt kannst du die Taktiken aus dem letzten Kapitel verwenden."
|
||||
|
||||
Tactics intro constructor assumption
|
||||
@ -0,0 +1,42 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
set_option tactic.hygienic false
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 2
|
||||
|
||||
Title "Revert"
|
||||
|
||||
Introduction
|
||||
"
|
||||
Mit `intro` kann man also eine Implikation aus dem Goal entfernen, indem man
|
||||
die Implikationsprämisse zu den *Annahmen* hinzufügt:
|
||||
|
||||
```
|
||||
example : A → B :=
|
||||
[Beweis]
|
||||
```
|
||||
|
||||
wird zu
|
||||
|
||||
```
|
||||
example (ha : A) : B :=
|
||||
[Beweis]
|
||||
```
|
||||
|
||||
Seltener kann auch die andere Richtung nützlich sein. Mit `revert ha` kann man die Annahme
|
||||
`ha` entfernen und als Implikationsprämisse vor's Goal hängen.
|
||||
"
|
||||
|
||||
Statement
|
||||
"Angenommen $A$ ist eine wahre Aussage und man hat eine Implikation $A \\Rightarrow B$, zeige
|
||||
dass $B$ wahr ist."
|
||||
(A B : Prop) (ha : A) (h : A → B) : B := by
|
||||
revert ha
|
||||
assumption
|
||||
|
||||
Hint (A : Prop) (B : Prop) (ha : A) (h : A → B): B =>
|
||||
"Mit `revert ha` kann man die Annahme `ha` als Implikationsprämisse vorne ans Goal anhängen."
|
||||
|
||||
Tactics revert assumption
|
||||
@ -0,0 +1,74 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
import Init.Data.ToString
|
||||
-- #check List UInt8
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 7
|
||||
|
||||
Title "Genau dann wenn"
|
||||
|
||||
Introduction
|
||||
"
|
||||
Hat man ein `(h : A ↔ B)` in den Annahmen, hat man die gleichen beiden Optionen wie beim
|
||||
logischen UND plus noch eine neue:
|
||||
|
||||
1. Mit `h.mp` und `h.mpr` (oder `h.1` und `h.2`) kann man die einzelnen Implikationen
|
||||
direkt auswählen.
|
||||
2. Mit `rcases h with ⟨h₁, h₂⟩` könnte man die Struktur `h` zerlegen und man erhält zwei
|
||||
separate Annahmen `(h₁ : A → B)` und `(h₂ : B → A)`
|
||||
3. **Mit** `rw [h]` **kann man im Goal `A` durch `B` ersetzen.**
|
||||
|
||||
Wir widmen uns zuerst `rw`. Dies steht für \"rewrite\". Da $A$ und $B$ logisch äquivalent
|
||||
sind, kann man beliebig das eine mit dem anderen vertauschen.
|
||||
`rw [h]` ersetzt $A$ durch $B$.
|
||||
Dabei gibt es noch einige Tricks:
|
||||
|
||||
- `rw [← h]` ersetzt umgekehrt $B$ durch $A$ (`\\l`, kleines L).
|
||||
- `rw [h, g]` ist das gleiche wie `rw [h]` gefolgt von `rw [g]`.
|
||||
"
|
||||
|
||||
Statement
|
||||
"Zeige dass `B ↔ C`."
|
||||
(A B C D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ C := by
|
||||
rw [h₁]
|
||||
rw [←h₂]
|
||||
assumption
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ C =>
|
||||
"Im Goal kommt `C` vor und `h₁` sagt `C ↔ D`.
|
||||
Probiers doch mit `rw [h₁]`."
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : A ↔ C =>
|
||||
"Im Goal kommt `C` vor und `h₁` sagt `C ↔ D`.
|
||||
Probiers doch mit `rw [h₁]`."
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ D =>
|
||||
"Man kann auch rückwärts umschreiben:
|
||||
`rw [←h₂]` ersetzt man im Goal `B` durch `a` (`\\l`, also ein kleines L)"
|
||||
|
||||
Hint (A : Prop) (B : Prop) (h : A ↔ B) : A ↔ B =>
|
||||
"Schau mal durch die Annahmen durch."
|
||||
|
||||
|
||||
-- These should not be necessary if they don't use `rw [] at`.
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ C) : B ↔ C =>
|
||||
"Auch eine Möglichkeit... Kannst du das Goal so umschreiben,
|
||||
dass es mit einer Annahme übereinstimmt?"
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : B ↔ D) : B ↔ C =>
|
||||
"Auch eine Möglichkeit.. Kannst du das Goal so umschreiben, dass es mit einer Annahme übereinstimmt?"
|
||||
|
||||
Message (A : Prop) (B : Prop) (h : B ↔ A) : A ↔ B =>
|
||||
"Naja auch Umwege führen ans Ziel... Wenn du das Goal zu `A ↔ A` umschreibst, kann man es mit
|
||||
`rfl` beweisen (rsp. das passiert automatisch.)"
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : D ↔ B) (h₃ : D ↔ A) : B ↔ C =>
|
||||
"Das ist nicht der optimale Weg..."
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : D ↔ B) (h₃ : A ↔ D) : B ↔ C =>
|
||||
"Das ist nicht der optimale Weg..."
|
||||
|
||||
|
||||
Tactics rw assumption
|
||||
@ -0,0 +1,44 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
set_option tactic.hygienic false
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 8
|
||||
|
||||
Title "Genau dann wenn"
|
||||
|
||||
Introduction
|
||||
"
|
||||
Nun schauen wir uns Option 1) an, die du schon von UND kennst:
|
||||
|
||||
1. Mit `h.mp` und `h.mpr` (oder `h.1` und `h.2`) kann man die einzelnen Implikationen
|
||||
direkt auswählen.
|
||||
|
||||
`h.mp` und `h.mpr` (oder `h.1` und `h.2`) sind die einzelnen Implikationen, und du kannst
|
||||
mit denen ensprechend arbeiten. Insbesondere kannst du mit `apply h.mp` die Implikation
|
||||
$A \\Rightarrow B$ anwenden, wenn das Goal $B$ ist.
|
||||
|
||||
*(PS: das `.mp` kommt von \"Modus Ponens\", ein Ausdruck as der Logik.)*
|
||||
"
|
||||
|
||||
Statement
|
||||
"Angenommen man hat $A \\iff B$ und $B \\Rightarrow C$, zeige $A \\Rightarrow C$."
|
||||
(A B C : Prop) (h : A ↔ B) (g : B → C) : A → C := by
|
||||
intro hA
|
||||
apply g
|
||||
apply h.mp
|
||||
assumption
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) : A → C =>
|
||||
"Fange wie immer mit `intro` an."
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) (hA : A) : C =>
|
||||
"Wie im Implikationen-Level kannst du nun `apply` verwenden."
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) (hA : A) : B =>
|
||||
"Mit `apply h.mp` kannst du nun die Implikation `A → B` anwenden."
|
||||
|
||||
Conclusion "Im nächsten Level findest du die zweite Option."
|
||||
|
||||
Tactics apply assumption
|
||||
@ -1,27 +0,0 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
Game "TestGame"
|
||||
World "Predicate"
|
||||
Level 6
|
||||
|
||||
Title "Definitionally equal"
|
||||
|
||||
Introduction
|
||||
"
|
||||
**Vorsicht:** `rfl` kann auch Gleichungen beweisen, wenn die beiden Terme Lean-intern gleich
|
||||
definiert sind, auch wenn diese unterschiedlich dargestellt werden. Das kann anfänglich
|
||||
zu Verwirrung führen.
|
||||
|
||||
So ist `2` als `1 + 1` definiert, deshalb funktioniert `rfl` auch hier.
|
||||
"
|
||||
|
||||
Statement "Zeige dass $1 + 1$ zwei ist." : 1 + 1 = 2 := by
|
||||
rfl
|
||||
|
||||
Conclusion
|
||||
"
|
||||
**Notiz:** Die meisten anderen Taktiken versuchen am Schluss automatisch `rfl`
|
||||
aufzurufen, deshalb brauchst du das nur noch selten.
|
||||
"
|
||||
|
||||
Tactics rfl
|
||||
@ -1,44 +0,0 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
import Init.Data.ToString
|
||||
-- #check List UInt8
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 6
|
||||
|
||||
Title "Genau dann wenn"
|
||||
|
||||
Introduction
|
||||
"
|
||||
Genau-dann-wenn, $A \\iff B$, wird als `A ↔ B (`\\iff`) geschrieben.
|
||||
|
||||
Als erstes kann man mit `rw` Annahmen der Form `(h : A ↔ B)` genau gleich wie Gleichungen
|
||||
`(h : a = b)` benützen, um das Goal umzuschreiben.
|
||||
|
||||
Hier also nochmals die Gleiche Aufgabe wie zuvor,
|
||||
aber diesmal mit Iff-Statements von Aussagen anstatt
|
||||
Gleichungen von natürlichen Zahlen.
|
||||
"
|
||||
|
||||
Statement
|
||||
"Zeige dass `B ↔ C`."
|
||||
(A B C D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ C := by
|
||||
rw [h₁]
|
||||
rw [←h₂]
|
||||
assumption
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ C =>
|
||||
"Im Goal kommt `C` vor und `h₁` sagt `C ↔ D`.
|
||||
Probiers doch mit `rw [h₁]`."
|
||||
|
||||
Hint (A : Prop) (B : Prop) (C : Prop) (D : Prop) (h₁ : C ↔ D) (h₂ : A ↔ B) (h₃ : A ↔ D) : B ↔ D =>
|
||||
"Zur Erinnerung: Man kann auch rückwärts umschreiben: `h₂` sagt `A ↔ b` mit
|
||||
`rw [←h₂]` ersetzt man im Goal `b` durch `a` (`\\l`, also ein kleines L)"
|
||||
|
||||
Hint (A : Prop) (B : Prop) (h : A ↔ B) : A ↔ B =>
|
||||
"Schau mal durch die Annahmen durch."
|
||||
|
||||
|
||||
|
||||
Tactics rw assumption
|
||||
@ -1,44 +0,0 @@
|
||||
import TestGame.Metadata
|
||||
|
||||
set_option tactic.hygienic false
|
||||
|
||||
Game "TestGame"
|
||||
World "Implication"
|
||||
Level 7
|
||||
|
||||
Title "Genau dann wenn"
|
||||
|
||||
Introduction
|
||||
"
|
||||
Wenn man eine Annahme `(h : A ↔ B)` hat, kann man auch davon die beiden einzelnen
|
||||
Implikationen $\\textrm{mp} : A \\Rightarrow B$ und $\\textrm{mpr} : B \\Rightarrow A$
|
||||
brauchen.
|
||||
|
||||
Dazu gibt es zwei Methoden:
|
||||
|
||||
1.) `h.mp` (oder `h.1`) und `h.mpr` (oder `h.2`) sind direkt die einzelnen Richtungen.
|
||||
Man kann also z.B. mit `apply h.mp` die Implikation `A → B` auf ein Goal `B` anwenden.
|
||||
|
||||
(PS: das `.mp` kommt von \"Modus Ponens\", ein Ausdruck as der Logik.)
|
||||
"
|
||||
|
||||
Statement
|
||||
"Angenommen man hat $A \\iff B$ und $B \\Rightarrow C$, zeige $A \\Rightarrow C$."
|
||||
(A B C : Prop) (h : A ↔ B) (g : B → C) : A → C := by
|
||||
intro hA
|
||||
apply g
|
||||
apply h.mp
|
||||
assumption
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) : A → C =>
|
||||
"Zuerst kannst du wieder `intro` benützen um die Implikation anzugehen."
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) (hA : A) : C =>
|
||||
"Der nächste Schritt kommt auch noch aus dem Implikationen-Level."
|
||||
|
||||
Message (A : Prop) (B : Prop) (C : Prop) (h : A ↔ B) (g : B → C) (hA : A) : B =>
|
||||
"Mit `apply h.mp` kannst du nun die Implikation `A → B` anwenden."
|
||||
|
||||
Conclusion "Im nächsten Level findest du die zweite Option."
|
||||
|
||||
Tactics apply assumption
|
||||
@ -0,0 +1 @@
|
||||
import TestGame.Levels.Predicate.L01_Ring
|
||||
Loading…
Reference in New Issue