Lazy AC-Pattern Matching for Rewriting
Walid Belkhir and Alain Giorgetti
FEMTO-ST, University of Franche-Comté,
16 route de Gray, 25030 Besançon cedex, France
INRIA Nancy - Grand Est, CASSIS project, 54600 Villers-lès-Nancy, France
{walid.belkhir,alain.giorgetti}@femto-st.fr
We define a lazy pattern-matching mechanism modulo associativity and commutativity. The solutions of a pattern-matching problem are stored in a lazy list composed of a first substitution at the
head and a non-evaluated object that encodes the remaining computations. We integrate the lazy
AC-matching in a strategy language: rewriting rule and strategy application produce a lazy list of
terms.

1

Introduction

Term rewriting modulo associativity and commutativity of some function symbols, known as AC-rewriting, is a key operation in many programming languages, theorem provers and computer algebra systems.
Examples of AC-symbols are + and ∗ for addition and multiplication in arithmetical expressions, ∨
and ∧ for disjunction and conjunction in Boolean expressions, etc. AC-rewriting performance mainly
relies on that of its AC-matching algorithm. On the one hand, the problem of deciding whether an ACmatching problem has a solution is NP-complete [2]. On the other hand, the number of solutions to a
given AC-matching problem can be exponential in the size of its pattern. Thus many works propose
optimizations for AC-matching. One can divide optimized algorithms in two classes, depending on
what they are designed for. In the first class some structural properties are imposed on the terms, and
the pattern falls into one of several forms for which efficient algorithms can be designed. Examples
are the depth-bounded patterns in the many-to-one matching algorithm used by Elan [12] and greedy
matching techniques adopted in Maude [6]. In the second class there is no restriction on the structural
properties of the terms. Algorithms in this class are search-based, and use several techniques to collapse
the search space, such as constraint propagation on non linear variables [11], recursive decomposition via
bipartite graphs [8], ordering matching subproblems based on constraint propagation [9] and Diophantine
techniques [10].
Formal semantics proposed so far for AC-rewriting enumerate all the possible solutions of each
matching problem. More precisely, the application modulo AC of a rewrite rule l → r to a given term
t usually proceeds in two steps. Firstly, all the solutions (i.e. substitutions) σ1 , . . . , σn (n ≥ 0) of the
AC-matching problem whether the term t matches the pattern l are computed and stored in a structure,
say a set {σ1 , . . . , σn }. Secondly, this set is applied to r and the result is the set {σ1 (r), . . . , σn (r)}.
Other structures such as multisets or lists can alternatively be used for other applications of the calculus.
Directly implementing this eager semantics is clearly less efficient than a lazy mechanism that only
computes a first result of the application of a rewrite rule and allows the computation by need of the
remaining results. As far as we know no work defines the AC-matching in a lazy way and integrates it in
a rewriting semantics.
Another motivation of this work lies in our involvement in the formulation of the homogenization
of partial derivative equations within a symbolic computation tool [16, 17]. For this purpose, we have
S. Escobar (Ed.): Workshop on Reduction Strategies
in Rewriting and Programming (WRS2011)
EPTCS 82, 2012, pp. 37–51, doi:10.4204/EPTCS.82.3

c W. Belkhir & A.Giorgetti
This work is licensed under the
Creative Commons Attribution License.

38

Lazy AC-matching for rewriting

designed and developed a rule-based language called symbtrans [1] for “symbolic transformations”
built on the computer algebra system Maple. Maple pattern-matching procedures are not efficient and its
rewriting kernel is very elementary. Besides, Maple is a strict language, it does not provide any laziness
feature. We plan to extend symbtrans with AC-matching.
In this paper we first specify a lazy AC-matching algorithm which computes the solutions of an ACmatching problem by need. Then we integrate the lazy AC-matching in a strategy language. In other
words we define a lazy semantics for rule and strategy functional application. Our goal is to specify the
lazy AC-matching and strategy semantics towards an implementation in a strict language, such as Maple.
We reach this goal by representing lazy lists by means of explicit objects.
The paper is organized as follows. Section 2 introduces some terminology and notations. Section 3
shows a connection between AC-matching and surjective functions, used in the remainder of the paper. Section 4 formally defines a lazy semantics of AC-matching (with rewrite rules). It states its main
properties and shows how it differs from an eager semantics. Section 5 integrates the lazy AC-matching
in the operational semantics of a rule application on a term, first at top position, and then at other positions, through classical traversal strategies. Section 6 presents a prototypal implementation of lazy
AC-matching and some experimental results derived from it. Section 7 concludes.

2

Notation and preliminaries

Let [n] denote the finite set of positive integers {1, . . . , n} and let |S| denote the cardinality of a finite set
S. Thus, in particular, |[n]| = n.
Familiarity with the usual first-order notions of signature, (ground) term, arity, position and substitution is assumed. Let X be a countable set of variables, F a countable set of function symbols, and
FAC ⊆ F the set of associative-commutative function symbols. Let T denote the set of terms built out
of the symbols in F and the variables in X . Let S denote the set of substitutions {x1 7→ t1 , . . . , xn 7→ tn }
with variables x1 , . . . , xn in X and terms t1 , . . . ,tn in T. If t is a term and σ is a substitution then σ (t) denotes the term that results from the application of σ to t. Given a position p, the subterm of t at position
p is denoted by t|p . We shall write tε for the symbol at the root of term t, i.e. t = tε (t1 , . . . ,tn ).
A term t in T is flat if, for any position p in t, t|p = +(t1 , . . . ,tn ) for some symbol + in FAC implies
that the root symbol (ti )ε of each direct subterm ti (1 ≤ i ≤ n) is not +. We denote by ]AC (t) the number
of AC-symbols in the term t.

T-Matching. For an equational theory T and any two terms t and t 0 in T we say that t matches t 0
modulo T and write tT t 0 iff there exists a substitution σ in S s.t. T |= (σ (t) = t 0 ). In this paper the
theory T is fixed. It is denoted AC and axiomatizes the associativity and commutativity of symbols in
FAC , i.e. it is the union of the sets of axioms {t1 + t2 = t2 + t1 , (t1 + t2 ) + t3 = t1 + (t2 + t3 )} when +
ranges over FAC .

Rule-based semantics The following sections define the semantics of AC-matching, rule application and strategy application by rewriting systems composed of labeled rewriting rules of the form
rule label:· ; ·, where the rewrite relation ; should not be confused with the relation → of the
rewriting language. This semantics is said to be “rule-based”.

W. Belkhir & A.Giorgetti

3

39

AC-matching and surjections

