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