Chapter 16
Narrowing

with Santiago Escobar

16.1 Introduction

Narrowing is a generalization of term rewriting that allows free variables in terms (as in logic programming) and replaces pattern matching by unification in order to (non-deterministically) reduce these terms. Narrowing was originally introduced as a mechanism for solving equational unification problems [54] and then generalized to solve the more general problem of symbolic reachability [86]. The narrowing mechanism has a number of important applications including automated proofs of termination [6], execution of functional-logic programming languages [5830619579], partial evaluation [4], verification of cryptographic protocols [86], and equational unification [65], to mention just a few.

At each rewriting step one must choose which subterm of the subject term and which rule of the specification are going to be considered. Similarly, at each narrowing step one must choose which subterm of the subject term, which rule of the specification,and which instantiation on the variables of the subject term and the rule’s lefthand side are going to be considered. The narrowing relation is formally defined as follows. Let R = (Σ,Ax,R) be an order-sorted rewrite theory where R is a set of unconditional rewrite rules specified with the rl keyword and Ax is a set of commonly occurring axioms (declared in Maude as equational attributes, see Section 4.4.1), such that an Ax-unification procedure is available in Maude (only unification for order-sorted signatures with free, C, or AC function symbols is available at this moment, see Chapter 12). Let CSUAx(u = u) provide1 a finitary and complete set of unifiers for any pair of terms u,uwith the same top sort. The R,Ax-narrowing relation on TΣ(X) is defined as t↝σ,p,R,Ax t(or ↝σ when p,R,Ax are understood) if there is a non-variable position p of t, a (possibly renamed) rule l r in R, and a unifier σ ∈ CSUAx(t|p = l) such that t= (t[r]p)σ. We denote by t σ,R,Ax+t (resp. t σ,R,Ax*t) the transitive (resp. reflexive-transitive) closure of the narrowing relation, where σ is obtained as the composition of the substitutions for each narrowing step in the sequence.

The difference between a rewriting step and a narrowing step is that in both cases we use a rewrite rule l r to rewrite t at a position p in t, but narrowing unifies the lefthand side l and the chosen subject term t|p before actually performing the rewriting step. Also, narrowing is usually2 restricted to non-variable positions of t, whereas rewriting does not require such a restriction.

Consider the following system module defining the addition function _+_ on natural numbers built from 0 and s:

  mod NAT-NARROWING is  
    sort Nat .  
    op 0 : -> Nat [ctor] .  
    op s : Nat -> Nat [ctor] .  
    op _+_ : Nat Nat -> Nat .  
 
    vars X Y : Nat .  
    rl [base] : 0 + Y => Y .  
    rl [ind] : s(X) + Y => s(X + Y) .  
  endm

Consider the term X + s(0) and the two rules base and ind. Narrowing will instantiate variable X with 0 and s(X’) respectively in order to be able to apply each of these rules, i.e., the following two narrowing steps are generated:

