Skip to content

Commit

Permalink
remove language notation as a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Aug 26, 2024
1 parent 94ce085 commit baa0f85
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 47 deletions.
1 change: 0 additions & 1 deletion Katydid.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ import Katydid.Expr.Desc
import Katydid.Expr.Regex

import Katydid.Conal.Language
import Katydid.Conal.LanguageNotation
import Katydid.Conal.Calculus
import Katydid.Conal.Examples
10 changes: 5 additions & 5 deletions Katydid/Conal/Calculus.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- A translation to Lean from Agda
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Calculus.lagda

import Katydid.Conal.LanguageNotation
import Katydid.Conal.Language
import Mathlib.Logic.Equiv.Defs -- ≃
import Katydid.Std.Tipe
open dLang
Expand All @@ -27,7 +27,7 @@ def example_of_proof_relevant_parse : (char 'a' ⋃ char 'b') (toList "a") -> Na
| mk eq =>
contradiction

def example_of_proof_relevant_parse2 : (char 'a', (char 'b' ⋃ char 'c')) (toList "ab") -> Nat := by
def example_of_proof_relevant_parse2 : (concat (char 'a') (char 'b' ⋃ char 'c')) (toList "ab") -> Nat := by
intro x1
simp at x1
cases x1 with
Expand Down Expand Up @@ -178,7 +178,7 @@ def nullable_scalar:
-- (λ { (([] , []) , refl , νP , νQ) → refl})
def nullable_concat:
∀ (P Q: dLang α),
ν' (P, Q) ≃ (Prod (ν' Q) (ν' P)) := by
ν' (concat P Q) ≃ (Prod (ν' Q) (ν' P)) := by
-- TODO
sorry

Expand Down Expand Up @@ -301,7 +301,7 @@ def derivative_scalar:
def derivative_concat:
∀ (a: α) (P Q: dLang α),
-- TODO: Redo this definition to do extensional isomorphism: `⟷` properly
(δ' (P , Q) a) ≡ dLang.scalar (ν' P) ((δ' Q a) ⋃ ((δ' P a), Q)) := by
(δ' (concat P Q) a) ≡ dLang.scalar (ν' P) ((δ' Q a) ⋃ (concat (δ' P a) Q)) := by
-- TODO
sorry

Expand Down Expand Up @@ -341,6 +341,6 @@ def derivative_concat:
def derivative_star:
∀ (a: α) (P: dLang α),
-- TODO: Redo this definition to do extensional isomorphism: `⟷` properly
(δ' (P *) a) ≡ dLang.scalar (List (ν' P)) (δ' P a, P *) := by
(δ' (P *) a) ≡ dLang.scalar (List (ν' P)) (concat (δ' P a) (P *)) := by
-- TODO
sorry
10 changes: 5 additions & 5 deletions Katydid/Conal/Examples.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- A translation to Lean from Agda
-- https://github.com/conal/paper-2021-language-derivatives/blob/main/Examples.lagda

import Katydid.Conal.LanguageNotation
import Katydid.Conal.Language
open dLang

example: (dLang.char 'a') ['a'] := by
Expand All @@ -27,25 +27,25 @@ example : (char 'a' ⋃ char 'b') (String.toList "b") := by

-- _ : a⋆b ('a' ∷ 'b' ∷ [])
-- _ = ([ 'a' ] , [ 'b' ]) , refl , refl , refl
example : (char 'a', char 'b') (String.toList "ab") := by
example : (concat (char 'a') (char 'b')) (String.toList "ab") := by
simp
exists ['a']
exists ['b']
exists trfl
exists trfl

example : (char 'a', char 'b') (String.toList "ab") := by
example : (concat (char 'a') (char 'b')) (String.toList "ab") := by
simp
refine PSigma.mk ['a'] ?a
refine PSigma.mk ['b'] ?b
refine PSigma.mk trfl ?c
refine PSigma.mk trfl ?d
rfl

example : (char 'a', char 'b') (String.toList "ab") :=
example : (concat (char 'a') (char 'b')) (String.toList "ab") :=
PSigma.mk ['a'] (PSigma.mk ['b'] (PSigma.mk trfl (PSigma.mk trfl rfl)))

example : (char 'a', char 'b') (String.toList "ab") :=
example : (concat (char 'a') (char 'b')) (String.toList "ab") :=
PSigma.mk ['a'] (PSigma.mk ['b'] (PSigma.mk trfl (PSigma.mk trfl rfl)))

example : ((char 'a')*) (String.toList "a") := by sorry
Expand Down
29 changes: 29 additions & 0 deletions Katydid/Conal/Language.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ def emptySet : dLang α :=
-- 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

-- 𝒰 : Lang
-- 𝒰 w = ⊤
def universal : dLang α :=
-- PUnit is Empty, but allows specifying the universe
-- PUnit is a Sort, which works for both Prop and Type
fun _ => PUnit

notation "𝒰" => dLang.universal -- backslash McU

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

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

-- ` : A → Lang
-- ` c w = w ≡ [ c ]
def char (a : α): dLang α :=
Expand All @@ -53,18 +60,24 @@ def char (a : α): dLang α :=
def scalar (s : Type u) (P : dLang α) : dLang α :=
fun w => s × P w

infixl:4 " · " => dLang.scalar -- backslash .

-- infixr 6 _∪_
-- _∪_ : Op₂ Lang
-- (P ∪ Q) w = P w ⊎ Q w
def or (P : dLang α) (Q : dLang α) : dLang α :=
fun w => P w ⊕ Q w

infixl:5 (priority := high) " ⋃ " => dLang.or -- backslash U

-- infixr 6 _∩_
-- _∩_ : Op₂ Lang
-- (P ∩ Q) w = P w × Q w
def and (P : dLang α) (Q : dLang α) : dLang α :=
fun w => P w × Q w

infixl:4 " ⋂ " => dLang.and -- backslash I

-- infixl 7 _⋆_
-- _⋆_ : Op₂ Lang
-- (P ⋆ Q) w = ∃⇃ λ (u , v) → (w ≡ u ⊙ v) × P u × Q v
Expand All @@ -83,6 +96,8 @@ def star (P : dLang α) : dLang α :=
fun (w : List α) =>
Σ' (ws : List (List α)), (_pws: All P ws) ×' w = (List.join ws)

postfix:6 "*" => dLang.star

-- TODO: What does proof relevance even mean for the `not` operator?
def not (P: dLang α) : dLang α :=
fun (w: List α) =>
Expand All @@ -91,6 +106,20 @@ def not (P: dLang α) : dLang α :=
-- attribute [simp] allows these definitions to be unfolded when using the simp tactic.
attribute [simp] universal emptySet emptyStr char scalar or and concat star

example: dLang α := 𝒰
example: dLang α := ε
example: dLang α := (ε ⋃ 𝒰)
example: dLang α := (ε ⋂ 𝒰)
example: dLang α := ∅
example: dLang α := (∅*)
example: dLang Char := char 'a'
example: dLang Char := char 'b'
example: dLang Char := (char 'a' ⋂ ∅)
example: dLang Char := (char 'a' ⋂ char 'b')
example: dLang Nat := (char 1 ⋂ char 2)
example: (_t: Type) -> dLang Nat := (PUnit · char 2)
example: dLang Nat := (concat (char 1) (char 2))

-- 𝜈 :(A✶ → B) → B -- “nullable”
-- 𝜈 f = f []
-- nullable
Expand Down
36 changes: 0 additions & 36 deletions Katydid/Conal/LanguageNotation.lean

This file was deleted.

0 comments on commit baa0f85

Please sign in to comment.