Matching logic is a family of formal systems that were created mainly to specify and reason about computer programs and their correctness. Compared to classical logics such as first-order logic, matching logic's formulas, called patterns, are interpreted as, not elements, but power sets of the underlying carrier set(s), with the intuition that a pattern is matched by the set of elements that "match" it. This way, matching logic is said to admit a semantics based on pattern matching.
Matching logic was initially coined by Grigore Rosu and finalized with Xiaohong Chen in 2019.[1] Matching logic is the logical foundation of the K framework.[2]
History
Early development
The term "matching logic" was coined in 2009.[3] and has been used to refer to a couple of formal systems since then. In the early days, matching logic was represented in the literature as a formal system to specify and reason about computer programs' configurations. Together with a set of rules, it was used to specify and reason about the dynamic behaviors of computer programs.
The latter was later developed into reachability logic, which is a language-agnostic formal system with a fixed number of rules that provides sound and relatively complete formal verification capability for all programming languages. In these works of literature, matching logic is presented as an independent component of reachability logic.
Formalization as a standalone logic
The first paper that establishes matching logic as a standalone formal logic was published in 2017.[4] There, matching logic was given an independent definition of its syntax, semantics, and proof system for the first time. In 2019, fixpoint constructors and proof rules were added to matching logic.[5]
More recently, researchers have shown increasing interest in simplifying matching logic to a bare minimum.[6] They aim to keep its expressive power intact during this process. All these formalizations exist in today's literature and sometimes appear under the same name "matching logic''.
Variants
We list them below in the chronological order:
"Matching logic”, which is a many-sorted logic but has no fixpoint operators.[4]
"Matching -logic", which extends the LMCS’17 formalization with fixpoint operators and proof rules.[5]
"Applicative matching logic", which is a restricted fragment that requires the signatures to include only one sort and only one non-constant symbol that is a binary symbol.[6]
Since then, the term "matching logic" has been used to refer to any of the above formalizations in the literature. To avoid confusion, we shall present the formalization of the most complete version, matching -logic. Then, we will present the other formalizations as variants.
Formal definition
Matching -logic is defined through its syntax and semantics, which are detailed below.
Syntax
The syntax of matching logic specifies how patterns are constructed using variables, symbols, and logical connectives.
Signatures and variables
Matching logic is parametric on a many-sorted signature that has a set of sorts and an -indexed set of many-sorted symbols, or simply symbols. A symbol means that it takes arguments of sorts , ..., , respectively, and returns a value of sort .
Let be a many-sorted signature. Let and be two disjoint families of -indexed sets of variables. We call elements in element variables, denoted , , ... and elements in set variables, denoted , , ...
Patterns
Matching logic formulas are called patterns. The set of -patterns, or simply patterns, is an -indexed set . We write or to denote a pattern of a sort . The set of all patterns is inductively defined by the following grammar rules:
.
.
for any .
.
.
. Note that and need not be the same.
if is positive in .
Here, is positive in if every occurrence of lies within an even number of implication left-hand sides. For example, is positive in but not in . In contrast, is positive in but not in .
Common notations
Notations can be defined in the usual way. The following are some standard notations:
Here, is the result of substituting every occurrence of for its negation . One can verify that is well-formed if is positive in .
Semantics
The semantics of matching logic defines how patterns are interpreted over models and valuations.
Interpretation of patterns
Matching logic formulas, called patterns, are interpreted not as true/false values, but as sets. Intuitively, a matching logic pattern is interpreted as the set of elements that “match” it.
Let be a signature. An -model, or simply a model, is denoted . It consists of:
A nonempty carrier set for every .
A function for every .
Here, denotes the power set of .
A valuation maps every element variable of sort to an element in . It also maps every set element of sort to a subset of . That is, and . Given a model and a valuation , the interpretation of a pattern is . This interpretation is inductively defined in the following way:
The fixpoint-free fragment of matching logic can be converted to first-order logic with equality. This conversion allows the K Framework to use existing Satisfiability modulo theories (SMT) solvers. These solvers help to find proofs for theorems.