mathhook_core/functions/
number_theory.rs1use crate::core::Expression;
7use crate::expr;
8use crate::functions::properties::*;
9use std::collections::HashMap;
10
11pub struct NumberTheoryIntelligence {
16 properties: HashMap<String, FunctionProperties>,
18}
19
20impl Default for NumberTheoryIntelligence {
21 fn default() -> Self {
22 Self::new()
23 }
24}
25
26impl NumberTheoryIntelligence {
27 pub fn new() -> Self {
29 let mut intelligence = Self {
30 properties: HashMap::with_capacity(8),
31 };
32
33 intelligence.initialize_gcd_lcm();
34 intelligence.initialize_modular_arithmetic();
35 intelligence.initialize_prime_functions();
36
37 intelligence
38 }
39
40 pub fn get_all_properties(&self) -> HashMap<String, FunctionProperties> {
42 self.properties.clone()
43 }
44
45 pub fn has_intelligence(&self, name: &str) -> bool {
47 self.properties.contains_key(name)
48 }
49
50 fn initialize_gcd_lcm(&mut self) {
51 self.properties.insert(
52 "gcd".to_owned(),
53 FunctionProperties::Elementary(Box::new(ElementaryProperties {
54 derivative_rule: None, antiderivative_rule: None,
56 special_values: vec![SpecialValue {
57 input: "0".to_owned(),
58 output: expr!(b),
59 latex_explanation: "\\gcd(0, b) = |b|".to_owned(),
60 }],
61 identities: Box::new(vec![]),
62 domain_range: Box::new(DomainRangeData {
63 domain: Domain::Integer,
64 range: Range::PositiveInteger,
65 singularities: vec![],
66 }),
67 wolfram_name: None,
68 periodicity: None, })),
70 );
71
72 self.properties.insert(
74 "lcm".to_owned(),
75 FunctionProperties::Elementary(Box::new(ElementaryProperties {
76 derivative_rule: None, antiderivative_rule: None,
78 special_values: vec![SpecialValue {
79 input: "1".to_owned(),
80 output: expr!(b),
81 latex_explanation: "\\text{lcm}(1, b) = |b|".to_owned(),
82 }],
83 identities: Box::new(vec![]),
84 domain_range: Box::new(DomainRangeData {
85 domain: Domain::Integer,
86 range: Range::PositiveInteger,
87 singularities: vec![],
88 }),
89 wolfram_name: None,
90 periodicity: None, })),
92 );
93 }
94
95 fn initialize_modular_arithmetic(&mut self) {
97 self.properties.insert(
99 "mod".to_owned(),
100 FunctionProperties::Elementary(Box::new(ElementaryProperties {
101 derivative_rule: None,
102 antiderivative_rule: None,
103 special_values: vec![SpecialValue {
104 input: "0".to_owned(),
105 output: Expression::integer(0),
106 latex_explanation: "a \\bmod m = 0 \\text{ when } a = 0".to_owned(),
107 }],
108 identities: Box::new(vec![]),
109 domain_range: Box::new(DomainRangeData {
110 domain: Domain::Integer,
111 range: Range::Integer,
112 singularities: vec![],
113 }),
114 wolfram_name: None,
115 periodicity: None, })),
117 );
118 }
119
120 fn initialize_prime_functions(&mut self) {
122 self.properties.insert(
124 "is_prime".to_owned(),
125 FunctionProperties::Elementary(Box::new(ElementaryProperties {
126 derivative_rule: None,
127 antiderivative_rule: None,
128 special_values: vec![SpecialValue {
129 input: "2".to_owned(),
130 output: Expression::integer(1), latex_explanation: "2 \\text{ is prime}".to_owned(),
132 }],
133 identities: Box::new(vec![]),
134 domain_range: Box::new(DomainRangeData {
135 domain: Domain::PositiveInteger,
136 range: Range::Integer,
137 singularities: vec![],
138 }),
139 wolfram_name: None,
140 periodicity: None, })),
142 );
143 }
144}