toward the concept of backtracking computation

144
Toward the concept of backtracking computation * Marija Kulaˇ s FernUniversit¨ at Hagen, Germany Abstract S 1 :PP is a new mathematical definition of the Byrd’s box model for pure Prolog, with: Forward and backward steps Modularity * paper presented at the SOS’04 Workshop, 30. August 2004, London

Upload: others

Post on 19-Apr-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Toward the concept of backtracking computation

Toward the concept of backtracking

computation∗

Marija Kulas

FernUniversitat Hagen, Germany

Abstract

S1:PP is a new mathematical definition of the Byrd’s box model

for pure Prolog, with:

• Forward and backward steps

• Modularity

∗paper presented at the SOS’04 Workshop, 30. August 2004, London

Page 2: Toward the concept of backtracking computation

Motivation: How to specify (and even prove)

properties of computation?

What does it mean that a run-time test is

“not affecting the computation” ?

• preserving the success set (what about order etc.?)

• “The transformed program Π ′ computes wrt the transformed query

Q ′ the same answers and in the same sequence as the original

program wrt the original query.” (how to specify this?)

• relevant parts of the computation remain the same (...)

Page 3: Toward the concept of backtracking computation

Some problems with describing (even pure)

Prolog execution

• complex data flow, alternating in forward and backward direction

• backward steps are much more global than forward steps (the most

recent choice point may be any distance away)

• lacking in means of simplification

e. g. abstraction, compositionality, modularity

• representing “state of computation” by data structures that give us

too many special cases for theorem proving

e. g. stack of stacks of frames (ancestor+environment)

Page 4: Toward the concept of backtracking computation

Byrd’s “box” metaphor

of Prolog execution

call descendant(X,Y) :- offspring(X,Y). exit

descendant(X,Z) :- offspring(X,Y),

fail descendant(Y,Z). redo

Page 5: Toward the concept of backtracking computation

Byrd’s “box” metaphor

of Prolog execution

call descendant(X,Y) :- offspring(X,Y). exit

descendant(X,Z) :- offspring(X,Y),

fail descendant(Y,Z). redo

Page 6: Toward the concept of backtracking computation

Byrd’s “box” metaphor

of Prolog execution

call descendant(X,Y) :- offspring(X,Y). exit

descendant(X,Z) :- offspring(X,Y),

fail descendant(Y,Z). redo

Page 7: Toward the concept of backtracking computation

Byrd’s “box” metaphor

of Prolog execution

call descendant(X,Y) :- offspring(X,Y). exit

descendant(X,Z) :- offspring(X,Y),

fail descendant(Y,Z). redo

Page 8: Toward the concept of backtracking computation

Byrd’s “box” metaphor

of Prolog execution

call descendant(X,Y) :- offspring(X,Y). exit

descendant(X,Z) :- offspring(X,Y),

fail descendant(Y,Z). redo

PS. What does the box stand for? Does it have to be the “selected

atom”?

Page 9: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

Page 10: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

Page 11: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

Page 12: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

Page 13: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

Page 14: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

Page 15: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

Page 16: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

Page 17: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

Page 18: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

redoHead _ redo Body

Page 19: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

redoHead _ redo Body

Page 20: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

redoHead _ redo Body

Page 21: Toward the concept of backtracking computation

... or can it be a general goal?

• focus on general goals is a main idea behind the S1:PP model

• canonical form of predicates reduces choice to disjunction

call exit

call exit

Body

fail redo

fail Head redo

call Head _ call Body

exit Body _ exit Head

redoHead _ redo Body

fail Body _ fail Head

Page 22: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

Page 23: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

Page 24: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

Page 25: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

Page 26: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

Page 27: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

Page 28: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

Page 29: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

Page 30: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

Page 31: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

Page 32: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

Page 33: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

Page 34: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

Page 35: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

Page 36: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

Page 37: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

fail B _ redoA

Page 38: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

fail B _ redoA

Page 39: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

fail B _ redoA

Page 40: Toward the concept of backtracking computation

Main idea (cont’d), Conjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A,B redo

call A,B _ call A

exit A _ call B

exit B _ exit A,B

redoA,B _ redoB

fail B _ redoA

fail A _ fail A,B

Page 41: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

Page 42: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

Page 43: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

Page 44: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

