Theory Diagnostics_Nitpick

theory Diagnostics_Nitpick
  imports Axiom_Free_Ontological_Trinity


begin
(*
  ============================================================================
  Developer-only Diagnostics: consistency / nontriviality checks, model existence checks
  - used only for Nitpick model probes and audits.
  ============================================================================
*)
section ‹1. Diagnostics Overview›
text ‹This theory gathers lightweight diagnostics for the U-core and packages:
• Purity checks: ensure no backflow from optional bridges/locales into the D-route core.
• Sanity checks: Nitpick is expected to find no counterexample (i.e., @{text "expect = none"}).
• Suspicion checks: Nitpick is expected to find a genuine counterexample (i.e., flags over-strong statements).
• Model checks(Trinity model): Nitpick is expected to produce a genuine Trinity witness model, certifying non-vacuity and concrete realizability of the target configuration.
• Model checks(anti-modal collapse): Nitpick is expected to produce a genuine witness model showing that created truths are not forced into necessity, thereby confirming the absence of modal collapse.
›


section ‹2. Locale / Theorem Introspection (non-proof diagnostics)›
text ‹Quick check that locales are only interpreted where intended (no leakage).›
print_interps FullIdBridge
print_interps Riemann_Toy

text ‹Show hypotheses while printing key equivalences, then turn it back off.›
declare [[show_hyps]]
thm PH_imp_EH PH_imp_TH EH_TH_imp_PH PH_iff_EH_TH
thm EqU_iff_LeU_both
declare [[show_hyps = false]]


section ‹3. Nitpick setup (parameters and unfolds)›
text ‹Global defaults for Nitpick runs in this file (bump if needed).›
nitpick_params [verbose, card = 2-4, card U = 1-3, timeout = 60]

text ‹Unfold core definitions so Nitpick can see the structure.›
declare SuppU_def                 [nitpick_unfold]
declare LeU_def                   [nitpick_unfold]
declare EqU_def                   [nitpick_unfold]
declare Supports_def              [nitpick_unfold]
declare EDia_def                  [nitpick_unfold]
declare TrueNow_def               [nitpick_unfold]
declare EH_def                    [nitpick_unfold]
declare TH_def                    [nitpick_unfold]
declare PH_def                    [nitpick_unfold]
declare LtU_def                   [nitpick_unfold]
declare H_negU_strict_def         [nitpick_unfold]
declare H_opt_def                 [nitpick_unfold]
declare PDom_def                  [nitpick_unfold]
declare PSupp_def                 [nitpick_unfold]


section ‹4. Sanity checks (no counterexample expected)›

text ‹1) @{term PH} iff @{text "EH ∧ TH"}.›
lemma Nitpick_PH_iff_EH_TH:
  shows "PH q  (EH q  TH q)"
  nitpick [expect = none] oops

text ‹2) @{term Hopt3} implies @{term N3} (unboxed, D-route).›
lemma Nitpick_OnlyN3_from_Hopt3_unboxed:
  assumes "Hopt3 a b c"
  shows   N3
  nitpick [expect = none] oops

text ‹3) Global n=1 exclusion (core witness wrapper).›
lemma Nitpick_n1_global_exclusion_core:
  assumes "a a' b c.
            EDia b  EDia c 
            (Arg b)  (Arg a)  (Arg c)  (Arg a) 
            (¬ ((Arg b)  (Arg a'))  ¬ ((Arg c)  (Arg a'))) 
            EH (Arg a')"
  shows False
  nitpick [expect = none] oops

text ‹4) Global n=1 exclusion (H\_opt wrapper).›
lemma Nitpick_n1_global_exclusion_for_Hopt:
  assumes "Q b c a'.
            H_opt Q  EDia b  EDia c 
            (¬ ((Arg b)  (Arg a'))  ¬ ((Arg c)  (Arg a'))) 
            EH (Arg a')"
  shows False
  nitpick [expect = none] oops

text ‹5) H\_opt finality over @{term PDom}: no strict superior.›
lemma Nitpick_argument_finality_PDom:
  assumes "H_opt q"
  shows "ζPDom. ¬ ((Arg q)  (Arg ζ))"
  nitpick [expect = none] oops

text ‹6) Pair collapse at Arg-level from two @{term PH} + possibility.›
lemma Nitpick_PH_pair_collapse_to_EqU:
  assumes "PH (Arg Φ)" "PH (Arg Ω)" "EDia Φ" "EDia Ω"
  shows   "(Arg Φ)  (Arg Ω)"
  nitpick [expect = none] oops


