Quantcast
Channel: Understanding failures of recursive calls on simple proof about FSA and regular languages in Agda - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Understanding failures of recursive calls on simple proof about FSA and regular languages in Agda

$
0
0

I'm trying to prove that a simple FSA in Agda only accepts string which end in zero- this is the first example in Sipser's book. I didn't implement evalFSA as a predicate, but rather as function, and am confused as to whether this was the right or wrong choice, as I'm now having trouble proving the soundness and completeness results with respect to the machine and the language, and whether this implementation detail is the cause of my difficululties.

As soon as I pattern match on x below, it highlights the below line blue. what does this mean, why is it doing it, and why does pattern matching on x0 resolve it?

soundM : (xs : List Σ') → evalFSA' M xs → endsIn0 xssoundM (x ∷ []) evM = {!!} soundM (x0 ∷ x1 ∷ xs) evM = {!!}-- soundM (0'∷ []) f = tt

and here is the final issue. why can't I apply the recursive call in the 1' case? the only difference between the f's is the use current state of the machine and the input string, but obviously this seems like a symmetry of the system that shouldn't effect our ability to compute.

soundM' : (xs : List Σ') → evalFSA' M xs → endsIn0 xssoundM' (0'∷ []) evM = ttsoundM' (0'∷ x1 ∷ xs) f = soundM' (x1 ∷ xs) fsoundM' (1'∷ x1 ∷ xs) f = soundM' {!!} f

Here is the inferred f in the 0' case:

f  : modal.helper M 0' (x1 ∷ xs) M xs (δ' S₁ x1) 

And similairly in the 1' case:

f  : modal.helper M 1' (x1 ∷ xs) M xs (δ' S₂ x1)

I'm having, simultaneous issues with what I'm calling completeness as well

completeM : (xs : List Σ') →  endsIn0 xs → evalFSA' M xs ≡⊤completeM (0'∷ []) ex = reflcompleteM (0'∷ x1 ∷ xs) ex = completeM (x1 ∷ xs) excompleteM (1'∷ x1 ∷ xs) ex = {!!}

Here is the code to get here

module fsa whereopen import Boolopen import Level using (_⊔_)open import Data.Nat.Base as Nat using (ℕ; zero; suc; _<′_; _+_)open import Data.List.Base as List using (List; []; _∷_)-- open import Data.Product as Prod using (∃; _×_; _,_)open import Data.Emptyopen import Data.Unitopen import Relation.Binary.PropositionalEquality using (_≡_; refl; subst)-- open import Data.Fin as Finrecord FSA : Set₁ where  field    Q : SetΣ : Setδ : Q →Σ→ Q    q₀ : Q    F : Q → SetevalFSA' : (fsa : FSA) → List (FSA.Σ fsa) → SetevalFSA' fsa [] = ⊥evalFSA' fsa (x ∷ xs) = helper fsa (x ∷ xs) (FSA.q₀ fsa)  where    helper : (fsa : FSA) → List (FSA.Σ fsa) → (FSA.Q fsa) → Set    helper fsa [] q = FSA.F fsa q    helper fsa (x ∷ xs) q = helper fsa xs ((FSA.δ fsa) q x)data Q' : Set where  S₁ : Q'  S₂ : Q'data Σ' : Set where  0' : Σ'  1' : Σ'q₀' : Q'q₀' = S₁F' : Q'→ SetF' S₁ = ⊤F' S₂ = ⊥δ' : Q'→Σ'→ Q'δ' S₁ 0' = S₁δ' S₁ 1' = S₂δ' S₂ 0' = S₁δ' S₂ 1' = S₂M : FSAFSA.Q M = Q'FSA.Σ M = Σ'FSA.δ M = δ'FSA.q₀ M = q₀'FSA.F M = F'exF1  = evalFSA' M (0'∷ [])exF2  = evalFSA' M (1'∷ (0'∷ 0'∷ 1'∷ []))-- a more general endIn that i was orignally trying to use, but likewise failed to get to workdata Dec (A : Set) : Set where  yes : A → Dec A  no  : (A →⊥) → Dec AsigDec : (x y : Σ') → Dec (x ≡ y)sigDec 0' 0' = yes reflsigDec 0' 1' = no (λ ())sigDec 1' 0' = no (λ ())sigDec 1' 1' = yes reflendsIn : {X : Set} → ((x y : X) → Dec (x ≡ y)) → List X → X → SetendsIn d [] x = ⊥endsIn d (x ∷ []) x0 with (d x0 x)... | yes refl = ⊤... | no x1 = ⊥endsIn d (x ∷ x1 ∷ xs) x0 = endsIn d (x1 ∷ xs) x0_endsIn'_ : List Σ'→Σ'→ Setxs endsIn' x = endsIn sigDec xs xendsIn0 : List Σ'→ SetendsIn0 [] = ⊥endsIn0 (0'∷ []) = ⊤endsIn0 (0'∷ x ∷ xs) = endsIn0 (x ∷ xs)endsIn0 (1'∷ xs) = endsIn0 xs-- testing10endsin0 = (1'∷ 0'∷ []) endsIn' 0'n10endsin0 = (1'∷ 1'∷ []) endsIn' 0'

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>