File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 11use std:: fmt;
22
3- use p3_field:: PrimeCharacteristicRing ;
3+ use p3_field:: { PrimeCharacteristicRing , PrimeField } ;
44
55use 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
6977impl From < usize > for ConstExpression {
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments