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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//! Logarithmic Function Intelligence
//!
//! with verified derivatives, special values, and logarithm laws.
use crate::core::{Expression, Symbol};
use crate::functions::properties::*;
use std::collections::HashMap;
use std::sync::Arc;
/// Logarithmic Function Intelligence
///
/// Complete mathematical intelligence for logarithmic functions
pub struct LogarithmicIntelligence {
/// Function properties for logarithmic functions
properties: HashMap<String, FunctionProperties>,
}
impl Default for LogarithmicIntelligence {
fn default() -> Self {
Self::new()
}
}
impl LogarithmicIntelligence {
/// Create new logarithmic intelligence system
pub fn new() -> Self {
let mut intelligence = Self {
properties: HashMap::with_capacity(4),
};
intelligence.initialize_ln();
intelligence.initialize_log();
intelligence
}
/// Get all logarithmic function properties
pub fn get_properties(&self) -> HashMap<String, FunctionProperties> {
self.properties.clone()
}
/// Check if function is logarithmic
pub fn has_function(&self, name: &str) -> bool {
self.properties.contains_key(name)
}
/// Initialize natural logarithm
fn initialize_ln(&mut self) {
// Natural Logarithm ln(x)
self.properties.insert(
"ln".to_owned(),
FunctionProperties::Elementary(Box::new(ElementaryProperties {
// DERIVATIVE: d/dx ln(x) = 1/x (x > 0)
derivative_rule: Some(DerivativeRule {
rule_type: DerivativeRuleType::Custom {
builder: Arc::new(|arg: &Expression| {
Expression::pow(arg.clone(), Expression::integer(-1))
}),
},
result_template: "1/x".to_owned(),
}),
antiderivative_rule: Some(AntiderivativeRule {
rule_type: AntiderivativeRuleType::Custom {
builder: Arc::new(|var: Symbol| {
Expression::add(vec![
Expression::mul(vec![
Expression::symbol(var.clone()),
Expression::function(
"ln",
vec![Expression::symbol(var.clone())],
),
]),
Expression::mul(vec![
Expression::integer(-1),
Expression::symbol(var),
]),
])
}),
},
result_template: "∫ln(x)dx = x·ln(x) - x + C".to_owned(),
constant_handling: ConstantOfIntegration::AddConstant,
}),
// SPECIAL VALUES
special_values: vec![
// ln(1) = 0
SpecialValue {
input: "1".to_owned(),
output: Expression::integer(0),
latex_explanation: "\\ln(1) = 0".to_owned(),
},
// ln(e) = 1
SpecialValue {
input: "e".to_owned(),
output: Expression::integer(1),
latex_explanation: "\\ln(e) = 1".to_owned(),
},
],
// Logarithm Laws
identities: Box::new(vec![
// ln(xy) = ln(x) + ln(y)
MathIdentity {
name: "Logarithm Product Law".to_owned(),
lhs: Expression::function(
"ln",
vec![Expression::mul(vec![
Expression::symbol("x"),
Expression::symbol("y"),
])],
),
rhs: Expression::add(vec![
Expression::function("ln", vec![Expression::symbol("x")]),
Expression::function("ln", vec![Expression::symbol("y")]),
]),
conditions: vec!["x, y > 0".to_owned()],
},
]),
domain_range: Box::new(DomainRangeData {
domain: Domain::Interval(Expression::integer(0), Expression::symbol("∞")), // (0, ∞)
range: Range::Real, // (-∞, ∞)
singularities: vec![Expression::integer(0)], // Singularity at x = 0
}),
// No periodicity
periodicity: None,
wolfram_name: Some("Log"),
})),
);
}
/// Initialize base-10 logarithm
fn initialize_log(&mut self) {
self.properties.insert(
"log".to_owned(),
FunctionProperties::Elementary(Box::new(ElementaryProperties {
derivative_rule: Some(DerivativeRule {
rule_type: DerivativeRuleType::Custom {
builder: Arc::new(|arg: &Expression| {
Expression::mul(vec![
Expression::pow(arg.clone(), Expression::integer(-1)),
Expression::pow(
Expression::function("ln", vec![Expression::integer(10)]),
Expression::integer(-1),
),
])
}),
},
result_template: "1/(x·ln(10))".to_owned(),
}),
antiderivative_rule: Some(AntiderivativeRule {
rule_type: AntiderivativeRuleType::Custom {
builder: Arc::new(|var: Symbol| {
Expression::mul(vec![
Expression::pow(
Expression::function("ln", vec![Expression::integer(10)]),
Expression::integer(-1),
),
Expression::add(vec![
Expression::mul(vec![
Expression::symbol(var.clone()),
Expression::function(
"ln",
vec![Expression::symbol(var.clone())],
),
]),
Expression::mul(vec![
Expression::integer(-1),
Expression::symbol(var),
]),
]),
])
}),
},
result_template: "∫log(x)dx = (1/ln(10))·(x·ln(x) - x) + C".to_owned(),
constant_handling: ConstantOfIntegration::AddConstant,
}),
special_values: vec![
SpecialValue {
input: "1".to_owned(),
output: Expression::integer(0),
latex_explanation: "\\log(1) = 0".to_owned(),
},
SpecialValue {
input: "10".to_owned(),
output: Expression::integer(1),
latex_explanation: "\\log(10) = 1".to_owned(),
},
],
identities: Box::new(vec![]),
domain_range: Box::new(DomainRangeData {
domain: Domain::Interval(Expression::integer(0), Expression::symbol("∞")),
range: Range::Real,
singularities: vec![Expression::integer(0)],
}),
periodicity: None,
wolfram_name: Some("Log"),
})),
);
}
}