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
//! Stable diagnostics for certified multi-tone composition.
use std::fmt;
use sim_lib_interference_core::SamplingPlane;
use crate::ReferenceSolveError;
/// A multi-tone study or observation was refused without a partial result.
#[derive(Clone, Debug, PartialEq)]
pub enum MultiToneError {
/// A tone's scale was zero, negative, or non-finite.
InvalidWeight {
/// Frequency of the rejected component.
frequency_hz: f64,
/// Rejected scale.
weight: f64,
},
/// An independently certified component solve failed.
ComponentSolve {
/// Frequency of the failed component.
frequency_hz: f64,
/// Exact reference-solver diagnostic.
cause: Box<ReferenceSolveError>,
},
/// A study must contain at least one tone.
EmptyStudy,
/// Equal frequencies must be modeled as one coherent problem.
DuplicateFrequency {
/// Rejected repeated frequency.
frequency_hz: f64,
},
/// One component was solved on different physical sample geometry.
MismatchedPlane {
/// Frequency of the mismatched component.
frequency_hz: f64,
/// Plane established by the first component.
expected: Box<SamplingPlane>,
/// Rejected component plane.
actual: Box<SamplingPlane>,
},
/// A shared observation time was non-finite.
InvalidSeconds {
/// Rejected time.
seconds: f64,
},
/// Frequency-to-angular-time conversion overflowed.
NonFiniteAngularTime {
/// Component frequency.
frequency_hz: f64,
/// Requested shared time.
seconds: f64,
/// Rejected derived angular time.
angular_time: f64,
},
/// Weighting one component scalar produced a non-finite value.
NonFiniteContribution {
/// Component frequency.
frequency_hz: f64,
/// Zero-based row.
row: usize,
/// Zero-based column.
column: usize,
/// Rejected weighted scalar.
value: f64,
},
/// Compensated cross-tone scalar accumulation became non-finite.
NonFiniteAccumulation {
/// Zero-based row.
row: usize,
/// Zero-based column.
column: usize,
/// Rejected accumulated scalar.
value: f64,
},
/// Scalar result storage could not be reserved.
AllocationFailed {
/// Requested scalar cells.
cells: usize,
},
/// The set's temporal Nyquist floor could not be represented.
NonFiniteTemporalSamplingRequirement {
/// Highest component frequency.
highest_frequency_hz: f64,
/// Rejected derived Nyquist sample rate.
samples_per_second: f64,
},
/// Component-certificate storage could not be reserved.
CertificateAllocationFailed {
/// Number of component certificates requested.
tones: usize,
},
}
impl fmt::Display for MultiToneError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidWeight {
frequency_hz,
weight,
} => write!(
formatter,
"tone at {frequency_hz} Hz requires a finite positive weight: {weight:?}"
),
Self::ComponentSolve {
frequency_hz,
cause,
} => write!(
formatter,
"tone at {frequency_hz} Hz could not be certified: {cause}"
),
Self::EmptyStudy => formatter.write_str("multi-tone study requires at least one tone"),
Self::DuplicateFrequency { frequency_hz } => write!(
formatter,
"frequency {frequency_hz} Hz occurs more than once; equal-frequency sources belong in one coherent problem"
),
Self::MismatchedPlane {
frequency_hz,
expected,
actual,
} => write!(
formatter,
"tone at {frequency_hz} Hz uses plane {actual:?}, not the shared plane {expected:?}"
),
Self::InvalidSeconds { seconds } => write!(
formatter,
"multi-tone observation time must be finite: {seconds:?}"
),
Self::NonFiniteAngularTime {
frequency_hz,
seconds,
angular_time,
} => write!(
formatter,
"tone at {frequency_hz} Hz and time {seconds} s produced non-finite angular time {angular_time:?}"
),
Self::NonFiniteContribution {
frequency_hz,
row,
column,
value,
} => write!(
formatter,
"tone at {frequency_hz} Hz produced non-finite weighted scalar {value:?} at ({row}, {column})"
),
Self::NonFiniteAccumulation { row, column, value } => write!(
formatter,
"multi-tone scalar accumulation became non-finite at ({row}, {column}): {value:?}"
),
Self::AllocationFailed { cells } => {
write!(
formatter,
"could not reserve {cells} multi-tone scalar cells"
)
}
Self::NonFiniteTemporalSamplingRequirement {
highest_frequency_hz,
samples_per_second,
} => write!(
formatter,
"highest frequency {highest_frequency_hz} Hz produced non-finite Nyquist rate {samples_per_second:?}"
),
Self::CertificateAllocationFailed { tones } => write!(
formatter,
"could not reserve provenance for {tones} multi-tone components"
),
}
}
}
impl std::error::Error for MultiToneError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::ComponentSolve { cause, .. } => Some(cause.as_ref()),
Self::InvalidWeight { .. }
| Self::EmptyStudy
| Self::DuplicateFrequency { .. }
| Self::MismatchedPlane { .. }
| Self::InvalidSeconds { .. }
| Self::NonFiniteAngularTime { .. }
| Self::NonFiniteContribution { .. }
| Self::NonFiniteAccumulation { .. }
| Self::AllocationFailed { .. }
| Self::NonFiniteTemporalSamplingRequirement { .. }
| Self::CertificateAllocationFailed { .. } => None,
}
}
}