Page 45: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

Page 46: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

Page 47: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

Page 48: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

Page 49: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

Page 50: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

Page 51: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

Page 52: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

Page 53: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoA

Page 54: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoA

Page 55: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoA

Page 56: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

Page 57: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

Page 58: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

Page 59: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

fail A _ call B

Page 60: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

fail A _ call B

Page 61: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

fail A _ call B

Page 62: Toward the concept of backtracking computation

Main idea (cont’d), Disjunction

call exit

call exit

A

fail redo

call exit

B

fail redo

fail A;B redo

call A;B _ call A

exit A _α exit A;B

exit B _β exit A;B

αredoA;B _ redoAβredoA;B _ redoB

fail A _ call B

fail B _ fail A;B

Page 63: Toward the concept of backtracking computation

A canonical form of Prolog predicates

original program

q(a,b).

q(Z,c) :- r(Z).

r(c).

⇓canonical representation

q(X,Y) :- X=a, Y=b, true; X=Z, Y=c, r(Z).

r(X) :- X=c, true.

Page 64: Toward the concept of backtracking computation

Filling-in the context

main :- good, bad.

good.

Page 65: Toward the concept of backtracking computation

Filling-in the context

main :- good, bad.

good :- true.

Page 66: Toward the concept of backtracking computation

Filling-in the context

main :- good, bad.

good :- true.

call main _

call (good, bad) _

call good _

call true _

exit true _

exit good _

call bad _

fail bad _

redo good _

redo true _

fail true _

fail good _

fail (good, bad) _

fail main

Page 67: Toward the concept of backtracking computation

Filling-in the context

main :- good, bad.

good :- true.

call main _

call (good, bad) _

call good _

call true _

exit true _

exit good _

call bad _

fail bad _

redo good _

redo true _

fail true _

fail good _

fail (good, bad) _

fail main

• context information needed: A-stack,

stack of ancestors

Page 68: Toward the concept of backtracking computation

Filling-in the context

main :- good, bad.

good :- true.

call main _

call (good, bad) _

call good _

call true _

exit true _

exit good _

call bad _

fail bad _

redo good _

redo true _

fail true _

fail good _

fail (good, bad) _

fail main

• context information needed: A-stack,

stack of ancestors

• rest of information: B-stack (bindings

for the variables etc.)

Page 69: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

Page 70: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

Page 71: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

Page 72: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

Page 73: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

Page 74: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

Page 75: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

Page 76: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

Page 77: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

Page 78: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

Page 79: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

Page 80: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

Page 81: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

_ fail (good, bad) , main •nil, nil

Page 82: Toward the concept of backtracking computation

main :- good, bad.good :- true.

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

_ fail (good, bad) , main •nil, nil

_ fail main , nil, nil

Page 83: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 84: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 85: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 86: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 87: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 88: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 89: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 90: Toward the concept of backtracking computation

S1:PP Language of events

Example fail bad 〈 BY (true) •nil

2/good,bad •main •nil〉

Grammarevent ::= port goal 〈B-stack

A-stack〉port ::= call | exit | fail | redo

goal ::= true | fail | atom | term=term | goal;goal | goal,goal

A-stack ::= nil | ancestor • A-stack

ancestor ::= atom | tag/goal;goal | tag/goal,goal

tag ::= 1 | 2

B-stack ::= nil | bet • B-stack

bet ::= mgu | memo

memo ::= BY (goal) | OR(tag)

Page 91: Toward the concept of backtracking computation

S1:PP Calculus in 20 rules

First of all, how to specify the built-in predicates true and fail?

True

Fail

Page 92: Toward the concept of backtracking computation

S1:PP Calculus in 20 rules

First of all, how to specify the built-in predicates true and fail?

True

call true 〈ΣU〉 _ exit true 〈Σ

U〉 (S1:true:1)

Fail

Page 93: Toward the concept of backtracking computation

S1:PP Calculus in 20 rules

First of all, how to specify the built-in predicates true and fail?

True

call true 〈ΣU〉 _ exit true 〈Σ

U〉 (S1:true:1)

redo true 〈ΣU〉 _ fail true 〈Σ

U〉 (S1:true:2)

Fail

Page 94: Toward the concept of backtracking computation

S1:PP Calculus in 20 rules

