Manuscript Offprint
arXiv:2609.07345Monadic Second-Order Logic in HOL: Deep and Shallow with Automated Faithfulness (Extended Preprint)
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Christoph Benzmüller¹,² [0000-0002-3392-3093]★ and Daniel Kirchner¹ [0000-0001-9229-1148]
¹ University of Bamberg, Bamberg, Germany christoph.benzmueller@uni-bamberg.de, daniel.kirchner@uni-bamberg.de ² Freie Universität Berlin, Berlin, Germany
Abstract. In Isabelle/HOL, we apply the deep-and-shallow embedding methodology of our prior work to monadic second-order logic (MSO). Three embeddings are developed side by side: a deep embedding (an inductive datatype with an explicit satisfaction relation); a maximal-shallow embedding that translates the connectives and quantifiers directly into HOL, carrying the interpretation and both assignments as explicit arguments; and a minimal-shallow embedding — a locale that fixes those parameters, collapsing the formula type to bool. The enabling new ingredient is a two-sorted substitution apparatus — capture-avoiding substitution, renaming, and a substitution lemma per namespace — in which each binder is transparent for the other; faithfulness of all three embeddings is mechanised and automated. Our central contribution is a fully mechanised two-sorted downward Löwenheim-Skolem theorem: the minimal embedding recovers deep validity relative to the (countable) assignment ranges, and this range-relative reading is shown to coincide with the general (Henkin-style) reading of MSO, whereas the standard reading is provably stronger, witnessed by comprehension. Both readings are nonetheless recovered from the minimal embedding, differing only in the admitted interpretations: all of them for the general reading, only the elementary substructures of the full model for the standard. We further exercise the embeddings on classical MSO landmarks: the Boolean-closure and graph schemata hold under the full second-order domain yet fail in the minimal embedding, making the dichotomy concrete, while reachability and 2-colorability are refuted throughout.
Keywords: Monadic second-order logic · Deep and shallow embedding · Isabelle/HOL · Henkin semantics · Automated faithfulness
1 Motivation and Introduction
Monadic second-order logic (MSO) sits at the heart of a body of results connecting logic, automata, and graph/tree structure theory [14,22,16]. It extends
- Dedicated to David Basin, whom I first met in Saarbrücken in the mid-1990s, over a shared enthusiasm for automated reasoning, formal methods, and expressive logics.
C. Benzmüller & D. Kirchner
first-order relational logic with a single, but powerful, additional resource: quantification over monadic predicates, i.e. over sets of individuals.
On the algorithmic side, a substantial line of work led by David Basin approaches MSO through automata and decision procedures: Basin and Klarlund use the weak monadic second-order theory of one successor (WS1S) and canonical string automata to specify and verify hardware, obtaining a decision procedure with counter-model generation [4,3], and Ayari and Basin develop bounded model construction for monadic second-order logics [1]. That line targets decidable fragments over strings and trees; the present work is complementary — it embeds full and general (Henkin-style) MSO into classical higher-order logic for interactive proof and metatheory, rather than deciding a fixed fragment.
Embeddings in classical higher-order logic (HOL) [15] are a versatile host for non-classical and expressive logics: treating HOL as a universal meta-logic, a wide range of object logics — modal, deontic, epistemic, and others — inherit its semantic infrastructure and proof automation. This is the basis of LogiKEy [8,9], a logic-pluralistic knowledge representation methodology in HOL, from computational metaphysics to ethical and legal reasoning; it grew out of the early modal-logic embeddings developed together with Paulson [10,11].
Shallow embeddings, which represent object-level formulae directly as HOL terms (for MSO, by the standard translation of connectives and quantifiers), give immediate access to Isabelle/HOL's proof automation — the prover sledgehammer, the finite-countermodel finder nitpick, and auto. Deep embeddings, in which formulae are elements of an inductively defined datatype, are needed for metalogical reasoning about syntax, substitution, or proof systems.
Shallow semantical embeddings of propositional and quantified modal logics in HOL were developed by Benzmüller and Paulson [10,11], initially without a deep embedding or a mechanised faithfulness proof. We have recently shown [12] that both embeddings can be carried out simultaneously, in a single HOL theory, with mutual faithfulness proofs automated. That development, however, only treats propositional modal logic, whose binders are modal operators carrying no variable binding. The same methodology now spans a range of logics; we develop it here for monadic second-order logic (MSO). We take up MSO not for expressive strength but for the phenomena of its second-order quantifier — above all the standard-versus-general (Henkin) distinction behind our central result — and, on the technical side, for its two-sorted binding: quantifying over individuals and sets of individuals at once, MSO's first- and second-order existentials are the two binders our apparatus must handle.
Contributions. We contribute MSOinHOL, an Isabelle/HOL development of MSO with binary relational atoms, monadic predication atoms, the propositional connectives, a first-order existential quantifier, and a monadic second-order existential quantifier. The particular contributions include:
-
A deep embedding (datatype ) and two shallow ones: a maximal embedding carrying explicit dependencies on the interpretation, the two domains, and the two assignments; and a minimal embedding that fixes the interpretation and assignments as locale parameters, collapsing the formula type to bool.
-
The minimal embedding is an Isabelle/HOL locale MinS; it admits a faithfulness theorem FaithfulMS_all stating that quantifying over all locale interpretations recovers exactly deep validity relative to the assignment ranges. Faithfulness of the maximal-shallow embedding with respect to the deep one (FaithfulSD) is likewise established and automated.
-
A two-sorted substitution apparatus for the deep embedding — free/bound/fresh predicates, capture-avoiding substitution, alphabetic renaming, the substitution lemma, and size-based induction — developed once per variable namespace, with each binder transparent for the other.
-
Experiments confirming tautologies, the monadic comprehension schema (proved for an arbitrary formula, generalising two ad-hoc instances), and nitpick countermodels for invalid schemata.
-
A suite of classical MSO landmarks — Boolean closure [14,22], monadic graph operations [16], reachability [4], and 2-colorability [22] — replicated across all three embeddings; the closure and graph schemata hold under the full second-order domain but fail in the general minimal embedding (and are recovered by its elementary refinement), while reachability and 2-colorability are non-theorems refuted throughout, turning the standard-vs-general dichotomy into a table of validity proofs, nitpick-found countermodels, and entailed cases.
-
The converse: range-relative validity coincides with general (Henkin-style) MSO validity, by a two-sorted Löwenheim–Skolem construction, while the standard reading is provably stronger — all formally proved.
Organisation. §2 fixes notation for HOL and §3 recalls MSO. §4 presents the three embeddings – deep, maximal-shallow, and the locale-based minimal-shallow (§4.4). §5 outlines the two-sorted substitution machinery, §6 the faithfulness theorems, and §7 the surjectivity problem. §8 reports experiments and §9 concludes with related work. The complete formal development is published as the Archive of Formal Proofs entry MSOinHOL [6]. Rendered theory sources appear in App. B and the full two-sorted Löwenheim–Skolem proof in App. A.
The landscape of standard models, Henkin models, and Andrews’ weaker -complexes, and the role of extensionality in fixing the class of Henkin models, is analysed by Benzmüller, Brown, and Kohlhase [5]; the shallow embeddings below inherit HOL’s functional and Boolean extensionality.
C. Benzmüller & D. Kirchner
3 Monadic second-order logic (MSO)
The syntax of MSO, given a (nonempty) signature of binary relation symbols, a denumerable set of individual (first-order) variables, and a denumerable set of monadic (second-order) variables, is fixed by the grammar
for relation symbols , individual variables , and monadic predicate variables ; the atom asserts that the monadic predicate holds of the individual (extensionally, that lies in the set denoted by ). The further connectives , the first-order universal , and the second-order universal are defined as usual by duality.
A model is a tuple , where is a nonempty domain of individuals, is a nonempty collection of admissible monadic predicates over (the second-order domain; extensionally a family of subsets), and the interpretation assigns to each relation symbol a binary relation . A first-order assignment maps each individual variable to a domain element, and a second-order assignment maps each monadic predicate variable to an admissible predicate in ; and denote the obvious updates.
Truth in a model is given recursively by
A formula is valid iff for every model, every into , and every into . When (every monadic predicate is admissible) the second-order quantifier is the standard (full) one; restricting yields the various general (Henkin-style) readings. The principle bridging the two is comprehension — that every property definable by a formula determines an admissible set; it holds by fiat when but can fail once is restricted. This is the monadic fragment: only monadic predicate variables (not relation variables) may be quantified, and a unary property of individuals is rendered directly as a monadic predicate applied to its argument.
Scope. For minimality we restrict the first-order signature to binary relation symbols and omit primitive equality; unary properties are rendered directly as monadic predications . Thus the formalisation covers the equality-free binary-relational fragment of MSO, which suffices for all results below.
4 Three embeddings of MSO in HOL
We now present the three embeddings side by side, after fixing the preliminaries shared by all of them.
4.1 Preliminaries
Preliminaries shared by all embeddings (theory MSOinHOL_preliminaries.thy, Fig. 6) declare the type (individuals) and the type synonyms (relation symbols), (first-order variables), (second-order variables), together with , the first-order assignment type , the second-order assignment type , and the two domain-restriction types and . Two variable-assignment update operators are introduced: for the first-order assignment and for the second-order one, each with its companion lemmata (L1–L4 and M1–M4). The set-as-predicate operations are polymorphic and hence shared between both sorts.
4.2 Deep embedding
The deep embedding (theory MSOinHOL_deep.thy, Fig. 1) is a single inductive datatype whose constructors mirror the grammar (1): (relational atom ), (monadic predication atom ), , , the first-order (), and the second-order (). The relative-truth predicate is declared in mixfix syntax and defined by primitive recursion: the predication clause evaluates the monadic predicate at the individual ; the first-order existential ranges over the explicit domain ; the second-order existential ranges over the explicit collection of admissible sets; the rest is standard. Validity closes universally over models, over domain-respecting first-order assignments ( into ), and over domain-respecting second-order assignments ( into ). An auxiliary full-domain notion fixes and and is a convenience for ; since implies , any counterexample for refutes as well.
Reading the clauses. The two existential clauses are the only places where the model is consulted nontrivially: each quantifies a witness over its domain ( over , over ) and re-evaluates under the corresponding assignment update. All remaining connectives (, and the two universals) are definitional abbreviations, unfolded automatically through the rewrite bag ; the same discipline () governs the two shallow embeddings, so the three notions of validity differ only in their primitives.
4.3 Maximal shallow embedding
The maximal shallow embedding (theory MSOinHOL_shallow.thy, Fig. 2) lifts every primitive of MSO to a -term abstracted over the explicit dependencies
C. Benzmüller & D. Kirchner

Fig. 1. Deep embedding of MSO in HOL: the datatype with the predication atom and the two binders, the derived connectives, the relative-truth predicate RelativeTruthD, and the validity definitions ValD, ValD'.
. The type of formulae is . Atoms consult the interpretation; the predication case applies the second-order assignment; the first-order existential pairs a meta-level HOL existential with a first-order assignment update; and the second-order existential pairs a meta-level HOL existential with a second-order assignment update. The pattern is identical to that of [12]; the only difference is that the formula type carries two assignments and two domain restrictions, because both the first-order (individual) and the second-order (set) quantifier must be accommodated. We write for the resulting validity and for its full-domain variant ( and ), the maximal-shallow analogues of and .
4.4 Minimal shallow embedding (locale-based)
The maximal-shallow type carries every dependency as an explicit argument, threaded throughout because each quantifier updates an assignment in its recursive call for for ). The minimal embedding avoids this: each MSO existential is encoded by HOL's own binder over the matching variable namespace , and atoms read their variables' denotations from

