Foundations of Artificial Intelligence: Logic
Foundations of Artificial Intelligence: Logic
Logic
Shang-Tse Chen
Department of Computer Science
& Information Engineering
National Taiwan University
a1
a2 a3
Syntaxland Semanticsland
Different kinds of logic
§ Propositional logic
§ Syntax: P Ú (¬Q Ù R); X1 Û (Raining Þ ¬Sunny)
§ Possible world: {P=true,Q=true,R=false,S=true} or 1101
§ Semantics: a Ù b is true in a world iff is a true and b is true (etc.)
§ First-order logic
§ Syntax: "x $y P(x,y) Ù ¬Q(Joe,f(x)) Þ f(x)=f(y)
§ Possible world: Objects o1, o2, o3; P holds for <o1,o2>; Q holds for <o3>;
f(o1)=o1; Joe=o3; etc.
§ Semantics: f(s) is true in a world if s=oj and f holds for oj; etc.
Different kinds of logic, contd.
§ Relational databases:
§ Syntax: ground relational sentences, e.g., Sibling(Ali,Bo)
§ Possible worlds: (typed) objects and (typed) relations
§ Semantics: sentences in the DB are true, everything else is false
§ Cannot express disjunction, implication, universals, etc.
§ Query language (SQL etc.) typically some variant of first-order logic
§ Often augmented by first-order rule languages, e.g., Datalog
§ Knowledge graphs (roughly: relational DB + ontology of types and relations)
§ Google Knowledge Graph: 5 billion entities, 500 billion facts, >30% of queries
§ Facebook network: 2.93 billion people, trillions of posts, maybe quadrillions of facts
Inference: entailment
§ Entailment: a |= b (“a entails b” or “b follows from a”) iff
in every world where a is true, b is also true
§ I.e., the a-worlds are a subset of the b-worlds [models(a) Í models(b)]
§ In the example, a2 |= a1
§ (Say a2 is ¬Q Ù R Ù S Ù W
a1 is ¬Q )
a1
a2
Inference: proofs
§ A proof is a demonstration of entailment between a and b
§ Sound algorithm: everything it claims to prove is in fact entailed
§ Complete algorithm: every that is entailed can be proved
Inference: proofs
§ Method 1: model-checking
§ For every possible world, if a is true make sure that is b true too
§ OK for propositional logic (finitely many worlds); not easy for first-order logic
§ Method 2: theorem-proving
§ Search for a sequence of proof steps (applications of inference rules) leading
from a to b
§ E.g., from P and (P Þ Q), infer Q by Modus Ponens
Propositional logic syntax
§ Given: a set of proposition symbols {X1,X2,…, Xn}
§ (we often add True and False for convenience)
§ Xi is a sentence
§ If a is a sentence then ¬a is a sentence
§ If a and b are sentences then a Ù b is a sentence
§ If a and b are sentences then a Ú b is a sentence
§ If a and b are sentences then a Þ b is a sentence
§ If a and b are sentences then a Û b is a sentence
§ And p.s. there are no other sentences!
Propositional logic semantics
§ Let m be a model assigning true or false to {X1,X2,…, Xn}
§ If a is a symbol then its truth value is given in m
§ ¬a is true in m iff a is false in m
§ a Ù b is true in m iff a is true in m and b is true in m
§ a Ú b is true in m iff a is true in m or b is true in m
§ a Þ b is true in m iff a is false in m or b is true in m
§ a Û b is true in m iff a Þ b is true in m and b Þ a is true in m
Propositional logic semantics in code
function PL-TRUE?(a,model) returns true or false
if a is a symbol then return Lookup(a, model)
if Op(a) = ¬ then return not(PL-TRUE?(Arg1(a),model))
if Op(a) = Ù then return and(PL-TRUE?(Arg1(a),model),
PL-TRUE?(Arg2(a),model))
etc.