1
//! Normalising rules for `Sum`
2

            
3
use conjure_core::ast::Expression as Expr;
4
use conjure_core::rule_engine::{register_rule, ApplicationError, ApplicationResult, Reduction};
5

            
6
use Expr::*;
7

            
8
use crate::ast::SymbolTable;
9

            
10
/// Removes sums with a single argument.
11
///
12
/// ```text
13
/// sum([a]) ~> a
14
/// ```
15
#[register_rule(("Base", 8800))]
16
294899
fn remove_unit_vector_sum(expr: &Expr, _: &SymbolTable) -> ApplicationResult {
17
1530
    match expr {
18
1530
        Sum(_, exprs) if (exprs.len() == 1) => Ok(Reduction::pure(exprs[0].clone())),
19
294865
        _ => Err(ApplicationError::RuleNotApplicable),
20
    }
21
294899
}