Quantification in Tail-recursive Function Definitions Sandip Ray - - PowerPoint PPT Presentation

quantification in tail recursive function definitions
SMART_READER_LITE
LIVE PREVIEW

Quantification in Tail-recursive Function Definitions Sandip Ray - - PowerPoint PPT Presentation

Quantification in Tail-recursive Function Definitions Sandip Ray Department of Computer Science University of Texas at Austin Email: sandip@cs.utexas.edu web: http://www.cs.utexas.edu/users/sandip U NIVERSITY OF T EXAS AT A USTIN D EPARTMENT OF C


slide-1
SLIDE 1

Quantification in Tail-recursive Function Definitions

Sandip Ray Department of Computer Science University of Texas at Austin Email: sandip@cs.utexas.edu web: http://www.cs.utexas.edu/users/sandip

UNIVERSITY OF TEXAS AT AUSTIN

slide-2
SLIDE 2

DEPARTMENT OF COMPUTER SCIENCES

Prologue

“ACL2 is a quantifier-free first order logic of recursive functions.”

UNIVERSITY OF TEXAS AT AUSTIN 1

slide-3
SLIDE 3

DEPARTMENT OF COMPUTER SCIENCES

Prologue

“ACL2 is a quantifier-free first order logic of recursive functions.” The Truth: The syntax of ACL2 is quantifier-free, but ACL2 allows us to write quantified predicates via Skolemization.

UNIVERSITY OF TEXAS AT AUSTIN 2

slide-4
SLIDE 4

DEPARTMENT OF COMPUTER SCIENCES

Prologue

“ACL2 is a quantifier-free first order logic of recursive functions.” The Truth: The syntax of ACL2 is quantifier-free, but ACL2 allows us to write quantified predicates via Skolemization. (defun-sk exists-foo (x) (exists y (foo x y)))

UNIVERSITY OF TEXAS AT AUSTIN 3

slide-5
SLIDE 5

DEPARTMENT OF COMPUTER SCIENCES

Prologue

“ACL2 is a quantifier-free first order logic of recursive functions.” The Truth: The syntax of ACL2 is quantifier-free, but ACL2 allows us to write quantified predicates via Skolemization. (defun-sk exists-foo (x) (exists y (foo x y))) (= (exists-foo x) (foo x (foo-witness x))) (implies (foo x y) (exists-foo x))

UNIVERSITY OF TEXAS AT AUSTIN 4

slide-6
SLIDE 6

DEPARTMENT OF COMPUTER SCIENCES

A Preliminary Illustration

Consider defining a predicate true with the following axiom: (= (true x) (if (done x) t (forall x (true (st x))))) The equation is recursive, but in addition has quantification in the body.

UNIVERSITY OF TEXAS AT AUSTIN 5

slide-7
SLIDE 7

DEPARTMENT OF COMPUTER SCIENCES

A Preliminary Illustration

Consider defining a predicate true with the following axiom: (= (true x) (if (done x) t (forall x (true (st x))))) The equation is recursive, but in addition has quantification in the body. ACL2 does not allow us to introduce definitional equations with both recursion and quantification.

UNIVERSITY OF TEXAS AT AUSTIN 6

slide-8
SLIDE 8

DEPARTMENT OF COMPUTER SCIENCES

A Preliminary Illustration

But if the axiom is introduced would the resulting theory be inconsistent? No.

UNIVERSITY OF TEXAS AT AUSTIN 7

slide-9
SLIDE 9

DEPARTMENT OF COMPUTER SCIENCES

A Preliminary Illustration

But if the axiom is introduced would the resulting theory be inconsistent? No. (encapsulate (((true *) => *)) (local (defun true (x) t)) (defthm true-satisfies-its-equation (= (true x) (if (done x) t (forall x (true (st x)))))))

UNIVERSITY OF TEXAS AT AUSTIN 8

slide-10
SLIDE 10

DEPARTMENT OF COMPUTER SCIENCES

A Preliminary Illustration

But if the axiom is introduced would the resulting theory be inconsistent? No. (encapsulate (((true *) => *)) (local (defun true (x) t)) (defthm true-satisfies-its-equation (= (true x) (if (done x) t (forall x (true (st x))))))) ACL2 users have from time to time wanted some form of recursion and quantification together.

UNIVERSITY OF TEXAS AT AUSTIN 9

slide-11
SLIDE 11

DEPARTMENT OF COMPUTER SCIENCES

This Talk

We show how to introduce in ACL2 a class of definitional axioms, called extended tail-recursive axioms, that contain both recursion and quantification.

UNIVERSITY OF TEXAS AT AUSTIN 10

slide-12
SLIDE 12

DEPARTMENT OF COMPUTER SCIENCES

This Talk

We show how to introduce in ACL2 a class of definitional axioms, called extended tail-recursive axioms, that contain both recursion and quantification. The defining equation of a predicate Q-iv is extended tail-recursive if

