a simple java code generator for acl2 based on a deep
play

A Simple Java Code Generator for ACL2 Based on a Deep Embedding of - PowerPoint PPT Presentation

A Simple Java Code Generator for ACL2 Based on a Deep Embedding of ACL2 in Java Alessandro Coglio Kestrel Institute Workshop 2018 ATJ Java code generator for ACL2 (ACL2 To Java) based on AIJ deep embedding of ACL2 in Java (ACL2 In Java)


  1. A Simple Java Code Generator for ACL2 Based on a Deep Embedding of ACL2 in Java Alessandro Coglio Kestrel Institute Workshop 2018

  2. ATJ Java code generator for ACL2 (ACL2 To Java) based on AIJ deep embedding of ACL2 in Java (ACL2 In Java)

  3. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards.

  4. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values.

  5. AIJ includes a Java representation of all the constructible ACL2 values. all the constructible ACL2 values complex rationals ratios characters strings symbols cons pairs rationals integers numbers

  6. AIJ includes a Java representation of all the constructible ACL2 values. values ⊂ ⊂ ⊂ ⊂ ⊂ numbers characters strings symbols cons pairs ⊂ ⊂ rationals complex rationals ⊂ ⊂ This hierarchy of sets... integers ratios

  7. AIJ includes a Java representation of all the constructible ACL2 values. Value Number Character String Symbol Cons Rational ComplexRational This hierarchy of sets... Integer Ratio ... is represented as a hierarchy of Java classes.

  8. AIJ includes a Java representation of all the constructible ACL2 values. public final class Integer extends Rational { // internal representation: private final java.math.BigInteger bigInt; // factory methods (to build values): public static Integer make(int ...) {...} public static Integer make(long ...) {...} public static Integer make(java.math.BigInteger ...) {...} // getter methods (to unbuild values): public int getJavaInt() {...} public long getJavaLong() {...} public java.math.BigInteger getJavaBigInteger() {...} ... }

  9. AIJ includes a Java representation of all the constructible ACL2 values. Value Number Character String Symbol Cons Rational ComplexRational These classes have: Integer Ratio • Private internal representations. • Public factory methods for building. • Public getter method for unbuilding.

  10. AIJ includes a Java representation of all the constructible ACL2 values. public final class Ratio extends Rational { // internal representation: private final Integer numerator; private final Integer denominator; ... }

  11. AIJ includes a Java representation of all the constructible ACL2 values. Value car cdr name Number Character String Symbol Cons packageName realPart Rational ComplexRational PackageName imaginaryPart numerator Integer Ratio denominator

  12. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values. • A Java representation of the ACL2 terms.

  13. AIJ includes a Java representation of the ACL2 (translated) terms. Term * arguments Variable FunctionApplication Constant name value function Symbol Value Function body * name NamedFunction LambdaExpression parameters These classes are structured analogously to the classes for values.

  14. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values. • A Java representation of the ACL2 terms. • A Java representation of the ACL2 environment.

  15. AIJ includes a Java representation of (part of) the ACL2 environment. public final class Environment { // package definitions: private static final java.util.Map<PackageName, Symbol[]> packageDefs; // function definitions: private static final java.util.Map<Symbol, LambdaExpression> functionDefs; // methods to build the environment: public static void addPackageDef(...) {...} public static void addFunctionDef(...) {...} ... }

  16. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values. • A Java representation of the ACL2 terms. • A Java representation of the ACL2 environment. • A Java implementation of the ACL2 primitives.

  17. AIJ includes a Java implementation of all the ACL2 primitive functions. ACL2 !>(strip-cars *primitive-formals-and-guards*) (ACL2-NUMBERP BAD-ATOM<= BINARY-* BINARY-+ UNARY-- UNARY-/ < CAR CDR CHAR-CODE CHARACTERP CODE-CHAR COMPLEX COMPLEX-RATIONALP COERCE CONS CONSP DENOMINATOR EQUAL IF IMAGPART INTEGERP INTERN-IN-PACKAGE-OF-SYMBOL NUMERATOR PKG-IMPORTS PKG-WITNESS RATIONALP REALPART STRINGP SYMBOL-NAME SYMBOL-PACKAGE-NAME SYMBOLP) ACL2 !> these functions have primitive ⇒ built-in no ACL2 definitions ⇍

  18. AIJ includes a Java implementation of all the ACL2 primitive functions. class Primitive { private static Value execBinaryPlus(Value x, Value y) {...} private static Value execUnaryMinus(Value x) {...} private static Value execCar(Value x) {...} private static Value execComplex(Value x, Value y) {...} private static Value execConsp(Value x) {...} private static Value execEqual(Value x) {...} private static Value execPkgImports(Value x) {...} ... } no execIf method ( if is treated specially)

  19. AIJ includes a Java implementation of all the ACL2 primitive functions. class Primitive { private static Value execBinaryPlus(Value x, Value y) {...} private static Value execUnaryMinus(Value x) {...} private static Value execCar(Value x) {...} private static Value execComplex(Value x, Value y) {...} private static Value execConsp(Value x) {...} private static Value execEqual(Value x) {...} private static Value execPkgImports(Value x) {...} ... static Value call(Symbol function, Value[] values) { if (function.equals(Symbol.BINARY_PLUS)) { // call execBinaryPlus } else if (function.equals(Symbol.UNARY_MINUS)) { // call execUnaryMinus } ... } }

  20. AIJ includes a Java implementation of all the ACL2 primitive functions. class Primitive { private static Value execUnaryMinus(Value x) { assert x != null; return x.negate(); } ... }

  21. AIJ includes a Java implementation of all the ACL2 primitive functions. public abstract class Value { Number negate() { return Integer.ZERO; } default ... implementation }

  22. AIJ includes a Java implementation of all the ACL2 primitive functions. Value.negate default Value implementation Number Character Symbol Cons String Value.negate Rational ComplexRational inherited implementation ComplexRational.negate Integer Ratio Ratio.negate Integer.negate overridding implementations

  23. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values. • A Java representation of the ACL2 terms. • A Java representation of the ACL2 environment. • A Java implementation of the ACL2 primitives. • A Java implementation of the ACL2 evaluator.

  24. AIJ includes a recursive Java implementation of the ACL2 evaluator “in the logic”, i.e. with (set-guard-checking :none) . abstract Value eval(java.util.Map<Symbol, Value> bindings); Term Variable Constant FunctionApplication Variable.eval Constant.eval FunctionApplication.eval evaluate non-strictly f i function applied o call Function.apply t h e r on the argument values

  25. AIJ includes a recursive Java implementation of the ACL2 evaluator “in the logic”, i.e. with (set-guard-checking :none) . abstract Value apply(Value[] values); Function NamedFunction LambdaExpression NamedFunction.apply LambdaExpression.apply call Term.eval on the body d e n obtained from Environment i f e d named function p r i call Primitive.call m i t i v e with the function name

  26. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values, terms, and environment. • A Java implementation of the ACL2 primitives and evaluator.

  27. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values, terms, and environment. • A Java implementation of the ACL2 primitives and evaluator. AIJ provides a Java API to: • Build the ACL2 environment.

  28. AIJ provides a Java API to build the ACL2 environment: package and function definitions, and their constituents. // build the package definitions: ... PackageName.make(...) ... Symbol.make(...) Environment.addPackageDef(...); Environment.addPackageDef(...); ... A call AIJ's AIJ P public // build the function definitions: I methods ... Variable.make(...) ... NamedFunction.make(...) ... FunctionApplication.make(...) Environment.addFunctionDef(...); Environment.addFunctionDef(...); ... code external to AIJ

  29. AIJ is a deep embedding in Java of an executable, side-effect-free, non-stobj-accessing subset of the ACL2 language without guards. AIJ includes: • A Java representation of the ACL2 values, terms, and environment. • A Java implementation of the ACL2 primitives and evaluator. AIJ provides a Java API to: • Build the ACL2 environment. • Evaluate ACL2 function calls: • Build the argument values. • Call the function on the arguments, obtaining a result. • Unbuild the result value.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend