Philosophy:Matching logic

From HandWiki

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:

  1. "Matching logic", which is a many-sorted logic but has no fixpoint operators.[4]
  2. "Matching μ-logic", which extends the LMCS'17 formalization with fixpoint operators and proof rules.[5]
  3. "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 (S,Σ) that has a set S of sorts and an (S*×S)-indexed set Σ of many-sorted symbols, or simply symbols. A symbol σΣs1sn,s means that it takes n arguments of sorts s1, ..., sn, respectively, and returns a value of sort s.

Let (S,Σ) be a many-sorted signature. Let EV={EVs}sS and SV={SVs}sS be two disjoint families of S-indexed sets of variables. We call elements in EV element variables, denoted x:s, y:s, ... and elements in SV set variables, denoted X:s, Y:s, ...

Patterns

Matching logic formulas are called patterns. The set of (S,Σ)-patterns, or simply patterns, is an S-indexed set Pattern={Patterns}sS. We write φsPattern or φPatterns to denote a pattern of a sort s. The set of all patterns is inductively defined by the following grammar rules:

  • x:sPatterns.
  • X:sPatterns.
  • σ(φs1,,φsn)Patterns for any σΣs1sn,s.
  • sPatterns.
  • φsφ'sPatterns.
  • x:sφsPatterns. Note that s and s need not be the same.
  • μX:sφsPatterns if φs is positive in X:s.

Here, φs is positive in X:s if every occurrence of X:s lies within an even number of implication left-hand sides. For example, X:sY:s is positive in Y:s but not in X:s. In contrast, (X:sY:s)X:s is positive in X:s but not in Y:s.

Common notations

Notations can be defined in the usual way. The following are some standard notations:

  • ¬φsφss
  • s¬s
  • φsφ's¬φsφ's
  • φsφ's¬(¬φs¬φ's)
  • φsφs(φsφ's)(φsφ's)
  • x:sφs¬x:s¬φs
  • νX:sφs¬μX:s¬φs[¬X:s/X:s]

Here, φs[¬X:s/X:s] is the result of substituting every occurrence of X:s for its negation ¬X:s. One can verify that νX:sφs is well-formed if φs is positive in X:s.

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 (S,Σ) be a signature. An (S,Σ)-model, or simply a model, is denoted M=({Ms}sS,{σM}σΣ). It consists of:

  • A nonempty carrier set Ms for every sS.
  • A function σM:Ms1××Msn𝒫(Ms) for every σΣs1sn,s.

Here, 𝒫(Ms) denotes the power set of Ms.

A valuation ρ maps every element variable of sort s to an element in Ms. It also maps every set element of sort s to a subset of Ms. That is, ρ(x:s)Ms and ρ(X:s)Ms. Given a model M and a valuation ρ, the interpretation of a pattern is |φs|M,ρMs. This interpretation is inductively defined in the following way:

  • |x:s|M,ρ={ρ(x:s)}
  • |X:s|M,ρ=ρ(X:s)
  • |σ(φs1,,φsn)|M,ρ=a1|φs1|M,ρan|φsn|M,ρσM(a1,,an)
  • |x|M,ρ=, the empty set.
  • |φsφ's|M,ρ=Ms(|φs|M,ρ|φ's|M,ρ), where "" denotes set difference.
  • |x:sφs|M,ρ=aMs|φs|M,ρ[a/x:s], where ρ[a/x:s] is the valuation that is identical to ρ except that it maps to x:s to a.
  • |μX:sφs|M,ρ={AMs|φs|M,ρ[A/X:s]A}

Fixpoints and properties

By the Knaster-Tarski Fixpoint Theorem, μX:sφs is the least fixpoint of the function that maps AMs to |φs|M,ρ[A/X:s].

The following properties hold for common notations:

  • |¬φs|M,ρ=Ms|φs|M,ρ
  • |s|M,ρ=Ms
  • |φsφ's|M,ρ=|φs|M,ρ|φ's|M,ρ
  • |φsφ's|M,ρ=|φs|M,ρ|φ's|M,ρ
  • |φsφ's|M,ρ=Ms(|φs|M,ρΔ|φ's|M,ρ), where "Δ" denotes the symmetric difference operator.
  • |x:sφs|M,ρ=aMs|φs|M,ρ[a/x:s]
  • |νX:sφs|M,ρ={AMsA|φs|M,ρ[A/X:s]A}

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

  1. Chen, Xiaohong; Roșu, Grigore (2019-01-19). "Matching μ-Logic". University of Illinois Research and Tech Reports (Computer Science). https://dl.acm.org/doi/10.5555/3470152.3470173. 
  2. 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. https://www.sciencedirect.com/science/article/pii/S1567832610000160. 
  3. Rosu, Grigore; Schulte, Wolfram (2009). "Matching Logic - Extended Report". University of Illinois Urbana-Champaign. https://www.ideals.illinois.edu/items/10794. 
  4. 4.0 4.1 Rosu, Grigore (2017-12-20). "Matching Logic". Logical Methods in Computer Science 13 (4). doi:10.23638/LMCS-13(4:28)2017. ISSN 1860-5974. https://lmcs.episciences.org/4153. 
  5. 5.0 5.1 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. https://dl.acm.org/doi/10.5555/3470152.3470173. 
  6. 6.0 6.1 Chen, Xiaohong; Lucanu, Dorel; Roşu, Grigore (2021-04-01). "Matching logic explained". Journal of Logical and Algebraic Methods in Programming 120. doi:10.1016/j.jlamp.2021.100638. ISSN 2352-2208. https://www.sciencedirect.com/science/article/abs/pii/S2352220821000018. 
  7. Roșu, Grigore; ̧Ștefănescu, Andrei; Ciobâcă, Ștefan; Moore, Brandon M. (2012). "Reachability Logic". University of Illinois Technical Report. https://fsl.cs.illinois.edu/publications/rosu-stefanescu-ciobaca-moore-2012-tr.html.