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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//! **THE FOLD AT THE MOUTH** — where a tower's fan closes, and where its two laws are structural.
//!
//! ```text
//! arm₀ (the original) × lane_en ─▶ tail ─▶ ranked stream ─┐
//! arm₀ × lane_ja ─▶ tail ─▶ ranked stream ─┤
//! arm₁ (a paraphrase) × lane_en ─▶ tail ─▶ ranked stream ─┼─ (F) dedup ─▶ (D) weights ─▶ fuse
//! arm₁ × lane_ja ─▶ tail ─▶ ranked stream ─┘
//! ```
//!
//! A [`tower`](crate::retrieve::tower) may contain FANNING SEGMENTS — a widening at ②, a crossing at
//! ④ — and the tower law's amendment is that every fan folds before the tower's mouth, so the outer
//! contract stays 1 → 1. This module is the fold that closes them, and the two rulings that shaped
//! it live in the two places nothing can route around:
//!
//! - **(D) MULTIPLY IS LAW.** A cell's coefficient is `arm × lane`, and the only door into a cell is
//! [`FanStream::new`], which takes the two numbers and multiplies them. There is no seat holding a
//! pre-composed weight, so there is no way to hand the fold a product it did not compute.
//! - **(F) ONE QUESTION'S FAMILY IS ONE WITNESS.** [`fuse_fanned`] deduplicates on FULL EVIDENCE
//! IDENTITY `(root, evidence)` across the ARMS of one lane before a single term is computed, so
//! two paraphrases of one question that found the same thing count once.
//!
//! # WHY THE DEDUP IS ACROSS ARMS AND NOT ACROSS LANES
//!
//! Reciprocal rank fusion measures AGREEMENT BETWEEN SOURCES, and the two axes of this grid are not
//! the same kind of thing. Two LANES are two indexes: a root that both the English and the Japanese
//! lane ranked was found twice, by two readers, and that is the agreement the fold exists to reward.
//! Two ARMS are one question said twice — the caller's own words and an expander's paraphrase of
//! them — so a root both arms found was found ONCE, by one reader, and counting it twice would be
//! measuring how many synonyms an expander happens to know.
//!
//! # AND WHY THE IDENTITY IS `(R, V)` RATHER THAN `R`
//!
//! Because the framework does not know what a root's evidence means, and must not guess. A product
//! whose evidence carries a time locus has two entries under one root that are genuinely two
//! findings — the same video at two different moments — and one that carries nothing has two entries
//! under one root that are genuinely one. Keying on the full pair lets each product's own `V: Eq`
//! settle it, which is the layering theorem rather than a framework policy: **no domain vocabulary
//! enters here, and the equality spent is the product's own.**
use crateLaneIdent;
use ;
/// **WHAT A FANNED TOWER'S TAIL ANSWERS**, and the seat the mouth reads its two parameters off.
///
/// A fanned tower's outer answer is `Vec<Fused<R, V>>` — one value, the amendment's 1 → 1 contract
/// kept — and the emission has to name `R` and `V` to say so. It cannot take them apart from the
/// type its author WROTE: a tail answering `MyStream` or a type alias is a token sequence, and a
/// macro that pattern-matched on the spelling would be reading a name instead of a type. So the two
/// are PROJECTED through this seam, and what a declaration writes at its last step decides them.
///
/// # It is OPEN, and the blanket is the shipped case rather than the only one
///
/// `Vec<Rooted<R, V>>` — what every read walk in this crate already answers in — wears it through
/// the blanket below and costs a declaration nothing. A tail that answers in its own carrier
/// implements this by hand and joins, which is the framework-open discipline the whole retrieve tier
/// keeps: the fold names no product type, and a product names no fold.
/// The shipped tail: a ranked stream IS a list of rooted hits, and the conversion is identity.
/// **ONE CELL OF A FAN'S GRID** — which lane, which arm, what the cell is worth, and what it found.
///
/// ```
/// use ingraph::{ArmWeights, FanStream, LaneIdent, Rooted, RoutedProbe};
///
/// // (D) MULTIPLY IS LAW: the paraphrase arm's 0.5 meets the emphasised lane's 2.0.
/// let cell = FanStream::new(
/// LaneIdent::new("ja"),
/// 1,
/// ArmWeights::DEFAULT_ARM_WEIGHT,
/// 2.0,
/// vec![Rooted::new(7_u32, 1, ())],
/// );
///
/// assert_eq!(cell.weight(), 1.0);
/// assert_eq!(cell.arm(), 1);
///
/// // The axis a tower did not open is the identity on that side, and it is spelled rather than
/// // guessed.
/// let uncut = FanStream::uncut(0, ArmWeights::ORIGINAL, vec![Rooted::new(7_u32, 1, ())]);
/// assert_eq!(uncut.lane(), LaneIdent::UND);
/// assert_eq!(uncut.weight(), RoutedProbe::<()>::UNWEIGHTED);
/// ```
///
/// # THE WEIGHT CANNOT BE HANDED IN, and that is (D) as a shape
///
/// The ruling is *multiply is law, and it is not configurable*. A seat taking a composed coefficient
/// would make the law a convention every caller re-keeps, so there is no such seat: the constructor
/// takes the ARM's number and the LANE's number and the product is the only thing stored. What a
/// deployment tunes is the two inputs, at the two places that own them —
/// [`ArmWeights`](crate::ArmWeights) at the widening step, and the router's own emphasis at the
/// crossing.
///
/// # The ARM is a POSITION and not a name
///
/// [`arm`](Self::arm) is the entry's place in the expansion family, and `0` is the original —
/// [`Expansion::expand`](crate::Expansion::expand)'s own law, which pins the caller's question at
/// the head of the road. The dedup needs to tell *the same lane, a different arm* from *the same
/// lane, the same arm asked twice*, and a position is the one fact that distinguishes them; the arm's
/// LABEL is [`ExpandOrigin`](crate::ExpandOrigin)'s and it has already been spent, on the weight.
/// **THE FOLD AT THE MOUTH** — a fan's whole grid in, one ranked answer out.
///
/// ```text
/// grid ─▶ (F) one family, one witness ─▶ (D) each cell at arm × lane ─▶ fuse_weighted ─▶ answer
/// ```
///
/// # It is [`fuse_weighted`] with ONE STAGE IN FRONT OF IT, and not a second fold
///
/// Every sentence of the fold's own note holds here verbatim: no member's score enters, the ordinal
/// is the engine's raw one, a member is counted once per root, the sort is stable and equal scores
/// come back in first-sighting order. What this adds is the family dedup — the one thing the fan
/// road knows that the fold cannot: which cells were the SAME QUESTION asked in different words.
///
/// # THE SURVIVOR IS THE BEST RANK, and the tie goes to the earlier arm
///
/// Where two arms of one lane found the same `(root, evidence)`, the entry at the LOWER engine
/// ordinal survives and the other is dropped whole. A tie keeps the entry already held, and since
/// the grid arrives in arm order and the original is arm `0`, a tie keeps the caller's own question's
/// finding.
///
/// **The consequence is worth stating**: the survivor carries ITS OWN cell's coefficient, so a
/// paraphrase that ranked something higher than the original did contributes at the paraphrase's
/// weight. That is the ruling read literally — *best rank surviving* — rather than a rank moved onto
/// another arm's entry, which would be this layer inventing an ordinal no engine reported.
///
/// # The bounds, and where each is spent
///
/// `J` is the join's mechanism, last, for [`fuse`](super::fuse)'s own reason. `V: Eq` is the FAMILY
/// dedup's and lands HERE rather than on [`fuse_weighted`], which asks nothing of `V` and must go on
/// asking nothing: a fold that demanded equality of an evidence type would tax every unfanned member
/// in the tree for a law only a fan has.
/// **(F), AS A MASK** — which entries of which cells survive the family dedup.
///
/// A mask rather than a rebuilt grid, because the comparison needs every cell's evidence in hand
/// while it decides: a walk that moved entries out as it went would be reading a collection it was
/// also draining. The mask is `Vec<Vec<bool>>` in the grid's own shape, so applying it is a zip.
///
/// The lanes are grouped in FIRST-APPEARANCE order and each group is walked in the grid's own order,
/// which is arm-major — that is what makes *the tie goes to the earlier arm* a property of the walk
/// rather than a comparison written down.