HL Student source diff

Switch volume / audience

HL/Equiv.lean

1111 --  This chapter develops a notion of *behavioral equivalence* for Imp's
1212 --  expressions and commands.
1313 --
14---  To illustrate it use, we verify that program transformations such as
14+--  To illustrate its use, we verify that program transformations such as
1515 --  constant folding preserve behavior. Along the way we also see
1616 --  techniques for proving that two programs are *not* equivalent. Finally,
1717 --  we close with an extended look at what equivalence means once Imp is
674674       injection heq with beq ceq
675675       subst beq ceq
676676       rw [hb] at hb'
677-      specialize ih2 rfl
677+      specialize ih2 (by rfl)
678678       apply Com.EvalR.whileTrue hb' _ ih2
679679       · rw [equiv_def] at hc
680680         exact hc.mp hc'
693693       injection heq with beq ceq
694694       subst beq ceq
695695       rw [← hb] at hb'
696-      specialize ih2 rfl
696+      specialize ih2 (by rfl)
697697       apply Com.EvalR.whileTrue hb' _ ih2
698698       · rw [equiv_def] at hc
699699         exact hc.mpr hc'
18171817     (ha : Approx c c') : zprop c' := by
18181818   sorry
18191819 
1820--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
1820+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL/Hoare.lean

17451745     · exact hoare_asgn
17461746     · assertion_auto
17471747 
1748---  We can even shorten it a little bit more. Wherever Lean expects a term
1749---  of some type, we may write `(by <tactics>)` in its place: the tactics
1750---  run immediately, and the proof they produce is spliced in as that term.
1751---  Here we use it to supply `hoare_consequence_pre`'s second argument, the
1752---  implication `P ↠ P'`, directly at the call site, instead of `apply`-ing
1748+--  We can even shorten it a little bit more. Recall that wherever Lean
1749+--  expects a term of some type, we may write `(by <tactics>)` in its
1750+--  place: the tactics run immediately, and the proof they produce is
1751+--  spliced in as that term. Here we use it to supply
1752+--  `hoare_consequence_pre`'s second argument, the implication `P ↠ P'`,
1753+--  directly at the call site, instead of `apply`-ing
17531754 --  `hoare_consequence_pre` and discharging that goal afterward with a
17541755 --  separate bullet.
17551756 
20782079   | whileTrue hb hc hloop ih₁ ih₂ =>
20792080     injection heq with hbeq hceq
20802081     subst hbeq hceq
2081-    exact ih₂ (hhoare hc ⟨hpre, hb⟩) rfl
2082+    apply ih₂ (hhoare hc ⟨hpre, hb⟩) (by rfl)
20822083   | skip | asgn | seq | ifTrue | ifFalse =>
20832084     contradiction
20842085 
28352836   | asgn n h =>
28362837     exists (x →ₜ n ; st)
28372838     subst h
2838-    exact ⟨rfl, hQ⟩
2839+    exact ⟨by rfl, hQ⟩
28392840 
28402841 theorem hoare_consequence_pre {P P' Q : Assertion} {c : Com}
28412842     (hhoare : {{ P' }} c {{ Q }}) (himp : P ↠ P') :
28792880   rw [validHoareTriple_def]
28802881   intro st r h hpre
28812882   inversion h
2882-  exact ⟨st, rfl, hpre⟩
2883+  exists st
28832884 
28842885 theorem hoare_if {P Q : Assertion} {b : Bexp} {c₁ c₂ : Com}
28852886     (htrue : {{ P ∧ b}} c₁ {{ Q }})
29052906   intro st r heval hpre
29062907   generalize heq : (imp { while (b) { c } }) = cmd at heval
29072908   induction heval generalizing P with
2908-  | whileFalse hb =>
2909+  | @whileFalse _ st _ hb =>
29092910     injection heq with hbeq hceq
29102911     subst hbeq hceq
2911-    exact ⟨_, rfl, hpre, by simp [hb]⟩
2912+    exists st
2913+    simp_all
29122914   | whileTrueNormal hb hc hloop ih₁ ih₂ =>
29132915     injection heq with hbeq hceq
29142916     subst hbeq hceq
2915-    apply ih₂ hhoare _ rfl
2917+    apply ih₂ hhoare _ (by rfl)
29162918     obtain ⟨s₁, heq₁, hs₁⟩ := hhoare hc ⟨hpre, hb⟩
29172919     injection heq₁ with he
29182920     subst he
29442946 
29452947 end HoareAssertAssume
29462948 
2947--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
2949+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL/Hoare2.lean

20702070 
20712071 end HimpHoare2
20722072 
2073--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
2073+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL/Imp.lean

880880     ]=> {Z ↦ 4, X ↦ 2} := by
881881   -- To supply the intermediate state to the `seq` rule, which is
882882   -- sometimes necessary, we can write `EvalR.seq (st' := ...)`.
883+  -- We can also write `EvalR.asgn (by rfl)` to immediately close
884+  -- the subgoal generated by the lookup.
883885   apply EvalR.seq (st' := {X ↦ 2})
884-  · exact EvalR.asgn rfl
886+  · apply EvalR.asgn (by rfl)
885887   · apply EvalR.ifFalse
886888     · rfl
887-    · exact EvalR.asgn rfl
889+    · apply EvalR.asgn (by rfl)
888890 
889891 --  Since the total-map update notation (`→ₜ`) is difficult to type, we
890892 --  prefer to use the `{}`-notation with `KVPair`s.
891893 --
892---  In the above proof, using `EvalR.asgn rfl` is convenient because it
893---  computes the value of the right-hand side and can use it to determine
894---  `st'`.
894+--  In the above proof, proving the premise of `EvalR.asgn` with `rfl` is
895+--  convenient because it computes the value of the right-hand side and can
896+--  use it to determine `st'`.
895897 --
896898 --  Here are some more examples. Note the use of `~` in the first, since
897899 --  `.num x` is a Lean term that we want to splice into Imp.
902904   -- `simp` or `rfl`
903905   simp
904906 
907+--  We can abbreviate this further using `apply EvalR.asgn (by rfl)`, which
908+--  automatically closes the `=` subproof with `rfl`.
909+
905910 example {x : Nat} : ∅ =[ X := ~(.num x) ]=> {X ↦ x} := by
906-  exact EvalR.asgn rfl
911+  apply EvalR.asgn (by rfl)
907912 
908913 example : ∅ =[ X := 2; Y := 3 ]=> {Y ↦ 3, X ↦ 2} := by
909914   apply EvalR.seq
910915   · -- `⊢ imp {X := 2}.EvalR ∅ ?st'`
911916     -- assigns the metavariable `?st'` to `{X ↦ 2}` (or equivalent)
912-    exact EvalR.asgn rfl
917+    apply EvalR.asgn (by rfl)
913918   · simp only [Aexp.eval_num, evalR_eq]
914-    exact EvalR.asgn rfl
919+    apply EvalR.asgn (by rfl)
915920 
916921 --  This is a case where `rfl` is more powerful than `simp`, because it can
917922 --  assign the `?st'` metavariable. To demonstrate, here's a version with
12311236     have hz : st[Z] ≠ 0 := by
12321237       intro hz
12331238       simp [hz] at hb
1234-    exact ih₂ (factBody_preserves_invariant hinv hz hc) rfl
1239+    apply ih₂ (factBody_preserves_invariant hinv hz hc)
1240+    rfl
12351241   | skip | asgn | seq | ifTrue | ifFalse => simp [factLoop] at heq
12361242 
12371243 --  Next, we show that, for any loop, if the loop terminates, then the
16651671 --  Notation for `for` loops, but feel free to play with this too if you
16661672 --  like.)
16671673 
1668--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
1674+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL/Preface.lean

163163 --  was supported, in part, by the National Science Foundation under the
164164 --  NSF Expeditions grant 1521523, *The Science of Deep Specification*.
165165 
166--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
166+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL/Slang.lean

653653 --  switch between points of view at will — exactly what we did above in
654654 --  `Slang.Aexp.evalR_iff_eval` and `Slang.Bexp.evalR_iff_eval`.
655655 
656--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
656+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

HL.lean

55 import HL.Hoare
66 import HL.Hoare2
77 
8--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
8+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

LF/Typeclasses.lean

15811581 
15821582 end Reflection
15831583 
1584--- Source revision: 2ca0e09, committed 2026-10-23 15:44 UTC
1584+-- Source revision: a06e066, committed 2026-10-27 16:51 UTC

SFLCompat/Experiment.lean

146146 Example:
147147 ```lean
148148 sf_expect_failure_in
149-  example : 1 = 2 := rfl
149+  example : 1 = 2 := by rfl
150150 ```
151151 -/
152152 def expectFailureTk := leading_parser

SFLCompat/Recall/Check.lean

460460 
461461 def twice (f : Nat → Nat) (n : Nat) : Nat := f (f n)
462462 
463-theorem twice_id : twice id 3 = 3 := rfl
463+theorem twice_id : twice id 3 = 3 := by rfl
464464 
465465 sf_recall
466466   inductive Palette where
490490 
491491 -- The statement form counts universe parameters: a placeholder universe
492492 -- becomes a parameter and matches, and a fixed universe is rejected.
493-theorem poly_refl.{u} : ∀ {α : Sort u} (a : α), a = a := fun _ => rfl
493+theorem poly_refl.{u} : ∀ {α : Sort u} (a : α), a = a := fun _ => by rfl
494494 
495495 sf_recall statement poly_refl : ∀ {α : Sort _} (a : α), a = a
496496 

SFLCompat/Recall/Source.lean

6363 
6464 def twice (f : Nat → Nat) (n : Nat) : Nat := f (f n)
6565 
66-theorem twice_id : twice id 3 = 3 := rfl
66+theorem twice_id : twice id 3 = 3 := by rfl
6767 
6868 sf_recall_source
6969   inductive Palette where