Analysis Verification and Transformation for Declarative Programming and Intelligent Systems Essays Dedicated to Manuel Hermenegildo on the Occasion of His 60th Birthday Pedro Lopez-Garcia - Quickly download the ebook in PDF format for unlimited reading
Analysis Verification and Transformation for Declarative Programming and Intelligent Systems Essays Dedicated to Manuel Hermenegildo on the Occasion of His 60th Birthday Pedro Lopez-Garcia - Quickly download the ebook in PDF format for unlimited reading
com
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/practical-guide-to-vegetable-oil-
processing-2nd-edition-monoj-k-gupta/
ebookmeta.com
Spacecraft 1st Edition Timothy Morton
https://ebookmeta.com/product/spacecraft-1st-edition-timothy-morton/
ebookmeta.com
Baby Don t Go Beach Babies 1st Edition M.K. Moore & Flirt
Club
https://ebookmeta.com/product/baby-don-t-go-beach-babies-1st-edition-
m-k-moore-flirt-club/
ebookmeta.com
https://ebookmeta.com/product/colonizing-kashmir-state-building-under-
indian-occupation-1st-edition-hafsa-kanjwal/
ebookmeta.com
https://ebookmeta.com/product/connecting-discrete-mathematics-and-
computer-science-solution-manual-2nd-edition-david-liben-nowell/
ebookmeta.com
https://ebookmeta.com/product/forbidden-french-1st-edition-r-s-grey/
ebookmeta.com
The Law and Politics of Unconstitutional Constitutional
Amendments in Asia 1st Edition Rehan Abeyratne (Editor)
https://ebookmeta.com/product/the-law-and-politics-of-
unconstitutional-constitutional-amendments-in-asia-1st-edition-rehan-
abeyratne-editor/
ebookmeta.com
Pedro Lopez-Garcia
John P. Gallagher
Roberto Giacobazzi (Eds.)
Festschrift
LNCS 13160
Roberto Giacobazzi
Università di Verona
Verona, Italy
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface
efficiency, and usefulness in real-world tasks were (and are) the driving forces behind his
research. He was an active member of the Association for Logic Programming (ALP)
and was first elected to the ALP executive committee in 1993 and later as ALP President,
from 2005 to 2009. To this day, he continues to be involved with the ALP as Secretary
and Director.
He has also been a member of the editorial boards of different journals as well as
program chair of many conferences and workshops on implementation, analysis, and
verification of logic programming, such as ICLP, LOPSTR, FLOPS, PADL, and PPDP –
always focussing on ensuring the quality of the scholarly works presented at these venues.
Apart from logic programming events, he has been involved in leading conferences
on programming languages, analysis, and verification more generally, including being
program chair of SAS and VMCAI and general chair of POPL.
As a relatively young science, computing has sometimes struggled to obtain public
research funding in competition with the established disciplines. Manuel has worked
tirelessly to raise the profile of computer science in Spain, taking on the job of Director
of the Spanish National Research Directorate for two years in 2000, while somehow
maintaining his research activities. As an extension to his national activities, Manuel
was deeply involved in representing Spain in European Union funding programs.
In 2003 Manuel returned partly to the USA to take on the Prince of Asturias Chair
in Information Science and Technology at the University of New Mexico, where he
extended his research activities and group, all of which gave rise to many collabora-
tions and results, including three Ph.D. theses, in addition to laying new avenues for
collaboration between Spain and the USA.
In the early 2000s, the Madrid regional government began to plan a network of
research institutes of the highest international stature. Manuel’s research achievements
and his experience in research policy was vital in ensuring that Computer Science was
adequately represented in these plans. In 2007, he was appointed as the Founding Sci-
entific Director of the IMDEA Software Institute, a position he held for 10 years, during
which the Institute was established and grew to be the world-class research institution
it is now.
Manuel has been given many awards, including the National “Aritmel” Prize for
Scientific Merit in Computer Science, 2005, and the National “Julio Rey Pastor” Prize
for Research in Mathematics and Information and Communication, 2006. He has been
appointed to many other positions of high responsibility, clearly showing the trust he has
within the research community: Elected member of the Academia Europæa; President of
the Scientific Advisory Board of Inria; President of the Association for Logic Program-
ming; and Member of the Scientific Advisory Board of the Schloß Dagstuhl International
Center. In 2022 he was elected a Fellow of the ACM for contributions to program analysis,
verification, parallelism, logic programming, and the IMDEA Software Institute.
Throughout his scientific career, Manuel has had hundreds of research collabora-
tors. All of them know his amazing capacity for detailed work, thoroughness, and expert
contributions at all the stages of a piece of work, from its inception to the final prod-
uct. Manuel has in abundance all the skills needed for successful collaboration: exten-
sive knowledge, innovative ideas, interpersonal skills, a positive attitude, capacity for
encouragement, a sense of humour, and the ability to turn a potential conflict into a
Preface ix
constructive discussion. In short, working with him is a pleasure and a source of inspira-
tion. Those who perhaps know this best are his 15 Ph.D. students: Kalyan Muthukumar,
Yow-Yan Lin, María García de la Banda, Francisco Bueno, Germán Puebla, Pedro López-
García, Manuel Carro, Daniel Cabeza, Jorge Navas, Amadeo Casas, Mario Méndez, José
Francisco Morales, Pablo Chico de Guzmán, Nataliia Stulova, and Isabel García.
To Manuel Hermenegildo, the scholar, teacher, engineer, manager, administrator,
leader, and friend, with deep admiration, gratitude, and affection. Happy birthday!
Editors
1 Introduction
Rewriting logic is a computational logic that was developed thirty years ago [11].
The semantics of rewriting logic [2] has a precise mathematical meaning, allowing
mathematical reasoning for proving properties, providing a flexible framework
for the specification of concurrent systems.
A system is specified in rewriting logic as a rewrite theory R = (Σ, E, R),
with (Σ, E) an underlying equational theory, which in this work will be order-
sorted equational logic, where terms are given as an algebraic data type, and R
is a set of rules that specify how the system can derive one term from another.
Strategies allow modular separation between the rules that specify a system
and the way that these rules are applied. In this work we will use a subset of
the Maude strategy language [5,10,20], and we will give an interpretation of its
semantics.
A reachability problem has the form ∃x̄(t(x̄) →∗ t (x̄)), with t, t terms with
variables in x̄, or a conjunction ∃x̄ i (ti (x̄) →∗ ti (x̄)). In the general case where
t(x̄) is not a ground term, a technique known as narrowing [7] that was first
proposed as a method for solving equational problems (unification), has been
extended to cover also reachability problems [15]. One of the weaknesses of nar-
rowing is the state space explosion associated to any reachability problem where
arithmetic equational theories are involved. Satisfiability modulo theories (SMT)
solvers [17] may mitigate this state space explosion.
This paper extends our previous work [1], where we developed a sound and
weakly complete, i.e., complete with respect to normalized answers, narrowing
calculus when R = (Σ, E0 ∪ B, R), with E0 a subset of the theories handled
by SMT solvers and B a set of axioms for the other algebraic data types. Here
we introduce: (i) the use of strategies to further reduce the state space, and (ii)
the support for parameters in the specifications, i.e., a subset of the variables in
them, either SMT or not, to be considered as common constants that need to be
given a value in the reachability problem. We have defined a strategy language
suitable for narrowing, given a proof tree based interpretation of the semantics
of the strategy language, and developed a completely new narrowing calculus
that includes the strategy language and the use of parameters. Under certain
requirements, the calculus is proven to be sound and weakly complete.
The work is structured as follows: Sect. 2 presents basic definitions and prop-
erties for order-sorted equational deduction and unification. Section 3 presents
rewriting modulo built-in subtheories and axioms (R/E). In Sect. 4 the concepts
of built-in subtheory, abstraction, B-extension, and rewrite theory closed under
B-extensions are introduced. Also, the relation →R,B is presented. This rela-
tion is closely related to the narrowing calculus to be developed in Sect. 7. Then
the equivalence of R/E-rewriting and R, B-rewriting, for rewrite theories closed
under B-extensions, is proved. In Sect. 5 the strategy language and its semantics
are presented; then, an interpretation of this semantics is proved. In Sect. 6 we
define the concept of parameterized reachability problem and its solution. In
Sect. 7 the narrowing calculus for reachability is introduced. Then the soundness
and weak completeness of the calculus are proved, as well as its completeness for
some rewrite theories. Section 8 shows an example of the use of the calculus. In
Sect. 9, related work, conclusions, and future lines of investigation for this work
are presented. The technical report TR-02/2021, with more definitions, expla-
nations, examples, and all the related proofs, together with the prototype with
the running example, can be found at http://maude.ucm.es/cnarrowing.
2 Preliminaries
Familiarity with term rewriting and rewriting logic [2] is assumed. Several def-
initions and results from [19] are included in this section. The technical report
TR-02/2021 holds other definitions, required in the proofs.
viated to ct) seconds. No overcooking is allowed. Fresh toasts are taken from a
toast bag, and they are cooked using a frying pan that can toast up to two toasts
simultaneously, well-cooking one side of each toast in the pan. There is a bin,
where fresh toasts are put when taken from the bag. A toast in the pan can be
returned to the bin, being flipped in this process. Finally, there is a dish where
well-cooked toasts can be output. There is a limit of failTime (ft) seconds to
reach the desired final state. In this example, ct and ft will be the parameters,
i.e., they are the variables that represent the common constants of the specifi-
cation that must be given a value either by the conditions of the problem or by
its solution (Fig. 1).
A Toast (abbreviated to t) can be either a RealToast (rt), represented as
an ordered pair of natural numbers, each one with sort Integer (i), storing the
seconds that each side has already been toasted, or an EmptyToast (et) which
has a constant zt, representing the absence of Toasts; a Pan (p) is an unordered
pair of Toasts; a Kitchen (k) has a timer, represented by a natural number, and
a Pan; a Bin (b) is a multiset of Toasts; the bag and the dish are represented
by natural numbers, the number of RealToasts in each one; the System (s) has
a bag, a Bin, a Kitchen, and a dish. When a RealToast is in the pan, the side
being toasted is represented by the first integer of the ordered pair. We will use
two auxiliary functions, cook and toast (in lowercase).
Example 2. In the cooking example, omitting the implied kind for each con-
nected component of S, Σ = (S, ≤, F ) is:
S = {Integer, RealToast, EmptyToast, Toast, Pan, Kitchen, Bin, System},
≤ = {(RealToast, Toast), (EmptyToast, Toast), (Toast, Bin)},
F = {{[ , ]}i i,rt , { }t t,p , { ; }b b,b , { ; }i p,k , {cook}k i,[k] , {toast}t i,[t] ,
{ / / / }i r k i,s , {zt}et }.
The notation used in F has the following meaning: {[ , ]}i i,rt means that
[ , ] is a mix-fix function symbol such that if i1 and i2 are terms with sort
Integer then [i1 , i2 ] is a term with sort RealToast.
A function symbol f in Σs1 ...sn ,s is displayed as f : s1 . . . sn → s, its rank
declaration. An S-sorted set X = {Xs }s∈S of variables satisfies s = s ⇒ Xs ∩
Xs = ∅, and the variables in X are disjoint from all the constants in Σ. Each
variable in X has a subscript indicating its sort, i.e., xs has sort s.
The sets TΣ,s and TΣ (X )s denote, respectively, the set of Σ-terms with sort
s and the set of Σ-terms with sort s when the variables in X are considered
extra
constantsof Σ. The notations TΣ and TΣ (X ) are used as a shortcut for
T
s∈S Σ,s and s∈S TΣ (X )s respectively. It is assumed that Σ has non-empty
sorts, i.e., TΣ,s = ∅ for all sorts s in S. We write vars(t) to denote the set of
variables in a term t in TΣ (X ). This definition is extended in the usual way to
any other structure, unless explicitly stated. If vars(A) = ∅, where A is any
structure, then A is said to be ground. A term where each variable occurs only
once is said to be linear.
Positions in a term t: when a term t is expressed in functional notation as
f (t1 , . . . , tn ), it can be pictured as a tree with root f at position and children
ti at position i, for 1 ≤ i ≤ n. The inner positions of t are referred as lists of
nonzero natural numbers separated by dots. The set of positions of t is written
pos(t). The set of non-variable positions of t is written pos Σ (t). t|p is the subtree
of t below position p. t[u]p is the replacement in t of t|p with u. t[ ]p is a term
with hole that is equal to t except that in the position p there is a special symbol
[ ], the hole. For positions p and q, we write p ≤ q if there is a position r such
that q = p.r. Given any ordered list ū = u1 , . . . , un , we call û = {u1 , . . . , un }.
Definition 3 (Preregularity). Given an order-sorted signature Σ, for each
natural number n, for every function symbol f in Σ with arity n, and for every
tuple (s1 , . . . , sn ) in S n , let Sf,s1 ...,sn be the set containing all the sorts s that
appear in rank declarations in Σ of the form f : s1 . . . sn → s such that si ≤ si ,
for 1 ≤ i ≤ n. If whenever Sf,s1 ,...,sn is not empty it is the case that Sf,s1 ,...,sn
has a least sort, then Σ is said to be preregular.
Preregularity guarantees that every Σ-term t has a least sort, denoted ls(t),
i.e., for any rank declaration f : s1 . . . sn → s that can be applied to t it is true
that ls(t) ≤ s.
A substitution σ : X → B, where B ⊆ TΣ (X ) is a superset of the range
of σ, defined below, is a function that matches the identity function in all X
except for a finite set called its domain, dom(σ). We represent the application
of a substitution σ to a variable x in X as xσ. Substitutions are written as
Strategies in Conditional Narrowing Modulo SMT Plus Axioms 5
n n
σ = {x1s1 →t 1 , · · ·, xsn →tn }, where dom(σ) is {xs1 , . . ., xsn } and the range of σ
1
n
is ran(σ) = i=1 vars(ti ). If ran(σ) = ∅ then σ is ground. We write σ : D → B,
where D ⊂ X is finite, to imply that dom(σ) = D. The identity substitution,
where dom(σ) = ∅, is displayed as none. A substitution σ where dom(σ) =
{x1s1 , . . . , xnsn } (n ≥ 0), xisi σ = ysi i ∈ X , for 1 ≤ i ≤ n, and ysi i = ysjj for
1 ≤ i < j ≤ n is called a renaming. The restriction σV of σ to a set of variables
V is defined as xσV = xσ if x ∈ V and xσV = x otherwise. The deletion σ\V ,
where V ⊆ X is defined as xσ\V = xσ if x ∈ dom(σ) \ V and xσ\V = x otherwise.
Substitutions are homomorphically extended to terms in TΣ (X ) and also to any
other syntactic structures. The composition of σ and σ is denoted by σσ , with
x(σσ ) = (xσ)σ (left associativity). Their closed composition, denoted by σ·σ ,
is defined as σ·σ = (σσ )\ran(σ) . If σσ = σ then we say that σ is idempotent.
A context C is a λ-term of the form λx1s1 · · · xnsn .t, with t ∈ TΣ (X ) and
{xs1 , . . . , xnsn } ⊆ vars(t). A Σ-equation has the form l = r, where l ∈ TΣ (X )sl ,
1
Example 3. The OS equational theory for the toast example has Σ = (S, ≤, F )
and E is the set E0 of equations for integer arithmetic (not displayed), together
with the equations:
(xb ; yb ); zb = xb ; (yb ; zb ), xb ; yb = yb ; xb , xb ; zt = xb , xt yt = yt xt
stating that Bin is a multiset of Toasts and that the position of the Toasts in
the Pan is irrelevant.
The deduction rules for OS equational logic specify a sound and complete
calculus, i.e., for all Σ-equations l = r, E l = r iff l = r is a logical consequence
of E (written E l = r) [12]; then we write l =E r.
A theory inclusion (Σ, E) ⊆ (Σ , E ) is called protecting iff the unique Σ-
homomorphism TΣ/E −→ TΣ /E |Σ to the Σ-reduct of the initial algebra TΣ /E ,
i.e., the elements of TΣ /E that consist only in function symbols from Σ, is a
Σ-isomorphism, written TΣ/E TΣ /E |Σ .
2.4 Unification
Given an OS equational theory (Σ, E), the E-subsumption preorder E on
TΣ (X ) is defined by t E t if there is a substitution σ such that t =E t σ. For
substitutions σ, ρ and a set of variables V we write ρV E σV , and say that σ
is more general than ρ with respect to V, if there is a substitution η such that
dom(σ) ∩ dom(η) = ∅, ran(ρV ) = ran((ση)V ), and ρV =E (ση)V . When V is not
specified, it is assumed that V = dom(ρ) and ρ =E σ·η. Then σ is said to be
more general than ρ. When E is not specified, it is assumed that E = ∅.
Given an OS equational
n theory (Σ, E), a system of equations F is a conjunc-
tion of Σ-equations i=1 li = ri . An E-unifier for F is a substitution σ such
that li σ =E ri σ, for 1 ≤ i ≤ n.
The symbol ¬ (that can be defined with respect to =, =, ∨, and ∧) will also
appear in this work. All the variables in vars(c) are interpreted as universally
quantified.
n Three particular cases of the general form are admitted: c : l →
r if i=1 li → ri , c : l → r if φ, and the unconditional case c : l → r.
Condition number 2 will be relaxed, but not totally removed, later in this
work. From now on, we will write “rewrite theory” as a shortcut for “conditional
rewrite theory with built-in subtheory and axioms”.
The transitive (resp. transitive and reflexive) closure of the relation →1R ,
∗
inductively defined below, is denoted →+ R (resp. →R ).
We write t −−−→1 t[rσ]p when we need to make explicit the rule, position, and
c,p,σ R
substitution. Any of these items can be omitted when it is irrelevant. We write
t −−→1 v to express that there exists a substitution δ such that t −−−→1 v.
cσ R c,σ·δ R
We write t −−−−→1 v when we need to make explicit the rule, matching term,
c,u,p,σ R/E
position, and substitution. Any of these items can be omitted.
Rewriting modulo is more expressive than rewriting (see example 3.9 in [1]).
4.1 Abstractions
Definition 13 (Abstraction of built-in [19]). If Σ is a signature with built-in
subsignature Σ0 , then an abstraction of built-in is a context C = λx1s1 · · · xnsn .t◦ ,
with n ≥ 0, such that t◦ ∈ TΣ1 (X ) and {x1s1 , . . . , xnsn } = vars(t◦ ) ∩ X0 . For pairs
of terms we write abstract Σ1 ((u, v)) = λ(x̄, ȳ).(u◦ , v ◦ ); (θu◦ , θv◦ ); (φ◦u , φ◦v ).
Lemma 1 shows that there exists an abstraction that provides a canonical
decomposition of any term in TΣ (X ).
Lemma 1 (Existence of a canonical abstraction [19]). Let Σ be a sig-
nature with built-in subsignature Σ0 . For each term t in TΣ (X ) there exist an
abstraction of built-in λx1s1 · · · xnsn .t◦ and a substitution θ◦ : X0 → TΣ0 (X0 ) such
that (i) t = t◦ θ◦ and (ii) dom(θ◦ ) = {x1s1 , . . . , xnsn } are pairwise distinct and
disjoint from vars(t); moreover, (iii) t◦ can always be selected to be S0 -linear
and with {x1s1 , . . . , xnsn } disjoint from an arbitrarily chosen finite subset Y of X0 .
Definition 14 (Abstract function [19]). Given a term t in TΣ (X ) and a
finite subset Y of X0 , define abstract Σ1 (t, Y) as λx1s1 · · · xnsn .t◦ ; θ◦ ; φ◦ where the
context λx1s1 · · · xnsn .t ◦
n and i the substitution θ◦ satisfy the properties (i)-(iii) in
◦ i ◦
Lemma 1 and φ = i=1 (xsi = xsi θ ). If t ∈ TΣ1 (X \X0 ) then abstract Σ1 (t, Y) =
λ.t; none; true. We write abstract Σ1 (t) when Y is the set of all the variables
that have already appeared in the current calculation, so each xisi is a fresh
variable. For pairs of terms we use the compact notation abstract Σ1 ((u, v)) =
λ(x̄, ȳ).(u◦ , v ◦ ); (θu◦ , θv◦ ); (φ◦u , φ◦v ).
Strategies in Conditional Narrowing Modulo SMT Plus Axioms 9
4.2 B-Extensions
The concept of B-extension, together with its properties, has been studied in [13].
Now, we allow for repeated labels in rules; later we will restrict this repetition.
We will use subscripts or apostrophes, e.g. c1 or c , when we need to refer to a
specific rule with label c.
Rewriting modulo does not change if we use a rewrite theory or any of its
associated rewrite theories closed under B-extensions.
Our definition of the relation →1R,B will require the use of a single represen-
tative for all the instances of each E0 -equivalence class that may appear in the
top Σ0 positions of the subterm that we are rewriting.
Definition 19 (Representative of a Σ0 -term over a set of Σ0 terms). Let
t be a term in TΣ0 and let û = {u1 , . . . , un } ⊆ TΣ0 such that t ∈ û. We define
the Σ0 -representative of t over û as rep ◦û (t) = umin({i|ui =E0 t)}) .
Definition 20 (Representative of a term over a set of Σ0 terms). Let t
be a term in TΣ , where top Σ0 (t) = p̂, and let û ⊆ TΣ0 such that t|p̂ ⊆ û. We
define the representative of t over û, as rep û (t) = t[rep ◦û (t|p̄ )]p̄ .
Definition 21 (Representative of a term). Let t be a term in TΣ , where
top Σ0 (t) = p̂. We define the representative of t as rep(t) = rep t|p̂ (t).
The transitive closure of the relation →1R,B , inductively defined below, is
denoted →+R,B . The relation →R,B is defined as →R,B =→R,B ∪ =E .
+
5 Strategies
In this section we present the combinators of a strategy language suitable for
narrowing, which is a subset of the Maude strategy language for rewriting [5,
10,20], a set-theoretic semantics for the language, and an interpretation of this
semantics.
A call strategy is a name given to a strategy to simplify the development of
more complex strategies. A call strategy definition is a user-defined association
of a strategy to one call strategy.
A rewrite theory R = (Σ, E, R) and a set of call strategy definitions for R,
written Call R , have an associated set of derivation rules DR,Call R that will be
defined and used in the following.
Strategies in Conditional Narrowing Modulo SMT Plus Axioms 11
m
If c : l → r if j=1 lj → rj | ψ is a rule in R, m ≥ 0, γ is a substitution, such
that dom(γ) ⊆ vars(c), ST = ST 1 , . . . , ST m is an ordered list of strategies,
and we call RA = c[γ]{ST }, then top(RA) is a strategy in Strat R,Call R . For
each substitution δ : vars(cγ) → TΣ such that E0 ψγδ, there is a derivation
rule l1 γδ→r1 γδ/ST 1 δ···lm γδ→rm γδ/ST m δ
lγδ→rγδ/top(RA) in DR,Call R .
4. Call strategy. Call strategy definitions allow the use of parameters and
the implementation of recursive strategies. We list the semantics for their
invocations, for any pair of terms t and v in HΣ such that ls(t) ≡≤ ls(v):
– If sd CS (x̄) := ST ∈ Call R , where x̄ = x1s1 , . . . , xnsn , n ≥ 0, are the
parameters of CS , t1 , . . . , tn are terms in TΣ (X \VR,Call R ), with sorts
s1 , . . . , sn respectively, and we call t̄ = t1 , . . . , tn , then the call strategy
invocation CS (t̄) is a strategy in Strat R,Call R . If ρ = {x̄ → t̄} then for
every renaming γ such that dom(γ) ∩ \x̂ = ∅ there is a derivation rule
t→v/ST (γ∪ρ)
t→v/CS (t̄) in DR,Call R .
– If csd CS (x̄) m:= ST if C ∈ Call R , where everything is as in the previous
case, C = j=1 (lj = rj ) ∧ φ, m ≥ 0, and δ : vars(C(γ ∪ ρ)) → TΣ is a
substitution such that ¯l(γ ∪ ρ)δ =E r̄(γ ∪ ρ)δ and E0 φ(γ ∪ ρ)δ, then
there is a derivation rule t→v/ST (γ∪ρδ)
t→v/CS (t̄) in DR,Call R .
m
5. Tests. A test strategy TS has the form match u s.t. j=1 (lj = rj ) ∧ φ. It
checks a property on an equivalence class [t]E in HΣ/E . The test returns
{[t]E } if the property holds, else ∅. For each equivalence class [t]E in HΣ/E
and ground substitution δ such that t =E uδ, ¯lδ =E r̄δ, and E0 φδ, there
is a derivation rule t→t/TS in DR,Call R .
6. If-then-else. An if-then-else strategy IS has the form match u s.t. φ ? ST 1 :
ST 2 . It uses the quantifier-free formula φ as test. For each pair of equivalence
classes [t]E and [v]E in HΣ/E and each substitution δ : vars(u)∪vars(φ) → TΣ
such that t =E uδ, if E0 φδ, then t→v/ST t→v/IS
1δ
∈ DR,Call R , and if E0 ¬φδ
then t→v/ST
t→v/IS
2δ
∈ DR,Call R . The restriction to SMT conditions will ensure
the completeness of the narrowing calculus since, in general, a reachability
condition cannot be proved false.
7. Regular expressions. Another way of combining strategies is the use of
regular expressions: ; (concatenation), | (union), and + (iteration). ST ∗ is
defined as idle | ST +. Let ST and ST be strategies, and let t, v and u
be terms in HΣ such that ls(t) ≡≤ ls(u) ≡≤ ls(v). Then, we have rules
t→u/ST 1 u→v/ST 2 t→v/ST 1 t→v/ST 2 t→v/ST t→v/ST ; ST +
t→v/ST 1 ; ST 2 , t→v/ST 1 | ST 2
, t→v/ST 1 | ST 2
, t→v/ST + , and t→v/ST +
in DR,Call R . The scope of this work is restricted to concatenated strategies
that have no variables in common.
8. Rewriting of subterms. The matchrew combinator allows the selection
of a subterm toapply a rule. Matchrew strategies have the form MS =
m
matchrew u s.t. j=1 (lj = rj ) ∧ φ by x1s1 using ST 1 , . . . , xnsn using ST n ,
where x̄ = x1s1 , . . . , xnsn are the match parameters of MS . We will also use
the short-form MS = matchrew u s.t. ¯l = r̄ ∧ φ by x̄ using ST . For each n-
n
tuple (t1 , . . . , tn ) of terms in HΣ such that ls(t̄) ≤ s̄, and each substitution
Strategies in Conditional Narrowing Modulo SMT Plus Axioms 13
We enumerate some of the properties of the semantics for each c.p.t. T formed
using the rules in DR,Call R , with head t → v/ST :
6 Reachability Problems
In this section we present the concept of reachability problem, together with its
solutions and the properties that a solution to one of these problems has. From
now on, we will consider as valid those rewrite theories R = (Σ, E0 ∪ B, R)
whose axioms B are any combination of associativity, commutativity, and
identity (ACU rewrite theories).
Fig. 2. Inference rules for reachability modulo SMT plus B with strategies (excerpt)
Strategies in Conditional Narrowing Modulo SMT Plus Axioms 17
8 Example
In this example, where ct = 20 (cooktime) and ft = 61 (failtime), from an
initial system with an empty toaster, an empty dish, and at most one toast in
the bin, we want to reach a final system where there are three toasts in the dish
and all the remaining elements are empty. We choose Call R to consist of the
following call strategy definitions:
– sd test := match N/B/Y ; V W/OK s.t. Y < ft
– sd cook1 := matchrew N/B/K/OK s.t. K = Y ; RV by K using kitchCook
– sd kitchCook := top(kitchen[none]) ; top(cook[none]{toasts, toasts})
– sd toasts := top(toast1[none]) | top(toast2[none])
– sd noCook := top(bin[none]) | top(pan[none]) | top(dish[none])
– sd loop := (noCook | (cook1 ; test ; noCook))+
– sd solve := top(bag[none]) ; top(bag[none]); (top(bag[none])|idle); loop.
The (symbolic) reachability problem is: P = N / T / 0 ; zt zt / 0 →
0 / zt / Y ; zt zt / 3 / solve | N > 0 ∧ N < 3 | {ct, ft, N, T, Y }, {ct → 20, ft → 61}.
In P we use the strategy solve. As there must be either two or three toasts
in the bag, we impose the application of the rule bag twice, followed by the
nondeterministic strategy top(bag[none]) | idle, and we use the variable T with
sort Toast to represent the bin, since both EmptyToast and RealToast are
subsorts of Toast, subsort of Bin, so T covers both initial cases: the one without
toasts in the bin and the one with one toast in the bin. The concatenation of
the strategy test after each invocation of cook1, comparing the timer against
ft, renders the search state space finite.
Among the answers returned by the prototype we have:
a - ct → 20, ft → 61, N → 3, Y → 60, T → zt,
b - ct → 20, ft → 61, N → 2, Y → 60, T → [0, 0],
c - ct → 20, ft → 61, N → 2, Y → 40, T → [20, 20], and
d - ct → 20, ft → 61, N → 2, Y → 40 + U + V, T → [C, D] such that
C + U = 20 ∧ D + V = 20 ∧ U + V ≤ 20 ∧ U > 0 ∧ V > 0,
stating that we need 60 s when (a) 3 toasts are in the bag or (b) 2 toasts are in
the bag and one fresh toast is in the bin. The required amount of time can be
smaller: (c) 40 s if the toast in the bin is well-cooked or, if it is not, (d) 40 s plus
the remaining toasting time for the toast in the bin, as long as this remaining
time is not above 20 s.
18 L. Aguirre et al.
given new theoretical results on that matter, including the definition of con-
strained variants for order-sorted conditional rewrite theories, but with no spe-
cific support for SMT solvers.
Order-sorted conditional rewriting with constraint solvers has been addressed
by Rocha et al. [19], where the only admitted conditions in the rules are
quantifier-free SMT formulas, and the only non-ground terms admitted in the
reachability problems are those whose variables have sorts belonging to the SMT
sorts supported.
In [14], Meseguer studies reachability in Generalized Rewrite Theories, that
include constructors and variants, using equational theories beyond our setup of
E0 ∪ B (that only asks for strict B-coherence), but with no rewrite conditions
in the rules. Frozenness is used as a type of strategy.
Future work will focus in broadening the applicability of the calculus. One line
of work will involve the development of a narrowing calculus for E0 ∪ (E1 ∪ B)
unification with strategies, where E1 is a non-SMT equational theory; another
line of work will study the extension of the strategies and reachability problems
supported by the calculus.
References
1. Aguirre, L., Martı́-Oliet, N., Palomino, M., Pita, I.: Conditional narrowing mod-
ulo SMT and axioms. In: Vanhoof, W., Pientka, B. (eds.) Proceedings of the
19th International Symposium on Principles and Practice of Declarative Pro-
gramming, Namur, Belgium, 09–11 October 2017, pp. 17–28. ACM (2017).
http://doi.acm.org/10.1145/3131851.3131856
2. Bruni, R., Meseguer, J.: Semantic foundations for generalized rewrite theories.
Theor. Comput. Sci. 360(1-3), 386–414 (2006). http://dx.doi.org/10.1016/j.tcs.
2006.04.012
3. Cholewa, A., Escobar, S., Meseguer, J.: Constrained narrowing for conditional
equational theories modulo axioms. Sci. Comput. Program. 112, 24–57 (2015).
https://doi.org/10.1016/j.scico.2015.06.001
4. Durán, F., et al.: Programming and symbolic computation in Maude. J. Log.
Algebr. Meth. Program. 110, 100497 (2020). https://doi.org/10.1016/j.jlamp.2019.
100497
5. Eker, S., Martı́-Oliet, N., Meseguer, J., Verdejo, A.: Deduction, strategies,
and rewriting. In: Archer, M., de la Tour, T.B., Muñoz, C. (eds.) Proceed-
ings of the 6th International Workshop on Strategies in Automated Deduc-
tion, STRATEGIES 2006, Seattle, WA, USA, 16 August 2006. Electronic Notes
in Theoretical Computer Science, vol. 174, no. 11, pp. 3–25. Elsevier (2007).
http://dx.doi.org/10.1016/j.entcs.2006.03.017
6. Escobar, S., Sasse, R., Meseguer, J.: Folding variant narrowing and opti-
mal variant termination. J. Logic Algebraic Program. 81(7-8), 898–928 (2012).
http://dx.doi.org/10.1016/j.jlap.2012.01.002
7. Fay, M.: First-order unification in an equational theory. In: Proceedings of the 4th
Workshop on Automated Deduction, Austin, pp. 161–167. Academic Press (1979)
8. Giovannetti, E., Moiso, C.: A completeness result for E-unification algorithms
based on conditional narrowing. In: Boscarol, M., Carlucci Aiello, L., Levi, G.
(eds.) Foundations of Logic and Functional Programming. LNCS, vol. 306, pp.
157–167. Springer, Heidelberg (1988). https://doi.org/10.1007/3-540-19129-1 7
20 L. Aguirre et al.
[email protected]
3 University of Illinois at Urbana-Champaign, Urbana, IL, USA
[email protected]
1 Introduction
Maude is a high-performance, concurrent functional language that efficiently imple-
ments Rewriting Logic (RWL), a logic of change that unifies a wide variety of models
of concurrency [38]. Maude is endowed with advanced symbolic reasoning capabilities
that support a high-level, elegant, and efficient approach to programming and analyz-
ing complex, highly nondeterministic software systems [24]. Maude’s symbolic capa-
bilities are based on equational unification and narrowing, a mechanism that extends
term rewriting by replacing pattern matching with unification [49], and they provide
advanced logic programming features such as unification modulo user-definable equa-
tional theories and symbolic reachability analysis in rewrite theories. Intricate comput-
ing problems may be effectively and naturally solved in Maude thanks to the synergy of
This work has been partially supported by the EC H2020-EU grant agreement No.
952215 (TAILOR), grants RTI2018-094403-B-C32 and PID2021-122830OB-C42 funded by
MCIN/AEI/10.13039/501100011033 and by “ERDF A way of making Europe”, by Generali-
tat Valenciana under grant PROMETEO/2019/098, and by the Department Strategic Plan (PSD)
of the University of Udine—Interdepartmental Project on Artificial Intelligence (2021-25).
these recently developed symbolic capabilities and classical Maude features, such as: (i)
rich type structures with sorts (types), subsorts, and overloading; (ii) equational rewrit-
ing modulo various combinations of axioms such as associativity (A), commutativity
(C), and identity (U); and (iii) classical reachability analysis in rewrite theories.
Partial evaluation (PE) is a program transformation technique that automatically
specializes a program to a part of its input that is known statically (at specialization
time) [23, 33]. Partial evaluation conciliates generality with efficiency by providing
automatic program optimization. In the context of logic programming, partial evalu-
ation is often called partial deduction and allows to not only instantiate input variables
with constant values but also with terms that may contain variables, thus providing
extra capabilities for program specialization [35, 36]. Early instances of this framework
implemented partial evaluation algorithms for different narrowing strategies, including
lazy narrowing [12], innermost narrowing [15], and needed narrowing [2, 16].
The Narrowing-driven partial evaluation (NPE) scheme for functional logic pro-
gram specialization defined in [14, 15] and implemented [1] in is strictly more power-
ful than the PE of both logic programs and functional programs thanks to combining
functional reduction with the power of logic variables and unification by means of nar-
rowing. In the Equational narrowing-driven partial evaluation (E Q NPE) scheme of
[7], this enhanced specialization capability was extended to the partial evaluation of
order-sorted equational theories. Given a signature Σ of program operators together
with their type definition, an equational theory E = (Σ, E B) combines a set E of
equations (that are implicitly oriented from left to right and operationally used as sim-
plification rules) on Σ and a set B of commonly occurring axioms (which are implicitly
expressed in Maude as operator attributes using the assoc, comm, and id: keywords)
that are essentially used for B-matching1 . To be executable in Maude, the equational
theory E is required to be convergent (i.e., the equations E are confluent, terminating,
sort-decreasing, and coherent modulo B). This ensures that every input expression t has
one (and only one) canonical form t↓E,B up to B-equality.
This paper addresses the specialization of rewrite theories R = (Σ, E B, R) whose
system transitions are specified by rewrite rules R on top of an underlying equational
theory E = (Σ, E B). Altogether, the rewrite theory R specifies a concurrent sys-
tem that evolves by rewriting states using equational rewriting, i.e., rewriting with the
rewrite rules in R modulo the equations and axioms in E [38]. In Maude, rewrite theo-
ries can also be symbolically executed by narrowing at two levels: (i) narrowing with the
(typically non-confluent and non-terminating) rules of R modulo E = (Σ, E B); and
(ii) narrowing with the (explicitly) oriented equations E modulo the axioms B. They
both have practical applications: (i) narrowing with R modulo E = (Σ, E B) is useful
for solving reachability goals [43] and logical model checking [29]; and (ii) narrow-
ing with E modulo B is useful for E -unification and variant computation [31]. Both
levels of narrowing should meet some conditions: (i) narrowing with R modulo E is
performed in a “topmost” way (i.e., the rules in R rewrite the global system state) and
there must be a finitary equational unification algorithm for E ; and (ii) narrowing with
E modulo B requires that B is a theory with a finitary unification algorithm and that
1 For example, assuming a commutative binary operator ∗, the term s(0) ∗ 0 matches within the
term X ∗ s(Y ) modulo the commutativity of symbol ∗ with matching substitution {X/0,Y /0}.
Optimizing Maude Programs via Program Specialization 23
E is convergent. When (Σ, E B) additionally has the property that a finite complete
set of most general variants2 exists for each term, known as the finite variant property
(FVP), E -unification is finitary and topmost narrowing with R modulo the equations
and axioms can be effectively performed.
For variant computation and (variant-based) E -unification, the folding variant nar-
rowing (or FV-narrowing) strategy of [31] is used in Maude, whose termination is guar-
anteed for theories that satisfy the FVP (also known as finite variant theories). Another
important class of rewrite theories are those that satisfy the so-called constructor finite
variant property (CFVP), i.e., they have a finite number of most general constructor
variants [40]. Many relevant theories have the FVP, including theories of interest for
Boolean satisfiability and theories that give algebraic axiomatizations of cryptographic
functions used in communication protocols, where FVP and CFVP are omnipresent.
CFVP is implied by FVP together with sufficient completeness modulo axioms (SC);
that is, all function calls (i.e., input terms) reduce to values (i.e., ground constructor
terms [27, 32]).
Given the rewrite theory R = (Σ, E B, R), the key idea of our method is to spe-
cialize the underlying equational theory E = (Σ, E B) to the precise use that the rules
of R make of the operators that are defined in E . This is done by partially evaluating
E with respect to the maximal (or outermost) function calls that can be retrieved from
the rules of R, in such a way that E gets rid of any possible over-generality and the
functional computations given by E are thus greatly compacted. Nevertheless, while
the transformation highly contracts the system states, we deliberately avoid making any
states disappear since both reachability analysis and logical model checking generally
require the whole search space of rewrite theories to be searched (i.e., all system states).
Our specialization algorithm follows the classic control strategy of logic specializ-
ers [36], with two separate components: 1) the local control (managed by an unfolding
operator [13]) that avoids infinite evaluations and is responsible for the construction
of the residual equations for each specialized call; and 2) the global control (managed
by an abstraction operator) that avoids infinite iterations of the partial evaluation algo-
rithm and decides which specialized functions appear in the transformed theory. A post-
processing compression transformation is finally performed that highly compacts the
functional computations occurring in the specialized rewrite theory while keeping the
system states as reduced as possible.
We provide three different implementations of the unfolding operator based on FV-
narrowing that may include some distinct extra control depending on the FVP/CFVP
behavior of the equational theory E . More precisely, we distinguish the following three
cases:
1. E does not fulfill the finite variant property: a subsumption check is performed at
each FV-narrowing step that compares the current term with all previous narrowing
redexes in the same derivation. The subsumption checking relies on the order-sorted
equational homeomorphic embedding relation of [8] that ensures all infinite FV-
narrowing computations are safely stopped;
2 A variant [22] of a term t in the theory E is the canonical (i.e., irreducible) form of t σ in E
for a given substitution σ ; in symbols, it is represented as the pair (t σ ↓E,B , σ ).
24 M. Alpuente et al.
2. E satisfies the finite variant property: FV-narrowing trees are always finite for any
input term, and therefore they are completely deployed; and
3. E satisfies the finite variant property and is also sufficiently complete: we supple-
ment unfolding with an extra “sort downgrading” transformation in the style of [41]
that safely rules out variants that are not constructor terms. This means that all
specialized calls get totally evaluated and the maximum compression is achieved,
thereby dramatically reducing the search space for the construction of the special-
ized theories.
It is worth noting that our specialization system is based on the Maude’s narrowing
engine and, hence, it respects the limitations and applicability conditions of the cur-
rent narrowing implementation. In particular, Maude’s narrowing (and thus our special-
izer) does not support conditional equations, built-in operators and special equational
attributes (e.g., owise). However, advances in narrowing and unification for Maude will
enlarge the class of rewrite theories that our specialization technique handles.
It is a great pleasure for us to honor Manuel Hermenegildo in this Festschrift.
Many of the themes and techniques we present—beginning with partial evaluation, and
including as well the solving of constraints in user-definable algebraic domains—are
themes to which Manuel and his collaborators have made outstanding contributions.
More broadly, we share also with him the passion for logically-based programming
language design, so as to integrate within a solid mathematical framework various pro-
gramming paradigms. Science is, should be, a dialogue. We look forward to continue
the pleasure of such a dialogue with Manuel—which some of us initiated with him
decades ago—and to his new outstanding contributions in the years to come.
Plan of the Paper. In Sect. 2, we introduce a leading example that illustrates the opti-
mization of rewrite theories that we can achieve by using our specialization technique,
which we formalize in Sect. 3. In Sect. 4, we focus on finite variant theories that are suf-
ficiently complete and we demonstrate that both properties, SC and FVP, are preserved
by our transformation scheme. In Sect. 5, we instantiate the specialization scheme for
the three classes of equational theories already mentioned: theories whose terms may
have an infinite number of most general variants, or a finite number of most general
variants, or a finite number of most general constructor variants. The proposed method-
ology is illustrated in Sect. 6 by describing several specializations of the bank account
specification of Sect. 2 and by presenting some experiments with the partial evaluator
Presto that implements our technique. In Sect. 7, we discuss some related work and we
conclude. The complete code of a non-trivial specialization example together with its
computed optimizations are given in Appendix.
2 A Leading Example
Let us motivate the power of our specialization scheme by optimizing a simple rewrite
theory that is inspired by [41]. The considered example has been engineered to ful-
fill the conditions for the applicability of all the three instances of our specialization
framework.
Optimizing Maude Programs via Program Specialization 25
Example 1. Consider a rewrite theory that specifies a bank account system with man-
aged accounts. The system automates a simple investment model for the beginner
investor that, whenever the account balance exceeds a given investment threshold, the
excess balance is automatically moved to investment funds. The system allows deposits
and withdrawals to occur non-deterministically, where each withdrawal occurs in two
steps: the withdrawal is initiated through a withdrawal request provided that the amount
to be withdrawn is less than or equal to the current account balance. Later on, the actual
withdrawal is completed. On the contrary, deposits are single-step operations that need
to consume explicit deposit messages to be performed. This asymmetric behaviour is
due to the fact that the amount in a deposit operation is unbounded, while a withdrawal
request is always limited by the account balance. For simplicity, the external operation
of the investment portfolio is not considered in the model.
A managed account is modelled as a term
< bal: n pend: x overdraft: b threshold: h funds: f >
where n is the current balance, x is the amount of money that is currently pending to
be withdrawn, b is a Boolean flag that indicates whether or not the account is in the red,
h is a fixed upper threshold for the account balance, and funds represents the amount
to be invested by the account manager. Messages of the form d(m) and w(m) specify
deposit and withdrawal operations, where m is the amount of money to be, respectively,
deposited and withdrawn. A bank account state (or simply state) is a pair act # msgs,
where act is an account and msgs a multiset of messages. Monetary values in a state are
specified by natural numbers in Presburger’s style3 . State transitions are formalized by
the three rewrite rules in Fig. 1 (namely, w-req, w, and dep) that respectively implement
withdrawal requests, (actual) withdrawals, and deposits.
The intended semantics of the three rules is as follows. The rule w-req non-
deterministically requests to draw money whenever the account balance covers the
request. The requested amount m is added to the amount of pending withdraw requests
and the withdraw message w(m) is generated. The rule w implements actual withdrawal
of money from the account. When the balance is not enough, the account is blocked by
3 In [40], natural numbers are encoded by using two constants 0 and 1 and an ACU operator +
so that a natural number is either the constant 0 or a finite sequence 1 + 1 ... + 1.
26 M. Alpuente et al.
setting overdraft to true and the withdrawal attempt fails (for simplicity, the excess
of balance that is moved to investment funds is never moved back). If not in overdraft,
money can be deposited in the account by processing the deposit message d(m) using
rule dep.
The auxiliary functions that are used by the three rules implement the pre-agreed,
automated investment policy for a given threshold. They update the account’s state by
means of an equational theory whose operators and equations are shown in Fig. 2. The
equational theory extends Presburger’s arithmetic with the operators over natural num-
bers _>_ and _-_, together with the if-then-construct [_, _, _] and an auxiliary version
«...» of the operator <...> that ensures that the current balance n is below the current
threshold h; otherwise, it sets the balance to n mod h and increments the funds by n
div h, where div is the division for natural numbers and mod is the remainder of the
division; both operations are encoded by successive subtractions. Roughly speaking,
this operator allows money to be moved from the bal attribute to the funds attribute,
whenever the balance exceeds the threshold h. Note that the amount of money in the
investment funds is measured in h units (1, 2, . . . ), which indicate the client’s wealth
category (the higher the category, the greater the investment advantages). The attribute
variant is used to identify the equations to be considered by the FV-narrowing strat-
egy.
The considered equational theory has neither the FVP nor the CFVP since, for
instance, the term « bal: n pend: x overdraft:false threshold: h funds: f »
has an infinite number of (incomparable) most general (constructor) variants
»J’ai besoin de vous, vous êtes mon seul refuge, ne me manquez pas,
tout me manqueroit. Souvenez-vous avec plaisir de cette pauvre Debby,
votre fille, comme vous l’appeliez et comme vous l’aimiez, dont les petits
bras s’enlacèrent tant de fois à votre col, et que vous berçâtes tant de fois
dans votre grande robe noire. Vous m’avez connue au berceau, vous
m’avez chérie dès mon enfance; chérissez-moi toujours, chérissez-moi au
moins encore une fois, je vous en prie au nom de ma malheureuse mère,
je vous en prie au nom de son père, mon ayeul, qui vous portoit tant
d’amitié. Il m’a placée sous votre protection, il m’a faite votre pupille, il
vous a confié ma défense et mes biens, sauvez-moi, vous êtes maître de
ma fortune et de ma vie.
» Lorsque je quittai l’Irlande, il y a dix mois environ, je vous adressai
un mémoire de tout ce qui venoit de se passer dans ma famille, et des
motifs qui me forçoient à m’expatrier; ce mémoire étoit triste, ce mémoire
étoit déchirant, votre cœur bon en a été très-affecté sans doute; je vous
demande pardon du chagrin que je vous ai fait. Je croyois que l’exil alloit
mettre fin à mes souffrances, et me donner le bonheur dont mon âme
étoit avide, parce quelle avoit avec qui le partager. Je croyois trouver en
France liberté et hospitalité!... Hélas! jamais déception fut-elle plus grande
que la mienne! Que n’allai-je plutôt me jeter dans le désert de Barca!...
Vous trouverez ci-inclus un nouveau mémoire, exact et vrai, de tout ce qui
m’est advenu depuis ma fuite sur le Continent. Le premier étoit déchirant,
celui-ci est affreux! Si votre cœur répugne aux tableaux sombres, si
l’injustice vous fait mal, prenez-le, lacérez-le, jetez-le au feu.... Alors qu’il
vous suffise de savoir qu’aujourd’hui je suis emprisonnée dans une bastille
d’État, d’où je ne dois plus sortir que sur l’épaule d’un fossoyeur. Mais
avec votre secours et votre aide, cela ne sera pas. J’ai longuement mûri
des projets d’évasion, voici le plus sûr et le plus simple, auquel je
m’arrête. Il coûtera sans doute des sommes considérables; allez, que ceci
ne vous ralentisse point, Dieu merci, j’ai assez de richesses, et depuis trois
jours je suis majeure.