





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






































Jos´ e Meseguer Computer Science Department University of Illinois at Urbana-Champaign
Equational Theories Theories in equational logic are called equational theories . In Computer Science they are sometimes referred to as algebraic specifications . An equational theory is a pair
, where:
, called the signature , describes the syntax of the theory, that is, what types of data and what operation symbols (function symbols) are involved;
is a set of equations between expressions (called terms ) in the syntax of
. 2
Maude Functional Modules Maude functional modules are equational theories
, declared with syntax fmod
endfm Such theories can be unsorted, many-sorted, ororder-sorted, or even more general membership equational theories (to be discussed later in the course).In what follows we will see examples of unsorted,many-sorted and order-sorted equational theories
expressed as Maude functional modules, and of how onecan use such theories as functional programs by computing with the equations
.
Unsorted Functional Modules *** prefix syntaxfmod NAT-PREFIX is sort Natural .op 0 : -> Natural .op s : Natural -> Natural .op plus : Natural Natural -> Natural .vars N M : Natural .eq plus(N,0) = N .eq plus(N,s(M)) = s(plus(N,M)). endfmMaude> red plus(s(s(0)),s(s(0))) .reduce in NAT-PREFIX : plus(s(s(0)), s(s(0))) .rewrites: 3 in -10ms cpu (0ms real) (~ rewrites/second)result Natural: s(s(s(s(0))))Maude>
Many-Sorted Functional Modules fmod NAT-LIST is protecting NAT-MIXFIX .sort List .op nil : -> List .op . : Natural List -> List .op length : List -> Natural .var N : Natural .var L : List .eq length(nil) = 0 .eq length(N. L) = s length(L). endfmMaude> red length(0. (s 0. (s s 0. (0. nil)))) .reduce in NAT-LIST : length(0. s 0. s s 0. 0. nil) .rewrites: 5 in 0ms cpu (0ms real) (~ rewrites/second)result Natural: s s s s 0Maude>
Many-Sorted Signatures The full signature
of the
example, that imports NAT-MIXFIX , is then, sorts Natural List .op 0 : -> Natural .op s_ : Natural -> Natural .op + : Natural Natural -> Natural .op * : Natural Natural -> Natural .op nil : -> List .op . : Natural List -> List .op length : List -> Natural.
Labeled Graphs Mathematically Any mathematical structure, including graphs, can bedescribed precisely in the language of elementary set theory.As a warmup exercise, we can do that first for labeledgraphs, and then for multigraphs.Note that many-sorted signatures consiting only of unary operations are exactly the same thing as labeled graphs (see the example in Picture 2.2)
Labeled Graphs Mathematically (II) We can define precisely a labeled directed graph
in set theory as a pair
s,s ′^
( s,s ′^ ) ∈ S × S
, where:
is a set, whose elements are called nodes
for each pair of nodes
s, s
,
s,s ′^ is the set of labels for edges with input s and output s ′ . In the Example of Picture 2.2 we have: S
Natural
Boolean
,
Natural ,Natural
s
, Σ Natural ,Boolean
odd
even
,
Boolean ,Boolean
not
.
Indexed Families of Sets (II) More precisely, given a set
, an
indexed family of sets is just a function
from
to a set of sets
, typically called a universe
. It is well known (Russell’s paradox) that there is no such thingas “the set of all sets,” but if we put restrictions on the size of the sets allowed as elements, there are many legitimatesets
that can be used as universes. Then, for the function
we use the notation X
i
i ∈ I , where, by definition,
i
i
. 13
Indexed Families of Sets (III) The needed universe (set of sets)
does not have to be very big. For example, for the indexed family
n
n ∈ IN
, and then we can view the indexed set as a function,
Similarly, since
∗ is the set of bit vectors of arbitrary length, the indexed family
n
n ∈ IN
∗
In general, we can always view
i
i ∈ I as the function, X
i^
i
.
Many-Sorted Signatures Mathematically (II) In full detail, the signature
in our
example has: set of sorts
Natural
List
, and indexed family of sets of operation symbols: Σ nil, Natural
,
nil, List
nil
, Σ Natural ,Natural
s
, Σ Natural Natural ,Natural
, Σ Natural List ,List
,
List ,Natural
length
, and all other
w,s
. Similarly, the signature
in our
example has: S
Natural
,
nil, Natural
,
Natural ,Natural
s
, Σ Natural Natural ,Natural
plus
, and all other Σ w, Natural
. 16
The Need for Order-Sorted Signatures Many-sorted signatures are still too restrictive
. The problem is that some operations are partial , and there is no natural way of defining them in just a many-sorted framework.Consider for example defining a function first that takes the first element of a list of natural numbers, or apredecessor function p that assigns to each natural number its predecessor. What can we do? If we define, op first : List -> Natural .op p_ : Natural -> Natural. we have then the awkward problem of defining the values of first(nil) and of p 0 , which in fact are undefined .
Order-Sorted Functional Modules fmod NATURAL is sorts Natural NzNatural .subsorts NzNatural < Natural .op 0 : -> Natural .op s_ : Natural -> NzNatural .op p_ : NzNatural -> Natural .op + : Natural Natural -> Natural .op + : NzNatural NzNatural -> NzNatural .vars N M : Natural .eq p s N = N .eq N + 0 = N .eq N + s M = s(N + M). endfmMaude> red p((s s 0) + (s s 0)) .reduce in NATURAL : p (s s 0 + s s 0) .rewrites: 4 in 0ms cpu (0ms real) (~ rewrites/second)result NzNatural: s s s 0
Order-Sorted Functional Modules (II) fmod NAT-LIST-II is protecting NATURAL .sorts NeList List .subsorts NeList < List .op nil : -> List .op . : Natural List -> NeList .op length : List -> Natural .op first : NeList -> Natural .op rest : NeList -> List .var N : Natural .var L : List .eq length(nil) = 0 .eq length(N. L) = s length(L) .eq first(N. L) = N .eq rest(N. L) = L. endfm