opensrdk_symbolic_computation/expression/transcendental_expression/functions/
log.rs

1use std::collections::HashMap;
2
3use crate::{BracketsLevel, Expression, TranscendentalExpression};
4
5impl Expression {
6    pub fn log(self, antilogarithm: Expression) -> Self {
7        if let Expression::Constant(base) = &self {
8            if let Expression::Constant(antilogarithm) = antilogarithm {
9                return antilogarithm.into_scalar().log(base.into_scalar()).into();
10            }
11        }
12        if let Expression::Mul(l, r) = &self {
13            return l.as_ref().clone().log(antilogarithm.clone())
14                + r.as_ref().clone().log(antilogarithm);
15        }
16        if let Expression::Transcendental(v) = &self {
17            match v.as_ref() {
18                TranscendentalExpression::Pow(base, exponent) => {
19                    return exponent.as_ref().clone() * base.as_ref().clone().log(antilogarithm);
20                }
21                _ => {}
22            }
23        }
24
25        TranscendentalExpression::Log(self.into(), antilogarithm.into()).into()
26    }
27}
28
29impl TranscendentalExpression {
30    pub(crate) fn tex_code_log(
31        base: &Box<Expression>,
32        antilogarithm: &Box<Expression>,
33        symbols: &HashMap<&str, &str>,
34    ) -> String {
35        format!(
36            "\\log_{{{}}}{{{}}}",
37            base._tex_code(symbols, BracketsLevel::ForOperation),
38            antilogarithm._tex_code(symbols, BracketsLevel::ForOperation)
39        )
40    }
41}