File size: 6,479 Bytes
ea14529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
"""Exact strong T_2 inputs whose merge fails T_(20/9).

Only standard-library rational arithmetic is used. The universal all-rank
extension is a written theorem; this executable certifies the rank-three
integer witnesses and all 225 indexed strong input relations.
"""
from fractions import Fraction
from itertools import combinations
from math import isqrt
from pathlib import Path
import json


def rational(value):
    value = Fraction(value)
    return {"numerator": value.numerator, "denominator": value.denominator}


def sqrt_interval(value, digits=80):
    """Rational endpoints proved to contain sqrt(value) by squaring."""
    value = Fraction(value)
    scale = 10 ** digits
    integer = isqrt(value.numerator * scale * scale // value.denominator)
    lower = Fraction(integer, scale)
    upper = lower if lower * lower == value else Fraction(integer + 1, scale)
    assert lower * lower <= value <= upper * upper
    return lower, upper


def certify(scale, small_coefficient):
    coefficients = {}
    for subset in combinations(range(1, 7), 3):
        key = frozenset(subset)
        if key == frozenset((1, 3, 5)):
            value = 4 * scale - 1
        elif key in (frozenset((1, 2, 6)), frozenset((3, 4, 6))):
            value = small_coefficient
        elif 6 in key:
            value = 5 * scale
        else:
            value = scale
        coefficients[key] = value

    strict_count = tautological_count = 0
    minimum_slack_bound = None
    relation_certificates = []
    for I_tuple in combinations(range(1, 7), 2):
        I = frozenset(I_tuple)
        for J_tuple in combinations(range(1, 7), 4):
            J = frozenset(J_tuple)
            values = [coefficients[I | {j}] * coefficients[J - {j}]
                      for j in sorted(J - I)]
            if len(values) == 2:
                assert values[0] == values[1]
                tautological_count += 1
            else:
                index = max(range(len(values)), key=values.__getitem__)
                intervals = [sqrt_interval(value) for value in values]
                lower_slack = sum(intervals[j][0] for j in range(len(values))
                                  if j != index) - intervals[index][1]
                assert lower_slack > 0
                strict_count += 1
                if minimum_slack_bound is None or lower_slack < minimum_slack_bound:
                    minimum_slack_bound = lower_slack
                relation_certificates.append({
                    "I": list(I_tuple), "J": list(J_tuple),
                    "products": values,
                    "exact_root_intervals": [[rational(lo), rational(hi)]
                                             for lo, hi in intervals],
                    "positive_polygon_slack_lower_bound": rational(lower_slack),
                })
    assert strict_count == 135 and tautological_count == 90

    merged = {}
    for i, j in combinations(range(1, 5), 2):
        merged[f"{i}{j}"] = (coefficients[frozenset((i, j, 5))]
                              + coefficients[frozenset((i, j, 6))])
    A = Fraction(merged["13"] * merged["24"], scale ** 2)
    B = Fraction(merged["14"] * merged["23"], scale ** 2)
    C = Fraction(merged["12"] * merged["34"], scale ** 2)
    left_lower = Fraction(6019, 1000)
    first_right_upper = Fraction(5016, 1000)
    second_right_upper = Fraction(1001, 1000)

    # Since 1/(20/9)=9/20, each interval claim becomes an integer-power
    # comparison after raising to the positive twentieth power.
    differences = [A ** 9 - left_lower ** 20,
                   first_right_upper ** 20 - B ** 9,
                   second_right_upper ** 20 - C ** 9]
    assert all(difference > 0 for difference in differences)
    output_defect_bound = left_lower - first_right_upper - second_right_upper
    assert output_defect_bound == Fraction(1, 500)

    # The baseline has peak r<4 and small coefficient epsilon<=1/4;
    # diagonal weight 5 on element 6 and global scale N give this array.
    peak = Fraction(4 * scale - 1, scale)
    epsilon = Fraction(small_coefficient, 5 * scale)
    assert 1 < peak < 4 and 0 < epsilon <= Fraction(1, 4)
    assert peak * epsilon <= 1

    return {
        "arithmetic": "exact rational arithmetic and certified rational root intervals",
        "input_parameter": rational(2),
        "failed_output_parameter": rational(Fraction(20, 9)),
        "global_coefficient_scale": scale,
        "element6_coefficient_weight": 5,
        "baseline_peak": rational(peak),
        "baseline_small_coefficient": rational(epsilon),
        "input_coefficients": {"".join(map(str, sorted(k))): v
                               for k, v in coefficients.items()},
        "strict_input_relations": strict_count,
        "tautological_input_relations": tautological_count,
        "minimum_input_root_polygon_slack_lower_bound": rational(minimum_slack_bound),
        "input_relation_certificates": relation_certificates,
        "merged_coefficients": merged,
        "normalized_output_products": {"A": rational(A), "B": rational(B),
                                       "C": rational(C)},
        "root_exponent": rational(Fraction(9, 20)),
        "left_root_lower_bound": rational(left_lower),
        "first_right_root_upper_bound": rational(first_right_upper),
        "second_right_root_upper_bound": rational(second_right_upper),
        "positive_twentieth_power_comparison_differences": [rational(d)
                                                           for d in differences],
        "normalized_output_defect_strictly_greater_than": rational(output_defect_bound),
        "status": "all certificates passed",
    }


def main():
    results = {
        "theorem_consequence": "The universal strong-input repair at q=2 is strictly greater than 20/9.",
        "qualification": "The strict inequality for the universal infimum follows by continuity in the output parameter, using this fixed strict witness.",
        "witnesses": [certify(100000, 5), certify(1000, 1)],
    }
    output = Path(__file__).with_name("strong_parameter_bound_results.json")
    output.write_text(json.dumps(results, indent=2) + "\n")
    print(json.dumps({"output": str(output.resolve()), "witnesses": 2,
                      "indexed_input_relations_per_witness": 225,
                      "arithmetic": "exact only", "status": "all checks passed"},
                     indent=2))


if __name__ == "__main__":
    main()