Isomorphic Data Type Transformations
Alessandro Coglio Stephen Westfold
KESTREL
INSTITUTE
Isomorphic Data Type Transformations Alessandro Coglio Stephen - - PowerPoint PPT Presentation
Isomorphic Data Type Transformations Alessandro Coglio Stephen Westfold KESTREL INSTITUTE Isomorphic data type transformations are useful in program synthesis. some of these may be ! requirements specification isomorphic
KESTREL
INSTITUTE
Isomorphic data type transformations are useful in program synthesis.
๐ ๐ก! ๐ก"
. . .
intermediate specifications stepwise refinements ๐ก! requirements specification implementation code generation
(optional in ACL2)
some of these may be isomorphic transformations ยง represent finite sets as repetition-free ordered lists e.g. ยง turn unbounded integers into bounded integers (under preconditions) ยง add redundant record components for caching ยง change loop direction ยง ...
Isomorphic data type transformations are useful in program synthesis. They are also useful in program analysis.
๐โฒ ๐ก!
"
๐ก#
"
. . .
๐ก$
"
existing program code representation code lifting anti-refinements, via โinversesโ of the transformations for refinements higher-level representations, which may be easier to verify some of these may be isomorphic transformations, which are inherently reversible ยง represent repetition-free
e.g. ยง turn bounded integers into unbounded integers (under preconditions) ยง remove redundant record components for caching ยง change loop direction ยง ...
๐ก! ๐ก%
. . .
๐ก!
"
. . .
๐ก$
"
๐โฒ top-down derivation bottom-up anti-derivation equal or trivially equivalent end-to-end proof that ๐โฒ satisfies ๐ก! ๐ก#
"
. . .
๐ก$
"
๐โฒ ๐ก!
"
Isomorphic data type transformations are useful in program synthesis. They are also useful in program analysis, as well as in analysis-by-synthesis.
๐ ๐ก# ๐ก%
. . .
๐ก!
Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. ๐ ๐"# ๐ ๐โฒ ๐"# โ ๐ = ๐๐$ ๐ โ ๐"# = ๐๐$!
Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. ๐ ๐"# ๐ ๐โฒ ๐"# โ ๐ = ๐๐$ ๐ โ ๐"# = ๐๐$! ๐"# ๐ ๐ ๐โฒ ๐"# โ ๐ = ๐๐% ๐ โ ๐"# = ๐๐%!
Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a function ๐ โถ ๐ โถ ๐, a computation from inputs of type ๐ to outputs of type ๐. ๐ ๐"# ๐ ๐โฒ ๐"# โ ๐ = ๐๐$ ๐ โ ๐"# = ๐๐$! ๐"# ๐ ๐ ๐โฒ ๐"# โ ๐ = ๐๐% ๐ โ ๐"# = ๐๐%! ๐
Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a function ๐ โถ ๐ โถ ๐, a computation from inputs of type ๐ to outputs of type ๐. We can mechanically construct a function ๐! โถ ๐โฒ โถ ๐โฒ that makes the diagram commute. ๐ ๐"# ๐ ๐โฒ ๐"# ๐ ๐ ๐โฒ ๐ ๐โฒ ๐"# โ ๐ = ๐๐$ ๐ โ ๐"# = ๐๐$! ๐"# โ ๐ = ๐๐% ๐ โ ๐"# = ๐๐%! ๐โฒ = ๐ โ ๐ โ ๐"# ๐ = ๐"# โ ๐โฒ โ ๐ โบ
๐โฒ ๐ ๐ ๐"# ๐"# ๐ ๐ ๐โฒ ๐ ๐โฒ ๐โฒ = ๐ โ ๐ โ ๐"# ๐โฒ โก ๐ โ ๐ โ ๐"#
we could just define ๐โฒ like this, but that is not very interesting
Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a function ๐ โถ ๐ โถ ๐, a computation from inputs of type ๐ to outputs of type ๐. We can mechanically construct a function ๐! โถ ๐โฒ โถ ๐โฒ that makes the diagram commute.
๐โฒ ๐ ๐ ๐"# ๐"# ๐ ๐ ๐โฒ ๐ ๐โฒ ๐โฒ = ๐ โ ๐ โ ๐"# Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a function ๐ โถ ๐ โถ ๐, a computation from inputs of type ๐ to outputs of type ๐. We can mechanically construct a function ๐! โถ ๐โฒ โถ ๐โฒ that makes the diagram commute.
๐ฃ๐ ๐ ๐ฆ ๐ฎ๐ข๐๐จ ๐ ๐ฆ ๐๐ฆ๐ญ๐ ๐(๐ฆ, ๐(๐(๐ฆ))) ๐ ๐ฆ โก
๐ โ ๐ ๐ โถ ๐ โถ ๐ ๐ โถ ๐ ร ๐ โถ ๐ ๐ โถ ๐ โถ ๐
representative recursive definition โข ยฌ๐ ๐ฆ โน ๐(๐(๐ฆ)) โบ ๐(๐ฆ) ๐ terminates keep the same structure and add the conversions ๐โฒ ๐ฆ" โก ๐ฃ๐ ๐(๐&# ๐ฆ" ) ๐ฎ๐ข๐๐จ ๐(๐(๐&# ๐ฆ" )) ๐๐ฆ๐ญ๐ ๐(๐(๐&# ๐ฆ" , ๐&# ๐โฒ(๐ ๐(๐&# ๐ฆ" ) ) ))
๐โฒ ๐ ๐ ๐"# ๐"# ๐ ๐ ๐โฒ ๐ ๐โฒ Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider two isomorphic sets (data types) ๐ and ๐โฒ with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a function ๐ โถ ๐ โถ ๐, a computation from inputs of type ๐ to outputs of type ๐. We can mechanically construct a function ๐! โถ ๐โฒ โถ ๐โฒ that makes the diagram commute.
๐ฃ๐ ๐ ๐ฆ ๐ฎ๐ข๐๐จ ๐ ๐ฆ ๐๐ฆ๐ญ๐ ๐(๐ฆ, ๐(๐(๐ฆ))) ๐ ๐ฆ โก
๐ โ ๐ ๐ โถ ๐ โถ ๐ ๐ โถ ๐ ร ๐ โถ ๐ ๐ โถ ๐ โถ ๐
representative recursive definition โข ยฌ๐ ๐ฆ โน ๐(๐(๐ฆ)) โบ ๐(๐ฆ) ๐ terminates keep the same structure and add the conversions ๐โฒ ๐ฆ" โก ๐ฃ๐ ๐(๐&# ๐ฆ" ) ๐ฎ๐ข๐๐จ ๐(๐(๐&# ๐ฆ" )) ๐๐ฆ๐ญ๐ ๐(๐(๐&# ๐ฆ" , ๐&# ๐โฒ(๐ ๐(๐&# ๐ฆ" ) ) )) ๐" โก ๐ โ ๐&# ๐โฒ terminates because ๐ does
โข ๐โฒ = ๐ โ ๐ โ ๐"#
b y i n d u c t i
automatic
๐โฒ ๐ ๐ ๐"# ๐"# ๐ ๐ ๐โฒ ๐ ๐โฒ โข ๐โฒ = ๐ โ ๐ โ ๐"#
๐โฒ ๐ฆ" โก ๐ฃ๐ ๐(๐&# ๐ฆ" ) ๐ฎ๐ข๐๐จ ๐(๐(๐&# ๐ฆ" )) ๐๐ฆ๐ญ๐ ๐(๐(๐&# ๐ฆ" , ๐&# ๐โฒ(๐ ๐(๐&# ๐ฆ" ) ) )) ๐ฃ๐ ๐ ๐ฆ ๐ฎ๐ข๐๐จ ๐ ๐ฆ ๐๐ฆ๐ญ๐ ๐(๐ฆ, ๐(๐(๐ฆ))) ๐ ๐ฆ โก goal: no trace of ๐, ๐, ๐, ๐&#, ๐, ๐&# keep the same structure and add the conversions automatic expand the definitions and rewrite/simplify user-guided ๐ฃ๐ ๐โฒ ๐ฆโฒ ๐ฎ๐ข๐๐จ ๐โฒ ๐ฆโฒ ๐๐ฆ๐ญ๐ ๐โฒ(๐ฆโฒ, ๐โฒโฒ(๐โฒ(๐ฆโฒ))) ๐โฒโฒ ๐ฆ" โก โข ๐"" = ๐โฒ
keep the same structure and add the conversions expand the definitions and rewrite/simplify ๐ ๐ฆ โก โฆ ๐โฒ ๐ฆโฒ โก โฆ ๐โฒโฒ ๐ฆ" โก โฆ
This is a general method: automatically create an isomorphic version and semi-automatically rewrite/simplify it. We can do it for ๐, ๐
#, ๐ 0, etc.,
#โฒ, ๐ #โฒโฒ, ๐ 0โฒ, ๐ 0โฒโฒ, etc.,
Consider a function ๐ that calls ๐, ๐
#, ๐ 0, etc.
๐ โฆ โก โฆ ๐ โฆ โฆ
We can apply the same general method to ๐.
keep the same structure and add the conversions ๐โฒ โฆ โก โฆ ๐(๐(๐&# โฆ )) โฆ expand the definitions and rewrite/simplify ๐โฒโฒ โฆ โก โฆ
If ๐ manipulates the data being transformed
#, ๐ 0, etc., we can automate
the rewriting/simplification step as well. โข ๐ = ๐"# โ ๐โฒ โ ๐
keep the same structure and add the conversions expand the definitions and rewrite/simplify ๐ ๐ฆ โก โฆ ๐โฒ ๐ฆโฒ โก โฆ ๐โฒโฒ ๐ฆ" โก โฆ
This is a general method: automatically create an isomorphic version and semi-automatically rewrite/simplify it. We can do it for ๐, ๐
#, ๐ 0, etc.,
#โฒ, ๐ #โฒโฒ, ๐ 0โฒ, ๐ 0โฒโฒ, etc.,
Consider a function ๐ that calls ๐, ๐
#, ๐ 0, etc.
We can apply the same general method to ๐. If ๐ manipulates the data being transformed
#, ๐ 0, etc., we can automate
the rewriting/simplification step as well. And we can do everything in one step.
keep the same structure and replace ๐ with ๐โฒ etc. ๐ โฆ โก โฆ ๐ โฆ โฆ ๐โฒ โฆ โก โฆ ๐โฒ โฆ โฆ
(isodata ๐ ...) (simplify ๐โฒ ...) ๐ ๐ฆ โก โฆ ๐โฒ ๐ฆโฒ โก โฆ ๐โฒโฒ ๐ฆ" โก โฆ
We use isodata to initiate the isomorphic transformation. We use propagate-iso to propagate the isomorphic transformation.
(propagate-iso ๐ ...) ๐ โฆ โก โฆ ๐ โฆ โฆ ๐โฒ โฆ โก โฆ ๐โฒ โฆ โฆ
The simplify transformation was described at ACL2-2017.
(propagate-iso ๐ ...)
We use propagate-iso to propagate the isomorphic transformation.
๐ โฆ โก โฆ ๐ โฆ โฆ ๐โฒ โฆ โก โฆ ๐โฒ โฆ โฆ (isodata ๐ ...) (simplify ๐โฒ ...) ๐ ๐ฆ โก โฆ ๐โฒ ๐ฆโฒ โก โฆ ๐โฒโฒ ๐ฆ" โก โฆ
We use isodata to initiate the isomorphic transformation.
๐ ๐&# ๐ ๐โฒ ๐ ๐&# ๐ ๐โฒ (defiso ๐ ๐โฒ ๐ ๐&# ...) (defiso ๐ ๐โฒ ๐ ๐&# ...) ๐ ๐&# ๐ ๐โฒ
We use defiso to establish the isomorphic mappings.
(defiso ๐ ๐โฒ ๐ ๐&# ...) and for other types and for ๐
#, ๐ ', etc.
and for ๐#, ๐', etc.
propagate-iso
1. Find events to propagate to
2. Type analysis: which arguments and results to be transformed
3. Dependent isomorphisms
4. Translation: substitution
5.
Dependent Isomorphism: Deriving isomorphism from predicate
๐ต๐๐๐ ๐ โก ๐ฃ๐ ๐๐ข๐๐ ๐ ๐ฎ๐ข๐๐จ ๐ ๐ ๐๐ฆ๐ญ๐ ๐(๐(๐๐๐ ๐ ), ๐ต๐๐๐ ๐๐๐ ๐ ) ๐๐ฃ๐๐ ๐(๐) โน ๐ ๐ = ๐๐๐ ๐ฃ๐ ๐๐ข๐๐ ๐ ๐ฎ๐ข๐๐จ ๐๐๐ ๐๐ฆ๐ญ๐ ๐น ๐น = ๐(๐(๐๐๐ ๐ ), ๐ต๐๐๐ ๐๐๐ ๐ ) โง ๐๐๐๐ก๐(๐น) โง ๐!(๐๐๐ ๐น ) โง ๐ต๐๐๐โฒ(๐๐๐ ๐น ) โด ๐น = ๐๐๐๐ก(๐ ๐๐๐ ๐ , ๐ต๐๐๐(๐๐๐ ๐ )) ๐ต๐๐๐ ๐ โก ๐ฃ๐ ๐๐ข๐๐ ๐ ๐ฎ๐ข๐๐จ ๐๐๐ ๐๐ฆ๐ญ๐ ๐๐๐๐ก(๐(๐๐๐ ๐ ), ๐ต๐๐๐(๐๐๐ ๐ )) Consider two isomorphic sets (data types) ๐ and ๐! with ๐ โถ ๐ โถ ๐โฒ and ๐"# โถ ๐โฒ โถ ๐. Consider a predicate ๐ต๐๐๐ ๐ โก ๐ฃ๐ ๐๐ข๐๐ ๐ ๐ฎ๐ข๐๐จ ๐๐ฃ๐๐ ๐ ๐๐ฆ๐ญ๐ ๐(๐๐๐ ๐ ) โง ๐ต๐๐๐(๐๐๐ (๐)). Then define predicate ๐ต๐๐๐โฒ(๐) โก ๐ฃ๐ ๐๐ข๐๐ ๐ ๐ฎ๐ข๐๐จ ๐๐ฃ๐๐ ๐ ๐๐ฆ๐ญ๐ ๐!(๐๐๐ ๐ ) โง ๐ต๐๐๐โฒ(๐๐๐ (๐)). We want to find definitions for the isomorphisms ๐ต๐๐๐ โถ ๐ต๐๐๐ โถ ๐ต๐๐๐โฒ and ๐ต๐๐๐"# โถ ๐ต๐๐๐โฒ โถ ๐ต๐๐๐. ๐๐ฃ๐๐ ๐ ๐!(๐๐๐ ๐ ) โง ๐ต๐๐๐โฒ(๐๐๐ (๐))
(defun P-map-p (m) (if (atom m) (null m) (and (consp (car m)) (P (caar m)) (natp (cdar m)) (P-map-p (cdr m)))) (defun P'-map-p (m) (if (atom m) (null m) (and (consp (car m)) (P' (caar m)) (natp (cdar m)) (P'-map-p (cdr m)))) (defun P-map-to-P'-map (m) (if (atom m) nil (cons (cons (P-to-P' (caar m)) (cdar m)) (P-map-to-P'-map (cdr m))))
Derive P-map-to-P'-map else clause
(consp (car m)) --> (cons (cons ? ?) ?) (P' (caar m)) --> (cons (cons (P-to-P' (caar m)) ?) ?) (natp (cdar m)) --> (cons (cons ? (cdar m)) ?) identity isomorphism (P'-map-p (cdr m))--> (cons (cons ? ?) (P-map-to-P'-map (cdr m))) Combined: (cons (cons (P-to-P' (caar m)) (cdar m)) (P-map-to--map (cdr m)))
Consider two isomorphic sets (data types) P and P'with P-to-P': P โถ P'
Demo: efficient value caching with invariant maintenance.
ACL2 !> (defiso ...) (isodata ...) (propagate-iso ...)
Coordinator
Drone 1 Drone 2