Skip to content

Commit a0224e5

Browse files
committed
return max degree and depth
1 parent b438ab1 commit a0224e5

File tree

1 file changed

+16
-8
lines changed
  • crates/multilinear_extensions/src/expression

1 file changed

+16
-8
lines changed

crates/multilinear_extensions/src/expression/utils.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ pub fn expr_compression_to_dag<E: ExtensionField>(
205205
Vec<Instance>,
206206
Vec<Expression<E>>,
207207
Vec<Either<E::BaseField, E>>,
208+
(usize, usize)
208209
) {
209210
let mut dag = vec![];
210211
let mut constant = vec![];
211212
let mut instance_scalar = vec![];
212213
let mut challenges = vec![];
213-
expr_compression_to_dag_helper(
214+
let (max_degree, max_depth) = expr_compression_to_dag_helper(
214215
&mut dag,
215216
&mut instance_scalar,
216217
challenges_offset,
@@ -219,7 +220,7 @@ pub fn expr_compression_to_dag<E: ExtensionField>(
219220
&mut constant,
220221
expr,
221222
);
222-
(dag, instance_scalar, challenges, constant)
223+
(dag, instance_scalar, challenges, constant, (max_degree, max_depth))
223224
}
224225

225226
fn expr_compression_to_dag_helper<E: ExtensionField>(
@@ -275,7 +276,7 @@ fn expr_compression_to_dag_helper<E: ExtensionField>(
275276
dag.extend(vec![DagAdd as u32]);
276277
(
277278
max_degree_a.max(max_degree_b),
278-
(max_depth_a + 1).max(max_depth_b),
279+
max_depth_a.max(max_depth_b + 1),
279280
) // 1 comes from store result of `a`
280281
}
281282
Expression::Product(a, b) => {
@@ -300,11 +301,11 @@ fn expr_compression_to_dag_helper<E: ExtensionField>(
300301
dag.extend(vec![DagMul as u32]);
301302
(
302303
max_degree_a + max_degree_b,
303-
(max_depth_a + 1).max(max_depth_b),
304+
max_depth_a.max(max_depth_b + 1),
304305
) // 1 comes from store result of `a`
305306
}
306307
Expression::ScaledSum(x, a, b) => {
307-
expr_compression_to_dag_helper(
308+
let (max_degree_x, max_depth_x) = expr_compression_to_dag_helper(
308309
dag,
309310
instance_scalar,
310311
challenges_offset,
@@ -313,7 +314,7 @@ fn expr_compression_to_dag_helper<E: ExtensionField>(
313314
constant,
314315
x,
315316
);
316-
expr_compression_to_dag_helper(
317+
let (max_degree_a, max_depth_a) = expr_compression_to_dag_helper(
317318
dag,
318319
instance_scalar,
319320
challenges_offset,
@@ -322,8 +323,10 @@ fn expr_compression_to_dag_helper<E: ExtensionField>(
322323
constant,
323324
a,
324325
);
326+
let xa_degree = max_degree_x + max_degree_a;
327+
let ax_max_depth = max_depth_x.max(max_depth_a + 1);
325328
dag.extend(vec![DagMul as u32]);
326-
expr_compression_to_dag_helper(
329+
let (max_degree_b, max_depth_b) = expr_compression_to_dag_helper(
327330
dag,
328331
instance_scalar,
329332
challenges_offset,
@@ -333,13 +336,18 @@ fn expr_compression_to_dag_helper<E: ExtensionField>(
333336
b,
334337
);
335338
dag.extend(vec![DagAdd as u32]);
339+
(
340+
xa_degree.max(max_degree_b),
341+
(ax_max_depth).max(max_depth_b + 1),
342+
) // 1 comes from store result of `ax`
336343
}
337344
c @ Expression::Challenge(..) => {
338345
challenges.push(c.clone());
339346
dag.extend(vec![
340347
DagLoadScalar as u32,
341348
(challenges_offset + challenges.len()) as u32 - 1,
342-
])
349+
]);
350+
(0, 1)
343351
}
344352
}
345353
}

0 commit comments

Comments
 (0)