Completeness and Minimality of Rule-based Languages Detlef Plump Annegret Habel University of York Universit¨ at Oldenburg
Abstract objects and rules Assumption 1 O and R are sets of objects and rules such that each S ⊆ R induces a binary relation ⇒ S on O .
Examples: objects and rules Graph rewriting: Double-pushout approach ([HP 01], previous talk) String rewriting: • O = Σ ∗ for some finite alphabet Σ • R = { l → r | l, r ∈ Σ ∗ } • v ⇒ S w if v = xly and w = xry for some ( l → r ) ∈ S and x, y ∈ Σ ∗ Term rewriting: • O = T( F ), set of closed terms over a finite set F of function symbols • R = { l → r | l, r ∈ T( F, X ) , l �∈ X, Var( r ) ⊆ Var( l ) } • t ⇒ S u if u results from t by replacing any subterm σ ( l ) with σ ( r ), where ( l → r ) ∈ S and σ : T( F, X ) → T( F )
Abstract programs Syntax (1) For every finite set S of rules, S and S ↓ are programs. (2) If P and Q are programs, then P ; Q is a program. Semantics The semantics of a program P is a binary relation � P � on O : (1) � S � = ⇒ S for every finite set S of rules (2) � S ↓ � = {� x, y � | x ⇒ ∗ S y and y �∈ Dom( ⇒ S ) } (3) � P ; Q � = � P � ◦ � Q � (relation composition)
Example: term rewriting program Negate = Eval ↓ ; { true → false , false → true } where ¬ ( true ) → false true ∧ x → x true ∨ x → true Eval = ¬ ( false ) → true false ∧ x → false false ∨ x → x Note: • F = { true , false , ¬ , ∧ , ∨} • � Negate � : T( F ) → T( F ) satisfies if t ⇒ ∗ true Eval false � Negate � ( t ) = if t ⇒ ∗ false Eval true
Representation of objects as strings Assumption 2 Σ is a finite alphabet and α : Σ ∗ → O a surjective partial function. Graph rewriting: α = gra: Σ ∗ → A C [HP 01] String rewriting: α : Σ ∗ → Σ ∗ is the identity function on Σ ∗ Term rewriting: • let Σ ⊇ F and ⌈ t ⌉ be the result of removing all parentheses and commas in a term t ; then ⌈ ⌉ is an injective function [Cohn 81] • α : Σ ∗ → T( F ) is defined by if there exists t ∈ T( F ) with ⌈ t ⌉ = w , t α ( w ) = undefined otherwise
Example: representation of terms g ( f ( a ) , h ( b , c )) α gfahbc
Abstract computability Let O 1 , O 2 ⊆ O . A partial function f : O 1 → O 2 is computable if there is a partial computable string function f ′ : α − 1 ( O 1 ) → α − 1 ( O 2 ) such that for all w ∈ α − 1 ( O 1 ): (1) α ( w ) ∈ Dom( f ) implies f ( α ( w )) = α ( f ′ ( w )). (2) α ( w ) �∈ Dom( f ) implies w �∈ Dom( f ′ ). f O 1 O 2 α α f ′ α − 1 ( O 1 ) α − 1 ( O 2 )
Computational completeness Completeness Condition There is a total function ( ) • : Σ ∗ → O such that: C1 (String functions) For every partial computable function f : S 1 → S 2 with S 1 , S 2 ⊆ Σ ∗ , there is a program P f such that for all w ∈ S 1 and x ∈ O , w • � P f � x if and only if f ( w ) • = x . C2 (Encoding) There is a program Encode such that for all x, y ∈ O , x � Encode � y if and only if x = α ( w ) and y = w • for some w ∈ Σ ∗ . C3 (Decoding) There is a program Decode such that for all w ∈ Σ ∗ and y ∈ O , w • � Decode � y if and only if y = α ( w ).
Completeness Condition in diagrams P f O O Partial computable string functions can be ( ) • ( ) • C1: simulated by programs on string-like objects. f S 1 S 2 Encode O O ( ) • C2: α All objects are encoded as string-like objects. Σ ∗ Decode O O ( ) • C3: α Decoding is inverse to encoding. Σ ∗
Example: encoding and decoding terms Encode g ( f ( a ) , h ( b , c )) g 1 ( f 1 ( a 1 ( h 1 ( b 1 ( c 1 ( ✷ )))))) Decode ( ) • α gfahbc
Computational completeness Theorem (Computational completeness) If the Completeness Condition is satisfied, then for every partial computable function f : O 1 → O 2 there is a program that computes f . Corollary (Completeness of string, term and graph programs) The languages of string, term and graph rewriting programs are computationally complete.
Minimality: graph, string and term programs Theorem (Graph and string programs) For graph and string rewriting, omitting any of the three programming constructs results in an incomplete language. Theorem (Term programs) For term rewriting, omitting either iteration or sequential composition results in an incomplete language.
Future work • Can single-step application of rules be omitted – in term programs? – in string and graph programs computing functions not defined on the empty string/graph? • Alternative way to guarantee completeness: adding contexts prior to computations – string rewriting: enclose input string in special markers – term rewriting: add special top symbol – graph rewriting: ? • Applying the framework to other rule-based models of computation
Structure of completeness proof f O 1 O 2 � Encode � � Decode � � P f ′ � O O α α ( ) • ( ) • f ′ α − 1 ( O 1 ) α − 1 ( O 2 ) The program P = Encode ; P f ′ ; Decode computes f , i.e. � P � ∩ ( O 1 × O 2 ) = f .
Minimality: cyclic functions Cyclic functions A partial function f : O → O is cyclic if there are o ∈ O and n ≥ 2 such that f ( o ) � = o and f n ( o ) = o . Examples: Reversal of graph edges, string reversal and Boolean term negation are cyclic functions. Lemma No cyclic partial function is computable by a program of the form P ↓ . Proof: Let f : O → O be cyclic and consider o ∈ O and n ≥ 2 such that f ( o ) � = o and f n ( o ) = o . Suppose that there is a program P ↓ such that � P ↓ � = f . Then � P ↓ � ( f n − 1 ( o )) = f n ( o ) = o , hence f n − 1 ( o ) ⇒ ∗ P o and o �∈ Dom( ⇒ P ). But � P ↓ � ( o ) = f ( o ) and o � = f ( o ) imply o ⇒ + P f ( o ), a contradiction.
Minimality: neutral objects Neutral objects o ∈ O is neutral if for every finite set of rules R and every x ∈ O , o ⇒ + R x implies x ∈ Dom( ⇒ R ). Examples: The empty graph and the empty string are neutral objects in graph and string rewriting, respectively. Lemma Let f : O 1 → O 2 be a partial function such that there is a neutral element o ∈ Dom( f ) with f ( o ) � = o . Then for every program P 1 ; . . . ; P n that computes f , one of the components P i is a set of rules.
Recommend
More recommend