\begin{code}
{-# OPTIONS --safe --experimental-lossy-unification #-}
open import Prelude renaming (tt to β¨β©)
open import Signatures
open import FinitenessConditions
open import FreeMonad.PackagedTheory
module Hoare.Definition {β} (π― : FullTheory β) where
open import FreeMonad.Quotiented π―
open import Truth hiding (Ξ©; True)
[_/β¨β©] : Term A β Term β€
[_/β¨β©] = _>> return β¨β©
module DisplayConditions where
module _ {A : Type a} where
SEF : Term A β Type _
DET : Term A β Type _
\end{code}
%<*sef-dsef>
\begin{code}[number=sef-dsef]
SEF t = (do t; return β¨β©) β‘ return β¨β©
DET t = (do x β t; y β t; return (x , y)) β‘ (do x β t; t; return (x , x))
\end{code}
%</sef-dsef>
\begin{code}
module _ (p : Level) where
module _ {A : Type a} where
SEF : Term A β Type _
SEF t = β {R : Type p} (k : Term R) β (do t ; k) β‘ k
DET : Term A β Type _
DET t = β {R : Type p} (k : A β A β Term R) β (do x β t ; y β t ; k x y) β‘ (do x β t ; t ; k x x)
module _ (p : Level) where
open import Truth.MonoLevel p
Assertion : Type (β ββ βsuc (βsuc p))
Assertion = Ξ£[ Ο β¦ Term Ξ© ] Γ SEF (βsuc p) Ο Γ DET (βsuc p) Ο
module _ {p : Level} where
open import Truth.MonoLevel p
module DisplayGlobal {a} {A : Type a} where
open import Truth.MonoLevel (β ββ βsuc p ββ a) using () renaming (Ξ© to Ξ©β)
open import Truth.MonoLevel using () renaming (Ξ© to Ξ©β²)
\end{code}
%<*global>
\begin{code}
π’ : Term (A Γ Ξ©) β Type _
π’ t = t β‘ (do x , _ β t; return (x , True))
\end{code}
%</global>
\begin{code}
π’-Ξ© : Term (A Γ Ξ©) β Ξ©β
ProofOf (π’-Ξ© t) = π’ t
IsProp (π’-Ξ© t) = squash/ _ _
Hoare : Term Ξ© β Term A β (A β Term Ξ©) β Type _
\end{code}
%<*hoare-def>
\begin{code}
Hoare Ο t Ο = π’ do p β Ο; x β t; q β Ο x; return (x , p |β| q)
\end{code}
%</hoare-def>
\begin{code}
hoare-def-explicit : Term Ξ© β Term A β (A β Term Ξ©) β Type _
hoare-def-explicit = Ξ» Ο t Ο β
\end{code}
%<*hoare-def-explicit-unnumbered>
\begin{code}
(do p β Ο; x β t; q β Ο x; return (x , p |β| q))
β‘ (do p β Ο; x β t; q β Ο x; return (x , True))
\end{code}
%</hoare-def-explicit-unnumbered>
\begin{code}
_ : Term Ξ© β Term A β (A β Term Ξ©) β Type _
_ = Ξ» Ο t Ο β
\end{code}
%<*hoare-def-explicit>
\begin{code}[number=hoare-eq]
(do p β Ο; x β t; q β Ο x; return (x , p |β| q))
β‘ (do p β Ο; x β t; q β Ο x; return (x , True))
\end{code}
%</hoare-def-explicit>
\begin{code}
HoareNoAssume : Term A β (A β Term Ξ©) β Type _
HoareNoAssume t Ο = Hoare (return True) t Ο
syntax Hoare Ο p (Ξ» x β Ο) = β
Ο β x β p β
Ο β
syntax HoareNoAssume p (Ξ» x β Ο) = β
β x β p β
Ο β
open DisplayGlobal using (hoare-def-explicit) public
open Truth
module _ {A : Type a} {b c : Level} where
record Hoare (Ο : Term (Ξ© b)) (t : Term A) (Ο : A β Term (Ξ© c)) : Type (β ββ βsuc (a ββ βsuc (b ββ c))) where
no-eta-equality
field
proof : β {R : Type (a ββ βsuc (b ββ c))} β (k : A β Ξ© (b ββ c) β Term R) β
(do a β Ο
x β t
b β Ο x
k x (a |β| b)) β‘
(do a β Ο
x β t
b β Ο x
k x True)
on-pair :
(do a β Ο
x β t
b β Ο x
return (x , a |β| b)) β‘
(do a β Ο
x β t
b β Ο x
return (x , True))
on-pair = proof Ξ» x p β return (x , p)
open Hoare public
syntax Hoare Ο p (Ξ» x β Ο) = β
Ο β x β p β
Ο β
Hoare-NoVar : Term (Ξ© b) β Term A β Term (Ξ© c) β Type _
Hoare-NoVar Ο p Ο = Hoare Ο p (const Ο)
syntax Hoare-NoVar Ο p Ο = β
Ο β p β
Ο β
Hoare-NoAssume : {A : Type a} β Term A β (A β Term (Ξ© b)) β Type _
Hoare-NoAssume p Ο = Hoare (return (True {βzero})) p Ο
syntax Hoare-NoAssume p (Ξ» x β Ο) = β
β x β p β
Ο β
Hoare-NoAssumeNoVar : Term β€ β Term (Ξ© b) β Type _
Hoare-NoAssumeNoVar = Hoare-NoVar (return (True {βzero}))
syntax Hoare-NoAssumeNoVar p Ο = β
β p β
Ο β
\end{code}