X + s(0) ↝ {X↦→0},base s(0)
X + s(0) ↝ {X↦→s(#1:Nat)},ind s(#1 : Nat+ s(0))
Note that, for simplicity, we show only the bindings of the unifier that affect the input term. There are infinitely many narrowing derivations starting at the input expression X + s(0) (at each step the reduced subterm is underlined):
  1. X + s(0) {X↦→0},base s(0)
  2. X + s(0)
    {X↦→s(#1:Nat)},ind s(#1 : Nat + s(0))
    {#1:Nat↦→0},base s(s(0))
  3. X + s(0)
    {X↦→s(#1:Nat)},ind s(#1 : Nat + s(0))
    {#1:Nat↦→s(#2:Nat)},ind s(s(#2 : Nat + s(0)))
    {#2:Nat↦→0},base s(s(s(0)))

and so on.

The following infinite narrowing derivation resulting from applying rule ind infinitely many times can also be shown:

X+-s(0) ↝ {X↦→s (#1:Nat)},ind s(#1--: Nat+-s(0))
        ↝ {#1:Nat↦→s(#2:Nat)},ind s(s(#2-: Nat-+-s(0)))
        ↝ {#2:Nat↦→s(#3:Nat)},ind s(s(s(#3-: Nat+-s(0))))
        ...

Given an order-sorted rewrite theory (Σ,Ax,R), a reachability problem is of the form X1,,Xk s.t. s *t, where X1,,Xk are all the variables of s and t. Such a reachability problem can be solved by narrowing modulo Ax, yielding a (possibly infinite) set of substitutions σ1,n, that bind some variables of X1,,Xk in such a way that σi(s) R,Ax*σi(t) for each i.

Due to nontermination, narrowing behaves as a semi-decision procedure for equational unification and for reachability analysis in a wide variety of theories. However, for some particular subject terms narrowing may terminate, providing a complete set of solutions. For instance, in the above Maude module, narrowing computes the solution {X↦→s(Y)} for the reachability problem X,Y s.t. 0 + X *s(Y) and it terminates with no more solutions. Instead, for the reachability problem X,Z s.t. X + s(0) *s(s(Z)), narrowing computes the solution {X↦→s(0), Z↦→0} but it cannot terminate because of the above infinite narrowing sequence using ind. Moreover, narrowing cannot prove that the reachability problem X s.t. X + s(0) *0 does not have a solution, again because of the above infinite narrowing sequence using ind.

We have implemented a version of narrowing with simplification, which is slightly different from the one formally defined above. Let R = (Σ,E Ax,R) be an order-sorted rewrite theory where R and Ax are defined as above and E are the remaining equations specified with the eq or ceq keywords. Each narrowing step of the form t↝σ,p,R,Ax tis followed by simplification using the relation E,Ax!, i.e., the combined relation (↝σ,p,R,Ax;E,Ax!) is defined as t↝σ,p,R,Ax;E,Ax!t′′ iff t↝σ,p,R,Ax t, t′→E,Ax*t′′, and t′′ is E,Ax-irreducible. Note that this combined relation (↝σ,p,R,Ax;E,Ax!) may be incomplete, i.e., given a reachability problem of the form t *tand a solution σ (i.e., σ(t) R,EAx*σ(t)), the relation ↝σ,p,R,Ax;E,Ax! may not be able to find a more general solution. The reason is that the equations E should also be executed by narrowing instead of rewriting to ensure completeness under appropriate conditions (see [86] and Section 16.2). However, the combination of narrowing using rules and axioms with simplification using equations and axioms can be quite helpful to allow built-in Maude functions such as addition or multiplication, which cannot be executed by narrowing in their predefined form.

16.2 Completeness of narrowing

Note that for any narrowing sequence t σ,R,Ax*s, we have a corresponding rewrite sequence σ(t) R,Ax*s. However, only under appropriate conditions is narrowing complete as an equational unification algorithm [6566], or as a procedure to solve reachability problems [86]. That is, given a reachability problem3 X1,,Xk s.t. s *t completeness means that for each possible substitution ρ that binds some variables of X1,,Xk in such a way that ρ(s) R,Ax*ρ(t), and for all the substitutions σ1,n, provided by narrowing from s, there is an index i and two substitutions θ,τ such that ρ(s) R,Ax*θ(s), ρ(t) R,Ax*θ(t), θ(s) R,Ax*θ(t), and θ = Axσi;τ, where σi;τ denotes substitution composition in diagrammatic order, i.e., (σi;τ)(X) = τ(σi(X)). Essentially, completeness holds either

  1. for R,Ax-normalized substitutions ρ above [86];
  2. for topmost rewrite theories4 ;
  3. for right-linear theories and linear reachability goals5 ; and
  4. in particular for theories that are confluent, terminating, and coherent, as the equational theories in Maude functional modules with such properties restricted to unconditional equations.

16.3 Theories supported

The narrowing relation is defined on top of the order-sorted unification procedure described in Chapter 12. As described there, Maude 2.4 currently provides an order-sorted Ax-unification algorithm for all order-sorted theories (Σ,E Ax) such that:

Explicitly excluded are theories with binary function symbols having either: (i) the id:, left id:, or right id: attributes; or (ii) the assoc attribute without the comm one; or (iii) a combination of (i) and (ii) (for example, a binary symbol with only assoc and id: attributes).

Let mod ,E Ax,R) endm be an order-sorted system module where R is a set of rewrite rules specified with the rl or crl keywords, Ax is a set of commonly occurring axioms (declared in Maude as equational attributes, see Section 4.4.1) such that (Σ,Ax) satisfies the restrictions mentioned above and in Chapter 12, and E are the remaining equations specified with the eq or ceq keywords. Furthermore, the rules R must satisfy the following extra conditions:

We recall again that the equations E in the system module are disregarded for narrowing purposes. However, they are applied for simplification after each narrowing step, as it is performed in Maude for rewriting. Recall, again, that this combination of one narrowing step followed by equational simplification is not complete. A full treatment of rules, equations, and axioms for narrowing is outside the scope of the present implementation and is left for future work.

Furthermore, frozen arguments (see Section 4.4.9) are allowed for narrowing, as for rewriting, and are given the standard meaning of not allowing any narrowing step below such frozen arguments, just as in the context-sensitive narrowing of [70].

Finally, we do not consider any narrowing strategy at all for solving reachability problems, i.e., all positions in a term with an admissible R,Ax-narrowing step are explored.

16.4 The narrowing search command

Given a system module ModId, the user can give to Full Maude a search command of the form:

  (search  [ n, m    ] in ModId : Term-1 SearchArrow Term-2 .)

where:

Consider, for example, the following variant of the vending machine for buying apples (a) or cakes (c) with dollars ($) and quarters (q) used in different parts of the manual, where now the rules are explicitly coherent and the lefthand sides are non-variable terms (this theory does indeed satisfy the completeness requirements for reachability mentioned in [86] and Section 16.2 above):

 (mod NARROWING-VENDING-MACHINE is  
    sorts Coin Item Marking Money State .  
    subsort Coin < Money .  
    op __ : Money Money -> Money [assoc comm] .  
    subsort Money Item < Marking .  
    op __ : Marking Marking -> Marking [assoc comm] .  
    op <_> : Marking -> State .  
    op $ : -> Coin [format (r! o)] .  
    op q : -> Coin [format (r! o)] .  
    op a : -> Item [format (b! o)] .  
    op c : -> Item [format (b! o)] .  
 
    var M : Marking .  
    rl [buy-c] : < $ > => < c > .  
    rl [buy-c] : < M $ > => < M c > .  
    rl [buy-a] : < $ > => < a q > .  
    rl [buy-a] : < M $ > => < M a q > .  
    rl [change]: < q q q q > => < $ > .  
    rl [change]: < M q q q q > => < M $ > .  
  endm)

We can use the narrowing search command to answer the question:

Is there any combination of one or more coins that returns exactly an apple and a cake?

This is done by searching for states that have a variable of sort Money instead of sort Marking at the starting term and match a corresponding pattern at the end.

  Maude> (search [,4] in NARROWING-VENDING-MACHINE :  
            < M:Money > ~>* < a c > .)  
 
  Solution 1  
  M:Money --> $ q q q  
 
  Solution 2  
  M:Money --> q q q q q q q  
 
  No more solutions.

Note that we must restrict the depth, because narrowing does not terminate for this reachability problem even though the above two solutions are indeed the only solutions. The problem is that narrowing follows a breadth-first exploration and does not stop until the whole narrowing tree demanded by the search command is created, even though this infinite search may not yield any further solutions. The very same problem happens for the standard search command (see Section 5.4.3). Indeed, if we increase the depth of the narrowing tree, we can experimentally observe that no more solutions are found.

  Maude> (search [,20] in NARROWING-VENDING-MACHINE :  
            < M:Money > ~>* < a c > .)  
 
  Solution 1  
  M:Money --> $ q q q  
 
  Solution 2  
  M:Money --> q q q q q q q  
 
  No more solutions.

As with the search command of Full Maude (see Section 15.5), the narrowing version does not provide paths to solutions.

We can formulate a more complex question for our vending machine:

Is there any combination of one or more coins that returns an apple and a cake and is such that some extra money is left but that extra money cannot be used to buy anything else?

The fact that some money is left is characterized by including a variable of sort Money in the final state, and the fact that nothing can be bought is characterized by using the ~>! arrow instead of ~>*.

  Maude> (search [,5] in NARROWING-VENDING-MACHINE :  
            < M:Money > ~>! < MO’:Money a c > .)  
 
  Solution 1  
  M:Money --> $ $ ; MO’:Money --> q  
 
  Solution 2  
  M:Money --> $ q q q q ; MO’:Money --> q  
 
  Solution 3  
  M:Money --> q q q q q q q q ; MO’:Money --> q  
 
   No more solutions.

There are a couple of issues related to this reachability problem:

  1. Solutions more general than those would be expected but are not generated, such as the following solution which is more general than solution 1:
      M:Money --> $ $ #1:Money ; MO’:Money --> q #1:Money

    The reason is that any state term enclosed by the <_> operator and containing a variable of sort Marking or Money does have a narrowing step from it and, thus, the state < q a c #1:Money > would not be strongly irreducible for narrowing.

  2. Solutions containing several coins q would also be expected and are not generated, such as
      M:Money --> $ $ q q ; MO’:Money --> q q q

    Now the reason is that there is no rule that introduces symbols q by unification, so the substitution M:Money --> $ $ q q cannot be computed. This does not mean that narrowing is incomplete (it is indeed complete for this theory). This solution is indeed a substitution instance of the solution mentioned in (1) above.

The reason why we do not obtain these solutions is our restriction to strongly irreducible final states. But if we give the very same command but using the ~>* arrow instead of ~>!, we do obtain the substitution

  M:Money --> $ $ #1:Money ; MO’:Money --> q #1:Money

described above. The somewhat subtle point is that the narrowing sequence

< M:Money > ↝+  < a c q #1:Money >
covering all these additional solutions as special cases ends in the state < a c q #1:Money > which can be further narrowed, whereas its instances < a c q q > and < a c q q q > cannot be further narrowed.

Another point of interest is the appearance of variables of the form #n:Sort, which are called fresh and are described in Chapter 12. Unification modulo axioms usually introduces fresh variables; furthermore, narrowing introduces many fresh variables because the rule applied at each narrowing step is appropriately renamed so that no variable is shared by it and the current term. Indeed, the standard solution used in logic and functional-logic programming language implementations is to use a counter along each narrowing derivation to ensure that fresh variables have never been used previously in that narrowing derivation. This method is called standardized apart.

Although rewriting does not allow extra variables in the righthand side of rules6 , extra variables in righthand sides pose no problem for narrowing. Since rules having extra variables in the righthand side are not allowed in Maude for rewriting purposes, the attribute nonexec (see Section 4.5.3) must be added to such rules if one wants to use them for narrowing. The nonexec attribute is not taken into account by narrowing: all unconditional rules, regardless of whether or not they include the nonexec attribute, are used by narrowing. Extra variables in the righthand side are a common feature of programs using narrowing as the operational evaluation mechanism, as in logic programming or functional-logic programming (see [61]). Let us motivate this feature with an example. Consider the following program defining the concatenation of two lists and the function last:

 (mod LAST-APPEND is  
    sort Nat .  
    op 0 : -> Nat .  
    op s : Nat -> Nat .  
 
    sort NatList .  
    op nil : -> NatList .  
    op _:_ : Nat NatList -> NatList .  
 
    vars XS YS : NatList .  
    vars N M X Y : Nat .  
 
    op append : NatList NatList -> NatList .  
    rl append(nil, YS) => YS .  
    rl append(N : XS, YS) => N : append(XS, YS) .  
 
    op error : -> [Nat] .  
 
    op last : NatList -> [Nat] .  
    rl last(XS)  
      => if append(YS, N : nil) =:= XS  
         then N  
         else error  
         fi  
      [nonexec] .  
 
    op _=:=_ : Nat Nat -> Bool [comm] .  
    rl N =:= N => true .  
    rl 0 =:= 0 => true .  
    rl s(N) =:= s(M) => N =:= M .  
    rl 0 =:= s(N) => false .  
 
    op _=:=_ : NatList NatList -> Bool [comm] .  
    rl XS =:= XS => true .  
    rl nil =:= nil => true .  
    rl X : XS =:= Y : YS  => X =:= Y and XS =:= YS .  
    rl nil =:= X : XS => false .  
  endm)

In the rule

    rl last(XS)  
      => if append(YS, N : nil) =:= XS  
         then N  
         else error  
         fi  
      [nonexec] .

we have used an extra variable N to denote the last element of the list and used a constraint

  append(YS, N : nil) =:= XS

that narrowing will solve by instantiating N in the proper way. Furthermore, note the use of the kind [Nat] and the value error in order to describe what a successful solution is. The following reachability problem is solved by narrowing but cannot be solved by rewriting due to the extra variable in the last rule.7

  Maude> (search [1] last(0 : s(0) : nil) ~>! Z:Nat .)  
 
  Solution 1  
  Z:Nat --> s(0)  
 
  No more solutions.

16.5 Unification with identities: The id-unify command

As described in Chapter 12 and also recalled in Section 16.3, Maude 2.4 currently provides an order-sorted Ax-unification algorithm for all order-sorted theories (Σ,E Ax) such that Σ is preregular and Ax can include any combination of equational axioms for a function symbol except the id:, left id:, right id:, and assoc without comm.

As explained in Section 12.6.1, if a theory (Σ,E Ax) satisfies the coherence, confluence, and termination modulo Ax requirements, we can systematically reduce E Ax-unification problems into narrowing problems as follows:

  1. we define the signature ^Σ by adding a fresh new sort Truth to Σ with a constant tt;
  2. we define the set of rules  ⃗
E by transforming each equation in E into a rule in  ⃗
E;
  3. for each top sort of each connected component of sorts we add to ^Σ a binary predicate eq of sort Truth and add to E⃗q the rule eq(x,x) tt, where x has such a top sort;
  4. we define the rewrite theory (^Σ,Ax,E⃗ E⃗q);
  5. we then reduce an EAx-unification problem t=?tto the narrowing reachability problem eq(t,t) *tt modulo Ax in the rewrite theory (^Σ,Ax,⃗E).

That is, we search for all narrowing paths modulo Ax from eq(t,t) to tt. Each such path then gives us a unifier of the equation t?=t, just by composing the unifiers of each narrowing step in the narrowing path.

Therefore, if a theory (Σ,Ax) contains the id:, left id:, or right id: attributes in Ax (but not assoc without comm), we can perform unification modulo Ax as follows:

  1. we decompose Ax into a disjoint union Ax = ^
Ax Ids, where ^
Ax does not contain any id:, left id:, or right id: attribute, and Ids is the set of such extra attributes;
  2. we define the rewrite theory (Σ,^Ax,I⃗ds) where ⃗Ids contains the obvious rules for each of the equational identity attributes, that is:
  3. we define the theory (^
Σ, ^
Ax,⃗
Ids  ⃗
Eq) as above and then reduce an Ax-unification problem t?
=t to the narrowing reachability problem eq(t,t) *tt modulo ^
Ax in the rewrite theory (^Σ,^Ax,I⃗ds E⃗q).

However, solving such reachability problems for ACU-unification using full AC-narrowing can easily lead to an infinite search space and therefore to undecidability, since it is well-known that narrowing modulo AC “almost never terminates” and, furthermore, that narrowing strategies facilitating termination such as basic narrowing are incomplete [27103]. However, based on the idea of “variants” in [27], a complete, yet quite efficient in terms of its search space, narrowing strategy modulo Ax, called variant narrowing, has been proposed in [53]. Such unification procedure can be used for ACU-unification in an equational theory (Σ,Ax) containing the id:, left id:, or right id: attributes in Ax but not assoc without comm. We proceed as follows (see [53] for further details):

  1. we take the rewrite theory (Σ,^Ax,I⃗ds) as defined above;
  2. for the unification problem t?
=t, we compute the variants of t and the variants of tusing (Σ,^Ax,I⃗ds) and perform A^x-unification pairwise among all the variants of t and t.

The unification procedure using variants is implemented through the command id-unify explained below.

Given a functional module, system module, or theory ModId having a set Ax of equational axioms for the signature Σ such that Σ does not include symbols with assoc without comm attributes in Ax, the user can give to Full Maude a unification command for Ax-unification of the form:

  (id-unify in ModId : Term-1 =? Term-2 .)

where only one unification problem is admitted (in contrast to the unify command described in Section 12.4) and such that no limit to the number of unifiers can be specified. The theories supported must satisfy the following requirements:

Consider, for example, the following simple definition of multisets with identity:

 (mod ID-UNIFICATION-EXAMPLE is  
    sorts MSet Elem .  
    subsorts Elem < MSet .  
    op __ : MSet MSet -> MSet [assoc comm id: e] .  
    ops a b c d e : -> Elem .  
  endm)

We can use the id-unify command to solve the following three unification problems:

  Maude> (id-unify in ID-UNIFICATION-EXAMPLE : a a =? a a e .)  
 
  Solution 1  
  empty substitution  
 
  No more solutions.

  Maude> (id-unify in ID-UNIFICATION-EXAMPLE : X:MSet =? a a e .)  
 
  Solution 1  
  X:MSet --> a a  
 
  No more solutions.

  Maude> (id-unify in ID-UNIFICATION-EXAMPLE : a X:MSet =? a a Y:MSet .)  
 
  Solution 1  
  X:MSet --> a Y:MSet  
 
  Solution 2  
  X:MSet --> a ; Y:MSet --> e  
 
  No more solutions.

For the following substitutions computed for the last unification problem: σ1 = {X:MSet↦→(a Y:MSet)} and σ2 = {X:MSet↦→a,Y:MSet↦→e}, the reader might believe that σ2 is subsumed by σ1, because the substitution ρ = {Y:MSet↦→e} can be built in such a way that σ1;ρ can be normalized into σ2. However, they are incomparable modulo AC, since both computed substitutions are valid only for I⃗ds,^Ax-normalized substitutions. Indeed, our equational unification procedure modulo identity can compute only I⃗ds,^Ax-normalized unifiers which are valid only for ⃗Ids,^Ax-normalized instance substitutions. That is, given Ax = ^Ax Ids, a unification problem t?
=t, and a Ax-unifier σ,

  1. σ is assumed to be  ⃗
Ids, ^
Ax-normalized (if not, we can normalize it and the normalized version will still be a valid Ax-unifier);
  2. there will be a computed Ax-unifier θ and an extra substitution ρ such that σ = ^
Axθ;ρ and both θ and ρ are also assumed to be ⃗
Ids,^
Ax-normalized.

Let us illustrate also the use of left-id and right-id attributes. Consider the following variation of the previous example where we remove associativity and commutativity, but still keep the identity operator as a left identity:

 (mod LEFTID-UNIFICATION-EXAMPLE is  
    sorts Magma Elem .  
    subsorts Elem < Magma .  
    op __ : Magma Magma -> Magma [gather (E e) left id: e] .  
    ops a b c d e : -> Elem .  
  endm)

Then the following two unification problems have a different and peculiar meaning, where we have swapped the position of the variables.

  Maude> (id-unify X:Magma a =? Y: Magma a a .)  
 
  Solution 1  
  X:Magma --> Y:Magma a  
 
  Solution 2  
  X:Magma --> a ; Y:Magma --> e  
 
  No more solutions.

  Maude> (id-unify a X:Magma =? a a Y:Magma .)  
  No unifier

Let us now consider the case of a right identity:

 (mod RIGHTID-UNIFICATION-EXAMPLE is  
    sorts Magma Elem .  
    subsorts Elem < Magma .  
    op __ : Magma Magma -> Magma [gather (e E) right id: e] .  
    ops a b c d e : -> Elem .  
  endm)

Then the very same unification problems above have a different behavior

  Maude> (id-unify X:Magma a =? Y:Magma a a .)  
 
  No unifier

  Maude> (id-unify a X:Magma =? a a Y:Magma .)  
 
  Solution 1  
  X:Magma --> a Y:Magma  
 
  Solution 2  
  X:Magma --> a ; Y:Magma --> e  
 
  No more solutions.

16.6 Reachability at the metalevel: metaNarrowSearch

Narrowing-based reachability analysis is also available at the metalevel by using the function metaNarrowSearch. The functional module providing the necessary infrastructure is called META-NARROWING-SEARCH and the function metaNarrowSearch has the following declaration:

op metaNarrowSearch :  
   Module Term Term Substitution Qid Bound Bound -> ResultTripleSet .

If a non-identity substitution is provided in the fourth argument, then any computed substitution must be an instance of the provided one, i.e., we can restrict the computed narrowing sequences to some concrete shape. The Qid argument metarepresents the appropriate search arrow, similar to the metaSearch command (see Section 11.4.6). For the bounds, the first bound is the maximum length of the narrowing sequences, i.e., the depth of the narrowing tree, and the second bound is the number of computed solutions.

For the NARROWING-VENDING-MACHINE system module in Section 16.4, the following search command considered in that section

  Maude> (search [,4] in NARROWING-VENDING-MACHINE :  
            < M:Money > ~>* < a c > .)

can be specified at the metalevel as follows, where ’<_>[’M:Money] is the metarepresentation of the state < M:Money > and ’<_>[’__[’a.Item,’c.Item]] is the metarepresentation of the state < a c >:

  Maude> (red in META-NARROWING-SEARCH :  
            metaNarrowSearch(upModule(NARROWING-VENDING-MACHINE),  
              ’<_>[’M:Money],  
              ’<_>[’__[’a.Item, ’c.Item]],  
              none, ’*, 4, unbounded) .)  
  result ResultTripleSet :  
    {’<_>[’__[’a.Item,’c.Item]], ’State,  
     ’#1:Marking <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#3:Money <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#4:Marking <- ’a.Item ;  
     ’#6:Marking <- ’a.Item ;  
     ’M:Money <- ’__[’$.Coin, ’__[’q.Coin, ’q.Coin, ’q.Coin]]}  
  | {’<_>[’__[’a.Item, ’c.Item]], ’State,  
     ’#1:Marking <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#3:Money <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#4:Marking <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#6:Money <- ’__[’q.Coin, ’q.Coin, ’q.Coin];  
     ’#7:Marking <- ’a.Item ;  
     ’#9:Marking <- ’a.Item ;  
     ’M:Money <- ’__[’q.Coin, ’q.Coin, ’q.Coin, ’q.Coin,  
                      ’__[’q.Coin, ’q.Coin, ’q.Coin]]}

Note that we obtain the very same two solutions, where the output contains two terms of type ResultTriple, each one containing the actual output term, its type, and the computed substitution, and

  ’M:Money <- ’__[’$.Coin, ’__[’q.Coin, ’q.Coin, ’q.Coin]]

is the metarepresentation of the substitution M:Money --> $ q q q, whereas

  ’M:Money <- ’__[’q.Coin, ’q.Coin, ’q.Coin, ’q.Coin,  
                   ’__[’q.Coin, ’q.Coin, ’q.Coin]]

is the metarepresentation of the substitution M:Money --> q q q q q q q. Moreover, the substitutions computed in this way also contain all the temporary bindings that narrowing has computed.

16.7 Unification with identities at the metalevel:
metaACUUnify

The procedure for equational Ax-unification where Ax can contain any equational attribute except assoc without comm is available at the metalevel by using the metaACUUnify function. The functional module providing the necessary infrastructure is called META-E-UNIFICATION and the metaACUUnify function has the following declaration:

  op metaACUUnify : Module Term Term -> SubstitutionSet .

For the ID-UNIFICATION-EXAMPLE system module in Section 16.5, the following id-unify command considered in that section

  Maude> (id-unify in ID-UNIFICATION-EXAMPLE : a X:MSet =? a a Y:MSet .)

can be specified at the metalevel as follows, where ’__[’a.Elem, ’X:MSet] metarepresents the term a X:MSet and ’__[’__[’a.Elem, ’a.Elem], ’Y:MSet] metarepresents the term a a Y:MSet:

  Maude> (red in META-NARROWING-SEARCH :  
            metaACUUnify(upModule(ID-UNIFICATION-EXAMPLE),  
              ’__[’a.Elem, ’X:MSet],  
              ’__[’__[’a.Elem, ’a.Elem], ’Y:MSet]) .)  
  result NeSubstitutionSet :  
     (’X:MSet <- ’a.Elem ;  
      ’Y:MSet <- ’e.Elem)  
   | (’X:MSet <- ’__[’a.Elem, ’Y:MSet])

Note that, as expected, the very same two solutions are returned, i.e., the metarepresentations of the two substitutions X:MSet --> a Y:MSet and X:MSet --> a ; Y:MSet --> e.