pub fn collect_like_muls(self) -> Expression {
        match self {
            Expression::Variadic(Operator::Mul, exprs) => {
                let exprs = exprs
                    .into_iter()
                    .map(Expression::collect_like_muls)
                    .filter_map(|expr| match expr {
                        Expression::Binary(Operator::Exp, base, pow) => Some((base, pow)),
                        _ => None,
                    })
                    .collect();
                let grouped = group_similar_by(exprs, |(base_a, _), (base_b, _)| base_a == base_b)
                    .into_iter()
                    .filter_map(|vec| match vec.first().cloned() {
                        Some((base, _)) => Some(Expression::Binary(
                            Operator::Exp,
                            base,
                            Box::new(Expression::Variadic(
                                Operator::Add,
                                vec.into_iter().map(|(_, b)| *b).collect(),
                            )),
                        )),
                        None => None,
                    })
                    .collect();
                Expression::Variadic(Operator::Mul, grouped)
            }
            other => other.apply_on_others(Expression::collect_like_muls),
        }
    }
//Groups exponents with the same base
Groups exponents with the same base
Groups exponents with the same base
pub fn collect_like_muls(self) -> Expression {
        match self {
            Expression::Variadic(Operator::Mul, exprs) => {
                let exprs = exprs
                    .into_iter()
                    .map(Expression::collect_like_muls)
                    .filter_map(|expr| match expr {
                        Expression::Binary(Operator::Exp, base, pow) => Some((base, pow)),
                        _ => None,
                    })
                    .collect();
                let grouped = group_similar_by(exprs, |(base_a, _), (base_b, _)| base_a == base_b)
                    .into_iter()
                    .filter_map(|vec| match vec.first().cloned() {
                        Some((base, _)) => Some(Expression::Binary(
                            Operator::Exp,
                            base,
                            Box::new(Expression::Variadic(
                                Operator::Add,
                                vec.into_iter().map(|(_, b)| *b).collect(),
                            )),
                        )),
                        None => None,
                    })
                    .collect();
                Expression::Variadic(Operator::Mul, grouped)
            }
            other => other.apply_on_others(Expression::collect_like_muls),
        }
    }
pub fn collect_like_muls ( self ) -> Expression { match self { Expression :: Variadic ( Operator :: Mul , exprs ) => { let exprs = exprs . into_iter ( ) . map ( Expression :: collect_like_muls ) . filter_map ( | expr | match expr { Expression :: Binary ( Operator :: Exp , base , pow ) => Some ( ( base , pow ) ) , _ => None , } ) . collect ( ) ; let grouped = group_similar_by ( exprs , | ( base_a , _ ) , ( base_b , _ ) | base_a == base_b ) . into_iter ( ) . filter_map ( | vec | match vec . first ( ) . cloned ( ) { Some ( ( base , _ ) ) => Some ( Expression :: Binary ( Operator :: Exp , base , Box :: new ( Expression :: Variadic ( Operator :: Add , vec . into_iter ( ) . map ( | ( _ , b ) | * b ) . collect ( ) , ) ) , ) ) , None => None , } ) . collect ( ) ; Expression :: Variadic ( Operator :: Mul , grouped ) } other => other . apply_on_others ( Expression :: collect_like_muls ) , } }
Groups exponents with the same base
Groups exponents with the same base
self
self