First of all, how to specify the built-in predicates true and fail?

True

call true 〈ΣU〉 _ exit true 〈Σ

U〉 (S1:true:1)

redo true 〈ΣU〉 _ fail true 〈Σ

U〉 (S1:true:2)

Fail

call fail 〈ΣU〉 _ fail fail 〈Σ

U〉 (S1:fail)

Page 95: Toward the concept of backtracking computation

S1:PP Calculus: Explicit unification

(S1:unif:1)

(S1:unif:2)

Page 96: Toward the concept of backtracking computation

S1:PP Calculus: Explicit unification

call T1=T2 〈Σ

U〉 _

exit T1=T2 〈σ •Σ

U〉, if mgu...

fail T1=T2 〈Σ

U〉, otherwise

(S1:unif:1)

(S1:unif:2)

† if mgu(Σ(T1), Σ(T2)) = σ.

Page 97: Toward the concept of backtracking computation

S1:PP Calculus: Explicit unification

call T1=T2 〈Σ

U〉 _

exit T1=T2 〈σ •Σ

U〉, if mgu...

fail T1=T2 〈Σ

U〉, otherwise

(S1:unif:1)

redo T1=T2 〈σ •Σ

U〉 _ fail T1=T2 〈

Σ

U〉 (S1:unif:2)

† if mgu(Σ(T1), Σ(T2)) = σ.

Page 98: Toward the concept of backtracking computation

S1:PP Calculus: User-defined atom

(S1:atom:1)

(S1:atom:2)

(S1:atom:3)

(S1:atom:4)

Page 99: Toward the concept of backtracking computation

S1:PP Calculus: User-defined atom

call GA 〈Σ

U〉 _

call σ(B) 〈 Σ

GA •U〉, if H :−B ...

fail GA 〈Σ

U〉, otherwise

(S1:atom:1)

(S1:atom:2)

(S1:atom:3)

(S1:atom:4)

‡ if H :−B is a fresh renaming of a clause in Π, and σ = mgu(G ′A, H ) with G ′

A := Σ(GA) and

σ(G ′A) = G ′

A.

Page 100: Toward the concept of backtracking computation

S1:PP Calculus: User-defined atom

call GA 〈Σ

U〉 _

call σ(B) 〈 Σ

GA •U〉, if H :−B ...

fail GA 〈Σ

U〉, otherwise

(S1:atom:1)

exit B 〈 Σ

GA •U〉 _ exit GA 〈

BY (B) •Σ

U〉 (S1:atom:2)

(S1:atom:3)

(S1:atom:4)

‡ if H :−B is a fresh renaming of a clause in Π, and σ = mgu(G ′A, H ) with G ′

A := Σ(GA) and

σ(G ′A) = G ′

A.

Page 101: Toward the concept of backtracking computation

S1:PP Calculus: User-defined atom

call GA 〈Σ

U〉 _

call σ(B) 〈 Σ

GA •U〉, if H :−B ...

fail GA 〈Σ

U〉, otherwise

(S1:atom:1)

exit B 〈 Σ

GA •U〉 _ exit GA 〈

BY (B) •Σ

U〉 (S1:atom:2)

fail B 〈 Σ

GA •U〉 _ fail GA 〈

Σ

U〉 (S1:atom:3)

(S1:atom:4)

‡ if H :−B is a fresh renaming of a clause in Π, and σ = mgu(G ′A, H ) with G ′

A := Σ(GA) and

σ(G ′A) = G ′

A.

Page 102: Toward the concept of backtracking computation

S1:PP Calculus: User-defined atom

call GA 〈Σ

U〉 _

call σ(B) 〈 Σ

GA •U〉, if H :−B ...

fail GA 〈Σ

U〉, otherwise

(S1:atom:1)

exit B 〈 Σ

GA •U〉 _ exit GA 〈

BY (B) •Σ

U〉 (S1:atom:2)

fail B 〈 Σ

GA •U〉 _ fail GA 〈

Σ

U〉 (S1:atom:3)

redo GA 〈BY (B) •Σ

U〉 _ redo B 〈 Σ

GA •U〉 (S1:atom:4)

‡ if H :−B is a fresh renaming of a clause in Π, and σ = mgu(G ′A, H ) with G ′

A := Σ(GA) and

σ(G ′A) = G ′

