Skip to content

Commit

Permalink
move some code out of Conal/Language.lean into appropriate files
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Aug 26, 2024
1 parent 785ac79 commit d1b4432
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 62 deletions.
2 changes: 2 additions & 0 deletions Katydid.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Katydid.Example.SimpLibrary
import Katydid.Expr.Desc
import Katydid.Expr.Regex

import Katydid.Conal.Decidability
import Katydid.Conal.Language
import Katydid.Conal.Calculus
import Katydid.Conal.Examples
import Katydid.Conal.Symbolic
2 changes: 1 addition & 1 deletion Katydid/Conal/Calculus.lean
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def derivative_char:
intros a c
unfold δ'
unfold char
unfold emptyStr
unfold emptystr
unfold scalar
sorry

Expand Down
39 changes: 39 additions & 0 deletions Katydid/Conal/Decidability.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- A translation to Lean from Agda
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Decidability.lagda


-- data Dec (A: Set l):Set l where
-- yes: A → Dec A
-- no :¬A → Dec A
inductive Dec (α: Type u): Type u where
| yes: α -> Dec α
| no: (α -> PEmpty.{u}) -> Dec α

-- ⊥? : Dec ⊥
-- ⊥? =no(𝜆())
def empty? : Dec PEmpty :=
Dec.no (by intro; contradiction)

def unit? : Dec PUnit :=
Dec.yes PUnit.unit

def sum? (a: Dec α) (b: Dec β): Dec (α ⊕ β) :=
match (a, b) with
| (Dec.no a, Dec.no b) =>
Dec.no (fun ab =>
match ab with
| Sum.inl sa => a sa
| Sum.inr sb => b sb
)
| (Dec.yes a, Dec.no _) =>
Dec.yes (Sum.inl a)
| (_, Dec.yes b) =>
Dec.yes (Sum.inr b)

def prod? (a: Dec α) (b: Dec β): Dec (α × β) :=
match (a, b) with
| (Dec.yes a, Dec.yes b) => Dec.yes (Prod.mk a b)
| (Dec.no a, Dec.yes _) => Dec.no (fun ⟨a', _⟩ => a a')
| (_, Dec.no b) => Dec.no (fun ⟨_, b'⟩ => b b')

def list?: Dec α -> Dec (List α) := fun _ => Dec.yes []
67 changes: 6 additions & 61 deletions Katydid/Conal/Language.lean
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- A translation to Lean from Agda
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Language.lagda
import Katydid.Std.Tipe

open List
import Katydid.Std.Tipe

-- module Language {ℓ} (A : Set ℓ) where
universe u
Expand All @@ -25,13 +24,13 @@ variable {α : Type u}

-- ∅ : Lang
-- ∅ w = ⊥
def emptySet : dLang α :=
def emptyset : dLang α :=
-- PEmpty is Empty, but allows specifying the universe
-- PEmpty is a Sort, which works for both Prop and Type
fun _ => PEmpty

-- `(priority := high)` is required to avoid the error: "ambiguous, possible interpretations"
notation (priority := high) "∅" => dLang.emptySet -- backslash emptyset
notation (priority := high) "∅" => dLang.emptyset -- backslash emptyset

-- 𝒰 : Lang
-- 𝒰 w = ⊤
Expand All @@ -44,10 +43,10 @@ notation "𝒰" => dLang.universal -- backslash McU

-- 𝟏 : Lang
-- 𝟏 w = w ≡ []
def emptyStr : dLang α :=
def emptystr : dLang α :=
fun w => w ≡ []

notation "ε" => dLang.emptyStr -- backslash epsilon
notation "ε" => dLang.emptystr -- backslash epsilon

-- ` : A → Lang
-- ` c w = w ≡ [ c ]
Expand Down Expand Up @@ -98,13 +97,8 @@ def star (P : dLang α) : dLang α :=

postfix:6 "*" => dLang.star

