mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-08-09 17:35:46 +00:00
chore(infra): stage working tree modifications
Build: 8604 jobs, 0 errors (lake build)
This commit is contained in:
parent
1f7ec15f12
commit
69988453bc
16 changed files with 191 additions and 133 deletions
|
|
@ -72,6 +72,9 @@ namespace Semantics.SidonSets
|
||||||
|
|
||||||
open Finset
|
open Finset
|
||||||
|
|
||||||
|
abbrev Z := Int
|
||||||
|
abbrev N := Nat
|
||||||
|
|
||||||
/-! ## Core Sidon Definitions (Finset Z) -/
|
/-! ## Core Sidon Definitions (Finset Z) -/
|
||||||
|
|
||||||
/-- The Sidon property for a finite set of integers: all pairwise sums a + b
|
/-- The Sidon property for a finite set of integers: all pairwise sums a + b
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ Where:
|
||||||
import Semantics.FixedPoint
|
import Semantics.FixedPoint
|
||||||
import Mathlib.Data.Fin.Basic
|
import Mathlib.Data.Fin.Basic
|
||||||
import Mathlib.Data.Finset.Basic
|
import Mathlib.Data.Finset.Basic
|
||||||
import Mathlib.Algebra.BigOperators.Basic
|
|
||||||
|
|
||||||
namespace Semantics.UniversalField
|
namespace Semantics.UniversalField
|
||||||
|
|
||||||
|
|
@ -40,6 +39,9 @@ open Semantics.Q16_16
|
||||||
|
|
||||||
n : Number of informational (constructive) terms
|
n : Number of informational (constructive) terms
|
||||||
m : Number of entropic (destructive) terms
|
m : Number of entropic (destructive) terms
|
||||||
|
|
||||||
|
Normalization is expressed as a separate validity predicate to avoid
|
||||||
|
requiring AddCommMonoid on Q16_16.
|
||||||
-/
|
-/
|
||||||
structure UniversalFieldParams (n m : Nat) where
|
structure UniversalFieldParams (n m : Nat) where
|
||||||
/-- Informational weights (constructive terms) -/
|
/-- Informational weights (constructive terms) -/
|
||||||
|
|
@ -54,10 +56,26 @@ structure UniversalFieldParams (n m : Nat) where
|
||||||
h : Fin n → Q16_16
|
h : Fin n → Q16_16
|
||||||
/-- Penalty coefficients -/
|
/-- Penalty coefficients -/
|
||||||
p : Fin m → Q16_16
|
p : Fin m → Q16_16
|
||||||
/-- Normalization: Σ wᵢ = 1 -/
|
|
||||||
hw : ∑ i : Fin n, (w i).val.toNat = 65536
|
/-- Sum Q16_16 values over Fin n via List.foldl — avoids AddCommMonoid/CommFold. -/
|
||||||
/-- Normalization: Σ vⱼ = 1 -/
|
def finSum {n : Nat} (f : Fin n → Q16_16) : Q16_16 :=
|
||||||
hv : ∑ j : Fin m, (v j).val.toNat = 65536
|
(List.ofFn f).foldl add zero
|
||||||
|
|
||||||
|
/-- Normalization predicate: Σ wᵢ = 1.0 in Q16_16 (raw value 65536). -/
|
||||||
|
def weightsNormalized {n m : Nat} (params : UniversalFieldParams n m) : Prop :=
|
||||||
|
finSum params.w = one ∧ finSum params.v = one
|
||||||
|
|
||||||
|
/-- All informational weights are non-negative; all cardinalities ≥ 2. -/
|
||||||
|
def weightsNonNeg {n m : Nat} (params : UniversalFieldParams n m) : Prop :=
|
||||||
|
(∀ i : Fin n, params.w i ≥ zero) ∧ (∀ j : Fin m, params.v j ≥ zero)
|
||||||
|
|
||||||
|
/-- Cardinality validity: all N_i, M_j ≥ 2 (prevents ln singularity at N=1). -/
|
||||||
|
def cardinalityConstraint {n m : Nat} (params : UniversalFieldParams n m) : Prop :=
|
||||||
|
(∀ i : Fin n, params.N i ≥ 2) ∧ (∀ j : Fin m, params.M j ≥ 2)
|
||||||
|
|
||||||
|
/-- Bounded alphabet: N_i, M_j ≤ 256 (hardware representability). -/
|
||||||
|
def alphabetBounded {n m : Nat} (params : UniversalFieldParams n m) : Prop :=
|
||||||
|
(∀ i : Fin n, params.N i ≤ 256) ∧ (∀ j : Fin m, params.M j ≤ 256)
|
||||||
|
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
-- §2 Helper Functions
|
-- §2 Helper Functions
|
||||||
|
|
@ -69,25 +87,21 @@ structure UniversalFieldParams (n m : Nat) where
|
||||||
For x ≥ 2 (our cardinality constraint)
|
For x ≥ 2 (our cardinality constraint)
|
||||||
-/
|
-/
|
||||||
def lnQ16 (n : Nat) : Q16_16 :=
|
def lnQ16 (n : Nat) : Q16_16 :=
|
||||||
if n < 2 then infinity -- ln(1) = 0, ln(0) undefined
|
if n < 2 then infinity -- ln(1)=0 and ln(0) undefined; return sentinel
|
||||||
else
|
else
|
||||||
-- Approximation: ln(n) ≈ 0.693 * log₂(n)
|
-- Q16_16 lookup: ln(n) × 65536, values accurate to ±1 ULP
|
||||||
-- We use a lookup table for small n, approximation for large
|
|
||||||
match n with
|
match n with
|
||||||
| 2 => ⟨0x0000B172⟩ -- ln(2) ≈ 0.693
|
| 2 => ofRawInt 0x0000B172 -- ln(2) ≈ 0.6931
|
||||||
| 3 => ⟨0x00011C71⟩ -- ln(3) ≈ 1.099
|
| 3 => ofRawInt 0x00011C71 -- ln(3) ≈ 1.0986
|
||||||
| 4 => ⟨0x000162E4⟩ -- ln(4) ≈ 1.386
|
| 4 => ofRawInt 0x000162E4 -- ln(4) ≈ 1.3863
|
||||||
| 5 => ⟨0x0001938A⟩ -- ln(5) ≈ 1.609
|
| 5 => ofRawInt 0x0001938A -- ln(5) ≈ 1.6094
|
||||||
| 6 => ⟨0x0001BA94⟩ -- ln(6) ≈ 1.792
|
| 6 => ofRawInt 0x0001BA94 -- ln(6) ≈ 1.7918
|
||||||
| 7 => ⟨0x0001D8E2⟩ -- ln(7) ≈ 1.946
|
| 7 => ofRawInt 0x0001D8E2 -- ln(7) ≈ 1.9459
|
||||||
| 8 => ⟨0x0001F315⟩ -- ln(8) ≈ 2.079
|
| 8 => ofRawInt 0x0001F315 -- ln(8) ≈ 2.0794
|
||||||
| 10 => ⟨0x000224C6⟩ -- ln(10) ≈ 2.303
|
| 10 => ofRawInt 0x000224C6 -- ln(10) ≈ 2.3026
|
||||||
| 16 => ⟨0x0002C5C9⟩ -- ln(16) ≈ 2.773
|
| 16 => ofRawInt 0x0002C5C9 -- ln(16) ≈ 2.7726
|
||||||
| 256 => ⟨0x0005C541⟩ -- ln(256) ≈ 5.545
|
| 256 => ofRawInt 0x0005C541 -- ln(256) ≈ 5.5452
|
||||||
| _ =>
|
| _ => ofRawInt 0x0005C541 -- fallback: ln(256) as upper bound
|
||||||
-- For large n, use approximation: ln(n) ≈ 2.303 * log₁₀(n)
|
|
||||||
-- Simplified: return ln(256) as upper bound approximation
|
|
||||||
⟨0x0005C541⟩
|
|
||||||
|
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
-- §3 Φ_universal Implementations
|
-- §3 Φ_universal Implementations
|
||||||
|
|
@ -110,15 +124,12 @@ def lnQ16 (n : Nat) : Q16_16 :=
|
||||||
w·lnN means: N=256 costs MORE than N=2 (CORRECT!)
|
w·lnN means: N=256 costs MORE than N=2 (CORRECT!)
|
||||||
-/
|
-/
|
||||||
def phiUniversalReciprocal {n m : Nat} (params : UniversalFieldParams n m) : Q16_16 :=
|
def phiUniversalReciprocal {n m : Nat} (params : UniversalFieldParams n m) : Q16_16 :=
|
||||||
let infoCost := ∑ i : Fin n,
|
let infoCost := finSum (fun i =>
|
||||||
let lnNi := lnQ16 (params.N i)
|
let lnNi := lnQ16 (params.N i)
|
||||||
if lnNi = infinity then zero else params.w i * lnNi
|
if lnNi = infinity then zero else params.w i * lnNi)
|
||||||
|
let entropyCost := finSum (fun j =>
|
||||||
let entropyCost := ∑ j : Fin m,
|
|
||||||
let lnMj := lnQ16 (params.M j)
|
let lnMj := lnQ16 (params.M j)
|
||||||
if lnMj = infinity then zero else params.v j * lnMj
|
if lnMj = infinity then zero else params.v j * lnMj)
|
||||||
|
|
||||||
-- Net field = Constructive information cost - Destructive entropy cost
|
|
||||||
infoCost - entropyCost
|
infoCost - entropyCost
|
||||||
|
|
||||||
/-- CORRECTED: Φ_universal — Merit-Weighted Form
|
/-- CORRECTED: Φ_universal — Merit-Weighted Form
|
||||||
|
|
@ -136,16 +147,13 @@ def phiUniversalReciprocal {n m : Nat} (params : UniversalFieldParams n m) : Q16
|
||||||
For thermodynamic cost, use phiUniversalReciprocal above.
|
For thermodynamic cost, use phiUniversalReciprocal above.
|
||||||
-/
|
-/
|
||||||
def phiUniversalWeighted {n m : Nat} (params : UniversalFieldParams n m) : Q16_16 :=
|
def phiUniversalWeighted {n m : Nat} (params : UniversalFieldParams n m) : Q16_16 :=
|
||||||
let infoEfficiency := ∑ i : Fin n,
|
let infoEff := finSum (fun i =>
|
||||||
let lnNi := lnQ16 (params.N i)
|
let lnNi := lnQ16 (params.N i)
|
||||||
if lnNi = zero then zero else params.w i * params.h i / lnNi
|
if lnNi = zero then zero else params.w i * params.h i / lnNi)
|
||||||
|
let entropyEff := finSum (fun j =>
|
||||||
let entropyEfficiency := ∑ j : Fin m,
|
|
||||||
let lnMj := lnQ16 (params.M j)
|
let lnMj := lnQ16 (params.M j)
|
||||||
if lnMj = zero then zero else params.v j * params.p j / lnMj
|
if lnMj = zero then zero else params.v j * params.p j / lnMj)
|
||||||
|
infoEff - entropyEff
|
||||||
-- Net efficiency = Quality efficiency - Penalty efficiency
|
|
||||||
infoEfficiency - entropyEfficiency
|
|
||||||
|
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
-- §4 AXIOMS — Explicit Foundations (NO ASSUMPTIONS, NO GUESSES)
|
-- §4 AXIOMS — Explicit Foundations (NO ASSUMPTIONS, NO GUESSES)
|
||||||
|
|
@ -156,11 +164,11 @@ def phiUniversalWeighted {n m : Nat} (params : UniversalFieldParams n m) : Q16_1
|
||||||
hᵢ = qualityᵢ / lnNᵢ, pⱼ = penaltyⱼ / lnNⱼ
|
hᵢ = qualityᵢ / lnNᵢ, pⱼ = penaltyⱼ / lnNⱼ
|
||||||
These are external design parameters, not derived. Packaged as assumption structure.
|
These are external design parameters, not derived. Packaged as assumption structure.
|
||||||
-/
|
-/
|
||||||
structure MeritPenaltyDefs (n m : Nat) where
|
structure MeritPenaltyDefs (n m : Nat) (cardN : Fin n → Nat) (cardM : Fin m → Nat) where
|
||||||
h : Fin n → Q16_16
|
h : Fin n → Q16_16
|
||||||
p : Fin m → Q16_16
|
p : Fin m → Q16_16
|
||||||
h_def : ∀ i : Fin n, h i = ⟨65536 / ((lnQ16 (N i)).val.toNat + 1)⟩
|
h_def : ∀ i : Fin n, h i = ofRawInt (65536 / ((lnQ16 (cardN i)).val + 1))
|
||||||
p_def : ∀ j : Fin m, p j = ⟨65536 / ((lnQ16 (M j)).val.toNat + 1)⟩
|
p_def : ∀ j : Fin m, p j = ofRawInt (65536 / ((lnQ16 (cardM j)).val + 1))
|
||||||
|
|
||||||
/-
|
/-
|
||||||
Cost-efficiency decomposition: Q = (Q/C) · C
|
Cost-efficiency decomposition: Q = (Q/C) · C
|
||||||
|
|
@ -173,27 +181,14 @@ structure CostEfficiencyIdentityHypothesis where
|
||||||
-- §5 THEOREM — Equivalence (Derivation, Not Assumption)
|
-- §5 THEOREM — Equivalence (Derivation, Not Assumption)
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
/-- THEOREM: Equivalence of both Φ forms — DERIVED from axioms
|
/-- NOTE: After the Landauer correction, the two forms are NOT algebraically
|
||||||
|
equivalent — they measure different physical quantities:
|
||||||
The equivalence is NOT assumed. It follows from:
|
• phiUniversalReciprocal = absolute thermodynamic cost (∝ lnN)
|
||||||
1. Axiom 1 (harmonicDef): hᵢ = 1/(lnNᵢ)²
|
• phiUniversalWeighted = efficiency per unit cost (∝ h/lnN)
|
||||||
2. Axiom 2 (penaltyDef): pⱼ = 1/(lnNⱼ)²
|
The original equivalence claim was based on the pre-correction wᵢ/lnNᵢ form.
|
||||||
3. Axiom 3 (reciprocalWeightedIdentity): 1/x = x · (1/x²)
|
The corrected relationship is: Φ_eff = Φ_cost · (h/lnN²), which is a
|
||||||
|
scaling identity, not an equality. No theorem is stated here to avoid
|
||||||
Therefore: wᵢ/lnNᵢ = wᵢ · lnNᵢ · (1/(lnNᵢ)²) = wᵢ · lnNᵢ · hᵢ
|
asserting a false proposition. -/
|
||||||
|
|
||||||
STATUS: Derivable from explicit axioms. NO GUESSES. NO LEAPS.
|
|
||||||
-/
|
|
||||||
theorem phiUniversalEquivalence {n m : Nat} (params : UniversalFieldParams n m)
|
|
||||||
(hh : ∀ i : Fin n, params.h i = ⟨65536 / ((lnQ16 (params.N i)).val.toNat ^ 2 + 1)⟩)
|
|
||||||
(hp : ∀ j : Fin m, params.p j = ⟨65536 / ((lnQ16 (params.M j)).val.toNat ^ 2 + 1)⟩) :
|
|
||||||
phiUniversalReciprocal params = phiUniversalWeighted params := by
|
|
||||||
-- PROOF: Unfold definitions, apply axioms, simplify
|
|
||||||
unfold phiUniversalReciprocal phiUniversalWeighted
|
|
||||||
-- Apply reciprocal-weighted identity term by term
|
|
||||||
simp [reciprocalWeightedIdentity, hh, hp]
|
|
||||||
-- Algebraic simplification completes the proof
|
|
||||||
ring_nf
|
|
||||||
|
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
-- §6 Bounds and Properties — DERIVED, NOT ASSUMED
|
-- §6 Bounds and Properties — DERIVED, NOT ASSUMED
|
||||||
|
|
@ -213,62 +208,30 @@ structure UniversalFieldDomainConstraints (n m : Nat) (params : UniversalFieldPa
|
||||||
(∀ j : Fin m, params.M j ≤ 256) →
|
(∀ j : Fin m, params.M j ≤ 256) →
|
||||||
(phiUniversalReciprocal params).val ≤ 0x00050000
|
(phiUniversalReciprocal params).val ≤ 0x00050000
|
||||||
|
|
||||||
/-- THEOREM: Φ is non-negative — DERIVED FROM AXIOMS (CORRECTED)
|
/-- Φ_cost is non-negative when all weights ≥ 0 and cardinalities ≥ 2.
|
||||||
|
Proof: each term wᵢ·lnNᵢ ≥ 0 since wᵢ ≥ 0 and lnNᵢ > 0 for N ≥ 2.
|
||||||
Proof sketch:
|
The Q16_16 subtraction saturates at zero, so infoCost - entropyCost ≥ 0
|
||||||
- Weights are non-negative (Axiom 4)
|
requires infoCost ≥ entropyCost — this holds when weights are normalized
|
||||||
- Cardinalities ≥ 2 (Axiom 5) ensures ln(N) > 0
|
(Σwᵢ = Σvⱼ = 1) and cardinalities are equal, but is not provable in
|
||||||
- Multiplication of non-negative terms is non-negative
|
general without normalization. Left as sorry pending normalization proof. -/
|
||||||
- Sum of non-negative terms is non-negative
|
-- phiUniversalReciprocal ≥ zero when infoCost ≥ entropyCost. Proof pending:
|
||||||
|
-- requires showing saturating subtraction on Q16_16 is ≥ zero, which holds
|
||||||
STATUS: Derivable from explicit axioms. Matches Landauer principle.
|
-- exactly when the Q16_16 sub result is clamped (infoCost < entropyCost → 0).
|
||||||
-/
|
-- Actually Q16_16 saturating sub always returns ≥ 0 since clamped to [min,max].
|
||||||
|
-- TODO: prove using Q16_16.sub_nonneg or Q16_16.sat_ge_zero lemma from FixedPoint.
|
||||||
theorem phiUniversalNonNeg {n m : Nat} (params : UniversalFieldParams n m)
|
theorem phiUniversalNonNeg {n m : Nat} (params : UniversalFieldParams n m)
|
||||||
(hw : weightsNonNeg params) (hc : cardinalityConstraint params) :
|
(_hw : weightsNonNeg params) (_hc : cardinalityConstraint params) :
|
||||||
phiUniversalReciprocal params ≥ zero := by
|
phiUniversalReciprocal params ≥ zero := by
|
||||||
unfold phiUniversalReciprocal
|
sorry -- pending Q16_16.sat_ge_zero or equivalent from FixedPoint
|
||||||
-- Destructure the axioms
|
|
||||||
rcases hw with ⟨hw_pos, hv_pos⟩
|
|
||||||
rcases hc with ⟨hN, hM⟩
|
|
||||||
-- Each term is non-negative: weight ≥ 0, ln(N) > 0, so w·ln(N) ≥ 0
|
|
||||||
apply Finset.sum_nonneg
|
|
||||||
intro i hi
|
|
||||||
have h1 : params.w i ≥ zero := hw_pos i
|
|
||||||
have h2 : lnQ16 (params.N i) > zero := by
|
|
||||||
have hN_i := hN i
|
|
||||||
simp [lnQ16, hN_i]
|
|
||||||
-- For N ≥ 2, lnQ16 returns positive value
|
|
||||||
split_ifs
|
|
||||||
· -- N < 2 case, contradiction
|
|
||||||
omega
|
|
||||||
· -- N ≥ 2, lookup table gives positive
|
|
||||||
simp [Q16_16.lt_def]
|
|
||||||
|
|
||||||
This is a constraint on the domain, not an assumption.
|
/-- Φ_cost ≤ ln(256) ≈ 5.545 when Σwᵢ = 1 and all Nᵢ ≤ 256.
|
||||||
-/
|
Bound: Σ wᵢ·lnNᵢ ≤ (Σ wᵢ) · ln(256) = 1.0 · 5.545 ≈ 0x0005C541 in Q16_16.
|
||||||
structure NormalizationBoundedHypothesis where
|
0x00050000 = 5.0 in Q16_16 is a conservative bound. -/
|
||||||
bound (params : UniversalFieldParams n m) :
|
|
||||||
(∑ i : Fin n, (params.w i).val.toNat = 65536) →
|
|
||||||
(∑ j : Fin m, (params.v j).val.toNat = 65536) →
|
|
||||||
(∀ i : Fin n, params.N i ≤ 256) →
|
|
||||||
(∀ j : Fin m, params.M j ≤ 256) →
|
|
||||||
(phiUniversalReciprocal params).val ≤ 0x00050000
|
|
||||||
|
|
||||||
/-- THEOREM: Φ is bounded — DERIVED FROM AXIOM 6 (CORRECTED)
|
|
||||||
|
|
||||||
The boundedness follows from the normalization constraint
|
|
||||||
and practical limits on alphabet size (N ≤ 256).
|
|
||||||
|
|
||||||
Maximum possible Φ ≈ ln(256) ≈ 5.5 for maximally complex systems.
|
|
||||||
NOT assumed — follows from domain definition.
|
|
||||||
-/
|
|
||||||
theorem phiUniversalBounded {n m : Nat} (params : UniversalFieldParams n m)
|
theorem phiUniversalBounded {n m : Nat} (params : UniversalFieldParams n m)
|
||||||
(h_norm_w : ∑ i : Fin n, (params.w i).val.toNat = 65536)
|
(h_norm : weightsNormalized params)
|
||||||
(h_norm_v : ∑ j : Fin m, (params.v j).val.toNat = 65536)
|
(h_bound : alphabetBounded params) :
|
||||||
(h_N_bound : ∀ i : Fin n, params.N i ≤ 256)
|
(phiUniversalReciprocal params).val ≤ 0x0005C541 := by -- ≤ ln(256) in Q16_16
|
||||||
(h_M_bound : ∀ j : Fin m, params.M j ≤ 256) :
|
sorry -- pending: requires finSum bound lemma over Q16_16 weighted products
|
||||||
(phiUniversalReciprocal params).val ≤ 0x00050000 := by -- ≤ 5.0 in Q16_16
|
|
||||||
apply normalizationBounded params h_norm_w h_norm_v h_N_bound h_M_bound
|
|
||||||
|
|
||||||
-- ═══════════════════════════════════════════════════════════════════════════
|
-- ═══════════════════════════════════════════════════════════════════════════
|
||||||
-- §6 Domain-Specific Bindings (Placeholders for Bedrock Unification)
|
-- §6 Domain-Specific Bindings (Placeholders for Bedrock Unification)
|
||||||
|
|
@ -317,16 +280,12 @@ def phiThermodynamics (infoGain temp entropyChange : Q16_16) : Q16_16 :=
|
||||||
|
|
||||||
-- Example: Simple binary system (N=2)
|
-- Example: Simple binary system (N=2)
|
||||||
def exampleParamsBinary : UniversalFieldParams 1 1 :=
|
def exampleParamsBinary : UniversalFieldParams 1 1 :=
|
||||||
{
|
{ w := fun _ => one -- Single weight = 1.0
|
||||||
w := fun _ => one, -- Single weight = 1.0
|
v := fun _ => one
|
||||||
v := fun _ => one,
|
N := fun _ => 2 -- Binary cardinality
|
||||||
N := fun _ => 2, -- Binary cardinality
|
M := fun _ => 2
|
||||||
M := fun _ => 2,
|
h := fun _ => ofRawInt 0x00004000 -- h ≈ 0.25 ≈ 1/ln(2)²
|
||||||
h := fun _ => ⟨0x00004000⟩, -- h = 0.25 (approx 1/ln(2)²)
|
p := fun _ => ofRawInt 0x00004000 }
|
||||||
p := fun _ => ⟨0x00004000⟩, -- p = 0.25
|
|
||||||
hw := by simp [one], native_decide,
|
|
||||||
hv := by simp [one], native_decide
|
|
||||||
}
|
|
||||||
|
|
||||||
#eval phiUniversalReciprocal exampleParamsBinary
|
#eval phiUniversalReciprocal exampleParamsBinary
|
||||||
#eval phiUniversalWeighted exampleParamsBinary
|
#eval phiUniversalWeighted exampleParamsBinary
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# ENE RDS — Rust workspace replacing the Python RDS stack
|
# ENE RDS — Rust workspace replacing the Python RDS stack
|
||||||
|
|
||||||
## Workspace structure
|
## Workspace structure
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ROOT="/home/allaun/Research Stack/4-Infrastructure/infra/ene-rds"
|
ROOT="/home/allaun/Research Stack/4-Infrastructure/infra/ene-rds"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# ene-session-sync
|
# ene-session-sync
|
||||||
|
|
||||||
Rust daemon that syncs OpenCode chat sessions to the ENE RDS PostgreSQL cluster.
|
Rust daemon that syncs OpenCode chat sessions to the ENE RDS PostgreSQL cluster.
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import itertools
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -148,6 +149,8 @@ def bosonic_centrality(
|
||||||
elif n_photons == 3:
|
elif n_photons == 3:
|
||||||
return _centrality_3(U, shots, start, timeout_s)
|
return _centrality_3(U, shots, start, timeout_s)
|
||||||
else:
|
else:
|
||||||
|
if method == "auto" and n_photons >= 5:
|
||||||
|
return _centrality_k(U, n_photons, "distinguishable", shots, start, timeout_s)
|
||||||
return _centrality_k(U, n_photons, method, shots, start, timeout_s)
|
return _centrality_k(U, n_photons, method, shots, start, timeout_s)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -432,7 +435,87 @@ def _centrality_3_mc(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# ── K ≥ 4 (distinguishable approximation) ──────────────────────
|
def _permanent_ryser(M: np.ndarray) -> complex:
|
||||||
|
"""Compute permanent of a small square complex matrix via Ryser's formula."""
|
||||||
|
n = M.shape[0]
|
||||||
|
if n == 0:
|
||||||
|
return 1.0 + 0.0j
|
||||||
|
total = 0.0 + 0.0j
|
||||||
|
for k in range(n + 1):
|
||||||
|
for cols in itertools.combinations(range(n), k):
|
||||||
|
row_sums = np.zeros(n, dtype=np.complex128)
|
||||||
|
for j in cols:
|
||||||
|
row_sums += M[:, j]
|
||||||
|
total += (-1) ** k * np.prod(row_sums)
|
||||||
|
return (-1) ** n * total
|
||||||
|
|
||||||
|
|
||||||
|
def _centrality_k_mc(
|
||||||
|
U: np.ndarray,
|
||||||
|
n_photons: int,
|
||||||
|
shots: int,
|
||||||
|
start: float,
|
||||||
|
timeout_s: float,
|
||||||
|
) -> dict:
|
||||||
|
"""K-photon bosonic Monte Carlo via Ryser permanent sampling.
|
||||||
|
|
||||||
|
Samples output mode tuples, evaluates the KxK permanent of the induced
|
||||||
|
scattering submatrix, and accumulates mode occupations weighted by
|
||||||
|
|Per(M)|^2 / K!. Preserves true bosonic statistics for any K.
|
||||||
|
"""
|
||||||
|
N = U.shape[0]
|
||||||
|
K = n_photons
|
||||||
|
rng = np.random.RandomState(42)
|
||||||
|
|
||||||
|
# Precompute column probability distributions for importance sampling
|
||||||
|
col_probs = [np.abs(U[:, k]) ** 2 for k in range(K)]
|
||||||
|
|
||||||
|
mode_counts = np.zeros(N, dtype=np.float64)
|
||||||
|
used_shots = 0
|
||||||
|
factor = math.factorial(K)
|
||||||
|
|
||||||
|
for _ in range(shots):
|
||||||
|
if time.time() - start > timeout_s:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Sample one output mode per input photon
|
||||||
|
rows = np.array([rng.choice(N, p=col_probs[k]) for k in range(K)], dtype=np.int64)
|
||||||
|
|
||||||
|
# Build KxK submatrix: selected output rows vs input columns 0..K-1
|
||||||
|
M = U[rows, :K]
|
||||||
|
|
||||||
|
perm = _permanent_ryser(M)
|
||||||
|
weight = np.abs(perm) ** 2 / factor
|
||||||
|
|
||||||
|
if weight > 0:
|
||||||
|
for r in rows:
|
||||||
|
mode_counts[r] += weight
|
||||||
|
used_shots += 1
|
||||||
|
|
||||||
|
total_prob = float(np.sum(mode_counts))
|
||||||
|
centrality = mode_counts / max(total_prob, 1e-15)
|
||||||
|
|
||||||
|
entropy = _mode_entropy(mode_counts, total_prob)
|
||||||
|
nonzero = int(np.sum(mode_counts > 1e-15))
|
||||||
|
|
||||||
|
elapsed = time.time() - start
|
||||||
|
|
||||||
|
return dict(
|
||||||
|
n=N, n_photons=K,
|
||||||
|
centrality=np.round(centrality, 6).tolist(),
|
||||||
|
mode_occupations=np.round(centrality, 6).tolist(),
|
||||||
|
output_entropy=round(entropy, 6),
|
||||||
|
nonzero_output_states=nonzero,
|
||||||
|
hilbert_dim=math.comb(N + K - 1, K),
|
||||||
|
total_samples=used_shots,
|
||||||
|
has_nan=False,
|
||||||
|
method=f"mc_permanent{K}",
|
||||||
|
total_ms=round(elapsed * 1000, 1),
|
||||||
|
edges_successful=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ── K ≥ 4 (distinguishable approximation or bosonic MC) ─────────
|
||||||
|
|
||||||
def _centrality_k(
|
def _centrality_k(
|
||||||
U: np.ndarray,
|
U: np.ndarray,
|
||||||
|
|
@ -442,19 +525,15 @@ def _centrality_k(
|
||||||
start: float,
|
start: float,
|
||||||
timeout_s: float,
|
timeout_s: float,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""K-photon centrality via distinguishable approximation.
|
"""K-photon centrality: bosonic MC if requested, else distinguishable approximation."""
|
||||||
|
if method == "bosonic-mc":
|
||||||
|
return _centrality_k_mc(U, n_photons, shots, start, timeout_s)
|
||||||
|
|
||||||
For K ≥ 4, the full bosonic tensor is prohibitive. We use the
|
# Distinguishable-photon fallback (fast, loses bosonic interference)
|
||||||
distinguishable-photon approximation which gives exact single-mode
|
|
||||||
marginals for random unitaries at large N (error O(1/N²)).
|
|
||||||
"""
|
|
||||||
N = U.shape[0]
|
N = U.shape[0]
|
||||||
t0 = time.time() - start
|
t0 = time.time() - start
|
||||||
rng = np.random.RandomState(42)
|
rng = np.random.RandomState(42)
|
||||||
|
|
||||||
# For distinguishable photons, each evolves independently
|
|
||||||
# P(m) = 1 - ∏_{k=0}^{K-1} (1 - |U[m,k]|²)
|
|
||||||
# This is exact for distinguishable, approximate for indistinguishable
|
|
||||||
mode_probs = np.ones(N, dtype=np.float64)
|
mode_probs = np.ones(N, dtype=np.float64)
|
||||||
for k in range(min(n_photons, N)):
|
for k in range(min(n_photons, N)):
|
||||||
col = U[:, k]
|
col = U[:, k]
|
||||||
|
|
@ -498,6 +577,7 @@ def stress_test(
|
||||||
timeout_s: float = 120.0,
|
timeout_s: float = 120.0,
|
||||||
use_real_graph: bool = True,
|
use_real_graph: bool = True,
|
||||||
coupling_phase: float = math.pi / 4,
|
coupling_phase: float = math.pi / 4,
|
||||||
|
bosonic_mc: bool = False,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Iterate over sizes, record when the bosonic TN breaks."""
|
"""Iterate over sizes, record when the bosonic TN breaks."""
|
||||||
results: list[dict] = []
|
results: list[dict] = []
|
||||||
|
|
@ -620,6 +700,8 @@ def main() -> int:
|
||||||
help="Sweep 2,3,4 photons")
|
help="Sweep 2,3,4 photons")
|
||||||
parser.add_argument("--perceval-compare", action="store_true",
|
parser.add_argument("--perceval-compare", action="store_true",
|
||||||
help="Compare K=3 entropy with Perceval at small N")
|
help="Compare K=3 entropy with Perceval at small N")
|
||||||
|
parser.add_argument("--bosonic-mc", action="store_true",
|
||||||
|
help="Use bosonic permanent MC for p>=4 (default is distinguishable approx)")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -654,6 +736,7 @@ def main() -> int:
|
||||||
timeout_s=args.timeout,
|
timeout_s=args.timeout,
|
||||||
use_real_graph=not args.synthetic,
|
use_real_graph=not args.synthetic,
|
||||||
coupling_phase=args.phase,
|
coupling_phase=args.phase,
|
||||||
|
bosonic_mc=args.bosonic_mc,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Summary
|
# Summary
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
"""Seed flexure dataset from the existing RRC equation projection table.
|
"""Seed flexure dataset from the existing RRC equation projection table.
|
||||||
|
|
||||||
Reads docs/rrc_equation_classification.md, generates plausible flexure paths
|
Reads docs/rrc_equation_classification.md, generates plausible flexure paths
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
"""Sync filesystem wiki Markdown files to ENE RDS and emit a JSON receipt."""
|
"""Sync filesystem wiki Markdown files to ENE RDS and emit a JSON receipt."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
"""Validate the RRC receipt-density sidecar table.
|
"""Validate the RRC receipt-density sidecar table.
|
||||||
|
|
||||||
Readback validator for Phase 2.1. Uses the shared rds_connect.connect_rds helper
|
Readback validator for Phase 2.1. Uses the shared rds_connect.connect_rds helper
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# cache-offload.sh
|
# cache-offload.sh
|
||||||
#
|
#
|
||||||
# Three-tier cache offload for database work.
|
# Three-tier cache offload for database work.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# db-consolidate.sh
|
# db-consolidate.sh
|
||||||
#
|
#
|
||||||
# Offloads active database work to Garage (S3) and consolidates static data
|
# Offloads active database work to Garage (S3) and consolidates static data
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# backup.sh — unified backup entrypoint
|
# backup.sh — unified backup entrypoint
|
||||||
#
|
#
|
||||||
# Orchestrates restic + Garage + rclone in their correct roles:
|
# Orchestrates restic + Garage + rclone in their correct roles:
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# PIST Receipt Density Backfill v1
|
# PIST Receipt Density Backfill v1
|
||||||
|
|
||||||
**Status:** CALIBRATED_ENGINEERING_DELTA
|
**Status:** CALIBRATED_ENGINEERING_DELTA
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# ENE-RDS Rust Workspace — Multi-Agent Review Report
|
# ENE-RDS Rust Workspace — Multi-Agent Review Report
|
||||||
|
|
||||||
**Date:** 2026-05-19
|
**Date:** 2026-05-19
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# Research Stack Credential System
|
# Research Stack Credential System
|
||||||
|
|
||||||
> **Canonical source**: `4-Infrastructure/infra/ene-session-sync/src/credential.rs` (Rust), `4-Infrastructure/infra/ene-session-sync/src/ene_cloud_credential_manager.rs` (Rust), `4-Infrastructure/infra/recover_credential_server.sh` (deployment script)
|
> **Canonical source**: `4-Infrastructure/infra/ene-session-sync/src/credential.rs` (Rust), `4-Infrastructure/infra/ene-session-sync/src/ene_cloud_credential_manager.rs` (Rust), `4-Infrastructure/infra/recover_credential_server.sh` (deployment script)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# INFRA:DEAD rds -- AWS RDS is gone. Any file referencing rds_connect.py or this hostname is stale and must be ported.
|
||||||
# ENE RDS Rust Workspace
|
# ENE RDS Rust Workspace
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue