chars
int64
40
24k
content_type
stringclasses
9 values
id
stringlengths
13
64
source
stringclasses
5 values
subset
stringclasses
31 values
text
stringlengths
40
24k
81
leanexplore_declaration
leanexplore:387749
leanexplore_sqlite
leanexplore_declarations
/-- Self application: δ := λ x. x x -/ def DelPoly : SKI.Polynomial 1 := &0 ⬝' &0
63
leanexplore_declaration
leanexplore:387750
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing δ -/ def Del : SKI := DelPoly.toSKI
86
leanexplore_declaration
leanexplore:387751
leanexplore_sqlite
leanexplore_declarations
theorem del_def (x : SKI) : (Del ⬝ x) ↠ x ⬝ x := DelPoly.toSKI_correct [x] (by simp)
75
leanexplore_declaration
leanexplore:387752
leanexplore_sqlite
leanexplore_declarations
/-- H := λ f x. f (x x) -/ def HPoly : SKI.Polynomial 2 := &0 ⬝' (&1 ⬝' &1)
59
leanexplore_declaration
leanexplore:387753
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing H -/ def H : SKI := HPoly.toSKI
95
leanexplore_declaration
leanexplore:387754
leanexplore_sqlite
leanexplore_declarations
theorem H_def (f x : SKI) : (H ⬝ f ⬝ x) ↠ f ⬝ (x ⬝ x) := HPoly.toSKI_correct [f, x] (by simp)
111
leanexplore_declaration
leanexplore:387755
leanexplore_sqlite
leanexplore_declarations
/-- Curry's fixed-point combinator: Y := λ f. H f (H f) -/ def YPoly : SKI.Polynomial 1 := H ⬝' &0 ⬝' (H ⬝' &0)
59
leanexplore_declaration
leanexplore:387756
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing Y -/ def Y : SKI := YPoly.toSKI
90
leanexplore_declaration
leanexplore:387757
leanexplore_sqlite
leanexplore_declarations
theorem Y_def (f : SKI) : (Y ⬝ f) ↠ H ⬝ f ⬝ (H ⬝ f) := YPoly.toSKI_correct [f] (by simp)
249
leanexplore_declaration
leanexplore:387758
leanexplore_sqlite
leanexplore_declarations
/-- The fixed-point property of the Y-combinator -/ theorem Y_correct (f : SKI) : MJoin Red (Y ⬝ f) (f ⬝ (Y ⬝ f)) := by use f ⬝ (H ⬝ f ⬝ (H ⬝ f)) constructor · exact Trans.trans (Y_def f) (H_def f (H ⬝ f)) · apply MRed.tail exact Y_def f
261
leanexplore_declaration
leanexplore:387759
leanexplore_sqlite
leanexplore_declarations
/-- It is useful to be able to produce a term such that the fixed point property holds on-the-nose, rather than up to a common reduct. An alternative is to use Turing's fixed-point combinator (defined below). -/ def fixedPoint (f : SKI) : SKI := H ⬝ f ⬝ (H ⬝ f)
89
leanexplore_declaration
leanexplore:387760
leanexplore_sqlite
leanexplore_declarations
theorem fixedPoint_correct (f : SKI) : f.fixedPoint ↠ f ⬝ f.fixedPoint := H_def f (H ⬝ f)
148
leanexplore_declaration
leanexplore:387761
leanexplore_sqlite
leanexplore_declarations
/-- Auxiliary definition for Turing's fixed-point combinator: ΘAux := λ x y. y (x x y) -/ def ThAuxPoly : SKI.Polynomial 2 := &1 ⬝' (&0 ⬝' &0 ⬝' &1)
66
leanexplore_declaration
leanexplore:387762
leanexplore_sqlite
leanexplore_declarations
/-- A term representing ΘAux -/ def ThAux : SKI := ThAuxPoly.toSKI
111
leanexplore_declaration
leanexplore:387763
leanexplore_sqlite
leanexplore_declarations
theorem ThAux_def (x y : SKI) : (ThAux ⬝ x ⬝ y) ↠ y ⬝ (x ⬝ x ⬝ y) := ThAuxPoly.toSKI_correct [x, y] (by simp)
112
leanexplore_declaration
leanexplore:387764
leanexplore_sqlite
leanexplore_declarations
/-- Turing's fixed-point combinator: Θ := (λ x y. y (x x y)) (λ x y. y (x x y)) -/ def Th : SKI := ThAux ⬝ ThAux
108
leanexplore_declaration
leanexplore:387765
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing Θ -/ theorem Th_correct (f : SKI) : (Th ⬝ f) ↠ f ⬝ (Th ⬝ f) := ThAux_def ThAux f
191
leanexplore_declaration
leanexplore:387766
leanexplore_sqlite
leanexplore_declarations
/-- A term a represents the boolean value u if it is βη-equivalent to a standard Church boolean. -/ def IsBool (u : Bool) (a : SKI) : Prop := ∀ x y : SKI, (a ⬝ x ⬝ y) ↠ (if u then x else y)
201
leanexplore_declaration
leanexplore:387767
leanexplore_sqlite
leanexplore_declarations
theorem isBool_trans (u : Bool) (a a' : SKI) (h : a ↠ a') (ha' : IsBool u a') : IsBool u a := by intro x y trans a' ⬝ x ⬝ y · apply MRed.head apply MRed.head exact h · exact ha' x y
54
leanexplore_declaration
leanexplore:387768
leanexplore_sqlite
leanexplore_declarations
/-- Standard true: TT := λ x y. x -/ def TT : SKI := K
77
leanexplore_declaration
leanexplore:387769
leanexplore_sqlite
leanexplore_declarations
@[scoped grind .] theorem TT_correct : IsBool true TT := fun x y ↦ MRed.K x y
59
leanexplore_declaration
leanexplore:387770
leanexplore_sqlite
leanexplore_declarations
/-- Standard false: FF := λ x y. y -/ def FF : SKI := K ⬝ I
202
leanexplore_declaration
leanexplore:387771
leanexplore_sqlite
leanexplore_declarations
@[scoped grind .] theorem FF_correct : IsBool false FF := fun x y ↦ calc (FF ⬝ x ⬝ y) ↠ I ⬝ y := by apply Relation.ReflTransGen.single; apply red_head; exact red_K I x _ ⭢ y := red_I y
85
leanexplore_declaration
leanexplore:387772
leanexplore_sqlite
leanexplore_declarations
/-- Conditional: Cond x y b := if b then x else y -/ protected def Cond : SKI := RotR
177
leanexplore_declaration
leanexplore:387773
leanexplore_sqlite
leanexplore_declarations
theorem cond_correct (a x y : SKI) (u : Bool) (h : IsBool u a) : (SKI.Cond ⬝ x ⬝ y ⬝ a) ↠ if u then x else y := by trans a ⬝ x ⬝ y · exact rotR_def x y a · exact h x y
77
leanexplore_declaration
leanexplore:387774
leanexplore_sqlite
leanexplore_declarations
/-- Neg := λ a. Cond FF TT a -/ protected def Neg : SKI := SKI.Cond ⬝ FF ⬝ TT
239
leanexplore_declaration
leanexplore:387775
leanexplore_sqlite
leanexplore_declarations
theorem neg_correct (a : SKI) (ua : Bool) (h : IsBool ua a) : IsBool (¬ ua) (SKI.Neg ⬝ a) := by apply isBool_trans (a' := if ua then FF else TT) · apply cond_correct (h := h) · cases ua · simp [TT_correct] · simp [FF_correct]
130
leanexplore_declaration
leanexplore:387776
leanexplore_sqlite
leanexplore_declarations
/-- And := λ a b. Cond (Cond TT FF b) FF a -/ def AndPoly : SKI.Polynomial 2 := SKI.Cond ⬝' (SKI.Cond ⬝ TT ⬝ FF ⬝' &1) ⬝' FF ⬝' &0
75
leanexplore_declaration
leanexplore:387777
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing And -/ protected def And : SKI := AndPoly.toSKI
138
leanexplore_declaration
leanexplore:387778
leanexplore_sqlite
leanexplore_declarations
theorem and_def (a b : SKI) : (SKI.And ⬝ a ⬝ b) ↠ SKI.Cond ⬝ (SKI.Cond ⬝ TT ⬝ FF ⬝ b) ⬝ FF ⬝ a := AndPoly.toSKI_correct [a, b] (by simp)
633
leanexplore_declaration
leanexplore:387779
leanexplore_sqlite
leanexplore_declarations
theorem and_correct (a b : SKI) (ua ub : Bool) (ha : IsBool ua a) (hb : IsBool ub b) : IsBool (ua && ub) (SKI.And ⬝ a ⬝ b) := by apply isBool_trans (a' := SKI.Cond ⬝ (SKI.Cond ⬝ TT ⬝ FF ⬝ b) ⬝ FF ⬝ a) (h := and_def _ _) cases ua · simp_rw [Bool.false_and] at ⊢ apply isBool_trans (a' := FF) (ha' := FF_corr...
128
leanexplore_declaration
leanexplore:387780
leanexplore_sqlite
leanexplore_declarations
/-- Or := λ a b. Cond TT (Cond TT FF b) b -/ def OrPoly : SKI.Polynomial 2 := SKI.Cond ⬝' TT ⬝' (SKI.Cond ⬝ TT ⬝ FF ⬝' &1) ⬝' &0
72
leanexplore_declaration
leanexplore:387781
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing Or -/ protected def Or : SKI := OrPoly.toSKI
135
leanexplore_declaration
leanexplore:387782
leanexplore_sqlite
leanexplore_declarations
theorem or_def (a b : SKI) : (SKI.Or ⬝ a ⬝ b) ↠ SKI.Cond ⬝ TT ⬝ (SKI.Cond ⬝ TT ⬝ FF ⬝ b) ⬝ a := OrPoly.toSKI_correct [a, b] (by simp)
591
leanexplore_declaration
leanexplore:387783
leanexplore_sqlite
leanexplore_declarations
theorem or_correct (a b : SKI) (ua ub : Bool) (ha : IsBool ua a) (hb : IsBool ub b) : IsBool (ua || ub) (SKI.Or ⬝ a ⬝ b) := by apply isBool_trans (a' := SKI.Cond ⬝ TT ⬝ (SKI.Cond ⬝ TT ⬝ FF ⬝ b) ⬝ a) (h := or_def _ _) cases ua · simp_rw [Bool.false_or] apply isBool_trans (a' := SKI.Cond ⬝ TT ⬝ FF ⬝ b) (h := ...
58
leanexplore_declaration
leanexplore:387784
leanexplore_sqlite
leanexplore_declarations
/-- MkPair := λ a b. ⟨a,b⟩ -/ def MkPair : SKI := SKI.Cond
47
leanexplore_declaration
leanexplore:387785
leanexplore_sqlite
leanexplore_declarations
/-- First projection -/ def Fst : SKI := R ⬝ TT
48
leanexplore_declaration
leanexplore:387786
leanexplore_sqlite
leanexplore_declarations
/-- Second projection -/ def Snd : SKI := R ⬝ FF
179
leanexplore_declaration
leanexplore:387787
leanexplore_sqlite
leanexplore_declarations
@[scoped grind .] theorem fst_correct (a b : SKI) : (Fst ⬝ (MkPair ⬝ a ⬝ b)) ↠ a := by calc _ ↠ SKI.Cond ⬝ a ⬝ b ⬝ TT := R_def _ _ _ ↠ a := cond_correct TT a b true TT_correct
180
leanexplore_declaration
leanexplore:387788
leanexplore_sqlite
leanexplore_declarations
@[scoped grind .] theorem snd_correct (a b : SKI) : (Snd ⬝ (MkPair ⬝ a ⬝ b)) ↠ b := by calc _ ↠ SKI.Cond ⬝ a ⬝ b ⬝ FF := R_def _ _ _ ↠ b := cond_correct FF a b false FF_correct
125
leanexplore_declaration
leanexplore:387789
leanexplore_sqlite
leanexplore_declarations
/-- Unpaired f ⟨x, y⟩ := f x y, cf `Nat.unparied`. -/ def UnpairedPoly : SKI.Polynomial 2 := &0 ⬝' (Fst ⬝' &1) ⬝' (Snd ⬝' &1)
86
leanexplore_declaration
leanexplore:387790
leanexplore_sqlite
leanexplore_declarations
/-- A term representing Unpaired -/ protected def Unpaired : SKI := UnpairedPoly.toSKI
134
leanexplore_declaration
leanexplore:387791
leanexplore_sqlite
leanexplore_declarations
theorem unpaired_def (f p : SKI) : (SKI.Unpaired ⬝ f ⬝ p) ↠ f ⬝ (Fst ⬝ p) ⬝ (Snd ⬝ p) := UnpairedPoly.toSKI_correct [f, p] (by simp)
289
leanexplore_declaration
leanexplore:387792
leanexplore_sqlite
leanexplore_declarations
theorem unpaired_correct (f x y : SKI) : (SKI.Unpaired ⬝ f ⬝ (MkPair ⬝ x ⬝ y)) ↠ f ⬝ x ⬝ y := by trans f ⬝ (Fst ⬝ (MkPair ⬝ x ⬝ y)) ⬝ (Snd ⬝ (MkPair ⬝ x ⬝ y)) · exact unpaired_def f _ · apply parallel_mRed · apply MRed.tail exact fst_correct _ _ · exact snd_correct _ _
121
leanexplore_declaration
leanexplore:387793
leanexplore_sqlite
leanexplore_declarations
/-- Pair f g x := ⟨f x, g x⟩, cf `Primrec.Pair`. -/ def PairPoly : SKI.Polynomial 3 := MkPair ⬝' (&0 ⬝' &2) ⬝' (&1 ⬝' &2)
78
leanexplore_declaration
leanexplore:387794
leanexplore_sqlite
leanexplore_declarations
/-- A SKI term representing Pair -/ protected def Pair : SKI := PairPoly.toSKI
132
leanexplore_declaration
leanexplore:387795
leanexplore_sqlite
leanexplore_declarations
theorem pair_def (f g x : SKI) : (SKI.Pair ⬝ f ⬝ g ⬝ x) ↠ MkPair ⬝ (f ⬝ x) ⬝ (g ⬝ x) := PairPoly.toSKI_correct [f, g, x] (by simp)
621
leanexplore_declaration
leanexplore:387796
leanexplore_sqlite
leanexplore_declarations
/-- A reduction step allowing simultaneous reduction of disjoint redexes -/ @[reduction_sys "ₚ"] inductive ParallelReduction : SKI → SKI → Prop /-- Parallel reduction is reflexive, -/ | refl (a : SKI) : ParallelReduction a a /-- Contains `Red`, -/ | red_I (a : SKI) : ParallelReduction (I ⬝ a) a | red_K (a b :...
82
leanexplore_declaration
leanexplore:387797
leanexplore_sqlite
leanexplore_declarations
/-- Parallel reduction is reflexive, -/ | refl (a : SKI) : ParallelReduction a a
72
leanexplore_declaration
leanexplore:387798
leanexplore_sqlite
leanexplore_declarations
/-- Contains `Red`, -/ | red_I (a : SKI) : ParallelReduction (I ⬝ a) a
53
leanexplore_declaration
leanexplore:387799
leanexplore_sqlite
leanexplore_declarations
| red_K (a b : SKI) : ParallelReduction (K ⬝ a ⬝ b) a
75
leanexplore_declaration
leanexplore:387800
leanexplore_sqlite
leanexplore_declarations
| red_S (a b c : SKI) : ParallelReduction (S ⬝ a ⬝ b ⬝ c) (a ⬝ c ⬝ (b ⬝ c))
181
leanexplore_declaration
leanexplore:387801
leanexplore_sqlite
leanexplore_declarations
/-- and allows simultaneous reduction of disjoint redexes. -/ | par ⦃a a' b b' : SKI⦄ : ParallelReduction a a' → ParallelReduction b b' → ParallelReduction (a ⬝ b) (a' ⬝ b')
652
leanexplore_declaration
leanexplore:387802
leanexplore_sqlite
leanexplore_declarations
@[reduction_sys "ₚ"] inductive ParallelReduction : SKI → SKI → Prop /-- Parallel reduction is reflexive, -/ | refl (a : SKI) : ParallelReduction a a /-- Contains `Red`, -/ | red_I (a : SKI) : ParallelReduction (I ⬝ a) a | red_K (a b : SKI) : ParallelReduction (K ⬝ a ⬝ b) a | red_S (a b c : SKI) : ParallelRe...
498
leanexplore_declaration
leanexplore:387804
leanexplore_sqlite
leanexplore_declarations
/-- The inclusion `⭢ₚ ⊆ ↠` -/ theorem mRed_of_parallelReduction {a a' : SKI} (h : a ⭢ₚ a') : a ↠ a' := by cases h case refl => exact Relation.ReflTransGen.refl case par a a' b b' ha hb => apply parallel_mRed · exact mRed_of_parallelReduction ha · exact mRed_of_parallelReduction hb case red_I => exac...
524
leanexplore_declaration
leanexplore:387805
leanexplore_sqlite
leanexplore_declarations
/-- The inclusion `⭢ ⊆ ⭢ₚ` -/ theorem parallelReduction_of_red {a a' : SKI} (h : a ⭢ a') : a ⭢ₚ a' := by cases h case red_S => apply ParallelReduction.red_S case red_K => apply ParallelReduction.red_K case red_I => apply ParallelReduction.red_I case red_head a a' b h => apply ParallelReduction.par · e...
506
leanexplore_declaration
leanexplore:387806
leanexplore_sqlite
leanexplore_declarations
/-- The inclusions of `mRed_of_parallelReduction` and `parallelReduction_of_red` imply that `⭢` and `⭢ₚ` have the same reflexive-transitive closure. -/ theorem reflTransGen_parallelReduction_mRed : ReflTransGen ParallelReduction = ReflTransGen Red := by ext a b constructor · apply Relation.reflTransGen_of_isT...
72
leanexplore_declaration
leanexplore:387807
leanexplore_sqlite
leanexplore_declarations
lemma I_irreducible (a : SKI) (h : I ⭢ₚ a) : a = I := by cases h rfl
72
leanexplore_declaration
leanexplore:387808
leanexplore_sqlite
leanexplore_declarations
lemma K_irreducible (a : SKI) (h : K ⭢ₚ a) : a = K := by cases h rfl
181
leanexplore_declaration
leanexplore:387809
leanexplore_sqlite
leanexplore_declarations
lemma Ka_irreducible (a c : SKI) (h : (K ⬝ a) ⭢ₚ c) : ∃ a', a ⭢ₚ a' ∧ c = K ⬝ a' := by cases h case refl => use a, .refl a case par b a' h h' => rw [K_irreducible b h]; use a'
72
leanexplore_declaration
leanexplore:387810
leanexplore_sqlite
leanexplore_declarations
lemma S_irreducible (a : SKI) (h : S ⭢ₚ a) : a = S := by cases h rfl
211
leanexplore_declaration
leanexplore:387811
leanexplore_sqlite
leanexplore_declarations
lemma Sa_irreducible (a c : SKI) (h : (S ⬝ a) ⭢ₚ c) : ∃ a', a ⭢ₚ a' ∧ c = S ⬝ a' := by cases h case refl => exact ⟨a, ParallelReduction.refl a, rfl⟩ case par b a' h h' => rw [S_irreducible b h]; use a'
267
leanexplore_declaration
leanexplore:387812
leanexplore_sqlite
leanexplore_declarations
lemma Sab_irreducible (a b c : SKI) (h : (S ⬝ a ⬝ b) ⭢ₚ c) : ∃ a' b', a ⭢ₚ a' ∧ b ⭢ₚ b' ∧ c = S ⬝ a' ⬝ b' := by cases h case refl => use a, b, .refl a, .refl b case par c b' hc hb => let ⟨d, hd⟩ := Sa_irreducible a c hc rw [hd.2] use d, b', hd.1
2,078
leanexplore_declaration
leanexplore:387813
leanexplore_sqlite
leanexplore_declarations
/-- The key result: the Church-Rosser property holds for `⭢ₚ`. The proof is a lengthy case analysis on the reductions `a ⭢ₚ a₁` and `a ⭢ₚ a₂`, but is entirely mechanical. -/ theorem parallelReduction_diamond : Diamond ParallelReduction := by intro a a₁ a₂ h₁ h₂ cases h₁ case refl => exact ⟨a₂, h₂, .refl a₂⟩ cas...
180
leanexplore_declaration
leanexplore:387814
leanexplore_sqlite
leanexplore_declarations
theorem join_parallelReduction_equivalence : Equivalence (MJoin ParallelReduction) := Confluent.equivalence_join_reflTransGen <| Diamond.toConfluent parallelReduction_diamond
213
leanexplore_declaration
leanexplore:387815
leanexplore_sqlite
leanexplore_declarations
/-- The **Church-Rosser** theorem in its general form. -/ theorem mJoin_red_equivalence : Equivalence (MJoin Red) := by rw [MJoin, ←reflTransGen_parallelReduction_mRed] exact join_parallelReduction_equivalence
263
leanexplore_declaration
leanexplore:387816
leanexplore_sqlite
leanexplore_declarations
/-- The **Church-Rosser** theorem in the form it is usually stated. -/ theorem MRed.diamond : Confluent Red := by intro a b c hab hac apply mJoin_red_equivalence.trans (y := a) · exact mJoin_red_equivalence.symm (MJoin.single hab) · exact MJoin.single hac
370
leanexplore_declaration
leanexplore:387817
leanexplore_sqlite
leanexplore_declarations
/-- An SKI expression is built from the primitive combinators `S`, `K` and `I`, and application. -/ inductive SKI where /-- `S`-combinator, with semantics $λxyz.xz(yz) -/ | S /-- `K`-combinator, with semantics $λxy.x$ -/ | K /-- `I`-combinator, with semantics $λx.x$ -/ | I /-- Application $x y ↦ xy$ -/ ...
56
leanexplore_declaration
leanexplore:387818
leanexplore_sqlite
leanexplore_declarations
/-- `S`-combinator, with semantics $λxyz.xz(yz) -/ | S
51
leanexplore_declaration
leanexplore:387819
leanexplore_sqlite
leanexplore_declarations
/-- `K`-combinator, with semantics $λxy.x$ -/ | K
50
leanexplore_declaration
leanexplore:387820
leanexplore_sqlite
leanexplore_declarations
/-- `I`-combinator, with semantics $λx.x$ -/ | I
55
leanexplore_declaration
leanexplore:387821
leanexplore_sqlite
leanexplore_declarations
/-- Application $x y ↦ xy$ -/ | app : SKI → SKI → SKI
158
leanexplore_declaration
leanexplore:387826
leanexplore_sqlite
leanexplore_declarations
@[inherit_doc] scoped infixl:100 " ⬝ " => app /-- Apply a term to a list of terms -/ def applyList (f : SKI) (xs : List SKI) : SKI := List.foldl (· ⬝ ·) f xs
111
leanexplore_declaration
leanexplore:387827
leanexplore_sqlite
leanexplore_declarations
/-- Apply a term to a list of terms -/ def applyList (f : SKI) (xs : List SKI) : SKI := List.foldl (· ⬝ ·) f xs
134
leanexplore_declaration
leanexplore:387828
leanexplore_sqlite
leanexplore_declarations
lemma applyList_concat (f : SKI) (ys : List SKI) (z : SKI) : f.applyList (ys ++ [z]) = f.applyList ys ⬝ z := by simp [applyList]
143
leanexplore_declaration
leanexplore:387829
leanexplore_sqlite
leanexplore_declarations
/-- The size of an SKI term is its number of combinators. -/ def size : SKI → Nat | S => 1 | K => 1 | I => 1 | x ⬝ y => size x + size y
541
leanexplore_declaration
leanexplore:387830
leanexplore_sqlite
leanexplore_declarations
/-- Single-step reduction of SKI terms -/ @[scoped grind, reduction_sys] inductive Red : SKI → SKI → Prop where /-- The operational semantics of the `S`, -/ | red_S (x y z : SKI) : Red (S ⬝ x ⬝ y ⬝ z) (x ⬝ z ⬝ (y ⬝ z)) /-- `K`, -/ | red_K (x y : SKI) : Red (K ⬝ x ⬝ y) x /-- and `I` combinators. -/ | red_I (...
108
leanexplore_declaration
leanexplore:387831
leanexplore_sqlite
leanexplore_declarations
/-- The operational semantics of the `S`, -/ | red_S (x y z : SKI) : Red (S ⬝ x ⬝ y ⬝ z) (x ⬝ z ⬝ (y ⬝ z))
53
leanexplore_declaration
leanexplore:387832
leanexplore_sqlite
leanexplore_declarations
/-- `K`, -/ | red_K (x y : SKI) : Red (K ⬝ x ⬝ y) x
63
leanexplore_declaration
leanexplore:387833
leanexplore_sqlite
leanexplore_declarations
/-- and `I` combinators. -/ | red_I (x : SKI) : Red (I ⬝ x) x
94
leanexplore_declaration
leanexplore:387834
leanexplore_sqlite
leanexplore_declarations
/-- Reduction on the head -/ | red_head (x x' y : SKI) (_ : Red x x') : Red (x ⬝ y) (x' ⬝ y)
97
leanexplore_declaration
leanexplore:387835
leanexplore_sqlite
leanexplore_declarations
/-- and tail of an SKI term. -/ | red_tail (x y y' : SKI) (_ : Red y y') : Red (x ⬝ y) (x ⬝ y')
859
leanexplore_declaration
leanexplore:387836
leanexplore_sqlite
leanexplore_declarations
@[scoped grind, reduction_sys] inductive Red : SKI → SKI → Prop where /-- The operational semantics of the `S`, -/ | red_S (x y z : SKI) : Red (S ⬝ x ⬝ y ⬝ z) (x ⬝ z ⬝ (y ⬝ z)) /-- `K`, -/ | red_K (x y : SKI) : Red (K ⬝ x ⬝ y) x /-- and `I` combinators. -/ | red_I (x : SKI) : Red (I ⬝ x) x /-- Reduction o...
247
leanexplore_declaration
leanexplore:387838
leanexplore_sqlite
leanexplore_declarations
lemma Red.ne {x y : SKI} : (x ⭢ y) → x ≠ y | red_S _ _ _, h => by cases h | red_K _ _, h => by cases h | red_I _, h => by cases h | red_head _ _ _ h', h => Red.ne h' (SKI.app.inj h).1 | red_tail _ _ _ h', h => Red.ne h' (SKI.app.inj h).2
89
leanexplore_declaration
leanexplore:387839
leanexplore_sqlite
leanexplore_declarations
theorem MRed.S (x y z : SKI) : (S ⬝ x ⬝ y ⬝ z) ↠ (x ⬝ z ⬝ (y ⬝ z)) := .single <| red_S ..
67
leanexplore_declaration
leanexplore:387840
leanexplore_sqlite
leanexplore_declarations
theorem MRed.K (x y : SKI) : (K ⬝ x ⬝ y) ↠ x := .single <| red_K ..
61
leanexplore_declaration
leanexplore:387841
leanexplore_sqlite
leanexplore_declarations
theorem MRed.I (x : SKI) : (I ⬝ x) ↠ x := .single <| red_I ..
104
leanexplore_declaration
leanexplore:387842
leanexplore_sqlite
leanexplore_declarations
theorem MRed.head {a a' : SKI} (b : SKI) (h : a ↠ a') : (a ⬝ b) ↠ (a' ⬝ b) := by induction h <;> grind
104
leanexplore_declaration
leanexplore:387843
leanexplore_sqlite
leanexplore_declarations
theorem MRed.tail (a : SKI) {b b' : SKI} (h : b ↠ b') : (a ⬝ b) ↠ (a ⬝ b') := by induction h <;> grind
144
leanexplore_declaration
leanexplore:387844
leanexplore_sqlite
leanexplore_declarations
lemma parallel_mRed {a a' b b' : SKI} (ha : a ↠ a') (hb : b ↠ b') : (a ⬝ b) ↠ (a' ⬝ b') := Trans.simple (MRed.head b ha) (MRed.tail a' hb)
117
leanexplore_declaration
leanexplore:387845
leanexplore_sqlite
leanexplore_declarations
lemma parallel_red {a a' b b' : SKI} (ha : a ⭢ a') (hb : b ⭢ b') : (a ⬝ b) ↠ (a' ⬝ b') := by trans a' ⬝ b <;> grind
152
leanexplore_declaration
leanexplore:387846
leanexplore_sqlite
leanexplore_declarations
theorem mJoin_red_head {x x' : SKI} (y : SKI) : MJoin Red x x' → MJoin Red (x ⬝ y) (x' ⬝ y) | ⟨z, hz, hz'⟩ => ⟨z ⬝ y, MRed.head y hz, MRed.head y hz'⟩
152
leanexplore_declaration
leanexplore:387847
leanexplore_sqlite
leanexplore_declarations
theorem mJoin_red_tail (x : SKI) {y y' : SKI} : MJoin Red y y' → MJoin Red (x ⬝ y) (x ⬝ y') | ⟨z, hz, hz'⟩ => ⟨x ⬝ z, MRed.tail x hz, MRed.tail x hz'⟩
433
leanexplore_declaration
leanexplore:387848
leanexplore_sqlite
leanexplore_declarations
/-- The predicate that a term has no reducible sub-terms. -/ def RedexFree : SKI → Prop | S => True | K => True | I => True | S ⬝ x => x.RedexFree | K ⬝ x => x.RedexFree | I ⬝ _ => False | S ⬝ x ⬝ y => x.RedexFree ∧ y.RedexFree | K ⬝ _ ⬝ _ => False | I ⬝ _ ⬝ _ => False | S ⬝ _ ⬝ _ ⬝ _ => False | K...
1,197
leanexplore_declaration
leanexplore:387849
leanexplore_sqlite
leanexplore_declarations
/-- One-step evaluation as a function: either it returns a term that has been reduced by one step, or a proof that the term is redex free. Uses normal-order reduction. -/ def evalStep : (x : SKI) → PLift (x.RedexFree) ⊕ SKI | S => Sum.inl (PLift.up trivial) | K => Sum.inl (PLift.up trivial) | I => Sum.inl (PLift....
2,153
leanexplore_declaration
leanexplore:387850
leanexplore_sqlite
leanexplore_declarations
/-- The normal-order reduction implemented by `evalStep` indeed computes a one-step reduction. -/ theorem evalStep_right_correct : (x y : SKI) → (x.evalStep = Sum.inr y) → x ⭢ y | S ⬝ x, a, h => match hx : x.evalStep with | Sum.inl _ => by simp only [hx, evalStep, reduceCtorEq] at h | Sum.inr x' => by ...
222
leanexplore_declaration
leanexplore:387851
leanexplore_sqlite
leanexplore_declarations
theorem redexFree_of_normal_red {x : SKI} (h : Normal Red x) : x.RedexFree := by match hx : x.evalStep with | Sum.inl h' => exact h'.down | Sum.inr y => rw [Normal_iff] at h; cases h _ (evalStep_right_correct x y hx)
691
leanexplore_declaration
leanexplore:387852
leanexplore_sqlite
leanexplore_declarations
theorem RedexFree.normal_red {x : SKI} (hx : x.RedexFree) : Normal Red x := by simp_rw [Normal_iff] intro y hy match x, hx, y, hy with | S ⬝ x, hx, S ⬝ y, red_tail _ _ _ hx' => rw [RedexFree] at hx; exact hx.normal_red ⟨_, hx'⟩ | K ⬝ x, hx, K ⬝ y, red_tail _ _ _ hx' => rw [RedexFree] at hx; exact hx.normal_re...
176
leanexplore_declaration
leanexplore:387853
leanexplore_sqlite
leanexplore_declarations
/-- A term is redex free iff it has no one-step reductions. -/ theorem redexFree_iff {x : SKI} : x.RedexFree ↔ Normal Red x := ⟨RedexFree.normal_red, redexFree_of_normal_red⟩
396
leanexplore_declaration
leanexplore:387854
leanexplore_sqlite
leanexplore_declarations
theorem redexFree_iff_evalStep {x : SKI} : x.RedexFree ↔ (x.evalStep).isLeft = true := by constructor case mp => intro h match hx : x.evalStep with | Sum.inl h' => exact rfl | Sum.inr y => cases h.normal_red ⟨_, (evalStep_right_correct _ _ hx)⟩ case mpr => intro h match hx : x.evalStep wit...