Skip to content

Commit

Permalink
feat(ast): add Expression::is_associative_commutative_operator()
Browse files Browse the repository at this point in the history
Implement method of Expression to check whether an expression is an
associative-commutative operator. The concept of an AC operator will be
useful down the line for A-CSE, generic normalisation rules, and
quantified expressions.

Related-issues: [conjure-cp#491,conjure-cp#493]
Fixes: conjure-cp#494
  • Loading branch information
niklasdewally committed Nov 26, 2024
1 parent d21981f commit 71257d7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/conjure_core/src/ast/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ impl Expression {
None
}
}

/// True if the expression is an associative and commutative operator
pub fn is_associative_commutative_operator(&self) -> bool {
matches!(
self,
Expression::Sum(_, _) | Expression::Or(_, _) | Expression::And(_, _)
)
}
}

fn display_expressions(expressions: &[Expression]) -> String {
Expand Down

0 comments on commit 71257d7

Please sign in to comment.