the language and its implementation Kazunori ... - FJCP 2005

computation and its manipulation c i o m ... Serve also as a practical programming language .... Translator to Java running on JDK 1.4 or higher ... I/O, arrays, window toolkit, socket, utilities, . .... Parallel, distributed, embedded implementation.
248KB taille 3 téléchargements 254 vues
1

LMNtal

― the language and its implementation Kazunori Ueda, Waseda Univ.

(joint work with Norio Kato, Koji Hara and Ken Mizuno)

November 2005 Copyright (C) 2002-2005 Kazunori Ueda

2

Diagrammatic representation of computation and its manipulation hub formed by membrane X

i

X0

Y

o

Y m

Y0

s

A

m g

L1 n

n

i L2

n

n n

cyclic structures

Y

receive

Z

unprotected

m

asynchronous π-calculus

A

L0 b

X

X

X

buffer header

S

m

m

operation right

m

protected by membrane Y

n-to-1 comm.

Y

send X

S1

channel formed by membrane

o

closed unary function

i

f m

o f

c

c

map function

m

3

Design goals of LMNtal „ „ „ „

A “Turing Machine” for universal computing environments (from wide-area to nanoscale) Serve also as a practical programming language  Implementation available! Unifying  e.g., processes = messages = data Simple and versatile  Computation is manipulation of graphs  Membranes express multisets and locality  Allows programming by self-organization

Models and languages with membranes + hierarchies „ „ „ „ „ „ „ „

Chemical Abstract Machine Mobile ambients P-systems Bigraphical reactive system LMNtal Seal calculus Kell calculus Brane Calculi (Abstract machines of Systems Biology)

4

5

Syntax of „

„

LMNtal processes Not in Flat LMNtal

P ::= 0 (null) | p(X1, . . . , Xm) (m ≥ 0) (atom) | P, P (molecule) | {P} (cell) | T :- T (rule) Link condition: Each link in P occurs at most twice and each link in a rule occurs exactly twice.  Free link of P = link occurring only once  P is closed = has no free links

6

Syntax of LMNtal process templates „

„

T ::= | | | | | | |

0 (m ≥ 0) p(X1 , . . . , Xm) T, T {T} T :- T @p $p[X1 , . . . , Xm|A] (m ≥ 0) p(*X1 , . . . ,*Xm) (m > 0)

(residual args) A ::= [ ] | *X

Not in Flat LMNtal

(null) (atom) (molecule) (cell) (rule) (rule context) (process context) (aggregate) (empty) (bundle)

7

Process contexts $p[X1 ,...,Xm|A] „

„

Express local contexts within cells  {p(X)} :„ matches a cell exactly consisting of p(X)  {p(X), $q[|*Y]} :„ matches a cell containing p(X), X free  {p(X), $q[X|*Y]} :„ matches a cell containing p(X), X local Arguments of a process context $p[X1 , ..., Xm|A]  X1 ,...,Xm : must occur as free links  A is [] : no other free links may occur  A is *X : other free links may occur

8

Term notation: Examples A

B

. 2

. 3

ans + * 2

5 a

C

. 5

D

. 7

E

[]