Let + ∈ FAC be some associative and commutative function symbol. This section first relates a restriction of the pattern-matching problem +(t1 , . . . ,tk )AC +(u1 , . . . , un ), where 1 ≤ k ≤ n, with the set Sn,k
of surjective functions (surjections, for short) from [n] to [k]. Then a notation is provided to replace
surjections with their rank to simplify the subsequent exposition.
Definition 3.1 (Application of a surjection on a term) Let n ≥ k ≥ 1 be two positive integers, u =
+(u1 , . . . , un ) be a term and s ∈ Sn,k be a surjection from [n] to [k]. The application of s on u is defined by s(u) = +(α1 , . . . , αk ) where αi = u j if s−1 ({i}) = { j} and αi = + (u j1 , . . . , u jm ) if s−1 ({i}) =
{ j1 , . . . , jm } and j1 < . . . < jm with m ≥ 2.
Example 3.1 The application of the surjection s = {1 7→ 2, 2 7→ 2, 3 7→ 3, 4 7→ 1} on the term +(u1 , u2 ,
u3 , u4 ) is s(+(u1 , u2 , u3 , u4 )) = +(u4 , +(u1 , u2 ), u3 ).
The following proposition, whose proof is omitted, relates a subclass of AC-matching problems with
a set of surjections.
Proposition 3.1 Let t and u be two flat terms with the same AC-symbol at the root and containing no
other AC-symbol than the one at the root. Let k (resp. n) be the arity of the root of t (resp. u). Then the
V
matching problem tAC u and the conjunction of matching problems s∈Sn,k t0/ s(u) admit the same set
of solutions.
For n ≥ k ≥ 1, an integer rk(s) in {1, . . . , |Sn,k |} can be associated one-to-one to each surjection s
in Sn,k . It is called the rank of s. It will be used in the subsequent sections to iterate over the set Sn,k .
For each term u of arity n ≥ 1, each 1 ≤ k ≤ n, and each integer i in {1, . . . , |Sn,k |}, let unrk(i) denote
the surjection with rank i. The application of the integer i to the term u, denoted by i(u), is defined by
i(u) = unrk(i)(u), where application of a surjection to a term is defined by Def. 3.1.

4

AC-matching

This section defines an eager and a lazy semantics for pattern-matching modulo associativity and commutativity. By “eager” we mean a rewriting system specifying the computation of all the solutions to
a given matching problem, without any mechanism to delay the production of other solutions when a
first one is produced. The AC-matching execution steps are made explicit by introduction of a syntactic
representation of matching problems by matching constraints. They are a generalization to AC-matching
of the matching constraints defined e.g. in [4] for syntactic matching (i.e. for the empty theory). Both
semantics of AC-matching are given in terms of a conditional rewrite system on these constraints. In
what follows all the terms are assumed to be flat.

4.1

Eager AC-matching

Figure 1 proposes a rule-based eager semantics for AC-matching. This system (named Eager) reduces
eager matching constraints inductively defined by the grammar E ::= F | I | TAC T | E ∧ E | E ∨ E.
This definition and the notations for matching constraints adapt and extend the ones from the ρ-calculus
with explicit matching [4]. The constraint F denotes an absence of solution (failure). The constraint
I denotes the identity substitution resulting from an initial trivial matching problem. The expression

40

Lazy AC-matching for rewriting

pAC t denotes the elementary matching problem whether the term t matches the pattern p modulo AC.
The symbol ∧ is the constructor of conjunctions of constraints. The symbol ∨ is introduced to enumerate
various solutions as lists of constraints. Its priority is lower than that of ∧. Both are assumed associative.
Then the notation C1 ∧ . . . ∧Cn is used without ambiguity, and similarly for ∨, for n ≥ 1. The constraint
I is a neutral element for ∧. The constraint F is a neutral element for ∨ and an absorbing element for ∧.

E match AC:

+(t1 , . . . ,tk ) AC +(u1 , . . . , un ) ;
| {z }
|
{z
}
t

W j=|Sn,k | Vi=k
j=1

i=1 ti AC αi

u

if + ∈ FAC , k ≤ n and j(u) = +(α1 , . . . , αk )
E match:

tε (t1 , . . . ,tn )AC tε (u1 , . . . , un ) ;

Vi=n

i=1 ti AC ui

E match AC fail: +(t1 , . . . ,tk )AC +(u1 , . . . , un ) ; F

if tε ∈ F \ FAC
if + ∈ FAC and k > n

E match fail:

tε (t1 , . . . ,tn )AC uε (u1 , . . . , um ) ; F

if tε 6= uε

E fail gen:

xAC t ∧ E ∧ xAC t 0 ; F

if x ∈ X and t 6= t 0

E var clash:

tε (t1 , . . . ,tn )AC x ; F

if x ∈ X

E DNF 1:
E DNF 2:

F ∧ (G ∨ H) ; (F ∧ G) ∨ (F ∧ H)
(G ∨ H) ∧ F ; (G ∧ F) ∨ (H ∧ F)
Figure 1: Eager system of AC-matching rules

In Figure 1, the notation i=n
i=1 ti AC ui stands for I if n = 0 and for t1 AC u1 ∧ . . . ∧tn AC un otherwise.
The rule E match AC corresponds to Proposition 3.1 when t1 , . . . , tk , u1 , . . . , un contain no AC symbol,
and generalizes it otherwise. The positive integer j iterates over surjection ranks. The rules E match,
E match fail, E fail gen, and E var clash are the same as in syntactic pattern-matching. With AC
symbols, they are completed with the rule E match AC fail. The rules E DNF 1 and E DNF 2 correspond to the normalization of constraints into a disjunctive normal form, DNF for short. A constraint is
in DNF if it is of the form ∨i ∧ j Fi, j , where Fi, j is a constraint not containing ∨ and ∧.
It is standard to show that the system Eager is terminating. The rules E DNF 1 and E DNF 2 make
it not confluent, but the following post-processing reduces to a unique normal form all the irreducible
constraints it produces from a given pattern-matching problem. The post-processing consists of (i) replacing the trivial constraints of the form xAC x by I, (ii) replacing each non-trivial constraint xAC t by
the elementary substitution x 7→ t, (iii) eliminating duplicated elementary substitutions by replacing each
Si=n
expression of the form ∧i=n
i=1 Ei (with n ≥ 1) by the set i=1 {Ei } that represents a non-trivial substitution,
then (iv) replacing I by { } and finally (v) replacing each disjunction of substitutions ∨ j=n
j=1 S j with n ≥ 1
V

by the set j=n
j=1 {S j }, that represents a set of substitutions. A constraint in normal form can be either F,
if there is no solution to the initial matching problem, or a non-empty set {σ1 , . . . , σn } of substitutions
which corresponds to the set of all solutions of the matching problem. In particular σi may be { }, for
some i ∈ [n].
The theory for the associative symbols ∧ and ∨ deliberately excludes commutativity, because they
appear in the pattern of some rules of the Eager system. We now motivate this design choice. Since
S

W. Belkhir & A.Giorgetti

41

the Eager system is terminating and confluent – in the sense explained above – we can consider it as
an algorithm and implement it without modification, in a programming language supporting patternmatching modulo the theory of constraint constructors. Thus it would be ill-founded to require that the
language supports AC-matching, in order to extend it precisely with an AC-matching algorithm! In this
aspect our approach differs from the one of [5], whose more compact calculus handles “result sets”, i.e.
the underlying theory includes associativity, commutativity and idempotency, but matching with patterns
containing set constructors is implemented by explorations of set data structures.