section ‹5. Suspicion checks (Nitpick should find genuine counterexamples)›
text ‹Universal entailment / empty entailment are both false.›
lemma entails_universal_suspect: "ALL e u. e  u"
  nitpick [card U=3, timeout=15, expect = genuine] oops

lemma entails_empty_suspect: "~ (EX e u. e  u)"
  nitpick [card U=3, timeout=15, expect = genuine] oops


section ‹6. Strengthened / boundary diagnostics›

text ‹Strict variants: @{term EH_strict} does not imply @{term EH} in general (should be refutable).›
lemma EH_strict_converse_suspect: "ALL q. EH_strict q --> EH q"
  nitpick [card U=3, timeout=20, expect = genuine] oops

text ‹But @{term PH_strict} does imply @{term PH} (holds by definitions used here).›
lemma PH_strict_converse_check: "ALL q. PH_strict q --> PH q"
  nitpick [card U=3, timeout=20, expect = none] oops

text ‹One-way TSupp-maximality: the converse direction should hold under our setup.›
lemma TH_TSupp_max_converse_check:
  "ALL q. ((ALL x. TSupp x  TSupp q) --> TH q)"
  nitpick [card U=3, timeout=20, expect = none] oops

text ‹The following global tautologies should be refutable.›
lemma Hopt_tautology_suspect: "ALL q. H_opt q"
  nitpick [card U=3, timeout=20, expect = genuine] oops

lemma Comparable_PDom_on_tautology_suspect: "ALL q. Comparable_PDom_on q"
  nitpick [card U=3, timeout=20, expect = genuine] oops

lemma H_negU_strict_tautology_suspect: "ALL q. H_negU_strict q"
  nitpick [card U=3, timeout=20, expect = genuine] oops


section ‹7. No modal collapse (Nitpick model test)›
text ‹
  We established that the Trinity implies the possibility of R (@{text "◇"}R).
  The critical question is whether the Trinity necessitates R (Modal Collapse).
  If Nitpick finds a counter-model for the lemma below, we confirm that
  Trinity and @{text "¬"}R can co-exist without contradiction, proving that collapse is resolved.
›

lemma Trinity_does_not_necessitate_R:
  fixes Φ Ω ψ R :: bool
  assumes T_Pattern: "Trinity Φ Ω ψ   R"    (* Trinity enables R *)
  assumes S_Pattern: "¬ (Trinity Φ Ω ψ)  ¬ R" (* No Trinity, No R *)
  shows "Trinity Φ Ω ψ  R"
  nitpick [expect = genuine, show_all, satisfy]
  oops

text ‹
  (1) Anti-degeneracy: @{text "◇"} is not trivially True for every proposition.
›
lemma Diamond_is_not_degenerate:
  shows "¬ (P::bool.  P)"
  nitpick [expect = genuine, show_all, satisfy]
  oops

text ‹
  (2) Non-triviality guard: @{text "◇"}False is not forced (not a theorem).
  We test both directions as independence smoke-tests.
›
lemma Dia_False_is_not_a_theorem:
  shows " False"
  nitpick [expect = genuine, show_all, satisfy]
  oops

lemma Not_Dia_False_is_not_a_theorem:
  shows "¬ ( False)"
  nitpick [expect = genuine, show_all, satisfy]
  oops


section ‹8. Computational Diagnostics and Trinity Model Existence (Nitpick test)›
text ‹
  APPENDIX: The following diagnostic block uses Nitpick to explore the model-theoretic
  properties of the theory.

  Note on ``oops'': The usage of ``oops'' here does not indicate a proof failure.
  Rather, it marks a diagnostic check where Nitpick attempts to find counter-examples.
  The absence of counter-examples in these finite scopes supports the consistency
  of the Triune Necessity (N=3) as the unique logical equilibrium of the system.
›

typedef U3 = "{0::nat, 1, 2}" by auto
setup_lifting type_definition_U3

definition HeadP_U3 :: "U3  bool" where
  "HeadP_U3 _  True"

definition NT_pair_supportU3 :: "U3  U3  U3  bool" where
  "NT_pair_supportU3 A B C  (A  B  A  C  B  C)"

definition TrinityModel :: bool where
  "TrinityModel  (A B C :: U3.
      HeadP_U3 A  HeadP_U3 B  HeadP_U3 C 
      A  B  A  C  B  C 
      NT_pair_supportU3 A B C 
      NT_pair_supportU3 B C A 
      NT_pair_supportU3 C A B)"

