This document provides a tutorial on Action Rules (AR), a language for delay declarations, constraint propagation, and programming with events. It discusses the syntax and semantics of AR, common programming applications like co-routining and concurrency, using events for constraint propagation, compiling Constraint Handling Rules into AR, and implementing interactive graphical user interfaces in AR. It also provides an overview of the implementation of AR in the ATOAM architecture and benchmarks comparing AR to other CLP(FD) and CHR systems.
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Zhou ciclops floc06
1. AR (Action Rules) The Language, Implementation, and Applications A tutorial given at CICLOPS’06 Neng-Fa Zhou CUNY Brooklyn College and Graduate Center
2.
3.
4.
5.
6.
7.
8.
9.
10.
11. Example An echoing agent echo(X),{event(X,O)} => writeln(O). ?-echo(X),post_event(X,hello). hello ?-echo(X),repeat,post_event(X,hello),fail. hello hello hello …
23. Propagator for A1*X1+...+An*Xn+C = 0 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn), n_vars_gt(n,2), {generated,ins(X1),bound(X1),...,ins(Xn),bound(Xn)} => reduce domains of X1,..,Xn to achieve ic . 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn) => nary_to_binary(NewC,B1,B2,Y1,Y2), call_binary_propagator(NewC,B1,Y1,B2,Y2). When the constraint contains more than 2 variables, achieve interval consistency. When the constraint becomes binary archive arc consistency.
24.
25.
26.
27.
28.
29. Benchmarking CLP(FD) systems (As of Aug. 14, 2006) BP: B-Prolog 6.9 EP: Eclipse 5.8 #107 GP: Gnu-Prolog 1.2.16 SP: Sicstus-Prolog 3.12.5 CPU time, Windows XP Benchmarks: www.probp.com/bench.tar.gz
30.
31.
32.
33. An example CHR program reflexivity @ leq(X,X) <=> true. antisymmetry @ leq(X,Y), leq(Y,X) <=> X = Y. idempotence @ leq(X,Y) leq(X,Y) <=> true. transitivity @ leq(X,Y), leq(Y,Z) ==> leq(X,Z). simplification propagation simpagation
34.
35. Translating CHR into AR Example p(X):- gen_constr_num(Cno), Constr=constr(Cno,AliveP,HistoryP,X), get_channel(p_1_1,ChP), get_channel(q_1_1,ChQ), agent_p_1_1(ChP,AliveP,X), post_p_1(ChQ,Constr,AliveP,X). agent_p_1_1(ChP,AliveP,X),var(AliveP), {event(ChP,Q),ins(AliveP)} => Q=constr(_,AliveQ,HistoryQ,Y), (var(AliveQ)->AliveP=0,AliveQ=0,r(X,Y);true). agent_p_1_1(ChP,AliveP,X) => true. p(X),q(Y) <=> r(X,Y).
36. CHR to AR Example (Cont.) post_p_1(ChQ,Constr,AliveP,X),var(AliveP), {generated,ins(X),ins(AliveP)} => post_event(ChQ,Constr). post_p_1(ChQ,Constr,AliveP,X) => true. p(X),q(Y) <=> r(X,Y).
37. Benchmarking CHR compilers CPU time: milliseconds, Windows XP 453 1,765 6,843 zebra 640 1,125 6,532 primes 360 2,313 6,406 leq 3,250 Leuven (SWI) 109 938 fib AR (by hand) Leuven (B-Prolog) Program
38.
39.
40. An example go:- cgButton(B,“Hello World!”), handleButtonClick(B), cgShow(B). handleButtonClick(B), {actionPerformed(B)} => halt.
41.
42. Timers and time events go:- timer(T1,100), timer(T2,1000), ping(T1), pong(T2), repeat,fail. ping(T),{time(T)} => writeln(ping). pong(T),{time(T)} => writeln(pong).
43.
44.
45. The implementation of AR (The ATOAM architecture) P code area X1 X2 ... Xn registers s AR stack heap trail H T TOP