Adding stuff to an existing logic is hard!
Original motivation: Templates for IDP
Lots of Haskell Code
data PLogic = Prop String
| And PLogic PLogic
| Or PLogic PLogic
| Not PLogic
type Structure = Map String Bool
eval :: Structure -> PLogic -> Bool
eval s (Prop a) = a `isTrueIn` s
eval s (And a b) = (eval s a) && (eval s b)
eval s (Or a b) = (eval s a) || (eval s b)
eval s (Not a) = not (eval s a)
The meaning of a complex expression is determined by the meanings of its constituent expressions and the rules used to combine them.
Wikipedia: Principle of compositionality
data PLogic = Prop String
| And PLogic PLogic
| Or PLogic PLogic
| Not PLogic
type Structure = Map String Bool
eval :: Structure -> PLogic -> Bool
eval s (Prop a) = a `isTrueIn` s
eval s (And a b) = (eval s a) && (eval s b)
eval s (Or a b) = (eval s a) || (eval s b)
eval s (Not a) = not (eval s a)
Propositional Logic +
Quantification over boolean domain
data QBFLogic = Prop String
| And QBFLogic QBFLogic
| Or QBFLogic QBFLogic
| Not QBFLogic
| Forall String QBFLogic
eval :: Structure -> QBFLogic -> Bool
eval s (Prop a) = a `isTrueIn` s
eval s (And a b) = (eval s a) && (eval s b)
eval s (Or a b) = (eval s a) || (eval s b)
eval s (Not a) = not (eval s a)
eval s (Forall x p) = (eval sTrue p) && (eval sFalse p)
where
sTrue = s `add` (x,True)
sFalse = s `add` (x,False)
Meaning of sentence is a function (Structure →Bool)
Logic =
Set of Language Constructs
Language Construct =
Syntax + Semantics
type Infon = Structure -> Bool
eval :: QBFLogic -> Infon
eval (And a b) = liftM2 (&&) (eval a) (eval b)
eval (Or a b) = liftM2 (||) (eval a) (eval b)
eval (Not a) = liftM (not) (eval a)
eval (Forall x p) = liftM2 (&&) infonTrue infonFalse
where
infonTrue :: Infon
infonTrue = (\s -> (eval p) (s `add` (x,True))
infonFalse :: Infon
infonFalse = (\s -> (eval p) (s `add` (x,False))
liftM2 :: (Bool -> Bool -> Bool)
-> (Infon -> Infon -> Infon)
data And a = And a a
data Prop a = Prop String
Logic = MyLang (MyLang (MyLang(MyLang ...
type (+) = Coproduct
type MyLang a = (Prop + And) a
We need union between And and Prop
type MyLogic = Fix MyLang
data Container a = S a | Empty
type Peano = Fix Container
--Peano = Container (Container (Container ...
zero = Fix Empty -- 0
one = Fix (S (Fix Empty)) -- S(0)
two = Fix (S (Fix (S (Fix Empty)))) -- S(S(0))
eval :: Container Int -> Int
eval Empty = 0
eval (S a) = 1+a
evalPeano :: Peano -> Int
evalPeano = cata eval
cata :: (con a -> a) -> Fix con -> a
> let two = Fix (S (Fix (S (Fix Empty))))
> evalPeano two -- eval (S (eval (S (eval Empty))))
2
Frege-compliant function ⇔ catamorphism!
Catamorphisms replace Fix constructor with a function
class Semantics a where
eval :: a -> Infon
instance Semantics (And Infon) where
eval (And a b) = liftM2 (&&) a b
instance Semantics (Prop a) where
eval (Prop a) = (\s -> a `isTrueIn` s)
⇑Interface for Semantics
Semantics for (Fix (Prop+And))?
instance (Semantics (construct Infon),_)
=> Semantics (Fix construct) where
eval :: (Fix construct) -> Infon
eval = cata (eval :: (construct Infon) -> Infon)
instance ( Semantics (construct1 Infon),
Semantics (construct2 Infon))
=> Semantics ((construct1+construct2) Infon) where
eval = (eval :: (construct1 Infon) -> Infon)
`coproduct`
(eval :: (construct2 Infon) -> Infon)
type PropLogic = Fix (Prop + And + Or + Not)
type QBFLogic = Fix (Prop + And + Or + Not + Forall)
type FO = Fix (Prop + And + Or + Not + Quantify)
type FODOT = FO + (WellFounded FO)
We want (inductive) definitions
Infons are insufficient
Well founded semantics is three valued
type TriBool = Unknown | False | True
type Trinfon = Structure -> TriBool
There is a general way to extend an
Infon ⇒ TrInfon
and :: TriBool -> TriBool -> TriBool
and True a = a
and a True = a
and False a = False
and a False = False
and _ _ = Unknown
applied to "And" this results in:
Using TrInfons we can construct:
Templates!
{transitiveClosure(P,Q) ←
{Q(x,y) ← P(x,y).
Q(x,y) ← (∃ z: Q(x,z)∧Q(z,y)).
}.
}
Frege's principle
New Language Constructs
Fixpoint of Coproduct
Catamorphisms
TrInfon
Inductive Definitions
Templates