There is exactly one recursive branch. The outermost function call in the recursive branch is Q-iv, possibly

enclosed by a sequence of quantifiers.

UNIVERSITY OF TEXAS AT AUSTIN 11

slide-13
SLIDE 13

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Why are extended tail-recursive definitions admissible?

UNIVERSITY OF TEXAS AT AUSTIN 12

slide-14
SLIDE 14

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Why are extended tail-recursive definitions admissible? (= (F-iv1 x) (if (done x) (base x) (forall i (F-iv1 (st1 x i)))))

UNIVERSITY OF TEXAS AT AUSTIN 13

slide-15
SLIDE 15

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Why are extended tail-recursive definitions admissible? (= (F-iv1 x) (if (done x) (base x) (forall i (F-iv1 (st1 x i))))) We view st1 as a transformation function that transforms an object x given a choice i. F-iv1 postulates an invariant over this transformation.

UNIVERSITY OF TEXAS AT AUSTIN 14

slide-16
SLIDE 16

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Why are extended tail-recursive definitions admissible? (= (F-iv1 x) (if (done x) (base x) (forall i (F-iv1 (st1 x i))))) We view st1 as a transformation function that transforms an object x given a choice i. F-iv1 postulates an invariant over this transformation. If (done x) holds the invariant is equal to (base x). Otherwise the invariant holds for x if and only if it holds for each successor.

UNIVERSITY OF TEXAS AT AUSTIN 15

slide-17
SLIDE 17

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

We can introduce the equation by defining a witnessing invariant that posits the same thing a little differently.

(defun sn1 (x ch) (if (endp ch) x (sn1 (st1 x (car ch)) (cdr ch)))) (defun n-done (x ch) (if (endp ch) (not (done ch)) (and (not (done x)) (n-done (st1 x (car ch)) (cdr ch))))) (defun done-ch1 (x ch) (and (done (sn1 x ch)) (implies (consp ch) (n-done x (dellast ch))))) (defun-sk F-iv1 (x) (forall ch (implies (done-ch1 x ch) (base (sn1 x ch)))))

UNIVERSITY OF TEXAS AT AUSTIN 16

slide-18
SLIDE 18

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Consider a variant of the above equation. (= (E-iv1 x) (if (done x) (base x) (exists i (E-iv1 (st1 x i)))))

UNIVERSITY OF TEXAS AT AUSTIN 17

slide-19
SLIDE 19

DEPARTMENT OF COMPUTER SCIENCES

Admissibility of Extended Tail-recursive Definitions

Consider a variant of the above equation. (= (E-iv1 x) (if (done x) (base x) (exists i (E-iv1 (st1 x i))))) We can introduce the equation the same way as above. ... (defun-sk E-iv1 (x) (exists ch (and (done-ch1 x ch) (sn1 x ch))))

UNIVERSITY OF TEXAS AT AUSTIN 18

slide-20
SLIDE 20

DEPARTMENT OF COMPUTER SCIENCES

Summing Up the Witnesses

(= (F-iv1 x) (if (done x) (base x) (forall i (F-iv1 (st1 x i))))) The witnessing predicate: “For each sequence ch of choices, such the first descendant of x that satisfies done also satisfies base.” Can be expressed in ACL2.

UNIVERSITY OF TEXAS AT AUSTIN 19

slide-21
SLIDE 21

DEPARTMENT OF COMPUTER SCIENCES

Summing Up the Witnesses

(= (E-iv1 x) (if (done x) (base x) (exists i (F-iv1 (st x i))))) The witnessing predicate: “There exists a sequence ch of choices, such that the first descendant of x that satisfies done also satisfies base.” Can be expressed in ACL2.

UNIVERSITY OF TEXAS AT AUSTIN 20

slide-22
SLIDE 22

DEPARTMENT OF COMPUTER SCIENCES

Summing Up the Witnesses

(= (EF-iv2 x) (if (done x) (base x) (exists i (forall j (F-iv1 (st2 x i j)))))) The witnessing predicate: “ There exists a sequence i-ch of i choices, such that for each sequence j-ch of j choices, the first descendant of x that satisfies done also satisfies base.” Can be expressed in ACL2.

UNIVERSITY OF TEXAS AT AUSTIN 21

slide-23
SLIDE 23

DEPARTMENT OF COMPUTER SCIENCES

Summing Up the Witnesses

(= (iv0 x) (if (done x) (base x) (iv0 (st0 x i)))))) The witnessing predicate: “The first descendant of x that satisfies done also satisfies base.” This is essentially the witnessed designed by Manolios and Moore (2000), to show that tail-recursive equations can always be introduced in ACL2.

UNIVERSITY OF TEXAS AT AUSTIN 22

slide-24
SLIDE 24

DEPARTMENT OF COMPUTER SCIENCES

Logical Impediments

