3.1 KiB
Lean syntax
rw
takes a list of rewrite rules and applies them—left to right—so if you have a rule of the formh : a = b
thenrw [h]
will replace alla
s in the goal withb
.rw [h] at h2
will do the same thing but in the assumptionh2
insteadrw \l [h]
will reverse the direction of rewrite rule, taking a theorem of the formh : a = b
and use it to rewrite allb
s intoa
-
repeat rw [...]
will apply the rewrite rules between the square brackets 0 or more times, as many times as it can- this is really useful when you need to do something like
repeat rw [add_succ]
in order to move a successor from deep inside a series of additions and pull it out to the front of the whole expression
- this is really useful when you need to do something like
-
apply
takes a theorem of the formh: A -> B
, in other words a function that transforms evidence thatA
is true and turns it into evidenceB
is true, and lets you either transform a goalB
into a goalA
(backwards reasoning) or lets you transform an assumptionA
into an assumptionB
- unlike
rw
,apply
always just takes one argument so it doesn't have the square brackets apply
can also just take a theorem of the formA
and apply it to a goalA
- unlike
-
induction n with n' ih
takes a numbern
and generates two new goals:- One where
n
is replaces with 0 - One where
n
is replaces withsucc n'
but you get to have as an additional assumptionih
which is evidence that the theorem is true forn'
- You don't always need induction, but it's useful when you have no other "hand holds" to grip the proof with. Always stop and think if there's something easier than induction first, though.
- One where
-
intro h
lets you take a goal of the formA -> B
and turn it into a goal ofB
with the assumptionh : A
. This is, basically, function definition and you're declaring an argument namedh
with typeA
and you get to use thath
in the "body" of your "function" when making your proof-
You can actually do multiple
intro
on one line likeintro h1 h2 h3
in order to take a goal ofA -> B -> C -> D
and turn it into a goal ofD
with the assumptionsh1 : A
,h2 : B
,h3 : C
, &c.- Pop-quiz! If I have a goal of type
(A -> B) -> C
what is the type ofh
if I dointro h
?
- Pop-quiz! If I have a goal of type
-
use
lets you prove an existential goal by providing an example of a thing that fits the condition-
cases
lets you take apart an existential assumption and get back a thing that satisfies the proposition. You don't get to know what it is specifically, just that it is a thingcases
is also useful when you need to take a hypothesis offalse
and end the proof. Why does this work? Well, remember how in classical logicF -> q
evaluates to true no matter whatq
is?
Strategies
- Don't use induction until after you've taken stock of what theorems might apply to the situation. If you look and don't see something that could obviously apply, then you probably need induction.
- If a proof isn't immediately obvious, try sketching it out with pen and paper instead
-
When proving an existential goal, think hard about what you need
- Again, try writing it out