4.2

Lazy AC-matching

We now define a lazy semantics for pattern-matching modulo associativity and commutativity, as a
rewriting system named Lazy. It reduces constraints defined as follows.
Definition 4.1 The set of delayed matching constraints, hereafter called constraints for short, is inductively defined by the grammar: C ::= F | I | TAC T | C∧C | C ∨ C | Next(C) | hT, T, N? i.
The first five constructions have the same meaning as in eager matching constraints. As in the eager case,
the symbols ∧ and ∨ are associative, the constraint F is an absorbing element for ∧, and the constraint I is
a neutral element for ∧. However, the constraint F is no longer a neutral element for ∨. The construction
Next(C) serves to activate the delayed computations present in the constraint C. When the terms t and u
have the same AC symbol at the root, the constraint ht, u, si denotes the delayed matching computations
of the problem tAC u starting with the surjection with rank s, and hence, the matching computations for
all the surjections with a rank s0 s.t. s0 < s have already been performed. The conditions that t and u have
the same AC symbol at the root and that the arities of t and u correspond to the domain and codomain of
the surjection with rank s are not made explicit in the grammar, but it would be easy to check that they
always hold by inspecting the rules of the forthcoming system Lazy. Delayed matching constraints of
the form ht, u, si and satisfying these conditions are more simply called triplets.
Figure 2 defines the first part of the lazy semantics, a rewriting system named R1 . The rules
match AC fail, match, match fail, var clash and fail gen are standard and already appeared
in the eager matching system. The rule match AC activates the delayed matching computations starting
from the first surjection. It is immediately followed by the rule match surj next from the rewriting
system R2 defined in Figure 3.
match AC:

+(t1 , . . . ,tk ) AC +(u1 , . . . , un ) ; Next(ht, u, 1i)
| {z }
|
{z
}

if + ∈ FAC and k ≤ n

match:

tε (t1 , . . . ,tn )AC tε (u1 , . . . , un ) ;

if tε ∈ F \ FAC

t

u

Vi=n

i=1 ti AC ui

match AC fail: +(t1 , . . . ,tk )AC +(u1 , . . . , un ) ; F

if + ∈ FAC and k > n

match fail:

tε (t1 , . . . ,tn )AC uε (u1 , . . . , um ) ; F

if tε 6= uε

fail gen:

xAC t ∧C ∧ xAC t 0 ; F

if x ∈ X and t 6= t 0

var clash:

tε (t1 , . . . ,tn )AC x ; F
Figure 2: R1 system: AC-matching rules

if x ∈ X

42

Lazy AC-matching for rewriting

fail next:
next id:

F ∨C ; Next(C)
Next(I) ; I

next and:
next or:

Next(C1 ∧C2 ) ; Next(C1 ) ∧ Next(C2 )
Next(C1 ∨C2 ) ; Next(C1 ) ∨C2 , if C1 6= F

next fail:
next basic:

Next(F) ; F
Next(xAC u) ; xAC u

match surj next: Next(ht, u, si) ; ( i=k
i=1 ti AC αi ) ∨ ht, u, s + 1i
if t = tε (t1 , . . . ,tk ), u = tε (u1 , . . . , un ), s < |Sn,k | and s(u) = tε (α1 , . . . , αk )
V

match surj last: Next(ht, u, |Sn,k |i) ; i=k
i=1 ti AC αi
if t = tε (t1 , . . . ,tk ), u = tε (u1 , . . . , un ) and |Sn,k |(u) = tε (α1 , . . . , αk )
Figure 3: R2 system: Next rules
V

In R2 the rule fail next states that the presence of a failure activates the delayed computations in
the constraint C. The other rules propagate the activation of the delayed computations on the inductive
structure of constraints. The rule next and propagates the Next constructor to sub-constraints. The rule
next or propagates the Next constructor to the head of a list of constraints, provided this head is not F.
When the constraint is ht, u, si, two cases have to be considered. If the surjection rank s < |Sn,k | is not
the maximal one, then the rule match surj next reduces the constraint Next(ht, u, si) to a set of matching constraints according to the surjection with rank s, followed by delayed computations that will be activated from the next surjection, with rank s + 1. In the final case when s = |Sn,k | (rule match surj last),
there is no delayed computations.
DNF 1: F ∧ (G ∨ H) ; (F ∧ G) ∨ (F ∧ H)
DNF 2: (G ∨ H) ∧ F ; (G ∧ F) ∨ (H ∧ F)
Figure 4: R3 system : DNF rules
Rules for the reduction of constraints in DNF are the same as in the eager system, but are defined in
the separate rewrite system R3 given in Figure 4.
Let us denote by Lazy the rewriting system R1 ∪ R2 ∪ R3 composed of the rules of Figures 2, 3 and
4, equipped with the evaluation strategy sat that consists of the iteration of the following process: (i)
Applying the rules of R1 ∪ R2 until no rule is applicable, then (ii) applying the rules of R3 until no rule
is applicable.

4.3

Termination of lazy AC-matching

We prove the termination of the lazy AC-matching system Lazy modularly, by considering some of its
sub-systems separately, in the following lemmas.
Lemma 4.1 The rewriting system R2 is terminating.
Proof. On the one hand, no rule in R2 produces the F constraint. Thus, after replacing with Next(C) the
occurrences of F ∨ C in the input constraint, the rule fail next is no longer used. On the other hand,
no rule in R2 can reduce the right side of the rules match surj next and match surj last. Thus it is
sufficient to prove the termination of R4 = {next fail, next id, next basic, next and, next or}.

W. Belkhir & A.Giorgetti

43

