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.
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.
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:






![{\displaystyle \nu X:s\cdot \varphi _{s}\equiv \neg \mu X:s\cdot \neg \varphi _{s}[\neg X:s/X:s]}](./1e2c4a80616f19810ae2f52f22fbdeba486e6eb6.svg)
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 empty set.
, where “
” denotes set difference.
, where
is the valuation that is identical to
except that it maps to
to
.
![{\displaystyle \mathrm {} \left\vert \mu X:s\cdot \varphi _{s}\right\vert _{M,\rho }=\bigcap \{{A\subseteq M_{s}\mid \mathrm {\left\vert \varphi _{s}\right\vert } _{M,\rho [A/X:s]}\subseteq A}\}}](./2e238794eb4a8ab618add94d2f4256ce3b507cdc.svg)
Fixpoints and properties
By the Knaster-Tarski Fixpoint Theorem,
is the least fixpoint of the function that maps
to
.
The following properties hold for common notations:




, where “
” denotes the symmetric difference operator.
![{\displaystyle \mathrm {} \left\vert \forall x:s'\cdot \varphi _{s}\right\vert _{M,\rho }=\bigcap _{a\in M_{s'}}\mathrm {\left\vert \varphi _{s}\right\vert } _{M,\rho [a/x:s']}}](./f2fbc416562c3512c55b9df20a88c0b5c114d717.svg)
![{\displaystyle \mathrm {} \left\vert \nu X:s\cdot \varphi _{s}\right\vert _{M,\rho }=\bigcup \{{A\subseteq M_{s}\mid A\subseteq \mathrm {\left\vert \varphi _{s}\right\vert } _{M,\rho [A/X:s]}\subseteq A}\}}](./b3750de4e9968da135f4214f6bc10d4d7276060a.svg)
Applications
Matching logic is used with reachability logic[7] by the K Framework to specify operational semantics and use them directly for formal verification, which forms an alternative approach to Hoare logic.
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.
See also
References
- ^ Chen, Xiaohong; Roșu, Grigore (2019-01-19). "Matching μ-Logic". University of Illinois Research and Tech Reports (Computer Science).
- ^ Roșu, Grigore; Florin Șerbănută, Traian (August 2010). "An overview of the K semantic framework". The Journal of Logic and Algebraic Programming. 79 (6): 397–434.
- ^ Rosu, Grigore; Schulte, Wolfram (2009). "Matching Logic - Extended Report". University of Illinois Urbana-Champaign.
- ^ a b Rosu, Grigore (2017-12-20). "Matching Logic". Logical Methods in Computer Science. 13 (4). arXiv:1705.06312. doi:10.23638/LMCS-13(4:28)2017. ISSN 1860-5974.
- ^ a b Chen, Xiaohong; Roşu, Grigore (2021-06-08). "Matching μ-logic". Proceedings of the 34th Annual ACM/IEEE Symposium on Logic in Computer Science. LICS '19. Vancouver, Canada: IEEE Press: 1–13.
- ^ a b Chen, Xiaohong; Lucanu, Dorel; Roşu, Grigore (2021-04-01). "Matching logic explained". Journal of Logical and Algebraic Methods in Programming. 120: 100638. doi:10.1016/j.jlamp.2021.100638. hdl:2142/107794. ISSN 2352-2208.
- ^ Roșu, Grigore; ̧Ștefănescu, Andrei; Ciobâcă, Ștefan; Moore, Brandon M. (2012). "Reachability Logic". University of Illinois Technical Report.