Skip to content

Commit

Permalink
add more simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vic1707 committed Nov 29, 2023
1 parent 02c8ce6 commit acac3c1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/element/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ impl<'a> Simplify<'a> for BinOp<'a> {
lhs,
rhs,
} if rhs == Number(1.0) => lhs,
////// NIGHTLY FEATURES //////
// (-a) * (-b) => a * b
#[cfg(NIGHTLY)]
BinOp {
op: Times,
lhs:
Element::UnOp(box UnOp {
op: Minus,
operand: lhs,
}),
rhs:
Element::UnOp(box UnOp {
op: Minus,
operand: rhs,
}),
} => BinOp::new_element(Operator::Times, lhs, rhs),
/////////////////////////// Divisions ///////////////////////////
// 0/0 => NaN // special case
BinOp {
Expand Down Expand Up @@ -140,6 +156,22 @@ impl<'a> Simplify<'a> for BinOp<'a> {
lhs,
rhs,
} if lhs == rhs => Number(1.0),
////// NIGHTLY FEATURES //////
// (-a) / (-b) => a / b
#[cfg(NIGHTLY)]
BinOp {
op: Divide,
lhs:
Element::UnOp(box UnOp {
op: Minus,
operand: lhs,
}),
rhs:
Element::UnOp(box UnOp {
op: Minus,
operand: rhs,
}),
} => BinOp::new_element(Operator::Divide, lhs, rhs),
///////////////////////////// Powers ////////////////////////////
// 0 ^ 0 => 1 // special case
BinOp {
Expand Down

0 comments on commit acac3c1

Please sign in to comment.