This is standard, using a recursive path ordering [7]. Intuitively, the termination of R4 is ensured by the
fact that all the rules in R4 push the Next constructor down until reaching the leaves.
Before proving the termination of R1 ∪ R2 , we need to introduce a variant of terms and triplets
to prove a technical lemma about their occurrences in derivations. The marked term t M associated to
the term t is obtained from t by replacing each AC symbol + at some position p in t with + p . The
marked triplet associated to the triplet ht, u, si is defined to be ht M , u, si. The marked constraint associated to the constraint tAC u is t M AC u. The marked variant R1M (resp. R2M , LazyM ) of the R1 (resp.
R2 , Lazy) system is obtained from the latter by replacing triplets with marked triplets, constraints with
marked constraints and +(t1 , . . . ,tk ) by + p (t1 , . . . ,tk ) for any p, in the pattern of the rules match AC
and match AC fail. It is clear, and thus admitted, that the derivations of LazyM are the variants of the
derivations of Lazy, in a natural sense.
Lemma 4.2 Let t M be a marked term with an AC symbol at the root and u be a term with the same AC
symbol at the root. Consider a derivation t M AC u ; C1 ; C2 ; . . . with rules in R1M ∪ R2M . Then,
the number of marked triplets in the sequence C1 ,C2 , . . . is strongly bounded, in the following sense: (i)
There is an upper bound for the number of marked triplets in each Ci and (ii) for each subterm t 0 of t with
an AC symbol at the root, if a marked triplet built up on the marked subterm t 0 (i.e. of the form ht 0 , u0 , si
for some u0 and s) is deleted from some Ci , i ≥ 1, then it never appears again in C j , for all j > i.
Proof. (i) The variant of the rule match AC replaces an elementary matching problem (between two
terms with an AC symbol at the root) with a marked triplet. It is the only rule of R1M ∪R2M that produces a
marked triplet whose first (marked) term is new. Then the variant of the rule match surj next replaces
a marked triplet whose first (marked) term is the subterm t 0 = + p (. . .) of t at some position p with a
marked triplet on the same terms, whose surjection rank is incremented. Thus the number of marked
triplets in a constraint is bounded above by the number of positions of AC symbols in t.
(ii) The only rule of R1M ∪ R2M that deletes a marked triplet whose first (marked) term is t 0 is the
variant of match surj last. This marked triplet never appears again because the variant of the rule
match surj next just increments the surjection rank of remaining triplets, whose first marked term t 00
is another subterm of t, located at another position in t (t 00 at least differs from t 0 by the name of its
root symbol), and the other rules of R1M ∪ R2M neither create new marked triplets nor duplicate existing
ones.
Lemma 4.3 The rewriting system R1 ∪ R2 is terminating.
Proof. Notice that R1 \ {match AC} is clearly terminating since it is a subsytem of the eager one, which
is known to be terminating. We deduce that R1 is terminating since no rule in R1 reduces the right
side of the rule match AC. Since R1 and R2 are terminating, it remains to show that there is no infinite
reduction that goes back and forth between R1 and R2 . Toward a contradiction, assume that there is an
+
+
infinite reduction C1 ;+
R1 C2 ;R2 C3 ;R1 . . . that goes back and forth between R1 and R2 , where C1 is a
pattern-matching problem. In R2 the rule match surj next is the only rule producing new redexes for
the system R1 , i.e. pattern-matching problems. Then the rule match surj next should appear infinitely
often in this infinite reduction. Equivalently, we consider the marked variant of this derivation, with the
same notations. Since the number of marked triplets in the sequence C1 ,C2 , . . . is strongly bounded (by
Lemma 4.2) there is a marked triplet (t, u, ski ) and an infinite sub-sequence Ck1 ,Ck2 , . . . of C1 ,C2 , . . . such
that ht, u, ski i ∈ Cki and ski+1 = ski + 1 for each i. This is a contradiction since the rank of surjections is
upper bounded.

44

Lazy AC-matching for rewriting

Theorem 4.4 The Lazy system is terminating.
Proof. On the one hand, the termination of R1 ∪ R2 is proved in Lemma 4.3. On the other hand, it is
standard to show that the system R3 is terminating. It corresponds to the normalization w.r.t. to the
disjunctive normal form. Therefore, it is sufficient to show that there is no infinite reduction that goes
back and forth between the saturation of R1 ∪ R2 and the saturation of R3 . Let R = tAC u ;ω
1 ∪R2
WRi=k
ω
C1 ;ω
C
;
.
.
.
be
a
reduction
in
Lazy.
Notice
that
each
C
,
where
p
is
even,
is
of
the
form
p
i=1 Fi
R3 2
R1 ∪R2

where Fi = j=m
j=1 D j and each D j is either a triplet or the matching problem of a term with a variable. If
there is no new redex in Cp then the reduction R stops. Otherwise, by observing the right side of the rules
of R1 ∪ R2 , we claim that if there is a new redex in Cp – which is created by the system R3 – then this
redex is necessarily of the form xAC t ∧ . . . ∧ xAC t 0 with t 6= t 0 , producing the F constraint. Let q ∈ [k]
W
be the smallest integer such that such a redex appears in Fq . If q = k then Cp is reduced to i=k−1
i=1 Fi ∨ F
and the reduction R terminates. Otherwise, Cp ;fail gen F1 ∨ . . . ∨ F ∨ Fq+1 ∨ . . . ∨ F ∨ . . . ∨ Fk ;fail next
F1 ∨ . . . ∨ Next(Fq+1 ) ∨ . . . ∨ F ∨ . . . ∨ Fk .
The rules of R2 push the Next constructor down, and all the constraints of the form Next(ht, u, si) in
V
Fp+1 are reduced to ( i=k
i=1 ti AC αi ) ∨ ht, u, s + 1i by the rule match surj next, if s(t) = tε (α1 , . . . , αk ).
To prove that the reduction R terminates it is sufficient to prove that the system R = R1 \ {match AC} ∪
{always next, match AC 2} ∪ R3 is terminating, with the following rule definitions:
V

match AC 2:

tAC u ; ht, u, 1i

and

always next:

ht, u, si ; (

i=k
^

ti AC αi ) ∨ ht, u, s + 1i.

i=1

However the termination of R is ensured by the termination of the eager system. That is, we have just
replaced the rule E match AC of Eager with the rules match AC 2 and always next in R.

4.4

Confluence of lazy AC-matching

The system Lazy is not confluent, due to the non-confluence of R3 . In this section we argue that the
system R1 ∪ R2 is confluent, and we consider an evaluation strategy for R3 to get a confluent AC-lazy
matching system, that we call Lazy↓ .
Proposition 4.5 The system R1 ∪ R2 is locally confluent.
Proof. It is straightforward to check that there is no critical overlap between any two redexes, i.e. the contraction of one redex does not destroy the others. It is worth mentioning that without the condition C1 6= F
of the rule next or we could have non-convergent critical pairs, e.g. Next(F ∨C) ; Next(Next(C)) by
the rule fail next and Next(F ∨C) ; Next(F) ∨C ; F ∨C ; Next(C).
Corollary 4.6 The system R1 ∪ R2 is confluent.
The reason of the non-confluence of R3 is the non-commutativity of the operators ∧ and ∨. It is
classical to add a strategy to R3 so that the resulting system becomes confluent.
Definition 4.2 Let R3↓ be the system R3 with the following strategy: (i) When reducing a constraint of
V W
Vi=k W
Wl=m
the form i=k
i=1 j Ci, j with k ≥ 3, first reduce i=2 j Ci, j , and (ii) reduce ( l=1 Al ) ∧ B to (A1 ∧ B) ∨
W
(( l=m
l=2 Al ) ∧ B).

W. Belkhir & A.Giorgetti

45

