{-# OPTIONS --safe #-}
open import Level
import DFA as D
open import Data.Nat
open import Data.Sum
open import Data.Empty
open import Data.List
import Data.Nat.Properties as ℕ
open import Data.Product
open import Function.Base
open import Relation.Binary.PropositionalEquality
module DFA-Examples.Enumerator (A : Set 0ℓ) (dfa[_] : ℕ → D.DFA A) where
open import DFA A
open import DFALearning A
open import Game-Definitions DFA F
open import Learner-Correctness DFA F DFALearning-Semantics
δ : Learnerδ DFA ℕ
δ n = equivalence dfa[ n ] dfa[ n ] (λ _ → 1 + n)
enumerator : Learner 0ℓ
enumerator = record
{ C = ℕ
; R = DFA
; q₀ = 0
; learner-on = record {
δ = δ
}
}
module enumerator-correct
(b : DFA → ℕ)
(surjective : ∀ (M : DFA) → M ≈ dfa[ b M ])
where
bound : DFA → ℕ
bound M = 1 + b M
enumerator-step-bounded : Learner-Stepping δ 0 bound
enumerator-step-bounded =
record
{ ticks = id
; allows = λ n M → n ≤ b M
; q₀-correct = λ _ → z≤n
; ticks-below-bound = λ _ _ q≤idx → s≤s q≤idx
; preserve = λ {n} {M} n≤idx[M] w M⟦w⟧≢dfa[n]⟦w⟧ →
case (ℕ.m≤n⇒m<n∨m≡n n≤idx[M]) of λ
{ (inj₁ n<idx[M]) → n<idx[M] , s≤s (ℕ.≤-reflexive refl)
; (inj₂ n≡idx[M]) →
⊥-elim (M⟦w⟧≢dfa[n]⟦w⟧ (begin
⟦DFA M ⟧ w ≡⟨ (surjective M) w ⟩
⟦DFA dfa[ b M ] ⟧ w ≡⟨ cong (λ - → ⟦DFA dfa[ - ] ⟧ w) n≡idx[M] ⟨
⟦DFA dfa[ n ] ⟧ w
∎))
}
}
where open ≡-Reasoning
thm : ∀ {ℓt} (teacher : DFATeacher ℓt)
→ enumerator defeats teacher with-bound (λ - → 1 + b -)
thm teacher =
Correctness.learner-correct
(Teacher.teacher-on (DFATeacher⇒Teacher teacher))
(record { δ = δ }) 0 bound enumerator-step-bounded (DFATeacher.st₀ teacher)
where
open TeacherNaturality F-map