'.' (2,B,A), '.' (3,C,B), '.' (5,D,C), '.' (7,E,D), '[]' (E) or A= '.' (2, '.' (3, '.' (5, '.' (7, '[]' )))) A=[2 | [3 | [5 | [7 | []]]] A=[2,3,5,7]

ans(A), '+' (B,C,A), '*' (D,E,B), 2(D), a(E), 5(C) or ans('+' ('*' (2,a),5)) ans(2*a+5)

ans +

5

2 3

ans(A), {+A, 2,3,5} or ans({2,3,5})

9

Term notation: The rule c(A1,X1,X0), c(A2,X2,X1), c(A3,X3,X2), n(X3) ≡ c(A1,c(A2,c(A3,n)),X0) ≡ X0 = Y, c(A1,c(A2,c(A3,n)),Y) ≡ X0 = c(A1,c(A2,c(A3,n))) f(3) ≡ 3(f) ≡ f = 3 ≡ 3 = f ≡ f(X), 3(X)

f 3

10

Example: Natural numbers Z= add(0,Y) :- Z= Y. Z= add(s(X),Y) :- Z= s(add(X,Y)). add(0,Y,Z) :- Y=Z. add(s(X),Y,Z0) :- Z0=Z, add(X,Y,Z).  Syntax note: processes not in parentheses

can either be comma-separated or periodterminated

11

Implementation Available ! Translator to Java running on JDK 1.4 or higher  http://www.ueda.info.waseda.ac.jp/lmntal/ „ Features: (still under development)  Arithmetics (int, float)  Modules  Foreign-language interface to Java  Visualizer  Interactive mode (Read-Eval-Print Loop)  Optimizer  Redex/Rule selection strategies  Library APIs „

12

Arithmetics numbers are unary atoms  8 and 3.14 are not numbers, 8(X) and 3.14(X) are. „ a ground expression evaluates itself to a number „

 ans(2*a+5), (a(X) :- 3(X)) Î ans(11), (a(X) :- 3(X)) „

numbers can be compared using guards  a(8), (a(X) :- X>5 | b(X), c(X), d(X)), (b(X) :- X>7|)

Î c(8), d(8), (a(X) :- X>5 | b(X), c(X), d(X)), (b(X) :- X>7|)  X is not just a link here; it’s a typed process context, representing “a link X and an integer atom (> 5) connected to X”.

13

Modules and foreign-language interface { module(io).

}

io.input(Message, X) :- [:/*inline*/ String s = javax.swing.JOptionPane.showInputDialog(null, me.nth(0)); me.setName("done"); me.nthAtom(0).setName(s); :](Message, X). ... I/O, arrays, window toolkit, socket, utilities, . . .

14

Structural congruence ( ≡ ) (E1) 0, P (E2) P, Q (E3) P, (Q, R) (E4) P (E5) P ≡ P’ (E6) P ≡ P’ (E7) X=X (E8) X=Y (E9) X = Y, P

multisets ≡ P ≡ Q, P ≡ (P, Q), R ≡ P [Y/X ] if X is a local link of P Ö P, Q ≡ P ’, Q Ö {P } ≡ {P’ } structural connectors ≡ 0 ≡ Y=X ≡ P [Y/X ]

if P is an atom and X is a free link of P

(E10) { X = Y, P } ≡ { P }, X = Y

if X is a free link of P and Y is not a free link of P

15

Reduction semantics (R1) (R3) (R4)

P → P’ P, Q → P ’, Q

P → P’ (R2) { P } → { P’ }

Q ≡ P P → P’ P’ ≡ Q’ Q → Q’ { X=Y, P } → X=Y, { P } if X and Y are free links of (X=Y, P)

(R5)

X=Y, { P } → { X=Y, P } if X and Y are free links of P

(R6) Tθ, (T :- U ) → Uθ, (T :- U )

θ is to instantiate process & rule contexts. Links are matched using α-conversion.

Example: Factorization

process context; matches non-rule molecules

16

rule context

„

{ gen(12). gen(N) :- N>=2 | n(N), gen(N-1). gen(N) :- N= PR | X0=[OpL,exp(e(Op,E1,E2)),OpR|X], op(OpL1,PL), op(Op1,P), op(OpR1,PR) .

J Parsing I Unparsing

X0=[N|X] :- int(N) | X0=[exp(N)|X]. ans1([begin, 123, '+', 45, '*', 67, '+', 8, end]) Î ans1([begin, exp(e('+',e('+',123,e('*',45,67)),8)), end]) op('*',4). op('*',4). op('*',4). op('+',3). op('+',3). op('+',3). op(begin,0). op(end,0).

operator precedence table

22

Example: Fullerene (C60) /* icosahedron */ dome(L0,L1,L2,L3,L4,L5,L6,L7,L8,L9) :p(T0,T1,T2,T3,T4), p(L0,L1,H0,T0,H4), p(L2,L3,H1,T1,H0), p(L4,L5,H2,T2,H1), p(L6,L7,H3,T3,H2), p(L8,L9,H4,T4,H3). dome(E0,E1,E2,E3,E4,E5,E6,E7,E8,E9), dome(E0,E9,E8,E7,E6,E5,E4,E3,E2,E1). /* icosahedron -> fullerene */ p(L0,L1,L2,L3,L4) :X=c(L0,c(L1,c(L2,c(L3,c(L4,X))))).

23

Example: Constraint Handling Rules „

CHR ≅ LMNtal − hierarchy + propagation    

„ „

r1 r2 r3 r4

@ @ @ @

leq(X,X) true. leq(X,Y), leq(Y,X) X=Y. leq(X,Y), leq(Y,Z) ==> leq(X,Z). leq(X,Y), leq(X,Y) leq(X,Y).

SOS of CHR has been encoded in LMNtal Work in progress:  built-in support of propagation rules (reaction history management)  molecules with infinite multiplicity

24

Onoing and Future Work Language  Propagation rules and infinite multiplicity  Constructs for physical aspects „ Foundations  Type systems  Theory of computational resources  Reversibility „ Implementation  Optimizing complation of sequential core  Integration with static analysis  Parallel, distributed, embedded implementation  Interoperability Î “Theory meets practice, logic meets physics.” „