fn term_and_pow_from_expr(expr: RcExpr) -> Result<(RcExpr, usize), String> {
    match expr.as_ref() {
        Expr::BinaryExpr(BinaryExpr {
            op: BinaryOperator::Exp,
            lhs,
            rhs,
        }) if rhs.is_const() => {
            let (pow_f64, term) = (rhs.get_const().unwrap(), lhs);
            let pow = pow_f64 as usize;
            if (pow as f64 - pow_f64).abs() > std::f64::EPSILON {
                // And we only support integer powers in the polynomial.
                return Err(format!("Expected a positive term degree for {}", expr));
            }
            Ok((term.clone(), pow))
        }
        // If there is no explicit exponentiation, just treat the whole expression
        // as a term.
        _ => Ok((expr, 1)),
    }
}
/// Gets the term and power of an expression.
/// Returns None if the power is not a positive integer.
Gets the term and power of an expression.
Returns None if the power is not a positive integer.
Gets the term and power of an expression . Returns None if the power is not a positive integer .
fn term_and_pow_from_expr(expr: RcExpr) -> Result<(RcExpr, usize), String> {
    match expr.as_ref() {
        Expr::BinaryExpr(BinaryExpr {
            op: BinaryOperator::Exp,
            lhs,
            rhs,
        }) if rhs.is_const() => {
            let (pow_f64, term) = (rhs.get_const().unwrap(), lhs);
            let pow = pow_f64 as usize;
            if (pow as f64 - pow_f64).abs() > std::f64::EPSILON {
                // And we only support integer powers in the polynomial.
                return Err(format!("Expected a positive term degree for {}", expr));
            }
            Ok((term.clone(), pow))
        }
        // If there is no explicit exponentiation, just treat the whole expression
        // as a term.
        _ => Ok((expr, 1)),
    }
}
fn term_and_pow_from_expr ( expr : RcExpr ) -> Result < ( RcExpr , usize ) , String > { match expr . as_ref ( ) { Expr :: BinaryExpr ( BinaryExpr { op : BinaryOperator :: Exp , lhs , rhs , } ) if rhs . is_const ( ) => { let ( pow_f64 , term ) = ( rhs . get_const ( ) . unwrap ( ) , lhs ) ; let pow = pow_f64 as usize ; if ( pow as f64 - pow_f64 ) . abs ( ) > std :: f64 :: EPSILON { // And we only support integer powers in the polynomial. return Err ( format ! ( " " expr ) ) ; } Ok ( ( term . clone ( ) , pow ) ) } // If there is no explicit exponentiation, just treat the whole expression // as a term. _ => Ok ( ( expr , 1 ) ) , } }
Gets the term and power of an expression.
Gets the term and power of an expression .
expr
RcExpr
expr
RcExpr