-- TODO: What does proof relevance even mean for the `not` operator?
def not (P: dLang α) : dLang α :=
fun (w: List α) =>
P w -> Empty

-- attribute [simp] allows these definitions to be unfolded when using the simp tactic.
attribute [simp] universal emptySet emptyStr char scalar or and concat star
attribute [simp] universal emptyset emptystr char scalar or and concat star

example: dLang α := 𝒰
example: dLang α := ε
Expand Down Expand Up @@ -141,55 +135,6 @@ def δ (f: dLang α) (a: α): (dLang α) :=

end dLang

-- data Dec (A: Set l):Set l where
-- yes: A → Dec A
-- no :¬A → Dec A
inductive Dec (α: Type u): Type u where
| yes: α -> Dec α
| no: (α -> PEmpty.{u}) -> Dec α

-- ⊥? : Dec ⊥
-- ⊥? =no(𝜆())
def empty? : Dec PEmpty :=
Dec.no (by intro; contradiction)

def unit? : Dec PUnit :=
Dec.yes PUnit.unit

def sum? (a: Dec α) (b: Dec β): Dec (α ⊕ β) :=
match (a, b) with
| (Dec.no a, Dec.no b) =>
Dec.no (fun ab =>
match ab with
| Sum.inl sa => a sa
| Sum.inr sb => b sb
)
| (Dec.yes a, Dec.no _) =>
Dec.yes (Sum.inl a)
| (_, Dec.yes b) =>
Dec.yes (Sum.inr b)

def prod? (a: Dec α) (b: Dec β): Dec (α × β) :=
match (a, b) with
| (Dec.yes a, Dec.yes b) => Dec.yes (Prod.mk a b)
| (Dec.no a, Dec.yes _) => Dec.no (fun ⟨a', _⟩ => a a')
| (_, Dec.no b) => Dec.no (fun ⟨_, b'⟩ => b b')

def list?: Dec α -> Dec (List α) := fun _ => Dec.yes []



inductive Lang : (List α -> Type u) -> Type (u + 1) where
-- | emptySet : Lang dLang.emptySet
| universal : Lang (fun _ => PUnit)
-- | emptyStr : Lang dLang.emptyStr
-- | char {a: Type u}: (a: α) -> Lang (dLang.char a)
-- | or : Lang P -> Lang Q -> Lang (dLang.or P Q)
-- | and : Lang P -> Lang Q -> Lang (dLang.and P Q)
-- | scalar {s: Type u}: (Dec s) -> Lang P -> Lang (dLang.scalar s P)
-- | concat : Lang P -> Lang Q -> Lang (dLang.concat P Q)
-- | star : Lang P -> Lang (dLang.star P)

-- TODO: 𝜈 : Lang P → Dec (⋄.𝜈 P)
-- theorem ν {α: Type u} {P: dLang α} (f: Lang P): Dec (dLang.ν P) := by
-- induction f with
Expand Down
19 changes: 19 additions & 0 deletions Katydid/Conal/Symbolic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- A translation to Lean from Agda
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Symbolic.lagda

import Katydid.Conal.Decidability
import Katydid.Conal.Language

variable {P Q : dLang α}
variable {s : Type u}

inductive Lang : (List α -> Type u) -> Type (u + 1) where
| emptySet : Lang dLang.emptyset
| universal : Lang (fun _ => PUnit)
| emptyStr : Lang dLang.emptystr
| char {a: Type u}: (a: α) -> Lang (dLang.char a)
| or : Lang P -> Lang Q -> Lang (dLang.or P Q)
| and : Lang P -> Lang Q -> Lang (dLang.and P Q)
| scalar {s: Type u}: (Dec s) -> Lang P -> Lang (dLang.scalar s P)
| concat : Lang P -> Lang Q -> Lang (dLang.concat P Q)
| star : Lang P -> Lang (dLang.star P)

0 comments on commit d1b4432

Please sign in to comment.