A.

Page 103: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

(S1:conj:1)

(S1:conj:2)

(S1:conj:3)

(S1:conj:4)

(S1:conj:5)

(S1:conj:6)

Page 104: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

(S1:conj:2)

(S1:conj:3)

(S1:conj:4)

(S1:conj:5)

(S1:conj:6)

Page 105: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

exit A 〈 Σ

1/A,B •U〉 _ call B 〈 Σ

2/A,B •U〉 (S1:conj:2)

(S1:conj:3)

(S1:conj:4)

(S1:conj:5)

(S1:conj:6)

Page 106: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

exit A 〈 Σ

1/A,B •U〉 _ call B 〈 Σ

2/A,B •U〉 (S1:conj:2)

fail A 〈 Σ

1/A,B •U〉 _ fail A,B 〈Σ

U〉 (S1:conj:3)

(S1:conj:4)

(S1:conj:5)

(S1:conj:6)

Page 107: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

exit A 〈 Σ

1/A,B •U〉 _ call B 〈 Σ

2/A,B •U〉 (S1:conj:2)

fail A 〈 Σ

1/A,B •U〉 _ fail A,B 〈Σ

U〉 (S1:conj:3)

exit B 〈 Σ

2/A,B •U〉 _ exit A,B 〈Σ

U〉 (S1:conj:4)

(S1:conj:5)

(S1:conj:6)

Page 108: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

exit A 〈 Σ

1/A,B •U〉 _ call B 〈 Σ

2/A,B •U〉 (S1:conj:2)

fail A 〈 Σ

1/A,B •U〉 _ fail A,B 〈Σ

U〉 (S1:conj:3)

exit B 〈 Σ

2/A,B •U〉 _ exit A,B 〈Σ

U〉 (S1:conj:4)

fail B 〈 Σ

2/A,B •U〉 _ redo A 〈 Σ

1/A,B •U〉 (S1:conj:5)

(S1:conj:6)

Page 109: Toward the concept of backtracking computation

S1:PP Calculus: Conjunction

call A,B 〈ΣU〉 _ call A 〈 Σ

1/A,B •U〉 (S1:conj:1)

exit A 〈 Σ

1/A,B •U〉 _ call B 〈 Σ

2/A,B •U〉 (S1:conj:2)

fail A 〈 Σ

1/A,B •U〉 _ fail A,B 〈Σ

U〉 (S1:conj:3)

exit B 〈 Σ

2/A,B •U〉 _ exit A,B 〈Σ

U〉 (S1:conj:4)

fail B 〈 Σ

2/A,B •U〉 _ redo A 〈 Σ

1/A,B •U〉 (S1:conj:5)

redo A,B 〈ΣU〉 _ redo B 〈 Σ

2/A,B •U〉 (S1:conj:6)

Page 110: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

(S1:disj:1)

(S1:disj:2)

(S1:disj:3)

(S1:disj:4)

(S1:disj:5)

Page 111: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

call A;B 〈ΣU〉 _ call A 〈 Σ

1/A;B •U〉 (S1:disj:1)

(S1:disj:2)

(S1:disj:3)

(S1:disj:4)

(S1:disj:5)

Page 112: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

call A;B 〈ΣU〉 _ call A 〈 Σ

1/A;B •U〉 (S1:disj:1)

fail A 〈 Σ

1/A;B •U〉 _ call B 〈 Σ

2/A;B •U〉 (S1:disj:2)

(S1:disj:3)

(S1:disj:4)

(S1:disj:5)

Page 113: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

call A;B 〈ΣU〉 _ call A 〈 Σ

1/A;B •U〉 (S1:disj:1)

fail A 〈 Σ

1/A;B •U〉 _ call B 〈 Σ

2/A;B •U〉 (S1:disj:2)

fail B 〈 Σ

2/A;B •U〉 _ fail A;B 〈Σ

U〉 (S1:disj:3)

(S1:disj:4)

(S1:disj:5)

Page 114: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

call A;B 〈ΣU〉 _ call A 〈 Σ

1/A;B •U〉 (S1:disj:1)

fail A 〈 Σ

1/A;B •U〉 _ call B 〈 Σ

2/A;B •U〉 (S1:disj:2)

fail B 〈 Σ

2/A;B •U〉 _ fail A;B 〈Σ

