{-# OPTIONS --safe #-}
open import Level
open import Data.Product as Σ
open import Data.Sum as ⊎
open import Data.Nat as ℕ hiding (_⊔_)
open import Data.Nat.Properties as ℕ
open import Data.Unit
open import Data.Empty
open import Function.Base
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Negation
open import Game-Basics
import Game-Definitions as Defs
module Learner-Correctness {ℓd : Level}
(𝔻 : Set ℓd)
(F : Game-Type)
(Sem : Defs.GameSemantics 𝔻 F)
where
open import Game-Definitions 𝔻 F
open GameSemantics Sem
record Learner-Stepping {ℓr : Level} {R : Set ℓr} {ℓc : Level} {C : Set ℓc} (c : Learnerδ R C) (q₀ : C) (bound : 𝔻 → ℕ): Set (Level.suc ℓd ⊔ Level.suc ℓc ⊔ ℓr) where
field
ticks : C → ℕ
allows : C → (𝔻 → Set ℓc)
q₀-correct : ∀ sec → allows q₀ sec
ticks-below-bound : ∀ q sec → allows q sec → ticks q < bound sec
q'-correct : 𝔻 → ℕ → (𝔻 → Set) × C → Set ℓc
q'-correct d ticks-q (_∈response , q') = d ∈response → allows q' d × ticks-q < ticks q'
field
preserve : ∀ {q} {d} → allows q d → ⟦F c q ⟧ ⊧F∀ q'-correct d (ticks q)
open TeacherNaturality F-map
module Correctness {ℓt ℓc ℓr : Level} {T : Set ℓt} {R : Set ℓr} {C : Set ℓc}
(teacher : Teacher-on T) (learner : Learner-on R C)
(q₀ : C)
where
private
module teacher = Teacher-on teacher
module learner = Learner-on learner
open Game Sem teacher.δ learner.δ
module learner-correct-proof-details
(bound : 𝔻 → ℕ)
(correct : Learner-Stepping learner.δ q₀ bound)
(n : 𝔻)
where
open Learner-Stepping correct
game-step-prop' : (l : C) → allows l n → M R T (Σ ((𝔻 → Set) × C) (q'-correct n (ticks l)))
game-step-prop' l n∈l = teacher.δ (F∀-elim ⟦F learner.δ l ⟧ (preserve n∈l))
proj₁∘game-step-prop' : (l : C) → (n∈l : allows l n) → (t : T) → game-step-prop (t , l) ≡ M-map proj₁ (game-step-prop' l n∈l) t
proj₁∘game-step-prop' l n∈l t =
begin
game-step-prop (t , l) ≡⟨ cong (λ - → teacher.δ - t) (proj₁∘F∀elim (preserve n∈l)) ⟨
teacher.δ (F-map proj₁ (F∀-elim ⟦F learner.δ l ⟧ (preserve n∈l))) t ≡⟨ teacher.natural proj₁ _ t ⟨
M-map proj₁ (teacher.δ (F∀-elim ⟦F learner.δ l ⟧ (preserve n∈l))) t
∎
where
open ≡-Reasoning
main-induction : (steps-remaining : ℕ) (t : T) (l : C)
→ (allows l n)
→ bound n ≤ steps-remaining + ticks l
→ learner (t , l) finds n within steps-remaining rounds
main-induction ℕ.zero t l n∈l bound≤tick = ⊥-elim (ℕ.<⇒≱ (ticks-below-bound l n n∈l) bound≤tick)
main-induction (ℕ.suc s) t l n∈l bound≤tick rewrite (proj₁∘game-step-prop' l n∈l t) with (teacher.δ (F∀-elim ⟦F learner.δ l ⟧ (preserve n∈l)) t)
... | (inj₁ _) = tt
... | (inj₂ (t' , (_∈response , l') , l'-prop )) = λ n∈response →
let
n∈l' , ticks-l<ticks-l' = l'-prop n∈response
open ≤-Reasoning
bound[n]≤s+ticks-l' : bound n ≤ s + ticks l'
bound[n]≤s+ticks-l' =
begin
bound n ≤⟨ bound≤tick ⟩
1 + s + ticks l ≡⟨ ℕ.+-suc s _ ⟨
s + (1 + ticks l) ≤⟨ +-mono-≤ (≤-reflexive refl) ticks-l<ticks-l' ⟩
s + ticks l'
∎
in
main-induction s t' l' n∈l' bound[n]≤s+ticks-l'
learner-correct : (bound : 𝔻 → ℕ)
→ Learner-Stepping learner.δ q₀ bound
→ ∀ st₀ n → learner (st₀ , q₀) finds n within (bound n) rounds
learner-correct bound learner-correct st₀ n =
main-induction (bound n) st₀ q₀ (q₀-correct n) (m≤m+n (bound n) _)
where
open Learner-Stepping learner-correct
open learner-correct-proof-details bound learner-correct n