A Translator of Actor Prolog to Java Alexei





















- Slides: 21
A Translator of Actor Prolog to Java Alexei A. Morozov, Olga S. Sushkova, and Alexander F. Polupanov Kotel’nikov Institute of Radio Engineering and Electronics of RAS Mokhovaya 11 -7, Moscow, Russia morozov@cplire. ru o. sushkova@mail. ru sashap 55@mail. ru
What is Actor Prolog? n n n n Actor Prolog is a logic language designed on the basis of our experience of business / industrial applications of logic programming. Actor Prolog was initially designed as an objectoriented language with a classical model-theoretic semantics. Actor Prolog is a concurrent language. Actor Prolog implements underdetermined sets. Actor Prolog supports domain and predicate declarations; that is very important for development of big / industrial programs. Actor Prolog produces a fast, stable, and portable stand-alone executable code (including Java applets). The Actor Prolog programming system is open; it can be easily extended by new built-in classes. For instance, Java 2 D and Java 3 D are connected with the Actor Prolog system in this way.
Why Translation to Java? n n It was our unsuccessful attempt to use a commercial Prolog for programming Web agents several years ago. The programs crashed after several days of work because of unintelligible internal problems in the translator and libraries. We need a reliable implementation of a logic language with a clear memory management. Logic programs operating with big amounts of data should work stably during long periods of time. We can use an industrial Java virtual machine as a basis for a logic programming system, because modern processors are fast enough to give up the speed of the executable code for the sake of robustness, readability, and openness of the logic programs. Nevertheless, we need a fast executable code that is appropriate for real-time data processing.
The Compilation Schema n n n n Source text scanning and parsing. Methods of thinking translation that prevent unnecessary processing of already translated source files are implemented. Inter-class links analysis. On this stage of global analysis, the translator collects information about usage of separate classes in the program, including data types of arguments of all class instance constructors. Type check. The translator checks data types of all predicate arguments and arguments of all class instance constructors. Determinism check. The translator checks whether predicates are deterministic or non-deterministic. Socalled imperative predicates are supported, that is, the compiler can check whether a predicate is deterministic and never fails. A global flow analysis. The compiler tracks flow patterns of all predicates in all classes of the program. Generation of an intermediate Java code. Translation of this code by a standard Java compiler.
The Compilation Schema The imperative predicates are translated to Java procedures directly. The imperative predicates usually constitute the main part of the program and ensure very high level of code optimization. n The deterministic predicates are translated to Java procedures too. All clauses of one predicate correspond to one Java procedure. Backtracking is implemented using a special kind of light-weight Java exceptions. n The non-deterministic predicates are implemented using a standard method of continuation passing. Clauses of one predicate correspond to one or several automatically generated Java classes. n
The Compilation Schema Tail recursion optimization is implemented for recursive predicates. Recursive predicates are implemented using the while Java command. n The Actor Prolog language supports explicit definition of ground / non-ground domains and the translator uses this information for deep optimization of the executable code. n The Actor Prolog language is significantly different from the conventional Clocksin & Mellish Prolog. Object-oriented features and supporting concurrent programming make translation of an Actor Prolog code to be a complex problem. n
The Imperative Predicates goal: p. p: q. q: writeln("Hi!"). public void imp. Proc. P_s 617_0(Choise. Point i. X) { imp. Proc. Q_s 618_0(i. X); } public void imp. Proc. Q_s 618_0(Choise. Point i. X) { imp. Proc. Writeln_s 193_1_i 1( i. X, new Prolog. String("Hi!")); }
The Deterministic Predicates goal: p. p: q. q: writeln("Hi!"). public void det. Proc. P_s 617_0(Choise. Point i. X) throws Backtracking { det. Proc. Q_s 618_0(i. X); } Backtracking is implemented using a special kind of light-weight Java exceptions. n Tail recursion optimization is possible. n
The Non-Deterministic Predicates class Nondet. Proc. P_s 617_0 extends Continuation { private Continuation c 1; Nondet. Proc. P_s 617_0(Continuation a. C) { c 0= a. C; } public void execute(Choise. Point i. X) throws Backtracking { c 1= new Nondet. Proc. Q_s 618_0(c 0); c 1. execute(i. X); } } n n A standard method of continuation passing is used. Tail recursion optimization is possible.
An Imperative Predicate P calls a Non-Deterministic Predicate Q p: q, !. p: writeln("P"). q: writeln("Q"). class And_1_1_P_s 694_0 extends Continuation { private Choise. Point p. S; And_1_1_P_s 694_0( Continuation a. C, Choise. Point a. CP) { c 0= a. C; p. S= a. CP; } public void execute(Choise. Point i. X) throws Backtracking { i. X. disable(p. S); c 0. execute(i. X); } } public void imp. Proc. P_s 694_0(Choise. Point i. X) { Continuation c 1; Continuation c 2; Choise. Point new. Ix; new. Ix= new Choise. Point(i. X); try { c 1= new And_1_1_P_s 694_0(c 0, i. X); c 2= new Nondet. Proc. Q_s 695_0(c 1); c 2. execute(new. Ix); } catch (Backtracking b 1) { if (new. Ix. is. Enabled()) { new. Ix. free. Trail(); imp. Proc. Writeln_s 205_1_i 1( new. Ix, new Prolog. String("P")); } else { throw new Imperative. Procedure. Failed(); } } }
Actor Prolog Benchmark Testing (Intel Core i 5 -2410 M, 2. 30 GHz, Win 7, 64 -bit) Test NREV CRYPT DERIV POLY_10 PRIMES QSORT QUEENS QUERY TAK *Benchmark Iter. No* 3, 000 100, 000 10, 000 100, 000 1, 000 10, 000 Actor Prolog to Java 64 -bit 109, 677, 895 lips 1. 820880 ms 0. 055460 ms 3. 750600 ms 0. 037340 ms 0. 043129 ms 19. 219600 ms 3. 135300 ms 3. 913400 ms SWI-Prolog v. 7. 2. 2 15, 792, 155 lips 1. 98979 ms 0. 0105815 ms 4. 4257 ms 0. 14196 ms 0. 063976 ms 32. 4248 ms 0. 4056 ms 11. 1182 ms time is measured in milliseconds per iteration.
Advantages and Disadvantages n n n n n Portability of the programs Reliability and stability of the programs Safety of the programs (Java-applets) Readability of the intermediate code Availability of all Java means (Internet protocols, Java 2 D, Java 3 D, etc. ) The use of industrial virtual machine is a basis for quick adaptation to new operating systems and processor architectures. The executable code is comparatively slow. Only static optimization is available. We depend on JVM.
Implementation of Actor Prolog Terms in Java n n n n Argument. Number. java Prohibited. Set. Element. java Prolog. Array. java Prolog. Empty. List. java Prolog. Empty. Set. java Prolog. Integer. java Prolog. List. java Prolog. No. Value. java Prolog. Optimized. Set. java Prolog. Real. java Prolog. Set. Element. java Prolog. String. java n n n n Prolog. Structure. java Prolog. Symbol. java Prolog. Unknown. Value. java Prolog. Variable. java Slot. Variable. Value. State. java Term. Circumscribing. Mode. java Term. Comparator. java Term. Position. java Underdetermined. Set. Item. java Underdetermined. Set. With. Tail. java Ground and non-ground (reference) Actor Prolog terms are implemented using the same Java classes.
Extension of Actor Prolog External Java classes can be declared as ancestors of automatically created Java classes and this is the basic principle of the implementation of built-in classes and integration of Actor Prolog programs with external libraries.
Extension of Actor Prolog package "Morozov/Vision": class 'Image. Subtractor' (specialized 'Alpha'): extract_blobs = 'no'; track_blobs = 'no'; . . . [ SOURCE: "morozov. built_in. Image. Subtractor"; CLAUSES: subtract(Frame. Number, Image): [external "subtract"]. . ] public static abstract class Abstr. Cls 5_1076_Image. Subtractor extends morozov. built_in. Image. Subtractor {. . .
Results and Conclusions A translator of Actor Prolog to Java was developed. The state-of-the-art compilation schema of the Actor Prolog system includes a type check, a determinism check, and a global flow analysis. This compilation schema ensures a high performance of the executable code. n The open source Java library of Actor Prolog builtin classes is published in Git. Hub. n Application domains of the translator include but are not limited to the intelligent visual surveillance (a real-time monitoring of anomalous people activities and a logical description and analysis of people behaviour), 3 D scientific visualization, and logic programming Web applications. n
Future Research n n n The future of the intelligent visual surveillance is intelligent multi-camera heterogeneous video surveillance systems. Multi-agent systems were recognised as a promising approach to the development of multi-camera surveillance systems. There a lot of research projects on development of ontologies, agent models, and agent protocols for video surveillance. The problem is in that agents need communication in special terms of low/high-level video processing to take a real benefit of decentralization. Thus, development of ontologies and agent protocols essentially depends on the ongoing research ideas and results in the area of video surveillance. We look for partners for joint projects. Cumulative research efforts are necessary.
Some Web Resources • The Project Web Site containing demo video clips, applets, and source code of Actor Prolog demo programs for intelligent video surveillance: http: //www. fullvision. ru/actor_prolog/ • A Git. Hub repository containing source codes of Actor Prolog built-in classes: https: //github. com/Morozov 2012/actor-prolog-java -library • Getting Started in Actor Prolog: http: //www. cplire. ru/Lab 144/start/ • A demo Web Site on linking Java 3 D with the Actor Prolog language: http: //alexei-morozov-2012. narod. ru/
An Example of a Logic Program Implementing a Kind of Intelligent Video Surveillance
Thank you http: //www. fullvision. ru/actor_prolog
We invite you to participate in the beta testing of the educational version of Actor Prolog: Domain and predicate declarations are supported. n One can switch off the check of the declarations. n Creation of And-Or trees is supported. n Compilers to Java and EXE code are available. n morozov@cplire. ru http: // www. fullvision. ru / actor_prolog