U〉 (S1:disj:3)

exit C 〈 Σ

N/A;B •U〉 _ exit A;B 〈OR(N ) •Σ

U〉, with C = bN/A; Bc (S1:disj:4)

(S1:disj:5)

Page 115: Toward the concept of backtracking computation

S1:PP Calculus: Disjunction

call A;B 〈ΣU〉 _ call A 〈 Σ

1/A;B •U〉 (S1:disj:1)

fail A 〈 Σ

1/A;B •U〉 _ call B 〈 Σ

2/A;B •U〉 (S1:disj:2)

fail B 〈 Σ

2/A;B •U〉 _ fail A;B 〈Σ

U〉 (S1:disj:3)

exit C 〈 Σ

N/A;B •U〉 _ exit A;B 〈OR(N ) •Σ

U〉, with C = bN/A; Bc (S1:disj:4)

redo A;B 〈OR(N ) •Σ

U〉 _ redo C 〈 Σ

N/A;B •U〉, with C = bN/A; Bc (S1:disj:5)

Page 116: Toward the concept of backtracking computation

Legal event and derivation

• Initial event: call Q 〈nilnil〉, where Q is any goal formula.

• Legal event: reachable from an initial event.

• Final event: a legal event that does not lead to another event.

Page 117: Toward the concept of backtracking computation

Legal event and derivation

• Initial event: call Q 〈nilnil〉, where Q is any goal formula.

• Legal event: reachable from an initial event.

• Final event: a legal event that does not lead to another event.

Page 118: Toward the concept of backtracking computation

Legal event and derivation

• Initial event: call Q 〈nilnil〉, where Q is any goal formula.

• Legal event: reachable from an initial event.

• Final event: a legal event that does not lead to another event.

call Q 〈nilnil〉 _

∗ E0 _∗ E

Page 119: Toward the concept of backtracking computation

Legal event and derivation

• Initial event: call Q 〈nilnil〉, where Q is any goal formula.

• Legal event: reachable from an initial event.

• Final event: a legal event that does not lead to another event.

call Q 〈nilnil〉 _

∗ E0 _∗ E

︸ ︷︷ ︸

legal derivation

Page 120: Toward the concept of backtracking computation

Legal event and derivation

• Initial event: call Q 〈nilnil〉, where Q is any goal formula.

• Legal event: reachable from an initial event.

• Final event: a legal event that does not lead to another event.

legal event

call Q 〈nilnil〉 _

∗ E0 _∗ E

︸ ︷︷ ︸

legal derivation

In S1:PP, a legal event can have only one legal predecessor, and only one

successor (Theorem 4.2 in [Kul04]).

Page 121: Toward the concept of backtracking computation

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

_ fail (good, bad) , main •nil, nil

_ fail main , nil, nil

Page 122: Toward the concept of backtracking computation

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

_ fail (good, bad) , main •nil, nil

_ fail main , nil, nil

Page 123: Toward the concept of backtracking computation

call main , nil, nil

_ call (good, bad) , main •nil, nil

_ call good , 1/good, bad •main •nil, nil

_ call true , good • 1/good, bad •main •nil, nil

_ exit true , good • 1/good, bad •main •nil, nil

_ exit good , 1/good, bad •main •nil, BY (true) •nil

_ call bad , 2/good, bad •main •nil, BY (true) •nil

_ fail bad , 2/good, bad •main •nil, BY (true) •nil

_ redo good , 1/good, bad •main •nil, BY (true) •nil

_ redo true , good • 1/good, bad •main •nil, nil

_ fail true , good • 1/good, bad •main •nil, nil

_ fail good , 1/good, bad •main •nil, nil

_ fail (good, bad) , main •nil, nil

_ fail main , nil, nil

Page 124: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉 _ _ ... _︸ ︷︷ ︸ E

no Pop 〈U〉

Page 125: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉

._ E

Page 126: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉

._ E

• backward derivation relative to U : Pop G 〈ΣU〉 _ _ ... _︸ ︷︷ ︸ E

no Push 〈U〉

Page 127: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉

._ E

• backward derivation relative to U : Pop G 〈ΣU〉

/_ E

Page 128: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉

._ E

• backward derivation relative to U : Pop G 〈ΣU〉

/_ E

• simple pass relative to G ,U : Push G 〈U〉

._ Pop G 〈

U〉

Pop G 〈U〉

/_ Push G 〈

U〉

Page 129: Toward the concept of backtracking computation

Aggregations: Simple pass

• forward derivation relative to U : Push G 〈ΣU〉

._ E

• backward derivation relative to U : Pop G 〈ΣU〉

/_ E

• simple pass relative to G ,U : Push G 〈U〉 −→ Pop G 〈

U〉

Pop G 〈U〉 −→ Push G 〈

U〉

G 〈U〉 −→ G 〈

U〉

stage stage

Page 130: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

Page 131: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉

Page 132: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉 ←− exit G 〈

U〉

Page 133: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉 ←− exit G 〈

U〉 ←− Push G 〈

U〉

Page 134: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉 ←− exit G 〈

U〉 ←− Push G 〈

U〉 ←− ...←− call G 〈

U〉

Page 135: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉 ←− exit G 〈

U〉 ←− Push G 〈

U〉 ←− ...←− call G 〈

U〉

Definition of composed pass relative to G ,U :

EG,U1 −→−→ ... −→︸ ︷︷ ︸ EG,U

2

no call G 〈U〉

also called composable sequence

Page 136: Toward the concept of backtracking computation

Aggregations: Composed pass

Based on:

• If Pop G 〈ΣU〉 is legal, then Pop G 〈Σ

U〉 ←− Push G 〈Σ

U〉. (Lemma 5.6)

• If fail H 〈ΣU〉 is legal, then fail H 〈Σ

U〉^∗ call H 〈Σ

U〉, where

call H 〈U〉 does not appear within the derivation. Furthermore, if

redo H 〈ΣU〉 is legal, then redo H 〈Σ

U〉 ←− exit H 〈Σ

U〉. (Theorem 6.1)

redo G 〈U〉 ←− exit G 〈

U〉 ←− Push G 〈

U〉 ←− ...←− call G 〈

U〉

Definition of composed pass relative to G ,U :

EG,U1 =⇒ EG,U

2

Page 137: Toward the concept of backtracking computation

Some properties of S1:PP

Uniqueness of steps: transition relation, as well as its converse on

legal events, are functional (Theorem 4.2)

→ forward and backward derivation steps are possible

For application, see the sketches on non-interference and

modularity of conjunction.

Page 138: Toward the concept of backtracking computation

Independence on the context of derivation: the same goal goes

through the same stages (Theorem 7.6)

Theorem 7.6 ( independence ) Let the following sequences be composable,

where m,k ≥ 1, and let Θ(H ) = Σ(G).

call G 〈ΣU〉 −→ EG,U

1 −→ ... −→ EG,Um

call H 〈ΘV〉 −→ EH ,V

1 −→ ... −→ EH ,Vk

Then for any i in common (i ≤ m, k) holds:

If EG,Ui := Γ G 〈Σ

U〉 then EH ,V

i = Γ H 〈Σ′−Σ +Θ

V〉.

Page 139: Toward the concept of backtracking computation

A legal derivation is modular, due to compositionality of rules wrt

conjunction and disjunction, and stages (Theorem 7.2, Theorem 7.3)

→ abstracting parts of a derivation is possible

Theorem 7.2 ( ) If call G 〈nilnil〉 _ E1 _ ... _ En _ Pop G 〈∆

nil〉, then for every

G, U , Σ such that call G 〈ΣU〉 is legal and Σ(G) = G holds:

call G 〈ΣU〉 _ E1

§ 〈Σ

U〉 _ ... _ En

§ 〈Σ

U〉 _ Pop G 〈∆ +Σ

U〉

is also a legal derivation.

Theorem 7.3 ( ) Let call G 〈ΣU〉 _ E1 _ ... _ En _ Pop G 〈Ω

U〉 be legal, and

Ei 6= Pop 〈U〉 for every i. Then for G ′ := Σ(G) holds:

call G ′ 〈nilnil〉 _ E ′

1 〈ΣU〉 _ ... _ E ′

n 〈ΣU〉 _ Pop G ′ 〈Ω−Σ

nil〉

is also a legal derivation. Here if Ei = Γ H 〈ΘV〉, then E′

i := Γ H ′ 〈 Θ

V′〉, where