lemma "TrinityModel"
  nitpick [satisfy, card U3 = 3, expect = genuine]
  oops


subsection ‹8.1 Trinity Model existence Nitpick Test - MaxNT›

datatype U10 = u0 | u1 | u2 | u3 | u4 | u5 | u6 | u7 | u8 | u9

consts HeadP_U10 :: "U10  bool"

definition NT_pair_supportU10 :: "U10  U10  U10  bool" where
  NT_pair_supportU10 A B C  (A  B  A  C  B  C)

definition TrinityModel_U10 :: bool where
  TrinityModel_U10 
    (A B C :: U10.
      HeadP_U10 A  HeadP_U10 B  HeadP_U10 C 
      NT_pair_supportU10 A B C 
      NT_pair_supportU10 B C A 
      NT_pair_supportU10 C A B)

definition Head_1_U10 :: bool where
  Head_1_U10 
    (a::U10. HeadP_U10 a  (x::U10. HeadP_U10 x  x = a))

definition Head_2_U10 :: bool where
  Head_2_U10 
    (a b::U10.
      a  b  HeadP_U10 a  HeadP_U10 b 
      (x::U10. HeadP_U10 x  (x = a  x = b)))

definition Head_3_U10 :: bool where
  Head_3_U10 
    (a b c::U10.
      a  b  a  c  b  c 
      HeadP_U10 a  HeadP_U10 b  HeadP_U10 c 
      (x::U10. HeadP_U10 x  (x = a  x = b  x = c)))

definition Head_4_U10 :: bool where
  Head_4_U10 
    (a b c d::U10.
      a  b  a  c  a  d 
      b  c  b  d  c  d 
      HeadP_U10 a  HeadP_U10 b  HeadP_U10 c  HeadP_U10 d 
      (x::U10. HeadP_U10 x 
        (x = a  x = b  x = c  x = d)))

lemma Trinity_excludes_1:
  ¬ (TrinityModel_U10  Head_1_U10)
  unfolding TrinityModel_U10_def Head_1_U10_def NT_pair_supportU10_def
  by metis

lemma Trinity_excludes_2:
  ¬ (TrinityModel_U10  Head_2_U10)
  unfolding TrinityModel_U10_def Head_2_U10_def NT_pair_supportU10_def
  by metis

lemma Trinity_Minimal_3_over_2:
  assumes TrinityModel_U10  Head_3_U10
  shows   ¬ (TrinityModel_U10  Head_2_U10)
  using Trinity_excludes_2 by blast

lemma TrinityModel_U10  Head_1_U10
  unfolding TrinityModel_U10_def Head_1_U10_def NT_pair_supportU10_def
  nitpick [satisfy, card U10 = 10, expect = none, show_all]
  oops

lemma TrinityModel_U10  Head_2_U10
  unfolding TrinityModel_U10_def Head_2_U10_def NT_pair_supportU10_def
  nitpick [satisfy, card U10 = 10, expect = none, show_all]
  oops

text‹
The failure of N=1 and N=2 models to satisfy the EdgeExist condition validates that the support relation (NT\_pair\_support) is strictly non-trivial.
›
lemma TrinityModel_U10  Head_3_U10
  unfolding TrinityModel_U10_def Head_3_U10_def NT_pair_supportU10_def
  nitpick [satisfy, card U10 = 10, expect = genuine, show_all]
  oops


subsection ‹8.2 Numerical Diagnostics for Trinity Necessity with number of distinct MaxCov entities›
text ‹
  This suite evaluates the structural stability of the H-opt framework.
  It systematically tests different values of N (number of distinct MaxCov entities)
  to identify the unique logical fixed point of the system.
›

lemma nitpick_1_MaxCov_insufficient_UNSAT:
  assumes M1: "MaxCov A"
  shows "False"
  nitpick [satisfy, expect = none]
oops

lemma nitpick_2_MaxCov_pairwise_nonapprox_UNSAT:
  assumes MA: "MaxCov A" and MB: "MaxCov B"
      and AB: "A  B"
  shows "False"
  nitpick [satisfy, expect = none]
oops

text ‹The Unique Fixed Point: N = 3 (The Trinity)›
lemma nitpick_3_MaxCov_Trinity_GENUINE:
  assumes MA: "MaxCov A" and MB: "MaxCov B" and MC: "MaxCov C"
      and AB: "A  B" and AC: "A  C" and BC: "B  C"
  shows "GodExists_U"
  nitpick [satisfy, expect = genuine]
  oops

