Skip to content

Commit c1d612b

Browse files
committed
lang: small fix
1 parent f8c2c93 commit c1d612b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/leanVm/src/lang/const_expr.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use p3_field::PrimeCharacteristicRing;
3+
use p3_field::{PrimeCharacteristicRing, PrimeField};
44

55
use crate::{
66
constant::F,
@@ -64,6 +64,14 @@ impl ConstExpression {
6464
_ => None,
6565
})
6666
}
67+
68+
#[must_use]
69+
pub fn try_naive_simplification(&self) -> Self {
70+
self.naive_eval().map_or_else(
71+
|| self.clone(),
72+
|value| Self::scalar(value.as_canonical_biguint().try_into().unwrap()),
73+
)
74+
}
6775
}
6876

6977
impl From<usize> for ConstExpression {

crates/leanVm/src/lang/simple_expr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ impl SimpleExpr {
3535
matches!(self, Self::Constant(_))
3636
}
3737

38+
#[must_use] pub fn simplify_if_const(&self) -> Self {
39+
if let Self::Constant(constant) = self {
40+
return constant.try_naive_simplification().into();
41+
}
42+
self.clone()
43+
}
44+
3845
#[must_use]
3946
pub fn as_constant(&self) -> Option<ConstExpression> {
4047
match self {

0 commit comments

Comments
 (0)