Proposition 4.7 (Admitted) R3↓ is confluent.
Now we are ready to define the lazy AC-matching.
Definition 4.3 The lazy AC-matching, denoted by Lazy↓ , is the rewriting system R1 ∪ R2 ∪ R3 composed of the rules of Figures 2, 3 and 4, equipped with the evaluation strategy sat↓ that consists of the
iteration of the following process: (i) Applying the rules of R1 ∪ R2 until no rule is applicable, then (ii)
applying R3↓ until no rule is applicable.
Theorem 4.8 Lazy↓ is terminating and confluent.
Proof. The termination of Lazy↓ is a consequence of the one of Lazy. The confluence of Lazy↓ follows
from the confluence of R1 ∪ R2 and R3↓ .
In what follows the normal form of a constraint C w.r.t. a system R will be denoted by NFR (C), or
just NF(C) if R is Lazy↓ .

4.5

Normal forms and lazy lists

In this section we prove Theorem 4.15 that characterizes the normal forms of the lazy AC-matching
Lazy↓ . They correspond basically to lazy lists. Roughly speaking, a lazy list is composed of a substitution
at the head and a non-evaluated object that represents the remaining substitutions. This characterization
of the normal forms is of major importance since it guarantees that the element at the head is always a
substitution. The formal definition of lazy lists follows.
Definition 4.4 A ∧-substitution is a conjunction of delayed matching constraints of the form xAC u
where x is a variable. A ∧-substitution is irreducible if it cannot be reduced by the rule fail gen . A
constraint is called a lazy list if it is F, I, an irreducible ∧-substitution or a constraint of the form σ ∨C
where σ is an irreducible ∧-substitution and NF(Next(C)) is also a lazy list.
In order to characterize the normal forms of Lazy↓ we first characterize in Lemma 4.9 the normal
forms of the system R1 ∪ R2 . Then we characterize in Lemma 4.12 the normal forms of R3↓ when it
has the normal forms of R1 ∪ R2 as input. Summing up these results, we show in Proposition 4.14 the
invariance of the syntax of constraints after the composition of the application of R1 ∪ R2 and of R3↓ .
Finally, Theorem 4.15 becomes an immediate consequence of Proposition 4.14.
Let us begin by characterizing the normal forms of R1 ∪ R2 and introduce for this purpose the
grammar G ::= G ∧ G | G ∨ hT, T, N∗ i | X AC T | I.
Lemma 4.9 The normal form of an AC-matching problem by the system R1 ∪ R2 is either F or follows
the grammar G.
Proof. Let tAC u be an AC-matching problem. When tAC u ;R1 ∪R2 F, the normal form of the ACmatching problem is F, since no rule rewrites F. The other cases when t or u is a variable are also trivial:
The matching problem is reduced to I or is irreducible.
It remains to consider the case when t = tε (t1 , . . . ,tk ) and u = tε (u1 , . . . , un ) for some k, n ≥ 0. The
proof is by induction on the number of symbols in t. If t is a constant, i.e. k = 0, then n = 0 and u = t.
The AC-matching problem tAC u is reduced to I, thus follows the grammar G. Otherwise, k ≥ 1. Only
one rule can be applied, match AC or match, depending on the nature of the symbol tε at the root of t.

46

Lazy AC-matching for rewriting

Case 1. If tε is an AC symbol, then k ≤ n and tAC u ;match AC Next(ht, u, 1i). We prove more generally
that the normal form of Next(ht, u, si) by R1 ∪R2 is F or follows the grammar G. Let s(u) = tε (α1 , . . . , αk )
V
and C = i=k
i=1 ti AC αi .
If |Sn,k | − s = 0, then Next(ht, u, si) ;match surj last C ;? NF(C). Otherwise, when |Sn,k | − s >
0, Next(ht, u, si) ;match surj next C ∨ ht, u, s + 1i ;? NF(C) ∨ ht, u, s + 1i. In both cases, since each ti
contains less symbols than t, the induction hypothesis holds for each ti , and hence the normal form
V
NF(C) of C = i=k
i=1 ti AC αi is F or a constraint which follows the grammar G, since F is an absorbing
element for ∧.
For this case the remainder of the proof is by induction on |Sn,k |−s. The basic case when |Sn,k |−s = 0
has already been treated. When |Sn,k | − s > 0, there are two cases. If NF(C) follows the grammar
G then it obviously also holds for NF(C) ∨ ht, u, s + 1i. Otherwise, NF(C) is F and Next(ht, u, si) ;?
F ∨ ht, u, s + 1i ;fail next Next(ht, u, s + 1i). Since |Sn,k | − (s + 1) < |Sn,k | − s, the induction hypothesis
gives that NF(Next(ht, u, s + 1i)) is F or follows the grammar G, hence also for Next(ht, u, si).
V
? Vi=k NF(t  u ).
Case 2. If tε is not an AC symbol, then k = n and tAC u ;match i=k
i AC i
i=1 ti AC ui ;
i=1
By induction hypothesis, for each i, NF(ti AC ui ) is F or follows the grammar G. If NF(ti AC ui ) = F for
some i ∈ [k], then tAC u ;∗ F, since F is an absorbing element for ∧. Otherwise, NF(ti AC ui ) follows
G for each i, and then it obviously also holds for their conjunction, and for NF(tAC u).
Lemma 4.10 Let C be an irreducible constraint w.r.t. R1 ∪ R2 that follows the grammar G. Then, the
normal form of Next(C) by R1 ∪ R2 is C.
Proof. The proof is by induction on the grammar constructions of G. If C is I or a matching problem of
the form xAC u where x is a variable, then the rules next id and next basic ensure that Next(C) ; C.
If C = C1 ∧C2 then Next(C1 ∧C2 ) ; Next(C1 ) ∧ Next(C2 ) and the induction hypothesis NF(Next(C1 )) =
C1 and NF(Next(C2 )) = C2 apply to show that NF(Next(C1 ∧ C2 )) = NF(C1 ∧ C2 ) = C1 ∧ C2 . If C =
C1 ∨ ht, u, si, then Next(C1 ∨ ht, u, si) ; Next(C1 ) ∨ ht, u, si ; C1 ∨ ht, u, si.
We can generalize the previous lemma by the following one.
V

Lemma 4.11 Let F be a constraint of the form i Fi , where each Fi is either a triplet or follows the
grammar G, such that F is irreducible w.r.t. R1 ∪ R2 . Then, the normal form of Next(F) by R1 ∪ R2 is
F or follows the grammar G.
Proof. By iterating application of the rule next and we get Next( i Fi ) ;∗ i Next(Fi ). Fi is irreducible
w.r.t. R1 ∪ R2 because F is irreducible. If Fi follows the grammar G, then NF(Next(Fi )) = Fi by Lemma
4.10. If Fi is a triplet then by Lemma 4.9 the normal form of Next(Fi ) is F or follows G. Therefore, the
V
normal form of i Next(Fi ) is F or follows the grammar G.
V

V

