2020-08-19 00:26:56 +03:00
|
|
|
module Decidable.Decidable
|
|
|
|
|
|
|
|
import Data.Rel
|
|
|
|
import Data.Fun
|
|
|
|
|
2021-06-09 01:05:10 +03:00
|
|
|
%default total
|
|
|
|
|
2021-01-18 04:32:04 +03:00
|
|
|
public export
|
|
|
|
isNo : Dec a -> Bool
|
|
|
|
isNo (Yes _) = False
|
|
|
|
isNo (No _) = True
|
|
|
|
|
|
|
|
public export
|
|
|
|
isYes : Dec a -> Bool
|
|
|
|
isYes (Yes _) = True
|
|
|
|
isYes (No _) = False
|
|
|
|
|
|
|
|
||| Proof that some `Dec` is actually `Yes`
|
|
|
|
public export
|
|
|
|
data IsYes : Dec a -> Type where
|
|
|
|
ItIsYes : IsYes (Yes prf)
|
|
|
|
|
|
|
|
public export
|
|
|
|
Uninhabited (IsYes (No contra)) where
|
|
|
|
uninhabited ItIsYes impossible
|
|
|
|
|
|
|
|
||| Decide whether a 'Dec' is 'Yes'
|
|
|
|
public export
|
|
|
|
isItYes : (v : Dec a) -> Dec (IsYes v)
|
|
|
|
isItYes (Yes _) = Yes ItIsYes
|
|
|
|
isItYes (No _) = No absurd
|
|
|
|
|
2020-12-29 00:41:12 +03:00
|
|
|
||| An n-ary relation is decidable if we can make a `Dec`
|
|
|
|
||| of its result type for each combination of inputs
|
|
|
|
public export
|
|
|
|
IsDecidable : (k : Nat) -> (ts : Vect k Type) -> Rel ts -> Type
|
2021-06-28 14:49:33 +03:00
|
|
|
IsDecidable k ts p = liftRel ts p Dec
|
2020-12-29 00:41:12 +03:00
|
|
|
|
2020-08-19 00:26:56 +03:00
|
|
|
||| Interface for decidable n-ary Relations
|
|
|
|
public export
|
2020-12-11 14:58:26 +03:00
|
|
|
interface Decidable k ts p where
|
2020-12-29 00:41:12 +03:00
|
|
|
total decide : IsDecidable k ts p
|
2020-08-19 00:26:56 +03:00
|
|
|
|
|
|
|
||| Given a `Decidable` n-ary relation, provides a decision procedure for
|
|
|
|
||| this relation.
|
2021-10-17 01:32:16 +03:00
|
|
|
decision : (ts : Vect k Type) -> (p : Rel ts) -> Decidable k ts p => liftRel ts p Dec
|
2020-08-19 00:26:56 +03:00
|
|
|
decision ts p = decide {ts} {p}
|
|
|
|
|
|
|
|
using (a : Type, x : a)
|
|
|
|
public export
|
|
|
|
data Given : Dec a -> Type where
|
|
|
|
Always : Given (Yes x)
|