lemma nitpick_4_MaxCov_pairwise_nonapprox_UNSAT:
  assumes MA: "MaxCov A" and MB: "MaxCov B" and MC: "MaxCov C" and MD: "MaxCov D"
      and AB: "¬(A  B)" and AC: "¬(A  C)" and AD: "¬(A  D)"
      and BC: "¬(B  C)" and BD: "¬(B  D)" and CD: "¬(C  D)"
  shows False
  nitpick [satisfy, expect = none, show_all]
  nitpick [satisfy, expect = none, show_all, timeout = 60]
oops
text ‹
Computational diagnostic (Nitpick).
We asked Nitpick for a model containing four MaxCov points that are pairwise non-@{text "≈"}.
No model is found (expect = none), even with an increased timeout.
This indicates that, within Nitpick's finite scopes, the current MaxCov/Cov/@{text "≈"} definitions
already exert a strong structural constraint against N @{text "≥"} 4 distinct maxima.
(This is evidence, not a theorem.)
›


section ‹9. Non-vacuous Genuine Trinity model Nitpick test›
(* ========================= *)
(* Non-vacuous Trinity (P-level) *)
(* ========================= *)
definition NT_edgeP :: "P  P  P  bool" where
  NT_edgeP A B C 
      (ArgP (A  B)  ArgP C) 
      ¬ (ArgP (A  B)  ArgP A) 
      ¬ (ArgP (A  B)  ArgP B)

definition TriSupport_JointP :: "P  P  P  bool" where
  TriSupport_JointP a b c 
      (ArgP (b  c)  ArgP a) 
      (ArgP (c  a)  ArgP b) 
      (ArgP (a  b)  ArgP c) 
      ¬ (ArgP a  ArgP b)  ¬ (ArgP b  ArgP a) 
      ¬ (ArgP b  ArgP c)  ¬ (ArgP c  ArgP b) 
      ¬ (ArgP c  ArgP a)  ¬ (ArgP a  ArgP c)

definition Trinity_nonvacuousP :: bool where
  Trinity_nonvacuousP 
      (a b c.
          H_optP a  H_optP b  H_optP c 
          TriSupport_JointP a b c 
          NT_edgeP a b c  NT_edgeP b c a  NT_edgeP c a b)

lemma Trinity_nonvacuousP_satisfiable:
  shows Trinity_nonvacuousP
  nitpick [satisfy, card P = 3, card U = 3, timeout = 60, show_all, expect = genuine]
  oops
text ‹
\paragraph{Finite-model witness (Nitpick).}
Nitpick finds a genuine model of @{term Trinity_nonvacuousP} in the finite scope
$\mathrm{card}(P)=3$ and $\mathrm{card}(U)=3$.

In the returned witness (up to renaming of elements), the Skolem triple is
@{text "‹a = P1›"}, @{text "‹b = P2›"}, @{text "‹c = P3›"},
and the conjunction-like operator @{text "‹⊓›"} satisfies the cycle
@{text "‹P1 ⊓ P2 = P3›"},
@{text "‹P2 ⊓ P3 = P1›"},
@{text "‹P3 ⊓ P1 = P2›"}.

This confirms that the non-vacuous triune package
(\texttt{TriSupport\_JointP} plus three \texttt{NT\_edgeP} constraints, together with \texttt{H\_optP})
is jointly satisfiable.›


lemma Trinity_nonvacuousP_not_valid_sanity:
  shows "¬ Trinity_nonvacuousP"
  nitpick [satisfy, card P = 3, card U = 3, timeout = 60, expect = genuine]
  oops
text ‹Nitpick status of @{term Trinity_nonvacuousP}.›

We use Nitpick here only as a finite-scope sanity check.

 ‹Satisfiable (SAT).›
Nitpick finds a genuine model of @{term Trinity_nonvacuousP} with card P = 3 and card U = 3.
Hence the non-vacuous triune package is consistent with the current definitional framework
(i.e., it is not definitionally empty or contradictory).

 ‹Not valid (not a tautology).›
Nitpick also finds a genuine model of @{term "¬ Trinity_nonvacuousP"} in the same scope.
Hence @{term Trinity_nonvacuousP} is not forced by the definitions alone.

‹Interpretation.›
Together, these witnesses show that @{term Trinity_nonvacuousP} is contentful:
it is compatible with the framework, yet not logically trivial in the tested scope.
These results are evidence for the chosen finite scope, not a meta-theorem about all models.
›


end