We define the grammar K ::= K ∧ K | XAC T | hT, T, N? i for conjunctions of atomic constraints, the
grammar F ::= F ∨ F | K for constraints in DNF, the grammar S ::= S ∧ S | XAC T for ∧-substitutions,
and the grammar H ::= S ∨ F | S | I ∨ F | I to formulate the following two lemmas. The first one is about
normal forms by R3↓ of inputs which are normal forms of R1 ∪ R2 .
Lemma 4.12 Let C be an irreducible constraint w.r.t. R1 ∪ R2 that follows the grammar G. Then, the
normal form of C by the system R3↓ follows the grammar H.

W. Belkhir & A.Giorgetti

47

Proof. On the one hand, since C follows the grammar G, it is built up on ∧, ∨, I, matching constraints of
the form xAC u and triplets. On the other hand, the normal form of C by R3↓ is in DNF. Therefore it is
sufficient to show that NFR ↓ (C) is either I or of the form σ ∨ F, where σ is either a ∧-substitution or I,
3
and F follows F. The proof is by induction on the grammar constructions of G. If C is I or xAC u then
the claim holds. Otherwise, we distinguish two cases:
Case 1. If C = C1 ∧C2 , then we only discuss the non-trivial case when NF(C1 ) or NF(C2 ) is of the form
σ ∨ F. Assume that C1 = σ1 ∨ F1 , the other case can be handled similarly. In this case C2 can be I, σ2 or
σ2 ∨ F2 . If C2 = I then (σ1 ∨ F1 ) ∧ I = σ ∨ F1 . If C2 = σ2 , then (σ1 ∨ F1 ) ∧ σ2 ; (σ1 ∧ σ2 ) ∨ (F1 ∧ σ2 ).
Finally, if C2 = σ2 ∨ F2 , then (σ1 ∨ F1 ) ∧ (σ2 ∨ F2 ) ;∗ (σ1 ∧ σ2 ) ∨ (σ1 ∧ F2 ) ∨ (F1 ∧ σ2 ) ∨ (F1 ∧ F2 ) and
the claim holds.
Case 2. If C = C1 ∨ ht, u, si, then we apply the induction hypothesis on NF(C1 ), and the desired result
follows.
The following lemma describes the syntax of the result of Next(F) by the application of R1 ∪ R2
followed by the application of R3↓ , when F is an irreducible constraint in DNF.
j=q
Lemma 4.13 Let φ (p) = i=p
i=1 j=1 Ci, j be an irreducible constraint w.r.t. R1 ∪ R2 that follows the
grammar F. Then NFR ↓ (NFR1 ∪R2 (Next(φ (p)))) is either F or follows the grammar H.

W

V

3

Proof. The proof is by induction on p. If p = 1 then by Lemma 4.11 φ 0 = NFR1 ∪R2 (Next(φ (1))) is F or
W V j=q
follows G. Therefore NFR ↓ (φ 0 ) is F, or follows H by Lemma 4.12. If p > 1 then Next( i=p
i=1 j=1 Ci, j ) ;
3

j=q
Next( j=q
j=1 C1, j ) ∨ φ (p − 1). By Lemma 4.11 again NFR1 ∪R2 (Next( j=1 C1, j )) is F or follows G.
In the first case, we apply F ∨ φ (p − 1) ; Next(φ (p − 1)), and use the induction hypothesis that
NFR ↓ (NFR1 ∪R2 (Next(φ (p − 1)))) follows H. In the second case, it comes from Lemma 4.12 that ψ =

V

3

V

V j=q

NFR ↓ (NFR1 ∪R2 (Next(
3
F.

j=1 C1, j )))

follows H. Hence ψ ∨ (φ (p − 1)) follows H, since φ (p − 1) follows

Now we are ready to prove the following invariance proposition. It generalizes the previous lemma
by considering an arbitrary constraint following the grammar H.
Proposition 4.14 (Invariance proposition) Let C be a constraint following the grammar H. Then
NFR ↓ (NFR1 ∪R2 (C)) is F or follows the grammar H.
3

Proof. The case when C is a ∧-substitution or I is trivial. Otherwise, let C = σ ∨ F, where σ is I or a
∧-substitution and F follows F. Notice that the only potential redexes in C w.r.t. the system R1 ∪ R2 are
of the form xAC u1 ∧ . . . ∧ xAC u2 such that u1 6= u2 . In this case the rule fail gen is applied. Let us
call such redexes failure redexes. We distinguish two cases.
Case 1. If there is no failure redex in F (i.e. F is irreducible w.r.t. R1 ∪ R2 ) then we again distinguish
two cases. If there is no failure redex in σ , then we are done. Otherwise, σ ∨ F ; F ∨ F ; Next(F), and
the result follows from Lemma 4.13.
W
Case 2. If there are some failure redexes in F then assume that F = i=m
i=1 Fi , and let I = [m]. Let us argue
W
that NFR1 ∪R2 (F) is either F or of the form i∈I 0 Fi0 where either Fi0 = Fi or Fi0 = NFR1 ∪R2 (Next(Fi )) 6=
F for some I 0 ⊆ I. We propose an algorithm to construct I 0 . Let I 0 := I initially. (a) If m = 1, the
expected form for NFR1 ∪R2 (F) is obtained with the current I 0 . Otherwise, if m > 1, let p be the smallest
Wi=m
W
integer in [m] such that Fi contains a failure redex. Therefore we have i=1
Fi ; i=p−1
Fi ∨ fail ∨
i=1

48

Lazy AC-matching for rewriting

i=m
Fp+1 ∨ i=m
Fi ; i=p−1
Fi ∨ Next(Fp+1 ) ∨ i=p+2
Fi . Continue the elimination of the failure redexes
i=1
Wi=m i=p+2
in i=p+2 Fi by iterating (a) with {p + 2, . . . , m} instead of [m]. Let G by the resulting disjunction. If
NFR1 ∪R2 (Next(Fp+1 )) 6= F, then let I 0 := I 0 \ {p}. Otherwise, if NFR1 ∪R2 (Next(Fp+1 )) = F, then let
I 0 := I 0 \ {p, p + 1} and continue the reduction on Next(G).
Since Fi0 = Fi or Fi0 = NFR1 ∪R2 (Next(Fi )), where i ∈ I 0 , then

W

W

W

(i) NFR ↓ (Fi0 ) either follows F or follows H by Lemma 4.12. Therefore, NFR ↓ (
3
3
follows F and NFR ↓ (NFR1 ∪R2 (F)) is either F or follows the grammar F.

0
i∈I 0 Fi )

W

is either F or

3

(ii) In order to simplify the computations, let q = |I 0 | and consider the renaming i∈[q] Hi = i∈I 0 Fi0 .
W
We argue by induction on q that NFR ↓ (NFR1 ∪R2 (Next( i∈[q] Hi ))) is either F or follows H. If
3
q = 1, then by Lemma 4.11 it follows that NFR1 ∪R2 (Next(Hi )) is either F or follows G and
therefore, by Lemma 4.12, we have that NFR ↓ (NFR1 ∪R2 (Next(Hi ))) is either F or follows H.
W

W

3

