Skip to content

Commit efe0801

Browse files
author
Trequetrum
committed
Level Updates
1 parent 00dad0b commit efe0801

36 files changed

+292
-107
lines changed

Game.lean

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import Game.Levels.AndIntro
88
import Game.Levels.ImpIntro
99
import Game.Levels.NotIntro
1010
import Game.Levels.OrIntro
11+
import Game.Levels.IffIntro
1112

1213
-- Here's where we show how to glue the worlds together
1314
Dependency AndIntro → ImpIntro
1415
Dependency ImpIntro → NotIntro
15-
16+
Dependency ImpIntro → OrIntro
17+
Dependency ImpIntro → IffIntro
1618

1719
-- Here's what we'll put on the title screen
1820
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
2628
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.
2729
2830
# 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.
3032
3133
# Building some notation
3234
Consider the following argument stated in natural language:
3335
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.” [¹]
3537
3638
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:
3739
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)
3941
3. If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. (Premise)
4042
4. Officer Thompson did not have an allergy attack. (Premise)
4143
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
4850
- 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**
4951
- Line 7 is the conclusion and is applying the \"if ... then ...\" statement on line 3. We'll call this one **modus ponens**.
5052
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.
5254
5355
# Propositions
5456
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
114116
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.
115117
116118
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*.
117123
"
118124

119125
Info "
@@ -123,9 +129,9 @@ Info "
123129
124130
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!
125131
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.
127133
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.
129135
130136
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.
131137
Github: [A Lean Intro to Logic](https://github.com/Trequetrum/lean4game-logic)

Game/Doc/Definitions.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ have h₃ : P ∧ Q := {left := p, right := q}
4646
have h₄ := ({left := p, right := q} : P ∧ Q)
4747
have h₅ := {left := p, right := q : P ∧ Q}
4848
-- Implicit Constructuer, annotations based on context
49+
-- Type these angle brackets with “\\<” and “\\>”
4950
have h₆ : P ∧ Q := ⟨p,q⟩
5051
have h₇ := (⟨p,q⟩ : P ∧ Q)
5152
```
@@ -55,7 +56,7 @@ DefinitionDoc FunElim as "→ elim" "
5556
# Function Application/Implication Elimination
5657
`P → Q` is propostion given to functions from evidence of `P` to evidence of `Q`.
5758
# Juxtaposition
58-
Juxtaposition just means \"to place next to each other,\" which is what we'll do to give a parameter to a function.
59+
Juxtaposition just means to place next to each other, which is what we'll do to give a parameter to a function.
5960
### Example
6061
You should already be familiar with `and_intro`. It is a funtion that takes two parameters.
6162
```

Game/Doc/Lemmas.lean

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ have h : A ∧ B := and_intro a b
1919
have h : A ∧ B := modus_ponens (modus_ponens and_intro a) b
2020
```
2121
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.
2333
"
2434

2535
def and_comm {P Q : Prop}: P ∧ Q ↔ Q ∧ P :=
@@ -83,14 +93,26 @@ example {P Q R : Prop}: P ∨ Q ∨ R ↔ (P ∨ Q) ∨ R := by
8393
exact ⟨mp,mpr⟩
8494

8595
def imp_trans {P Q R : Prop} (hpq : P → Q) (hqr : Q → R) (p : P): R := hqr (hpq p)
96+
8697
LemmaDoc imp_trans as "imp_trans" in "→" "
8798
# → is transitive
8899
`P → Q` and `Q → R` implies `P → R`
89100
```
90101
imp_trans : (P → Q) → (Q → R) → P → R
91102
```
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.
92111
"
93112

113+
infixl:85 " ≫ " => λa b ↦ Function.comp b a -- type as \gg
114+
115+
94116
def not_not_not {P : Prop}: ¬¬¬P ↔ ¬P := ⟨
95117
(λh p ↦ h (λnp ↦ np p)),
96118
(λh np ↦ np h)
@@ -114,6 +136,9 @@ Therefore, not P.
114136
```
115137
mt : (P → Q) → ¬Q → ¬P
116138
```
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`.
117142
"
118143

119144
def identity {P : Prop}(p : P) : P := p

Game/Doc/Tactics.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import GameServer.Commands
22

33
TacticDoc exact "
44
# 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.
66
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.
88
99
# Errors
1010
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:

Game/Levels/AndIntro.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You're hosting your yearly soirée, and it's time to start planning! Last year y
1717
\\
1818
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.
1919
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.\\
2121
\\
2222
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.\\
2323
\\

Game/Levels/AndIntro/L01.lean

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ You've made a todo list, so you've begun to plan your party. Exhibit evidence th
1414
## Proposition Key:
1515
`P` — You're **P**lanning a party
1616
## 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`\\
2118
# The Exact Tactic
2219
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.\\
2320
\\
@@ -26,9 +23,9 @@ It's entered like this:
2623
Goal: P
2724
exact <<expression that evaluates to evidence for P>>
2825
```
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.\\
3027
\\
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.
3229
3330
# Become Familiar with the User Interface!
3431
@@ -37,17 +34,16 @@ Found in the middle bottom of the screen, the proof state tells you what objects
3734
## 1. Objects:
3835
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.
3936
## 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.
4238
## 3. Goal:
4339
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.
4440
# Inventory
4541
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.
4642
"
4743

4844
/-- 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
5147

5248
Conclusion "
5349
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.

Game/Levels/AndIntro/L02.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ Title "And Introduction"
77
NewDefinition and_intro
88

99
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.\\
1212
\\
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.
1414
# 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
1717
# `∧`
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.\\
1919
\\
2020
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.
2121
# Assumptions
2222
- `p : P` — Your invitation for Paul is evidence that Paul is invited to the party
2323
- `s : S` — Your invitation for Sarah is evidence that Sarah is invited to the party
2424
# 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)
2626
2727
# 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.\\
2929
\\
3030
The help-page has even more detail about creating conjunctions like this.
3131
# A reminder

0 commit comments

Comments
 (0)