@@ -22,21 +22,21 @@ coinductive computation (α : Type u) : Type u
2222 An element of `computation α` is an infinite sequence of `option α` such
2323 that if `f n = some a` for some `n` then it is constantly `some a` after that. -/
2424def computation (α : Type u) : Type u :=
25- { f : stream (option α) // ∀ {n a}, f n = some a → f (n+ 1 ) = some a }
25+ {f : stream (option α) // ∀ {n a}, f n = some a → f (n + 1 ) = some a}
2626
2727namespace computation
2828variables {α : Type u} {β : Type v} {γ : Type w}
2929
3030-- constructors
3131/-- `return a` is the computation that immediately terminates with result `a`. -/
32- def return (a : α) : computation α := ⟨stream.const (some a), λn a', id⟩
32+ def return (a : α) : computation α := ⟨stream.const (some a), λ n a', id⟩
3333
3434instance : has_coe_t α (computation α) := ⟨return⟩ -- note [use has_coe_t]
3535
3636/-- `think c` is the computation that delays for one "tick" and then performs
3737 computation `c`. -/
3838def think (c : computation α) : computation α :=
39- ⟨none :: c.1 , λn a h, by {cases n with n, contradiction, exact c.2 h}⟩
39+ ⟨none :: c.1 , λ n a h, by {cases n with n, contradiction, exact c.2 h}⟩
4040
4141/-- `thinkN c n` is the computation that delays for `n` ticks and then performs
4242 computation `c`. -/
@@ -57,7 +57,7 @@ def tail (c : computation α) : computation α :=
5757
5858/-- `empty α` is the computation that never returns, an infinite sequence of
5959 `think`s. -/
60- def empty (α) : computation α := ⟨stream.const none, λn a', id⟩
60+ def empty (α) : computation α := ⟨stream.const none, λ n a', id⟩
6161
6262instance : inhabited (computation α) := ⟨empty _⟩
6363
@@ -147,7 +147,7 @@ def corec.F (f : β → α ⊕ β) : α ⊕ β → option α × (α ⊕ β)
147147 `corec f b = think (corec f b')`. -/
148148def corec (f : β → α ⊕ β) (b : β) : computation α :=
149149begin
150- refine ⟨stream.corec' (corec.F f) (sum.inr b), λn a' h, _⟩,
150+ refine ⟨stream.corec' (corec.F f) (sum.inr b), λ n a' h, _⟩,
151151 rw stream.corec'_eq,
152152 change stream.corec' (corec.F f) (corec.F f (sum.inr b)).2 n = some a',
153153 revert h, generalize : sum.inr b = o, revert o,
@@ -203,12 +203,12 @@ section bisim
203203 theorem eq_of_bisim (bisim : is_bisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ :=
204204 begin
205205 apply subtype.eq,
206- apply stream.eq_of_bisim (λx y, ∃ s s' : computation α, s.1 = x ∧ s'.1 = y ∧ R s s'),
206+ apply stream.eq_of_bisim (λ x y, ∃ s s' : computation α, s.1 = x ∧ s'.1 = y ∧ R s s'),
207207 dsimp [stream.is_bisimulation],
208208 intros t₁ t₂ e,
209209 exact match t₁, t₂, e with ._, ._, ⟨s, s', rfl, rfl, r⟩ :=
210210 suffices head s = head s' ∧ R (tail s) (tail s'), from
211- and.imp id (λr , ⟨tail s, tail s',
211+ and.imp id (λ r , ⟨tail s, tail s',
212212 by cases s; refl, by cases s'; refl, r⟩) this ,
213213 begin
214214 have := bisim r, revert r this ,
@@ -467,8 +467,8 @@ mem_rec_on (get_mem s) (h1 _) h2
467467
468468/-- Map a function on the result of a computation. -/
469469def map (f : α → β) : computation α → computation β
470- | ⟨s, al⟩ := ⟨s.map (λo , option.cases_on o none (some ∘ f)),
471- λn b, begin
470+ | ⟨s, al⟩ := ⟨s.map (λ o , option.cases_on o none (some ∘ f)),
471+ λ n b, begin
472472 dsimp [stream.map, stream.nth],
473473 induction e : s n with a; intro h,
474474 { contradiction }, { rw [al e, ←h] }
@@ -511,7 +511,7 @@ by apply s.cases_on; intro; simp
511511@[simp] theorem map_id : ∀ (s : computation α), map id s = s
512512| ⟨f, al⟩ := begin
513513 apply subtype.eq; simp [map, function.comp],
514- have e : (@option.rec α (λ_ , option α) none some) = id,
514+ have e : (@option.rec α (λ _ , option α) none some) = id,
515515 { ext ⟨⟩; refl },
516516 simp [e, stream.map_id]
517517end
528528@[simp] theorem ret_bind (a) (f : α → computation β) :
529529 bind (return a) f = f a :=
530530begin
531- apply eq_of_bisim (λc ₁ c₂,
531+ apply eq_of_bisim (λ c ₁ c₂,
532532 c₁ = bind (return a) f ∧ c₂ = f a ∨
533533 c₁ = corec (bind.F f) (sum.inr c₂)),
534534 { intros c₁ c₂ h,
@@ -550,7 +550,7 @@ destruct_eq_think $ by simp [bind, bind.F]
550550
551551@[simp] theorem bind_ret (f : α → β) (s) : bind s (return ∘ f) = map f s :=
552552begin
553- apply eq_of_bisim (λc ₁ c₂, c₁ = c₂ ∨
553+ apply eq_of_bisim (λ c ₁ c₂, c₁ = c₂ ∨
554554 ∃ s, c₁ = bind s (return ∘ f) ∧ c₂ = map f s),
555555 { intros c₁ c₂ h,
556556 exact match c₁, c₂, h with
@@ -568,7 +568,7 @@ by rw bind_ret; change (λ x : α, x) with @id α; rw map_id
568568@[simp] theorem bind_assoc (s : computation α) (f : α → computation β) (g : β → computation γ) :
569569 bind (bind s f) g = bind s (λ (x : α), bind (f x) g) :=
570570begin
571- apply eq_of_bisim (λc ₁ c₂, c₁ = c₂ ∨
571+ apply eq_of_bisim (λ c ₁ c₂, c₁ = c₂ ∨
572572 ∃ s, c₁ = bind (bind s f) g ∧ c₂ = bind s (λ (x : α), bind (f x) g)),
573573 { intros c₁ c₂ h,
574574 exact match c₁, c₂, h with
@@ -678,7 +678,7 @@ theorem terminates_map_iff (f : α → β) (s : computation α) :
678678 the first one that gives a result. -/
679679def orelse (c₁ c₂ : computation α) : computation α :=
680680@computation.corec α (computation α × computation α)
681- (λ⟨c₁, c₂⟩, match destruct c₁ with
681+ (λ ⟨c₁, c₂⟩, match destruct c₁ with
682682 | sum.inl a := sum.inl a
683683 | sum.inr c₁' := match destruct c₂ with
684684 | sum.inl a := sum.inl a
@@ -703,15 +703,15 @@ destruct_eq_think $ by unfold has_orelse.orelse; simp [orelse]
703703
704704@[simp] theorem empty_orelse (c) : (empty α <|> c) = c :=
705705begin
706- apply eq_of_bisim (λc ₁ c₂, (empty α <|> c₂) = c₁) _ rfl,
706+ apply eq_of_bisim (λ c ₁ c₂, (empty α <|> c₂) = c₁) _ rfl,
707707 intros s' s h, rw ←h,
708708 apply cases_on s; intros s; rw think_empty; simp,
709709 rw ←think_empty,
710710end
711711
712712@[simp] theorem orelse_empty (c : computation α) : (c <|> empty α) = c :=
713713begin
714- apply eq_of_bisim (λc ₁ c₂, (c₂ <|> empty α) = c₁) _ rfl,
714+ apply eq_of_bisim (λ c ₁ c₂, (c₂ <|> empty α) = c₁) _ rfl,
715715 intros s' s h, rw ←h,
716716 apply cases_on s; intros s; rw think_empty; simp,
717717 rw←think_empty,
@@ -723,28 +723,28 @@ def equiv (c₁ c₂ : computation α) : Prop := ∀ a, a ∈ c₁ ↔ a ∈ c
723723
724724infix ` ~ `:50 := equiv
725725
726- @[refl] theorem equiv.refl (s : computation α) : s ~ s := λ_ , iff.rfl
726+ @[refl] theorem equiv.refl (s : computation α) : s ~ s := λ _ , iff.rfl
727727
728728@[symm] theorem equiv.symm {s t : computation α} : s ~ t → t ~ s :=
729- λh a, (h a).symm
729+ λ h a, (h a).symm
730730
731731@[trans] theorem equiv.trans {s t u : computation α} : s ~ t → t ~ u → s ~ u :=
732- λh1 h2 a, (h1 a).trans (h2 a)
732+ λ h1 h2 a, (h1 a).trans (h2 a)
733733
734734theorem equiv.equivalence : equivalence (@equiv α) :=
735735⟨@equiv.refl _, @equiv.symm _, @equiv.trans _⟩
736736
737737theorem equiv_of_mem {s t : computation α} {a} (h1 : a ∈ s) (h2 : a ∈ t) : s ~ t :=
738- λa ', ⟨λma , by rw mem_unique ma h1; exact h2,
739- λma , by rw mem_unique ma h2; exact h1⟩
738+ λ a ', ⟨λ ma , by rw mem_unique ma h1; exact h2,
739+ λ ma , by rw mem_unique ma h2; exact h1⟩
740740
741741theorem terminates_congr {c₁ c₂ : computation α}
742742 (h : c₁ ~ c₂) : terminates c₁ ↔ terminates c₂ :=
743743by simp only [terminates_iff, exists_congr h]
744744
745745theorem promises_congr {c₁ c₂ : computation α}
746746 (h : c₁ ~ c₂) (a) : c₁ ~> a ↔ c₂ ~> a :=
747- forall_congr (λa ', imp_congr (h a') iff.rfl)
747+ forall_congr (λ a ', imp_congr (h a') iff.rfl)
748748
749749theorem get_equiv {c₁ c₂ : computation α} (h : c₁ ~ c₂)
750750 [terminates c₁] [terminates c₂] : get c₁ = get c₂ :=
@@ -758,9 +758,9 @@ theorem thinkN_equiv (s : computation α) (n) : thinkN s n ~ s :=
758758
759759theorem bind_congr {s1 s2 : computation α} {f1 f2 : α → computation β}
760760 (h1 : s1 ~ s2) (h2 : ∀ a, f1 a ~ f2 a) : bind s1 f1 ~ bind s2 f2 :=
761- λ b, ⟨λh , let ⟨a, ha, hb⟩ := exists_of_mem_bind h in
761+ λ b, ⟨λ h , let ⟨a, ha, hb⟩ := exists_of_mem_bind h in
762762 mem_bind ((h1 a).1 ha) ((h2 a b).1 hb),
763- λh , let ⟨a, ha, hb⟩ := exists_of_mem_bind h in
763+ λ h , let ⟨a, ha, hb⟩ := exists_of_mem_bind h in
764764 mem_bind ((h1 a).2 ha) ((h2 a b).2 hb)⟩
765765
766766theorem equiv_ret_of_mem {s : computation α} {a} (h : a ∈ s) : s ~ return a :=
@@ -779,10 +779,10 @@ theorem lift_rel.swap (R : α → β → Prop) (ca : computation α) (cb : compu
779779and_comm _ _
780780
781781theorem lift_eq_iff_equiv (c₁ c₂ : computation α) : lift_rel (=) c₁ c₂ ↔ c₁ ~ c₂ :=
782- ⟨λ⟨h1, h2⟩ a,
782+ ⟨λ ⟨h1, h2⟩ a,
783783 ⟨λ a1, let ⟨b, b2, ab⟩ := h1 a1 in by rwa ab,
784784 λ a2, let ⟨b, b1, ab⟩ := h2 a2 in by rwa ←ab⟩,
785- λe , ⟨λ a a1, ⟨a, (e _).1 a1, rfl⟩, λ a a2, ⟨a, (e _).2 a2, rfl⟩⟩⟩
785+ λ e , ⟨λ a a1, ⟨a, (e _).1 a1, rfl⟩, λ a a2, ⟨a, (e _).2 a2, rfl⟩⟩⟩
786786
787787theorem lift_rel.refl (R : α → α → Prop ) (H : reflexive R) : reflexive (lift_rel R) :=
788788λ s, ⟨λ a as, ⟨a, as, H a⟩, λ b bs, ⟨b, bs, H b⟩⟩
@@ -831,9 +831,9 @@ H.right h
831831
832832theorem lift_rel_def {R : α → β → Prop } {ca cb} : lift_rel R ca cb ↔
833833 (terminates ca ↔ terminates cb) ∧ ∀ {a b}, a ∈ ca → b ∈ cb → R a b :=
834- ⟨λh , ⟨terminates_of_lift_rel h, λ a b ma mb,
834+ ⟨λ h , ⟨terminates_of_lift_rel h, λ a b ma mb,
835835 let ⟨b', mb', ab⟩ := h.left ma in by rwa mem_unique mb mb'⟩,
836- λ⟨l, r⟩,
836+ λ ⟨l, r⟩,
837837 ⟨λ a ma, let ⟨⟨b, mb⟩⟩ := l.1 ⟨⟨_, ma⟩⟩ in ⟨b, mb, r ma mb⟩,
838838 λ b mb, let ⟨⟨a, ma⟩⟩ := l.2 ⟨⟨_, mb⟩⟩ in ⟨a, ma, r ma mb⟩⟩⟩
839839
@@ -858,8 +858,8 @@ let ⟨l1, r1⟩ := h1 in
858858
859859@[simp] theorem lift_rel_return_left (R : α → β → Prop ) (a : α) (cb : computation β) :
860860 lift_rel R (return a) cb ↔ ∃ {b}, b ∈ cb ∧ R a b :=
861- ⟨λ⟨l, r⟩, l (ret_mem _),
862- λ⟨b, mb, ab⟩,
861+ ⟨λ ⟨l, r⟩, l (ret_mem _),
862+ λ ⟨b, mb, ab⟩,
863863 ⟨λ a' ma', by rw eq_of_ret_mem ma'; exact ⟨b, mb, ab⟩,
864864 λ b' mb', ⟨_, ret_mem _, by rw mem_unique mb' mb; exact ab⟩⟩⟩
865865
@@ -870,13 +870,13 @@ by rw [lift_rel.swap, lift_rel_return_left]
870870@[simp] theorem lift_rel_return (R : α → β → Prop ) (a : α) (b : β) :
871871 lift_rel R (return a) (return b) ↔ R a b :=
872872by rw [lift_rel_return_left]; exact
873- ⟨λ⟨b', mb', ab'⟩, by rwa eq_of_ret_mem mb' at ab',
874- λab , ⟨_, ret_mem _, ab⟩⟩
873+ ⟨λ ⟨b', mb', ab'⟩, by rwa eq_of_ret_mem mb' at ab',
874+ λ ab , ⟨_, ret_mem _, ab⟩⟩
875875
876876@[simp] theorem lift_rel_think_left (R : α → β → Prop ) (ca : computation α) (cb : computation β) :
877877 lift_rel R (think ca) cb ↔ lift_rel R ca cb :=
878- and_congr (forall_congr $ λb , imp_congr ⟨of_think_mem, think_mem⟩ iff.rfl)
879- (forall_congr $ λb , imp_congr iff.rfl $
878+ and_congr (forall_congr $ λ b , imp_congr ⟨of_think_mem, think_mem⟩ iff.rfl)
879+ (forall_congr $ λ b , imp_congr iff.rfl $
880880 exists_congr $ λ b, and_congr ⟨of_think_mem, think_mem⟩ iff.rfl)
881881
882882@[simp] theorem lift_rel_think_right (R : α → β → Prop ) (ca : computation α) (cb : computation β) :
0 commit comments