?
If q > 1, then Next( i∈[q] Hi ) ; Next(H1 ) ∨ i=q
i=2 Hi . If Next(H1 ) ; F, then we apply the inducWi=q
tion hypothesis to NFR ↓ (NFR1 ∪R2 (Next( i=2 Hi ))). Otherwise, NFR1 ∪R2 (Next(H1 )) follows G,

W

W

3

Wq

and hence NFR ↓ (NFR1 ∪R2 (Next(H1 ))) follows H. On the other hand, NFR ↓ (
3

Wq

by (i). Summing up, we get that NFR ↓ (NFR1 ∪R2 (Next(H1 ))) ∨ NFR ↓ (
3

3

3

i=2 Hi ))

i=2 Hi )

follows F,

follows H.

Now we distinguish two cases for σ . If there is no failure redex in σ , then by (i) we get that
σ ∨ NFR ↓ (NFR1 ∪R2 (F)) is either a ∧-substitution or follows H. Otherwise, if there are some failure
3
redexes in σ , then we get σ ∨ F ;? F ∨ NFR1 ∪R2 (F) ; Next(NFR1 ∪R2 (F)). From (ii) it follows that
NFR ↓ (Next(NFR1 ∪R2 (F))) is F or follows H.
3

Theorem 4.15 The normal form of a pattern-matching constraint C by the system Lazy↓ is a lazy list.
Proof. From the termination of Lazy↓ (Theorem 4.8) and Proposition 4.14, we deduce that the normal
form of Lazy↓ is either F or follows the grammar H and does not contain any failure redex. Such a normal
form is of the form σ or σ ∨ F, where σ is either I or an irreducible ∧-substitution. Therefore, it remains
to show that NF(Next(F)) is a lazy list, or, equivalently, that NFR ↓ (NFR1 ∪R2 (Next(F))) follows H. But
3
this holds by Lemma 4.13.

5

Lazy AC-rewriting with strategies

In this section we integrate lazy AC-matching with strategy application. More details on strategy languages can be found in [3, 15, 13].
Primitive strategies are rewrite rules l → r and the id and fail strategies that respectively always and
never succeed. They are completed with the most usual reduction strategies, namely the four traversal
strategies leftmost-outermost, leftmost-innermost, parallel-outermost and parallel-innermost [14, Definition 4.9.5] that control a rewrite system by selecting redexes according to their position. For sake of
simplicity we restrict their control to a single rewrite rule. Let v be one of these four strategies. The
application of v to the rewrite rule l → r is denoted by v(l → r). The sequential composition of two
strategies u and w is denoted by u; w. The application of a strategy u to a term t is denoted by [u] · t.
A strategy application produces a lazy list of terms, defined by the grammar L ::= ⊥T | L :: L | T
| C(T). A list is usually defined by a constructor for an empty list and a constructor adding one element
at the head of another list. Then concatenation of two lists is defined, with another notation. Here we

W. Belkhir & A.Giorgetti

49

equivalently introduce an associative symbol :: for concatenation of two lists of terms, and a symbol ⊥T
to denote an empty list of terms, which is a neutral element for ::. We use the same conventions as for ∨
in Section 4. Let LList(T) denote the set of lazy lists of terms.

identity: [id] · τ ; τ
failure: [fail] · τ ; ⊥T
compose: [u; v] · τ ; [u] · ([v] · τ)
(a) id, fail and composition rules

rule1: [l → r] · ⊥T ; ⊥T
rule2: [l → r] · (t :: τ) ; (lAC t)(r) :: ([l → r] · τ)
subs fail: F(t) ; ⊥T
subs id: I(t) ; t
subs: (σ ∨C)(t) ; σ (t) :: C(t)
(b) Top rewriting

Figure 5: AC-rewriting operational semantics
The operational semantics of the strategies id and fail and of strategy composition are defined in
Figure 5(a) for any lazy list of terms τ and any two strategies u and v. The operational semantics of top
rewriting is defined in Figure 5(b). Let LTR be the system composed of these five rules and the Lazy↓ ACmatching. The rules rule1 and rule2 reduce the application of a rewrite rule at the top of terms in a
lazy list of terms. In rule2 the expression lAC t is reduced to its normal form by Lazy↓ . The result
is a lazy list of constraints. The rules subs fail, subs id and subs reduce the application of a lazy
list of constraints on a term. In the right side of rule subs, a ∧-substitution σ is applied to a term, in a
sense which is a simple extension of the standard definition of substitution application. Equivalently ∧substitutions can be reduced to standard ones by a transformation similar to the post-processing defined
for the eager AC-matching.
The application of the system LTR to the expression [l → r] · (t) produces either ⊥T or a non-empty
lazy list of terms u1 :: τ1 , where u1 is the first result of the application of the rewrite rule l → r at the top
of the term t and τ1 is (a syntactic object denoting) the lazy list of the other results. When applying on τ1
the rewrite system defined in Figure 6, and then the system LTR, we get again either ⊥T or a non-empty
lazy list u2 :: τ2 , where u2 is the second result of the application of the rewrite rule l → r at the top of
the term t and τ2 is again (a syntactic object denoting) a lazy list of terms that represents the remaining
results, and so on.
next empty: Next(⊥T ) ; ⊥T
next term: Next(t) ; t, if t is a term

next app: Next(L1 :: L2 ) ; Next(L1 ) :: L2
next cstr: Next(C(t)) ; Next(C)(t)

