Nov 19, 2009 - 60s, 70s Constraint networks in artificial intelligence. ..... uses clausal normal form and unification ..... Resolution Calculus â Inference Rules.
Constraint Programming
Constraint Programming Prof. Dr. Thom Fru ¨hwirth November 19, 2009
Based on: Essentials of Constraint Programming, Thom Fru ¨ hwirth and Slim Abdennadher, Textbook, Springer Verlag, 2003.
Thom Fru ¨ hwirth – University of Ulm
Page 1 – WS 09/10
Constraint Programming
Overview • Introduction • Foundation from Logics • Constraint Languages For each: – Syntax – Declarative and Operational Semantics – Soundness and Completeness • Constraint Systems For each: – Constraint Theory – Solving Algorithms – Applications Thom Fru ¨ hwirth – University of Ulm
Page 2 – WS 09/10
Constraint Programming
The Holy Grail Constraint Programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it. Eugene C. Freuder, Inaugural issue of the Constraints Journal, 1997.
Thom Fru ¨ hwirth – University of Ulm
Page 3 – WS 09/10
Constraint Programming
Constraint Reasoning The Idea • Example – Combination Lock: 0 1 2 3 4 5 6 7 8 9 Greater or equal 5. Prime number. • Declarative problem representation by variables and constraints: x ∈ {0, 1, . . . , 9} ∧ x ≥ 5 ∧ prime(x) • Constraint propagation and simplification reduce search space: x ∈ {0, 1, . . . , 9} ∧ x ≥ 5 → x ∈ {5, 6, 7, 8, 9}
Thom Fru ¨ hwirth – University of Ulm
Page 4 – WS 09/10
Constraint Programming
Constraint Programming Robust, flexible, maintainable software faster. • Declarative modeling by constraints: Description of properties and relationships between partially known objects. Correct handling of precise and imprecise, finite and infinite, partial and full information. • Automatic constraint reasoning: Propagation of the effects of new information (as constraints). Simplification makes implicit information explicit. • Solving combinatorial problems efficiently: Easy Combination of constraint solving with search and optimization. Thom Fru ¨ hwirth – University of Ulm
Page 5 – WS 09/10
Constraint Programming
Terminology Language is first-order logic with equality. • Constraint: Conjunction of atomic constraints (predicates) E.g., 4X + 3Y = 10 ∧ 2X − Y = 0 • Constraint Problem (Query): A given, initial constraint • Constraint Solution (Answer): A valuation for the variables in a given constraint problem that satisfies all constraints of the problem. E.g., X = 1 ∧ Y = 2 In general, a normal/solved form of, e.g., the problem 4X + 3Y + Z = 10 ∧ 2X − Y = 0 simplifies into Y + Z = 10 ∧ 2X − Y = 0 Thom Fru ¨ hwirth – University of Ulm
Page 6 – WS 09/10
Constraint Programming
Constraint Reasoning and Constraint Programming A generic framework for • Modeling
– with partial information – with infinite information
• Reasoning
– with new information
• Solving
– combinatorial problems
Thom Fru ¨ hwirth – University of Ulm
Page 7 – WS 09/10
Constraint Programming
Constraint Programming – Mortgage % % % % %
D: T: I: R: S:
Amount of Loan, Debt, Principal Duration of loan in months Interest rate per month Rate of payments per month Balance of debt after T months
mortgage(D, T, I, R, S) T = 0, D = S ; T > 0, T1 = T - 1, D1 = D + D*I - R, mortgage(D1, T1, I, R, S). Thom Fru ¨ hwirth – University of Ulm
Model of F , Validity • I model of F or I satisfies F , written I |= F : I, η |= F for every variable valuation η • I model of theory T : I model of each formula in T Sentence S is • valid : satisfied by every interpretation, i.e., I |= S for every I • satisfiable: satisfied by some interpretation, i.e., I |= S for some I • falsifiable: not satisfied by some interpretation, i.e., I 6|= S for some I • unsatisfiable: not satisfied by any interpretation, i.e., I 6|= S for every I (Σ signature, I interpretation) Thom Fru ¨ hwirth – University of Ulm
Page 37 – WS 09/10
Constraint Programming
Example – Validity, Satisfiability, Falsifiable, Unsatisfiability (1) valid
satisfiable
falsifiable
unsatisfiable
A ∨ ¬A A ∧ ¬A A → ¬A A → (B → A) A → (A → B) A ↔ ¬A
(A, B formulae) Thom Fru ¨ hwirth – University of Ulm
Page 38 – WS 09/10
Constraint Programming
Example – Validity, Satisfiability, Unsatisfiability (2) correct/counter example If F is valid, then F is satisfiable. If F is satisfiable, then ¬F is unsatisfiable. If F is valid, then ¬F is unsatisfiable. If F is unsatisfiable, then ¬F is valid.
I(next) : U → U , next day function Mon 7→ Tue, . . . , Sun 7→ Mon
Thom Fru ¨ hwirth – University of Ulm
Page 40 – WS 09/10
Constraint Programming
Example – Interpretation and Model (cont) • (one possible) valuation η η(X) := Sun, η(Y ) := Tue – η I (next(X)) = Mon – η I (next(next(Y ))) = Thu – I, η |= pair(next(X), Y ) • model relationship (“for all variable valuations”) – I 6|= ∀X∀Y.pair(next(X), Y )
– I |= ∀X.pair(next(X), Sun)
– I |= ∀X∃Y.pair(X, Y )
Thom Fru ¨ hwirth – University of Ulm
Page 41 – WS 09/10
Constraint Programming
Logical Consequence • A sentence/theory T1 is a logical consequence of a sentence/theory T2 , written T2 |= T1 , if every model of T2 is also a model of T1 , i.e. I |= T2 implies I |= T1 . • Two sentences or theories are equivalent (|=| ) if they are logical consequences of each other. • |= is undecidable [Church] Example: ¬(A ∧ B) |=| ¬A ∨ ¬B (de Morgan)
Thom Fru ¨ hwirth – University of Ulm
Page 42 – WS 09/10
Constraint Programming
Example – Tautology Laws (1) Dual laws hold for ∧ and ∨ exchanged. • A |=| ¬¬A (double negation) • ¬(A ∧ B) |=| ¬A ∨ ¬B (de Morgan) • A ∧ A |=| A (idempotence) • A ∧ (A ∨ B) |=| A (absorption) • A ∧ B |=| B ∧ A (commutativity) • A ∧ (B ∧ C) |=| (A ∧ B) ∧ C (associativity) • A ∧ (B ∨ C) |=| (A ∧ B) ∨ (A ∧ B) (distributivity)
Thom Fru ¨ hwirth – University of Ulm
Page 43 – WS 09/10
Constraint Programming
Example – Tautology Laws (2) • A → B |=| ¬A ∨ B (implication) • A → B |=| ¬B → ¬A (contraposition) • (A → (B → C)) |=| (A ∧ B) → C • ¬∀XA |=| ∃X¬A • ¬∃XA |=| ∀X¬A • ∀X(A ∧ B) |=| ∀XA ∧ ∀XB • ∃X(A ∨ B) |=| ∃XA ∨ ∃XB • ∀XB |=| B |=| ∃XB (with X not free in B)
Thom Fru ¨ hwirth – University of Ulm
Page 44 – WS 09/10
Constraint Programming
Example – Logical Consequence F
G
A
A∨B
A
A∧B
A, B
A∨B
A, B
A∧B
A∧B
A
A∨B
A
A, (A → B)
B
F |= G or F 6|= G
Note: I is a model of {A, B}, iff I |= A and I |= B. Thom Fru ¨ hwirth – University of Ulm
Page 45 – WS 09/10
Constraint Programming
Example – Logical Consequence, Validity, Unsatisfiability The following statements are equivalent: 1. F1 , . . . , Fk |= G (G is a logical consequence of F1 , . . . , Fk ) V k 2. i=1 Fi → G is valid. V k 3. i=1 Fi ∧ ¬G is unsatisfiable.
Note: In general, F 6|= G does not imply F |= ¬G.
Thom Fru ¨ hwirth – University of Ulm
Page 46 – WS 09/10
Constraint Programming
Herbrand Interpretation – Motivation The formula A is valid in I, I |= A, if I, η |= A for every valuation η. This requires to fix a universe U as both I and η use U . Jacques Herbrand (1908-1931) discovered that there is a universal domain together with a universal interpretation, s.t. that any universally valid formula is valid in any interpretation. Therefore, only interpretations in the Herbrand universe need to be checked, provided the Herbrand universe is infinite.
Thom Fru ¨ hwirth – University of Ulm
Page 47 – WS 09/10
Constraint Programming
Herbrand Interpretation • Herbrand universe: set T (Σ, ∅) of ground terms • for every n-ary function symbol f of Σ, the assigned function I(f ) maps a tuple (t1 , . . . , tn ) of ground terms to the ground term “f (t1 , . . . , tn )”. Herbrand model of sentence/theory: Herbrand interpretation satisfying sentence/theory. Herbrand base for signature Σ: set of ground atoms in F(Σ, ∅), i.e., {p(t1 , . . . , tn ) | p is an n-ary predicate symbol of Σ and t1 , . . . , tn ∈ T (Σ, ∅)}.
Thom Fru ¨ hwirth – University of Ulm
Page 48 – WS 09/10
Constraint Programming
Example – Herbrand Interpretation For the formula F ≡ ∃X∃Y.p(X, a) ∧ ¬p(Y, a) the Herbrand universe is {a} and F is unsatisfiable in the Herbrand universe as p(a, a) ∧ ¬p(a, a) is false, i.e., there is no Herbrand model. However, if we add (another element) b we have p(a, a) ∧ ¬p(b, a) so F is valid for any interpretation whose universe’ cardinality is greater than 1. For the formula ∀X∀Y.p(X, a) ∧ q(X, f (Y )) the (infinite, as there is a constant and a function symbol) Herbrand domain is {a, f (a), f (f (a)), f (f (f (a))), . . . }.
Thom Fru ¨ hwirth – University of Ulm
Page 49 – WS 09/10
Constraint Programming
Logic and Calculus logic: formal language for expressions • syntax : ”spelling rules” for expressions • semantics: meaning of expressions (logical consequence |=) • calculus: set of given formulae and syntactic rules for manipulation of formulae to perform proofs
Thom Fru ¨ hwirth – University of Ulm
Page 50 – WS 09/10
Constraint Programming
Calculus • axioms: given formulae, elementary tautologies and contradictions which cannot be derived within the calculus • inference rules: allow to derive new formulae from given formulae • derivation φ ⊢ ψ: a sequence of inference rule applications starting with φ and ending in ψ |= and ⊢ should coincide • Soundness: φ ⊢ ρ implies φ |= ρ • Completeness: φ |= ρ implies φ ⊢ ρ
Thom Fru ¨ hwirth – University of Ulm
Page 51 – WS 09/10
Constraint Programming
Resolution Calculus [Robinson 1965] • calculus that can be easily implemented • used as execution mechanism of (constraint) logic programming • uses clausal normal form and unification
Thom Fru ¨ hwirth – University of Ulm
Page 52 – WS 09/10
Constraint Programming
Normal Forms Negation Normal Form of Formula F F in negation normal form Fneg : • no sub-formula of the form F → F ′ • in every sub-formula of the form ¬F ′ the formula F ′ is atomic
Thom Fru ¨ hwirth – University of Ulm
Page 53 – WS 09/10
Constraint Programming
Negation Normal Form – Computation For every sentence F , there is an equivalent sentence Fneg in negated normal form (apply ”tautologies” from left to right.): Negation ¬⊥ |=| ⊤
¬⊤ |=| ⊥
¬¬F |=| F
F is atomic
¬(F ∧ F ′ ) |=| ¬F ∨ ¬F ′ ¬∀XF |=| ∃X¬F
¬(F ∨ F ′ ) |=| ¬F ∧ ¬F ′
¬∃XF |=| ∀X¬F
¬(F → F ′ ) |=| F ∧ ¬F ′
Implication F → F ′ |=| ¬F ∨ F ′ Thom Fru ¨ hwirth – University of Ulm
Page 54 – WS 09/10
Constraint Programming
Skolemization of Formula F • F = Fneg ∈ F(Σ, V) in negation normal form • occurrence of sub formula ∃XG with free variables V1 , . . . , Vn • f /n function symbol not occurring in Σ Compute F ′ by replacing ∃XG with G[X 7→ f (V1 , . . . , Vn )] in F (all occurrences of X in G are replaced by f (V1 , . . . , Vn )). Naming conventions: • Skolemized form of F : F ′ • Skolem function: f /n Thom Fru ¨ hwirth – University of Ulm
Page 55 – WS 09/10
Constraint Programming
Prenex Form of Formula F F = Q1 X1 . . . Qn Xn G • Qi quantifiers • Xi variables • G formula without quantifiers • quantifier prefix : Q1 X1 . . . Qn Xn • matrix : G • For every sentence F , there is an equivalent sentence in prenex form and it is possible to compute such a sentence from F by applying tautology laws to push the quantifieres outwards.
Thom Fru ¨ hwirth – University of Ulm
Page 56 – WS 09/10
Constraint Programming
Example – Prenex Normal Form ¬∃xp(x) ∨ ∀xr(x) |=| ∀x¬p(x) ∨ ∀xr(x) |=| ∀x¬p(x) ∨ ∀yr(y)
Clauses and Literals • literal : atom (positive literal) or negation of atom (negative literal) • complementary literals: positive literal L and its negation ¬L Wn • clause (in disjunctive normal form): formula of the form i=1 Li where Li are literals. – empty clause (empty disjunction): n = 0: ⊥
Thom Fru ¨ hwirth – University of Ulm
Page 58 – WS 09/10
Constraint Programming
Clauses and Literals (cont) • implication form of the clause: F =
n ^
j=1
Bj →
m _
Hk
k=1
| {z }
| {z }
¬B
for i = 1, . . . , n
body
head
for F =
n+m _
Li with Li =
i=1
for atoms Bj and Hk
i
Hi−n
for i = n + 1, . . . , n + m
• closed clause: sentence ∀x1 , . . . , xn C with C clause • clausal form of theory: consists of closed clauses Thom Fru ¨ hwirth – University of Ulm
Page 59 – WS 09/10
Constraint Programming
Normalization steps An arbitrary theory T can be transformed into clausal form as follows • Convert every formula in the theory into an equivalent formula in negation normal form. • Perform Skolemization in order to eliminate all existential quantifiers. • Convert the resulting theory, which is still in negation normal form, into an equivalent theory in clausal form: Move conjunctions and universal quantifiers outwards.
Thom Fru ¨ hwirth – University of Ulm
Page 60 – WS 09/10
Constraint Programming
Unification Substitution to a Term • σ : V → T (Σ, V ′ ) • finite: V finite, written as {X1 7→ t1 , . . . , Xn 7→ tn } with distinct variables Xi and terms ti • identity substitution ǫ = ∅ • written as postfix operators, application from left to right in composition • σ : T (Σ, V) → T (Σ, V ′ ) implicit homomorphic extension, i.e., f (t1 , . . . , tn )σ := f (t1 σ, . . . , tn σ). Example: σ = {X 7→ 2, Y 7→ 5}: (X ∗ (Y + 1))σ = 2 ∗ (5 + 1) Thom Fru ¨ hwirth – University of Ulm
Page 61 – WS 09/10
Constraint Programming
Substitution to a Formula Homomorphic extension • p(t1 , . . . , tn )σ := p(t1 σ, . . . , tn σ) • (s=t)σ ˙ := (sσ)=(tσ) ˙ • ⊥σ := ⊥ and ⊤σ := ⊤ • (¬F )σ := ¬(F σ) • (F ∗ F ′ )σ := (F σ) ∗ (F ′ σ) for ∗ ∈ {∧, ∨, →} Except • (∀XF )σ := ∀X ′ (F σ[X 7→ X ′ ]) • (∃XF )σ := ∃X ′ (F σ[X 7→ X ′ ]) where X ′ is a fresh variable. Thom Fru ¨ hwirth – University of Ulm
Page 62 – WS 09/10
Constraint Programming
Example – Substitution to a Formula • σ = {X 7→ Y, Z 7→ 5}: (X ∗ (Z + 1))σ = Y ∗ (5 + 1) • σ = {X 7→ Y, Y 7→ Z}: p(X)σ = p(Y ) 6= p(X)σσ = p(Z) • σ = {X 7→ Y }, τ = {Y 7→ 2}
Logical Expression over V • term with variables in V, • formula with free variables in V, • substitution from an arbitrary set of variables into T (Σ, V), or • tuple of logical expressions over V. A logical expression is a simple expression if it does not contain quantifiers. Examples: V = {X}: f (X), ∀Y.p(X) ∧ q(Y ), {X 7→ a}, hp(X), σi
Thom Fru ¨ hwirth – University of Ulm
Page 64 – WS 09/10
Constraint Programming
Instance, Variable Renaming, Variants • e instance of e′ : e = e′ σ • e′ more general than e: e is instance of e′ • variable renaming for e: substitution σ – σ injective
– Xσ ∈ V for all X ∈ V
– Xσ does not occur in e for free variables X of e
• e and e′ variants (identical modulo variable renaming): e = e′ σ and e′ = eτ Examples: variable renaming (∀Xp(X1 )){X1 7→ X2 } = ∀X ′ p(X2 ) but not (∀Xp(X1 ) ∧ q(X2 )){X1 7→ X2 } = ∀X ′ .p(X2 ) ∧ q(X2 ) (e, e′ logical expressions, σ, τ substitutions)
Thom Fru ¨ hwirth – University of Ulm
Page 65 – WS 09/10
Constraint Programming
Unification • unifier for e1 , . . . , en : e1 σ = · · · = en σ • e1 , . . . , en unifiable: unifier exists • most general unifier (mgu) σ for e1 , . . . , en : every unifier τ for e1 , . . . , en is instance of σ, i.e., τ = σρ for some ρ (e1 , . . . , en simple expressions, σ, τ , ρ, σi substitutions)
Thom Fru ¨ hwirth – University of Ulm
Page 66 – WS 09/10
Constraint Programming
Example – Most General Unifier f (X, a) = ˙ f (g(U ), Y )
= ˙ Z
MGU: σ = {X 7→ g(U ), Y 7→ a, Z 7→ f (g(U ), a)} Proof: f (X, a)σ = f (g(U ), Y )σ = Zσ = f (g(U ), a) one element.
Unifier, but not MGU: σ ′ = {X 7→ g(h(b)), U 7→ h(b), Y 7→ a, Z 7→ f (g(h(b)), a)} Proof: σ ′ = σ{U 7→ h(b)}. Thom Fru ¨ hwirth – University of Ulm
Page 67 – WS 09/10
Constraint Programming
Most General Unifier by Hand • unbound variable: there is no substitution for it • Start with ǫ • scan terms simultaneously from left to right according to their structure • check the syntactic equivalence of the symbols encountered repeat – different function symbols: halt with failure – identical : continue – one is unbound variable and other term: ∗ variable occurs in other term: halt with failure ∗ apply the new substitution to the logical expressions add corresponding substitution – variable is not unbound : replace it by applying substitution Thom Fru ¨ hwirth – University of Ulm
Page 68 – WS 09/10
Constraint Programming
Example – Most General Unifier to unify
current substitution, remarks
p(X, f (a))=p(a, ˙ f (X))
ǫ, start
X =a ˙
{X 7→ a}, substitution added
f (a)=f ˙ (X) a=X ˙ a=a ˙
continue
{X 7→ a}, variable is not unbound
continue
MGU is {X 7→ a} What about p(X, f (b)) = p(a, f (X))?
Thom Fru ¨ hwirth – University of Ulm
Page 69 – WS 09/10
Constraint Programming
Example – Most General Unifier s
t
f
g
failure
a
a
ǫ
X
a
X
Y
{X 7→ a}
f (a, X)
f (Y, b)
f (g(a, X), Y )
f (c, X)
failure
f (g(a, X), h(c))
f (g(a, b), Y )
f (g(a, X), h(Y ))
f (g(a, b), Y )
{X 7→ b, Y 7→ h(c)}
Thom Fru ¨ hwirth – University of Ulm
{X 7→ Y }, but also {Y 7→ X} {Y 7→ a, X 7→ b}
failure
Page 70 – WS 09/10
Constraint Programming
Inference Rules • Given a set of formulae F 1 , . . . , Fn F – premises F1 , . . . , Fn – conclusion F – if premises are given, conclusion is added to the formulae – derivation step F1 , . . . , Fn ⊢ F
– derivation: sequence of derivation steps with conclusion taken as premises for next step
• rule application usually nondeterministic Thom Fru ¨ hwirth – University of Ulm
Page 71 – WS 09/10
Constraint Programming
Resolution Calculus – Inference Rules Works by contradiction: Theory united with negated consequence must be unsatisfiable (“derive empty clause”). Axiom empty clause (i.e. the elementary contradiction) Resolution R∨A R′ ∨ ¬A′ (R ∨ R′ )σ
σ is a most general unifier for the atoms A and A′
Factoring R ∨ L ∨ L′ (R ∨ L)σ
σ is a most general unifier for the literals L and L′
R ∨ A and R′ ∨ ¬A′ must have different variables: rename variables apart Thom Fru ¨ hwirth – University of Ulm
Page 72 – WS 09/10
Constraint Programming
Resolution – Remarks • resolution rule:
– two clauses C and C ′ instantiated s.t. literal from C and literal from C ′ complementary – two instantiated clauses are combined into a new clause – resolvent added
• factoring rule:
– clause C instantiated, s.t. two literals become equal – remove one literal – factor added
Constraint Programming Languages Preliminaries Syntax • extended Backus-Naur form (EBNF) for notation of production rules Name: G, H ::= A B, Condition – capital letters: syntactical entities – symbols G and H defined : with name Name. – Condition holds: G and H can be of the form A or B
Thom Fru ¨ hwirth – University of Ulm
Page 75 – WS 09/10
Constraint Programming
Semantics Operational (Procedural) Semantics State transition system (refined calculus) Declarative Semantics Logical reading of program as theory, i.e. set of formulae of first-order logic Operational vs. Declarative Semantics • Soundness • Completeness Thom Fru ¨ hwirth – University of Ulm
Page 76 – WS 09/10
Constraint Programming
Operational (Procedural) Semantics Refined Calculus Triple (Σ, ≡, T ) • Σ: signature for a first-order logic language • ≡: congruence (equivalence relation) on states • T = (S, 7→): simple state transition system states S represent logical expressions over the signature Σ
Thom Fru ¨ hwirth – University of Ulm
Page 77 – WS 09/10
Constraint Programming
Simple State Transition System • (S, 7→)
– S set of states – 7→ binary relation over states: transition relation
– (state) transition from S1 to S2 possible if (some give) condition holds, written S1 7→ S2
• distinguished subsets of S: initial and final states • S1 7→ S2 7→ . . . 7→ Sn derivation (computation) • S 7→∗ S ′ reflexive-transitive closure of 7→ Reduction is synonym for transition
Thom Fru ¨ hwirth – University of Ulm
Page 78 – WS 09/10
Constraint Programming
Transition Rules IF
Condition
THEN
S 7→ S ′ .
• (state) transition (reduction, derivation step, computation) from S to S ′ possible if the condition Condition holds • straightforward to concretize a calculus (“⊢”) into a state transition system (“7→”)
Thom Fru ¨ hwirth – University of Ulm
Page 79 – WS 09/10
Constraint Programming
Congruence • states which are considered equivalent for purpose of computation • congruence instead of modeling with additional transition rules • formally congruence is equivalence relation: (Reflexivity) (Symmetry) (Transitivity)
Transition Rules for Resolution Calculus (1) • state: set of clauses • initial state: clauses representing the theory and the negated consequence • final state: contains the empty clause
Thom Fru ¨ hwirth – University of Ulm
Page 82 – WS 09/10
Constraint Programming
Transition Rules for Resolution Calculus (2) S 7→ S ∪ {F } • Resolvent F = (R ∨ R′ )σ
IF {R ∨ A} ∈ S and {R′ ∨ ¬A′ } ∈ S and σ is a most general unifier for the atoms A and A′ , THEN S ∪ {(R ∨ R′ )σ}.
• Factor F = (R ∨ L)σ
IF {R ∨ L ∨ L′ } ∈ S and σ is a most general unifier for the literals L and L′ , THEN S ∪ {(R ∨ L)σ}.
Thom Fru ¨ hwirth – University of Ulm
Page 83 – WS 09/10
Constraint Programming
Logic Programming A logic program is a set of axioms, or rules, defining relationships between objects. A computation of a logic program is a deduction of consequences of the program. A program defines a set of consequences, which is its meaning. The art of logic programming is constructing concise and elegant programs that have desired meaning. Sterling and Shapiro: The Art of Prolog, Page 1.
Thom Fru ¨ hwirth – University of Ulm
Page 84 – WS 09/10
Constraint Programming
LP Syntax • goal :
– empty goal ⊤ (top) or ⊥ (bottom), or
– atom, or
– conjunction of goals • (Horn) clause: A ← G – head A: atom – body G: goal • Naming conventions
– fact: clause of form A ← ⊤ – rule: all others
• (logic) program: finite set of Horn clauses • predicate symbol defined : it occurs in head of a clause Thom Fru ¨ hwirth – University of Ulm
Page 85 – WS 09/10
Constraint Programming
LP Calculus – Syntax Atom:
A, B
::=
Goal :
G, H
::=
Clause:
K
::=
Program:
P
::=
Thom Fru ¨ hwirth – University of Ulm
p(t1 , . . . , tn ), n ≥ 0
⊤
⊥
A←G
A
G∧H
K1 . . . Km , m ≥ 0
Page 86 – WS 09/10
Constraint Programming
LP Calculus – State Transition System • state – G: goal
– θ: substitution • initial state • successful final state • failed final state
Thom Fru ¨ hwirth – University of Ulm
Page 87 – WS 09/10
Constraint Programming
Derivations, Goals Derivation is • successful : its final state is successful • failed : its final state is failed • infinite: if there are an infinite sequence of states and transitions S1 7→ S2 7→ S3 7→ . . . Goal G is • successful : it has a successful derivation starting with • finitely failed : it has only failed derivations starting with
Thom Fru ¨ hwirth – University of Ulm
Page 88 – WS 09/10
Constraint Programming
Logical Reading, Answer ¯ • logical reading of : ∃X(Hθ)
– 7→∗ ¯ variables which occur in Hθ but not in G – X:
• (computed) answer of a goal G: substitution θ with successful derivation 7→∗ G is also called initial goal or query
Thom Fru ¨ hwirth – University of Ulm
Page 89 – WS 09/10
Constraint Programming
Operational Semantics LP Transition Rules Unfold If