{"id":49068838,"url":"https://github.com/zfifteen/cognitive-distortion-layer","last_synced_at":"2026-04-20T06:14:55.232Z","repository":{"id":348084792,"uuid":"1196403275","full_name":"zfifteen/cognitive-distortion-layer","owner":"zfifteen","description":"Validated curvature signal for integer structural classification. κ(n) = d(n)·ln(n)/e² separates primes from composites at 3.05× ratio with 88.2% hold-out accuracy. Core signal layer of the Z Framework. Includes CDL API, adaptive threshold protocol, Z-normalization, and falsification experiments. Active research: v-inference.","archived":false,"fork":false,"pushed_at":"2026-03-30T17:46:57.000Z","size":10127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-30T19:28:22.581Z","etag":null,"topics":["computational-number-theory","curvature","data-science","divisor-function","integer-classification","mathematical-framework","mathematics","normalization","number-theory","numerical-analysis","primality-testing","prime-numbers","python","quasi-monte-carlo","signal-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zfifteen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T17:03:42.000Z","updated_at":"2026-03-30T17:47:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zfifteen/cognitive-distortion-layer","commit_stats":null,"previous_names":["zfifteen/cognitive-distortion-layer"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/zfifteen/cognitive-distortion-layer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfifteen%2Fcognitive-distortion-layer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfifteen%2Fcognitive-distortion-layer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfifteen%2Fcognitive-distortion-layer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfifteen%2Fcognitive-distortion-layer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfifteen","download_url":"https://codeload.github.com/zfifteen/cognitive-distortion-layer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfifteen%2Fcognitive-distortion-layer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32035372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-number-theory","curvature","data-science","divisor-function","integer-classification","mathematical-framework","mathematics","normalization","number-theory","numerical-analysis","primality-testing","prime-numbers","python","quasi-monte-carlo","signal-processing"],"created_at":"2026-04-20T06:14:54.517Z","updated_at":"2026-04-20T06:14:55.211Z","avatar_url":"https://github.com/zfifteen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cognitive Model: A Forward Diagnostic Framework for Number-Theoretic Distortion\n\n![Cognitive Distortion Layer Banner](assets/readme-banners/banner.png)\n\n## Overview\n\nThis repository presents a theoretical and computational framework for analyzing discrete integer sequences through a geometry-inspired \"curvature\" model. By drawing a pedagogical analogy to relativistic distortions, we define a **forward diagnostic map** that highlights structural irregularities—especially those arising from divisor density. This model is intended for **structural analysis**, not for blind inversion of unknown values.\n\n**🆕 The Cognitive Distortion Layer (CDL)** standardizes κ(n) as the shared curvature signal across the Z Framework, providing unified primitives for prime diagnostics, QMC sampling, and signal normalization. Source modules now live under [`src/python/`](src/python), with specifications in [`docs/specification/CDL_SPECIFICATION.md`](docs/specification/CDL_SPECIFICATION.md) and [`docs/specification/INTEGRATION.md`](docs/specification/INTEGRATION.md).\n\n## Key Concepts\n\n1. **Curvature Function**\n\n   $$\n   \\kappa(n) = \\frac{d(n) \\cdot \\ln(n)}{e^2}\n   $$\n\n   * **d(n)**: Divisor count of $n$ (i.e., $\\sigma_0(n)$).\n   * **ln(n)**: Natural logarithm of $n$.\n   * **Normalization**: Constant $e^2$ determined empirically.\n   * **Interpretation**: Higher divisor counts and larger values yield greater local \"curvature\".\n\n2. **Distortion Mapping (Forward Model)**\n\n   $$\n   \\Delta_n = v \\cdot \\kappa(n)\n   $$\n\n   * **v**: A user-defined \"traversal rate\" parameter (e.g., cognition or iteration speed).\n   * **$\\Delta_n$**: Modeled distortion at $n$.\n   * **Purpose**: Encodes how rapid progression through integers skews apparent structure.\n\n3. **Perceived Value**\n\n   $$\n   n_{\\text{perceived}} = n \\times \\exp\\bigl(\\Delta_n\\bigr)\n   $$\n\n   * Applies exponential scaling to the true integer based on $\\Delta_n$.\n   * Emphasizes how distortion amplifies structural irregularities in composites.\n\n4. **Z-Transformation (Context-Dependent Normalization)**\n\n   $$\n   Z(n) \\;=\\; \\frac{n}{\\exp\\bigl(v \\cdot \\kappa(n)\\bigr)}\n   $$\n\n   * **Forward diagnostic use only**: Assumes knowledge of $n$ and $v$ to normalize distortion.\n   * **Outcome**: Reveals underlying structural stability, particularly for primes where $\\kappa(n)$ is minimal.\n\n## Empirical Validation\n\n* **Prime vs. Composite Curvature (n = 2–49)**\n\n  * Prime average curvature: \\~0.739\n  * Composite average curvature: \\~2.252\n  * Ratio: Composites ≈3.05× higher curvature\n\n* **Classification Test**\n\n  * Simple threshold on $\\kappa(n)$ yields \\~83% accuracy distinguishing primes from composites.\n\nThese results demonstrate that primes appear as \"minimal-curvature geodesics\" within the discrete sequence, providing a quantitative diagnostic measure of number complexity.\n\n## Implementation\n\n* **Language**: Python 3\n* **Source Layout**:\n\n  * `src/python/cdl.py`: Canonical CDL primitives\n  * `src/python/cdl_prime_geodesic_prefilter.py`: Deterministic cryptographic prime prefilter and generator\n  * `src/python/cdl_continuous.py`: Continuous-domain CDL extensions\n  * `src/python/v_recovery.py`: Traversal-rate inference\n  * `src/python/cognitive_pilot.py`: Sprint 6 cognitive pilot pipeline\n\n* **Repository Layout**:\n\n  * `docs/`: Specifications, summaries, roadmap, and concept notes\n  * `data/`: Reference data and generated simulation traces\n  * `artifacts/`: Generated reports and figures\n  * `experiments/`: Research sprint outputs and benchmarks\n  * `scripts/`: Demo, dashboard, report, and reproduction utilities\n  * `tests/`: Reorganized pytest suite\n\n### Quick Start with CDL\n\nThe Cognitive Distortion Layer provides production-ready primitives:\n\n```python\nimport cdl\n\n# Core primitive 1: Curvature signal\nkappa_value = cdl.kappa(17)  # Returns κ(n)\n\n# Core primitive 2: Threshold classifier\nclassification = cdl.classify(17, threshold=1.5)  # \"prime\" or \"composite\"\n\n# Core primitive 3: Z-normalization\nz_value = cdl.z_normalize(17, v=1.0)  # Returns Z(n)\n\n# Integration helpers\nlikely_primes, likely_composites = cdl.prime_diagnostic_prefilter(candidates)\nbiased_candidates = cdl.qmc_sampling_bias(candidates, bias_strength=0.8)\nnormalized_signals = cdl.signal_normalize_pipeline(raw_signals, v=1.0)\n```\n\n**See [`docs/specification/INTEGRATION.md`](docs/specification/INTEGRATION.md) for complete integration examples.**\n\n### Deterministic Cryptographic Prime Generation\n\nThe production CDL geodesic prefilter now ships as `src/python/cdl_prime_geodesic_prefilter.py`. It applies the sweet-spot band at `v = e² / 2`, rejects composites through deterministic gated prime tables, and then runs fixed-base Miller-Rabin plus final `sympy.isprime` confirmation on survivors.\n\n```python\nfrom cdl_prime_geodesic_prefilter import CDLPrimeGeodesicPrefilter\n\np_prefilter = CDLPrimeGeodesicPrefilter(bit_length=1024, namespace=\"rsa-demo:p\")\nq_prefilter = CDLPrimeGeodesicPrefilter(bit_length=1024, namespace=\"rsa-demo:q\")\n\np = p_prefilter.generate_prime(public_exponent=65537)\nq = q_prefilter.generate_prime(public_exponent=65537, excluded_values={p})\n```\n\nBenchmarked result:\n- `2.09x` end-to-end speedup across `300` deterministic `2048`-bit RSA keypairs\n- `2.82x` end-to-end speedup across `50` deterministic `4096`-bit RSA keypairs\n- `90.97%` to `91.07%` Miller-Rabin reduction with the prime band preserved\n\nThese are full key-generation numbers, not just candidate-loop screening ratios. See [`experiments/crypto_prefilter/BENCHMARK_REPORT.md`](experiments/crypto_prefilter/BENCHMARK_REPORT.md) for the separate candidate-loop and end-to-end timing breakdown.\n\n### Quick Start with Self-Contained Gist\n\nThe standalone gist lives at `scripts/demos/curvature_gist.py` and has **only numpy** as a dependency:\n\n```bash\n# Basic usage (n = 2-50, default parameters)\npython scripts/demos/curvature_gist.py\n\n# Extended analysis with 10,000 numbers\npython scripts/demos/curvature_gist.py --max-n 10000\n\n# Custom v-parameter for Z-transformation\npython scripts/demos/curvature_gist.py --max-n 1000 --v-param 0.5\n\n# Fewer bootstrap samples for faster execution\npython scripts/demos/curvature_gist.py --max-n 100 --bootstrap-samples 500\n```\n\n**Key Features**:\n- Instant computation for custom n ranges\n- Built-in primality checks and bootstrap CI reporting\n- Extensible v-parameter tuning for Z-normalization\n- Outputs `data/reference/kappas.csv` with (n, κ(n), Z(n)) data\n- ~83% classification accuracy for prime vs composite\n\nThe gist can also be imported as a module:\n\n### Full Model Example\n\n```bash\n# Run complete cognitive model with visualizations\npython scripts/demos/main.py\n```\n\nGenerates curvature statistics, writes figures into `artifacts/figures/`, and writes CSV traces into `data/simulated/`.\n\n### Validation \u0026 Testing\n\n```bash\n# Run CDL test suite\npython tests/test_suite.py\n\n# Generate baseline validation report\npython scripts/reports/baseline_report.py\n\n# Generate visualization dashboards\npython scripts/dashboards/generate_cdl_dashboards.py\n\n# Run the full Sprint 1–6 local reproduction\npython scripts/reproduce_sprints.py\n```\n\n**Validation Results:**\n- Seed set (n=2-49): Prime avg κ = 0.739, Composite avg κ = 2.252, Accuracy = 83.7%\n- Hold-out (n=50-10K): Accuracy = 88.2%, maintains separation pattern\n- Z-normalization: 99.2% variance reduction\n- All acceptance criteria met ✓\n\nThe baseline report is written to `artifacts/reports/baseline_report.json`.\n\n## Limitations \u0026 Scope\n\n1. **Forward Diagnostic Only**\n\n   * The Z-transformation **requires** known $n$ and rate $v$. It **does not** serve as a standalone inverse to recover unknown integers from perceived values.\n2. **Context-Dependent Parameters**\n\n   * Parameters like $v$ (traversal rate) must be set or estimated; values are not inferred solely from data.\n3. **Metaphorical Analogy**\n\n   * References to relativity and geodesics are pedagogical. The core mathematics stands independently of physical interpretations.\n\n## Future Directions\n\n* **Parameter Estimation**: Explore data-driven methods to approximate traversal rates from observed distortions.\n* **Enhanced Classification**: Integrate curvature features into machine-learning classifiers for primality testing.\n* **Theoretical Extensions**: Investigate connections between divisor-based curvature and deeper analytic number theory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfifteen%2Fcognitive-distortion-layer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfifteen%2Fcognitive-distortion-layer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfifteen%2Fcognitive-distortion-layer/lists"}