File size: 1,997 Bytes
9552b49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Reproduce exact closure and the analytic rank-error frontier."""
import json
import sys
from pathlib import Path
import numpy as np

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
from oqaivaei.continuation import (
    involution_pair, exact_closure, balanced_real_projector,
    coordinate_minimax_error,
)


def run():
    closures = []
    for n in [3, 4, 5, 8, 12, 16]:
        a, b, c = involution_pair(n)
        combined = exact_closure([a, b], c)
        closures.append({
            "n": n, "rank_a": exact_closure([a], c).dimension,
            "rank_b": exact_closure([b], c).dimension,
            "rank_combined": combined.dimension,
            "dimensions_by_round": combined.dimensions_by_round,
            "maximum_retained_word_length": max(map(len, combined.words)),
        })
    rows = []
    for n in [8, 16, 32, 64]:
        for k in range(n + 1):
            p = balanced_real_projector(n, k)
            measured = coordinate_minimax_error(p)
            expected = float(np.sqrt(1 - k / n))
            rows.append({"n": n, "k": k, "formula": expected,
                         "constructed_error": measured,
                         "absolute_residual": abs(measured - expected)})
    return {"exact_closures": closures, "rank_error_frontier": rows,
            "max_absolute_residual": max(r["absolute_residual"] for r in rows),
            "verification": "exact rational closure; floating-point projectors",
            "data_kind": "synthetic mathematical instances"}


if __name__ == "__main__":
    out = ROOT / "results" / "continuation_results.json"
    out.parent.mkdir(exist_ok=True)
    result = run()
    out.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
    print(json.dumps({"output": str(out), "exact_instances": len(result["exact_closures"]),
                      "frontier_points": len(result["rank_error_frontier"]),
                      "max_residual": result["max_absolute_residual"]}))