We cannot allow arbitrary recursion and quantification. Doing so will violate conservativity. Acknowledgement: This proof is due to an example provided by Matt

  • Kaufmann. (Thanks, Matt!)
  • 1. A truth predicate of Peano arithmetic is not conservative over Peano Arithmetic.
  • 2. If we have both recursion and quantification then we can define a predicate

true-formula in ACL2.

  • 3. We can then prove by induction that true-formula holds for all formulas that are

provable.

  • 4. Details are in the paper.

UNIVERSITY OF TEXAS AT AUSTIN 23

slide-25
SLIDE 25

DEPARTMENT OF COMPUTER SCIENCES

Upshot of Logical Impediments

It is possible to define true-formula if we allow two recursive branches and quantification. Therefore in general a recursive definition containing quantification and more than one recursive branch is not conservative.

UNIVERSITY OF TEXAS AT AUSTIN 24

slide-26
SLIDE 26

DEPARTMENT OF COMPUTER SCIENCES

A Potential Application

Moore (2003) showed how to use inductive assertions on operationally modeled sequential programs.

UNIVERSITY OF TEXAS AT AUSTIN 25

slide-27
SLIDE 27

DEPARTMENT OF COMPUTER SCIENCES

A Potential Application

Moore (2003) showed how to use inductive assertions on operationally modeled sequential programs.

(= (inv s) (if (cutpoint s) (assertion s) (inv (step s))))

Attempting to prove (implies (inv s) (inv (step s))) causes symbolic simulation of the operational semantics from each cutpoint.

UNIVERSITY OF TEXAS AT AUSTIN 26

slide-28
SLIDE 28

DEPARTMENT OF COMPUTER SCIENCES

A Potential Application

Moore (2003) showed how to use inductive assertions on operationally modeled sequential programs.

(= (inv s) (if (cutpoint s) (assertion s) (inv (step s))))

Attempting to prove (implies (inv s) (inv (step s))) causes symbolic simulation of the operational semantics from each cutpoint. But suppose step is non-deterministic and also takes an input oracle.

UNIVERSITY OF TEXAS AT AUSTIN 27

slide-29
SLIDE 29

DEPARTMENT OF COMPUTER SCIENCES

A Potential Application

Moore (2003) showed how to use inductive assertions on operationally modeled sequential programs.

(= (inv s) (if (cutpoint s) (assertion s) (inv (step s))))

Attempting to prove (implies (inv s) (inv (step s))) causes symbolic simulation of the operational semantics from each cutpoint. But suppose step is non-deterministic and also takes an input oracle. To apply Moore’s method, we now need to write inv as:

(= (inv s) (if (cutpoint s) (assertion s) (forall i (inv (step s i)))))

This equation can be introduced since it is extended tail-recursive.

UNIVERSITY OF TEXAS AT AUSTIN 28

slide-30
SLIDE 30

DEPARTMENT OF COMPUTER SCIENCES

Future Work

We are looking at more avenues for using extended tail-recursive equations.

UNIVERSITY OF TEXAS AT AUSTIN 29

slide-31
SLIDE 31

DEPARTMENT OF COMPUTER SCIENCES

Future Work

We are looking at more avenues for using extended tail-recursive equations.

One possible area might be in formalizing programming language metatheories. Swords: Extended tail-recursive equations might be useful in that domain in some cases, but probably not sufficient for all the interesting properties.

UNIVERSITY OF TEXAS AT AUSTIN 30

slide-32
SLIDE 32

DEPARTMENT OF COMPUTER SCIENCES

Future Work

We are looking at more avenues for using extended tail-recursive equations.

One possible area might be in formalizing programming language metatheories. Swords: Extended tail-recursive equations might be useful in that domain in some cases, but probably not sufficient for all the interesting properties.

We are also looking at extending the class of equations.

Might be possible to have more general equations if we restrict to only well-founded recursions?

UNIVERSITY OF TEXAS AT AUSTIN 31

slide-33
SLIDE 33

DEPARTMENT OF COMPUTER SCIENCES

Future Work

We are looking at more avenues for using extended tail-recursive equations.

One possible area might be in formalizing programming language metatheories. Swords: Extended tail-recursive equations might be useful in that domain in some cases, but probably not sufficient for all the interesting properties.

We are also looking at extending the class of equations.

Might be possible to have more general equations if we restrict to only well-founded recursions? An obvious and frustrating drawback: The semantics of LTL involves both recursion and quantification but is not extended tail-recursive (requires more than one recursive branch).

UNIVERSITY OF TEXAS AT AUSTIN 32

slide-34
SLIDE 34

DEPARTMENT OF COMPUTER SCIENCES

Acknowledgements

J Strother Moore for challenging me to find a way to make his

inductive assertions work applicable for non-deterministic systems.

Matt Kaufmann for extensive discussions on conservativity in ACL2.

UNIVERSITY OF TEXAS AT AUSTIN 33