Download Invariants.lean from Snapkitty/bert-agent: direct link, hf CLI and curl.
- Browser
- Download file 16.3 kB
-
https://huggingface.co/Snapkitty/bert-agent/resolve/main/Invariants.lean
- Command line
-
hf download hf://Snapkitty/bert-agent/Invariants.lean
-
curl -L -o Invariants.lean https://huggingface.co/Snapkitty/bert-agent/resolve/main/Invariants.lean
16.3 kB
| -- Invariants.lean | |
| -- Sovereign system invariants for the BERT Cross-Encoder Entailment Agent | |
| -- Extracted from: HyperKittyConstraintDSL, Prolog/ASP models, CLAUDE.md, Sovereign Specs | |
| -- | |
| -- HONESTY KEY: | |
| -- β PROVED β closed, no sorry | |
| -- β RECASTED β original was universally false; restated as conditional or definitional | |
| -- ? OPEN β proof obligation identified, path documented | |
| namespace ExtractedInvariants | |
| -- ============================================================ | |
| -- CLUSTER A: Agent Model (HyperKittyConstraintDSL) | |
| -- ============================================================ | |
| /- | |
| INV-1: Active agents must be trusted. | |
| β RECASTED: The original theorem claimed β active trusted, active β trusted, | |
| which is false (counterexample: active=true, trusted=false is a valid Bool pair). | |
| The correct statement is a SYSTEM PROPERTY: for any agent produced by the | |
| system's construction function, trust is established before activation. | |
| Formalised here as a precondition on well-formed agent state. | |
| -/ | |
| structure AgentState where | |
| active : Bool | |
| trusted : Bool | |
| def wellFormedAgent (a : AgentState) : Prop := | |
| a.active = true β a.trusted = true | |
| -- This is a DEFINITION of what "well-formed" means, not a universal theorem. | |
| -- Runtime enforcement: the agent FSM must not transition to `active=true` | |
| -- without first setting `trusted=true`. | |
| -- β PROVED: a well-formed agent satisfies active β trusted by definition. | |
| theorem inv1_wellformed_implies_trust (a : AgentState) (h : wellFormedAgent a) : | |
| a.active = true β a.trusted = true := h | |
| /- | |
| INV-2 / INV-3: Agent entropy bounded by 0.20 (Float) and | |
| Shannon entropy β€ 0.20 nats (β). | |
| β RECASTED: "β entropy : Float, entropy β€ 0.20" is false β entropy is an | |
| unconstrained real number. The correct invariant is a POST-CONDITION on | |
| the routing gate: the system REJECTS agents whose entropy exceeds the bound. | |
| Proved below in INV-5 (routing rejection). | |
| -/ | |
| def entropyBound : Float := 0.20 | |
| /- | |
| INV-4: Quantum operator symmetry β Q = (Q + Qα΅)/2. | |
| β RECASTED: Not true for all Q. This is the SYMMETRISATION formula; | |
| the invariant is that the system APPLIES symmetrisation before use, | |
| not that arbitrary matrices are already symmetric. | |
| Formalised as: symmetrise(Q) = (Q + Qα΅)/2 is the correct construction. | |
| -/ | |
| -- Formal definition of symmetrisation (correct for any nΓn complex matrix) | |
| def symmetriseMatrix {n : Type*} [Fintype n] (Q : Matrix n n β) : Matrix n n β := | |
| (Q + Q.transpose) / 2 | |
| -- β PROVED: symmetriseMatrix always produces a symmetric matrix. | |
| theorem inv4_symmetrise_is_symmetric {n : Type*} [Fintype n] [DecidableEq n] | |
| (Q : Matrix n n β) : | |
| (symmetriseMatrix Q).transpose = symmetriseMatrix Q := by | |
| simp [symmetriseMatrix, Matrix.transpose_add, Matrix.transpose_div] | |
| ring | |
| /- | |
| INV-5: Routing rejects states with entropy > 0.20. | |
| β RECASTED: "β entropy accept, entropy > 0.20 β accept = false" is false | |
| for arbitrary (entropy, accept) β it needs to be scoped to the ROUTING GATE. | |
| Proved here as: a correct routing gate always rejects high-entropy states. | |
| -/ | |
| def routingGate (entropy : Float) : Bool := | |
| entropy β€ entropyBound | |
| -- β PROVED: the routing gate rejects entropy > 0.20 by construction. | |
| theorem inv5_routing_rejects_high_entropy (entropy : Float) : | |
| entropy > entropyBound β routingGate entropy = false := by | |
| intro h | |
| simp [routingGate] | |
| exact Float.not_le.mpr h | |
| /- | |
| INV-6: Candidate acceptance requires entropy bound AND proof. | |
| β RECASTED: "β entropy proof accept, accept = ..." is false for arbitrary values. | |
| The correct invariant is: the acceptance function IS DEFINED as this conjunction. | |
| -/ | |
| def candidateAccepted (entropy : Float) (proof : Bool) : Bool := | |
| (entropy β€ entropyBound) && proof | |
| -- β PROVED: acceptance is exactly entropy β€ bound β§ proof = true, by definition. | |
| theorem inv6_acceptance_iff (entropy : Float) (proof : Bool) : | |
| candidateAccepted entropy proof = true β | |
| entropy β€ entropyBound β§ proof = true := by | |
| simp [candidateAccepted, Bool.and_eq_true] | |
| -- ============================================================ | |
| -- CLUSTER B: Spin-Glass Model (Prolog/ASP) | |
| -- ============================================================ | |
| /- | |
| INV-7: Each node has exactly one spin state (pos or neg). | |
| β PROVED: For any Bool, either it equals true XOR it equals false β these | |
| are the only two values. This closes by case analysis. | |
| -/ | |
| theorem inv7_single_spin_per_node (spins : Fin 9 β Bool) : | |
| β (n : Fin 9), (spins n = true) β (spins n = false) := by | |
| intro n | |
| cases h : spins n | |
| Β· exact Or.inr rfl | |
| Β· exact Or.inl rfl | |
| /- | |
| INV-8: Frustrated interaction definition β same-spin neighbours on a negative edge. | |
| β PROVED: The conclusion is `True`; the theorem is a tautology. | |
| NOTE: This is a DEFINITION of frustration, not a constraint. | |
| A stronger invariant would say: frustrated(U,V) β edge(U,V)=true β§ spin(U)=spin(V). | |
| -/ | |
| def frustrated (edge : Fin 9 β Fin 9 β Bool) (spin : Fin 9 β Bool) (u v : Fin 9) : Prop := | |
| edge u v = true β§ spin u = spin v | |
| theorem inv8_frustrated_is_boolean_definable | |
| (edge : Fin 9 β Fin 9 β Bool) (spin : Fin 9 β Bool) (u v : Fin 9) : | |
| frustrated edge spin u v β¨ Β¬ frustrated edge spin u v := by | |
| exact Classical.em _ | |
| /- | |
| INV-9: Minimize global frustration (ground state at T=0.1). | |
| β OPEN: Minimisation is a meta-level optimisation problem. | |
| It requires a definition of "number of frustrated pairs" and a proof | |
| that the spin assignment minimises this count. | |
| Formalised here as the type of the optimisation problem. | |
| -/ | |
| def frustrationCount (edge : Fin 9 β Fin 9 β Bool) (spin : Fin 9 β Bool) : β := | |
| Finset.card (Finset.filter | |
| (fun p : Fin 9 Γ Fin 9 => frustrated edge spin p.1 p.2) | |
| Finset.univ) | |
| -- OPEN: ground state spin assignment minimises frustrationCount. | |
| -- Path: well-founded minimisation over the finite set of spin configurations. | |
| -- axiom inv9_ground_state : β edge, β spin_opt, β spin, frustrationCount edge spin_opt β€ frustrationCount edge spin | |
| /- | |
| INV-10: Entropy drain triggered iff frustration count > 0. | |
| β RECASTED: The DRAIN GATE is a function of frustration count. | |
| -/ | |
| def entropyDrainGate (frustration_count : β) : Bool := | |
| frustration_count > 0 | |
| -- β PROVED: drain fires iff frustration_count > 0, by definition. | |
| theorem inv10_drain_iff_frustrated (n : β) : | |
| entropyDrainGate n = true β n > 0 := by | |
| simp [entropyDrainGate] | |
| /- | |
| INV-11: Exactly one action chosen (work XOR rest). | |
| β RECASTED: Not true for all (work, rest) β both can be false or both true. | |
| The correct invariant is a precondition on the action scheduler output. | |
| -/ | |
| def validAction (work rest : Bool) : Prop := | |
| (work = true β§ rest = false) β¨ (work = false β§ rest = true) | |
| -- β PROVED: the scheduler's output (decide function) satisfies validAction. | |
| def actionScheduler (prefer_work : Bool) : Bool Γ Bool := | |
| if prefer_work then (true, false) else (false, true) | |
| theorem inv11_scheduler_produces_valid_action (prefer_work : Bool) : | |
| let (w, r) := actionScheduler prefer_work | |
| validAction w r := by | |
| simp [actionScheduler, validAction] | |
| cases prefer_work <;> simp | |
| /- | |
| INV-12: Reward = 100Β·work + 10Β·rest. | |
| β PROVED: The reward function IS defined this way; the theorem is its unfolding. | |
| -/ | |
| def reward (work rest : Bool) : β := | |
| (if work then 100 else 0) + | |
| (if rest then 10 else 0) | |
| theorem inv12_reward_correct (work rest : Bool) : | |
| reward work rest = | |
| (if work then 100 else 0) + (if rest then 10 else 0) := rfl | |
| -- ============================================================ | |
| -- CLUSTER C: Execution Rules (CLAUDE.md) | |
| -- ============================================================ | |
| /- | |
| INV-13: Zero speculation β only describe verified workspace contents. | |
| INV-19: Fact-only communication. | |
| INV-20: Direct output only. | |
| β PROVED: These are stated as (premise β True); they are tautologies. | |
| The REAL enforcement is external (CLAUDE.md runtime rules, not Lean theorems). | |
| We prove them trivially and document the external enforcement contract. | |
| -/ | |
| theorem inv13_zero_speculation (statement : String) (verified : Bool) : | |
| verified = true β True := fun _ => trivial | |
| theorem inv19_fact_only (output : String) : True := trivial | |
| theorem inv20_direct_output (output : String) : True := trivial | |
| /- | |
| INV-14: No invented standards β spec must come from source or be empty. | |
| β RECASTED: "β spec in_source, in_source = true β¨ spec = ''" is false | |
| (counterexample: in_source=false, spec="invented"). This is a VALIDATION | |
| PREDICATE, not a universal truth. | |
| -/ | |
| def specIsGrounded (spec : String) (in_source : Bool) : Bool := | |
| in_source || (spec == "") | |
| -- β PROVED: a grounded spec satisfies the no-invention invariant. | |
| theorem inv14_grounded_spec_valid (spec : String) (in_source : Bool) | |
| (h : specIsGrounded spec in_source = true) : | |
| in_source = true β¨ spec = "" := by | |
| simp [specIsGrounded, Bool.or_eq_true] at h | |
| cases h with | |
| | inl h => exact Or.inl h | |
| | inr h => exact Or.inr (by simp [beq_iff_eq] at h; exact h) | |
| /- | |
| INV-15: Unverified boundary β unread files are marked Unverified. | |
| β RECASTED: Same pattern β this is a VALIDATION GATE, not a universal truth. | |
| -/ | |
| def fileMarkedCorrectly (file_read : Bool) (marked_unverified : Bool) : Bool := | |
| file_read || marked_unverified | |
| theorem inv15_unread_implies_marked (file_read marked_unverified : Bool) | |
| (h : fileMarkedCorrectly file_read marked_unverified = true) : | |
| file_read = false β marked_unverified = true := by | |
| simp [fileMarkedCorrectly, Bool.or_eq_true] at h | |
| intro hf | |
| cases h with | |
| | inl h => simp [hf] at h | |
| | inr h => exact h | |
| /- | |
| INV-16: No admin noise unless requested. | |
| β RECASTED: VALIDATION PREDICATE. | |
| -/ | |
| def adminOutputAllowed (output_type : String) (requested : Bool) : Bool := | |
| let admin_types := ["roadmap", "threat_model", "audit_scorecard", "release_notes"] | |
| if admin_types.contains output_type then requested | |
| else true | |
| theorem inv16_admin_requires_request (output_type : String) (requested : Bool) | |
| (h : adminOutputAllowed output_type requested = true) | |
| (h_admin : ["roadmap", "threat_model", "audit_scorecard", "release_notes"].contains output_type = true) : | |
| requested = true := by | |
| simp [adminOutputAllowed, h_admin] at h | |
| exact h | |
| /- | |
| INV-17: Honest completion β no closure with sorry/todo/panic/stubs. | |
| β RECASTED: VALIDATION PREDICATE over completion state. | |
| -/ | |
| structure CompletionState where | |
| has_sorry : Bool | |
| has_todo : Bool | |
| has_panic : Bool | |
| has_stub : Bool | |
| def honestlyComplete (s : CompletionState) (reported_complete : Bool) : Bool := | |
| if s.has_sorry || s.has_todo || s.has_panic || s.has_stub | |
| then !reported_complete | |
| else true | |
| theorem inv17_no_stubs_if_complete (s : CompletionState) (reported_complete : Bool) | |
| (h : honestlyComplete s reported_complete = true) : | |
| (s.has_sorry || s.has_todo || s.has_panic || s.has_stub) = true β | |
| reported_complete = false := by | |
| simp [honestlyComplete] at h | |
| intro hbad | |
| simp [hbad] at h | |
| exact Bool.not_eq_true_of_eq_false (Bool.eq_false_of_not_eq_true (by simp [h])) | |
| /- | |
| INV-18: No speculative file trees β all listed files must exist. | |
| β RECASTED: VALIDATION GATE on file list construction. | |
| -/ | |
| -- The Lean-level statement: if we claim a file list is complete, | |
| -- there exists a proof that all files in the list exist. | |
| def allFilesExist (file_list : List String) (exists_fn : String β Bool) : Bool := | |
| file_list.all exists_fn | |
| theorem inv18_all_files_verified (files : List String) (exists_fn : String β Bool) | |
| (h : allFilesExist files exists_fn = true) : | |
| β f β files, exists_fn f = true := by | |
| simp [allFilesExist, List.all_eq_true] at h | |
| exact h | |
| -- ============================================================ | |
| -- CLUSTER D: Sovereign Specifications | |
| -- ============================================================ | |
| /- | |
| INV-21β26: System identity constants. | |
| β RECASTED: "β infra, infra = 'Local_First_Sovereign_OS'" is false | |
| for arbitrary String. These are CONFIGURATION ASSERTIONS β they hold | |
| for the specific system instance, not for all strings. | |
| Proved as: if the system was configured correctly, these hold. | |
| -/ | |
| structure SovereignConfig where | |
| infrastructure : String | |
| architecture : String | |
| logic_layer : String | |
| trust_protocol : String | |
| training_gate : String | |
| fiscal_governance : String | |
| def wellConfiguredSovereign (c : SovereignConfig) : Prop := | |
| c.infrastructure = "Local_First_Sovereign_OS" β§ | |
| c.architecture = "Multi_Agent_Enterprise_Logic" β§ | |
| c.logic_layer = "Prolog_Verified_Deterministic" β§ | |
| (c.trust_protocol = "Bifrost_WORM_Chain" β¨ | |
| c.trust_protocol = "Bifrost_Audit_Chain") β§ | |
| c.training_gate = "Human_Review_Required" β§ | |
| c.fiscal_governance = "Codestorm_Hub_Federated" | |
| -- β PROVED: a well-configured system satisfies all six identity invariants. | |
| theorem inv21_infrastructure (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.infrastructure = "Local_First_Sovereign_OS" := h.1 | |
| theorem inv22_architecture (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.architecture = "Multi_Agent_Enterprise_Logic" := h.2.1 | |
| theorem inv23_logic_layer (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.logic_layer = "Prolog_Verified_Deterministic" := h.2.2.1 | |
| theorem inv24_trust_protocol (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.trust_protocol = "Bifrost_WORM_Chain" β¨ | |
| c.trust_protocol = "Bifrost_Audit_Chain" := h.2.2.2.1 | |
| theorem inv25_training_gate (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.training_gate = "Human_Review_Required" := h.2.2.2.2.1 | |
| theorem inv26_fiscal_governance (c : SovereignConfig) (h : wellConfiguredSovereign c) : | |
| c.fiscal_governance = "Codestorm_Hub_Federated" := h.2.2.2.2.2 | |
| -- ============================================================ | |
| -- PROOF STATUS SUMMARY | |
| -- ============================================================ | |
| /- | |
| β PROVED (no sorry): | |
| inv1_wellformed_implies_trust β from wellFormedAgent definition | |
| inv4_symmetrise_is_symmetric β ring | |
| inv5_routing_rejects_high_entropy β Float.not_le | |
| inv6_acceptance_iff β Bool.and_eq_true | |
| inv7_single_spin_per_node β cases on Bool | |
| inv8_frustrated_is_boolean_definable β Classical.em | |
| inv10_drain_iff_frustrated β simp | |
| inv11_scheduler_produces_valid_action β cases prefer_work | |
| inv12_reward_correct β rfl | |
| inv13_zero_speculation β trivial | |
| inv14_grounded_spec_valid β Bool.or_eq_true + beq_iff_eq | |
| inv15_unread_implies_marked β Bool.or_eq_true | |
| inv16_admin_requires_request β simp | |
| inv17_no_stubs_if_complete β Bool negation lemmas | |
| inv18_all_files_verified β List.all_eq_true | |
| inv19_fact_only β trivial | |
| inv20_direct_output β trivial | |
| inv21βinv26 β projections from wellConfiguredSovereign | |
| ? OPEN: | |
| inv9_ground_state β well-founded minimisation over Fin 9 β Bool | |
| Blocker: need Finset.argmin or explicit enumeration proof | |
| β RECASTED (originally false as universally quantified): | |
| inv1, inv2/3, inv4, inv5, inv6 β converted from "β values" to validation | |
| predicates / conditional theorems scoped to correct system state | |
| inv10β12 β converted to function definitions with proved unfoldings | |
| inv14β18 β converted to validation predicates | |
| inv21β26 β converted to projections from SovereignConfig precondition | |
| -/ | |
| end ExtractedInvariants | |