Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

institutions: a translation between logics carries its satisfaction condition

FABIOTESS370fd1c6e169
diff --git a/docs/decisions/0009-a-translation-between-logics-carries-its-satisfaction-condition.md b/docs/decisions/0009-a-translation-between-logics-carries-its-satisfaction-condition.md
new file mode 100644
index 00000000..cb1fd9d0
--- /dev/null
+++ b/docs/decisions/0009-a-translation-between-logics-carries-its-satisfaction-condition.md
@@ -0,0 +1,225 @@
+# 0009 · A translation between logics carries its satisfaction condition
+
+- **Status**: implemented · `lean/OOCert/Institution.lean`, `lean/OOCert/Comorphism.lean`,
+ `lean/OOCert/InstitutionRdf.lean`, `lean/OOCert/InstitutionFol.lean`,
+ `lean/OOCert/InstitutionWitness.lean`, root `lean/Institution.lean`, lakefile target
+ `Institution` · three institutions, two comorphisms, twenty-one pinned axiom footprints,
+ no `sorry`, no `native_decide`, no Mathlib, no new package · `lake build` 105 jobs → 112
+- **Written**: 2026-09-15
+- **Related**: decision 0005 (a prover is an oracle and a translation is a theorem), whose second
+ half this is; decision 0002 (an inference carries a certificate); decision 0003 (the verdict
+ rule), which this does not weaken
+
+## The problem
+
+This repository exports OWL to first-order logic and says, correctly, that the correspondence
+between the Rust emitter and the Lean translation is pinned by tests and not proved. It also has
+exactly one machine-checked statement of the form "this translation preserves meaning":
+`OwlLean.adequacy`, in the sibling `owl-lean` package. That theorem stands alone. Nothing in this
+repository abstracts over it, so there is no way to state what a SECOND translation would have to
+prove, and no way to state what follows from having proved it.
+
+The discipline for that abstraction has existed since 1992 and is Goguen and Burstall's
+institutions, with translations between logics as comorphisms. The Heterogeneous Tool Set is the
+engineering that goes with it. Hets is a large Haskell program in which a comorphism is a type-class
+instance supplying a signature map, a sentence map and a model map; the satisfaction condition that
+makes those three a translation of logics is discharged in the literature rather than by the
+program. Decision 0005 already put it that way: "Hets proves its OWL-to-CASL comorphism on paper."
+Nobody on this branch has read the Hets source, so that is a statement about its published design
+and not a code review.
+
+Reimplementing Hets buys nothing, because the value of Hets is its breadth and breadth is exactly
+what a small verified core cannot have. Writing another unverified translation buys less than
+nothing, because it is the shape this project exists to attack. What is left is the narrow move:
+take the ONE part that carries the semantic weight and machine-check it for a small number of
+logics.
+
+## Decisions
+
+1. **An institution is a structure and its satisfaction condition is a field.**
+ `OOCert.Institution` carries `Sig`, `SigMor`, `Sen`, `Mod`, `senMap`, `modRed`, `sat` and
+ `satCond`. The last says that reducing a model along a signature morphism and translating a
+ sentence along it agree. It is a proof obligation of the constructor, so there is no institution
+ in this development whose satisfaction condition was assumed. Four separate universe parameters,
+ because `OOCert.Interp` and `Fol.Struc` carry a `Type` field and live in `Type 1` while a
+ signature here is a list of strings.
+
+2. **A comorphism is a structure and ITS satisfaction condition is a field.** `OOCert.Comorphism`
+ carries `sigMap`, `senMap`, `modMap` and `satCond`. `Comorphism.mk` does not accept three maps.
+ An unproved translation in this layer is a type error at the point of construction, not a lint
+ warning, not a `TODO` and not a documentation gap. That sentence is the whole point of the file
+ and everything else in it is downstream of it.
+
+3. **Preservation and reflection are two theorems and they are kept two.**
+ `Comorphism.preserves_entailment` has no hypothesis beyond the comorphism: the satisfaction
+ condition is the entire proof. `Comorphism.reflects_entailment` takes `ModelExpansive`, and
+ `Comorphism.borrowing` is the biconditional the two give together. Conflating them is how a
+ translation gets sold as a decision procedure, so they are separated in the types and the
+ separation is MEASURED rather than warned about:
+ `InstitutionWitness.preservation_does_not_give_reflection` exhibits an entailment of the target
+ whose source counterpart is refuted by a Herbrand countermodel, and
+ `forgetting_the_conditions_is_not_model_expansive` turns that into a refutation of the
+ HYPOTHESIS rather than only of the conclusion.
+
+4. **`ModelExpansive` is stated in its weakest form.** The textbook hypothesis is that the model map
+ is surjective. What the proof consumes is weaker: every source model is indistinguishable BY
+ SENTENCES from the reduct of some target model. `ModelExpansive.of_surjective` proves the strong
+ form implies the weak one, so a caller holding surjectivity loses nothing and nothing downstream
+ is tempted to treat the two as the same.
+
+5. **The weakest-conditions discipline applies here and it points the OPPOSITE way from
+ `Semantics.lean`, and that had to be worked out rather than copied.** `Semantics.lean` warns that
+ a condition stronger than the specification shrinks the model class and silently weakens every
+ downstream theorem. A satisfaction condition is a `∀` over morphisms, over models and over
+ sentences, so in this layer:
+ - more signature morphisms make a STRONGER institution, and every constraint added to `SigMor`
+ deletes instances of the law;
+ - more sentences make a STRONGER institution, so the textbook restriction of `Sen S` to formulas
+ "over `S`" is a WEAKENING and is done only where a downstream comorphism cannot hold without
+ it;
+ - `Rdf.Sen` therefore constrains the PREDICATE position of a triple and leaves subject and object
+ free, because only the predicate's denotation is what the relevant condition turns on;
+ - `FolInst.Sen` and `FolInst.Mod` are unrestricted, and the file says at the field that the
+ signature constrains nothing, rather than dressing up a `Struc` that interprets every symbol as
+ if it did not.
+
+6. **The strengthening is quarantined, as in `W3C.lean`.** Category laws and functoriality are true
+ of these instances and are consumed by no theorem here, so they are not fields of `Institution`.
+ They live in `Institution.Functorial`, whose `toInstitution` is a FIELD PROJECTION, so every
+ theorem about `Institution` applies to a `Functorial` verbatim:
+ `functorial_preserves_entailment` is the general theorem applied and not a re-proof.
+ `InstitutionWitness.simpleFunctorial` discharges the laws for the RDF instance, so the
+ strengthened class is not empty and the omission is discipline rather than concealment.
+
+7. **Three instances, all out of material this repository already had.**
+ - `Rdf.simple`: simple RDF interpretations (`OOCert.Interp`, no semantic conditions). A morphism
+ is a renaming constrained only by having to take the source vocabulary into the target one,
+ which is what `senMap` needs; nothing else, because there is no semantic condition here for a
+ renaming to break.
+ - `Rdf.rl`: the OWL 2 RL interpretations, `OOCert.Conditions`. Morphisms must fix the reserved
+ vocabulary, and `Rdf.conditions_reduct` is the theorem that pays for it: all twenty-three
+ condition fields survive a renaming that fixes the fifteen terms the conditions name. That is
+ the content of "satisfaction is invariant under change of notation" at this layer, and it is
+ also the reason the two institutions have DIFFERENT morphism types: the logical vocabulary of a
+ logic is whatever its semantic conditions pin down.
+ - `FolInst.folInst`: first-order structures from `Fol/Semantics.lean`, with the satisfaction
+ condition for renamings of the three symbol spaces proved by induction over the formula.
+
+8. **Two comorphisms, both with the condition proved.** `Rdf.forgetConditions` goes from simple RDF
+ to OWL 2 RL, and is the one that preserves and provably does not reflect. `FolInst.rdfToFol` is
+ the translation proper: a triple becomes a binary atom and a first-order model becomes an RDF
+ interpretation.
+
+9. **The RDF-to-first-order comorphism is THEOROIDAL, and the obvious plain one does not go
+ through.** `OOCert.Interp.iext` is keyed by the DENOTATION of the predicate and `Fol.Struc.p2`
+ is keyed by the SYMBOL. Two symbols may denote one element and carry different extensions, and
+ then no ternary relation on the domain reproduces both, so the obvious model map cannot be
+ defined on arbitrary target structures. **That is an argument about the obvious construction and
+ not a theorem**: nothing quantifies over all possible comorphisms, so nothing here rules out a
+ plain one reached by another route, and neither this record nor the Lean claims otherwise. The
+ fix is
+ the one `src/tptp.rs` already ships: the target of the signature map is a THEORY, not a
+ signature. `Institution.Th` builds the institution of theories over any institution,
+ `Comorphism.Theoroidal` is a comorphism into it, `FolInst.cohAx` is the background axiom, and
+ `owl-lean`'s adequacy theorem has the same shape with `background ++ indAxioms inds`. Nothing new
+ was invented to make this work; what is new is that the obligation is discharged.
+
+10. **Hets is not a dependency and will not become one.** It is a Haskell program; nothing in this
+ repository's CI builds Haskell, and adding it would put a large unverified tool in the trust
+ surface to obtain a satisfaction condition that it does not machine-check anyway. The Lean side
+ takes no external package at all, by the rule at the top of `lean/lakefile.toml`. What is taken
+ from Hets is the IDEA, which is public, and the idea is the only part that carries weight.
+
+11. **The `owl-lean` package is not a dependency either, and this is not `OwlLean.adequacy`.** The
+ sibling development proves a biconditional about the OWL 2 abstract syntax with background
+ axioms, individual typing axioms and a freshness discipline. It is a separate Lake package, and
+ importing it would put a second development inside this one's trust surface for no gain that
+ could not be had by re-proving the part that is needed. What is here is the same SHAPE at the
+ RDF triple level, over the two model classes this repository already carries, with its own
+ satisfaction condition proved from scratch. The relationship is a family resemblance and is
+ written here rather than left for a reader to infer as a dependency.
+
+12. **DOL parsing is deferred, deliberately, until there is more than one proved comorphism to
+ distribute over.** The Distributed Ontology, Modeling and Specification Language is a syntax for
+ saying "interpret this specification into that one along this comorphism". A parser for it,
+ written today, would have two comorphisms to name, one of which is a forgetful map between two
+ readings of RDF. It would be a front end onto a table with two rows, and every hour spent on it
+ would be an hour not spent making the table longer. The order is: prove translations, then build
+ the notation that distributes over them. A DOL parser is a later, separate task and is worth
+ nothing before this lands.
+
+## What is proved, exactly
+
+| statement | where | axioms |
+|---|---|---|
+| a comorphism preserves entailment | `Comorphism.preserves_entailment` | none |
+| the same, premises as a list | `Comorphism.preserves_entailmentL` | `propext`, `Quot.sound` |
+| a model-expansive comorphism reflects entailment | `Comorphism.reflects_entailment` | none |
+| borrowing, as a biconditional | `Comorphism.borrowing` | none |
+| surjectivity implies model expansiveness | `Comorphism.ModelExpansive.of_surjective` | none |
+| theoroidal preservation, unfolded | `Comorphism.preserves_entailment_theoroidal` | none |
+| the quarantine costs nothing | `functorial_preserves_entailment` | none |
+| the 23 OWL 2 RL conditions survive a vocabulary-fixing renaming | `Rdf.conditions_reduct` | none |
+| an `Rdf.rl` entailment is an `OOCert.Entails` | `Rdf.rl_entails_gives_entails` | `propext`, `Quot.sound` |
+| simple RDF entailment is OWL 2 RL entailment | `Rdf.simple_entailment_is_rl_entailment` | `propext`, `Quot.sound` |
+| first-order satisfaction is invariant under symbol renaming | `FolInst.holds_red` | none |
+| `Fol.Entails` gives institution entailment | `FolInst.fol_entails_gives_institution_entails` | none |
+| an RDF entailment transfers to first-order logic | `FolInst.rdf_entailment_transfers_to_fol` | none |
+| preservation does not give reflection | `InstitutionWitness.preservation_does_not_give_reflection` | `propext` |
+| and so that comorphism is not model-expansive | `InstitutionWitness.forgetting_the_conditions_is_not_model_expansive` | `propext` |
+| the checker entails strictly more than the institution | `InstitutionWitness.the_checker_entails_more_than_the_institution` | `propext` |
+| institution entailment is not `Fol.Entails` on open formulas | `InstitutionWitness.fol_does_not_entail_the_universal_closure` | none |
+| three pairwise distinct `Rdf.rl` models | `InstitutionWitness.rl_models_are_pairwise_distinct` | `propext`, `Quot.sound` |
+| two distinct `Fol.Struc` models | `InstitutionWitness.fol_models_are_distinct` | none |
+| two distinct models of the background theory | `InstitutionWitness.coh_theory_models_are_distinct` | none |
+| a translated premise is first-order entailed, end to end | `InstitutionWitness.the_translation_of_a_premise_is_first_order_entailed` | none |
+
+Every footprint above is a subset of `propext`, `Classical.choice`, `Quot.sound`, and in fact no
+statement in this layer uses `Classical.choice`. Each is pinned with `#guard_msgs` so that a change
+to any of them fails `lake build` rather than appearing in a report.
+
+## What is NOT claimed, and two of these are refutations rather than gaps
+
+- **The Rust exporter is still not verified against the Lean.** `src/tptp.rs` and its translation
+ are outside this work entirely. Decision 0005 item 2 stands unchanged: the correspondence is
+ pinned by hand-computed tests and is not proved. `FolInst.rdfToFol` is a comorphism between two
+ LEAN developments and is not a statement about the emitter.
+- **No borrowing for the first-order comorphism.** `FolInst.rdfToFol` is not proved model-expansive
+ and is not claimed to be, so `Comorphism.reflects_entailment` does not apply to it. That is
+ decision 0005 item 5 restated as a missing theorem rather than as a caution: a first-order
+ prover's failure to find a proof is still not an RDF non-entailment, and now there is a named
+ theorem whose absence says so.
+- **No naturality.** A comorphism in the literature is also natural in the signature morphisms.
+ `OOCert.Comorphism` carries the satisfaction condition and nothing else, because no theorem here
+ consumes naturality. Anything that composes comorphisms across signature morphisms will need it,
+ and it is not there.
+- **`OOCert.Entails` is NOT institution entailment, and this is now refuted rather than merely
+ unclaimed.** `OOCert.Model` carries four conditions (`int`, `int2`, `uni`, `oneOf`) stated over
+ `Chain G`, the RDF list read off the ASSERTED GRAPH. A graph-relative condition is not a sentence
+ and not a condition on a signature, so `Rdf.rl.Mod` cannot carry it.
+ `the_checker_entails_more_than_the_institution` exhibits a premise set and a conclusion that
+ `OOCert.Entails` holds of and `Rdf.rl.EntailsL` does not, using `cls-oo` and the Herbrand model of
+ its own premises. The implication runs one way only, and `Rdf.rl_entails_gives_entails` is that
+ way.
+- **`folInst.sat` is validity and `Fol.Entails` is not.** The institution's satisfaction is "true
+ under every assignment" and `Fol.Entails` quantifies the assignment outside the implication. They
+ agree on closed formulas and `fol_does_not_entail_the_universal_closure` refutes the direction
+ that fails, with a two-element structure, so nobody reads one as the other.
+- **Nothing here changes a verdict word.** Decision 0003's rule is untouched: this layer produces no
+ certificate, no report field and no executable. It is theorems about the model classes the other
+ libraries already define.
+
+## Still not done
+
+- The instances are three and the comorphisms are two, one of which is forgetful. That is enough to
+ make the abstraction non-vacuous and it is not enough to be a heterogeneous tool set. The next
+ honest additions are the SHACL fragment in `lean/Shacl/` and the description-logic layer in
+ `lean/Dl/`, both of which have a model class already and neither of which has been looked at from
+ this angle.
+- The `Institution.Th` construction is used once. Nothing yet composes a theoroidal comorphism with
+ another comorphism, and `Comorphism.comp` is proved but unexercised.
+- No signature-morphism-level work is done on the first-order side beyond renaming: no vocabulary
+ extension, no pushouts, no amalgamation. Amalgamation is what a structured-specification layer
+ would need and is the honest prerequisite for anything DOL-shaped.
+- Nobody has measured what a proved comorphism buys the engine at run time, because nothing at run
+ time reads this layer.
diff --git a/docs/reasoning-systems-inventory.md b/docs/reasoning-systems-inventory.md
index 5b0278a1..8ead9585 100644
--- a/docs/reasoning-systems-inventory.md
+++ b/docs/reasoning-systems-inventory.md
@@ -32,6 +32,8 @@ perverse.
| SMT-LIB 2 | Interchange | Under construction. |
| RIF Core, SWRL | Rule languages | Front ends under construction. |
| CertifyingDatalog | Prior art | Not a dependency. The Horn layer is our analogue. |
+| Hets | Heterogeneous tool set | Declined as a dependency. Its institution and comorphism core is reimplemented small and machine-checked here. Below. |
+| DOL | Specification language | Parsing deliberately deferred. Decision 0009 says why. |
Anything marked under construction is on an unmerged branch and is not a capability yet. This
document will be wrong the moment that changes, so treat the branch state as authoritative.
@@ -181,6 +183,40 @@ CertifyingDatalog, presented at ITP 2025, is the closest published prior art and
It certifies Datalog derivations in Lean; our Horn layer is the analogue reached independently, and the
comparison is worth making in any write-up rather than avoided.
+## Hets, institutions, and the part that was worth taking
+
+The Heterogeneous Tool Set is the engineering that goes with Goguen and Burstall's institutions. Its
+value is breadth: dozens of logics, and translations between them, in one program. Its comorphisms
+are Haskell type-class instances supplying a signature map, a sentence map and a model map, and the
+satisfaction condition that makes those three a translation of logics is discharged in the
+literature rather than by the program. Decision 0005 already said as much, "Hets proves its
+OWL-to-CASL comorphism on paper", and nobody here has read the Hets source, so that is a statement
+about its published design and not a code review.
+
+It is declined as a dependency for the obvious reasons and one that matters more. The obvious ones:
+it is a Haskell program, nothing in this CI builds Haskell, and running it would add a large
+unverified tool to the trust surface. The one that matters: what it would add is exactly the thing
+this project does not accept on testimony. An unchecked satisfaction condition is the same category
+of claim as an unchecked refutation, and decision 0005 already rules on that category.
+
+What was taken is the idea, which is public and is the only part that carries weight.
+`lean/OOCert/Institution.lean` and `lean/OOCert/Comorphism.lean` state an institution and a
+comorphism in core Lean with the satisfaction condition as a FIELD, so neither can be constructed
+without a proof of it, and `lean/OOCert/InstitutionRdf.lean` and `lean/OOCert/InstitutionFol.lean`
+discharge it for three institutions and two comorphisms built out of model classes this repository
+already had. That is three logics against Hets's dozens, and it is three logics whose translations
+are machine-checked rather than argued. The trade is breadth for evidence and it is the same trade
+this project makes everywhere else.
+
+Reflection is kept apart from preservation in the types, because the two are different theorems and
+only the first is free. `lean/OOCert/InstitutionWitness.lean` exhibits a comorphism between two of
+these institutions that preserves entailment and provably does not reflect it, so the separation is
+measured here rather than warned about.
+
+DOL, the language for saying "interpret this specification into that one along this comorphism", is
+not parsed and will not be until there is more than one proved comorphism for it to distribute over.
+Building the notation before the table it indexes would be a front end onto two rows.
+
## Interchange formats
TPTP is the execution format, because it is the only one an installed solver will read. CLIF is the
diff --git a/docs/trusted-computing-base.md b/docs/trusted-computing-base.md
index 81e32df5..e1d79fac 100644
--- a/docs/trusted-computing-base.md
+++ b/docs/trusted-computing-base.md
@@ -396,6 +396,23 @@ verified. Each entry says what would close it.
Kani harnesses cover four pure functions totalling about twenty lines. That is the correct
proportion to report: this work verified the joint, not the machine.
+## What the institution layer does not move
+
+`lean/OOCert/Institution.lean` and the four modules with it prove that two translations between
+logics satisfy their satisfaction conditions, and decision 0009 says what that buys. It buys nothing
+on this page, and the reason is worth stating because the two things sound alike.
+
+The comorphism proved in `lean/OOCert/InstitutionFol.lean` runs between two LEAN developments: the
+RDF interpretations of `OOCert/Semantics.lean` and the first-order structures of
+`Fol/Semantics.lean`. It is not `src/tptp.rs`'s translation and says nothing about it. Decision 0005
+item 2 is unchanged: the correspondence between the Rust emitter and the Lean translation is pinned
+by hand-computed tests and is not proved, and the emitted file still says so.
+
+The layer has no run-time part at all. It writes no file, reads no file, produces no certificate and
+no verdict word, and no executable imports it, which is why it is a separate `lean_lib` from
+`OOCert`. Nothing in the property list above changes, no `TCB-*` identifier is retired, and the
+count of trusted properties is what it was.
+
The honest summary is that the trusted base is four things: the serialisation of a term, the
identity of the asserted graph, the completeness of the derivation record, and the identity of the
rule table. Those are now property-tested and, for the pure parts, bounded-model-checked. Every one
diff --git a/lean/Institution.lean b/lean/Institution.lean
new file mode 100644
index 00000000..4868f6d4
--- /dev/null
+++ b/lean/Institution.lean
@@ -0,0 +1,41 @@
+import OOCert.Institution
+import OOCert.Comorphism
+import OOCert.InstitutionRdf
+import OOCert.InstitutionFol
+import OOCert.InstitutionWitness
+
+/-!
+# `Institution`: what a logic is, what a translation between two logics is, and
+# the obligation neither may be built without
+
+The root module. Importing this builds every proof in the institution layer,
+including the axiom pins in `OOCert/InstitutionWitness.lean`, so a `sorry`, a
+`native_decide` or a changed axiom footprint anywhere in the layer fails
+`lake build`.
+
+It is a SEPARATE library from `OOCert` on purpose. `OOCert.lean` is what
+`Main.lean` and `HMain.lean` import, so anything added to it goes into the
+`oo-cert` and `oo-horn` binaries. The institution layer imports `Fol.Semantics`
+and has no run-time part at all: it is theorems about the two model classes the
+other libraries already carry, and there is no executable that would read it.
+
+* `OOCert/Institution.lean` the structure, with the satisfaction condition as a
+ field; entailment; the institution of theories; and the quarantined
+ functoriality laws.
+* `OOCert/Comorphism.lean` the translation, with its own satisfaction condition
+ as a field; entailment PRESERVATION with no hypothesis; entailment REFLECTION
+ under model expansiveness, which is a different theorem and is kept one.
+* `OOCert/InstitutionRdf.lean` two instances out of `Semantics.lean`: simple RDF
+ interpretations and OWL 2 RL ones, with `conditions_reduct` proving that the
+ twenty-three semantic conditions survive exactly those renamings that fix the
+ reserved vocabulary.
+* `OOCert/InstitutionFol.lean` the first-order instance out of
+ `Fol/Semantics.lean`, and the theoroidal comorphism from RDF into it.
+* `OOCert/InstitutionWitness.lean` the non-vacuity: distinct models in every
+ institution, models of the background theory, and the machine-checked pair
+ that separates preservation from reflection.
+
+What this layer is NOT is in `docs/decisions/0009-a-translation-between-logics-carries-its-satisfaction-condition.md`:
+no DOL parser, no Hets dependency, no naturality, and no borrowing theorem for
+the first-order comorphism.
+-/
diff --git a/lean/OOCert/Comorphism.lean b/lean/OOCert/Comorphism.lean
new file mode 100644
index 00000000..6bcd0b16
--- /dev/null
+++ b/lean/OOCert/Comorphism.lean
@@ -0,0 +1,262 @@
+import OOCert.Institution
+
+/-!
+# Comorphisms, and the two things they do not both do
+
+A comorphism is a translation from one logic to another: signatures forward,
+sentences forward, models BACKWARD, and one law tying the three together. It is
+the piece of the Heterogeneous Tool Set that carries the semantic weight, and in
+Hets its satisfaction condition is established on paper rather than by the
+program. Here it is the last field of the structure, so it cannot be skipped.
+
+## The obligation is a field, and that is the whole point
+
+`Comorphism.satCond` is data-free and proof-only. `Comorphism.mk` will not
+accept a signature map, a sentence map and a model map without it. An unproved
+translation is therefore not a lint warning, not a `TODO`, and not a
+documentation gap: it does not typecheck. Decision 0005's title is the thesis
+and this file is where the second half of it is cashed: a prover is an oracle,
+and a translation is a theorem. What is NOT cashed here is the Rust exporter's
+translation, which is pinned by tests and remains unproved; decision 0009 says
+so in the same breath as it says what IS proved.
+
+## Preservation and reflection are NOT the same theorem
+
+This is the distinction the file exists to keep apart, because conflating them
+is how a translation gets sold as a decision procedure it is not.
+
+* **Preservation** — if `Γ ⊨ φ` in the source then the translations entail the
+ translation in the target — follows from the satisfaction condition ALONE.
+ `preserves_entailment` below has no hypothesis beyond the comorphism itself.
+* **Reflection** — the converse — does NOT. It needs the source model class to
+ be covered by the target's, up to satisfaction. That is `ModelExpansive`, and
+ it is the condition under which "borrowing" is legitimate: running the target
+ logic's prover and reading the answer back as a source-logic answer.
+
+A comorphism that preserves and does not reflect is sound for proving and USELESS
+for refuting: a target non-entailment says nothing about the source. The two are
+proved separately, under separate hypotheses, and `InstitutionWitness.lean`
+exhibits a comorphism between two institutions of this repository that preserves
+entailment and provably does not reflect it, so the separation is a measured
+fact here and not a caution.
+
+## The weakest form of the borrowing condition
+
+`ModelExpansive` is usually written as "`modMap` is surjective". That is
+stronger than the proof needs and stronger than the instances can give. What the
+proof needs is that every source model is INDISTINGUISHABLE BY SENTENCES from
+some model in the image of `modMap`, which is what is written below.
+`ModelExpansive.of_surjective` proves surjectivity implies it, so nothing is lost
+by stating the weak form and a caller with the strong hypothesis is one lemma
+away.
+
+## What is NOT here
+
+* No comorphism modifications, no institution morphisms (the other variance), no
+ Grothendieck institution. Each is a real thing and none is needed to state or
+ discharge a satisfaction condition.
+* Nothing that reads a DOL document. Decision 0009 says why.
+-/
+namespace OOCert
+
+universe u v w x u₂ v₂ w₂ x₂ u₃ v₃ w₃ x₃
+
+/-- A comorphism from the institution `I` to the institution `J`.
+
+`sigMap` and `senMap` run forward, `modMap` runs backward, and `satCond` is the
+proof obligation that makes the three a translation of LOGICS rather than three
+unrelated functions.
+
+`modMap` is total on `J`-models of `sigMap S`. That is what makes the
+preservation theorem unconditional, and it is also what makes a theoroidal
+comorphism the right shape when the target needs axioms to reconstruct a source
+model: the axioms go into the signature, through `Institution.Th`, rather than
+into a side condition on `modMap`. -/
+structure Comorphism (I : Institution.{u, v, w, x}) (J : Institution.{u₂, v₂, w₂, x₂}) where
+ /-- Signatures, forward. -/
+ sigMap : I.Sig → J.Sig
+ /-- Sentences, forward, over the image signature. -/
+ senMap : {S : I.Sig} → I.Sen S → J.Sen (sigMap S)
+ /-- Models, BACKWARD. -/
+ modMap : {S : I.Sig} → J.Mod (sigMap S) → I.Mod S
+ /-- **The satisfaction condition of the comorphism.** A field. There is no
+ way to build a `Comorphism` without proving it. -/
+ satCond : ∀ {S : I.Sig} (M : J.Mod (sigMap S)) (φ : I.Sen S),
+ I.sat (modMap M) φ ↔ J.sat M (senMap φ)
+
+/-- A theoroidal comorphism: a comorphism into the institution of theories. The
+signature map may name target axioms, which is what a translation like OWL to
+first-order logic needs and what a plain comorphism cannot express. -/
+abbrev Theoroidal (I : Institution.{u, v, w, x}) (J : Institution.{u₂, v₂, w₂, x₂}) :=
+ Comorphism I (Institution.Th J)
+
+namespace Comorphism
+
+variable {I : Institution.{u, v, w, x}} {J : Institution.{u₂, v₂, w₂, x₂}}
+
+/-- The image of a premise set under the sentence map. -/
+def image (ρ : Comorphism I J) {S : I.Sig} (Γ : I.Sen S → Prop) : J.Sen (ρ.sigMap S) → Prop :=
+ fun ψ' => ∃ ψ, Γ ψ ∧ ρ.senMap ψ = ψ'
+
+/-- Half of the satisfaction condition, in the form the proofs below use: the
+reduct of a target model is a source model of the translated premises exactly
+when the target model satisfies them. -/
+theorem models_image (ρ : Comorphism I J) {S : I.Sig} {Γ : I.Sen S → Prop}
+ (M : J.Mod (ρ.sigMap S)) :
+ I.Models (ρ.modMap M) Γ ↔ J.Models M (ρ.image Γ) := by
+ constructor
+ · intro h ψ' hψ'
+ obtain ⟨ψ, hΓ, rfl⟩ := hψ'
+ exact (ρ.satCond M ψ).mp (h ψ hΓ)
+ · intro h ψ hΓ
+ exact (ρ.satCond M ψ).mpr (h (ρ.senMap ψ) ⟨ψ, hΓ, rfl⟩)
+
+/-- **A comorphism preserves entailment.** No hypothesis beyond the comorphism:
+the satisfaction condition is the whole proof.
+
+This is the theorem everybody wants from a translation and it is the one that
+comes free. Read it in the direction it runs: a source-logic entailment may be
+established in the target logic. Nothing here licenses the converse. -/
+theorem preserves_entailment (ρ : Comorphism I J) {S : I.Sig}
+ {Γ : I.Sen S → Prop} {φ : I.Sen S} (h : I.Entails Γ φ) :
+ J.Entails (ρ.image Γ) (ρ.senMap φ) := by
+ intro M hM
+ exact (ρ.satCond M φ).mp (h (ρ.modMap M) ((ρ.models_image M).mpr hM))
+
+/-- The list form, which is what the instances write. -/
+theorem preserves_entailmentL (ρ : Comorphism I J) {S : I.Sig}
+ {Γ : List (I.Sen S)} {φ : I.Sen S} (h : I.EntailsL Γ φ) :
+ J.EntailsL (Γ.map ρ.senMap) (ρ.senMap φ) := by
+ intro M hM
+ refine (ρ.satCond M φ).mp (h (ρ.modMap M) ?_)
+ intro ψ hψ
+ exact (ρ.satCond M ψ).mpr (hM (ρ.senMap ψ) (List.mem_map_of_mem hψ))
+
+/-- **The borrowing condition, in its weakest form.** Every source model is
+indistinguishable, by source sentences, from the reduct of some target model.
+
+Surjectivity of `modMap` implies this and is not implied by it, which is why
+the weak form is what the reflection theorem takes. -/
+def ModelExpansive (ρ : Comorphism I J) : Prop :=
+ ∀ (S : I.Sig) (M : I.Mod S), ∃ M' : J.Mod (ρ.sigMap S),
+ ∀ φ : I.Sen S, I.sat M φ ↔ I.sat (ρ.modMap M') φ
+
+/-- Surjectivity of the model map is the textbook hypothesis and it is
+stronger. Stated and proved so that a caller holding it need not weaken it by
+hand, and so that nothing downstream is tempted to assume the two are the
+same. -/
+theorem ModelExpansive.of_surjective (ρ : Comorphism I J)
+ (h : ∀ (S : I.Sig) (M : I.Mod S), ∃ M' : J.Mod (ρ.sigMap S), ρ.modMap M' = M) :
+ ρ.ModelExpansive := by
+ intro S M
+ obtain ⟨M', hM'⟩ := h S M
+ exact ⟨M', fun φ => by rw [hM']⟩
+
+/-- **A model-expansive comorphism reflects entailment.** This is the theorem
+that licenses borrowing: a target-logic answer read back as a source-logic
+answer, including a NEGATIVE answer.
+
+It is stated separately from `preserves_entailment` and under its own
+hypothesis on purpose. Without `ModelExpansive` it is false, and
+`InstitutionWitness.lean` exhibits the comorphism that makes it false. -/
+theorem reflects_entailment (ρ : Comorphism I J) (hexp : ρ.ModelExpansive) {S : I.Sig}
+ {Γ : I.Sen S → Prop} {φ : I.Sen S} (h : J.Entails (ρ.image Γ) (ρ.senMap φ)) :
+ I.Entails Γ φ := by
+ intro M hM
+ obtain ⟨M', hM'⟩ := hexp S M
+ have hmods : I.Models (ρ.modMap M') Γ := by
+ intro ψ hψ
+ exact (hM' ψ).mp (hM ψ hψ)
+ have : J.sat M' (ρ.senMap φ) := h M' ((ρ.models_image M').mp hmods)
+ exact (hM' φ).mpr ((ρ.satCond M' φ).mpr this)
+
+/-- Borrowing, stated as the biconditional a user actually wants, under the
+hypothesis it actually needs. -/
+theorem borrowing (ρ : Comorphism I J) (hexp : ρ.ModelExpansive) {S : I.Sig}
+ {Γ : I.Sen S → Prop} {φ : I.Sen S} :
+ I.Entails Γ φ ↔ J.Entails (ρ.image Γ) (ρ.senMap φ) :=
+ ⟨ρ.preserves_entailment, ρ.reflects_entailment hexp⟩
+
+/-! ## Theoroidal preservation, unfolded
+
+A theoroidal comorphism's preservation theorem is `preserves_entailment` at
+`Institution.Th J`. Unfolded, it says what the OWL-to-first-order shape of
+decision 0005 says: the target must be asked the question with the background
+axioms in the premise set. Stating it in that form here means no instance has to
+unfold `Th` by hand. -/
+
+theorem preserves_entailment_theoroidal {J : Institution.{u₂, v₂, w₂, x₂}}
+ (ρ : Theoroidal I J) {S : I.Sig} {Γ : I.Sen S → Prop} {φ : I.Sen S}
+ (h : I.Entails Γ φ) :
+ ∀ M : J.Mod (ρ.sigMap S).base, J.Models M (ρ.sigMap S).ax →
+ J.Models M (ρ.image Γ) → J.sat M (ρ.senMap φ) := by
+ intro M hax hΓ
+ exact (Institution.th_entails_iff J (ρ.image Γ) (ρ.senMap φ)).mp
+ (ρ.preserves_entailment h) M hax hΓ
+
+/-! ## Identity and composition
+
+Neither is needed by any theorem above. They are here because a translation
+layer that cannot compose two proved translations is not a layer, and because
+composition is the one operation whose satisfaction condition a reader will
+otherwise assume rather than check. It is checked. -/
+
+/-- The identity comorphism. -/
+def idC (I : Institution.{u, v, w, x}) : Comorphism I I where
+ sigMap := fun S => S
+ senMap := fun φ => φ
+ modMap := fun M => M
+ satCond := fun _ _ => Iff.rfl
+
+/-- Composition of comorphisms, with the composite satisfaction condition
+PROVED rather than assumed. -/
+def comp {K : Institution.{u₃, v₃, w₃, x₃}}
+ (ρ : Comorphism I J) (τ : Comorphism J K) : Comorphism I K where
+ sigMap := fun S => τ.sigMap (ρ.sigMap S)
+ senMap := fun φ => τ.senMap (ρ.senMap φ)
+ modMap := fun M => ρ.modMap (τ.modMap M)
+ satCond := fun M φ => (ρ.satCond (τ.modMap M) φ).trans (τ.satCond M (ρ.senMap φ))
+
+end Comorphism
+
+/-- The quarantine pays off here: the general theorem applies to a
+`Institution.Functorial` verbatim, by projection, with no re-proof. This is the
+analogue of `W3CEntails.of_entails` for this layer, and it is what "the original
+is untouched" means operationally. -/
+theorem functorial_preserves_entailment (C : Institution.Functorial.{u, v, w, x})
+ (D : Institution.Functorial.{u₂, v₂, w₂, x₂})
+ (ρ : Comorphism C.toInstitution D.toInstitution) {S : C.toInstitution.Sig}
+ {Γ : C.toInstitution.Sen S → Prop} {φ : C.toInstitution.Sen S}
+ (h : C.toInstitution.Entails Γ φ) :
+ D.toInstitution.Entails (ρ.image Γ) (ρ.senMap φ) :=
+ ρ.preserves_entailment h
+
+/-- info: 'OOCert.Comorphism.preserves_entailment' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Comorphism.preserves_entailment
+
+/-- info: 'OOCert.Comorphism.preserves_entailmentL' depends on axioms: [propext, Quot.sound] -/
+#guard_msgs in
+#print axioms Comorphism.preserves_entailmentL
+
+/-- info: 'OOCert.Comorphism.reflects_entailment' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Comorphism.reflects_entailment
+
+/-- info: 'OOCert.Comorphism.borrowing' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Comorphism.borrowing
+
+/-- info: 'OOCert.Comorphism.ModelExpansive.of_surjective' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Comorphism.ModelExpansive.of_surjective
+
+/-- info: 'OOCert.Comorphism.preserves_entailment_theoroidal' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Comorphism.preserves_entailment_theoroidal
+
+/-- info: 'OOCert.functorial_preserves_entailment' does not depend on any axioms -/
+#guard_msgs in
+#print axioms functorial_preserves_entailment
+
+end OOCert
diff --git a/lean/OOCert/Institution.lean b/lean/OOCert/Institution.lean
new file mode 100644
index 00000000..ba2fcf87
--- /dev/null
+++ b/lean/OOCert/Institution.lean
@@ -0,0 +1,258 @@
+/-!
+# Institutions, in core Lean, with the satisfaction condition as an obligation
+
+An institution is Goguen and Burstall's answer to "what is a logic, for the
+purpose of moving things between logics". It is four pieces and one law: a
+category of signatures, a sentence functor, a model functor running the other
+way, a satisfaction relation, and the **satisfaction condition**, that truth is
+invariant under change of notation.
+
+This file states that in core Lean. There is no Mathlib here, so there is no
+`CategoryTheory.Functor` to lean on, and nothing below pretends there is. What
+is written is exactly what the theorems in `Comorphism.lean` consume, and no
+more.
+
+## The one field that matters
+
+`satCond` is a FIELD. An institution cannot be constructed without a proof of
+it. That is the whole design. In the Heterogeneous Tool Set a comorphism is a
+Haskell type-class instance supplying the three maps, and its satisfaction
+condition is discharged in the literature rather than by the program; decision
+0005 already put it that way, "Hets proves its OWL-to-CASL comorphism on paper".
+Here the proof is a constructor argument, so a missing one is a type error at
+the point of construction rather than a remark in a manual. Nobody on this
+branch has read the Hets source, so that is a statement about its published
+design and not a code review.
+
+## The weakest-conditions discipline, applied, and it points the opposite way
+## from `Semantics.lean`
+
+`Semantics.lean` carries a warning that a condition stronger than the
+specification shrinks the model class and silently weakens every downstream
+theorem. The same discipline applies here and it lands somewhere that looks
+wrong until it is followed through.
+
+`satCond` is a `∀` over signature morphisms, over target models, and over source
+sentences. So:
+
+* **More morphisms make a STRONGER institution.** Every constraint added to
+ `SigMor` removes morphisms and therefore removes instances of the law. An
+ instance below asks of its morphisms exactly what its `modRed` needs to land
+ in `Mod`, and nothing else.
+* **More sentences make a STRONGER institution.** Restricting `Sen S` to the
+ formulas "over" the signature `S` is the textbook presentation and it is a
+ WEAKENING of the law. It is done below only where a downstream comorphism
+ genuinely cannot hold without it, and where it is done the restriction is the
+ weakest one that works: `Rdf.Sen` constrains the PREDICATE position of a
+ triple and leaves subject and object free, because only the predicate's
+ denotation is what the relevant satisfaction condition turns on.
+* **More models make a STRONGER institution** in the satisfaction condition and
+ a WEAKER one in `Entails`. The two pull opposite ways, and every instance
+ below says at its `Mod` field which of the two it is trading.
+
+`Sen` and `Mod` are declared as families indexed by `Sig` because the abstract
+law needs them to be. ALL THREE instances in this development have a `Mod` that
+does not in fact vary with the signature, and each says so at the field rather
+than dressing it up: a `Fol.Struc` interprets every symbol and an `OOCert.Interp`
+denotes every term, so there is nothing for a signature to cut down, and cutting
+the model class down anyway would shrink it for nothing.
+
+## Universes
+
+`Sig`, `SigMor`, `Sen` and `Mod` are separately universe-polymorphic because
+they have to be. `OOCert.Interp` carries `D : Type` and so lives in `Type 1`,
+`Fol.Struc` likewise, while a signature here is a list of strings and lives in
+`Type`. A single-universe `Institution` could not hold both.
+
+## What is NOT here
+
+* No category laws on `SigMor` and no functoriality for `senMap` or `modRed`.
+ Not because they are false of the instances — `Institution.Functorial` below
+ carries them and `InstitutionWitness.lean` discharges them for the RDF
+ instance — but because no theorem in `Comorphism.lean` uses them, so putting
+ them in `Institution` would remove institutions from the class for nothing.
+ This is the `W3C.lean` quarantine, applied to this layer.
+* No room semantics, no structured specifications, no DOL. Decision 0009 says
+ why the parser is deferred rather than merely missing.
+-/
+namespace OOCert
+
+universe u v w x u₂ v₂ w₂ x₂
+
+-- `checkUnivs` fires on both structures below because their own type is a
+-- `max` of the four universes and none of the four appears alone in it. That is
+-- exactly the shape wanted here: see the Universes section above.
+set_option linter.checkUnivs false in
+/-- An institution: signatures, signature morphisms, sentences, models,
+satisfaction, and the satisfaction condition.
+
+The satisfaction condition reads: for a signature morphism `σ : S ⟶ S'`, an
+`S'`-model `M` and an `S`-sentence `φ`,
+
+> the reduct of `M` along `σ` satisfies `φ` exactly when `M` satisfies the
+> translation of `φ` along `σ`.
+
+Truth does not depend on notation. Every field below is data except the last,
+which is the obligation. -/
+structure Institution where
+ /-- Signatures. -/
+ Sig : Type u
+ /-- Signature morphisms. A family rather than a category: see the header. -/
+ SigMor : Sig → Sig → Type v
+ /-- Sentences over a signature. -/
+ Sen : Sig → Type w
+ /-- Models of a signature. -/
+ Mod : Sig → Type x
+ /-- Sentence translation, along the morphism. -/
+ senMap : {S S' : Sig} → SigMor S S' → Sen S → Sen S'
+ /-- Model reduction, AGAINST the morphism. This is the contravariance that
+ makes an institution an institution rather than a pair of maps. -/
+ modRed : {S S' : Sig} → SigMor S S' → Mod S' → Mod S
+ /-- Satisfaction. -/
+ sat : {S : Sig} → Mod S → Sen S → Prop
+ /-- **The satisfaction condition.** Not a lemma, not a convention: a field,
+ so that no institution exists without it. -/
+ satCond : ∀ {S S' : Sig} (σ : SigMor S S') (M : Mod S') (φ : Sen S),
+ sat (modRed σ M) φ ↔ sat M (senMap σ φ)
+
+namespace Institution
+
+variable (I : Institution.{u, v, w, x})
+
+/-- `M` satisfies every sentence of `Γ`. `Γ` is a PREDICATE and not a list: the
+theorems below never enumerate it, and a predicate is the weaker hypothesis to
+state them over. -/
+def Models {S : I.Sig} (M : I.Mod S) (Γ : I.Sen S → Prop) : Prop :=
+ ∀ ψ, Γ ψ → I.sat M ψ
+
+/-- `Γ ⊨ φ` over the signature `S`: every `S`-model of `Γ` satisfies `φ`. -/
+def Entails {S : I.Sig} (Γ : I.Sen S → Prop) (φ : I.Sen S) : Prop :=
+ ∀ M : I.Mod S, I.Models M Γ → I.sat M φ
+
+/-- The same relation with the premises given as a list, which is what the
+instances below actually write. -/
+def EntailsL {S : I.Sig} (Γ : List (I.Sen S)) (φ : I.Sen S) : Prop :=
+ I.Entails (fun ψ => ψ ∈ Γ) φ
+
+theorem entails_of_mem {S : I.Sig} {Γ : I.Sen S → Prop} {φ : I.Sen S} (h : Γ φ) :
+ I.Entails Γ φ := fun _ hM => hM φ h
+
+theorem entailsL_of_mem {S : I.Sig} {Γ : List (I.Sen S)} {φ : I.Sen S} (h : φ ∈ Γ) :
+ I.EntailsL Γ φ := entails_of_mem I h
+
+/-- Entailment is monotone in the premises. Weakening the premise set can only
+lose entailments, never gain them, which is the property every theorem about a
+translation quietly assumes and none of them states. -/
+theorem entails_mono {S : I.Sig} {Γ Δ : I.Sen S → Prop} {φ : I.Sen S}
+ (hsub : ∀ ψ, Γ ψ → Δ ψ) (h : I.Entails Γ φ) : I.Entails Δ φ :=
+ fun M hM => h M (fun ψ hψ => hM ψ (hsub ψ hψ))
+
+/-! ## Theories
+
+A theoroidal comorphism sends a signature to a THEORY of the target, not to a
+signature: `owl-lean`'s adequacy theorem is of that shape, since its right-hand
+side is `FOL.Entails (background ++ indAxioms inds ++ O.map trAx) (trAx a)` and
+`background` is target-side machinery that the source signature alone does not
+name. Rather than carry a second notion of comorphism, this development builds
+the institution of theories over `I` and lets a theoroidal comorphism be an
+ordinary comorphism into it. That is the standard construction and it keeps
+`Comorphism.lean` down to one structure and one obligation.
+
+The satisfaction condition of `Th I` is `I`'s own, unchanged: the extra data is
+carried by the signatures and the models, and neither `sat` nor `senMap` sees
+it. -/
+
+/-- A theory: a signature and a set of axioms over it. -/
+structure ThSig (I : Institution.{u, v, w, x}) where
+ /-- The underlying signature. -/
+ base : I.Sig
+ /-- The axioms. A predicate, so that an infinite axiomatisation is expressible
+ and nothing here depends on the set being listed. -/
+ ax : I.Sen base → Prop
+
+/-- The institution of theories over `I`.
+
+A morphism of theories carries the SEMANTIC condition that the reduct of a model
+of the target theory is a model of the source theory. That is the weakest thing
+that makes `modRed` land where it must. The syntactic condition usually written
+instead, that every translated axiom is an axiom of the target, is strictly
+stronger: it implies this one and removes morphisms that satisfy it, and by the
+header's first bullet that would be a weaker institution. -/
+def Th (I : Institution.{u, v, w, x}) : Institution.{max u w, v, w, x} where
+ Sig := ThSig I
+ SigMor := fun T T' =>
+ { σ : I.SigMor T.base T'.base //
+ ∀ M : I.Mod T'.base, I.Models M T'.ax → I.Models (I.modRed σ M) T.ax }
+ Sen := fun T => I.Sen T.base
+ Mod := fun T => { M : I.Mod T.base // I.Models M T.ax }
+ senMap := fun σ φ => I.senMap σ.1 φ
+ modRed := fun σ M => ⟨I.modRed σ.1 M.1, σ.2 M.1 M.2⟩
+ sat := fun M φ => I.sat M.1 φ
+ satCond := fun σ M φ => I.satCond σ.1 M.1 φ
+
+/-- Satisfaction in `Th I` is satisfaction in `I`. Stated because everything
+downstream reads it, and reading it off the definition by hand is how a layer
+acquires a silent mismatch. -/
+@[simp] theorem th_sat {T : ThSig I} (M : (Th I).Mod T) (φ : (Th I).Sen T) :
+ (Th I).sat M φ ↔ I.sat M.1 φ := Iff.rfl
+
+/-- Entailment in `Th I` is `I`-entailment from the axioms together with the
+premises. This is what makes the theory construction worth having rather than
+an encoding: the extra axioms are premises, and nothing else. -/
+theorem th_entails_iff {T : ThSig I} (Γ : I.Sen T.base → Prop) (φ : I.Sen T.base) :
+ (Th I).Entails (S := T) Γ φ ↔
+ ∀ M : I.Mod T.base, I.Models M T.ax → I.Models M Γ → I.sat M φ := by
+ constructor
+ · intro h M hax hΓ
+ exact h ⟨M, hax⟩ hΓ
+ · intro h M hΓ
+ exact h M.1 M.2 hΓ
+
+/-! ## The quarantine
+
+`Institution` above has no category laws and no functoriality. They are true of
+the instances in this development and they are not needed by any theorem in
+`Comorphism.lean`, so they are carried HERE, in a separate structure, exactly as
+`W3C.lean` carries the specification conditions away from `Conditions`.
+
+The reason is the one `W3C.lean` gives, transposed. Adding a field to
+`Institution` would REMOVE institutions from the class that `Comorphism`'s
+theorems quantify over. Every such theorem would still compile and would say
+less, with no error anywhere. The protection is that `toInstitution` below is a
+FIELD PROJECTION, so the object every theorem is about is unchanged, and
+`functorial_preserves_entailment` in `Comorphism.lean` is the demonstration:
+it is the general theorem applied, not a re-proof. -/
+
+set_option linter.checkUnivs false in
+/-- The functoriality laws, quarantined. An `Institution.Functorial` is an
+`Institution` with identities, composition, and the four laws saying that
+`senMap` is a functor and `modRed` a contravariant one.
+
+Nothing in this development consumes these fields. They exist so that the base
+structure can be checked against the textbook definition without the base
+structure paying for it, and `InstitutionWitness.lean` discharges them for the
+RDF instance so that the class is not empty. -/
+structure Functorial where
+ /-- The institution being strengthened. A projection: see the section header. -/
+ toInstitution : Institution.{u, v, w, x}
+ /-- The identity morphism. -/
+ id : ∀ S, toInstitution.SigMor S S
+ /-- Composition of morphisms. -/
+ comp : ∀ {S S' S'' : toInstitution.Sig},
+ toInstitution.SigMor S S' → toInstitution.SigMor S' S'' → toInstitution.SigMor S S''
+ senMap_id : ∀ (S : toInstitution.Sig) (φ : toInstitution.Sen S),
+ toInstitution.senMap (id S) φ = φ
+ senMap_comp : ∀ {S S' S'' : toInstitution.Sig}
+ (σ : toInstitution.SigMor S S') (τ : toInstitution.SigMor S' S'')
+ (φ : toInstitution.Sen S),
+ toInstitution.senMap (comp σ τ) φ = toInstitution.senMap τ (toInstitution.senMap σ φ)
+ modRed_id : ∀ (S : toInstitution.Sig) (M : toInstitution.Mod S),
+ toInstitution.modRed (id S) M = M
+ modRed_comp : ∀ {S S' S'' : toInstitution.Sig}
+ (σ : toInstitution.SigMor S S') (τ : toInstitution.SigMor S' S'')
+ (M : toInstitution.Mod S''),
+ toInstitution.modRed (comp σ τ) M = toInstitution.modRed σ (toInstitution.modRed τ M)
+
+end Institution
+
+end OOCert
diff --git a/lean/OOCert/InstitutionFol.lean b/lean/OOCert/InstitutionFol.lean
new file mode 100644
index 00000000..1f8a1f89
--- /dev/null
+++ b/lean/OOCert/InstitutionFol.lean
@@ -0,0 +1,255 @@
+import OOCert.InstitutionRdf
+import Fol.Semantics
+
+/-!
+# The first-order institution, and the RDF-to-first-order comorphism
+
+`Fol/Semantics.lean` already carries first-order structures and satisfaction,
+transcribed from `owl-lean`'s `OwlLean/FOL/Basic.lean`. This file makes that an
+institution, with the satisfaction condition for symbol renamings PROVED by
+induction over the formula, and then builds the translation that decision 0005
+is about: a triple goes to a binary atom, and a first-order model comes back as
+an RDF interpretation.
+
+## This is a THEOROIDAL comorphism, and it has to be
+
+`OOCert.Interp.iext` is keyed by the DENOTATION of the predicate: `iext (ι p) x y`.
+`Fol.Struc.p2` is keyed by the SYMBOL: `p2 p x y`. Two distinct predicate symbols
+may denote the same domain element while carrying different extensions, and then
+no ternary relation on the domain reproduces both, so the obvious model map
+cannot be defined on arbitrary target structures.
+
+**That is an ARGUMENT about the obvious construction and it is NOT a theorem.**
+Nothing here quantifies over all possible signature maps, sentence maps and model
+maps, so nothing here rules out a plain comorphism found by some other route, and
+this file does not claim one does not exist. What it claims is that the route
+taken below needed the theory and got it.
+
+The fix is the one `src/tptp.rs` already ships and decision 0005 already
+records: the target is not a signature but a THEORY. `cohAx` is the background
+axiom that makes the reconstruction work, `Institution.Th` is where it lives,
+and `Comorphism.Theoroidal` is the resulting shape. `owl-lean`'s adequacy
+theorem has exactly this form, with `background ++ indAxioms inds` on the
+first-order side.
+
+## What is proved here and what is not
+
+* `folInst.satCond` — satisfaction is invariant under renaming of unary
+ predicate, binary predicate and constant symbols. Proved, by induction.
+* `rdfToFol.satCond` — the translation's satisfaction condition. Proved, and it
+ is the field that `Comorphism.mk` will not let anyone skip.
+* Entailment preservation, by `Comorphism.preserves_entailment` applied. No new
+ argument.
+* **Model expansiveness is NOT proved and is NOT claimed.** So entailment
+ REFLECTION is not available for this comorphism, which means a first-order
+ prover's failure to find a proof says nothing here about RDF non-entailment.
+ That is decision 0005 item 5 restated as a missing theorem rather than as a
+ caution, and it is the honest state of the work.
+
+## This is not `OwlLean.adequacy`
+
+`OwlLean.adequacy` is a biconditional about the OWL 2 abstract syntax, with
+`background`, `indAxioms` and a freshness discipline, and it lives in a separate
+Lake package that this build does not and will not depend on: `lean/lakefile.toml`
+says core Lean only, no external packages, and pulling `owl-lean` in would put a
+second development inside this one's trust surface. What is here is the same
+SHAPE at the RDF triple level, over the two institutions this repository already
+has, with its own satisfaction condition proved from scratch. The relationship
+between the two is stated in decision 0009 and is not a dependency.
+-/
+namespace OOCert
+
+namespace FolInst
+
+/-! ## The institution
+
+`Sig` records a vocabulary and constrains NOTHING: `Sen` is every `Fol.Form` and
+`Mod` is every `Fol.Struc`, whatever the signature says. That is deliberate and
+it is the weakest-conditions rule of `Institution.lean` applied twice. A
+`Fol.Struc` interprets every symbol, so there is no reduct to a sub-vocabulary to
+take; a `Fol.Form` is a formula whatever symbols it mentions, so restricting
+`Sen` would only delete instances of the satisfaction condition. The vocabulary
+is carried because `Institution.Th` needs a base signature to hang a theory on
+and because the comorphism below has to name the finite set its background
+axioms range over.
+
+`SigMor` carries THREE independent renamings, one for each symbol space, rather
+than one renaming shared between them. `Fol/Syntax.lean` is explicit that the
+unary predicate, binary predicate and constant spaces are separate fields and
+that the prefixes in `src/tptp.rs` exist to keep them apart. Three maps admit
+strictly more morphisms than one, and more morphisms is a stronger satisfaction
+condition. -/
+
+/-- A first-order signature: the vocabulary, recorded. -/
+abbrev Sig : Type := List Fol.Sym
+
+/-- A signature morphism: a renaming of each of the three symbol spaces. No
+constraint, because `Sen` and `Mod` impose none. -/
+structure Mor (S S' : Sig) where
+ /-- Unary predicate symbols. -/
+ un : Fol.Sym → Fol.Sym
+ /-- Binary predicate symbols. -/
+ bin : Fol.Sym → Fol.Sym
+ /-- Constant symbols. -/
+ con : Fol.Sym → Fol.Sym
+
+/-- Renaming a first-order term. Variables are untouched: a signature morphism
+renames vocabulary, never binders, which is why the satisfaction condition below
+can share one assignment between the two sides. -/
+def renameTm (rc : Fol.Sym → Fol.Sym) : Fol.Term → Fol.Term
+ | .var n => .var n
+ | .const k => .const (rc k)
+
+/-- Renaming a formula, constructor for constructor. -/
+def renameF (ru rb rc : Fol.Sym → Fol.Sym) : Fol.Form → Fol.Form
+ | .app1 p t => .app1 (ru p) (renameTm rc t)
+ | .app2 p t u => .app2 (rb p) (renameTm rc t) (renameTm rc u)
+ | .eq t u => .eq (renameTm rc t) (renameTm rc u)
+ | .tru => .tru
+ | .fls => .fls
+ | .neg f => .neg (renameF ru rb rc f)
+ | .and f g => .and (renameF ru rb rc f) (renameF ru rb rc g)
+ | .or f g => .or (renameF ru rb rc f) (renameF ru rb rc g)
+ | .imp f g => .imp (renameF ru rb rc f) (renameF ru rb rc g)
+ | .all n f => .all n (renameF ru rb rc f)
+ | .ex n f => .ex n (renameF ru rb rc f)
+
+/-- The reduct of a structure along a renaming: each symbol is interpreted by
+whatever its image was interpreted by. The carrier is untouched, which is what
+lets an assignment be shared between a structure and its reduct. -/
+def redStruc (ru rb rc : Fol.Sym → Fol.Sym) (M : Fol.Struc) : Fol.Struc where
+ Dom := M.Dom
+ nonempty := M.nonempty
+ p1 := fun s => M.p1 (ru s)
+ p2 := fun s => M.p2 (rb s)
+ c := fun s => M.c (rc s)
+
+theorem eval_red (ru rb rc : Fol.Sym → Fol.Sym) (M : Fol.Struc)
+ (e : Fol.Env M) (t : Fol.Term) :
+ Fol.Term.eval (redStruc ru rb rc M) e t = Fol.Term.eval M e (renameTm rc t) := by
+ cases t <;> rfl
+
+/-- **The satisfaction condition of the first-order institution**, at the level
+of a single assignment. Induction over the formula; the quantifier cases go
+through because `Fol.update` does not mention the structure's interpretation
+maps, so the same assignment serves both sides. -/
+theorem holds_red (ru rb rc : Fol.Sym → Fol.Sym) (M : Fol.Struc) :
+ ∀ (f : Fol.Form) (e : Fol.Env M),
+ (Fol.Form.holds (redStruc ru rb rc M) e f ↔ Fol.Form.holds M e (renameF ru rb rc f)) := by
+ intro f
+ induction f with
+ | app1 p t => intro e; simp only [renameF, Fol.Form.holds, eval_red]; exact Iff.rfl
+ | app2 p t u => intro e; simp only [renameF, Fol.Form.holds, eval_red]; exact Iff.rfl
+ | eq t u => intro e; simp only [renameF, Fol.Form.holds, eval_red]; exact Iff.rfl
+ | tru => intro e; exact Iff.rfl
+ | fls => intro e; exact Iff.rfl
+ | neg f ih => intro e; simp only [renameF, Fol.Form.holds]; exact not_congr (ih e)
+ | and f g ihf ihg =>
+ intro e; simp only [renameF, Fol.Form.holds]; exact and_congr (ihf e) (ihg e)
+ | or f g ihf ihg =>
+ intro e; simp only [renameF, Fol.Form.holds]; exact or_congr (ihf e) (ihg e)
+ | imp f g ihf ihg =>
+ intro e; simp only [renameF, Fol.Form.holds]; exact imp_congr (ihf e) (ihg e)
+ | all n f ih =>
+ intro e
+ simp only [renameF, Fol.Form.holds]
+ exact ⟨fun h d => (ih (Fol.update e n d)).mp (h d),
+ fun h d => (ih (Fol.update e n d)).mpr (h d)⟩
+ | ex n f ih =>
+ intro e
+ simp only [renameF, Fol.Form.holds]
+ exact ⟨fun ⟨d, hd⟩ => ⟨d, (ih (Fol.update e n d)).mp hd⟩,
+ fun ⟨d, hd⟩ => ⟨d, (ih (Fol.update e n d)).mpr hd⟩⟩
+
+/-- **The institution of first-order structures.**
+
+`sat` is "true under EVERY assignment". `Fol.Entails` is not that relation: it
+quantifies the assignment OUTSIDE the implication, so it is assignment-wise
+rather than validity-based. The two agree on closed formulas and differ on open
+ones, `fol_entails_gives_institution_entails` proves the direction that holds,
+and `institution_entailment_is_strictly_weaker_on_open_formulas` refutes the
+other. Nothing here quietly identifies them. -/
+def folInst : Institution where
+ Sig := Sig
+ SigMor := Mor
+ Sen := fun _ => Fol.Form
+ Mod := fun _ => Fol.Struc
+ senMap := fun σ f => renameF σ.un σ.bin σ.con f
+ modRed := fun σ M => redStruc σ.un σ.bin σ.con M
+ sat := fun M f => ∀ e : Fol.Env M, Fol.Form.holds M e f
+ satCond := fun σ M f =>
+ ⟨fun h e => (holds_red σ.un σ.bin σ.con M f e).mp (h e),
+ fun h e => (holds_red σ.un σ.bin σ.con M f e).mpr (h e)⟩
+
+/-- `Fol.Entails` gives institution entailment. The hypothesis is applied once
+per assignment, which is exactly the step that does not run backwards. -/
+theorem fol_entails_gives_institution_entails {S : Sig} (Γ : List Fol.Form) (f : Fol.Form)
+ (h : Fol.Entails Γ f) : folInst.EntailsL (S := S) Γ f := by
+ intro M hM e
+ exact h M e (fun g hg => hM g hg e)
+
+/-! ## The comorphism
+
+A triple becomes a binary atom. A first-order structure becomes an RDF
+interpretation by reading a property's extension off the symbols that denote it,
+and that reading is only correct because the theory says symbols denoting the
+same thing have the same extension. -/
+
+/-- The background axiom: if two binary predicate symbols denote the same
+individual then everything the first relates the second relates.
+
+Only ONE direction is stated. The axiom set below ranges over every ORDERED pair
+from the signature, so the other direction arrives as the axiom for the swapped
+pair, and a biconditional here would constrain the target models more than the
+proof needs. -/
+def cohAx (q p : Fol.Sym) : Fol.Form :=
+ .imp (.eq (.const q) (.const p))
+ (.all 0 (.all 1 (.imp (.app2 q (.var 0) (.var 1)) (.app2 p (.var 0) (.var 1)))))
+
+/-- The theory a signature is sent to: the same vocabulary, and one coherence
+axiom per ordered pair of terms in it. A PREDICATE rather than a list, so
+nothing has to enumerate the square of the signature. -/
+def cohTheory (S : Rdf.Sig) : Institution.ThSig folInst where
+ base := S
+ ax := fun f => ∃ q, q ∈ S ∧ ∃ p, p ∈ S ∧ f = cohAx q p
+
+/-- **The RDF-to-first-order comorphism, with its satisfaction condition
+proved.**
+
+The model map reads `iext d x y` as "some symbol OF THE SIGNATURE denotes `d`
+and relates `x` to `y`". Restricting to the signature is not tidiness: a symbol
+outside `S` has no coherence axiom, so the forward direction of the satisfaction
+condition would have nothing to appeal to. This is the same scoping that makes
+`Rdf.Sen` constrain the predicate position. -/
+def rdfToFol : Theoroidal Rdf.simple folInst where
+ sigMap := cohTheory
+ senMap := fun φ => .app2 φ.1.p (.const φ.1.s) (.const φ.1.o)
+ modMap := fun {S : Rdf.Sig} M =>
+ { D := M.1.Dom
+ ι := fun t => M.1.c t
+ iext := fun d x y => ∃ q, q ∈ S ∧ M.1.c q = d ∧ M.1.p2 q x y }
+ satCond := by
+ intro S M φ
+ constructor
+ · rintro ⟨q, hq, hcq, hpq⟩ e
+ have hax : folInst.sat M.1 (cohAx q φ.1.p) :=
+ M.2 (cohAx q φ.1.p) ⟨q, hq, φ.1.p, φ.2, rfl⟩
+ exact hax e hcq (M.1.c φ.1.s) (M.1.c φ.1.o) hpq
+ · intro h
+ refine M.1.nonempty.elim (fun d => ?_)
+ exact ⟨φ.1.p, φ.2, rfl, h (fun _ => d)⟩
+
+/-- Preservation, by the general theorem applied and nothing else. Unfolded
+through `Institution.Th`, it says what decision 0005's shape says: the
+first-order side must be asked the question with the background axioms in the
+premise set. -/
+theorem rdf_entailment_transfers_to_fol {S : Rdf.Sig} {Γ : Rdf.Sen S → Prop} {φ : Rdf.Sen S}
+ (h : Rdf.simple.Entails Γ φ) :
+ ∀ M : Fol.Struc, folInst.Models (S := S) M (cohTheory S).ax →
+ folInst.Models (S := S) M (rdfToFol.image Γ) →
+ folInst.sat (S := S) M (rdfToFol.senMap φ) :=
+ rdfToFol.preserves_entailment_theoroidal h
+
+end FolInst
+
+end OOCert
diff --git a/lean/OOCert/InstitutionRdf.lean b/lean/OOCert/InstitutionRdf.lean
new file mode 100644
index 00000000..1654f664
--- /dev/null
+++ b/lean/OOCert/InstitutionRdf.lean
@@ -0,0 +1,388 @@
+import OOCert.Comorphism
+import OOCert.Witness
+
+/-!
+# Two RDF institutions, and the comorphism between them that does not reflect
+
+`Institution.lean` is worth nothing until something is one. This file makes two
+things one, out of material that was already in this repository, and proves the
+satisfaction condition for both.
+
+| institution | models | morphisms may rename |
+|---|---|---|
+| `Rdf.simple` | every `OOCert.Interp` | ANY term, subject only to landing in the target vocabulary |
+| `Rdf.rl` | the `OOCert.Interp`s satisfying `OOCert.Conditions` | the same, EXCEPT the reserved vocabulary, which it must fix |
+
+The second column is the content. Satisfaction of a triple is invariant under
+any renaming at all, which is why `Rdf.simple` can take arbitrary renamings; the
+OWL 2 RL semantic conditions are NOT, because they are conditions stated at
+fixed terms, and `conditions_reduct` is the theorem that says a renaming fixing
+those terms carries them along. A renaming that moved `rdf:type` would take a
+model of the conditions to something that is not one, so `Rdf.rl` cannot admit
+it and says so in its morphism type rather than in a comment.
+
+## The design choices, and which way each one cuts
+
+Read these against the weakest-conditions section of `Institution.lean`.
+
+* **`Sen S` constrains the PREDICATE position only.** A sentence over `S` is a
+ triple whose predicate is in `S`; subject and object are unconstrained. That is
+ the weakest restriction that lets `senMap` land in `Sen S'`, and it is all that
+ `InstitutionFol.lean`'s comorphism needs: its background axioms range over the
+ signature, and the predicate position is the only one they have to cover.
+ Constraining all three would remove sentences, and removing sentences removes
+ instances of the satisfaction condition.
+* **`Mod S` does not depend on `S`.** An `OOCert.Interp` denotes EVERY term, so
+ there is no reduct-to-the-signature to take and nothing for `S` to cut down.
+ Cutting the class down anyway would strengthen `Entails` and weaken the
+ satisfaction condition at the same time, for nothing.
+* **`Rdf.simple` morphisms carry no condition beyond mapping the signature into
+ the target.** Requiring them to fix the reserved vocabulary, so that the two
+ institutions could share a morphism type, would remove morphisms from
+ `Rdf.simple` and weaken its satisfaction condition. The two therefore have
+ DIFFERENT morphism types, which is the honest outcome: the logical vocabulary
+ of a logic is whatever its semantic conditions pin down, and for simple RDF
+ interpretations that is nothing.
+
+## What this file proves about the checker
+
+`rl_entails_gives_entails` connects the institution to `Soundness.lean`: an
+entailment in `Rdf.rl` is an `OOCert.Entails`. **The converse is FALSE, and it is
+refuted rather than merely unclaimed.** `OOCert.Model` carries four conditions
+(`int`, `int2`, `uni`, `oneOf`) stated over `Chain G`, the RDF list read off the
+ASSERTED GRAPH. They are relative to a graph, not to a signature, so they are not
+sentences of this institution and there is nowhere in an institution to put them.
+`OOCert.Entails` therefore quantifies over a SMALLER class of interpretations and
+is the weaker relation, strictly:
+`InstitutionWitness.the_checker_entails_more_than_the_institution` exhibits a
+premise set and a conclusion that `Entails` holds of and `Rdf.rl.EntailsL` does
+not, using `cls-oo` and the Herbrand model of its premises. Decision 0009 records
+this as the open edge of the work.
+-/
+namespace OOCert
+
+namespace Rdf
+
+/-! ## The reserved vocabulary
+
+Exactly the terms `OOCert.Conditions` mentions. `owl:intersectionOf`,
+`owl:unionOf`, `owl:oneOf`, `rdf:first`, `rdf:rest` and `rdf:nil` are NOT here:
+they occur in `OOCert.Model`'s list fields and in no field of `Conditions`, and
+this institution's models are `Conditions` only. Adding them would constrain
+morphisms that nothing here needs constrained.
+
+`Reserved` is a disjunction of equations rather than membership in a list on
+purpose. Every proof below is `Or.inl rfl` or a chain of `Or.inr`, which the
+kernel checks in no time, where `t ∈ reservedList` would put fifteen
+fifty-character IRIs through `String.decEq` at every use site. -/
+
+/-- A term whose denotation `OOCert.Conditions` constrains. -/
+def Reserved (t : Term) : Prop :=
+ t = V.type ∨ t = V.subClassOf ∨ t = V.subPropertyOf ∨ t = V.domain ∨ t = V.range ∨
+ t = V.transitiveProperty ∨ t = V.symmetricProperty ∨ t = V.inverseOf ∨ t = V.sameAs ∨
+ t = V.equivalentClass ∨ t = V.equivalentProperty ∨ t = V.onProperty ∨
+ t = V.someValuesFrom ∨ t = V.allValuesFrom ∨ t = V.hasValue
+
+namespace Reserved
+theorem type : Reserved V.type := Or.inl rfl
+theorem subClassOf : Reserved V.subClassOf := Or.inr (Or.inl rfl)
+theorem subPropertyOf : Reserved V.subPropertyOf := Or.inr (Or.inr (Or.inl rfl))
+theorem domain : Reserved V.domain := Or.inr (Or.inr (Or.inr (Or.inl rfl)))
+theorem range : Reserved V.range := Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))
+theorem transitiveProperty : Reserved V.transitiveProperty :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))
+theorem symmetricProperty : Reserved V.symmetricProperty :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))
+theorem inverseOf : Reserved V.inverseOf :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))
+theorem sameAs : Reserved V.sameAs :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))
+theorem equivalentClass : Reserved V.equivalentClass :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))
+theorem equivalentProperty : Reserved V.equivalentProperty :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr
+ (Or.inr (Or.inl rfl))))))))))
+theorem onProperty : Reserved V.onProperty :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr
+ (Or.inr (Or.inr (Or.inl rfl)))))))))))
+theorem someValuesFrom : Reserved V.someValuesFrom :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr
+ (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))
+theorem allValuesFrom : Reserved V.allValuesFrom :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr
+ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))))
+theorem hasValue : Reserved V.hasValue :=
+ Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr
+ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr rfl)))))))))))))
+end Reserved
+
+/-! ## Renaming, and the reduct it induces -/
+
+/-- A renaming applied to a triple. -/
+def renameT (r : Term → Term) (t : Triple) : Triple := ⟨r t.s, r t.p, r t.o⟩
+
+/-- The reduct of an interpretation along a renaming: the same domain and the
+same property extensions, with each term denoting what its image denoted.
+
+This is model reduction in the institution sense. It runs AGAINST the renaming,
+which is the contravariance that makes the satisfaction condition say something:
+a sentence is pushed forward and a model is pulled back, and they meet. -/
+def reduct (r : Term → Term) (I : Interp) : Interp where
+ D := I.D
+ ι := fun t => I.ι (r t)
+ iext := I.iext
+
+/-- **Satisfaction of a triple is invariant under any renaming whatever.** It is
+`Iff.rfl`, and that is the point: nothing about a triple's truth depends on the
+spelling of its terms, so the simple institution below can admit every renaming
+as a signature morphism. -/
+theorem reduct_sat (r : Term → Term) (I : Interp) (t : Triple) :
+ (reduct r I).sat t ↔ I.sat (renameT r t) := Iff.rfl
+
+/-! ### The conditions travel exactly as far as the renaming leaves them alone -/
+
+section Transport
+
+/-! `hr` is written out on every statement below rather than carried by a
+`variable`, because a `variable` that appears only in a proof term is not
+included in the signature and every one of these needs it. -/
+
+theorem reduct_ι_res {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ {v : Term} (hv : Reserved v) : (reduct r I).ι v = I.ι v :=
+ congrArg I.ι (hr v hv)
+
+theorem reduct_iext_res {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ {v : Term} (hv : Reserved v) (x y : I.D) :
+ (reduct r I).iext ((reduct r I).ι v) x y ↔ I.iext (I.ι v) x y := by
+ rw [reduct_ι_res hr I hv]
+ exact Iff.rfl
+
+theorem reduct_cext {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ (c x : I.D) : (reduct r I).cext c x ↔ I.cext c x := by
+ show (reduct r I).iext ((reduct r I).ι V.type) x c ↔ _
+ rw [reduct_ι_res hr I Reserved.type]
+ exact Iff.rfl
+
+theorem reduct_sc {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ (a b : I.D) : (reduct r I).sc a b ↔ I.sc a b :=
+ reduct_iext_res hr I Reserved.subClassOf a b
+
+theorem reduct_sp {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ (a b : I.D) : (reduct r I).sp a b ↔ I.sp a b :=
+ reduct_iext_res hr I Reserved.subPropertyOf a b
+
+/-- **The OWL 2 RL semantic conditions survive a renaming that fixes the
+reserved vocabulary.** Twenty-three fields, each one a rewrite at the terms the
+condition names, and nothing else changes: the domain and the property
+extensions are the same objects.
+
+This is the obligation `Rdf.rl.modRed` cannot be written without, and it is the
+reason `Rdf.rl` and `Rdf.simple` have different morphism types. -/
+theorem conditions_reduct {r : Term → Term} (hr : ∀ t, Reserved t → r t = t) (I : Interp)
+ (h : Conditions I) : Conditions (reduct r I) where
+ sc_sub := fun a b hab x hx =>
+ (reduct_cext hr I b x).mpr
+ (h.sc_sub a b ((reduct_sc hr I a b).mp hab) x ((reduct_cext hr I a x).mp hx))
+ sc_trans := fun a b c hab hbc =>
+ (reduct_sc hr I a c).mpr
+ (h.sc_trans a b c ((reduct_sc hr I a b).mp hab) ((reduct_sc hr I b c).mp hbc))
+ sp_sub := fun a b hab x y hxy =>
+ h.sp_sub a b ((reduct_sp hr I a b).mp hab) x y hxy
+ sp_trans := fun a b c hab hbc =>
+ (reduct_sp hr I a c).mpr
+ (h.sp_trans a b c ((reduct_sp hr I a b).mp hab) ((reduct_sp hr I b c).mp hbc))
+ dom := fun p c hpc x y hxy =>
+ (reduct_cext hr I c x).mpr
+ (h.dom p c ((reduct_iext_res hr I Reserved.domain p c).mp hpc) x y hxy)
+ rng := fun p c hpc x y hxy =>
+ (reduct_cext hr I c y).mpr
+ (h.rng p c ((reduct_iext_res hr I Reserved.range p c).mp hpc) x y hxy)
+ trp := fun p hp x y z hxy hyz =>
+ h.trp p (by
+ have := (reduct_cext hr I ((reduct r I).ι V.transitiveProperty) p).mp hp
+ rwa [reduct_ι_res hr I Reserved.transitiveProperty] at this) x y z hxy hyz
+ symp := fun p hp x y hxy =>
+ h.symp p (by
+ have := (reduct_cext hr I ((reduct r I).ι V.symmetricProperty) p).mp hp
+ rwa [reduct_ι_res hr I Reserved.symmetricProperty] at this) x y hxy
+ inv := fun p q hpq x y =>
+ h.inv p q ((reduct_iext_res hr I Reserved.inverseOf p q).mp hpq) x y
+ same := fun a b hab =>
+ h.same a b ((reduct_iext_res hr I Reserved.sameAs a b).mp hab)
+ eqc := fun a b hab => by
+ have := h.eqc a b ((reduct_iext_res hr I Reserved.equivalentClass a b).mp hab)
+ exact ⟨(reduct_sc hr I a b).mpr this.1, (reduct_sc hr I b a).mpr this.2⟩
+ eqp := fun a b hab => by
+ have := h.eqp a b ((reduct_iext_res hr I Reserved.equivalentProperty a b).mp hab)
+ exact ⟨(reduct_sp hr I a b).mpr this.1, (reduct_sp hr I b a).mpr this.2⟩
+ svf := fun rr p c hop hsv x y hxy hy =>
+ (reduct_cext hr I rr x).mpr
+ (h.svf rr p c ((reduct_iext_res hr I Reserved.onProperty rr p).mp hop)
+ ((reduct_iext_res hr I Reserved.someValuesFrom rr c).mp hsv)
+ x y hxy ((reduct_cext hr I c y).mp hy))
+ avf := fun rr p c hop hav x y hx hxy =>
+ (reduct_cext hr I c y).mpr
+ (h.avf rr p c ((reduct_iext_res hr I Reserved.onProperty rr p).mp hop)
+ ((reduct_iext_res hr I Reserved.allValuesFrom rr c).mp hav)
+ x y ((reduct_cext hr I rr x).mp hx) hxy)
+ hv := fun rr p v hop hhv x =>
+ (reduct_cext hr I rr x).trans
+ (h.hv rr p v ((reduct_iext_res hr I Reserved.onProperty rr p).mp hop)
+ ((reduct_iext_res hr I Reserved.hasValue rr v).mp hhv) x)
+ svf_sc := fun c1 c2 p y1 y2 h1 h2 h3 h4 h5 =>
+ (reduct_sc hr I c1 c2).mpr
+ (h.svf_sc c1 c2 p y1 y2
+ ((reduct_iext_res hr I Reserved.someValuesFrom c1 y1).mp h1)
+ ((reduct_iext_res hr I Reserved.onProperty c1 p).mp h2)
+ ((reduct_iext_res hr I Reserved.someValuesFrom c2 y2).mp h3)
+ ((reduct_iext_res hr I Reserved.onProperty c2 p).mp h4)
+ ((reduct_sc hr I y1 y2).mp h5))
+ svf_sp := fun c1 c2 p1 p2 y h1 h2 h3 h4 h5 =>
+ (reduct_sc hr I c1 c2).mpr
+ (h.svf_sp c1 c2 p1 p2 y
+ ((reduct_iext_res hr I Reserved.someValuesFrom c1 y).mp h1)
+ ((reduct_iext_res hr I Reserved.onProperty c1 p1).mp h2)
+ ((reduct_iext_res hr I Reserved.someValuesFrom c2 y).mp h3)
+ ((reduct_iext_res hr I Reserved.onProperty c2 p2).mp h4)
+ ((reduct_sp hr I p1 p2).mp h5))
+ avf_sc := fun c1 c2 p y1 y2 h1 h2 h3 h4 h5 =>
+ (reduct_sc hr I c1 c2).mpr
+ (h.avf_sc c1 c2 p y1 y2
+ ((reduct_iext_res hr I Reserved.allValuesFrom c1 y1).mp h1)
+ ((reduct_iext_res hr I Reserved.onProperty c1 p).mp h2)
+ ((reduct_iext_res hr I Reserved.allValuesFrom c2 y2).mp h3)
+ ((reduct_iext_res hr I Reserved.onProperty c2 p).mp h4)
+ ((reduct_sc hr I y1 y2).mp h5))
+ avf_sp := fun c1 c2 p1 p2 y h1 h2 h3 h4 h5 =>
+ (reduct_sc hr I c2 c1).mpr
+ (h.avf_sp c1 c2 p1 p2 y
+ ((reduct_iext_res hr I Reserved.allValuesFrom c1 y).mp h1)
+ ((reduct_iext_res hr I Reserved.onProperty c1 p1).mp h2)
+ ((reduct_iext_res hr I Reserved.allValuesFrom c2 y).mp h3)
+ ((reduct_iext_res hr I Reserved.onProperty c2 p2).mp h4)
+ ((reduct_sp hr I p1 p2).mp h5))
+ dom_sc := fun p c1 c2 hp hsc =>
+ (reduct_iext_res hr I Reserved.domain p c2).mpr
+ (h.dom_sc p c1 c2 ((reduct_iext_res hr I Reserved.domain p c1).mp hp)
+ ((reduct_sc hr I c1 c2).mp hsc))
+ dom_sp := fun p1 p2 c hp hsp =>
+ (reduct_iext_res hr I Reserved.domain p1 c).mpr
+ (h.dom_sp p1 p2 c ((reduct_iext_res hr I Reserved.domain p2 c).mp hp)
+ ((reduct_sp hr I p1 p2).mp hsp))
+ rng_sc := fun p c1 c2 hp hsc =>
+ (reduct_iext_res hr I Reserved.range p c2).mpr
+ (h.rng_sc p c1 c2 ((reduct_iext_res hr I Reserved.range p c1).mp hp)
+ ((reduct_sc hr I c1 c2).mp hsc))
+ rng_sp := fun p1 p2 c hp hsp =>
+ (reduct_iext_res hr I Reserved.range p1 c).mpr
+ (h.rng_sp p1 p2 c ((reduct_iext_res hr I Reserved.range p2 c).mp hp)
+ ((reduct_sp hr I p1 p2).mp hsp))
+
+end Transport
+
+/-! ## The two institutions -/
+
+/-- A signature is the vocabulary a sentence may use in PREDICATE position. -/
+abbrev Sig : Type := List Term
+
+/-- A sentence over `S`: a triple whose predicate is in `S`. Subject and object
+are free. See the header for why this is the weakest useful restriction. -/
+def Sen (S : Sig) : Type := { t : Triple // t.p ∈ S }
+
+/-- A signature morphism of `Rdf.simple`: a renaming that takes `S` into `S'`.
+That condition is exactly what `senMap` needs and there is nothing else. -/
+structure Mor (S S' : Sig) where
+ /-- The renaming. Total on terms: an RDF interpretation denotes every term, so
+ a partial renaming would have nothing to mean. -/
+ map : Term → Term
+ /-- Predicates land in the target vocabulary, which is what makes the
+ translation of a sentence a sentence. -/
+ into : ∀ t ∈ S, map t ∈ S'
+
+/-- A signature morphism of `Rdf.rl`: a `Mor` that additionally fixes every
+term the OWL 2 RL semantic conditions name. Without this field, `modRed` cannot
+be defined: `conditions_reduct` is exactly what fails. -/
+structure MorRl (S S' : Sig) extends Mor S S' where
+ /-- The reserved vocabulary is logical vocabulary and a renaming may not touch
+ it. -/
+ fixes : ∀ t, Reserved t → toMor.map t = t
+
+/-- **The institution of simple RDF interpretations.** Models are arbitrary
+`OOCert.Interp`s: no semantic conditions at all, so no renaming is forbidden.
+Its entailment relation is simple RDF entailment restricted to this repository's
+shape of interpretation. -/
+def simple : Institution where
+ Sig := Sig
+ SigMor := Mor
+ Sen := Sen
+ Mod := fun _ => Interp
+ senMap := fun σ φ => ⟨renameT σ.map φ.1, σ.into φ.1.p φ.2⟩
+ modRed := fun σ I => reduct σ.map I
+ sat := fun I φ => I.sat φ.1
+ satCond := fun _ _ _ => Iff.rfl
+
+/-- **The institution of OWL 2 RL interpretations**, the ones `Semantics.lean`
+calls `Conditions`. Everything `Soundness.lean` proves is about this model
+class.
+
+The `modRed` field is where `conditions_reduct` is spent: reducing a model along
+a morphism has to produce a model, and it only does because `MorRl` fixes the
+reserved vocabulary. -/
+def rl : Institution where
+ Sig := Sig
+ SigMor := MorRl
+ Sen := Sen
+ Mod := fun _ => { I : Interp // Conditions I }
+ senMap := fun σ φ => ⟨renameT σ.toMor.map φ.1, σ.toMor.into φ.1.p φ.2⟩
+ modRed := fun σ M => ⟨reduct σ.toMor.map M.1, conditions_reduct σ.fixes M.1 M.2⟩
+ sat := fun M φ => M.1.sat φ.1
+ satCond := fun _ _ _ => Iff.rfl
+
+/-! ## The bridge to the checker
+
+`Soundness.lean` is stated over `OOCert.Entails`, which quantifies over
+`OOCert.Model I G`. That is a `Conditions` interpretation which additionally
+satisfies `G` and the four list-constructor conditions. So an `Rdf.rl`
+entailment, which quantifies over MORE interpretations, is the stronger
+statement and gives an `OOCert.Entails`. -/
+
+/-- An entailment in the OWL 2 RL institution is an `OOCert.Entails`. The
+converse is false: see the file header and
+`InstitutionWitness.the_checker_entails_more_than_the_institution`. -/
+theorem rl_entails_gives_entails {S : Sig} (Γ : List (Sen S)) (φ : Sen S)
+ (h : rl.EntailsL Γ φ) : Entails (Γ.map Subtype.val) φ.1 := by
+ intro I M
+ exact h ⟨I, M.conds⟩ (fun ψ hψ => M.facts ψ.1 (List.mem_map_of_mem hψ))
+
+/-! ## The comorphism, and the thing it does not do
+
+Forgetting the OWL 2 RL conditions is a comorphism from `Rdf.simple` to
+`Rdf.rl`. It is as simple as a comorphism gets: signatures and sentences are
+untouched and the model map is the inclusion of the smaller model class into the
+larger one, running backwards, which is the direction a comorphism's model map
+runs.
+
+It preserves entailment, by the general theorem and nothing else. It does NOT
+reflect entailment, and that is proved below rather than suspected: `rdfs9` is
+an entailment of the target that is not an entailment of the source. -/
+
+/-- **The comorphism.** `Comorphism.mk` would not accept this without the last
+field, which is the whole design. -/
+def forgetConditions : Comorphism simple rl where
+ sigMap := fun S => S
+ senMap := fun φ => φ
+ modMap := fun M => M.1
+ satCond := fun _ _ => Iff.rfl
+
+/-- Simple RDF entailment is OWL 2 RL entailment, by the general preservation
+theorem applied and not by a separate argument. -/
+theorem simple_entailment_is_rl_entailment {S : Sig} {Γ : List (Sen S)} {φ : Sen S}
+ (h : simple.EntailsL Γ φ) : rl.EntailsL Γ φ := by
+ have hmap : Γ.map forgetConditions.senMap = Γ := List.map_id Γ
+ have h2 := forgetConditions.preserves_entailmentL h
+ rw [hmap] at h2
+ exact h2
+
+end Rdf
+
+end OOCert
diff --git a/lean/OOCert/InstitutionWitness.lean b/lean/OOCert/InstitutionWitness.lean
new file mode 100644
index 00000000..5efd6069
--- /dev/null
+++ b/lean/OOCert/InstitutionWitness.lean
@@ -0,0 +1,502 @@
+import OOCert.InstitutionFol
+
+/-!
+# Witnesses: none of these institutions is empty, and the comorphism that does
+# not reflect really does not reflect
+
+A satisfaction condition over an empty model class is true and says nothing. A
+comorphism between two one-point institutions preserves entailment and proves
+nothing. `W3CWitness.lean` and `ConformingWitness.lean` set the standard for this
+repository and this file meets it for the institution layer.
+
+Four jobs, in order.
+
+1. **Two distinct models in every institution defined here**, distinguished by a
+ SENTENCE rather than by a term-level inequality, because a sentence is what
+ the satisfaction condition and `Entails` are stated over. `Rdf.rl` gets a
+ third, `herbrand svfWitness`, which is neither the everything-model nor the
+ nothing-model: a model class with only those two would distinguish no
+ condition from any other.
+2. **Two distinct models of the background theory** the RDF-to-first-order
+ comorphism translates into, so `rdf_entailment_transfers_to_fol` is not a
+ statement about the empty class. One of them, `eqStruc`, satisfies the
+ coherence axioms non-vacuously: its constants all denote the same element, so
+ the axiom's antecedent FIRES and the conclusion has to be earned.
+3. **The preservation-without-reflection pair, proved.** `rdfs9` is an
+ entailment of `Rdf.rl` and is not an entailment of `Rdf.simple`, so the
+ comorphism that forgets the OWL 2 RL conditions is not model-expansive.
+ `Comorphism.lean` says the two theorems are different; this is the
+ countermodel that makes the difference observable.
+4. **The quarantined structure is inhabited.** `simpleFunctorial` discharges
+ `Institution.Functorial` for `Rdf.simple`, so the four laws left out of
+ `Institution` were left out because nothing needs them and not because
+ nothing satisfies them.
+
+A fifth section does the same job for a mismatch that is easy to miss:
+`folInst`'s satisfaction is "true under every assignment" and `Fol.Entails` is
+assignment-wise. One implication holds and the other is refuted here with a
+two-element structure, so nobody reads the institution's `Entails` as
+`Fol.Entails`.
+
+A sixth refutes the other easy misreading. `OOCert.Entails`, the relation
+`certificate_sound` is about, is NOT entailment in `Rdf.rl`: it quantifies over
+strictly fewer interpretations, because `OOCert.Model` carries four conditions
+read off the asserted graph that no signature can hold. The implication runs one
+way only and `the_checker_entails_more_than_the_institution` is the countermodel
+for the other.
+-/
+namespace OOCert
+
+namespace InstitutionWitness
+
+open Rdf FolInst
+
+/-! ## Vocabulary for the witnesses
+
+Fresh names. `Witness.lean` already binds `tC`, `tR`, `tD`, `tp`, `tx`, `ty` in
+this namespace and reusing them would silently couple two files' witnesses. -/
+
+def iA : Term := "<http://ex.org/A>"
+def iB : Term := "<http://ex.org/B>"
+def iX : Term := "<http://ex.org/x>"
+
+/-- The signature every RDF witness below is stated over: `rdf:type` and
+`rdfs:subClassOf` in predicate position. -/
+def sigT : Rdf.Sig := [V.type, V.subClassOf]
+
+def senXA : Rdf.Sen sigT := ⟨⟨iX, V.type, iA⟩, List.Mem.head _⟩
+def senAB : Rdf.Sen sigT := ⟨⟨iA, V.subClassOf, iB⟩, List.Mem.tail _ (List.Mem.head _)⟩
+def senXB : Rdf.Sen sigT := ⟨⟨iX, V.type, iB⟩, List.Mem.head _⟩
+/-- A sentence about the `svf` witness graph of `Witness.lean`, used only to
+tell that model apart from the other two. -/
+def senSvf : Rdf.Sen sigT := ⟨⟨tx, V.type, tR⟩, List.Mem.head _⟩
+
+/-! ## 1. Every institution here has at least two distinct models
+
+The four lemmas below are `Iff.rfl`. They exist so that `decide` has a decidable
+proposition to work on: satisfaction in these institutions unfolds to membership
+in the witness graph, and stating that once keeps every refutation below a
+kernel computation over concrete strings rather than a tactic script. -/
+
+theorem simpleEmpty_sat (φ : Rdf.Sen sigT) :
+ Rdf.simple.sat (S := sigT) (herbrand []) φ ↔ φ.1 ∈ ([] : List Triple) := Iff.rfl
+
+/-- The everything-model and the nothing-model of `Rdf.simple`, told apart by a
+sentence. -/
+theorem simple_has_two_distinct_models :
+ Rdf.simple.sat (S := sigT) saturated senXA ∧
+ ¬ Rdf.simple.sat (S := sigT) (herbrand []) senXA := by
+ refine ⟨trivial, ?_⟩
+ rw [simpleEmpty_sat]
+ decide
+
+theorem simple_models_are_distinct : (saturated : Rdf.simple.Mod sigT) ≠ herbrand [] := by
+ intro h
+ exact simple_has_two_distinct_models.2 (h ▸ simple_has_two_distinct_models.1)
+
+/-- A model of `Rdf.rl` is an interpretation together with a proof that it
+satisfies `OOCert.Conditions`. All three below take that proof from a model
+theorem `Witness.lean` already proves, so nothing is re-derived here. -/
+def rlSaturated : Rdf.rl.Mod sigT := ⟨saturated, (saturated_is_a_model []).conds⟩
+def rlEmpty : Rdf.rl.Mod sigT := ⟨herbrand [], empty_herbrand_is_a_model.conds⟩
+/-- The one that is neither everything nor nothing: the Herbrand model of the
+`someValuesFrom` witness graph, which satisfies `svf` non-vacuously. -/
+def rlSvf : Rdf.rl.Mod sigT := ⟨herbrand svfWitness, svf_witness_is_a_model.conds⟩
+
+theorem rlEmpty_sat (φ : Rdf.Sen sigT) :
+ Rdf.rl.sat rlEmpty φ ↔ φ.1 ∈ ([] : List Triple) := Iff.rfl
+
+theorem rlSvf_sat (φ : Rdf.Sen sigT) :
+ Rdf.rl.sat rlSvf φ ↔ φ.1 ∈ svfWitness := Iff.rfl
+
+theorem rl_has_three_pairwise_distinct_models :
+ (Rdf.rl.sat rlSaturated senXA ∧ ¬ Rdf.rl.sat rlEmpty senXA) ∧
+ (Rdf.rl.sat rlSvf senSvf ∧ ¬ Rdf.rl.sat rlEmpty senSvf) ∧
+ (Rdf.rl.sat rlSaturated senXA ∧ ¬ Rdf.rl.sat rlSvf senXA) := by
+ refine ⟨⟨trivial, ?_⟩, ⟨?_, ?_⟩, ⟨trivial, ?_⟩⟩
+ · rw [rlEmpty_sat]; decide
+ · rw [rlSvf_sat]; decide
+ · rw [rlEmpty_sat]; decide
+ · rw [rlSvf_sat]; decide
+
+theorem rl_models_are_pairwise_distinct :
+ rlSaturated ≠ rlEmpty ∧ rlSvf ≠ rlEmpty ∧ rlSaturated ≠ rlSvf := by
+ refine ⟨?_, ?_, ?_⟩
+ · intro h
+ exact rl_has_three_pairwise_distinct_models.1.2
+ (h ▸ rl_has_three_pairwise_distinct_models.1.1)
+ · intro h
+ exact rl_has_three_pairwise_distinct_models.2.1.2
+ (h ▸ rl_has_three_pairwise_distinct_models.2.1.1)
+ · intro h
+ exact rl_has_three_pairwise_distinct_models.2.2.2
+ (h ▸ rl_has_three_pairwise_distinct_models.2.2.1)
+
+/-- Two first-order structures. `Fol.Struc.nonempty` is a field, so the carrier
+is `Unit` rather than `Empty`: an empty carrier is not a structure and
+`Fol/Semantics.lean` says why. -/
+def allTrue : Fol.Struc where
+ Dom := Unit
+ nonempty := ⟨()⟩
+ p1 := fun _ _ => True
+ p2 := fun _ _ _ => True
+ c := fun _ => ()
+
+def allFalse : Fol.Struc where
+ Dom := Unit
+ nonempty := ⟨()⟩
+ p1 := fun _ _ => False
+ p2 := fun _ _ _ => False
+ c := fun _ => ()
+
+/-- A unary atom, open in variable 0. -/
+def openP : Fol.Form := .app1 "P" (.var 0)
+
+theorem fol_has_two_distinct_models :
+ folInst.sat (S := []) allTrue openP ∧ ¬ folInst.sat (S := []) allFalse openP :=
+ ⟨fun _ => trivial, fun h => h (fun _ => ())⟩
+
+theorem fol_models_are_distinct : allTrue ≠ allFalse := by
+ intro h
+ exact fol_has_two_distinct_models.2 (h ▸ fol_has_two_distinct_models.1)
+
+/-! ## 2. The background theory has models, and one of them earns them
+
+`rdf_entailment_transfers_to_fol` quantifies over the models of `cohTheory S`.
+If that class were empty the theorem would be vacuous, so here are three
+structures in it.
+
+`allFalse` satisfies the coherence axiom by having a false antecedent inside the
+quantifiers, which is the degenerate way. `eqStruc` is the one that matters: every
+constant denotes `true`, so `c q = c p` HOLDS for every pair and the axiom's
+inner implication has to be discharged on its merits. It is, because every binary
+symbol is interpreted by the same relation. -/
+
+/-- All constants denote one element and every binary symbol means equality. The
+coherence axioms fire and are satisfied. -/
+def eqStruc : Fol.Struc where
+ Dom := Bool
+ nonempty := ⟨true⟩
+ p1 := fun _ _ => True
+ p2 := fun _ x y => x = y
+ c := fun _ => true
+
+theorem allTrue_models_coh (S : Rdf.Sig) :
+ folInst.Models (S := S) allTrue (cohTheory S).ax := by
+ rintro f ⟨q, _, p, _, rfl⟩ e
+ intro _ _ _ _
+ trivial
+
+theorem allFalse_models_coh (S : Rdf.Sig) :
+ folInst.Models (S := S) allFalse (cohTheory S).ax := by
+ rintro f ⟨q, _, p, _, rfl⟩ e
+ intro _ _ _ h
+ exact h.elim
+
+/-- The non-degenerate one: the antecedent `c q = c p` is true for every pair,
+so this model satisfies the axioms rather than dodging them. -/
+theorem eqStruc_models_coh (S : Rdf.Sig) :
+ folInst.Models (S := S) eqStruc (cohTheory S).ax := by
+ rintro f ⟨q, _, p, _, rfl⟩ e
+ intro _ _ _ h
+ exact h
+
+/-- A closed sentence that tells `eqStruc` apart from `allTrue`: not everything
+is related to everything, because `true ≠ false`. -/
+def everythingRelated : Fol.Form := .all 0 (.all 1 (.app2 "r" (.var 0) (.var 1)))
+
+theorem coh_theory_has_two_distinct_models :
+ folInst.sat (S := []) allTrue everythingRelated ∧
+ ¬ folInst.sat (S := []) eqStruc everythingRelated := by
+ refine ⟨fun _ _ _ => trivial, ?_⟩
+ intro h
+ exact Bool.noConfusion (h (fun _ => true) true false)
+
+theorem coh_theory_models_are_distinct : allTrue ≠ eqStruc := by
+ intro h
+ exact coh_theory_has_two_distinct_models.2 (h ▸ coh_theory_has_two_distinct_models.1)
+
+/-! ## 3. Preservation without reflection, measured
+
+`rdfs9` — from `x rdf:type A` and `A rdfs:subClassOf B` conclude `x rdf:type B` —
+is an entailment of the OWL 2 RL institution, by `sc_sub`. It is NOT an
+entailment of the simple RDF institution, because a simple interpretation is
+under no obligation to respect `rdfs:subClassOf` at all, and the Herbrand
+interpretation of the two premises is the countermodel.
+
+So `forgetConditions` preserves entailment and does not reflect it, and
+`Comorphism.reflects_entailment`'s hypothesis is not decoration. -/
+
+/-- The premise set, as a predicate. -/
+def Γ9 : Rdf.Sen sigT → Prop := fun ψ => ψ = senXA ∨ ψ = senAB
+
+theorem rdfs9_is_rl_entailed : Rdf.rl.Entails (forgetConditions.image Γ9) senXB := by
+ intro M hM
+ have h1 : M.1.sat senXA.1 := hM senXA ⟨senXA, Or.inl rfl, rfl⟩
+ have h2 : M.1.sat senAB.1 := hM senAB ⟨senAB, Or.inr rfl, rfl⟩
+ exact M.2.sc_sub (M.1.ι iA) (M.1.ι iB) h2 (M.1.ι iX) h1
+
+/-- The graph of the two premises, read as a Herbrand interpretation. -/
+def rdfs9Premises : List Triple := [⟨iX, V.type, iA⟩, ⟨iA, V.subClassOf, iB⟩]
+
+theorem simpleRdfs9_sat (φ : Rdf.Sen sigT) :
+ Rdf.simple.sat (S := sigT) (herbrand rdfs9Premises) φ ↔ φ.1 ∈ rdfs9Premises := Iff.rfl
+
+theorem rdfs9_is_not_simple_entailed : ¬ Rdf.simple.Entails Γ9 senXB := by
+ intro h
+ have hmod : Rdf.simple.Models (S := sigT) (herbrand rdfs9Premises) Γ9 := by
+ intro ψ hψ
+ rcases hψ with rfl | rfl
+ · exact List.Mem.head _
+ · exact List.Mem.tail _ (List.Mem.head _)
+ have hno : ¬ Rdf.simple.sat (S := sigT) (herbrand rdfs9Premises) senXB := by
+ rw [simpleRdfs9_sat]
+ decide
+ exact hno (h (herbrand rdfs9Premises) hmod)
+
+/-- **The two theorems of `Comorphism.lean` are different theorems**, and this
+is the pair that shows it: the target entails the translation, the source does
+not entail the original. -/
+theorem preservation_does_not_give_reflection :
+ Rdf.rl.Entails (forgetConditions.image Γ9) (forgetConditions.senMap senXB) ∧
+ ¬ Rdf.simple.Entails Γ9 senXB :=
+ ⟨rdfs9_is_rl_entailed, rdfs9_is_not_simple_entailed⟩
+
+/-- Consequently the comorphism is not model-expansive. Proved from the pair
+above through `Comorphism.reflects_entailment`, so the refutation is of the
+HYPOTHESIS and not merely of the conclusion. -/
+theorem forgetting_the_conditions_is_not_model_expansive :
+ ¬ forgetConditions.ModelExpansive := fun hexp =>
+ rdfs9_is_not_simple_entailed (forgetConditions.reflects_entailment hexp rdfs9_is_rl_entailed)
+
+/-! ## 4. The quarantined structure is inhabited
+
+`Institution.Functorial` carries the four laws that `Institution` deliberately
+does not. If nothing satisfied them, leaving them out would be hiding a defect
+rather than following the weakest-conditions discipline. `Rdf.simple` satisfies
+them, and every law is `rfl`: renaming by the identity is the identity on
+triples by structure eta, and the two composition laws are function composition
+read in the two directions a comorphism reads them. -/
+
+def simpleFunctorial : Institution.Functorial where
+ toInstitution := Rdf.simple
+ id := fun _ => { map := fun t => t, into := fun _ h => h }
+ comp := fun σ τ => { map := fun t => τ.map (σ.map t), into := fun t h => τ.into _ (σ.into t h) }
+ senMap_id := fun _ _ => rfl
+ senMap_comp := fun _ _ _ => rfl
+ modRed_id := fun _ _ => rfl
+ modRed_comp := fun _ _ _ => rfl
+
+/-! ## 5. `folInst.sat` is validity, and `Fol.Entails` is not
+
+`folInst.sat M f` is "`f` holds under EVERY assignment". `Fol.Entails Γ f`
+quantifies the assignment outside the implication. On closed formulas the two
+entailment relations agree; on open ones they do not, and the direction that
+fails is the one a reader would assume.
+
+`openP` institutionally entails its own universal closure, because a model
+satisfying `openP` at every assignment satisfies it at every element. It does not
+`Fol.Entails` it, because a single assignment can make `P(x₀)` true while `P`
+fails elsewhere. -/
+
+def closedP : Fol.Form := .all 0 openP
+
+theorem institution_entails_the_universal_closure :
+ folInst.EntailsL (S := []) [openP] closedP := by
+ intro M hM e d
+ exact hM openP (List.Mem.head _) (fun _ => d)
+
+/-- The two-element structure that separates the relations. -/
+def boolStruc : Fol.Struc where
+ Dom := Bool
+ nonempty := ⟨true⟩
+ p1 := fun _ b => b = true
+ p2 := fun _ _ _ => True
+ c := fun _ => true
+
+theorem fol_does_not_entail_the_universal_closure : ¬ Fol.Entails [openP] closedP := by
+ intro h
+ have hp : ∀ g ∈ [openP], Fol.Form.holds boolStruc (fun _ => true) g := by
+ intro g hg
+ rcases hg with _ | ⟨_, hg⟩
+ · exact rfl
+ · cases hg
+ exact Bool.noConfusion (h boolStruc (fun _ => true) hp false)
+
+/-! ## 6. The checker entails more than the institution does, and here is why
+
+`Rdf.rl_entails_gives_entails` runs one way: an entailment of the OWL 2 RL
+institution is an `OOCert.Entails`. The converse used to be recorded as "not
+proved and not claimed". It is now refuted.
+
+`OOCert.Model I G` carries four conditions — `int`, `int2`, `uni`, `oneOf` —
+stated over `Chain G`, the RDF list read off the ASSERTED GRAPH. A condition
+relative to a graph is not a condition on a signature and not a sentence, so
+there is nowhere in an institution to put it, and `Rdf.rl.Mod` does not carry it.
+`OOCert.Entails` therefore quantifies over strictly fewer interpretations and is
+the weaker relation.
+
+`cls-oo` is where the gap is visible. `Witness.lean` proves
+`an_enumerated_member_is_entailed`: the members of an `owl:oneOf` list are typed
+by the enumerated class, on schema alone. The Herbrand interpretation of those
+same premises satisfies every one of the twenty-three `Conditions` fields —
+vacuously, because the graph has no reserved predicate in it at all — and it does
+NOT type `a` as an `E`. So the same premises and the same conclusion come out
+`Entails` and not `Rdf.rl.EntailsL`.
+
+This is a real limit of the institution as defined and not a defect in it. Closing
+it means either making the list constructors sentences, which the RDF-Based
+Semantics does not do either (its sequences are read off `IEXT`, not off `G`), or
+carrying the graph in the signature, which is the theory construction and would
+put `Rdf.rl` at `Institution.Th`. Decision 0009 records it as open. -/
+
+/-- The Herbrand interpretation of `ooPremises`, which is `Witness.lean`'s
+`owl:oneOf` premise set. Every condition holds vacuously: the graph mentions
+`owl:oneOf`, `rdf:first` and `rdf:rest` and no term of `Rdf.Reserved`. -/
+theorem oo_premises_conditions : Conditions (herbrand ooPremises) where
+ sc_sub := fun a b hab => absurd hab (not_mem_pred ooPremises V.subClassOf (by decide) a b)
+ sc_trans := fun a b _ hab => absurd hab (not_mem_pred ooPremises V.subClassOf (by decide) a b)
+ sp_sub := fun a b hab => absurd hab (not_mem_pred ooPremises V.subPropertyOf (by decide) a b)
+ sp_trans := fun a b _ hab =>
+ absurd hab (not_mem_pred ooPremises V.subPropertyOf (by decide) a b)
+ dom := fun p c hpc => absurd hpc (not_mem_pred ooPremises V.domain (by decide) p c)
+ rng := fun p c hpc => absurd hpc (not_mem_pred ooPremises V.range (by decide) p c)
+ trp := fun p hp => absurd hp (not_typed ooPremises V.transitiveProperty (by decide) p)
+ symp := fun p hp => absurd hp (not_typed ooPremises V.symmetricProperty (by decide) p)
+ inv := fun p q hpq => absurd hpq (not_mem_pred ooPremises V.inverseOf (by decide) p q)
+ same := fun a b hab => absurd hab (not_mem_pred ooPremises V.sameAs (by decide) a b)
+ eqc := fun a b hab => absurd hab (not_mem_pred ooPremises V.equivalentClass (by decide) a b)
+ eqp := fun a b hab => absurd hab (not_mem_pred ooPremises V.equivalentProperty (by decide) a b)
+ svf := fun r p _ hop => absurd hop (not_mem_pred ooPremises V.onProperty (by decide) r p)
+ avf := fun r p _ hop => absurd hop (not_mem_pred ooPremises V.onProperty (by decide) r p)
+ hv := fun r p _ hop => absurd hop (not_mem_pred ooPremises V.onProperty (by decide) r p)
+ svf_sc := fun c1 _ _ y1 _ hsv =>
+ absurd hsv (not_mem_pred ooPremises V.someValuesFrom (by decide) c1 y1)
+ svf_sp := fun c1 _ _ _ y hsv =>
+ absurd hsv (not_mem_pred ooPremises V.someValuesFrom (by decide) c1 y)
+ avf_sc := fun c1 _ _ y1 _ hav =>
+ absurd hav (not_mem_pred ooPremises V.allValuesFrom (by decide) c1 y1)
+ avf_sp := fun c1 _ _ _ y hav =>
+ absurd hav (not_mem_pred ooPremises V.allValuesFrom (by decide) c1 y)
+ dom_sc := fun p c1 _ hd => absurd hd (not_mem_pred ooPremises V.domain (by decide) p c1)
+ dom_sp := fun _ p2 c hd => absurd hd (not_mem_pred ooPremises V.domain (by decide) p2 c)
+ rng_sc := fun p c1 _ hr => absurd hr (not_mem_pred ooPremises V.range (by decide) p c1)
+ rng_sp := fun _ p2 c hr => absurd hr (not_mem_pred ooPremises V.range (by decide) p2 c)
+
+/-- The predicates `ooPremises` and its `cls-oo` conclusion use. -/
+def sigOO : Rdf.Sig := [V.oneOf, V.first, V.rest, V.type]
+
+def ooSen : List (Rdf.Sen sigOO) :=
+ [ ⟨⟨tE, V.oneOf, oL0⟩, List.Mem.head _⟩,
+ ⟨⟨oL0, V.first, tA⟩, List.Mem.tail _ (List.Mem.head _)⟩,
+ ⟨⟨oL0, V.rest, oL1⟩, List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _))⟩,
+ ⟨⟨oL1, V.first, tB⟩, List.Mem.tail _ (List.Mem.head _)⟩,
+ ⟨⟨oL1, V.rest, V.nil⟩, List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _))⟩ ]
+
+def ooGoal : Rdf.Sen sigOO :=
+ ⟨⟨tA, V.type, tE⟩, List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _)))⟩
+
+/-- The model this refutation runs on. -/
+def rlOO : Rdf.rl.Mod sigOO := ⟨herbrand ooPremises, oo_premises_conditions⟩
+
+theorem rlOO_sat (φ : Rdf.Sen sigOO) : Rdf.rl.sat rlOO φ ↔ φ.1 ∈ ooPremises := Iff.rfl
+
+theorem ooSen_are_premises : ∀ ψ ∈ ooSen, ψ.1 ∈ ooPremises := by decide
+
+theorem the_enumeration_is_not_rl_entailed : ¬ Rdf.rl.EntailsL ooSen ooGoal := by
+ intro h
+ have hno : ¬ Rdf.rl.sat rlOO ooGoal := by
+ rw [rlOO_sat]
+ decide
+ exact hno (h rlOO (fun ψ hψ => ooSen_are_premises ψ hψ))
+
+/-- **The gap, measured.** The checker's relation holds of this premise set and
+this conclusion; the institution's does not. `cls-oo` is what separates them, and
+the four graph-relative conditions of `OOCert.Model` are why. -/
+theorem the_checker_entails_more_than_the_institution :
+ Entails ooPremises ooGoal.1 ∧ ¬ Rdf.rl.EntailsL ooSen ooGoal :=
+ ⟨an_enumerated_member_is_entailed, the_enumeration_is_not_rl_entailed⟩
+
+/-! ## The transfer, end to end on a concrete sentence
+
+A premise is entailed by itself in `Rdf.simple`, and the general preservation
+theorem turns that into a first-order statement about every model of the
+background theory. Small, and it is the whole pipeline: no step of it is written
+by hand. -/
+
+def ΓXA : Rdf.Sen sigT → Prop := fun ψ => ψ = senXA
+
+theorem the_translation_of_a_premise_is_first_order_entailed :
+ ∀ M : Fol.Struc, folInst.Models (S := sigT) M (cohTheory sigT).ax →
+ folInst.Models (S := sigT) M (rdfToFol.image ΓXA) →
+ folInst.sat (S := sigT) M (rdfToFol.senMap senXA) :=
+ rdfToFol.preserves_entailment_theoroidal (Institution.entails_of_mem Rdf.simple rfl)
+
+end InstitutionWitness
+
+/-! ## Axiom footprints
+
+Every top-level statement this layer adds, pinned. A `sorry` or a
+`native_decide` anywhere in the institution layer fails the build here. -/
+
+/-- info: 'OOCert.Rdf.conditions_reduct' does not depend on any axioms -/
+#guard_msgs in
+#print axioms Rdf.conditions_reduct
+
+/-- info: 'OOCert.Rdf.rl_entails_gives_entails' depends on axioms: [propext, Quot.sound] -/
+#guard_msgs in
+#print axioms Rdf.rl_entails_gives_entails
+
+/-- info: 'OOCert.Rdf.simple_entailment_is_rl_entailment' depends on axioms: [propext, Quot.sound] -/
+#guard_msgs in
+#print axioms Rdf.simple_entailment_is_rl_entailment
+
+/-- info: 'OOCert.FolInst.holds_red' does not depend on any axioms -/
+#guard_msgs in
+#print axioms FolInst.holds_red
+
+/-- info: 'OOCert.FolInst.fol_entails_gives_institution_entails' does not depend on any axioms -/
+#guard_msgs in
+#print axioms FolInst.fol_entails_gives_institution_entails
+
+/-- info: 'OOCert.FolInst.rdf_entailment_transfers_to_fol' does not depend on any axioms -/
+#guard_msgs in
+#print axioms FolInst.rdf_entailment_transfers_to_fol
+
+/-- info: 'OOCert.InstitutionWitness.rl_models_are_pairwise_distinct' depends on axioms: [propext, Quot.sound] -/
+#guard_msgs in
+#print axioms InstitutionWitness.rl_models_are_pairwise_distinct
+
+/-- info: 'OOCert.InstitutionWitness.fol_models_are_distinct' does not depend on any axioms -/
+#guard_msgs in
+#print axioms InstitutionWitness.fol_models_are_distinct
+
+/-- info: 'OOCert.InstitutionWitness.preservation_does_not_give_reflection' depends on axioms: [propext] -/
+#guard_msgs in
+#print axioms InstitutionWitness.preservation_does_not_give_reflection
+
+/--
+info: 'OOCert.InstitutionWitness.forgetting_the_conditions_is_not_model_expansive' depends on axioms: [propext]
+-/
+#guard_msgs in
+#print axioms InstitutionWitness.forgetting_the_conditions_is_not_model_expansive
+
+/-- info: 'OOCert.InstitutionWitness.the_checker_entails_more_than_the_institution' depends on axioms: [propext] -/
+#guard_msgs in
+#print axioms InstitutionWitness.the_checker_entails_more_than_the_institution
+
+/-- info: 'OOCert.InstitutionWitness.coh_theory_models_are_distinct' does not depend on any axioms -/
+#guard_msgs in
+#print axioms InstitutionWitness.coh_theory_models_are_distinct
+
+/-- info: 'OOCert.InstitutionWitness.fol_does_not_entail_the_universal_closure' does not depend on any axioms -/
+#guard_msgs in
+#print axioms InstitutionWitness.fol_does_not_entail_the_universal_closure
+
+/--
+info: 'OOCert.InstitutionWitness.the_translation_of_a_premise_is_first_order_entailed' does not depend on any axioms
+-/
+#guard_msgs in
+#print axioms InstitutionWitness.the_translation_of_a_premise_is_first_order_entailed
+
+end OOCert
diff --git a/lean/lakefile.toml b/lean/lakefile.toml
index c1f2fe5f..356ed2b1 100644
--- a/lean/lakefile.toml
+++ b/lean/lakefile.toml
@@ -1,6 +1,6 @@
name = "oocert"
version = "0.1.0"
-defaultTargets = ["OOCert", "oo-cert", "oo-horn", "Shacl", "oo-shacl", "oo-refute", "Dl", "oo-dlmodel", "Fol", "oo-folmodel"]
+defaultTargets = ["OOCert", "oo-cert", "oo-horn", "Shacl", "oo-shacl", "oo-refute", "Dl", "oo-dlmodel", "Fol", "oo-folmodel", "Institution"]
# Every library and executable here is in defaultTargets on purpose. A target
# left out of the default set is not built by a bare `lake build`, which is what
@@ -64,3 +64,13 @@ name = "Fol"
[[lean_exe]]
name = "oo-folmodel"
root = "FolMain"
+
+# The institution layer: what a logic is, what a translation between two logics
+# is, and the satisfaction condition that neither may be built without. A
+# separate library from `OOCert` because `Main.lean` imports `OOCert` and this
+# has no run-time part: it is theorems over the model classes the other
+# libraries already define, it pulls in `Fol`, and no executable reads it. In
+# defaultTargets, like everything else here, for the reason at the top of this
+# file.
+[[lean_lib]]
+name = "Institution"