flat domains and recursive equations in acl2 by john
play

Flat Domains and Recursive Equations in ACL2 by John Cowles - PDF document

Flat Domains and Recursive Equations in ACL2 by John Cowles University of Wyoming 1 ACL2 is a logic of total functions. Some recursive equations have no satisfying ACL2 functions: No ACL2 function g satisfies this recursive equation


  1. Flat Domains and Recursive Equations in ACL2 by John Cowles University of Wyoming 1

  2. ACL2 is a logic of total functions. • Some recursive equations have no satisfying ACL2 functions: No ACL2 function g satisfies this recursive equation (equal (g x) (if (equal x 0) nil (cons nil (g (- x 1))))). Theory of flat domains is a rival logic of total functions. • Every recursive equation has at least one satisfying function. 2

  3. Flat Domains From the fix-point theory of program semantics. A flat domain is a structure < S, ⊑ , ⊥ > , where • S is a set, • ⊥ ∈ S , and • ⊑ is the partial order defined by ⇒ x = ⊥ ∨ x = y. x ⊑ y ⇐ 3

  4. Graphical representation of a flat domain: S − {⊥} · · · · · · t t t t t ❜ ✧✧✧✧✧✧✧✧ ▲ ☞ ❜ ▲ ☞ ❜ ❜ ▲ ☞ ❜ ▲ ☞ ❜ ❜ ▲ ☞ ❜ ⊥ • Graphical representation of the ❁ relation defined by x ❁ y ⇐ ⇒ x ⊑ y ∧ x � = y. • The “flat part” is depicted by the vertices labeled with S − {⊥} . 4

  5. Extend the partial order, ⊑ , componentwise to • tuples from S × S × · · · × S by < x 1 , . . . , x n > ⊑ < y 1 , . . . , y n > ⇐ ⇒ x 1 ⊑ y 1 ∧ · · · ∧ x n ⊑ y n • functions f, g : S × · · · × S → S by x ∈ S n )[ f ( � ⇒ ( ∀ � x ) ⊑ g ( � x )] f ⊑ g ⇐ 5

  6. Flat Domains Use total functions to model partial functions . • Interpret f ( � x ) = ⊥ as meaning f ( � x ) is undefined . • Interpret, for functions f and g , f ⊑ g as meaning whenever f ( � x ) is defined, ◦ g ( � x ) is also defined, and ◦ f ( � x ) = g ( � x ). 6

  7. Least Upper Bounds of Chains Every chain of functions on S , f 0 ⊑ f 1 ⊑ · · · ⊑ f i ⊑ · · · , has an unique least upper bound , ⊔ f i . • ⊔ f i is a function on S , • for all j , f j ⊑ ⊔ f i and • if f is any function such that for all i , f i ⊑ f , then ⊔ f i ⊑ f , • define ⊔ f i ( � x ) by cases: Case 1. ∀ i ( f i ( � x ) = ⊥ ). Let ⊔ f i ( � x ) = ⊥ . Case 2. ∃ j ( f j ( � x ) � = ⊥ ). Let ⊔ f i ( � x ) = f j ( � x ). 7

  8. Flat Domains Recursive Equations Let F be a function variable and let τ [ F ] be a term built by compositions involving F and other functions. A recursive equation is of the form F ( � x ) = τ [ F ]( � x ) . A solution for such an equation is a function f such that for all � x , f ( � x ) = τ [ f ]( � x ) . Such a solution f is called a fixed point of the term τ [ F ]( � x ). 8

  9. Flat Domains The Kleene Construction A term τ [ F ] is monotonic : • Whenever f and g are functions such that f ⊑ g , then τ [ f ] ⊑ τ [ g ]. Kleene’s construction: • When τ [ F ] is monotonic, F ( � x ) = τ [ F ]( � x ) always has a solution. 9

  10. Flat Domains The Kleene Construction Kleene’s construction: • Use the term τ [ F ] to recursively define a chain of functions, f 0 ( � x ) = ⊥ f i +1 ( � x ) = τ [ f i ]( � x ) . • Since τ [ F ] is monotonic, f 0 ⊑ f 1 ⊑ · · · ⊑ f i ⊑ · · · • Then, ⊔ f i = τ [ ⊔ f i ] . That is, ⊔ f i is a solution for the recursive equation F ( � x ) = τ [ F ]( � x ). 9-a

  11. Turn ACL2 data into a flat domain Impose a partial order, $<=$ , on ACL2 data: • specify a “least element”, ($bottom$) , strictly less than any other ACL2 datum (defstub $bottom$ () => *) • no other distinct data items are related: (defun $<=$ (x y) (or (equal x ($bottom$)) (equal x y))) • ($bottom$) plays the part of ⊥ and $<=$ plays the part of ⊑ . 10

  12. Chains of functions in ACL2 Formalize a chain of functions f 0 ⊑ f 1 ⊑ · · · ⊑ f i ⊑ · · · . • Treat the index as an additional argument to the function, so f i ( x ) becomes (f i x) in ACL2. • The $<=$ -chain of functions is consistently axiomatized by (implies (and (integerp i) (>= i 0)) ($<=$ (f i x) (f (+ 1 i) x))). 11

  13. Chains of functions in ACL2 Formalize the least upper bound, ⊔ f i , of f 0 ⊑ f 1 ⊑ · · · ⊑ f i ⊑ · · · . • Use defchoose to pick the appropriate “index” required in the definition of the least upper bound. • ACL2 verifies this formal least upper bound is, in fact, the least upper bound of the chain. 12

  14. Which ACL2 terms are monotonic? Recall: To ensure that Kleene’s construction always produces • a solution for the recursive equation F ( � x ) = τ [ F ]( � x ) , • the term τ [ F ] must be monotonic: f ⊑ g ⇒ τ [ f ] ⊑ τ [ g ] . 13

  15. Which ACL2 terms are monotonic? Tail Recursion. Let test , base , and st be arbitrary unary functions. Consider a term τ [ F ] of the form (if (test x) (base x) (F (st x)))). Such tail recursive terms are always monotonic . • This means that tail recursive equations always have solutions. • Another explanation for Pete & J’s result that any tail recursive equation is satisfiable by some ACL2 function. 14

  16. Such tail recursive terms are always monotonic : Let f and g be functions such that ($<=$ (f x)(g x)) , [i.e., f ⊑ g ]. Case 1. (test x) is not NIL . τ [ f ]( x ) = ( base x ) = τ [ g ]( x ). So τ [ f ] ⊑ τ [ g ]. Case 2. (test x) is NIL Since ∀ y [( f y ) ⊑ ( g y )], τ [ f ]( x ) = ( f ( st x )) ⊑ ( g ( st x )) = τ [ g ]( x ) . Thus τ [ f ] ⊑ τ [ g ]. 14-a

  17. Which ACL2 terms are monotonic? Primitive Recursion. Let test , base , and st be arbitrary unary functions. Let h be a binary function. Consider a term τ [ F ] of the form (if (test x) (base x) (h x (F (st x))))) Often such terms are not monotonic. Such terms are monotonic if h always preserves ⊑ in its second input: y 1 ⊑ y 2 ⇒ ( h x y 1 ) ⊑ ( h x y 2 ) 15

  18. Such primitive recursive terms are monotonic if h always preserves ⊑ in its second input: Let f and g be functions such that ($<=$ (f x)(g x)) , [i.e., f ⊑ g ]. Case 1. (test x) is not NIL . τ [ f ]( x ) = ( base x ) = τ [ g ]( x ). So τ [ f ] ⊑ τ [ g ]. Case 2. (test x) is NIL Since ∀ y [( f y ) ⊑ ( g y )], ( f ( st x )) ⊑ ( g ( st x )) . Since h always preserves ⊑ in its second input, τ [ f ]( x ) = ( h x ( f ( st x ))) ⊑ ( h x ( g ( st x ))) = τ [ g ]( x ) . Thus τ [ f ] ⊑ τ [ g ]. 15-a

  19. Such primitive recursive terms are monotonic if h always preserves ⊑ in its second input: y 1 ⊑ y 2 ⇒ ( h x y 1 ) ⊑ ( h x y 2 ) From Consistently Adding Primitive Recursive Definitions in ACL2 , (equal (F x) (if (test x) (base x) (h x (F (st x))))). A sufficient (but not necessary) condition on h for the existence of F is that h have a right fixed point. That is, there is some c such that (h x c) = c . Restate in the terminology of flat domains: A sufficient (but not necessary) condition on h for a primitive recursive term, τ [ F ], to be monotonic is that h have a right fixed point. 15-b

  20. Use: Such primitive recursive terms are monotonic if h always preserves ⊑ in its second input: y 1 ⊑ y 2 ⇒ ( h x y 1 ) ⊑ ( h x y 2 ) To Prove: A sufficient (but not necessary) condition on h for a primitive recursive term, τ [ F ], to be monotonic is that h have a right fixed point, c . Proof. Use the right fixed point c to build a flat domain: • Use c for ⊥ and • ⊑ c for ⊑ where x ⊑ c y ⇐ ⇒ x = c ∨ x = y. • Then y 1 ⊑ c y 2 ⇒ ( h x y 1 ) ⊑ c ( h x y 2 ) 15-c

  21. Which ACL2 terms are monotonic? Nested Recursion. Let test , base , and st be arbitrary unary functions. Consider a term τ [ F ] of the form (if (test x) (base x) (F (F (st x)))) Often such terms are not monotonic. Such terms are monotonic if F always preserves ⊑ : y 1 ⊑ y 2 ⇒ ( F y 1 ) ⊑ ( F y 2 ) That is, restrict the variable F to range only over functions that always preserve ⊑ . 16

  22. Nested Recursion and Kleene’s Construction Recall Kleene’s construction: • Use the term τ [ F ] to recursively define a chain of functions, f 0 ( x ) = ⊥ f i +1 ( x ) = τ [ f i ]( x ) . • Since τ [ F ] is monotonic , f 0 ⊑ f 1 ⊑ · · · ⊑ f i ⊑ · · · • To ensure τ [ F ] is monotonic , the function variable F should range only over functions that always preserve ⊑ . • That is, each f i should always preserve ⊑ . 16-a

  23. Nested Recursion and Kleene’s Construction To ensure that each f i always preserves ⊑ : • Clearly, f 0 , defined by f 0 ( x ) = ⊥ , always preserves ⊑ . • Require : Whenever f always preserves ⊑ , then τ [ f ] is also a function that always preserves ⊑ . 16-b

  24. Nested Recursion and Kleene’s Construction Requirement. Whenever f always preserves ⊑ , then τ [ f ] is also a function that always preserves ⊑ . Orthodox Solution. Functions, that always preserve ⊑ , are closed under composition. • Restrict τ [ F ] to compositions involving F and functions that always preserve ⊑ . • So test , base , st , and if should all be functions that always preserve ⊑ (if (test x) (base x) (F (F (st x)))) • Problem. ACL2’s if does not preserve ⊑ . 16-c

  25. Nested Recursion and Kleene’s Construction Problem. ACL2’s if does not preserve ⊑ . • Assume ⊥ � = NIL . • Then ⊥ ❁ NIL , but • ( if ⊥ 0 1 ) = 0 �⊑ 1 = ( if NIL 0 1 ) Solution. Replace ACL2’s if with a sequential version, sq-if , that always preserves ⊑ . ( sq-if ⊥ b c ) = ⊥ ( sq-if NIL b c ) = c ( sq-if b c ) = b if a � = ⊥ ∧ a � = NIL a 16-d

Recommend


More recommend