You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Game.lean
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,13 @@ import Game.Levels.AndIntro
8
8
import Game.Levels.ImpIntro
9
9
import Game.Levels.NotIntro
10
10
import Game.Levels.OrIntro
11
+
import Game.Levels.IffIntro
11
12
12
13
-- Here's where we show how to glue the worlds together
13
14
Dependency AndIntro → ImpIntro
14
15
Dependency ImpIntro → NotIntro
15
-
16
+
Dependency ImpIntro → OrIntro
17
+
Dependency ImpIntro → IffIntro
16
18
17
19
-- Here's what we'll put on the title screen
18
20
Title "A Lean Intro to Logic"
@@ -26,16 +28,16 @@ To play this puzzler you'll need to learn some notation. Unlike learning how to
26
28
Below, you're provided with whirlwind tour of the notation at play as well as a bit of motivation for why the notation looks the way it does. This is all done through a single example. Many of the details will seem lacking; The concepts covered here will be addressed with more detail during the tutorial worlds of this game.
27
29
28
30
# But first, a tip!
29
-
This introduction as well as some of the tutotial levels can get a bit wordy. The three column panels — text on the left, game worlds in the middle, and your inventory on the right — can all be expanded or shrunk as nesesary. Every screen is different, so do feel encouraged to re-size these pannels.
31
+
This introduction as well as some of the tutorial levels can get a bit wordy. The three column panels — text on the left, game worlds in the middle, and your inventory on the right — can all be expanded or shrunk as necessary. Every screen is different, so do feel encouraged to re-size these panels.
30
32
31
33
# Building some notation
32
34
Consider the following argument stated in natural language:
33
35
34
-
\"Either cat fur or dog fur was found at the scene of the crime. If dog fur was found at the scene of the crime, officer Thompson had an allergy attack. If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. But officer Thompson didn’t have an allergy attack, and so therefore Macavity must be responsible for the crime.\"
36
+
“Either cat fur or dog fur was found at the scene of the crime. If dog fur was found at the scene of the crime, Officer Thompson had an allergy attack. If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. But Officer Thompson didn’t have an allergy attack, and so therefore Macavity must be responsible for the crime.” [¹]
35
37
36
38
Does this argument convince you? The validity of this argument can be made more obvious by representing the chain of reasoning leading from the premises to the conclusion:
37
39
1. Either cat fur was found at the scene of the crime, or dog fur was found at the scene of the crime. (Premise)
38
-
2. If dog fur was found at the scene of the crime, then officer Thompson had an allergy attack. (Premise)
40
+
2. If dog fur was found at the scene of the crime, then Officer Thompson had an allergy attack. (Premise)
39
41
3. If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. (Premise)
40
42
4. Officer Thompson did not have an allergy attack. (Premise)
41
43
5. Dog fur was not found at the scene of the crime. (Follows from 2 and 4)
@@ -48,7 +50,7 @@ If you take a moment to re-read them again, lines 5, 6, & 7 are all slightly dif
48
50
- Line 6 is using the process of elimination on two options. This is the style of reasoning responsible for Sherlock Holmes' most famous quote — \"When you have eliminated the impossible, whatever remains, however improbable, must be the truth\". We'll give this a name too: **modus tollendo ponens**
49
51
- Line 7 is the conclusion and is applying the \"if ... then ...\" statement on line 3. We'll call this one **modus ponens**.
50
52
51
-
We won't always be denoting these with latin names, but the general process of being able to give some generically useful deductive reasoning a name is nice. It makes them easier to reference. During the course of this game some of your proofs will be given names and correspondingly unlocked in your inventory. Thus names are a way to avoid proving the same thing over and over again.
53
+
We won't always be denoting these with Latin names, but the general process of being able to give some generically useful deductive reasoning a name is nice. It makes them easier to reference. During the course of this game some of your proofs will be given names and correspondingly unlocked in your inventory. Thus names are a way to avoid proving the same thing over and over again.
52
54
53
55
# Propositions
54
56
If we separate out the 4 true/false statements required for our line of reasoning and introduce some connectives, we can see the exact same argument in a more concise form. The numbers 1 - 7 here are meant to match exactly with the natural language above.
@@ -114,6 +116,10 @@ To introduce new evidence — such as `h₅` — you need to write out an expres
114
116
In this game, each level will ask you to provide evidence of some proposition. This will often involve using the evidence you already have in some way.
115
117
116
118
Click on the first world — **Party Invites** — to get started.
119
+
120
+
----
121
+
122
+
[¹]Logic example taken from [IEP](https://iep.utm.edu/propositional-logic-sentential-logic/#H5) entry: *Propositional Logic*.
117
123
"
118
124
119
125
Info "
@@ -123,9 +129,9 @@ Info "
123
129
124
130
This game is currently in its initial development phase, designed to be largely self-contained and accessible without requiring a programming or math background to navigate. Feedback about meeting that goal is welcome!
125
131
126
-
While self-contained; in many ways, this game is targeted more at programmers than mathematicians. It doesn't use classical reasoning, sticking instead to constructive logic.The emphasis for most of the theorem proving is on writting proof terms — rather than using tactics. In fact, logic proof automation is such that the tactic **`tauto`**can solve any propositional logic theorem (Though possible, that's an NP-Complete problem).
132
+
While self-contained; in many ways, this game is targeted more at programmers than mathematicians. It doesn't use classical reasoning, sticking instead to constructive logic.The emphasis for most of the theorem proving is on writing proof terms — rather than using tactics. In fact, logic proof automation is such that if you use the tactic **`tauto`**, you can prove any propositional logic theorem.
127
133
128
-
The main thrust of this game is to create puzzles that are fun to think through on your own. I can write a simple algorithm that solves every proper Sudoku. Yet, when I spend a train-ride scribbling numbers into boxes in my sudoku book, I never lament how much faster my phone's CPU could do the job.
134
+
Constructive propositional logic is effectively decidable, in the sense that a finite constructive process applies uniformly to every propositional formula, either producing a proof of the formula or demonstrating that no such proof can exist. The fun is in thinking your way through a puzzle with the tools made available to you.
129
135
130
136
Please feel encouraged to visit the game's GitHub repository and initiate a discussion on any topic regarding this game. Just open a new issue or comment on an existing one.
131
137
Github: [A Lean Intro to Logic](https://github.com/Trequetrum/lean4game-logic)
Copy file name to clipboardExpand all lines: Game/Doc/Lemmas.lean
+26-1Lines changed: 26 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,17 @@ have h : A ∧ B := and_intro a b
19
19
have h : A ∧ B := modus_ponens (modus_ponens and_intro a) b
20
20
```
21
21
22
-
You should never use this lemma and just use function application instead as that will generally be clearer.
22
+
You should never use this style of prefix `modus_ponens` and just use function application instead as that will generally be clearer.
23
+
24
+
----
25
+
# Infix Modus Ponens
26
+
There is are infix operators for function application; they look like `|>` and `<|`. `f <| x`, and `x |> f` means the same as the same as `f x`.
27
+
28
+
`<|` parses `x` with lower precedence, which means that `f <| g $ <|` is interpreted as `(f (g x))` rather than `((f g) x)`.
29
+
30
+
It's twin, `|>` chains such that x |> f |> g is interpreted as g (f x).
31
+
32
+
What makes the infix operators usefull is that they can often replace a pair of brackets `(...)` making expressions easier to read.
23
33
"
24
34
25
35
defand_comm {P Q : Prop}: P ∧ Q ↔ Q ∧ P :=
@@ -83,14 +93,26 @@ example {P Q R : Prop}: P ∨ Q ∨ R ↔ (P ∨ Q) ∨ R := by
83
93
exact ⟨mp,mpr⟩
84
94
85
95
defimp_trans {P Q R : Prop} (hpq : P → Q) (hqr : Q → R) (p : P): R := hqr (hpq p)
96
+
86
97
LemmaDoc imp_trans as "imp_trans"in"→""
87
98
# → is transitive
88
99
`P → Q` and `Q → R` implies `P → R`
89
100
```
90
101
imp_trans : (P → Q) → (Q → R) → P → R
91
102
```
103
+
104
+
Of course, because of `and_comm`, you know you can flip this around too.
105
+
`Q → R` and `P → Q` implies `P → R` has a near-identical proof.
106
+
107
+
### Infix Operator:
108
+
`imp_trans` has an infix operator. This looks like `≫` (which is written as “`\\gg`”).
109
+
110
+
For the math-inclined, because the expression for an implication is a function, you can also use function composition for the same purpose (`∘` is written as “`\\o`”). Just remember that `∘` has the parameters swapped from the way `imp_trans` is defined.
92
111
"
93
112
113
+
infixl:85" ≫ " => λa b ↦ Function.comp b a -- type as \gg
114
+
115
+
94
116
defnot_not_not {P : Prop}: ¬¬¬P ↔ ¬P := ⟨
95
117
(λh p ↦ h (λnp ↦ np p)),
96
118
(λh np ↦ np h)
@@ -114,6 +136,9 @@ Therefore, not P.
114
136
```
115
137
mt : (P → Q) → ¬Q → ¬P
116
138
```
139
+
140
+
### Infix Operator:
141
+
`mt` is a specialized version of `imp_trans`, which makes it possible to use `≫` as an infix operator for `mt`.
Copy file name to clipboardExpand all lines: Game/Doc/Tactics.lean
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@ import GameServer.Commands
2
2
3
3
TacticDoc exact "
4
4
# Summary
5
-
The `exact` tactic is a means through which you give the game your answer. Many levels can be done in multiple steps. You'll use the `have` tactic when you're ready to create the final expression. It will be evaluated to see weather it matches the goal.
5
+
The `exact` tactic is a means through which you give the game your answer. Many levels can be done in multiple steps. You'll use the `exact` tactic when you're ready to create the final expression. It will be evaluated to see weather it matches the goal.
6
6
7
-
`exact` will work with any expression and attempt to unify it with the current goal. The simplest such expression is just a name that — `:` — \"is evidence for\" the goal. More complicated expressions often make use of unlocked definitions and theorems as well as function abstraction and application.
7
+
`exact` will work with any expression and attempt to unify it with the current goal. The simplest such expression is just a name that — `:` — “is evidence for” the goal. More complicated expressions often make use of unlocked definitions and theorems as well as function abstraction and application.
8
8
9
9
# Errors
10
10
Because most of the starting levels use only the `exact` tactic and an expression, it's common to forget to specify the tactic. Sometimes this raises the error:
Copy file name to clipboardExpand all lines: Game/Levels/AndIntro.lean
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ You're hosting your yearly soirée, and it's time to start planning! Last year y
17
17
\\
18
18
This year will be different‼ This year, if you want to be sure that there will be fancy cheeses, you had better have evidence that somebody is bringing the cheese platter.
19
19
20
-
World 1: **Party Invites** is a tutorial world that is meant to introduce you to conjunction — the logical \"and\". The symbol used to denote an \"and\" looks like \"`∧`\". You'll learn to how to use evidence to create an `∧` and how also how to get evidence out when it's been `∧`ed together.\\
20
+
World 1: **Party Invites** is a tutorial world that is meant to introduce you to conjunction — the logical “and”. The symbol used to denote an “and” looks like “`∧`”. You'll learn to how to use evidence to create an `∧` and how also how to get evidence out when it's been `∧`ed together.\\
21
21
\\
22
22
The real-world analogues for evidence of `A ∧ B` might be a box with evidence for `A` and evidence for `B`, an audio recording with both pieces of evidence, or a tree with evidence in its branches.\\
Copy file name to clipboardExpand all lines: Game/Levels/AndIntro/L01.lean
+6-10Lines changed: 6 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,7 @@ You've made a todo list, so you've begun to plan your party. Exhibit evidence th
14
14
## Proposition Key:
15
15
`P` — You're **P**lanning a party
16
16
## Assumptions
17
-
`h : P` — Can be read as `h` is evidence for `P`\\
18
-
\\
19
-
On the one hand, you can think of `h` as a reference to the assumption `P`. On the other hand, given the flavour text above, you can imagine that `h` is the name you've give your todo list (because your todo list is evidence for the proposition that \"You're **P**lanning a party\")
20
-
17
+
`todo_list : P` — Can be read as `todo_list` “is evidence for” `P`\\
21
18
# The Exact Tactic
22
19
The Exact tactic is — for now — the means through which you give the game your answer. It's your way of declaring that you're done. In this level, you're just going to be using one of the premises directly, but as you learn how to form expressions the `exact` tactic will accept those too.\\
23
20
\\
@@ -26,9 +23,9 @@ It's entered like this:
26
23
Goal: P
27
24
exact <<expression that evaluates to evidence for P>>
28
25
```
29
-
You can use the `exact` tactic to give `h` as your answer.\\
26
+
You can use the `exact` tactic to give `todo_list` as your answer.\\
30
27
\\
31
-
⋆Spoilers!⋆ If you enter \"`exact h`\", you will have completed this level.
28
+
⋆Spoilers!⋆ If you enter “`exact todo_list`,” you will have completed this level.
32
29
33
30
# Become Familiar with the User Interface!
34
31
@@ -37,17 +34,16 @@ Found in the middle bottom of the screen, the proof state tells you what objects
37
34
## 1. Objects:
38
35
In this level, you'll notice that there is only one proposition. `P : Prop` is the game's way of telling you that it knows that `P` is a proposition. You can check out the **Proposition Key** above to learn what it's denoting in this level if you're interested.
39
36
## 2. Assumptions:
40
-
You'll notice that you have some evidence too. The shorthand for a proposition traditionally starts with a capital letter and the shorthand for evidence traditionally starts with a lowercase letter.
41
-
1. `h : P` — again, you can read this as `h` is evidence for `P`. If the line said `h : ¬P` instead, then that would be saying that `h` is evidence that you're not planning a party.
37
+
Most levels will give you some starting assumptions that take the form of evidence for some propositions. The shorthand for a proposition traditionally starts with a capital letter and the shorthand for evidence traditionally starts with a lowercase letter.
42
38
## 3. Goal:
43
39
The goal is always a proposition that you want to exhibit some evidence for. In this level, one of your assumptions already contains evidence for the goal. That will certainly not always be the case.
44
40
# Inventory
45
41
On the right of the screen is your inventory of tactics, definitions, and theorems. Once unlocked, you can click them to read about what they do.
46
42
"
47
43
48
44
/-- Exhibit evidence that you're planning a party. -/
49
-
Statement (P : Prop)(h : P) : P := by
50
-
exact h
45
+
Statement (P : Prop)(todo_list : P) : P := by
46
+
exact todo_list
51
47
52
48
Conclusion "
53
49
Congratulations, not only have you started your todo list, you've learned how to exhibit the list as evidence that you've started planning the party.
Copy file name to clipboardExpand all lines: Game/Levels/AndIntro/L02.lean
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -7,25 +7,25 @@ Title "And Introduction"
7
7
NewDefinition and_intro
8
8
9
9
Introduction "
10
-
# Sending out some Invites
11
-
You have two letters, one is an invitation for Paul and one is for Sarah, the two of them live together so you'd like to combine their invites into a single item to be shipped. The box you're putting them in has room for two items, one on the left and one of the right.\\
10
+
# Sending Invitations in a Single Package
11
+
You have two letters, one extending an invitation to Paul and the other to Sarah. Since they share a residence, you'd like to consolidate their invites into a single package for shipping. The box you're using has space for two items, one on the left and one on the right.\\
12
12
\\
13
-
You label the box to say that Paul's invite on the left and Sarah's invite on the right. That way nobody can be confused about what's in the box. Also, once they open the box, they'll know exactly where to look for the invite without needing to check the entire box.
13
+
You've labelled the box explicitly, specifying that Paul's invitation is on the left and Sarah's invitation is on the right. This ensures there's no confusion about the contents of the box. Upon opening it, they will easily locate their respective invites without the need to search the entire package.
14
14
# Proposition Key:
15
-
- P — \"**P**aul is invited to the party\"
16
-
- S — \"**S**arah is invited to the party\"
15
+
- P — “**P**aul is invited to the party”
16
+
- S — “**S**arah is invited to the party”
17
17
# `∧`
18
-
The hat symbol \" ∧ \" is how logicians denote a logical \"and\". `A ∧ B` means \"A and B\". It works the way you would intuitively expect. Like a lot of math operators (like `+,-,÷,×`,and others), the `∧` symbol is an infix operator. This means it has a left side and a right side. Looking at `A ∧ B`, you can see that `A` is on the left and `B` is on the right.\\
18
+
The hat symbol “ ∧ ” is how logicians denote a conjunction — a logical “and”. `A ∧ B` means “A and B”. It works the way you would intuitively expect. Like a lot of math operators (`+,-,÷,×`,and others), the `∧` symbol is an infix operator. This means it has a left side and a right side. Looking at `A ∧ B`, you can see that `A` is on the left and `B` is on the right.\\
19
19
\\
20
20
In this game, that means anything operating as evidence for `A ∧ B` will have a left part and a right part as well. The box described in the intro works this way.
21
21
# Assumptions
22
22
- `p : P` — Your invitation for Paul is evidence that Paul is invited to the party
23
23
- `s : S` — Your invitation for Sarah is evidence that Sarah is invited to the party
24
24
# Goal
25
-
Use `p` and `s` to produce evidence that `P ∧ S`. Remember that you use evidence (generally lowercase letters), to deduce new propositions (generally upercase letters)
25
+
Use `p` and `s` to produce evidence that `P ∧ S`. Remember that you use evidence (generally lowercase letters), to deduce new propositions (generally uppercase letters)
26
26
27
27
# A new definition
28
-
This level has unlocked \"∧ intro\" under definitions. This has made the `and_intro` constructor available. You can use `and_intro` by giving it the two relevant pieces of evidence. The expression looks like: `and_intro e₁ e₂` where `e₁` and `e₂` are evidence.\\
28
+
This level has unlocked “∧ intro” under definitions. This has made the `and_intro` constructor available. You can use `and_intro` by giving it the two relevant pieces of evidence. The expression looks like: `and_intro e₁ e₂` where `e₁` and `e₂` are evidence.\\
29
29
\\
30
30
The help-page has even more detail about creating conjunctions like this.
0 commit comments