Fig. 2. Maximal shallow embedding (MSOinHOL_shallow.thy): the formula type , the six primitive cases (the two existentials thread and respectively), the derived connectives, and validity.
the assignment is , so a bound variable is a symbol looked up in the assignment rather than a witness installed into an updated one. The recursion therefore never changes , , or ; this, with the absence of any world dependency, lets us promote them to locale parameters, and the formula type reduces to bool.
We package the minimal embedding as an Isabelle/HOL locale MinS [2] (theory MSOinHOL_shallow_minimallocale.thy, Fig. 3), fixing . The six primitive cases are AtmM, PrdM (predication defined as ), NegM, AndM, the first-order binder ExM over , and the second-order binder ExM2 over . As the formula type is bool, relative truth and validity ValM (written ) are the identity. Both binders are declared as HOL binders, so that sledgehammer treats second-order MSO goals as ordinary HOL goals: bound first- and second-order variables become HOL-level bound variables of types and , and the external provers reason about them directly without unfolding the deep-embedding syntax.
For practical experimentation the locale is also instantiated once at the global level (theory MSOinHOL_shallow_minimal.thy, Fig. 7): three uninterpreted constants II, gg, GG are introduced and a global_interpretation re-issues the locale notation at the global level. The locale formulation remains the single source of all theorems; the global interpretation propagates them to the constants without proof duplication.
C. Benzmüller & D. Kirchner
1 theory MSOinHOL_shallow_minimal_localce imports MSOinHOL_preliminaries
2 begin
3 —<Minimal (lightweight) shallow embedding of MSO in HOL, packaged as a locale.
4 Since MSO carries no world dependency, the formula type collapses to <bool>, >
5 locale MinS = fixes II :: I and gg :: ξ and GG :: G
6 begin
7 —<Six primitive cases. ExM, ExM2 are HOL binders over the symbol types V, V2;
8 atoms consult II via gg, and membership consults GG via gg, >
9 definition AtmM :: "R⇒V⇒V⇒bool" (":_m"("_")") where "r^m(x,y) ≡ II r (gg x) (gg y)"
10 definition PrdM :: "V2⇒V⇒bool" (":_m"("_")") where "X^m(x) ≡ (GG X) (gg x)"
11 definition NegM :: "bool⇒bool" (":_m"=" [58]59) where "¬mφ ≡ ¬φ"
12 definition AndM :: "bool⇒bool⇒bool" (infixr "∧m" 56) where "φ ∧ m ψ ≡ φ ∧ ψ"
13 definition ExM :: "(V⇒bool)⇒bool" (binder "∃m" 53) where "∃m d, φ d ≡ ∃d, φ d"
14 definition ExM2 :: "(V2⇒bool)⇒bool" (binder "∃m" 53) where "∃m d, φ D ≡ ∃D, φ D"
15 —<Derived connectives, >
16 definition OrM :: "bool⇒bool⇒bool" (infixr "∨m" 54) where "φ ∨ m ψ ≡ ¬m(¬m φ ∧ m ¬m ψ)"
17 definition ImpM :: "bool⇒bool⇒bool" (infixr "∨m" 55) where "φ ∨ m ψ ≡ ¬m φ ∨ m ψ"
18 definition IfM :: "bool⇒bool⇒bool" (infixr "¬m" 54) where "φ ¬m ψ ≡ (φ ∨ m ψ) ∧ m (φ ¬m φ)"
19 definition AllM :: "(V⇒bool)⇒bool" (binder "∨m" 53) where "∨m d, φ d ≡ ∨d, φ d"
20 definition AllM2 :: "(V2⇒bool)⇒bool" (binder "∨m" 53) where "∨m d, φ D ≡ ∨D, φ D"
21 —<Relative truth and validity. As the formula type is <bool>, validity is the identity, >
22 definition ValM :: "bool⇒bool" ("|=m" 9) where "|=m φ ≡ φ"
23 —<Bag of definitions, >
24 named_theorems DefM lemmas DefM_def [DefM] = AtmM_def PrdM_def NegM_def AndM_def ExM_def ExM2_def
25 OrM_def ImpM_def IfM_def AllM_def AllM2_def ValM_def
26 end
27 end
Fig. 3. The locale MinS (MSOinHOL_shallow_minimal_localce.thy) packaging the minimal shallow embedding: parameters II, gg, GG; the six primitive cases including the HOL binders ExM (over V) and ExM2 (over V2); the derived connectives; and validity.
Maximal vs. minimal: the trade-off. The two shallow embeddings encode the same object logic but package the semantic parameters oppositely. The maximal embedding keeps the interpretation and both assignments explicit in each translated formula (type ): the parameters are under direct control and the translation lines up term-for-term with the deep embedding, which makes it the natural faithfulness bridge (FaithfulSD) and the place to express the full-domain standard readings ; the price is weight, as every subterm threads . The minimal embedding hides those parameters in the locale MinS, so a translated formula becomes an ordinary HOL proposition of type bool with each MSO binder a native HOL binder: sledgehammer and nitpick act on it directly, which makes it the convenient vehicle for downstream reasoning and for comparing classes of interpretations — general vs. standard (§7) — at the cost of leaving the semantic parameters implicit.
5 Two-sorted substitution machinery
Substitution lemmas are needed for the deepminimal-shallow faithfulness proof, to handle the two existential-quantifier cases. Since MSO has two variable namespaces, we develop two parallel substitution apparatuses, Part A (first-order) and Part B (second-order), in theory MSOinHOL_deep_subst_lemma.thy (Figs. 9–11). We use named variables and explicit capture-avoiding substitution rather than a nominal or de Bruijn infrastructure, keeping the two namespaces and their mutual transparency visible in the formal text.
The two apparatuses. Each part provides the standard components — free/bound/fresh predicates, a variable-for-variable substitution Subst (written ; second-order Subst2), a substitutability predicate, the SubstitutionLemma (resp. SubstitutionLemma2, whose semantic side is the update ), and an -renaming ren_for_subst composing into the safe substitution ren_subst, written . The size-based induction principles SInduct and QInduct recurse on both binders. The outcomes used downstream are L27/N27 (safe substitution commutes with assignment update) and L29/N29, which re-express a deep existential as a HOL existential over a fresh symbol — exactly the equation the minimal translation needs.
Transparency across namespaces. A binder of one sort contributes nothing to the machinery of the other: binding no variable of that namespace, it descends through every predicate, substitution, renaming, and induction by a single uniform clause, structurally identical to the negation clause and dispatched by the same auto/simp. This holds twice over — the second-order binder ExD2 is transparent for Part A and the first-order ExD for Part B — the only genuinely new leaf being the predication atom , which contributes a free first-order occurrence to Part A and a free second-order one to Part B. The -renaming is what keeps substitution sound across a binder: replacing by in would capture the free , which ren_subst prevents by first renaming the bound to a fresh symbol. We additionally isolate the single-binder semantic core as rename_eval/rename_eval2 (theory MSOinHOL_subst_extras.thy, Fig. 12).
6 Faithfulness, automated
An embedding is faithful when validity transfers in both directions — a formula is valid in MSO exactly when its HOL translation is — so the embedding neither loses nor invents theorems; we establish this, automatically, for all three.
Two mappings translate deep formulae into shallow ones (theory MSOinHOL_faithfulness_local.thy, Fig. 4): DpToShS (deep to maximal-shallow), written , and DpToShM (deep to minimal-shallow), written . The first recurses transparently through every primitive, since both source and target use named-variable binders for both sorts. The second, declared inside the locale MinS, bridges the two named-variable binders of the deep embedding to the two HOL binders of the minimal embedding: its first-order existential clause inserts a first-order safe substitution , and its second-order existential clause inserts a second-order safe substitution .
Pointwise and validity-level theorems. The deepmaximal-shallow correspondence FaithfulSDlem is derived by a single induction on with auto simp: DefSDefD; its validity-level form FaithfulSD – the statement for closed
C. Benzmüller & D. Kirchner
validity rather than for a fixed model and assignment – then follows by unfolding the two validity definitions ValD_def and ValS_def. The deep↔minimal-shallow correspondence is first shown pointwise, FaithfulMDlem, by a single induct with rule QInduct: simp add: DefDDefM discharges the propositional and atomic cases, and the two existential cases are closed by blast after the safe-substitution lemmata L27 and N27 rewrite the translated binders. As the minimal validity ValM is the identity, FaithfulMD coincides with FaithfulMDlem, and FaithfulMS follows by composition with FaithfulSDlem.
Faithfulness across all locale interpretations. The locale form admits the all-interpretations theorem FaithfulMS_all: a formula holds in the minimal embedding under every interpretation (II, gg, GG) of MinS iff it holds, in the deep embedding, in every model whose first- and second-order domains are exactly the ranges of the assignments,
The proof is a single simp with FaithfulMD. The forward direction toward full deep validity, Deep_to_MinS, holds outright: a deep-valid formula transfers to every minimal interpretation. The converse is exactly the surjectivity problem — whether the countable assignment ranges can be made to exhaust the full second-order domain — to which we now turn.
What FaithfulMS_all buys. FaithfulMS_all makes the minimal embedding usable as a proof device, not merely a definitional convenience. To establish a deep validity one discharges the corresponding goal in the minimal embedding — a plain HOL formula with two ordinary binders, on which sledgehammer and auto operate directly — and the theorem transports the result to the deep syntax over the range-determined model class; conversely, any nitpick countermodel against the minimal embedding refutes the deep formula. The only gap is the passage from the range-determined model class to the full general (Henkin-style) class, which §7 closes; for the standard reading it shows that unrestricted all-interpretations faithfulness is impossible, while an elementary-substructure restriction recovers it exactly.
7 The surjectivity problem, second-order
In the minimal-shallow embedding the first-order binder ranges over the namespace through , with effective range Range ; the second-order binder ranges over through — the type of monadic sets (predicates) over individuals — with effective range Range . Both ranges are countable, whereas the deep embedding lets the existentials range over the full domains and , so faithfulness against the full domains does not follow from FaithfulMD. By FaithfulMS_all the missing converse is precisely
1 theory MSOinHOL_faithfulness_local
2 imports MSOinHOL_deep MSOinHOL_shallow MSOinHOL_shallow_minimal_local MSOinHOL_deep_subst_lemma
3 begin
4 —<Translation from deep to maximal shallow (transparent: both use named-variable binders).>
5 fun DpToShS ("[]") where "[r^d(x,y)] = r^d(x,y)" | "*[X^d(x)] = X^d(x)" | "*[-^d_φ] = ¬[φ] | "*[φ ∧^d_φ] = [φ] ∧^s [φ]"
6 | "*[^d_φ, φ] = (∃v, [φ]) * | "*[^d_φ, φ] = (∃v, V, [φ])"
7 —<Translation from deep to minimal shallow (within the locale MinS): each binder is bridged by safe substitution
8 into a HOL-level binder -- first-order via ⟨{v←d}⟩, second-order via ⟨{v←r2D}⟩.
9 fun (in MinS) DpToShM ("[]") where "([r^d(x,y)] = r^m(x,y)) | "*[X^d(x)] = X^m(x)" | "*[-^d_φ] = ¬m[φ] | "*[φ ∧^d_φ] = (φ) ∧^m [φ]"
10 | "*[^d_φ, φ] = (∃m.d. (|v←r_d[φ]|)) | "*[^d_φ, φ] = (∃m_φ.D. (|V←r_2 D[φ]))"
11 —<Faithfulness deep —> maximal shallow. Pointwise first: global by unfolding validity.>
12 theorem FaithfulSDlem: "((I,D,E),g,G =^s [φ]) —> ((I,D,E),g,G =^d φ)" by (induct φ arbitrary: g G; auto simp: DefS DefD)
13 theorem FaithfulSD: "([=^s [φ]]) —> (=[=^d φ]) by (simp add: FaithfulSDlem ValD_def ValS_def)
14 —<Faithfulness deep —> minimal shallow, parametrised by the locale, relative to the ranges of gg and GG.>
15 context MinS begin
16 theorem FaithfulMDlem: "([φ]) —> ((|I,Range gg,Range GG),gg,GG =^d φ))"
17 by (induct φ rule: QInduct; simp add: DefD DefM) blast+
18 theorem FaithfulMD: "([=^m (φ)]) —> ((|I,Range gg,Range GG),gg,GG =^d φ)"
19 using FaithfulMDlem by (simp add: ValM_def)
20 theorem FaithfulMSlem: "([φ]) —> ((|I,Range gg,Range GG),gg,GG =^s [φ])"
21 using FaithfulSDlem FaithfulMDlem by auto
22 theorem FaithfulMS: "([=^m (φ)]) —> ((|I,Range gg,Range GG),gg,GG =^s [φ])"
23 using FaithfulMSlem by (simp add: ValM_def)
24 end
25 —<Global faithfulness: a formula holds in every minimal interpretation of MinS iff it holds in every model
26 whose first- and second-order domains are exactly the ranges of the chosen assignments.>
27 theorem FaithfulMS_all: "(y|l gg GG, MinS.ValM (MinS.DpToShM || gg GG φ)) = (y|l g G. (I,Range g,Range G),g,G =^d φ)"
28 by (simp add: MinS.FaithfulMD)
29 —<One direction toward full deep validity: deep validity transfers to every minimal interpretation.
30 The converse is the (second-order) surjectivity problem discussed in the paper.>
31 theorem Deep_to_MinS: "([=^d φ]) ⇒ (y|l gg GG, MinS.ValM (MinS.DpToShM || gg GG φ))"
32 by (metis (mono_tags, lifting) MinS.FaithfulMD ValD_def)
33 —<Consistency check.>
34 lemma True nitpick[satisfy] oops
35 end
Fig. 4. Faithfulness: the translations [·] and (|·|) (the latter bridging both binders via the two safe substitutions), the deep↔maximal-shallow theorems, the locale-based deep↔minimal-shallow correspondences, the all-interpretations theorem FaithfulMS_all, and the one-directional bridge Deep_to_MinS.
The decisive observation is that the general validity imposes no closure on the admissible collection : it quantifies over arbitrary families with into . That is exactly the general (Henkin-style) reading of MSO, which is nothing but two-sorted first-order logic over the structure with individuals as one sort,
The reading is the class of structures with an arbitrary admissible family and no closure condition; terminology for it is not uniform. Shapiro [21] calls these Henkin models, reserving faithful Henkin model for one that additionally satisfies comprehension and choice, and full model for the standard case . Henkin [18], Väänänen [23], and Manzano [19] instead call the comprehension-closed structures Henkin models and the unrestricted ones general models. We write “general (Henkin-style)” for to stay neutral: it is Shapiro’s Henkin class and Väänänen’s general class. On either convention the levels nest as full/standard comprehension-closed (faithful Henkin/Henkin) general, with the widest; the diagonal comprehension instance separates from the comprehension-closed level, while the categoricity phenomenon separates that level from the full one. Via the reduction of this semantics to many-sorted first-order logic (Shapiro [21, Thm. 3.5]; Manzano [19]), inherits the downward Löwenheim–Skolem theorem directly.
C. Benzmüller & D. Kirchner
the admissible sets as a second sort, the relation symbols as binary relations on the first sort, and a membership relation between the sorts. First-order logic has the downward Löwenheim–Skolem property; the apparent “second-order” difficulty is an artefact of conflating with the standard reading treated below.
The converse (range-relative deep validity) holds, for the general reading. Together with Deep_to_MinS, this gives the following exact characterisation of range-relative validity.
Theorem 1. For every formula , range-relative validity coincides with general (Henkin-style) deep validity:
Equivalently, via FaithfulMS_all, the minimal-shallow embedding is faithful exactly to general (Henkin-style) MSO validity.
The proof (App. A) is a two-sorted downward Löwenheim–Skolem construction. From a countermodel one extracts a countable elementary sub-model — one satisfying exactly the same formulae — containing the assignment ranges by the Tarski–Vaught test (a witness-reflection criterion that guarantees elementarity), drawing set-witnesses honestly from — so that no comprehension is assumed and the sub-model stays inside the general class — and then reindexes the countably many variables to surject onto the countable sub-domains while fixing the finitely many free variables of , using a coincidence lemma. The second-order domain is never replaced by a powerset; being “comprehension-closed” is a property the hull enjoys, not a hypothesis it requires.
Unrestricted minimal interpretations do not capture the standard reading. No Löwenheim–Skolem argument can strengthen this to the standard validity (where ), because the two notions genuinely differ. Writing for range-relative validity — the left-hand side of Theorem 1, there identified with — we have
The inclusion is immediate – the standard model is itself one of the general models quantified over by , which is the content of the lemma we name – while its strictness is witnessed by comprehension: the instance is -valid (comprehension_atom) but not -valid, as the nitpick countermodels of §8, over a restricted that omits the diagonal set , show. In the three-level hierarchy of Footnote 4, this instance separates the general reading from the comprehension-closed Henkin reading, and hence a fortiori from the full reading ; the residual gap, between the Henkin and the full reading, is the familiar categoricity phenomenon — the full reading pinning models down up to isomorphism — since monadic quantification over sets already expresses Dedekind completeness (quantify over the bounded set whose least upper bound is asserted), so a sentence forcing a complete dense order without endpoints has only uncountable full models and admits no downward Löwenheim–Skolem under the standard reading. The machine-checked witness in our development is the simpler diagonal comprehension instance above.
The analysis thus resolves into a dichotomy: the converse is a theorem for the general (Henkin-style) reading and a provable non-reduction for the standard reading. The supplementary theories MSOinHOL_lowenheim_skolem_lemmas.thy and MSOinHOL_lowenheim_skolem.thy carry this out — the coincidence lemma coincidence, the surjective reindexing reindex, the assembled converse RangeValid_imp_ValD (with corollaries RangeValid_iff_ValD and Faithful_to_Henkin), the negative Standard_strictly_stronger with its explicit diagonal countermodel, and the two-sorted elementary-substructure hull ls_hull, a countable Tarski-Vaught hull skolem_hull whose truth-preservation lemma truth_pres drives the two-sorted construction — and, built on the same hull, the elementary-substructure relation ElementarySubstructure, the first-class downward Löwenheim–Skolem theorem DownwardLowenheimSkolem, and the standard-reading characterisation Deep_to_MinS. All are complete structured proofs, machine-checked under Isabelle2025-2; the construction is given in App. A.
The standard reading, captured exactly by elementary interpretations. The non-reduction says only that no range-relative — equivalently, all-interpretations — faithfulness can reach . It does not say the standard reading escapes the minimal embedding: it does not. Writing for the two-sorted elementary substructure relation ElementarySubstructure (, and the two models satisfy the same formulae under every assignment landing in the smaller pair), the development now isolates the Tarski–Vaught hull as a first-class downward Löwenheim–Skolem theorem DownwardLowenheimSkolem: every countable nonempty seed sub-pair of a model extends to a countable elementary substructure. Using it, the strongest faithfulness theorem Deep_to_MinS characterises the standard reading exactly,
where is the full model ( ). Both readings of MSO are therefore recovered from the minimal embedding, differing only in the admissible interpretations: quantifies over all minimal interpretations (Theorem 1, via FaithfulMS_all), whereas quantifies over the elementary ones — those whose countable range model is an elementary substructure of the full model. The strict inclusion is exactly the statement that this elementary restriction cannot be dropped, the diagonal comprehension instance witnessing it. Concretely, the nitpick countermodels to the closure schemas in the minimal embedding (§8) are necessarily non-elementary interpretations: their countable range omits a set the schema needs, so they refute it; on the elementary interpretations the same schemas become provable, in agreement with their -validity. (They are
C. Benzmüller & D. Kirchner
thus not genuine counterexamples to the standard reading, but artefacts of admitting non-elementary ranges; under the elementary-substructure restriction (the locale MinS_ES_Univ) each would be a theorem.)
A recursion-theoretic strengthening. The non-reduction just established is model-theoretic: the failure of downward Löwenheim–Skolem shows that the full MSO models — those with — do not form an elementary class. A complementary, recursion-theoretic obstruction is that standard validity is not recursively enumerable — a classical consequence of the expressive strength of standard second-order logic (cf. Shapiro [21], Väänänen [23]), which we do not formalise here — so it is the consequence set of no recursively axiomatisable first-order theory. This non-enumerability reflects quantification over all interpretations of the relation symbols, not the standard reading as such: restricting to a fixed structure or class of structures — , the infinite binary tree, or finite words and trees — makes standard MSO decidable, hence complete and enumerable [14,22,16].
8 Experiments
We illustrate the development with two test files. The core file MSOinHOL_experiments.thy (Fig. 5) collects tautologies, comprehension, and nitpick disproofs; the larger file MSOinHOL_experiments_classic.thy replicates a suite of classical MSO landmarks across all three embeddings (§8.1). Propositional tautologies (proved in all three embeddings with the d/s/m discipline), first-order tautologies such as , and the predication tautology are dispatched by simp or auto after unfolding DefD, DefS, or DefM.
Monadic comprehension. The principal second-order validity we verify is monadic comprehension, stated over the full second-order domain (, ). In its general form it is a schema, parametric in an arbitrary formula in which the comprehension variable does not occur free:
The witnessing set is exactly the property defined by , namely the HOL predicate ; it always lies in because in the standard semantics, and the side condition on lets the second-order irrelevance lemma discharge the -slot inside . We record this as the theorem comprehension_schema (supplementary theory MSOinHOL_comprehension.thy, Fig. 13); the two instances proved directly in MSOinHOL_experiments.thy — the set of -self-related individuals, , with witness , and the universally-true predicate , with witness — are its corollaries. No second-order search is required, because the comprehension term is itself an ordinary HOL predicate.
Disproofs by nitpick. nitpick reliably finds finite countermodels for invalid schemata; these are exploratory searches, terminated with oops rather than stored as theorems. “Every monadic predicate holds somewhere”, , fails by the empty predicate; the comprehension instance asking for a predicate that both holds and fails of every individual, , is unsatisfiable hence invalid; and symmetry of , fails by a two-element model. Each disproof uses the full-domain relation .

Fig. 5. Experiments: propositional and first-order tautologies in all three embeddings, the predication tautology, monadic comprehension and the universal-predicate validity over the full second-order domain, and nitpick disproofs of “every predicate holds somewhere”, a self-contradictory predicate, and symmetry of .
8.1 Classical MSO landmarks across the three embeddings
A second, larger experiment file (MSOinHOL_experiments_classic.thy, Fig. 14) revisits a sequence of textbook MSO constructions and runs each one through all three embeddings. The point is not the individual validities — they are folklore — but the pattern of their truth values across the five readings , , , , which is the operational face of the standard-vs-general dichotomy of §7. Table 1 collects the outcomes.
C. Benzmüller & D. Kirchner
Table 1. Classical MSO landmarks across the five readings. In the full-domain columns , () and the minimal column , is a validity proof (an explicit second-order witness for ), a -found countermodel, and “-” a case not separately tested (failing as complement/intersection do). The general readings , are not tested independently: they coincide with by FaithfulSD () and Theorem 1 ( is the minimal embedding over all interpretations); the full readings likewise agree, .
| Schema (and witness, where valid) | |||||
|---|---|---|---|---|---|
| Complement | ✗ | ✓ | ✗ | ✓ | ✗ |
| Intersection | ✗ | ✓ | ✗ | ✓ | ✗ |
| Union | - | ✓ | - | ✓ | - |
| Separation | - | ✓ | - | ✓ | - |
| P-image | - | ✓ | - | ✓ | - |
| P-preimage | - | ✓ | - | ✓ | - |
| Reachability | ✗ | ✗ | ✗ | ✗ | ✗ |
| Reflexive reachability | ✓ | ✓ | ✓ | ✓ | ✓ |
| 2-colorability | ✗ | ✗ | ✗ | ✗ | ✗ |
Boolean closure and graph operations. The first six rows are instances of the comprehension schema above: each asserts the set defined by a formula , i.e. , with witness (the predicate shown in the table). Over the full second-order domain (, ) each witness is an ordinary HOL predicate supplied by a single : the Boolean cases [14,22] use , , , and the monadic graph operations [16] the witnesses shown in the table. After unfolding DefD (resp. DefS) and -reducing, the deep and maximal-shallow goals are HOL-identical, so the two proof scripts are line-for-line the same — the d/s alignment made visible on non-trivial second-order content. In the minimal embedding ranges over through , so the required predicate need not lie in Range and nitpick refutes complement and intersection (the remaining four fail for the same reason).
Reachability and colorability. Reachability and 2-colorability are genuinely invalid in MSO, independently of the standard/general choice, and fail in all columns: reachability [4] — “if contains and is closed under -successors then contains ” — has a nitpick countermodel with -disconnected; its reflexive variant (conclusion ) follows from the first conjunct alone, needs no witness, and so survives even the minimal embedding; 2-colorability [22] fails on an odd cycle (). The overall pattern — closure rows valid under the full readings but refuted under the general , reachability and 2-colorability uniformly refuted — is exactly the inclusion of §7 read off machine-checked outcomes: faithful to the general (Henkin-style) reading, the minimal embedding refutes precisely the principles that separate the standard reading from the general one, while reflexive reachability, needing no set witness, holds across the board.
Locale-based transfer. A short demonstration (theory MSOinHOL_experiments_locale.thy, Fig. 15) proves a schema purely from minimal-shallow definitions, inside the locale, and transfers it to the range-relative deep embedding by a single application of MinS_to_Deep, the directional reading of FaithfulMS_all. This is the operational pay-off of the locale design: the user proves once in the simplest setting, and the strong faithfulness theorem ports the result to the syntactic deep embedding.
9 Conclusion
MSOinHOL demonstrates that the deep-and-shallow methodology of [12] scales to a setting with two binders over different sorts. The new ingredients are a two-sorted substitution apparatus, in which each binder is transparent for the other namespace, and a locale-based minimal embedding with two HOL binders and an all-interpretations faithfulness theorem. The powerset character of the second-order domain turns the surjectivity problem into a clean dichotomy. On one side, range-relative validity coincides with the general (Henkin-style) reading of MSO — a two-sorted Löwenheim-Skolem theorem (§7). On the other, the standard reading is provably stronger, yet it too is captured exactly by the minimal embedding once one restricts to elementary interpretations (Deep'_to_MinS). The two readings are thus one and the same translation, differing only in the class of interpretations over which validity is quantified. The whole construction — coincidence, the two-sorted elementary-substructure hull, reindexing, the assembled converse, and the negative result — is machine-checked. A suite of classical MSO landmarks — Boolean closure, graph operations, reachability, 2-colorability — replicated across the three embeddings turns this dichotomy into a table of validity proofs, nitpick-found countermodels, and entailed cases: the closure principles are valid under the full second-order domain and refuted by the general minimal embedding.
The ingredients are individually classical: downward Löwenheim-Skolem has been formalised in Isabelle for first-order logic [13]; the distinction between the standard and the general (Henkin-style) reading of second-order semantics is textbook [23]; and the general reading is known to be, in effect, a two-sorted first-order theory [19]. What is new here, to our knowledge, is to carry a mechanised downward Löwenheim-Skolem theorem all the way through to monadic second-order validity. The construction is a two-sorted elementary-substructure argument that, at each step, takes the set it needs as a witness from the model's own admissible collection rather than forming it as an arbitrary subset — and that is exactly what keeps the result inside the general (Henkin-style) class, where such sets need not exist in advance.
Use in teaching. Beyond its metatheoretic interest, the development doubles as teaching material for logic at the graduate and even undergraduate level. Because the shallow embeddings turn MSO formulae into ordinary Isabelle/HOL goals, the precise difference between the standard and the general (Henkin-style) reading — and its consequences for MSO — becomes something students
C. Benzmüller & D. Kirchner
can explore hands-on and around the clock, through interactive proof and with sledgehammer and nitpick. A principle that holds under the full second-order domain yet fails in the minimal, range-restricted embedding makes the standard-vs-general gap immediately tangible: a machine-checked proof in one column and an explicit countermodel in another.
Availability. The full Isabelle/HOL development is published as the Archive of Formal Proofs entry MSOinHOL [6]: seventeen theory files (the ten core theories together with seven supplementary ones — subst_extras, comprehension, experiments_classic, the elementary minimal interpretation shallow_minimal_elementary and its experiments experiments_classic_elementary, and the two-sorted Löwenheim-Skolem development split into lowenheim_skolem_lemmas and lowenheim_skolem), loaded in dependency order by the session ROOT; the published entry adds one further experiments theory (experiments_extra) not required for the results reported here. The development has been checked in Isabelle2025-2 on a MacBook Air (Apple M3, 16 GB). An extended version of this paper, with the full two-sorted Löwenheim-Skolem proof and the rendered Isabelle/HOL theory sources as appendices, is available on arXiv [7].
Disclosure on the use of generative AI. The authors used generative AI assistants (Anthropic's Claude family of models) to draft and shorten prose, to propose and shorten some proofs (in particular parts of the two-sorted Löwenheim-Skolem construction), and to maintain cross-references between the LaTeX source and the Isabelle/HOL files. The mathematical content, the theory development, and the design choices are the authors'; all text and proofs in the final manuscript have been verified by the authors, who take full responsibility for the content.
References
-
Ayari, A., Basin, D.: Bounded model construction for monadic second-order logics. In: Computer Aided Verification (CAV 2000). Lecture Notes in Computer Science, vol. 1855, pp. 99–112. Springer (2000)
-
Ballarin, C.: Locales: A module system for mathematical theories. Journal of Automated Reasoning 52(2), 123–153 (2014). https://doi.org/10.1007/s10817-013-9284-7
-
Basin, D., Klarlund, N.: Automata based symbolic reasoning in hardware verification. Formal Methods in System Design 13(3), 255–288 (1998)
-
Basin, D.A., Klarlund, N.: Hardware verification using monadic second-order logic. In: Computer Aided Verification (CAV 1995). Lecture Notes in Computer Science, vol. 939. Springer (1995). https://doi.org/10.1007/3-540-60045-0_38
-
Benzmüller, C., Brown, C., Kohlhase, M.: Higher-order semantics and extensionality. Journal of Symbolic Logic 69(4), 1027–1088 (2004). https://doi.org/10.2178/jsl/1102022211
-
Benzmüller, C., Kirchner, D.: Monadic second-order logic in HOL: Deep and shallow embeddings with automated faithfulness. Archive of Formal Proofs (2026), formal proof development, https://isa-afp.org/entries/MSOinHOL.html
-
Benzmüller, C., Kirchner, D.: Monadic second-order logic in HOL: Deep and shallow with automated faithfulness (extended preprint). arXiv preprint arXiv:XXXX.XXXXX (2026), extended version, with the full Löwenheim-Skolem proof and the rendered Isabelle/HOL theory sources as appendices
-
Benzmüller, C., Kirchner, D., Pasetto, L.: Many logics, one methodology: A plea for logical pluralism in formalised reasoning. arXiv preprint arXiv:2605.27246 [cs.LO] (2026)
-
Benzmüller, C., Parent, X., van der Torre, L.: Designing normative theories for ethical and legal reasoning: LogiKEy framework, methodology, and tool support. Artificial Intelligence 287, 103348 (2020). https://doi.org/10.1016/j.artint.2020.103348
-
Benzmüller, C., Paulson, L.C.: Multimodal and intuitionistic logics in simple type theory. The Logic Journal of the IGPL 18(6), 881–892 (2010). https://doi.org/10.1093/jigpal/jzp080
-
Benzmüller, C., Paulson, L.C.: Quantified multimodal logics in simple type theory. Logica Universalis (Special Issue on Multimodal Logics) 7(1), 7–20 (2013). https://doi.org/10.1007/s11787-012-0052-y
-
Benzmüller, C.: Faithful logic embeddings in HOL — deep and shallow. In: Barrett, C., Waldmann, U. (eds.) Automated Deduction – CADE-30 – 30th International Conference on Automated Deduction, Stuttgart, Germany, July 28-31, 2025, Proceedings. Lecture Notes in Computer Science, vol. 15943, pp. 280–302. Springer (2025). https://doi.org/10.1007/978-3-031-99984-0_16, (preprint: arXiv:2502.19311)
-
Berghofer, S.: First-order logic according to fitting. Archive of Formal Proofs (2007), formal proof development, includes a mechanised downward Löwenheim-Skolem theorem for countable first-order logic, https://isa-afp.org/entries/FOL-Fitting.html
-
Büchi, J.R.: Weak second-order arithmetic and finite automata. Zeitschrift für mathematische Logik und Grundlagen der Mathematik 6(1–6), 66–92 (1960)
-
Church, A.: A formulation of the simple theory of types. Journal of Symbolic Logic 5(2), 56–68 (1940). https://doi.org/10.2307/2266170
-
Courcelle, B., Engelfriet, J.: Graph Structure and Monadic Second-Order Logic: A Language-Theoretic Approach, Encyclopedia of Mathematics and its Applications, vol. 138. Cambridge University Press (2012)
-
van Heijenoort, J.: From Frege to Gödel: A Source Book in Mathematics, 1879-1931. Source books in the history of the sciences series, Harvard Univ. Press, Cambridge, MA, 3rd printing, 1997 edn. (1967)
-
Henkin, L.: Completeness in the theory of types. Journal of Symbolic Logic 15(2), 81–91 (1950). https://doi.org/10.2307/2266967
-
Manzano, M.: Extensions of First-Order Logic, Cambridge Tracts in Theoretical Computer Science, vol. 19. Cambridge University Press (1996)
-
Nipkow, T., Paulson, L.C., Wenzel, M.: Isabelle/HOL - A Proof Assistant for Higher-Order Logic, Lecture Notes in Computer Science, vol. 2283. Springer (2002)
-
Shapiro, S.: Foundations without Foundationalism: A Case for Second-Order Logic, Oxford Logic Guides, vol. 17. Oxford University Press (1991)
-
Thomas, W.: Languages, automata, and logic. In: Rozenberg, G., Salomaa, A. (eds.) Handbook of Formal Languages, Vol. 3: Beyond Words, pp. 389–455. Springer (1997)
-
Väänänen, J.: Models and Games, Cambridge Studies in Advanced Mathematics, vol. 132. Cambridge University Press (2011)
C. Benzmüller & D. Kirchner
A The converse of FaithfulMS_all: range vs. general (Henkin-style) validity
We prove Theorem 1. Write for range-relative validity,
The forward direction is immediate (it is Deep_to_MinS: maps into Range and into Range , so both are admissible). We prove the converse.
Setup. A model is read as a two-sorted first-order structure over the fixed individual type: sort 1 is , sort 2 is , each relation symbol denotes the binary relation on sort 1, and a single membership relation is defined by . Under this reading is ordinary two-sorted FO satisfaction, with ranging over sort 1 and over sort 2; no closure on is imposed.
Coincidence (generalising L12/N12). By induction on : if agree on every first-order variable free in and agree on every second-order variable free in , then . The binder cases use that an update (resp. ) preserves agreement on the free variables of the body.
Proof. Converse of Theorem 1, contrapositively. Suppose . Then there are with into into , and .
Step 1 (downward Löwenheim–Skolem). Build sub-predicates and by closing Range under Tarski-Vaught witnesses for the existential subformulae of : whenever a sort-1 existential has a witness in for a parameter tuple drawn from the current stage, add one to ; whenever a sort-2 existential has a witness , add that to . Iterating times yields that are countable (the language and the two ranges are countable, and each stage adds only countably many witnesses) and elementary for . By the Tarski-Vaught test, for every subformula of ; in particular . The set-witnesses are honest elements of , so : no comprehension is used.
Step 2 (reindexing). and are countable and nonempty (they contain the nonempty ranges Range , Range ). Since are infinite and only finitely many variables occur free in , choose agreeing with on the free first-order variables of with Range , and agreeing with on the free second-order variables with Range — fix the finitely many free slots, and let the cofinitely many remaining slots enumerate the countable target.
Step 3 (conclude). By Coincidence, . But and , hence , i.e. , as required.
Remark (the standard reading, exactly). The hull above is not only the engine of the converse; packaged with its truth-preservation it is a self-contained downward Löwenheim–Skolem theorem DownwardLowenheimSkolem
— every countable nonempty seed sub-pair extends to a countable elementary substructure . Applied to the full model and combined with FaithfulMD and the surjective reindexing, it yields the strongest faithfulness theorem Deep'_to_MinS: iff holds for every minimal interpretation whose range model is an elementary substructure of the full model (locale MinS_ES_Univ). The general reading is thus captured by the minimal embedding over all interpretations, the standard reading over the elementary ones; the gap between them is exactly the comprehension instance below.
Remark (why the standard reading is excluded by Löwenheim–Skolem). The construction stays within the general class precisely because the sort-2 witnesses are taken from the given . It cannot reach the standard reading by an all-interpretations argument: by comprehension_atom the formula is -valid, yet a general model whose omits the diagonal refutes it, so it is not -valid. Thus , and no range-relative Löwenheim–Skolem argument can bridge the two; the elementary restriction of Deep'_to_MinS cannot be relaxed to all interpretations. A structured Isabelle development of the argument above is provided as MS0inHOL_lowenheim_skolem.thy: the coincidence and reindexing lemmas, the two-sorted hull ls_hull (with its countable Tarski-Vaught construction skolem_hull and the truth preservation truth_pres it yields), the assembled converse, the elementary-substructure relation with DownwardLowenheimSkolem and Deep'_to_MinS, and this non-reduction remark are written out in full and machine-checked under Isabelle2025-2.
B Rendered Isabelle/HOL sources
For completeness every theory file of the development is rendered here as a syntax-highlighted source figure (the five theories already presented in the body — the deep embedding, the maximal- and minimal-shallow embeddings, faithfulness, and the experiments — are not repeated here). Long theories are split into consecutive parts of at most eighty lines; the line-number gutter is continuous, so the parts read as one listing. The full session (file ROOT) loads all theories in dependency order.
C. Benzmüller & D. Kirchner
1 theory MSOinHOL_preliminaries imports Main begin 3 —<Some global settings.> declare[[syntax_ambiguity_warning=false]] nitpick_params[user_axioms,expect=genuine] 4 —<Declarations shared between the deep, maximal-shallow, and minimal-shallow embeddings of MSO in HOL.> 5 typedec1 D —<Domain of individuals.> 6 type_synonym R = nat —<Binary relation symbols (encoded as naturals).> 7 type_synonym V = nat —<First-order variable symbols (encoded as naturals).> 8 type_synonym V2 = nat —<Second-order (monadic) variable symbols (encoded as naturals).> 9 type_synonym R = "D⇒D⇒bool" —<Binary relations on individuals.> 10 type_synonym I = "R⇒R" —<Interpretations of relation symbols.> 11 type_synonym E = "V⇒D" —<First-order variable assignments.> 12 type_synonym Q = "V2⇒(D⇒bool)" —<Second-order variable assignments.> 13 type_synonym D = "D⇒bool" —<First-order domain restrictions (subsets of D as predicates).> 14 type_synonym P = "(D⇒bool)⇒bool" —<Second-order domain restrictions (collections of sets as predicates).> 15 —<Pointwise update of first-order variable assignments.> 16 definition EnvMod::"ℰ⇒V⇒D⇒ℰ" (["←"] [110,0,0] 110) where "g[x←d] ≡ λz. if z = x then d else g z" 17 —<Pointwise update of second-order variable assignments (distinct notation, angle brackets).> 18 definition SetMod::"ℰ⇒V2⇒(D⇒bool)⇒ℰ" ("←") [110,0,0] 110) where "G(X←S) ≡ λZ. if Z = X then S else G Z" 19 —<Standard lemmas about first-order variable-assignment update.> 20 lemma L1 [simp]: "x ≠ y ⇒ (g(y←d)) x = g x" by (simp add: EnvMod_def) 21 lemma L2: "a ≠ c ⇒ g[a←d].[c←d] = g[c←d].[a←d]." by (auto simp: EnvMod_def) 22 lemma L3 [simp]: "(g[a←d]) a = d" by (simp add: EnvMod_def) 23 lemma L4 [simp]: "g[a←d].[a←d] = g[a←d]." by (auto simp: EnvMod_def) 24 —<Standard lemmas about second-order variable-assignment update.> 25 lemma M1 [simp]: "X ≠ Y ⇒ (G(Y←S)) X = G X" by (simp add: SetMod_def) 26 lemma M2: "A ≠ C ⇒ G(A←S_1)(C←S_2) = G(C←S_2)(A←S_1)" by (auto simp: SetMod_def) 27 lemma M3 [simp]: "(G(A←S)) A = S" by (simp add: SetMod_def) 28 lemma M4 [simp]: "G(A←S_1)(A←S_2) = G(A←S_2)" by (auto simp: SetMod_def) 29 —<Bounded quantifiers: <∀x:D. φ> stands for <∀x. D x → φ x> and <∃x:D. φ> stands for <∃x. D x ∧ φ x>.> 30 abbreviation "BAI D φ" ≡ ∀x. D x —→ φ x" syntax "BAI": "pttrn⇒logic⇒bool⇒bool" ("(3∀(∩)/") [0,0,10]10) 31 translations "∀x:D. φ" ⇒ "CONST BAI D (λx. φ)" 32 abbreviation "BEX D φ" ≡ ∃x. D x ∧ φ x" syntax "BEX": "pttrn⇒logic⇒bool⇒bool" ("(3∃(∩)/") [0,0,10]10) 33 translations "∃x:D. φ" ⇒ "CONST BEX D (λx. φ)" 34 —<Set-as-predicate operations, range, and the universal domain (polymorphic; used for both sorts).> 35 abbreviation "Into" (infix "into" 100) where "f into D ≡ ∀x. D (f x)" 36 abbreviation "Range" where "Range f ≡ λx. ∃y. x = f y" 37 abbreviation "Onto" (infix "onto" 100) where "f onto D ≡ D = Range" 38 abbreviation "Subset" (infix "⊆" 100) where "A ⊆ B ≡ ∀x. A x —→ B x" 39 abbreviation "Union" (infix "∪" 110) where "A ∪ B ≡ λx. A x ∨ B x" 40 abbreviation "Univ" where "Univ ≡ λx. True" 41 —<Surjectivity onto the universal predicate coincides with HOL surjectivity.> 42 lemma onto_Univ: "surj f = (f onto Univ)" by (auto simp: surj_def fun_eq_iff) 43 —<Backward implication; useful for stating equivalences in two directions.> 44 abbreviation Bimp (infix "——" 50) where "φ ← ψ ≡ ψ —→ φ" 45 end
Fig. 6. Theory MSOinHOL_preliminaries.thy: the shared type declarations, the two variable-assignment update operators and with their companion lemmata, the bounded quantifiers, and the polymorphic set-as-predicate operations.
1 theory MSOinHOL_shallow_minimal imports MSOinHOL_faithfulness_local
2 begin
3 —<Constants-only presentation: a global interpretation of the minimal shallow embedding.>
4 constants II::I gg::£ GG::£
5 global_interpretation MinS II gg GG .
6 —<Re-introduce the locale-internal notation at the global level.>
7 notation AtmM ("_m"(__.*)) and PrdM ("_m"(__.*)) and NegM ("_m"_[58]59)
8 and AndM (infixr "X_m" 56) and ExM (binder "X_m" 53) and ExM2 (binder "X_m" 53)
9 and OrM (infixr "Y_m" 54) and ImpM (infixr "Y_m" 55) and IffM (infixr "Y_m" 54)
10 and AllM (binder "Y_m" 53) and AllM2 (binder "Y_m" 53) and ValM ("=" 9) and DpToShM ("(")
11 end
Fig. 7. Theory MSOinHOL_shallow_minimal.thy: the constants-only global_interpretation of MinS that re-issues the locale notation at the level of three uninterpreted constants II,gg,GG.
1 theory MSOinHOL_faithfulness imports MSOinHOL_shallow_minimal
2 begin
3 —<Re-issuing the locale faithfulness theorems at the constants level.>
4 —<Deep ---- maximal shallow.>
5 theorem "((I,D,E),g,G ≡ [φ]) ↔ ((I,D,E),g,G ≡ d φ)" using FaithfulSDlem .
6 theorem "((= 5 [φ]) ↔ (= d φ)" using FaithfulSD .
7 —<Deep ---- minimal shallow, relative to the ranges of the chosen assignments gg and GG.>
8 theorem "([φ]) ↔ ((I,Range gg,Range GG),gg,GG ≡ d φ)" using FaithfulMDlem .
9 theorem "((= m [φ]) ↔ ((I,Range gg,Range GG),gg,GG ≡ d φ)" using FaithfulMD .
10 theorem "([φ]) ↔ ((I,Range gg,Range GG),gg,GG ≡ 5 [φ])" using FaithfulMSlem .
11 theorem "((= m [φ]) ↔ ((I,Range gg,Range GG),gg,GG ≡ 5 [φ])" using FaithfulMS .
12 —<Global form across all interpretations and the one-directional bridge to full deep validity.>
13 theorem "((yl gg GG, (= m (MinS.DpToShM II gg GG))) = (yl g G, ((I,Range g,Range G),g,G ≡ d φ))" using FaithfulMS_all by (simp add: MinS.ValM_def)
14 theorem "((= d φ) ⇒ ((yl gg GG, (= m (MinS.DpToShM II gg GG φ)))" using Deep_to_MinS by (simp add: MinS.ValM_def)
15 —<Consistency check.>
16 lemma True nitpick[satisfy] oops
17 end
Fig. 8. Theory MSOinHOL_faithfulness.thy: the locale faithfulness theorems re-issued at the constants level (deep↔maximal- and deep↔minimal-shallow correspondences, the all-interpretations theorem, and the one-directional bridge to deep validity).
C. Benzmüller & D. Kirchner
1 theory MSOinHOL_deep_subst_lemma imports MSOinHOL_deep 2 begin 3 —<Part A: first-order variable machinery.> 4 —<Free and bound first-order variable occurrences.> 5 primrec is_free (infix "free_in" 900) where 6 "x free_in (r^d(u,v)) = (x = u ∨ x = v)" 7 | "x free_in (X^d(z)) = (x = z)" 8 | "x free_in (-^d_φ) = (x free_in_φ)" 9 | "x free_in (φ ∧^d ψ) = (x free_in_φ ∨ x free_in_ψ)" 10 | "x free_in (∃^d_Y, φ) = (x free_in_φ ∧ x ≠ y)" 11 | "x free_in (∃^d_Y, φ) = (x free_in_φ)" 12 abbreviation is_not_free (infix "not_free_in" 900) where "x not_free_in φ ≡ -(x free_in_φ)" 13 fun is_bound (infix "bound_in" 900) where 14 "x bound_in (r^d(u,v)) = False" 15 | "x bound_in (X^d(z)) = False" 16 | "x bound_in (-^d_φ) = (x bound_in_φ)" 17 | "x bound_in (φ ∧^d ψ) = (x bound_in_φ ∨ x bound_in_ψ)" 18 | "x bound_in (∃^d_Y, φ) = (x = y ∨ x bound_in_φ)" 19 | "x bound_in (∃^d_Y, φ) = (x bound_in_φ)" 20 abbreviation is_not_bound (infix "not_bound_in" 900) where "x not_bound_in φ ≡ -(x bound_in_φ)" 21 abbreviation occurs (infix "occurs_in" 900) where "x occurs_in φ ≡ x free_in_φ ∨ x bound_in_φ" 22 abbreviation not_in (infix "not_in" 900) where "x not_in φ ≡ x not_free_in_φ ∧ x not_bound_in_φ" 23 —<A fresh first-order variable: strictly larger than every first-order variable occurring in φ.> 24 primrec fresh ("fresh_") where 25 "fresh (r^d(u,v)) = max (u+1) (v+1)" 26 | "fresh (X^d(z)) = z+1" 27 | "fresh (-^d_φ) = fresh_φ" 28 | "fresh (φ ∧^d ψ) = max (fresh_φ) (fresh_ψ)" 29 | "fresh (∃^d_X, φ) = max (x+1) (fresh_φ)" 30 | "fresh (∃^d_Y, φ) = fresh_φ" 31 lemma L5: "x bound_in φ ⇒ x < (fresh_φ)" by (induct φ) auto 32 lemma L6: "x free_in φ ⇒ x < (fresh_φ)" by (induct φ) auto 33 lemma L7: ("fresh_φ) not_in φ" using L5 L6 by blast 34 lemma L8: "max (fresh_φ) (fresh_ψ) not_free_in φ" by (metis L6 L7 max.absorb3 max_def) 35 lemma L9: "max (fresh_φ) (fresh_ψ) not_bound_in φ" by (metis L5 L7 max.absorb3 max_def) 36 lemma L10: "max (fresh_φ) (fresh_ψ) not_free_in φ" by (metis L8 max commute) 37 lemma L11: "max (fresh_φ) (fresh_ψ) not_bound_in φ" by (metis L9 max commute) 38 —irrelevance lemma: updating a non-free first-order variable does not affect truth.> 39 lemma L12: "y not_free_in φ ⇒ ((I,D,E),g(y—d),G) = (I,D,E),g,G) = d_φ" by (induct φ arbitrary; g G; simp; metis L4 L2) 40 —<First-order variable-for-variable substitution. The second-order binder descends transparently.> 41 primrec Subst ("_—") where 42 "x-z = r^d((if x = u then z else u), (if x = v then z else v))" 43 | "x-z = X^d(if x = w then z else w)" 44 | "x-z = -^d(x-z)" 45 | "[x-z](φ ∧^d ψ) = (x-z ∧^d x-z)" 46 | "[x-z](∃^d_Y, φ) = (if x = y then (∃^d_Y, φ) else (∃^d_Y, x-z))" 47 | "[x-z](∃^d_Y, φ) = (∃^d_Y, x-z)" 48 lemma L13 [simp]: "size x-z = size φ" by (induct φ) auto 49 lemma L14 [simp]: "x-x = φ" by (induct φ) auto 50 lemma L15: assumes "x ≠ a" shows "a-z = a-x" using assms by (induct φ) auto 51 lemma L16 [simp]: assumes "a ≠ x" shows "a not_free_in (a-x)" using assms by (induct φ) auto 52 —Size-based induction principle (size-based on both existential binders).> 53 lemma SInduct: 54 assumes "[r u v, P (r^d(u,v))]" 55 and "[X z, P (X^d(z))]" 56 and "[φ, size φ ≤ size φ] ⇒ P ψ] ⇒ P (−^d_φ)" 57 and "[φ, size φ ≤ size φ + size φ] ⇒ P χ] ⇒ P (φ ∧^d ψ)" 58 and "[φ, size φ ≤ size φ] ⇒ P ψ] ⇒ P (∃^d_Y, φ)" 59 and "[φ, size φ ≤ size φ] ⇒ P ψ] ⇒ P (∃^d_Y, φ)" 60 shows "P φ" 61 using assms proof (induct "size φ" arbitrary; φ rule: less_induct) case less thus ?case by (induct φ) auto qed 62 —<Stronger induction: structural for the propositional cases, size-based for the two binders.> 63 lemma QInduct: 64 assumes "[r u v, P (r^d(u,v))]" 65 and "[X z, P (X^d(z))]" 66 and "[φ, P φ] ⇒ P (−^d_φ)" 67 and "[φ, P φ] ⇒ P (φ ∧^d ψ)" 68 and "[φ, P φ] ⇒ P (φ ∧^d ψ)" 69 and "[φ, P φ] ⇒ P (φ ∧^d ψ)" 70 and "[φ, P φ] ⇒ P (φ ∧^d ψ)" 71 shows "P φ" 72 using assms by (induct φ rule: SInduct) auto
Fig. 9. Theory MSOinHOL_deep_subst_lemma.thy (Part 1 of 3): Part A (first-order variables) — is_free, is_bound, fresh with their consequence lemmata, the irrelevance lemma L12, variable-for-variable substitution, and the size-based induction principles SInduct/QInduct.
73 — Substitutability predicate: z may safely replace x in φ without capture. 74 primrec SubstitutableForIn ("_ is_subst_for_in_") [999,1,999] 999 where 75 "z is_subst_for_x in (r^d(u,v)) = True" 76 | "z is_subst_for_x in (X^d(w)) = True" 77 | "z is_subst_for_x in (-^d_φ) = (z is_subst_for_x in φ)" 78 | "z is_subst_for_x in (φ ∧^d_φ) = (z is_subst_for_x in φ ∧ z is_subst_for_x in φ)" 79 | "z is_subst_for_x in (∃^d_φ, φ) = (y = x ∨ (x not_free_in φ ∨ y ≠ z) ∧ z is_subst_for_x in φ)" 80 | "z is_subst_for_x in (∃^d_Y, φ) = (z is_subst_for_x in φ)" 81 — Substitution lemma: a syntactic z-for-x substitution corresponds to updating the assignment. 82 lemma SubstitutionLemma [simp]: 83 assumes "z is_subst_for_x in φ" 84 shows "((I,D,E),g,G) =^d ((x←z)[φ])) = ((I,D,E),g[x←(g z)],G) =^d_φ)" 85 using assms by (induction φ arbitrary): g G; auto simp; L12 L2) 86 — Alphabetic renaming preparing capture-avoiding substitution. 87 fun ren_for_subst where 88 "ren_for_subst x z (r^d(u,v)) = r^d(u,v)" 89 | "ren_for_subst x z (X^d(w)) = X^d(w)" 90 | "ren_for_subst x z (-^d_φ) = -^d-ren_for_subst x z φ)" 91 | "ren_for_subst x z (φ ∧^d_φ) = (ren_for_subst x z φ ∧ ren_for_subst x z φ)" 92 | "ren_for_subst x z (∃^d_φ, φ) = (if y = z ∧ x free_in φ) then let f = max (fresh_φ) (z+1); φ' = y←f in (∃^d_φ, ren_for_subst x z φ') else ∃^d_φ, ren_for_subst x z φ)" 93 | "ren_for_subst x z (∃^d_Y, φ) = ∃^d_Y, ren_for_subst x z φ" 94 | "ren_for_subst x z (∃^d_Y, φ) = ∃^d_Y, ren_for_subst x z φ" 95 lemma L17 [simp]: "size (ren_for_subst x z φ) = size_φ" by (induct φ arbitrary): z X rule: Qinduct; simp add: Let_def) 96 lemma L18: "x not_in φ ⇒ α is_subst_for β in φ" by (induct φ) auto 97 lemma L19: "x free_in φ ⇒ y ≠ x ⇒ x free_in y←z" by (induct φ) auto 98 lemma L20 [simp]: "x free_in ren_for_subst x z φ = (x free_in φ)" 99 by (induct φ rule: Qinduct; simp add: Let_def) (metis L16 L6 L7 L19 max.absorb3 max_def_raw) 100 lemma L21: "((I,D,E),g,G) =^d_φ) = ((I,D,E),g,G) =^d (ren_for_subst x z φ)" by (induct φ arbitrary): z g G rule: Qinduct; simp add: Let_def; smt (verit) L12 L18 L2 L3 L5 L6 SubstitutionLemma max.strict_order_off max_def) 101 lemma L22: "z is_subst_for_x in (ren_for_subst x z φ)" by (induct φ rule: Qinduct; simp; metis L13 SubstitutableForIn.simp(s) Suc_n_not_l_e_n dual_order.refl max.cobounded:2) 102 lemma L23: "x is_subst_for_x in φ" by (induct φ) auto 103 lemma L24: "x not_free_in φ ⇒ x←z = φ" by (induct φ) auto 104 lemma L26 [simp]: "z bound_in x←y = z bound_in φ" by (induct φ) auto 105 — Safe (capture-avoiding) first-order substitution: rename first, then substitute. 106 definition ren_subst ("_←r") where "x←z](φ) = [x←z](ren_for_subst x z φ)" 107 lemma L27 [simp]: "((I,D,E),g,G) =^d x←z) = ((I,D,E),g[x←g z],G) =^d_φ" using L21 L22 ren_subst_def by auto 108 lemma L28 [simp]: "size (x←z) = size_φ" by (induct φ rule: Qinduct) (auto simp: ren_subst_def Let_def) 109 lemma L29: "g onto D ⇒ ((I,D,E),g,G) =^d (∃^d_x, φ)) = (∃z, (I,D,E),g,G) =^d (x←z)" by (induct φ arbitrary): l g X rule: Qinduct; simp; blast) 110 — Part B: second-order (monadic) variable machinery. 111 primrec is_free2 (infix "free2_in" 900) where 112 "x free2_in (r^d(u,v)) = False" 113 | "x free2_in (Y^d(z)) = (X = Y)" 114 | "x free2_in (-^d_φ) = (X free2_in φ)" 115 | "x free2_in (φ ∧^d_φ) = (X free2_in φ ∨ X free2_in φ)" 116 | "x free2_in (∃^d_φ, φ) = (X free2_in φ)" 117 | "x free2_in (∃^d_Y, φ) = (X free2_in φ ∧ X ≠ Y)" 118 abbreviation is_not_free2 (infix "not_free2_in" 900) where "X not_free2_in φ ≡ - (X free2_in φ)" 119 fun is_bound2 (infix "bound2_in" 900) where 120 "x bound2_in (r^d(u,v)) = False" 121 | "x bound2_in (Y^d(z)) = False" 122 | "x bound2_in (-^d_φ) = (X bound2_in φ)" 123 | "x bound2_in (φ ∧^d_φ) = (X bound2_in φ ∨ X bound2_in φ)" 124 | "x bound2_in (∃^d_φ, φ) = (X bound2_in φ)" 125 abbreviation is_not_bound2 (infix "not_bound2_in" 900) where "X not_bound2_in φ ≡ - (X bound2_in φ)" 126 abbreviation not_in2 (infix "not2_in" 900) where "X not2_in φ ≡ X not_free2_in φ ∧ X not_bound2_in φ" 127 primrec fresh2 where 128 "fresh2 (r^d(u,v)) = 0" 129 | "fresh2 (Y^d(z)) = Y+1" 130 | "fresh2 (-^d_φ) = fresh2_φ" 131 | "fresh2 (φ ∧^d_φ) = max (fresh2_φ) (fresh2_φ)" 132 | "fresh2 (∃^d_φ, φ) = fresh2_φ" 133 | "fresh2 (∃^d_Y, φ) = max (fresh2_φ)" 134 lemma N5: "X bound2_in φ ⇒ X < (fresh2_φ)" by (induct φ) auto 135 lemma N6: "X free2_in φ ⇒ X < (fresh2_φ)" by (induct φ) auto 136 lemma N7: "fresh2_φ) not2_in φ" by (metis N5 N6 by blast) 137 lemma N8: "max (fresh2_φ) (fresh2_φ) not_free2_in φ" by (metis N6 N7 max.absorb3 max_def) 138 lemma N9: "max (fresh2_φ) (fresh2_φ) not_bound2_in φ" by (metis N5 N7 max.absorb3 max_def) 139 lemma N10: "max (fresh2_φ) (fresh2_φ) not_free2_in φ" by (metis N8 max commute) 140 lemma N11: "max (fresh2_φ) (fresh2_φ) not_bound2_in φ" by (metis N9 max commute)
Fig.10. Theory MS0inHOL_deep_substlemma.thy (Part 2 of 3): the substitutability predicate, SubstitutionLemma, alphabetic renaming ren_for_subst, safe substitution ren_subst, and L17–L29 (Part A concluded); then the start of Part B (second-order variables) — is_free2, is_bound2, fresh2, and N5–N11.
C. Benzmüller & D. Kirchner
146 —<irrelevance lemma for second-order assignments.> 147 lemma N12: "Y not_free2_in φ ⇒ ((I,D,E),g,G(Y←S) ⊢^d φ) = ((I,D,E),g,G ⊢^d φ)" 148 by (induct φ arbitrary: g G; simp; metis M4 M2) 149 —<Second-order variable-for-variable substitution. The first-order binder descends transparently.> 150 primrec Subst2 ("_←_2") where 151 "([X←_2Z][r^d(u,v)) = r^d(u,v)]" 152 "([X←_2Z][Y^d(w)) = (if X = Y then Z else Y)^d(w)") 153 "([X←_2Z][∅_φ]) = -^d(X←_2Z)" 154 "([X←_2Z][φ ∧^d ψ)) = ([X←_2Z][φ] ∧^d X←_2Z)" 155 "([X←_2Z][∅^d y, φ)) = (∃^d y, X←_2Z)" 156 "([X←2Z][∅^d y, φ)) = (if X = Y then (∃^d_2Y, φ) else (∃^d_2Y, X←_2Z))" 157 lemma N13 [simp]: "size X←_2Z = size φ" by (induct φ; auto) 158 lemma N14 [simp]: "(X←_2X) = φ" by (induct φ; auto) 159 lemma N16 [simp]: assumes "A ≠ X" shows "A not_free2_in (A←_2X)" using assms_by (induct φ) auto 160 primrec SubstitutableForIn2 (" is'_subst2' for _ in " [999,1,999] 999) where 161 "Z is_subst2_for X in (r^d(u,v)) = True" 162 "Z is_subst2_for X in (Y^d(w)) = True" 163 "Z is_subst2_for X in (-^d_φ) = (Z is_subst2_for X in φ)" 164 "Z is_subst2_for X in (φ ∧^d ψ) = (Z is_subst2_for X in φ ∧ Z is_subst2_for X in ψ)" 165 "Z is_subst2_for X in (∃^d y, φ) = (Z is_subst2_for X in φ)" 166 "Z is_subst2_for X in (∃^d y, φ) = (Y = X ∨ (X not_free2_in φ ∨ Y ≠ Z) ∧ Z is_subst2_for X in φ)" 167 lemma SubstitutionLemma2 [simp]: 168 assumes "Z is_subst2_for X in φ" shows "((I,D,E),g,G ⊢^d (X←_2Z)) = ((I,D,E),g,G(X←(G Z)) ⊢^d φ)" using assms_by (induction φ arbitrary: g G; auto simp; N12 M2) 169 fun ren_for_subst2 where 170 "ren_for_subst2 X Z (r^d(u,v)) = r^d(u,v)" 171 "ren_for_subst2 X Z (Y^d(w)) = Y^d(w)" 172 "ren_for_subst2 X Z (-^d_φ) = -^d-ren_for_subst2 X Z φ)" 173 "ren_for_subst2 X Z (φ ∧^d ψ) = (ren_for_subst2 X Z φ ∧^d ren_for_subst2 X Z ψ)" 174 "ren_for_subst2 X Z (∃^d y, φ) = ∃^d y, ren_for_subst2 X Z φ" 175 "ren_for_subst2 X Z (∃^d_2Y, φ) = (if Y = Z ∧ X free2_in φ) 176 then let f = max (fresh2 φ) (Z+1); φ' = Y←_2f in (∃^d_2f, ren_for_subst2 X Z φ') 177 else ∃^d_2Y, ren_for_subst2 X Z φ)" 178 lemma N17 [simp]: "size (ren_for_subst2 X Z φ) = size φ" by (induct φ arbitrary: Z X rule: QInduct; simp add: Let_def) 179 lemma N18: "α not2_in φ ⇒ α is_subst2_for β in φ" by (induct φ) auto 180 lemma N19: "X free2_in φ ⇒ Y ≠ X ⇒ X free2_in Y←_2Z" by (induct ψ) auto 181 lemma N20 [simp]: "X free2_in ren_for_subst2 X Z φ = (X free2_in φ)" 182 by (induct φ rule: QInduct; simp add: Let_def) (metis N16 N6 N7 N19 max.absorb3 max_def_raw) 183 lemma N21: "((I,D,E),g,G ⊢^d φ) = ((I,D,E),g,G ⊢^d (ren_for_subst2 X Z φ))" by (induct φ arbitrary: Z g G) 184 rule: QInduct; simp add: Let_def; smt (verit) N12 N18 M2 M3 N5 N6 SubstitutionLemma2 max_strict_order_if max_def) 185 lemma N22: "Z is_subst2_for X in (ren_for_subst2 X Z φ)" by (induct φ rule: QInduct; simp; metis N13 SubstitutableForIn2.simp(6) Suc_n_not_i_n dual_order.refl max.cobounded2) 186 definition ren_subst2 ("←2") where "(X←_2Z) = [X←_2Z](ren_for_subst2 X Z φ)" 187 lemma N27 [simp]: "((I,D,E),g,G ⊢^d X←_2Z) = ((I,D,E),g,G(X←G Z)) ⊢^d φ)" using N21 N22 ren_subst2_def by auto 188 lemma N28 [simp]: "size (X←_2Z) = size φ" by (induct φ rule: QInduct) (auto simp; ren_subst2_def Let_def) 189 lemma N29: "G onto E ⇒ ((I,D,E),g,G ⊢^d (∃^d X, φ)) = (∃Z, ((I,D,E),g,G ⊢^d (X←_2Z))))" 190 by (induct φ arbitrary: I g G X rule: QInduct; simp; blast) 191 end
Fig. 11. Theory MS0inHOL_deep_subst lemma.thy (Part 3 of 3): Part B (second-order variables) concluded — the irrelevance lemma N12, second-order substitution Subst2, SubstitutionLemma2, renaming ren_for_subst2/ren_subst2, and N17–N29.
1 theory MSOinHOL_subst_extras imports MSOinHOL_deep_subst_lemma 2 begin 3 —<Explicit rename-evaluation lemmas: renaming a bound variable to a fresh f and updating the assignment 4 preserves truth -- the semantic core behind L21 / N21 (a future smt-free reproof).> 5 —<First-order: rename y to a fresh f, then evaluate.> 6 lemma rename_eval: 7 assumes "fresh φ ≤ f" and "y < f" shows "((I,D,E),g[f←d],G ⊢= d y←f) = ((I,D,E),g[y←d],G ⊢= d φ)" 8 proof. 9 have fy: "f ≠ y" using assms(2) by simp 10 have nf: "f not_free_in φ" using assms(1) by (meson L6 leD) 11 have "f not_in φ" using assms(1) by (meson L5 L6 leD) 12 hence sub: "f is_subst_for y in φ" by (rule L18) 13 have swap: "(g[f←d])[y←d] = (g[y←d])[f←d]" using fy by (rule L2) 14 have "((I,D,E),g[f←d],G ⊢= d y←f) = ((I,D,E),g[f←d])[y←((g[f←d]) f)],G ⊢= d φ)" 15 using sub by (rule SubstitutionLemma) 16 also have "... = ((I,D,E),g(f←d))[y←d],G ⊢= d φ)" by simp 17 also have "... = ((I,D,E),g(y←d))[f←d],G ⊢= d φ)" using swap by simp 18 also have "... = ((I,D,E),g(y←d],G ⊢= d φ)" using nf by (simp add: L12) 19 finally show ?thesis, 20 qed 21 —<Second-order: rename Y to a fresh f, then evaluate. (The monadic-set twin of rename_eval.)> 22 lemma rename_eval2: 23 assumes "fresh2 φ ≤ f" and "Y < f" shows "((I,D,E),g,G(f←S) ⊢= d Y←2f) = ((I,D,E),g,G(Y←S) ⊢= d φ)" 24 proof 25 have fy: "f ≠ Y" using assms(2) by simp 26 have nf: "f not_free2_in φ" using assms(1) by (meson N6 leD) 27 have "f not2_in φ" using assms(1) by (meson N5 N6 leD) 28 hence sub: "f is_subst2_for Y in φ" by (rule N18) 29 have swap: "G(f←S)(Y←S) = G(Y←S)(f←S)" using fy by (rule M2) 30 have "((I,D,E),g,G(f←S) ⊢= d Y←2f) = ((I,D,E),g,G(f←S))(Y←((G(f←S)) f)) ⊢= d φ)" 31 using sub by (rule SubstitutionLemma2) 32 also have "... = ((I,D,E),g,(G(f←S))(Y←S) ⊢= d φ)" by simp 33 also have "... = ((I,D,E),g,(G(Y←S))(f←S) ⊢= d φ)" using swap by simp 34 also have "... = ((I,D,E),g,G(Y←S) ⊢= d φ)" using nf by (simp add: N12) 35 finally show ?thesis, 36 qed 37 end
Fig. 12. Theory MSOinHOL_subst_extras.thy: the explicit rename-evaluation lemmas rename_eval (first-order) and rename_eval2 (second-order).
C. Benzmüller & D. Kirchner
1 theory MSOinHOL_comprehension imports MSOinHOL_deep_subst_lemma
2 begin
3 —<Monadic comprehension as a derived schema: under the full second-order domain (@{text "ValD"}), E = Univ)
4 comprehension holds for every φ with X not free; the witness is the set defined by φ.>
5 theorem comprehension_schema: assumes "X not_free2_in φ" shows "|=^d (∃^d_2X. ∀^d_x. ((X^d(x)) —^d φ))"
6 unfolding ValD'_def
7 proof (intro all))
8 fix l g G
9 let ?S = "λd. (l.Univ,Univ), g[X ← d], G |=^d φ"
10 have "(l.Univ,Univ), g,G (X ← ?S) |=^d (∀^d_x. ((X^d(x)) —^d φ))" using assms by (simp add; DefD N12)
11 thus "(l.Univ,Univ), g,G |=^d (∃^d_2X. ∀^d_x. ((X^d(x)) —^d φ))" by auto
12 qed
13 —<Headline instance (cf. comprehension_d): the set of r-self-related individuals exists.>
14 corollary comprehension_atom: "|=^d (∃^d_2X. ∀^d_x. ((X^d(x)) —^d (r^d(x,x))))" by (rule comprehension_schema) simp
15 —<Standard vs. weak (Henkin): comprehension_schema needs E = Univ and fails for general @{text "ValD"}>
16 -- the standard-vs-Henkin gap behind the Loewenheim-Skolem problem (see the paper).>
17 end
Fig. 13. Theory MSOinHOL_comprehension.thy: the general monadic comprehension_schema over the full second-order domain with its witness, the corollary comprehension_atom, and the discussion relating comprehension to standard vs. general (Henkin-style) semantics.
1 theory MSOinHOL_experiments_classic imports MSOinHOL_deep MSOinHOL_shallow MSOinHOL_shallow_minimal begin 2 abbreviation "x::V) ≡ 1" abbreviation "y::V) ≡ 2" abbreviation "z::V) ≡ 3" 3 abbreviation "X::V2) ≡ 1" abbreviation "Y::V2) ≡ 2" abbreviation "(Z::V2) ≡ 3" 4 abbreviation "u::V) ≡ 4" abbreviation "v::V) ≡ 5" constants P::R 6 —: Boolean closure (Buch 1960; Thomas 1997) under @ (text "=") 7 lemma complement_d: "=" d (v^d) X, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d^d X^d(x))) 8 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 9 subgoal for S by (rule ex[of_ "λd. ¬ S d"])(auto simp: SetMod_def EnvMod_def) done 10 lemma intersection_d: "=" d (v^d) X, ∃ d^2 Y, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∧ d Y^d(x))) 11 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 12 subgoal for S Sa by (rule ex[of_ "λd. S d ∧ Sa d"])(auto simp: SetMod_def EnvMod_def) done 13 lemma union_d: "=" d (v^d) X, ∃ d^2 Y, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∨ d Y^d(x))) 14 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 15 subgoal for S Sa by (rule ex[of_ "λd. S d ∨ Sa d"])(auto simp: SetMod_def EnvMod_def) done 16 —: Graph operations (Courcelle 2012). 17 lemma separation_d: "=" d (v^d) X, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∧ d P^d(x,x))) 18 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 19 subgoal for I S by (rule ex[of_ "λd. S d ∧ I P d"])(auto simp: SetMod_def EnvMod_def) done 20 lemma image_d: "=" d (v^d) X, ∃ d^2 Y, ∨ d^x, (Y^d(x) —→ d ∃ y, (X^d(y) ∧ d P^d(y,x))) 21 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 22 subgoal for I S by (rule ex[of_ "λd. ∃ d' S d ∧ I P d d"])(auto simp: SetMod_def EnvMod_def) done 23 lemma preimage_d: "=" d (v^d) X, ∃ d^2 Y, ∨ d^x, (Y^d(x) —→ d ∃ y, (P^d(x,y) ∧ d X^d(y))) 24 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 25 subgoal for I S by (rule ex[of_ "λd. ∃ d' I P d d ∧ S d"])(auto simp: SetMod_def EnvMod_def) done 26 —: Reachability (Basin & Klarlund 1995): not universally valid; reflexive variant is. 27 lemma reachability_not_valid_d: "=" d (v^d) Z, ((Z^d(x) ∧ d (v^d) u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(y))) 28 unfolding DefD apply simp nitpick oops 29 lemma reachability_reflexive_d: "=" d (v^d) Z, ((Z^d(x) ∧ d (v^d) u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(x))) 30 unfolding DefD by simp 31 —: 2-colorability (Thomas 1997): refuted on $K_3S. 32 lemma two_colorability_not_valid_d: "=" d (∃ d^2 Z, ∨ d^x, ∨ d^y, (P^d(x,y) ∨ d (Z^d(x) —→ d^d Z^d(y)))) 33 unfolding DefD apply simp nitpick oops 34 —: Same landmarks in the maximal-shallow embedding: structurally identical proofs. 35 lemma complement_s: "=" d (v^d) X, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d^d X^d(x))) 36 unfolding DefS apply (intro all, simp, intro all) subgoal for S by (rule ex[of_ "λd. ¬ S d"])(auto done 37 lemma intersection_s: "=" d (v^d) X, ∃ d^2 Y, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∧ Y^d(x))) 38 unfolding DefS apply (intro all, simp, intro all) subgoal for S Sa by (rule ex[of_ "λd. S d ∧ Sa d"])(auto done 39 lemma union_s: "=" d (v^d) X, ∃ d^2 Y, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∨ d Y^d(x))) 40 unfolding DefS apply (intro all, simp, intro all) subgoal for S Sa by (rule ex[of_ "λd. S d ∨ Sa d"])(auto done 41 lemma separation_s: "=" d (v^d) X, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∧ d P^d(x,x))) 42 unfolding DefS apply (intro all, simp, intro all) subgoal for I S by (rule ex[of_ "λd. S d ∧ I P d d"])(auto done 43 lemma image_s: "=" d (v^d) X, ∃ d^2 Y, ∨ d^x, (Y^d(x) —→ d (X^d(y) ∧ d P^d(y,x))) 44 unfolding DefS apply (intro all, simp, intro all) subgoal for I S by (rule ex[of_ "λd. ∃ d' S d ∧ I P d d"])(auto done 45 lemma preimage_s: "=" d (v^d) X, ∃ d^2 Y, ∨ d^x, (Y^d(x) —→ d (∃ y, (P^d(x,y) ∧ d X^d(y)))) 46 unfolding DefS apply (intro all, simp, intro all) subgoal for I S by (rule ex[of_ "λd. ∃ d' I P d d ∧ S d"])(auto done 47 lemma reachability_not_valid_s: "=" d (v^d) Z, ((Z^d(x) ∧ d (v^d) u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(y))) 48 unfolding DefS apply (intro all) apply simp nitpick oops 49 lemma reachability_reflexive_s: "=" d (v^d) Z, ((Z^d(x) ∧ d (v^d) u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(x))) 50 unfolding DefS by simp 51 lemma two_colorability_not_valid_s: "=" d (∃ d^2 Z, ∨ d^x, ∨ d^y, (P^d(x,y) ∨ d (Z^d(x) —→ d^d Z^d(y)))) 52 unfolding DefS apply (intro all) apply simp nitpick oops 53 —: Minimal embedding: SO quantifier ranges over the countable Range GG (via nat), not all of Pow(D). 54 Nitpick can only certify a POTENTIAL countermodel. 55 lemma complement_m_not_valid: "=" d (v^d) X, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d^d X^d(x))) 56 unfolding DefM nitpick[expect=potential] oops 57 lemma intersection_m_not_valid: "=" d (v^d) X, ∃ d^2 Y, ∃ d^2 Z, ∨ d^x, (Z^d(x) —→ d (X^d(x) ∧ d Y^d(x))) 58 unfolding DefM nitpick[expect=potential] oops 59 lemma reachability_not_valid_m: "=" d (v^d) Z, ((Z^d(x) ∧ d X^d(u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(y))) 60 unfolding DefM nitpick[expect=potential] oops 61 —: Reflexive reachability: the conclusion is the first conjunct of the antecedent; genuinely valid. 62 lemma reachability_reflexive_m: "=" d (v^d) Z, ((Z^d(x) ∧ d (v^d) u, (Z^d(u) ∨ d ∨ d v, (P^d(u,v) ∨ d Z^d(v)))) ∨ d Z^d(x))) 63 unfolding DefM by simp 64 lemma two_colorability_not_valid_m: "=" d (∃ d^2 Z, ∨ d^x, ∨ d^y, (P^d(x,y) ∨ d (Z^d(x) —→ d^d Z^d(y)))) 65 unfolding DefM nitpick[expect=potential] oops 66 end
Fig. 14. Theory MSOinHOL_experiments_classic.thy: the classical MSO landmarks in the deep and maximal-shallow embeddings — Boolean closure (complement, intersection, union), monadic graph operations (separation, P-image, P-preimage), reachability, and 2-colorability — each with an explicit second-order witness via exI; and the minimal embedding, where Boolean closure and reachability fail by nitpick while reflexive reachability remains valid.
C. Benzmüller & D. Kirchner

Fig. 15. Theory MSOinHOL_experiments_locale.thy: locale-based transfer to the deep embedding — the directional reading MinS_to_Deep of FaithfulMS_all, two cosmetic rewrite rules, a schema proved inside the locale, and its one-line transfer.
1 theory MSOinHOL_lowenheim_skolem_lemmas 2 imports MSOinHOL_faithfulness_local MSOinHOL_comprehension "HOL-Library.Countable_Set" 3 begin 4 —<Supporting lemmas for the downward Löwenheim-Skolem construction in MSOinHOL lowenheim skolem. 5 This file holds the technical machinery (Skolem-witness operators wF / wS, the omega-stage iteration 6 stage_monotonicity / countability / common-stage lemmas). The main theorems live in the parent file. 7 —coincidence (generalises L12 / N12) truth depends only on the free variables of φ. Compact structured induction: 8 the binder cases use |H| after extending the agreement through the bound-variable update via EnvMod_def / SetMod_def. 9 lemma coincidence: 10 assumes |X. x free_in φ ⇒ g x = g' x and "|X. X free2_in φ ⇒ G X = G' X" 11 shows ((I,D,E),g,G|=d φ) = ((I,D,E),g',G'=d φ) 12 using assms 13 proof (induct φ arbitrary: g g' G G') 14 case (AtmD r u v) thus ?case by simp next 15 case (PrdD X z) thus ?case by simp next 16 case (NegD) have "((I,D,E),g,G|=d φ) = ((I,D,E),g',G'=d φ)" 17 using NegD.hypS NegD.prems(1,2) is_free.simp(3) is_free2.simp(3) by presburger thus ?case by simp next 18 case (AndD φ) from AndD.hypS(of g g' G G) AndD.prems show ?case by simp next 19 case (ExD y φ) have "((I,D,E),g[y←d],G|=d φ) = ((I,D,E),g[y←d],G'=d φ)" for d 20 using EnvMod_def ExD.hypS ExD.prems(1,2) is_free.simp(5) is_free2.simp(5) by presburger thus ?case by simp next 21 case (ExD2 Y φ) have "((I,D,E),g(Y←S)=d φ) = ((I,D,E),g',G'(Y←S)=d φ)" for S 22 by (rule ExD2.hypS) (use ExD2.prems in <auto simp: SetMod_def>) thus ?case by simp 23 qed 24 —The formula type F is countable (datatype over countable atoms). 25 instance F :: countable by countable datatype 26 —Pad a finite parameter list to a total assignment (default outside its range). 27 definition padA :: "D⇒D list⇒(V⇒D)" where "padA d0 xs = (λi. if i < length xs then xs ! i else d0)" 28 definition padB :: "(D⇒bool) ⇒ (D⇒bool) list⇒(V2⇒(D⇒bool))" where 29 "padB S0 Ss = (λi. if i < length Ss then Ss ! i else S0)" 30 —FO / SO Skolem witnesses for one demand, drawn from the big model (I,D,E). 31 definition wF :: "I⇒(D⇒bool) ⇒ ((D⇒bool)⇒bool) ⇒ D⇒(D⇒bool) ⇒ F⇒V⇒D list⇒(D⇒bool) list⇒D" where 32 "wF I D E d0 S0 ψ y xs Ss = (if (id. D d ∧ (I,D,E),(padA d0 xs)[y←d],(padB S0 Ss)|=d φ) 33 then (SOME d. D d ∧ (I,D,E),(padA d0 xs)[y←d],(padB S0 Ss)|=d φ) 34 else d0)" 35 definition wS :: "I⇒(D⇒bool) ⇒ ((D⇒bool)⇒bool) ⇒ D⇒(D⇒bool) ⇒ F⇒V2⇒D list⇒(D⇒bool) list⇒(D⇒bool))" where 36 "wS I D E d0 S0 ψ Y xs Ss = (if (S5. E S ∧ (I,D,E),(padA d0 xs),(padB S0 Ss)(Y←S)=d φ) 37 then (SOME S. E S ∧ (I,D,E),(padA d0 xs),(padB S0 Ss)(Y←S)=d φ) 38 else S0)" 39 lemma wF_mem: "D d0 ⇒ D (wF I D E d0 S0 ψ y xs Ss)" unfolding wF_def 40 by (cases "3d. D d ∧ (I,D,E),(padA d0 xs)[y←d],(padB S0 Ss)|=d φ); simp, metis (mono_tags,lifting) somelex) 41 lemma wS_mem: "E S0 ⇒ E (wS I D E d0 S0 ψ Y xs Ss)" unfolding wS_def 42 by (cases "3S. E S ∧ (I,D,E),(padA d0 xs),(padB S0 Ss)(Y←S)|=d φ); simp, metis (mono_tags,lifting) somelex) 43 —Witness-membership specialised to seeds @ (text "g 0") / @ (text "G 0"): no extra "D (g 0)" premise. 44 lemma wF_mem_seed: "g into D ⇒ D (wF I D E (g 0) S0 ψ y xs Ss)" by (blast intro: wF_mem) 45 lemma wS_mem_seed: "g into E ⇒ E (wS I D E d0 (G 0) ψ Y xs Ss)" by (blast intro: wS_mem) 46 —The omega-stage (FO carrier, SO carrier): step n+1 adds every wF / wS witness over parameter lists drawn from 47 the carriers at stage n. 48 primrec stage::"I⇒(D⇒bool) ⇒ ((D⇒bool)⇒bool) ⇒ (V⇒D) ⇒ (V2⇒(D⇒bool)) ⇒ nat⇒((D⇒bool)×((D⇒bool)⇒bool))" where 49 "stage I D E g G 0 = (Range g, Range G) 50 | "stage I D E g G (Suc n) = 51 ((λd. fst (stage I D E g n) d) 52 ∨ (∃) y xs Ss. (vXset xs. fst (stage I D E g n) x) 53 ∧ (vSset Ss. snd (stage I D E g n) S) ∧ d = wF I D E (g 0) (G 0) ψ y xs Ss). 54 (ΔS. snd (stage I D E g n) S) 55 ∨ (∃) Y xs Ss. (vXset xs. fst (stage I D E g n) x) 56 ∧ (vSset Ss. snd (stage I D E g n) S) ∧ S = wS I D E (g 0) (G 0) ψ Y xs Ss)) 57 —Helper: countability of a binary product (from countable_SIGMA). 58 lemma countable_Times2: "countable A ⇒ countable B ⇒ countable (A × B) 59 using countable_SIGMA[of A _ B*] by (simp add: Sigma_def) 60 —An explicit Skolem witness produced from parameters drawn from stage n sits in stage (Suc n) (FO / SO). 61 Direct from the second clause of "stage". 62 lemma fst_stage_Suc_intro: 63 "vXset xs. fst (stage I D E g N) x ⇒ vSset Ss. snd (stage I D E g N) S 64 ⇒ fst (stage I D E g G (Suc N)) (wF I D E (g 0) (G 0) ψ y xs Ss)" by (simp, blast) 65 lemma snd_stage_Suc_intro: 66 "vXset xs. fst (stage I D E g N) x ⇒ vSset Ss. snd (stage I D E g N) S 67 ⇒ snd (stage I D E g (Suc N)) (wS I D E (g 0) (G 0) ψ Y xs Ss)" by (simp, blast) 68 —coincidence applied to padded assignments built from a/b on the free-variable prefix of φ: 69 the padded truth equals the original. Drives the TV-step truth transfer automatically. 70 lemma pad_truth_eq_FO: 71 "((I,D,E),(padA d0 (map a [0..<fresh ψ]))[y←d],(padB Ss (map b [0..<fresh2 ψ]))|=d φ) = ((I,D,E),a,[y←d],b|=d φ)" 72 by (rule coincidence) (auto dest: L6 N6 simp: EnvMod_def padA_def padB_def) 73 lemma pad_truth_eq_SO: 74 "((I,D,E),(padA d0 (map a [0..<fresh ψ]),(padB Ss (map b [0..<fresh2 ψ]))[Y←S]=d φ) = ((I,D,E),a,b(Y←S)=d φ)" 75 by (rule coincidence) (auto dest: L6 N6 simp: SetMod_def padA_def padB_def)
Fig. 16. Theory MSOinHOL_lowenheim_skolem_lemmas.thy (Part 1 of 4): the supporting machinery for the Löwenheim-Skolem construction — the coincidence lemma coincidence (a two-sorted generalisation of L12/N12), the padding maps padA/padB, the Skolem-witness operators wF/wS with their membership lemmas, the ω-stage operator stage, the stage-introduction lemmas fst_stage_Suc_intro/snd_stage_Suc_intro, and the padding-truth lemmas pad_truth_eq_FO/pad_truth_eq_SO.
C. Benzmüller & D. Kirchner
76 ← The Skolem witness wF / wS realizes its demand whenever one exists in (D,E): membership in D / E plus
77 the truth on the padded assignment. Direct from 'somelex'.
78 lemma wF_realizes:
79 assumes "3d. D d ∧ ((I,D,E),(padA d0 xs)[y←d],(padB S0 Ss) |=d ψ"
80 shows "D (wF I D E d0 S0 ψ y xs Ss) ∧ ((I,D,E),(padA d0 xs)[y←wF I D E d0 S0 ψ y xs Ss],(padB S0 Ss) |=d ψ)"
81 using somelex[OF assms] assumes unfolding wF_def by simp
82 lemma wS_realizes:
83 assumes "3S. E S ∧ ((I,D,E),(padA d0 xs),(padB S0 Ss)(Y←S) |=d ψ"
84 shows "E (wS I D E d0 S0 ψ Y xs Ss) ∧ ((I,D,E),(padA d0 xs),(padB S0 Ss)(Y←wS I D E d0 S0 ψ Y xs Ss) |=d ψ)"
85 using somelex[OF assms] assumes unfolding wS_def by simp
86 ← Full Tarski-Vaught step (FO / SO): from an existential over (D,E) reachable through a, b, the wF / wS witness
87 lives in D / E and satisfies the formula relative to a, b. Core lemma for the TVfo / TVsq of skolem_hull.
88 lemma skolem_step_FO:
89 assumes "3d. D d ∧ ((I,D,E),a[y←d],b |=d ψ"
90 shows "D (wF I D E d0 S0 ψ y (map a [0..<fresh ψ]) (map b [0..<fresh2 ψ]))
91 ∧ ((I,D,E), a[y←wF I D E d0 S0 ψ y (map a [0..<fresh ψ]) (map b [0..<fresh2 ψ]))], b |=d ψ"
92 proof -
93 let ?xs = "map a [0..<fresh ψ]" and ?Ss = "map b [0..<fresh2 ψ]"
94 have "3d. D d ∧ ((I,D,E),(padA d0 ?xs)[y←d],(padB S0 ?Ss) |=d ψ" using assms by (simp add: pad_truth_eq_FO)
95 from wF_realizes[OF this] show ?thesis by (simp add: pad_truth_eq_FO)
96 qed
97 lemma skolem_step_SO:
98 assumes "3S. E S ∧ ((I,D,E),a,b(Y←S) |=d ψ"
99 shows "E (wS I D E d0 S0 ψ Y (map a [0..<fresh ψ]) (map b [0..<fresh2 ψ]))
100 ∧ ((I,D,E), a,b(Y←wS I D E d0 S0 ψ Y (map a [0..<fresh ψ]) (map b [0..<fresh2 ψ])) |=d ψ"
101 proof -
102 let ?xs = "map a [0..<fresh ψ]" and ?Ss = "map b [0..<fresh2 ψ]"
103 have "3S. E S ∧ ((I,D,E),(padA d0 ?xs),(padB S0 ?Ss)(Y←S) |=d ψ" using assms by (simp add: pad_truth_eq_SO)
104 from wS_realizes[OF this] show ?thesis by (simp add: pad_truth_eq_SO)
105 qed
106 ← The (Suc n)-stage is contained in the n-stage plus the image of wF / wS over UNIV × UNIV × (lists from n).
107 Used to derive countability of each stage by induction.
108 lemma fst_stage_Suc_subset:
109 " {d. fst (stage I D E g G (Suc n)) d} ⊆ {d. fst (stage I D E g G n) d} ∪ (λ(ψ, y, xs, Ss). wF I D E (g 0) (G 0) ψ y xs Ss)
110 (UNIV × UNIV × {xs. set xs ⊆ {d. fst (stage I D E g G n) d}) × {Ss. set Ss ⊆ {S. snd (stage I D E g G n) S})} (is "⊆ ?R")
111 proof (rule subseti, simp only: mem_Collect_eq)
112 fix d assume "fst (stage I D E g G (Suc n)) d"
113 then consider "fst (stage I D E g G n) d"
114 | ψ y xs Ss where "∀x cset xs. fst (stage I D E g G n) x" "∀S cset Ss. snd (stage I D E g G n) S"
115 "d = wF I D E (g 0) (G 0) ψ y xs Ss" by auto
116 thus "d ∈ ?R" by cases (auto intro: rev_image_eq[(where x="(_ _ _ )])
117 qed
118 lemma snd_stage_Suc_subset:
119 " {S. snd (stage I D E g G (Suc n)) S} ⊆ {S. snd (stage I D E g G n) S} ∪ (λ(ψ, Y, xs, Ss). wS I D E (g 0) (G 0) ψ Y xs Ss)
120 (UNIV × UNIV × {xs. set xs ⊆ {d. fst (stage I D E g G n) d}) × {Ss. set Ss ⊆ {S. snd (stage I D E g G n) S})} (is "⊆ ?R")
121 proof (rule subseti, simp only: mem_Collect_eq)
122 fix S assume "snd (stage I D E g G (Suc n)) S"
123 then consider "snd (stage I D E g G n) S"
124 | ψ Y xs Ss where "∀x cset xs. fst (stage I D E g G n) x" "∀S cset Ss. snd (stage I D E g G n) S"
125 "S = wS I D E (g 0) (G 0) ψ Y xs Ss" by auto
126 thus "S ∈ ?R" by cases (auto intro: rev_image_eq[(where x="(_ _ _ )])
127 qed
128 ← Monotonicity of the 'stage' chain: a single-step extension lifts to arbitrary suffixes.
129 lemma fst_stage_mono: "m ≤ n ⇒ fst (stage I D E g G m) d ⇒ fst (stage I D E g G n) d"
130 by (induct n) (auto simp del: stage.simps simp: stage.simps(2) le_Suc_eq)
131 lemma snd_stage_mono: "m ≤ n ⇒ snd (stage I D E g G m) S ⇒ snd (stage I D E g G n) S"
132 by (induct n) (auto simp del: stage.simps simp: stage.simps(2) le_Suc_eq)
133 ← Finitely many parameters in the omega-union all share a common stage.
134 lemma common_stage_lifted:
135 assumes hx: "∀x cset xs. ∃n. fst (stage I D E g G n) x" and hS: "∀S cset Ss. ∃n. snd (stage I D E g G n) S"
136 shows "∃N. (∀x cset xs. fst (stage I D E g G N) x) ∧ (∀S cset Ss. snd (stage I D E g G N) S)"
137 proof -
138 obtain fX where fX: "∀x cset xs. fst (stage I D E g G (fX x)) x" using hx by metis
139 obtain fS where fS: "∀S cset Ss. snd (stage I D E g G (fS S)) S" using hS by metis
140 let ?N = "Max (insert 0 (fX set xs ∪ fS set Ss))"
141 have bX: "fX x ≤ ?N" if "x ∈ set xs" for x using that by (simp add: Max_ge)
142 have bS: "fS S ≤ ?N" if "S ∈ set Ss" for S using that by (simp add: Max_ge)
143 from bX fX fst_stage_mono have "∀x cset xs. fst (stage I D E g G N) x" by blast
144 moreover from bS fs snd_stage_mono have "∀S cset Ss. snd (stage I D E g G N) S" by blast
145 ultimately show ?thesis by blast
146 qed
Fig. 17. Theory MS0inHOL_lovenheim_skolem_lemmas.thy (Part 2 of 4): the witness-realisation lemmas wF_realizes/wS_realizes, the per-step Skolem closure skolem_step_FO/skolem_step_SO, the subset bookkeeping fst_stage_Suc_subset/snd_stage_Suc_subset, the stage monotonicity fst_stage_mono/snd_stage_mono, and the common-stage lemma common_stage_lifted.
147 —<A wF / wS witness built from hull-valued parameters is itself in the hull. Combines common_stage_lifed 148 with the single_Suc-step intro>s 149 lemma wF_in_omega_union: 150 assumes "x≤set xs. 3n. fst (stage I D E g G n) x" and "y≤set Ss. 3n. snd (stage I D E g G n) S" 151 shows "3n. fst (stage I D E g G n) (wF I D E (g 0) (G 0) y xs Ss)" 152 using common_stage_lifed[OF assms] by (meson fst_stage_Suc_intro) 153 lemma wS_in_omega_union: 154 assumes "x≤set xs. 3n. fst (stage I D E g G n) x" and "y≤set Ss. 3n. snd (stage I D E g G n) S" 155 shows "3n. snd (stage I D E g G n) (wS I D E (g 0) (G 0) y Y xs Ss)" 156 using common_stage_lifed[OF assms] by (meson snd_stage_Suc_intro) 157 —<Tarski-Vaught closure of the omega-union: combines 'skolem_step_FQ/SO' with 'wF/wS_in_omega_union'.> 158 lemma stage_TV_FO: 159 assumes "a into (Id. 3n. fst (stage I D E g G n) d)" and "b into (AS. 3n. snd (stage I D E g G n) S)" 160 and "3d. D d ∧ (I,D,E),a[y←d],b = d" 161 shows "3d. (3n. fst (stage I D E g G n) d) ∧ (I,D,E),a[y←d],b = d" 162 using skolem_step_FO[OF assms(3), of "g 0" "G 0"] 163 wF_in_omega_union[of "map a [0..<fresh ψ] I D E g G "map b [0..<fresh2 ψ] "y] assms(1,2) by auto 164 lemma stage_TV_SO: 165 assumes "a into (Id. 3n. fst (stage I D E g G n) d)" and "b into (AS. 3n. snd (stage I D E g G n) S)" 166 and "3S. E S ∧ (I,D,E),a,b(Y←S) = d" 167 shows "3S. (3n. snd (stage I D E g G n) S) ∧ (I,D,E),a,b(Y←S) = d" 168 using skolem_step_SO[OF assms(3), of "g 0" "G 0"] 169 wS_in_omega_union[of "map a [0..<fresh ψ] I D E g G "map b [0..<fresh2 ψ] "Y] assms(1,2) by auto 170 —<Inductive step for stage_countability: each Suc_stage is countable provided both n-stages are.> 171 lemma cntDE_step: 172 assumes cD: "countable {d. fst (stage I D E g G n) d}" and cE: "countable {S. snd (stage I D E g G n) S}" 173 shows "countable {d. fst (stage I D E g (Suc n)) d}" and "countable {S. snd (stage I D E g (Suc n)) S}" 174 proof 175 let ?A = {xs. set xs ⊆ {d. fst (stage I D E g G n) d})* 176 let ?B = {Ss. set Ss ⊆ {S. snd (stage I D E g G n) S})* 177 have IDE: "countable ?A" "countable ?B" 178 apply (metis cD countable_lists_lists_eq_set) by (metis cE countable_lists_lists_eq_set) 179 hence cT: "countable ((UNIV::F set) × (UNIV::V set) × ?A × ?B)" "countable ((UNIV::F set) × (UNIV::V2 set) × ?A × ?B)" 180 by (auto intro1: countable_Times2) 181 hence prods: "countable ((λ(φ,Y,xs,Ss). wF I D E (g 0) (G 0) ψ y xs Ss) ^ ((UNIV::F set) × (UNIV::V set) × ?A × ?B))" 182 "countable ((λ(φ,Y,xs,Ss). wS I D E (g 0) (G 0) ψ Y xs Ss)) ^ ((UNIV::F set) × (UNIV::V2 set) × ?A × ?B))" 183 by (auto intro1: countable_image) 184 from prods(1) cD fst_stage_Suc_subset[of I D E g G n] show "countable {d. fst (stage I D E g (Suc n)) d}" 185 by (meson countable_Un_countable_subset) 186 from prods(2) cE snd_stage_Suc_subset[of I D E g G n] show "countable {S. snd (stage I D E g (Suc n)) S}" 187 by (meson countable_Un_countable_subset) 188 qed 189 —<Stage carriers stay inside D / E (by induction on the stage; wF mem_seed / wS mem_seed handle the witness case).> 190 lemma fst_stage_subD: "g into D⇒fst (stage I D E g G n) d ⇒ D d" by (induct n arbitrary: d) (auto simp: wF_mem_seed) 191 lemma snd_stage_subE: "G into E⇒snd (stage I D E g G n) S ⇒ E S" by (induct n arbitrary: S) (auto simp: wS_mem_seed) 192 —<Every stage is countable; hence so is the omega-union of stages. Pure consequence of "cntDE_step".> 193 lemma stage_countable: "countable {d. fst (stage I D E g G n) d} ∧ countable {S. snd (stage I D E g G n) S}" 194 proof (induct n) 195 case 0 have " {d. fst (stage I D E g G 0) d} = range g" {S. snd (stage I D E g G 0) S} = range G" by auto 196 thus ?case by simp next 197 case {Suc n} thus ?case using cntDE_step[of I D E g G n] by simp 198 qed 199 lemma stage_omega_countable: "countable {d. 3n. fst (stage I D E g G n) d}" "countable {S. 3n. snd (stage I D E g G n) S}" 200 proof - 201 have eqs: " {d. 3n. fst (stage I D E g G n) d} = (∪n. {d. fst (stage I D E g G n) d})" 202 "*{S. 3n. snd (stage I D E g G n) S} = (∪n. {S. snd (stage I D E g G n) S})" by auto 203 show "countable {d. 3n. fst (stage I D E g G n) d}" "countable {S. 3n. snd (stage I D E g G n) S}" 204 unfolding eqs using stage_countable by (auto intro: countable_UN) 205 qed 206 —reindex one sort onto a countable nonempty sub-domain, keeping the values on a finite "guarded" prefix 207 specified by a predicate 'free' bounded by 'fr'.> 208 lemma reindex_one: 209 fixes free :: "nat⇒bool" and fr :: nat and D₀ :: "a⇒bool" and g :: "nat⇒'a" 210 assumes "countable {x. D₀ x}" and "D₀ d" and "Range g ⊆ D₀" and bound: "∨x. free x ⇒⇒ x < fr" 211 obtains g' where "Range g' = D₀" and "∨x. free x ⇒⇒ g' x = g x" 212 proof - 213 let ?D = {x. D₀ x} 214 have hD: "7D ≠ {}" and re: "range (from_nat_into ?D) = ?D" and mem: "D₀ (from_nat_into ?D k)" for k 215 using assms(2) range_from_nat_into[OF_ assms(1)] from_nat_into by auto 216 define g where "g' n = (if free n then g n else from_nat_into ?D (n - fr))" for n 217 have "Range g' = D₀" 218 proof (rule ext, rule iff) 219 fix d assume "Range g' d" thus "D₀ d" using assms(3) mem by (auto simp: g_def split; if_split_asm) next 220 fix d assume "D₀ d" hence "d ∈ range (from_nat_into ?D)" using re by simp
Fig. 18. Theory MSOinHOL_lowenheim_skolem_lemmas.thy (Part 3 of 4): the ω-union membership lemmas wF_in_omega_union/wS_in_omega_union, the first- and second-order Tarski-Vaught closures stage_TV_FO/stage_TV_SO, the inductive countability step cntDE_step, the carriers-stay-inside lemmas fst_stage_subD/snd_stage_subE, stage-wise and ω-countability stage_countable/stage_omega_countable, and the surjective reindexing reindex_one.
C. Benzmüller & D. Kirchner
221 then obtain k where "from_nat_into ?D k = d" by auto 222 moreover have "¬ free (fr + k)" using bound by force 223 ultimately have "g" (fr + k) = d" by (simp add: g'_def) 224 thus "Range g' d" by auto 225 qed 226 moreover have "∧x. free x ⇒ g' x = g x" by (simp add: g'_def) 227 ultimately show ?thesis using that by blast 228 qed 229 —<reindex (both sorts): reindex the (countably many) variables to surject onto the countable @{text "D0, E0"} 230 while agreeing with the originals on the finitely many free variables of φ. Two applications of 'reindex one'. 231 lemma reindex: 232 assumes "countable {d. D₀ d}" and "D₀ d₀" and "countable {S. E₀ S}" and "E₀ S₀" 233 and "Range g ⊆ D₀" and "Range G ⊆ E₀" 234 obtains g' G' where "Range g' = D₀" and "Range G' = E₀" 235 and "∧x. x free_in φ ⇒ g' x = g x" and "∧X. X free2_in φ ⇒ G' X = G X" 236 proof - 237 obtain g' where g': "Range g' = D₀" "∧x. x free_in φ ⇒ g' x = g x" 238 using reindex_one[OF assms(1,2,5), of "∧x. x free_in φ" "fresh φ"] L6 by blast 239 obtain G' where G': "Range G' = E₀" "∧X. X free2_in φ ⇒ G' X = G X" 240 using reindex_one[OF assms(3,4,6), of "∧X. X free2_in φ" "fresh2 φ"] N6 by blast 241 show ?thesis using that g' G' by blast 242 qed 243 —<reindex + coincidence in one step: obtain @{text "g'/G'} surjecting onto the countable @{text "D0/E0"} 244 whose induced truth on φ coincides with the original. 245 lemma reindex_coincide: 246 assumes "countable {d. D₀ d}" and "countable {S. E₀ S}" and "Range g ⊆ D₀" and "Range G ⊆ E₀" 247 obtains g' G' where "Range g' = D₀" and "Range G' = E₀" and "((I.D₀,E₀),g,G | = d φ) = ((I.D₀,E₀),g',G' | = d φ)" 248 proof - 249 have nD: "D₀ (g 0)" and nE: "E₀ (G 0)" using assms(3,4) by auto 250 obtain g' G' where rg: "Range g' = D₀" and rG: "Range G' = E₀" 251 and ag: "∧x. x free_in φ ⇒ g' x = g x" and aG: "∧X. X free2_in φ ⇒ G' X = G X" 252 using reindex[OF assms(1) nD assms(2) nE assms(3,4)] by blast 253 have "((I.D₀,E₀),g,G | = d φ) = ((I.D₀,E₀),g',G' | = d φ)" by (rule coincidence) (simp_all add: ag aG) 254 thus thesis using that rg rg by blast 255 qed 256 end
Fig. 19. Theory MSOinHOL_lowenheim_skolem_lemmas.thy (Part 4 of 4): the conclusion of reindex_one, the surjective reindexing reindex, and the combined reindex_coincide lemma.
1 theory MSOinHOL_lowenheim_skolem imports MSOinHOL_lowenheim_skolem_lemmas 2 begin 3 —Two-sorted elementary substructure (Tarski-Vaught form). 4 definition ElementarySubstructure ("") ⊆ E ("") where "((I,D',E') ⊆ E ((I,D,E)) = 5 D' ⊆ D ∧ E' ⊆ E ∧ (∀ g G ∨. G into E' → g into D') — ((I,D,E),g,G) = d φ) = ((I,D',E'),g,G) = d φ) 6 —Minimal interpretation whose range model is elementary in a larger model. 7 locale MinS_ES = MinS + fixes DD::D and EE::P 8 assumes ES: "(I,Range gg, Range GG) ⊆ E ((I,DD,EE))" 9 begin 10 lemma X_valid_ES: "(I,DD,EE), gg, GG) = d φ = ((I,Range gg, Range GG), gg, GG) = d φ" 11 using ES ElementarySubstructure_def by (smt (verit)) 12 end 13 —Specialisation to the standard model @ (text "((I,Univ,Univ))). 14 locale MinS_ES_Univ = MinS_ES || gg GG Univ Univ for II gg GG 15 begin 16 lemma X_valid_ES_Univ: "(I,Univ,Univ), gg, GG) = d φ = ((I,Range gg,Range GG), gg, GG) = d φ" using X_valid_ES, 17 end 18 —Range-relative validity: the right-hand side of FaithfulMS_all. 19 definition RangeValid ("_") ⊆ 9 where "≡" ∨ ∀ g G. (I, Range g, Range G), g,G) = d φ" 20 lemma into_Range: "f into Range" by auto 21 —Easy direction. 22 lemma ValD_imp_RangeValid: "≡ d φ ⇒" using RangeValid_def ValD_def using into_Range by smt 23 —Truth preservation across a Tarski-Vaught-closed sub-pair @ (text "(D0,E0)"). 24 lemma truth_pres: 25 assumes subD: "D₀ ⊆ D" and subE: "E₀ ⊆ E" 26 and TVfo: "∀ ψ a b. a into D₀ ⇒ b into E₀ ⇒ (3d. D d ∧ ((I,D,E),a[y←d],b) = d) ⇒ (3d. D₀ d ∧ ((I,D,E),a[y←d],b) = d) 27 and TVso: "∀ ψ a b. a into D₀ ⇒ b into E₀ ⇒ (3S. E S ∧ ((I,D,E),a,b(Y←S)) = d) ⇒ (3S. E₀ S ∧ ((I,D,E),a,b(Y←S)) = d) 28 and aD: "a into D₀" and bE: "b into E₀" 29 shows "(I,D₀,E₀),a,b) = ((I,D,E),a,b) = d φ" using aD bE 30 proof (induct φ arbitrary: a b) 31 case (ExD γ) thus ?case using ExD.hypsf[of "a[y←] b] TVfo[of a b γ] subD by (force simp: EnvMod_def) next 32 case (ExD2 Y) thus ?case using ExD2.hypsf[of a "b(Y←)"] TVso[of a b Y] subE by (force simp: SetMod_def) 33 qed simp_all 34 —Countable seed-form Tarski-Vaught hull: extends any countable nonempty @ (text "(D0,E0) ⊆ (D,E)") 35 to a countable TV-closed pair @ (text "(N,M)") between them. 36 lemma skolem_hull: 37 fixes I::"I" and D::"D" and E::"p" 38 assumes "D₀ ⊆ D" and "E₀ ⊆ E" and "∃ x. D₀ x" and "∃ S. E₀ S" and "countable {d. D₀ d}" and "countable {d. E₀ d}" 39 obtains N M where "N ⊆ D" and "M ⊆ E" and "D₀ ⊆ N" and "E₀ ⊆ M" 40 and "countable {d. N d}" and "countable {S. M S}" 41 and "∀ ψ a b. a into N ⇒ b into M ⇒ (3d. D d ∧ ((I,D,E),a[y←d],b) = d) ⇒ (3d. N d ∧ ((I,D,E),a[y←d],b) = d) 42 and "∀ ψ a b. a into N ⇒ b into M ⇒ (3S. E S ∧ ((I,D,E),a,b(Y←S)) = d) ⇒ (3S. M S ∧ ((I,D,E),a,b(Y←S)) = d) 43 proof. 44 obtain g::"g" where g: "Range g = D₀" 45 by (metis (mono_tags, lifting) Collect_inj assms(3,5) empty_Collect_eq full_SetCompr_eq range_from_nat_into) 46 obtain G::"G" where G: "Range G = E₀" 47 by (metis (mono_tags, lifting) Collect_inj assms(4,6) empty_Collect_eq full_SetCompr_eq range_from_nat_into) 48 define Dh where Dh: "Dh = (λd. ∃n. fst (stage I D E g n) d)" 49 define Eh where Eh: "Eh = (λS. ∃n. snd (stage I D E g n) S)" 50 have base: "Range g d ⇒ fst (stage I D E g G) d" "Range G S ⇒ snd (stage I D E G G) S" for d S by simp_all 51 have RgDh: "Range g ⊆ Dh" and RGEH: "Range G ⊆ Eh" using base unfolding Dh Eh by blast+ 52 have DhsubD: "Dh ⊆ D" using fst_stage_subD assms(1) unfolding Dh by (metis (full_types) g) 53 have EhsubE: "Eh ⊆ E" using snd_stage_subE assms(2) unfolding Eh by (metis (mono_tags, lifting) G) 54 have cDh: "countable {d. Dh d}" and cEh: "countable {S. E S}" unfolding Dh Eh by (rule stage_omega_countable)+ 55 have TVfo: "a into Dh ⇒ b into Eh ⇒ (3d. D d ∧ ((I,D,E),a[y←d],b) = d) ⇒ (3d. Dh d ∧ ((I,D,E),a[y←d],b) = d)" 56 for γ a b unfolding Dh Eh by (rule stage_TV_FO) 57 have TVso: "a into Dh ⇒ b into Eh ⇒ (3S. E S ∧ ((I,D,E),a,b(Y←S)) = d) ⇒ (3S. E h S ∧ ((I,D,E),a,b(Y←S)) = d)" 58 for γ a b unfolding Dh Eh by (rule stage_TV_SO) 59 show ?thesis using DhsubD EhsubE G RGEH RgDh TVfo TVso cDh eCh g that by force 60 qed 61 —Downward L\owenheim--Skolem: TV-closure is upgraded to genuine elementarity via @ (text truth_pres). 62 theorem DownwardLowenheimSkolem: 63 assumes "D₀ ⊆ D" and "E₀ ⊆ E" and "∃ x. D₀ x" and "∃ x. E₀ x" and "countable {d. D₀ d}" and "countable {S. E₀ S}" 64 shows "∃N M. D₀ ⊆ N ∧ countable {d. N d} ∧ E₀ ⊆ M ∧ countable {S. M S} ∧ ((I,N,M) ⊆ E ((I,D,E))" 65 proof. 66 obtain N M where "N ⊆ D" "M ⊆ E" "D₀ ⊆ N" "E₀ ⊆ M" "countable {d. N d}" "countable {S. M S}" 67 "∀ ψ a b. a into N ⇒ b into M ⇒ 3d:D. (I,D,E),a[y←d],b) = d ⇒ 3d:N. (I,D,E),a[y←d],b) = d" 68 "*∀ Y a b. a into N ⇒ b into M ⇒ 3S:E. (I,D,E),a,b(Y←S)) = d ⇒ 3S:M. (I,D,E),a,b(Y←S)) = d" 69 using skolem_hull[of D₀ D E₀ E, OF assms] by blast 70 hence "D₀ ⊆ N ∧ countable {d. N d} ∧ E₀ ⊆ M ∧ countable {S. M S} ∧ ((I,N,M) ⊆ E ((I,D,E))" 71 using ElementarySubstructure_def truth_pres skolem_hull[of D₀ D E₀ E, OF assms] by auto 72 thus ?thesis by blast 73 qed
Fig. 20. Theory MSOinHOL_lowenheim_skolem.thy (Part 1 of 2): the elementary-substructure layer — the relation ElementarySubstructure ( ) and the locales MinS_ES/MinS_ES_Univ — range-relative validity RangeValid, the easy direction ValD_imp_RangeValid, truth preservation truth_pres for a Tarski-Vaught-closed sub-pair, the countable seed hull skolem_hull, and the first-class downward Löwenheim-Skolem theorem DownwardLowenheimSkolem.
36 C. Benzm¨uller & D. Kirchner Fig. 21. Theory MSOinHOL lowenheim skolem.thy (Part 2 of 2): the strongest faithfulness theorem Deep’ to MinS (standard validity ⇔ minimal validity over elementary interpretations) with its corollary Faithful to Standard; then the earlier generalreading route, derived in one step from DownwardLowenheimSkolem — the assembled elementary-substructure hull ls hull, the range reduction Range reduction, the main theorem RangeValid imp ValD with corollaries RangeValid iff ValD/Faithful to Henkin, and the negative result Standard strictly stronger with its explicit diagonal countermodel.
theory MSOinHOL_shallow_minimal_elementary imports MSOinHOL_faithfulness_locale MSOinHOL_lowenheim_skolem begin —<Extra simp rules for @{term DpToShS} (derived quantifiers and connectives).> lemma (in MinS) DpToShS_All[simp]: "(v^d x . φ) = (v^m d . ((x ←, d)(φ)))" unfolding DefD DefM by (simp add: ExM_def NegM_def ren_subst_def) lemma (in MinS) DpToShS_All2[simp]: "(v^d_2 x . φ) = (v^m_2 d . ((x ←_2 d)(φ)))" unfolding DefD DefM using MinS.FaithfulMDlem by auto lemma (in MinS) DpToShS_Equiv[simp]: "(φ ←^d φ) = ((φ_2) ←^m (φ))" unfolding DefD DefM by (simp add: AndM_def NegM_def) lemma (in MinS) DpToShS_Imp[simp]: "(φ_2 ⊃^d φ) = ((φ_2) ⊃^m (φ))" unfolding DefD DefM by (simp add: AndM_def NegM_def) —<Elementary constants-only presentation: @{text II}, @{text gg}, @{text GG} chosen so that the global interpretation is a @{text MinS_ES_Univ} (existence via @{text Deep'_to_MinS}).> consts II::ℓ gg::ℓ GG::ℓ specification(II gg GG) ES_Univ: "MinS_ES_Univ II gg GG" by (meson Deep'_to_MinS RelativeTruthD.simps ValD'_def) global_interpretation MinS_ES_Univ II gg GG using ES_Univ by auto notation AtmM ("_m"(__))" and PrdM ("m"())" and NegM ("_m" [58]59) and AndM (infixr "λ^m" 56) and ExM (binder "∃^m" 53) and ExM2 (binder "∃^m" 53) and OrM (infixr "∨^m" 54) and ImpM (infixr "∨^m" 55) and IffM (infixr "⊃^m" 54) and AllM (binder "∨^m" 53) and AllM2 (binder "∨^m" 53) and ValM ("="_m" 9) and DpToShM ("⊃") —<Faithfulness under universal carriers.> lemma FaithfulMD_ES: "((=^m (φ))) = (II,Univ,Univ).gg.GG ⊃^d φ" using FaithfulMD λ'_valid_ES_Univ by blast —<Inheritance: standard validity transfers to minimal validity.> lemma ValidM_if_ValidD: "((=^d φ) ⇒ ((=^m (φ))" by (metis MinS_ES_Univ_axioms Deep'_to_MinS) end
Fig. 22. Theory MSOinHOL_shallow_minimal_elementary.thy: an elementary constants-only presentation of the minimal shallow embedding — four DpToShS simplification lemmas for the derived quantifiers and connectives (DpToShS_All1, DpToShS_All2, DpToShS_Equiv, DpToShS_Imp), the three uninterpreted constants II, gg, GG, a specification establishing the existence of a global interpretation that forms a MinS_ES_Univ elementary substructure (with existence justified by Deep'_to_MinS), the corresponding global_interpretation re-issuing the locale notation at the constants level, and the inheritance lemmas FaithfulMD_ES (faithfulness under universal carriers) and ValidM_if_ValidD' (standard validity lifts to minimal validity).
C. Benzmüller & D. Kirchner
1 theory MSOinHOL_experiments_classic_elementary 2 imports MSOinHOL_deep MSOinHOL_shallow MSOinHOL_shallow_minimal_elementary 3 begin 4 —<Extra simp rules for derived quantifiers / connectives.> 5 lemma ren_for_subst2_simp_All[simp]: "ren_for_subst2 X Z (ṽᵈᵧ, φ) = (if Y = Z ∧ X free2_in φ 6 then let f = max (fresh2_φ) (Z+1); φ' = [Y←φ]((φ) in (ṽᵈᵧ,f. ren_for_subst2 X Z φ)) 7 else ṽᵈᵧ, ren_for_subst2 X Z φ)" 8 unfolding DefD by (auto simp: Let_def) 9 lemma subst2_all[simp]: "X←Z[Z](ṽᵈᵧ, φ) = (if X = Y then (ṽᵈᵧ,Y, φ) else (ṽᵈᵧ,Y, X←Z))" 10 unfolding DefD by (auto simp: Let_def) 11 lemma free2_in_equiv[simp]: "X free2_in (φ ← d φ) = (X free2_in φ ∨ X free2_in φ)" by (auto simp add: DefD) 12 lemma free2_in_all[simp]: "X free2_in (ṽᵈᵧ, φ) = (X free2_in φ)" by (simp add: AllD_def) 13 lemma free2_in_all2[simp]: "X free2_in (ṽᵈᵧ, φ) = (X free2_in φ ∧ X ≠ Y)" by (metis AllD2_def is_free2.simps) 14 —<Some abbreviations for variables.> 15 abbreviation "(x::V) ≡ 1" abbreviation "(y::V) ≡ 2" abbreviation "(z::V) ≡ 3" 16 abbreviation "(X::V2) ≡ 1" abbreviation "(Y::V2) ≡ 2" abbreviation "(Z::V2) ≡ 3" 17 abbreviation "(u::V) ≡ 4" abbreviation "(v::V) ≡ 5" constants P::R 18 —<Boolean closure (Büchi 1960; Thomas 1997) under @ (text "|=d"): witnesses supplied via @ (text ex|.)> 19 lemma complement_d: "|=d (ṽᵈᵧ, X, ∃d₂, Z, ∇dₓ, (Zᵈ(x) ←d Xᵈ(x)))" 20 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 21 subgoal for S by (rule ex|[of _ "λd. ¬5 d"])(auto simp: SetMod_def EnvMod_def) done 22 lemma intersection_d: "|=d (ṽᵈᵧ, X, ∃d₂, Y, ∃d₃, Z, ∇dₓ, (Zᵈ(x) ←d (Xᵈ(x) ∧ d Yᵈ(x))))" 23 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 24 subgoal for S Sa by (rule ex|[of _ "λd. S d ∧ Sa d"])(auto simp: SetMod_def EnvMod_def) done 25 lemma intersection_d: "|=d (∃d₂, Z, ∇dₓ, (Zᵈ(x) ←d (Xᵈ(x) ∧ d Yᵈ(x))))" 26 by (simp add: comprehension_schema) 27 lemma union_d: "|=d (ṽᵈᵧ, X, ∃d₂, Y, ∃d₃, Z, ∇dₓ, (Zᵈ(x) ←d (Xᵈ(x) ∇d Yᵈ(x))))" 28 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 29 subgoal for S Sa by (rule ex|[of _ "λd. S d ∨ Sa d"])(auto simp: SetMod_def EnvMod_def) done 30 —<Graph operations (Courcelle 2012).> 31 lemma separation_d: "|=d (ṽᵈᵧ, X, ∃d₂, Z, ∇dₓ, (Zᵈ(x) ←d (Xᵈ(x) ∧ d Pᵈ(x,x)))" 32 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 33 subgoal for I S by (rule ex|[of _ "λd. S d ∧ (P d d")](auto simp: SetMod_def EnvMod_def) done 34 lemma image_d: "|=d (ṽᵈᵧ, X, ∃d₂, Y, ∇dₓ, (Yᵈ(x) ←d ∃d, (Xᵈ(y) ∧ d Pᵈ(y,x)))" 35 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 36 subgoal for I S by (rule ex|[of _ "λd. ∃d', S d' ∧ (P d d")](auto simp: SetMod_def EnvMod_def) done 37 lemma preimage_d: "|=d (ṽᵈᵧ, X, ∃d₂, Y, ∇dₓ, (Yᵈ(x) ←d ∃d, (Pᵈ(x,y) ∧ d Xᵈ(y))))" 38 unfolding DefD apply (intro all, simp add: SetMod_def EnvMod_def, intro all) 39 subgoal for I S by (rule ex|[of _ "λd. ∃d', I P d' ∧ S d"])(auto simp: SetMod_def EnvMod_def) done 40 —<Reachability (Basin & Klarlund 1995): not universally valid; reflexive variant is.> 41 lemma reachability_not_valid_d: "|=d (ṽᵈᵧ, Z, ((Zᵈ(x) ∧ d (ṽᵈu, (Zᵈ(u) ⊃ d ∇d, (Pᵈ(u,v) ⊃ d Zᵈ(v)))) ⊃ d Zᵈ(y))))" 42 unfolding DefD apply simp nitpick oops 43 lemma reachability_reflexive_d: "|=d (ṽᵈᵧ, Z, ((Zᵈ(x) ∧ d (ṽᵈu, (Zᵈ(u) ⊃ d ∇d, (Pᵈ(u,v) ⊃ d Zᵈ(v)))) ⊃ d Zᵈ(x)))" 44 unfolding DefD by simp 45 —<2-colorability (Thomas 1997): refuted on $K_5_5.> 46 lemma two_colorability_not_valid_d: "|=d (∃d₂, Z, ∇dₓ, ∇dᵧ, (Pᵈ(x,y) ⊃ d (Zᵈ(x) ←d ¬d Zᵈ(y))))" 47 unfolding DefD apply simp nitpick oops
Fig. 23. Theory MSOinHOL_experiments_classic_elementary.thy (Part 1 of 2): additional simplification rules for the derived second-order quantifier and equivalence (ren_for_subst2_simp_All, subst2_all, free2_in_equiv, free2_in_all, free2_in_all2), the convenient variable abbreviations, and the full set of deep-embedding classical MSO landmarks — Boolean closure (complement_d, intersection_d/intersection_d', union_d), monadic graph operations (separation_d, image_d, preimage_d), reachability (reachability_not_valid_d, reachability_reflexive_d), and 2-colorability (two_colorability_not_valid_d).
47 unfolding DefD apply simp nitpick oops 48 —<Same landmarks in the maximal-shallow embedding: structurally identical proofs.> 49 lemma complement_s: "|=^ (∨^sX, ∃^sZ, ∨^sX, (Z^i(x) ←→^s X^i(x)))" 50 unfolding DefS apply (intro all,simp,intro all) subgoal for S by (rule ex[of_ "λd. → S d"] auto done 51 lemma intersection_s: "|=^ (∨^sX, ∨^sY, ∃^sZ, ∨^sX, (Z^i(x) ←→^s (X^i(x) ∧^s Y^i(x)))" 52 unfolding DefS apply (intro all,simp,intro all) subgoal for S Sa by (rule ex[of_ "λd. S d ∧ Sa d"] auto done 53 lemma union_s: "|=^ (∨^sX, ∨^sY, ∃^sZ, ∨^sX, (Z^i(x) ←→^s (X^i(x) ∧^s Y^i(x)))" 54 unfolding DefS apply (intro all,simp,intro all) subgoal for S Sa by (rule ex[of_ "λd. S d ∨ Sa d"] auto done 55 lemma separation_s: "|=^ (∨^sX, ∃^sZ, ∨^sX, (Z^i(x) ←→^s (X^i(x) ∧^s P^i(x,x)))" 56 unfolding DefS apply (intro all,simp,intro all) subgoal for I S by (rule ex[of_ "λd. S d ∧ | P d d"] auto done 57 lemma image_s: "|=^ (∨^sX, ∃^sY, ∨^sX, (Y^i(x) ←→^s (∃^iY, (X^i(y) ∧^s P^i(y,x)))" 58 unfolding DefS apply (intro all,simp,intro all) subgoal for I S by (rule ex[of_ "λd. ∃d. S d ∧ | P d d"] auto done 59 lemma preimage_s: "|=^ (∨^sX, ∃^sY, ∨^sX, (Y^i(x) ←→^s (∃^iY, (P^i(x,y) ∧^s X^i(y)))" 60 unfolding DefS apply (intro all,simp,intro all) subgoal for I S by (rule ex[of_ "λd. ∃d. | P d d ∧ S d"] auto done 61 lemma reachability_not_valid_s: "|=^ (∨^sZ, ((Z^i(x) ∧^s (∨^sU, (Z^i(u) ⊃^s (∨^sV, (P^i(u,v) ⊃^s Z^i(v)))))) ⊃^s Z^i(y)))" 62 unfolding DefS apply (intro all) apply simp nitpick oops 63 lemma reachability_reflexive_s: "|=^ (∨^sZ, ((Z^i(x) ∧^s (∨^sU, (Z^i(u) ⊃^s (∨^sV, (P^i(u,v) ⊃^s Z^i(v)))))) ⊃^s Z^i(x)))" 64 unfolding DefS by simp 65 lemma two_colorability_not_valid_s: "|=^ (∃^sZ, ∨^sX, ∨^sY, (P^i(x,y) ⊃^s (Z^i(x) ←→^s Z^i(y)))" 66 unfolding DefS apply (intro all) apply simp nitpick oops 67 —<Transfer to the elementary minimal embedding via @ (text DpToShS) normal-form and @ (text ValidM_if ValidD')> 68 lemma compl_m_DpToSh: "∨^dX, ∃^dZ, ∨^dX, (Z^i(x) ←→^d X^i(x))) = (∨^mX, ∃^mZ, ∨^mX, (Z^m(x) ←→^m X^m(x)))" 69 by (auto simp add: ren_subst2_def ren_subst_def Let_def) (auto simp: DefD DefM ren_subst_def) 70 lemma compl_m_valid: "|=^ (∨^mX, ∃^mZ, ∨^mX, (Z^m(x) ←→^m X^m(x)))" 71 using compl_m_DpToSh ValidM_if ValidD' [OF complement_d] by simp 72 lemma inters_m_DpToSh: "∃^dZ, ∨^dX, (Z^i(x) ←→^d (X^i(x) ∧^d Y^i(x))) = (∃^mZ, ∨^mX, (Z^m(x) ←→^m (X^m(x) ∧^m Y^m(x)))" 73 by (auto simp add: ren_subst2_def ren_subst_def Let_def) (auto simp: DefD DefM ren_subst_def) 74 lemma DpToSh_alleq: "∨ (d. ((X →_i d) (∨) = ψ d) ⇒ (∨^dX, ∨^d) = (∨^mX, ψ X)" by simp 75 lemma all_m_eq: "∨ (X, φ X = ψ X) ⇒ (∨^mX, φ X) = (∨^mX, ψ X)" by presburger 76 lemmas DpToSh_simp = DefM Let_def ren_subst_def DefD ren_subst2_def 77 lemma intersect_m_DpToSh: "∨^dX, ∨^dY, ∃^dZ, ∨^dX, (Z^i(x) ←→^d (X^i(x) ∧^d Y^i(x))) = (∨^mX, ∨^mY, ∃^mZ, ∨^mX, (Z^m(x) ←→^m (X^m(x) ∧^m Y^m(x)))" 78 apply (rule DpToSh_alleq, simp only: ren_subst2_def subst2_all ren_for_subst2_simp_All, simp) 79 apply (case_tac "d = Z", simp, rule all_m_eq) 80 subgoal by (auto simp: DpToSh_simp) 81 apply (simp, case_tac "d = Y", simp) 82 subgoal by (auto simp: DpToSh_simp) metis+ 83 apply (simp, rule all_m_eq, auto simp: ren_subst2_def ren_subst_def Let_def, auto simp: DpToSh_simp) 84 by (smt (verit, del_insts) Suc_n_not_l_n max.cobounded1 max.left, commute numeral_2_eq_2 numeral_3_eq_3) 85 lemma intersection_m_valid: "|=^ (∨^mX, ∨^mY, ∃^mZ, ∨^mX, (Z^m(x) ←→^m (X^m(x) ∧^m Y^m(x)))" 86 using ValidM_def ValidD' intersection_d intersect_m_DpToSh by blast 87 —<Reachability and 2-colorability remain refuted in the elementary minimal embedding.> 88 lemma reachability_not_valid_m: "|=^ (∨^mZ, ((Z^m(x) ∧^m (∨^mU, (Z^m(u) ⊃^m (∨^mV, (P^m(u,v) ⊃^m Z^m(v)))))) ⊃^m Z^m(y)))" 89 unfolding DefM oops 90 lemma reachability_reflexive_m: "|=^ (∨^mZ, ((Z^m(x) ∧^m (∨^mU, (Z^m(u) ⊃^m (∨^mV, (P^m(u,v) ⊃^m Z^m(v)))))) ⊃^m Z^m(x)))" 91 unfolding DefM by simp 92 lemma two_colorability_not_valid_m: "|=^ (∃^mZ, ∨^mX, ∨^mY, (P^m(x,y) ⊃^m (Z^m(x) ←→^m X^m(y)))" 93 unfolding DefM oops 94 end
Fig. 24. Theory MS0inHOL_experiments_classic_elementary.thy (Part 2 of 2): the same landmarks in the maximal-shallow embedding (the deep↔maximal-shallow scripts are line-for-line identical because the goals are HOL-equal after unfolding), and their lifts to the elementary global interpretation — the DpToShS-normal-form lemmas (compl_m_DpToSh, inters_m_DpToSh', intersect_m_DpToSh), the helper combinators (DpToSh_alleqI, all_m_eqI, DpToSh_simp), and the ValidM_if ValidD'-style validity transfers (compl_m_valid, intersection_m_valid); reachability and 2-colorability remain refuted in the elementary minimal embedding as expected.