Games.Alternative
Martin Escardo, Paulo Oliva, 9th July 2024. Alternative, equivalent, inductive definition of the type Game of games, which may have some practical advantages, such as more modular definitions of games.{-# OPTIONS --safe --without-K #-} open import MLTT.Spartan hiding (J) module Games.Alternative {π€ π¦β : Universe} (R : π¦β Μ ) where open import UF.Equiv open import UF.FunExt open import Games.TypeTrees {π€} open import Games.FiniteHistoryDependent {π€} R renaming (Game to Game' ; game to game') open import MonadOnTypes.K open K-definitions R data Game : π€ βΊ β π¦β Μ where leaf : R β Game branch : (X : π€ Μ ) β K X β (X β Game) β Game leaf' : R β Game' leaf' r = game' [] (Ξ» β¨β© β r) β¨β© branch' : (X : π€ Μ ) β K X β (X β Game') β Game' branch' X Ο Gf = game' (X β· (game-tree β Gf)) (Ξ» (x :: xs) β payoff-function (Gf x) xs) (Ο :: (quantifier-tree β Gf)) from-Game : Game β Game' from-Game (leaf r) = leaf' r from-Game (branch X Ο Gf) = branch' X Ο (from-Game β Gf)We need the curried version h of the conversion function to-Game defined below to convince the termination checker that the following recursion does terminate.to-Game : Game' β Game to-Game (game' Xt q Οt) = h Xt q Οt where h : (Xt : π») β (Path Xt β R) β π Xt β Game h [] q β¨β© = leaf (q β¨β©) h (X β· Xf) q (Ο :: Οf) = branch X Ο (Ξ» x β h (Xf x) (subpred q x) (Οf x))The equations we would have liked to use to define the function to-Game are the following:to-Game-base : (q : Path [] β R) β to-Game (game' [] q β¨β©) οΌ leaf (q β¨β©) to-Game-base q = refl to-Game-step : (X : π€ Μ ) (Xf : X β π») (Ο : K X) (Οf : (x : X) β π (Xf x)) (q : Path (X β· Xf) β R) β to-Game (game' (X β· Xf) q (Ο :: Οf)) οΌ branch X Ο (Ξ» x β to-Game (game' (Xf x) (subpred q x) (Οf x))) to-Game-step X Xf Ο Οf q = reflWe also have the following equivalent definitional equalities expressed in terms of leaf' and branch':to-Game-base' : (r : R) β to-Game (leaf' r) οΌ leaf r to-Game-base' r = refl module _ (X : π€ Μ ) (Xf : X β π») (Ο : K X) (Οf : (x : X) β π (Xf x)) (q : Path (X β· Xf) β R) where subgame : X β Game' subgame x = game' (Xf x) (subpred q x) (Οf x) to-Game-step' : to-Game (branch' X Ο subgame) οΌ branch X Ο (to-Game β subgame) to-Game-step' = reflThe above conversion functions are mutually inverse and so the types Game and Game' are equivalent, assuming function extensionality.module _ (fe : Fun-Ext) where from-to-Game : from-Game β to-Game βΌ id from-to-Game (game' Xt q Οt) = h Xt q Οt where h : (Xt : π») (q : Path Xt β R) (Οt : π Xt) β from-Game (to-Game (game' Xt q Οt)) οΌ game' Xt q Οt h [] q β¨β© = refl h (X β· Xf) q (Ο :: Οf) = from-Game (to-Game (game' (X β· Xf) q (Ο :: Οf))) οΌβ¨reflβ© from-Game (branch X Ο (to-Game β Gf)) οΌβ¨reflβ© branch' X Ο Hf οΌβ¨ I β© branch' X Ο Gf οΌβ¨reflβ© game' (X β· Xf) q (Ο :: Οf) β where Gf Hf : X β Game' Gf x = subgame X Xf Ο Οf q x Hf x = from-Game (to-Game (Gf x)) IH : Hf βΌ Gf IH x = h (Xf x) (subpred q x) (Οf x) I : branch' X Ο Hf οΌ branch' X Ο Gf I = ap (branch' X Ο) (dfunext fe IH) to-from-Game : to-Game β from-Game βΌ id to-from-Game (leaf x) = refl to-from-Game (branch X Ο Gf) = to-Game (from-Game (branch X Ο Gf)) οΌβ¨reflβ© to-Game (branch' X Ο (from-Game β Gf)) οΌβ¨reflβ© branch X Ο (to-Game β from-Game β Gf) οΌβ¨ I β© branch X Ο Gf β where I = ap (branch X Ο) (dfunext fe (to-from-Game β Gf)) Game-is-equiv-to-Game' : Game β Game' Game-is-equiv-to-Game' = qinveq from-Game (to-Game , to-from-Game , from-to-Game)