Σ(H ) = H ′ and Σ(V ) = V′.

§ possibly the fresh variables of Ei have to be renamed

Page 140: Toward the concept of backtracking computation

Modeling Prolog execution in S1:PP

Theorem 8.1 ( existential termination, success, failure ) Prolog computation of agoal G relative to Π terminates existentially if there is a simple pass

call G 〈nilnil〉 −→ Pop G 〈∆

nil〉

In case Pop = exit , the computation is successful, otherwise it is failed.

Theorem 8.2 ( the first computed answer ) If call G 〈nilnil〉 −→ exit G 〈∆

nil〉, then

subst(∆) |G is the first computed answer substitution for G relative to Π in Prolog.

Theorem 8.3 ( all computed answers, universal termination ) In a composablesequence

call G 〈 nil1/G,fail • nil

〉 −→2k−1 exit G 〈 ∆

1/G,fail • nil〉

is subst(∆) |G the kth computed answer substitution for G relative to Π in Prolog.Furthermore, G is universally terminating relative to Π if

call G 〈 nil1/G,fail • nil

〉 =⇒ fail G 〈 nil1/G,fail • nil

Page 141: Toward the concept of backtracking computation

Vanilla meta-interpreter

Let exit A,B 〈ΣU〉 be a legal event. How could it have been derived?

There is only one way:

exit A,B 〈ΣU〉

^ exit B 〈 Σ

2/A,B •U〉, by (S1:conj:4)

⇐= call B 〈 Σ

2/A,B •U〉, by Theorem 6.5(2), with Σ Σ

^ exit A 〈 Σ

1/A,B •U〉, by (S1:conj:2)

⇐= call A 〈 Σ

1/A,B •U〉, by Theorem 6.5(2), with Σ

Σ

^ call A,B 〈Σ

U〉, by (S1:conj:1)

The converse (starting from exit A and exit B) yields itself as well.

Similarly for disjunction.

Page 142: Toward the concept of backtracking computation

Summary of S1:PP operational semantics

• focus on general goals¶ instead of selected atoms

• forward and backward derivation steps treated equally

• modularity of derivation: parts of execution can be abstracted

• lean data structure for “state of computation”:

– one ancestor stack, A-stack

– one (generalized) environment, B-stack

¶ there are precursors in advocating the idea of general goals: [CvEHL92], [TB93]

Page 143: Toward the concept of backtracking computation

Back to motivation: Capturing non-interference

Push events (call, redo) are more amenable to forward steps, and pop

events (exit, fail) are more amenable to backward steps.

Example: Assume run-time test Cc succeeds exactly once.

call Cc,G 〈U〉 fail Cc,G 〈

U〉

_ call Cc 〈Cc,G •U

〉 ^ fail Cc 〈Cc,G •U

−→ exit Cc 〈Cc,G •U

〉 ←− redo Cc 〈Cc,G •U

_ call G 〈Cc,G •U

〉 ^ fail G 〈Cc,G •U

exit Cc,G 〈U〉 redo Cc,G 〈

U〉

^ exit G 〈Cc,G •U

〉 _ redo G 〈Cc,G •U

Page 144: Toward the concept of backtracking computation

References

[Byr80] Lawrence Byrd. Understanding the control flow of Prolog programs. InS. A. Tarnlund, editor, Proc. of the 1980 Logic Programming Workshop,Debrecen, pages 127–138, 1980. Also as D.A.I. Research Paper 151.

[CvEHL92] M. H. M. Cheng, M. H. van Emden, R. N. Horspool, and M. Levy.Compositional operational semantics for Prolog programs. J. NewGeneration Computing, 10(3):315–328, 1992.

[JM84] N. D. Jones and A. Mycroft. Stepwise development of operational anddenotational semantics for Prolog. In Proc. of ISLP’84, Atlantic City,pages 281–288, 1984.

[Kul04] M. Kulas. Toward the concept of backtracking computation. In L. Aceto,W. J. Fokkink, and I. Ulidowski, editors, Proc. of SOS’04, London,ENTCS. Elsevier, 2004. To appear.

[TB93] G. Tobermann and C. Beckstein. What’s in a trace: The box modelrevisited. In Proc. of AADEBUG’93, Linkoping, volume 749 of LNCS,pages 171–187. Springer-Verlag, 1993.