Figure 6: Next rules for lists of terms
The application of a traversal strategy on a lazy list of terms in LList(T) is defined as follows:
traversal1: [v(l → r)] · ⊥T ; ⊥T
traversal2: [v(l → r)] · (t :: τ) ; [v(l → r)] · t :: [v(l → r)] · τ
The rules
(
[u] · t
[v(u)] · t ;
↑ f ([v(u)] · t1 , . . . , [v(u)] · tn )

if [u] · t 6= ⊥T or t ∈ X
if [u] · t = ⊥T and t = f (t1 , . . . ,tn )

define the application of the traversal strategy v(u) on the term t for the rewrite rule u and the paralleloutermost strategy constructor v. The other traversal strategies can be handled similarly. We have seen
that the application of a rewrite rule at the top of a term yields a lazy list of terms in LList(T). Here

50

Lazy AC-matching for rewriting

the application of a rule to a term at arbitrary depth, via a traversal strategy, yields a decorated term,
which is a term where some subterms are replaced by a lazy list of terms. This lazy list of terms is
abusively called a lazy subterm, with the property that lazy subterms are not nested. In other words,
the positions of two lazy subterms are not comparable, for the standard prefix partial order over the set
of term positions. The operator ↑ is assumed to reduce a decorated term to a lazy list of terms. We
summarize its behavior as follows. A decorated term can be encoded by a tuple (t, k, p, δ ) where t is the
term before strategy application, k is the number of decorated positions, p is a function from {1, . . . , k}
to the domain of t (i.e. its set of positions) which defines the decorated positions, such that p(i) and p( j)
are not comparable if i 6= j, and δ is the function from {1, . . . , k} to LList(T) such that δ (i) is the lazy
list at position p(i), 1 ≤ i ≤ k. It is easy to construct an iterator over the k-tuples of positive integers (for
instance in lexicographical order), and to derive from it an iterator over tuples of terms (s1 , . . . , sk ) with
si in the list δ (i) for 1 ≤ i ≤ k. From this iterator and function p we derive an iterator producing the lazy
list ↑ t by replacing each subterm t|p(i) by si .

6

Implementation and experiments

We present here a prototypal implementation of lazy AC-matching and report about its experimentation. Our implementation is a straightforward translation of the Lazy↓ system in the rule-based language
symbtrans [1] built on the computer algebra system Maple.
This prototype obviously does not claim efficiency in the usual sense of the number of solutions
computed in a given amount of time. But this section shows that our prototype optimises the standard
deviation of the time between two successive solutions. This performance criterion corresponds to our
initial motivations and can be measured on the prototype. We consider the matching problem x1 +
. . . + x18 AC a1 + . . . + a18 , for 18 variables x1 , . . . , x18 and 18 constants a1 , . . . , a18 . On this problem
our lazy prototype provides any two consecutive solutions in an average time of 0.37 seconds, with a
standard deviation of 0.021 seconds between the 100-th first solutions. In comparison the computation
time between two consecutive solutions with the Maude function metaXmatch grows exponentially. The
experiment is done on an Intel core 2 Duo T6600@2.2GHz with 3.4Gb of memory, under a x86 64
Ubuntu Linux.
Finally, it is worth mentioning the performance of the Maple standard matching procedure patmatch(expr, pattern,’s’) that returns true if it is able to match expr to pattern, and false otherwise. If the matching is successful, then s is assigned a substitution such that AC |= s(pattern)=expr.
This procedure runs out of memory if the arity of the AC symbols is large. With Maple 14 this failure
can be observed when computing a solution of the matching problem x1 + . . . + x12 AC a1 + . . . + a12 .

7

Conclusion

We presented a lazy AC-matching algorithm and a lazy evaluation semantics for AC-rewriting and some
basic strategies. The semantics is designed to be implemented in a strict language by representing delayed
matching constraints and lazy lists of terms by explicit objects. We also described a common principle
for lazy traversal strategies. The potential benefits are clear: performances are dramatically increased
by avoiding unnecessary computations. We are working on an implementation of lazy AC-matching and
AC-rewriting: first results show that our approach is efficient when the arity of AC symbols is high and
when the number of solutions of the AC-matching problem is large. However, we do not claim efficiency
for the search of the first solution by the AC-matching algorithm.

W. Belkhir & A.Giorgetti

51

Here no neutral element is assumed for AC symbols. As a consequence the lazy AC-matching relies
on a surjection iterator. We plan to address the question of its efficiency, and to extend the present work
to AC symbols with a neutral element. Our intuition is that our approach can easily be adapted to that
case.

References
[1] W. Belkhir, A. Giorgetti & M. Lenczner (December 2010): Rewriting and Symbolic Transformations for
Multi-scale Methods. Url: http://arxiv.org/abs/1101.3218v1. Submitted.
[2] D. Benanav, D. Kapur & P. Narendran (1985): Complexity of matching problems. In: Proc. of the 1st Int.
Conf. on Rewriting Techniques and Applications, LNCS 202, Springer, pp. 417–429. doi:10.1007/3-54015976-2 22.
[3] P. Borovanský, C. Kirchner, H. Kirchner & C. Ringeissen (2001): Rewriting with strategies in ELAN:
a functional semantics. International Journal of Foundations of Computer Science 12(1), pp. 69–98.
doi:10.1142/S0129054101000412.
[4] H. Cirstea, G. Faure & C. Kirchner (2007): A ρ-calculus of explicit constraint application. Higher-Order and
Symbolic Computation 20, pp. 37–72. doi:10.1007/s10990-007-9004-2.
[5] H. Cirstea & C. Kirchner (2001): The rewriting calculus — Part I and II. Logic Journal of the Interest Group
in Pure and Applied Logics 9(3), pp. 427–498.
[6] M. Clavel, F. Durán, S. Eker, P. Lincoln, N. Martı́-Oliet, J. Meseguer & C. L. Talcott, editors (2007): All
About Maude - A High-Performance Logical Framework, How to Specify, Program and Verify Systems in
Rewriting Logic. LNCS 4350, Springer.
[7] N. Dershowitz (1982): Ordering for Term-Rewriting Systems. Theoretical Computer Science 17, pp. 279–
300. doi:10.1016/0304-3975(82)90026-3.
[8] S. Eker (1995): AC-Matching Via Bipartite Graph Matching.
doi:10.1093/comjnl/38.5.381.

Comput. J. 38(5), pp. 381–399.

[9] S. Eker (1996): Fast matching in combinations of regular equational theories. ENTCS 4, pp. 90–109.
[10] S. Eker (2002): Single Elementary AC-Matching.
doi:10.1023/A:1020122610698.

J. Autom. Reasoning 28(1), pp. 35–51.

[11] B. Gramlich (1988): Efficient AC-Matching using Constraint Propagation. In: Proc. 2nd Int. Workshop on
Unification, Internal Report 89 R 38, CRIN, Val d’Ajol, France.
[12] H. Kirchner & P.-E. Moreau (2001): Promoting rewriting to a programming language: a compiler for nondeterministic rewrite programs in AC-theories. J. Funct. Program. 11, pp. 207–251.
[13] N. Martı́-Oliet, J. Meseguer & A. Verdejo (2005): Towards a Strategy Language for Maude. Electr. Notes
Theor. Comput. Sci. 117, pp. 417–441. doi:10.1016/j.entcs.2004.06.020.
[14] Terese (2003): Term Rewriting Systems. Cambridge Tracts in Theor. Comp. Sci. 55, Cambridge Univ. Press.
[15] E. Visser (2001): Stratego: A Language for Program Transformation based on Rewriting Strategies. System
Description of Stratego 0.5. In: Proc. of RTA’01, Lecture Notes in Computer Science 2051, Springer-Verlag,
pp. 357–361. doi:10.1007/3-540-45127-7 27.
[16] B. Yang, W. Belkhir, R.N. Dhara, M. Lenczner & A. Giorgetti (2011): Computer–Aided Multiscale Model
Derivation for MEMS Arrays. In: EuroSimE 2011, 13-th Int. Conf. on Thermal, Mechanical and MultiPhysics Simulation and Experiments in Microelectronics and Microsystems, IEEE Computer Society, Linz,
Austria. 6 pages. doi:10.1109/ESIME.2011.5765784.
[17] B. Yang, R.N. Dhara, W. Belkhir, M. Lenczner & A. Giorgetti (2011): Formal Methods for Multiscale Models
Derivation. In: CFM 2011, 20th Congrès Français de Mécanique. 5 pages.

