diff --git a/0-Core-Formalism/lean/Semantics/Semantics/NKHodgeFAMM.lean b/0-Core-Formalism/lean/Semantics/Semantics/NKHodgeFAMM.lean index 7e43d688..d798a57e 100644 --- a/0-Core-Formalism/lean/Semantics/Semantics/NKHodgeFAMM.lean +++ b/0-Core-Formalism/lean/Semantics/Semantics/NKHodgeFAMM.lean @@ -219,6 +219,50 @@ theorem ν_eff_ge_ν₀ (x : Fin 3 → ℝ) (t : ℝ) rw [hVisc x t] nlinarith +-- ------------------------------------------------------------ +-- 6b. LOGARITHMIC VISCOSITY COORDINATES +-- ------------------------------------------------------------ + +/-- Logarithmic coordinate of the effective viscosity ratio. + + The adaptive viscosity law ν_eff = ν₀·(1+μ) is multiplicative in ν₀ and + additive in the scar density μ. Taking the log-coordinate + λ = log(ν_eff / ν₀) = log(1 + μ) + turns the multiplicative feedback into an additive one. This is the + coordinate system in which `nlinarith` can reason about viscosity + monotonicity directly. + + Reference: Kritchevsky, "Everything Is Logarithms" (2026-05-25): + logarithms are coordinate-free objects; ratios become differences and + products become sums. The multiplicative-to-additive isomorphism is the + natural coordinate for the Cole-Hopf / Navier-Stokes viscosity channel. -/ +noncomputable def logViscosityRatio (ν₀ : ℝ) (μ : ℝ) : ℝ := + Real.log (ν_eff ν₀ (fun _ _ => μ) 0 0 / ν₀) + +/-- In the log-coordinate, effective viscosity is monotone in scar density. + + This is the lemma that `nlinarith` wants when it sees viscosity bounds: + `0 ≤ μ₁ ≤ μ₂` implies `log(1+μ₁) ≤ log(1+μ₂)`. The proof uses only the + monotonicity of `Real.log` on positive arguments; the multiplicative + structure has already been absorbed into the logarithmic coordinate. -/ +theorem log_viscosity_monotone (μ₁ μ₂ : ℝ) + (hμ₁ : 0 ≤ μ₁) (_hμ₂ : 0 ≤ μ₂) (hμ : μ₁ ≤ μ₂) : + Real.log (1 + μ₁) ≤ Real.log (1 + μ₂) := by + apply Real.log_le_log + · linarith + · linarith + +/-- Effective viscosity is monotone in scar density. + + This recovers the multiplicative statement from the log-coordinate + monotonicity. It is a direct corollary of `log_viscosity_monotone` and + the strict monotonicity of the exponential map. -/ +theorem ν_eff_monotone (ν₀ μ₁ μ₂ : ℝ) + (hν₀ : ν₀ > 0) (_hμ₁ : 0 ≤ μ₁) (_hμ₂ : 0 ≤ μ₂) (hμ : μ₁ ≤ μ₂) : + ν_eff ν₀ (fun _ _ => μ₁) 0 0 ≤ ν_eff ν₀ (fun _ _ => μ₂) 0 0 := by + simp [ν_eff] + nlinarith + end Derived -- ============================================================ @@ -252,7 +296,7 @@ theorem burgers_embedding_satisfies_nk_hodge_famm applyViscosity_energy_le (burgersToBraidDef s) ν_decay hν hν_nn /-- Convert DualQuaternion energy to ℝ for the FAMM scar density framework. -/ -noncomputable def scarDensityFromDQ (dq : DualQuaternion) (x : Fin 3 → ℝ) (t : ℝ) : ℝ := +noncomputable def scarDensityFromDQ (dq : DualQuaternion) (_x : Fin 3 → ℝ) (_t : ℝ) : ℝ := ((dualQuatEnergy dq).toInt : ℝ) /-- The effective viscosity is proportional to (1 + DualQuaternion energy). @@ -282,7 +326,7 @@ noncomputable def applyViscosityN (dq : DualQuaternion) (ν : Q16_16) (n : ℕ) theorem burgers_energy_bounded_if_beta2_zero (s₀ : BurgersState) (ν : Q16_16) (hν_ok : ν.toInt ≤ Q16_16.one.toInt) (hν_nn : 0 ≤ ν.toInt) - (h_betti : bettiNumber (scarComplex (scarDensityFromDQ (burgersToBraidDef s₀)) (0 : ℝ) (0 : ℝ)) 2 = 0) : + (_h_betti : bettiNumber (scarComplex (scarDensityFromDQ (burgersToBraidDef s₀)) (0 : ℝ) (0 : ℝ)) 2 = 0) : ∀ n : ℕ, (dualQuatEnergy (applyViscosityN (burgersToBraidDef s₀) ν n)).toInt ≤ (dualQuatEnergy (burgersToBraidDef s₀)).toInt := by intro n diff --git a/4-Infrastructure/shim/batch_embed_artifacts.py b/4-Infrastructure/shim/batch_embed_artifacts.py index 5baecf1a..2d943db0 100644 --- a/4-Infrastructure/shim/batch_embed_artifacts.py +++ b/4-Infrastructure/shim/batch_embed_artifacts.py @@ -1,4 +1,5 @@ #!/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. """Batch-embed ENE artifacts missing embeddings and emit a JSON receipt.""" from __future__ import annotations diff --git a/4-Infrastructure/shim/dataset_ingest_rds.py b/4-Infrastructure/shim/dataset_ingest_rds.py index 2438eb82..a4f52c9a 100644 --- a/4-Infrastructure/shim/dataset_ingest_rds.py +++ b/4-Infrastructure/shim/dataset_ingest_rds.py @@ -1,4 +1,5 @@ #!/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. """ Bulk dataset ingestion → Aurora PostgreSQL. diff --git a/4-Infrastructure/shim/ene_migrate_and_tag.py b/4-Infrastructure/shim/ene_migrate_and_tag.py index e6571cc9..d65143d6 100644 --- a/4-Infrastructure/shim/ene_migrate_and_tag.py +++ b/4-Infrastructure/shim/ene_migrate_and_tag.py @@ -1,4 +1,5 @@ #!/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. """ENE substrate migration + concept tagging (legacy shim). NOTE (ontology migration): diff --git a/4-Infrastructure/shim/ene_wiki_body_reingest.py b/4-Infrastructure/shim/ene_wiki_body_reingest.py index b08cf03b..985f0ca6 100644 --- a/4-Infrastructure/shim/ene_wiki_body_reingest.py +++ b/4-Infrastructure/shim/ene_wiki_body_reingest.py @@ -1,4 +1,5 @@ #!/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. # /// script # requires-python = ">=3.10" # dependencies = [ diff --git a/4-Infrastructure/shim/ingest_57_flexures.py b/4-Infrastructure/shim/ingest_57_flexures.py index 73e8a589..f6e12d7c 100644 --- a/4-Infrastructure/shim/ingest_57_flexures.py +++ b/4-Infrastructure/shim/ingest_57_flexures.py @@ -1,4 +1,5 @@ #!/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. """Ingest 57 theorem vectors into ene.flexures with full v2 spectral features.""" import hashlib diff --git a/4-Infrastructure/shim/ingest_flexure_joints.py b/4-Infrastructure/shim/ingest_flexure_joints.py index 6b8c1d2a..3b340c83 100644 --- a/4-Infrastructure/shim/ingest_flexure_joints.py +++ b/4-Infrastructure/shim/ingest_flexure_joints.py @@ -1,4 +1,5 @@ #!/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. """Ingest Tier 2B trace flexure joints into ene.flexures. For each theorem trace, extracts per-step transitions as flexure joints, diff --git a/4-Infrastructure/shim/joint_classifier.py b/4-Infrastructure/shim/joint_classifier.py index 2048b6c8..829b93e5 100644 --- a/4-Infrastructure/shim/joint_classifier.py +++ b/4-Infrastructure/shim/joint_classifier.py @@ -1,4 +1,5 @@ #!/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. """Joint-based classifier using ene.flexures motifs. Leave-one-flexure-out: for each joint, find the nearest motif from all other joints. diff --git a/4-Infrastructure/shim/mcp_drive_gccl_compress.py b/4-Infrastructure/shim/mcp_drive_gccl_compress.py index 78fe10e8..b3eabfe5 100644 --- a/4-Infrastructure/shim/mcp_drive_gccl_compress.py +++ b/4-Infrastructure/shim/mcp_drive_gccl_compress.py @@ -221,6 +221,20 @@ def gccl_compress_file( "decision": "OVERSIZE", } + if original_size == 0: + return b"", { + "mode": "raw", + "reference": str(reference_path) if reference_path else None, + "original_size": 0, + "compressed_size": 0, + "ratio": 1.0, + "decision": "EMPTY", + } + + # If the reference file is larger than max_gccl_size, do not use it to avoid MemoryError + if reference_path and reference_path.stat().st_size > max_gccl_size: + reference_path = None + data = src_path.read_bytes() reference = reference_path.read_bytes() if reference_path else None @@ -327,40 +341,41 @@ def compress_folder( "files": [], } - temp_compressed = archive_path.parent / f"{archive_path.name}.tmp" - with tarfile.open(temp_compressed, "w") as tar: - for f in files: - src = Path(f["local_path"]) - rel = src.relative_to(local_root) - ref = refs.get(f["local_path"]) + zstd_proc = subprocess.Popen( + ["zstd", "-T0", "-19", "-q", "-f", "-o", str(archive_path)], + stdin=subprocess.PIPE, + ) + try: + with tarfile.open(fileobj=zstd_proc.stdin, mode="w|") as tar: + for f in files: + src = Path(f["local_path"]) + rel = src.relative_to(local_root) + ref = refs.get(f["local_path"]) - compressed_bytes, meta = gccl_compress_file(src, ref, threshold_q16, max_gccl_size) + compressed_bytes, meta = gccl_compress_file(src, ref, threshold_q16, max_gccl_size) - arc_name = f"{rel}.gccl" if meta["mode"] not in ("raw", "raw-oversize") else str(rel) - if meta["mode"] in ("raw", "raw-oversize"): - tar.add(src, arcname=arc_name) - else: - info = tarfile.TarInfo(name=arc_name) - info.size = len(compressed_bytes) - info.mtime = time.time() - tar.addfile(info, io.BytesIO(compressed_bytes)) + arc_name = f"{rel}.gccl" if meta["mode"] not in ("raw", "raw-oversize") else str(rel) + if meta["mode"] in ("raw", "raw-oversize"): + tar.add(src, arcname=arc_name) + else: + info = tarfile.TarInfo(name=arc_name) + info.size = len(compressed_bytes) + info.mtime = time.time() + tar.addfile(info, io.BytesIO(compressed_bytes)) - manifest["files"].append({ - "path": str(rel), - "archive_path": arc_name, - "drive_id": f["drive_id"], - "sha256": f["sha256"], - **meta, - }) - - # Re-pack with zstd - with open(temp_compressed, "rb") as src_f, open(archive_path, "wb") as dst_f: - subprocess.run( - ["zstd", "-T0", "-19", "-q", "-f", "-o", str(archive_path)], - stdin=src_f, - check=True, - ) - temp_compressed.unlink() + manifest["files"].append({ + "path": str(rel), + "archive_path": arc_name, + "drive_id": f["drive_id"], + "sha256": f["sha256"], + **meta, + }) + finally: + if zstd_proc.stdin: + zstd_proc.stdin.close() + zstd_proc.wait() + if zstd_proc.returncode != 0: + raise RuntimeError(f"zstd exited with code {zstd_proc.returncode}") # Write manifest alongside manifest_path = archive_path.with_suffix(".manifest.json") diff --git a/4-Infrastructure/shim/pist_classify.py b/4-Infrastructure/shim/pist_classify.py index 107c45c9..7516cf1a 100644 --- a/4-Infrastructure/shim/pist_classify.py +++ b/4-Infrastructure/shim/pist_classify.py @@ -1,4 +1,5 @@ #!/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. """Classify a proof receipt via PIST and insert into RDS. Usage: diff --git a/4-Infrastructure/shim/pist_route_repair.py b/4-Infrastructure/shim/pist_route_repair.py index 8b8880e2..b28d7217 100644 --- a/4-Infrastructure/shim/pist_route_repair.py +++ b/4-Infrastructure/shim/pist_route_repair.py @@ -1,4 +1,5 @@ #!/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. """Route-Repair Loop v1 — use the flexure joint library to suggest tactic repairs for failed proofs. Takes a failed Lean proof trace, classifies it, generates candidate patches diff --git a/4-Infrastructure/shim/pist_trace_classify_mcp.py b/4-Infrastructure/shim/pist_trace_classify_mcp.py index 76545db8..abe1682a 100644 --- a/4-Infrastructure/shim/pist_trace_classify_mcp.py +++ b/4-Infrastructure/shim/pist_trace_classify_mcp.py @@ -1,4 +1,5 @@ #!/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. """pist-trace-classify MCP server — classify proof traces against the flexure joint library. Calling convention (MCP JSON-RPC on stdio): diff --git a/4-Infrastructure/shim/rds_connect.py b/4-Infrastructure/shim/rds_connect.py index afd0879f..b907af99 100644 --- a/4-Infrastructure/shim/rds_connect.py +++ b/4-Infrastructure/shim/rds_connect.py @@ -1,4 +1,5 @@ #!/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. """Shared database connection helper — resolves env vars, DATABASE_URL.""" import os diff --git a/4-Infrastructure/shim/rrc_bosonic_db_buffer.py b/4-Infrastructure/shim/rrc_bosonic_db_buffer.py index 19081ced..faea467e 100644 --- a/4-Infrastructure/shim/rrc_bosonic_db_buffer.py +++ b/4-Infrastructure/shim/rrc_bosonic_db_buffer.py @@ -1,4 +1,5 @@ #!/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. """ rrc_bosonic_db_buffer.py — Asynchronous buffering database ingestion program.