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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/// Typed progress verdict for repeated exact-Hessian rescue at an inner
/// objective plateau.
///
/// The quasi-Laplace acceptance rule is disjunctive in two KKT currencies:
/// either the raw residual or its identified-quotient residual may establish
/// stationarity. Continuation therefore has to preserve those currencies
/// separately too. Collapsing them to one scalar can retire a productive
/// quotient contraction merely because the ambient residual rose along a
/// gauge/stiff direction.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum StallPolishProgressVerdict {
/// The first plateau establishes the finite residual frontier.
Baseline,
/// At least one KKT currency improved beyond numerical resolution.
Contracting { raw: bool, quotient: bool },
/// Neither KKT currency improved beyond numerical resolution.
NonContracting,
/// A residual, tolerance, or resolution was not a valid certificate input.
Invalid,
}
impl StallPolishProgressVerdict {
pub(crate) fn permits_continuation(self) -> bool {
matches!(self, Self::Baseline | Self::Contracting { .. })
}
}
/// Cross-plateau contraction certificate for terminal exact-Newton polish.
///
/// #2653 — a raw eight-invocation cap retired a K=1 circle solve while the
/// exact-Hessian continuation was still contracting both KKT residuals. This
/// certificate replaces invocation counting with the property the count was
/// trying to approximate: each re-entry must move the Pareto frontier of the
/// two stationarity currencies by more than the caller's numerical-resolution
/// band. A non-contracting plateau is refused; a contracting one may continue.
///
/// This is globally bounded without an arbitrary iteration ration. Every
/// permitted re-entry after the baseline decreases at least one non-negative
/// frontier by `relative_resolution * tolerance`; neither frontier can
/// decrease below zero. Thus a finite starting residual and positive KKT
/// tolerance imply finitely many permitted re-entries, while a healthy
/// contraction is never cut off solely because it happened to be the ninth.
#[derive(Clone, Copy, Debug)]
pub(crate) struct StallPolishProgressCertificate {
relative_resolution: f64,
best_raw: Option<f64>,
best_quotient: Option<f64>,
}
impl StallPolishProgressCertificate {
pub(crate) fn new(relative_resolution: f64) -> Self {
Self {
relative_resolution,
best_raw: None,
best_quotient: None,
}
}
fn materially_contracts(&self, current: f64, best: f64, tolerance: f64) -> bool {
if !(current.is_finite()
&& current >= 0.0
&& best.is_finite()
&& best >= 0.0
&& tolerance.is_finite()
&& tolerance > 0.0
&& self.relative_resolution.is_finite()
&& self.relative_resolution > 0.0
&& self.relative_resolution <= 1.0)
{
return false;
}
let resolution = self.relative_resolution * best.max(tolerance);
best - current > resolution
}
pub(crate) fn observe(
&mut self,
raw: f64,
quotient: f64,
tolerance: f64,
) -> StallPolishProgressVerdict {
if !(raw.is_finite()
&& raw >= 0.0
&& quotient.is_finite()
&& quotient >= 0.0
&& tolerance.is_finite()
&& tolerance > 0.0
&& self.relative_resolution.is_finite()
&& self.relative_resolution > 0.0
&& self.relative_resolution <= 1.0)
{
return StallPolishProgressVerdict::Invalid;
}
let (Some(best_raw), Some(best_quotient)) = (self.best_raw, self.best_quotient) else {
self.best_raw = Some(raw);
self.best_quotient = Some(quotient);
return StallPolishProgressVerdict::Baseline;
};
let raw_contracting = self.materially_contracts(raw, best_raw, tolerance);
let quotient_contracting = self.materially_contracts(quotient, best_quotient, tolerance);
if !(raw_contracting || quotient_contracting) {
return StallPolishProgressVerdict::NonContracting;
}
// Advance only the frontier that actually paid this continuation.
// Recording a sub-resolution decrease would discard it without ever
// letting accumulated movement become material, and would break the
// finite-decrease argument above.
if raw_contracting {
self.best_raw = Some(raw);
}
if quotient_contracting {
self.best_quotient = Some(quotient);
}
StallPolishProgressVerdict::Contracting {
raw: raw_contracting,
quotient: quotient_contracting,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn contracting_kkt_tail_remains_eligible_after_eight_plateaus_2653() {
let tolerance = 9.211_394e-5;
let mut certificate = StallPolishProgressCertificate::new(f64::EPSILON.sqrt());
let mut raw = 8.312_567e-4;
let mut quotient = 7.389_493e-4;
assert_eq!(
certificate.observe(raw, quotient, tolerance),
StallPolishProgressVerdict::Baseline
);
// A raw invocation cap at eight rejected the production tail even
// though both stationarity currencies were still contracting. The
// certificate has no ordinal boundary: all twelve later plateaus earn
// continuation from measured KKT progress.
for plateau in 1..=12 {
raw *= 0.94;
quotient *= 0.93;
let verdict = certificate.observe(raw, quotient, tolerance);
assert!(
matches!(
verdict,
StallPolishProgressVerdict::Contracting {
raw: true,
quotient: true
}
),
"plateau {plateau} must remain eligible while both KKT currencies contract: \
{verdict:?}"
);
assert!(verdict.permits_continuation());
}
assert!(
raw > tolerance && quotient > tolerance,
"the witness must still need continuation after the old eight-entry boundary"
);
}
#[test]
fn either_kkt_currency_can_pay_but_a_repeated_frontier_cannot_2653() {
let tolerance = 1.0e-4;
let mut certificate = StallPolishProgressCertificate::new(f64::EPSILON.sqrt());
assert_eq!(
certificate.observe(8.0e-4, 6.0e-4, tolerance),
StallPolishProgressVerdict::Baseline
);
assert_eq!(
certificate.observe(8.2e-4, 5.0e-4, tolerance),
StallPolishProgressVerdict::Contracting {
raw: false,
quotient: true,
},
"quotient contraction is independently sufficient because quotient KKT \
stationarity is an acceptance authority"
);
assert_eq!(
certificate.observe(8.1e-4, 5.0e-4, tolerance),
StallPolishProgressVerdict::NonContracting,
"neither currency moved its best frontier"
);
assert!(!StallPolishProgressVerdict::NonContracting.permits_continuation());
assert_eq!(
certificate.observe(f64::NAN, 4.0e-4, tolerance),
StallPolishProgressVerdict::Invalid
);
}
}