Algebraic semantics (computer science) explained

In computer science, algebraic semantics is a form of axiomatic semantics based on algebraic laws for describing and reasoning about program specifications in a formal manner.[1] [2] [3] [4]

Syntax

The syntax of an algebraic specification is formulated in two steps: (1) defining a formal signature of data types and operation symbols, and (2) interpreting the signature through sets and functions.

Definition of a signature

The signature of an algebraic specification defines its formal syntax. The word "signature" is used like the concept of "key signature" in musical notation.

S

of data types, known as sorts, together with a family

\Sigma

of sets, each set containing operation symbols (or simply symbols) that relate the sorts.We use
\Sigma
s1s2...sn,~s
to denote the set of operation symbols relating the sorts

s1,~s2,~...,~sn\inS

to the sort

s\inS

.

For example, for the signature of integer stacks, we define two sorts, namely,

int

and

stack

, and the following family of operation symbols:

\begin{align} \SigmaΛ,~stack&=\{{\rmnew}\}\\ \Sigmaint~stack,~stack&=\{{\rmpush}\}\\Sigmastack,~stack&=\{{\rmpop}\}\\ \Sigmastack,~int&=\{{\rmdepth},{\rmtop}\}\\ \end{align}

where

Λ

denotes the empty string.

Set-theoretic interpretation of signature

A

interprets the sorts and operation symbols as sets and functions.Each sort

s

is interpreted as a set

As

, which is called the carrier of

A

of sort

s

, and each symbol

\sigma

in
\Sigma
s1s2...sn,~s
is mapped to a function

\sigmaA:

A
s1

x

A
s2

x ~...

x ~A
sn
, which is called an operation of

A

.

With respect to the signature of integer stacks, we interpret the sort

int

as the set

\Z

of integers, and interpret the sort

stack

as the set

Stack

of integer stacks. We further interpret the family of operation symbols as the following functions:

\begin{align} {\rmnew}&:~\toStack\\ {\rmpush}&:~\Z x Stack\toStack\\ {\rmpop}&:~Stack\toStack\\ {\rmdepth}&:~Stack\to\Z\\ {\rmtop}&:~Stack\to\Z\\ \end{align}

Semantics

Semantics refers to the meaning or behavior. An algebraic specification provides both the meaning and behavior of the object in question.

Equational axioms

The semantics of an algebraic specifications is defined by axioms in the form of conditional equations.[1]

With respect to the signature of integer stacks, we have the following axioms:

For any

z\in\Z

and

s\inStack

,

\begin{align} &A1:~~{\rmpop}({\rmpush}(z,s))=s\\ &A2:~~{\rmdepth}({\rmpush}(z,s))={\rmdepth}(s)+1\\ &A3:~~{\rmtop}({\rmpush}(z,s))=z\\ &A4:~~{\rmpop}({\rmnew})={\rmnew}\\ &A5:~~{\rmdepth}({\rmnew})=0\\ &A6:~~{\rmtop}(s)=-404~{\rmif~depth}(s)=0\\ \end{align}

where "

-404

" indicates "not found".

Mathematical semantics

The mathematical semantics (also known as denotational semantics)[5] of a specification refers to its mathematical meaning.

The mathematical semantics of an algebraic specification is the class of all algebras that satisfy the specification.In particular, the classic approach by Goguen et al.[1] [2] takes the initial algebra (unique up to isomorphism) as the "most representative" model of the algebraic specification.

Operational semantics

The operational semantics[6] of a specification means how to interpret it as a sequence of computational steps.

We define a ground term as an algebraic expression without variables. The operational semantics of an algebraic specification refers to how ground terms can be transformed using the given equational axioms as left-to-right rewrite rules, until such terms reach their normal forms, where no more rewriting is possible.

Consider the axioms for integer stacks. Let "

\Rrightarrow

" denote "rewrites to".

\begin{align} &{\rmtop}({\rmpop}({\rmpop}({\rmpush}(1,~{\rmpush}(2,~{\rmpush}(3,~{\rmpop}({\rmnew}))))))) &\\ \Rrightarrow~ &{\rmtop}({\rmpop}({\rmpop}({\rmpush}(1,~{\rmpush}(2,~{\rmpush}(3,~{\rmnew})))))) &({\rmby~Axiom~}A4)\\ \Rrightarrow~ &{\rmtop}({\rmpop}({\rmpush}(2,~{\rmpush}(3,~{\rmnew})))) &({\rmby~Axiom~}A1)\\ \Rrightarrow~ &{\rmtop}({\rmpush}(3,~{\rmnew})) &({\rmby~Axiom~}A1)\\ \Rrightarrow~ &3 &({\rmby~Axiom~}A3)\\ \end{align}

Canonical property

An algebraic specification is said to be confluent (also known as Church-Rosser) if the rewriting of any ground term leads to the same normal form. It is said to be terminating if the rewriting of any ground term will lead to a normal form after a finite number of steps. The algebraic specification is said to be canonical (also known as convergent) if it is both confluent and terminating. In other words, it is canonical if the rewriting of any ground term leads to a unique normal form after a finite number of steps.

Given any canonical algebraic specification, the mathematical semantics agrees with the operational semantics.[7]

As a result, canonical algebraic specifications have been widely applied to address program correctness issues. For example, numerous researchers have applied such specifications to the testing of observational equivalence of objects in object-oriented programming. See Chen and Tse[8] as a secondary source that provides a historical review of prominent research from 1981 to 2013.

See also

Notes and References

  1. Initial algebra semantics and continuous algebras . J.A. Goguen . J.W. Thatcher . E.G. Wagner . J.B. Wright . . 24 . 1 . 1977 . 68–95 . 10.1145/321992.321997. 11060837 . free .
  2. Book: J.A. Goguen . Joseph Goguen . J.W. Thatcher. E.G. Wagner . An initial algebra approach to the specification, correctness and implementation of abstract data types . Current Trends in Programming Methodology, Vol. IV: Data Structuring . R.T. Yeh . 80–149 . . 1978.
  3. Book: J.A. Goguen . Joseph Goguen . C. Kirchner . H. Kirchner . A. Megrelis . J. Meseguer . An introduction to OBJ3 . Proceedings of the First Workshop on Conditional Term Rewriting Systems . Lecture Notes in Computer Science . 258–263 . . 1988 . 308 . https://link.springer.com/chapter/10.1007/3-540-19242-5_22 . 10.1007/3-540-19242-5_22. 978-3-540-19242-8 .
  4. Book: J.A. Goguen . Joseph Goguen . G. Malcolm. Algebraic Semantics of Imperative Programs. 1996. MIT Press. 9780262071727 .
  5. Book: David A. Schmidt . Denotational Semantics: A Methodology for Language Development . William C. Brown Publishers . 1986 . 9780205104505.
  6. . A structural approach to operational semantics . Technical Report DAIMI FN-19 . . 1981.
  7. Book: S. Lucas . J. Meseguer . Rewriting Logic and Its Applications . Strong and Weak Operational Termination of Order-Sorted Rewrite Theories . Lecture Notes in Computer Science . S. Escobar . 178–194 . . Cham . 2014 . 8663 . 10.1007/978-3-319-12904-4_10 . 978-3-319-12903-7 .
  8. H.Y. Chen . T.H. Tse . Equality to equals and unequals: A revisit of the equivalence and nonequivalence criteria in class-level testing of object-oriented software . . 39 . 11 . 1549–1563 . 2013 . 10.1109/TSE.2013.33 . 10722/187124 . 8694513 . free .