How to define a
compositional logic
Ingmar Dasseville
Don't force others to repeat your work
DTAI Seminar
09/11/2015
Why?
Adding stuff to an existing logic is hard!
- Aggregates in ASP
- Definitions
- ...
Original motivation: Templates for IDP
This talk
Lots of Haskell Code
- Forces rigorous definitions
- Represents definitions in papers
- Syntax Irrelevant
What is compositional?
Reformulations
Three Valued Logics
Logic =
Syntax
+ Semantics
Propositional Logic
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)
Is this composable?
Frege's Principle
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
Succes?
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)
-
Frege: YES
-
New language constructs: NO
Let's make it worse...
Quantified Boolean Formulas
(QBF)
Propositional Logic +
Quantification over boolean domain
QBF Logic
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)
-
Frege: NO
-
New language constructs: NO
What is compositional?
Reformulations
Three Valued Logics
Frege
Meaning of sentence is a function (Structure →Bool)
New language constructs
Logic =
Set of Language Constructs
Language Construct =
Syntax + Semantics
INFON
Requirements
Frege Compliant QBF
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)
Language Constructs: Data Types
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
Intermezzo: Fix of a datatype
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))
Intermezzo: Catamorphism
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
Semantics
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))?
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)
Some Logics
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)
What is compositional?
Reformulations
Three Valued Logics
Bad News
We want (inductive) definitions
Infons are insufficient
TRINFON
Well founded semantics is three valued
type TriBool = Unknown | False | True
type Trinfon = Structure -> TriBool
Good
More Good News
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:
Finally!
Using TrInfons we can construct:
- FO(.)
- ASP
- ...
Templates!
{transitiveClosure(P,Q) ←
{Q(x,y) ← P(x,y).
Q(x,y) ← (∃ z: Q(x,z)∧Q(z,y)).
}.
}
What is compositional?
Reformulations
Three Valued Logics
Frege's principle
New Language Constructs
Fixpoint of Coproduct
Catamorphisms
TrInfon
Inductive Definitions
The end
Templates
Compositional Logics
By Ingmar Dasseville
Compositional Logics
- 1,021