ouroboros-consensus-1.0.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Util.Pred

Description

Self-explaining boolean predicates

These can be used to provide detailed counterexamples or witnesses for boolean predicates that evaluate to False or True, respectively.

NOTE: to keep this as simple as possible, we do not perform any boolean simplifications (e.g., double negations, or De Morgan's laws) on the predicates while evauating them. This can be added later if needed.

Synopsis

Documentation

data Pred tag where Source #

Constructors

(:=) ∷ ∀ tag. !tag → !(Pred tag) → Pred tag infixr 2

Tag a predicate with some metadata

Bool ∷ ∀ tag. !BoolPred tag

A concrete boolean value

Not ∷ ∀ tag. !(Pred tag) → Pred tag infixr 5

Boolean negation

(:>:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag infix 5

Greater-than comparison

(:<=:) ∷ ∀ a tag. (Typeable a, Ord a, Show a) ⇒ !a → !a → Pred tag infix 5

Less-than-or-equal comparison

(:==:) ∷ ∀ a tag. (Typeable a, Eq a, Show a) ⇒ !a → !a → Pred tag infix 5

Equality comparison

(:/\:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag infixr 4

Conjunction

(:\/:) ∷ ∀ tag. !(Pred tag) → !(Pred tag) → Pred tag infixr 3

Disjunction

Instances

Instances details
Show tag ⇒ Show (Pred tag) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

Methods

showsPrecIntPred tag → ShowS #

showPred tag → String #

showList ∷ [Pred tag] → ShowS #

Eq tag ⇒ Eq (Pred tag) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

Methods

(==)Pred tag → Pred tag → Bool #

(/=)Pred tag → Pred tag → Bool #

Explainable a ⇒ Explainable (Pred a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

data Evidence (res ∷ Bool) a where Source #

Sufficient evidence to show that a predicate is either true or false

Constructors

ETrue ∷ ∀ a. Pred a → Evidence 'True a 
EFalse ∷ ∀ a. Pred a → Evidence 'False a 

Instances

Instances details
Show a ⇒ Show (Evidence res a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

Methods

showsPrecIntEvidence res a → ShowS #

showEvidence res a → String #

showList ∷ [Evidence res a] → ShowS #

Eq a ⇒ Eq (Evidence res a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

Methods

(==)Evidence res a → Evidence res a → Bool #

(/=)Evidence res a → Evidence res a → Bool #

forgetEvidence ∷ ∀ (res ∷ Bool) a. Evidence res a → Bool Source #

Forget the evidence payload, yielding just its corresponding boolean value

evalPredPred tag → (∀ (res ∷ Bool). Evidence res tag → r) → r Source #

Evaluate a predicate, yielding either a counterexample or a witness.

The returned value contains the minimum (modulo conjunction/disjunction short circuiting) evidence needed to explain the outcome.

Some examples:

>>> data P = A | B | C deriving Show
>>> a = A := Bool True   -- a ~ True
>>> b = B := 2+2 :==: 5  -- b ~ False
>>> c = C := 10 :>: 5    -- c ~ True
>>> evalPred (a :/\: c) show  -- success because both a~True and c~True
"ETrue ((A := Bool True) :/\\: (C := 10 :>: 5))"
>>> evalPred (a :\/: b) show  -- success because a~True, short-circuits
"ETrue (A := Bool True)"
>>> evalPred (a :/\: b :/\: c) show  -- failure because b~False, short-circuits
"EFalse (B := 4 :==: 5)"
>>> evalPred ((b :\/: a) :/\: (b :\/: c)) show  -- success because of a~True and c~True
"ETrue ((A := Bool True) :/\\: (C := 10 :>: 5))"
>>> evalPred (b :\/: (Not c)) show  -- failure because both b~False and c~True
"EFalse ((B := 4 :==: 5) :\\/: Not (C := 10 :>: 5))"
>>> evalPred (Not (a :/\: b)) show  -- success because b~False
"ETrue (Not (B := 4 :==: 5))"
>>> evalPred (Not (a :/\: c)) show  -- failure because both a~True and c~True
"EFalse (Not ((A := Bool True) :/\\: (C := 10 :>: 5)))"

class Explainable a where Source #

Provides a human-readable explanation for a value

Minimal complete definition

(explain | explainPrec)

data ExplanationMode Source #

Explanation mode

Used to control whether we want to continue explaining terms beyond tags * Shallow: only explain tags * Deep: explain full predicates

Constructors

Shallow 
Deep 

newtype ShowExplain a Source #

Default Explainable instance via Show to be used with 'deriving via'

Constructors

ShowExplain a 

Instances

Instances details
Show a ⇒ Show (ShowExplain a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

Methods

showsPrecIntShowExplain a → ShowS #

showShowExplain a → String #

showList ∷ [ShowExplain a] → ShowS #

Show a ⇒ Explainable (ShowExplain a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Pred

explainShallowExplainable a ⇒ a → String Source #

Shallow explanation

explainDeepExplainable a ⇒ a → String Source #

Deep explanation