mathhook_core/educational/message_registry/
noncommutative.rs

1//! Noncommutative algebra educational messages
2//!
3//! Provides messages explaining left/right division, order dependence,
4//! and commutativity concepts for matrix, operator, and quaternion algebra.
5
6use super::core::{MessageCategory, MessageKey, MessageTemplate, MessageType};
7use std::collections::HashMap;
8
9/// Initialize all noncommutative algebra messages
10pub fn initialize_noncommutative_messages(registry: &mut HashMap<MessageKey, MessageTemplate>) {
11    initialize_left_division_messages(registry);
12    initialize_right_division_messages(registry);
13    initialize_commutativity_messages(registry);
14    initialize_order_messages(registry);
15}
16
17/// Initialize left division messages
18fn initialize_left_division_messages(registry: &mut HashMap<MessageKey, MessageTemplate>) {
19    registry.insert(
20        MessageKey::new(
21            MessageCategory::NoncommutativeAlgebra,
22            MessageType::LeftMultiplyInverse,
23            0,
24        ),
25        MessageTemplate::new(
26            "Left Multiplication by Inverse",
27            "Multiply both sides on the LEFT by {inverse}\nFor equation {equation}, we get: {inverse}*({lhs}) = {inverse}*({rhs})",
28            &["inverse", "equation", "lhs", "rhs"],
29        ),
30    );
31
32    registry.insert(
33        MessageKey::new(
34            MessageCategory::NoncommutativeAlgebra,
35            MessageType::LeftMultiplyInverse,
36            1,
37        ),
38        MessageTemplate::new(
39            "Left Division Explanation",
40            "For equation {A}*{X} = {B}, multiply LEFT by {A_inv}\nReason: {X} is on the RIGHT of {A}, so we multiply on the LEFT to isolate {X}",
41            &["A", "X", "B", "A_inv"],
42        ),
43    );
44
45    registry.insert(
46        MessageKey::new(
47            MessageCategory::NoncommutativeAlgebra,
48            MessageType::LeftMultiplyInverse,
49            2,
50        ),
51        MessageTemplate::new(
52            "Left Division Step",
53            "Step: {A_inv}*({A}*{X}) = {A_inv}*{B}\nUse associativity: ({A_inv}*{A})*{X} = {A_inv}*{B}\nSince {A_inv}*{A} = I (identity): I*{X} = {A_inv}*{B}\nSolution: {X} = {A_inv}*{B}",
54            &["A", "X", "B", "A_inv"],
55        ),
56    );
57
58    registry.insert(
59        MessageKey::new(
60            MessageCategory::NoncommutativeAlgebra,
61            MessageType::LeftMultiplyInverse,
62            3,
63        ),
64        MessageTemplate::new(
65            "Left Division Educational Note",
66            "Why multiply on the LEFT?\nIn {A}*{X} = {B}, the variable {X} appears on the RIGHT of {A}.\nFor noncommutative objects, {A_inv}*{B} is NOT equal to {B}*{A_inv}.\nTherefore, we must multiply on the LEFT to preserve equation validity.",
67            &["A", "X", "B", "A_inv"],
68        ),
69    );
70}
71
72/// Initialize right division messages
73fn initialize_right_division_messages(registry: &mut HashMap<MessageKey, MessageTemplate>) {
74    registry.insert(
75        MessageKey::new(
76            MessageCategory::NoncommutativeAlgebra,
77            MessageType::RightMultiplyInverse,
78            0,
79        ),
80        MessageTemplate::new(
81            "Right Multiplication by Inverse",
82            "Multiply both sides on the RIGHT by {inverse}\nFor equation {equation}, we get: ({lhs})*{inverse} = ({rhs})*{inverse}",
83            &["inverse", "equation", "lhs", "rhs"],
84        ),
85    );
86
87    registry.insert(
88        MessageKey::new(
89            MessageCategory::NoncommutativeAlgebra,
90            MessageType::RightMultiplyInverse,
91            1,
92        ),
93        MessageTemplate::new(
94            "Right Division Explanation",
95            "For equation {X}*{A} = {B}, multiply RIGHT by {A_inv}\nReason: {X} is on the LEFT of {A}, so we multiply on the RIGHT to isolate {X}",
96            &["X", "A", "B", "A_inv"],
97        ),
98    );
99
100    registry.insert(
101        MessageKey::new(
102            MessageCategory::NoncommutativeAlgebra,
103            MessageType::RightMultiplyInverse,
104            2,
105        ),
106        MessageTemplate::new(
107            "Right Division Step",
108            "Step: ({X}*{A})*{A_inv} = {B}*{A_inv}\nUse associativity: {X}*({A}*{A_inv}) = {B}*{A_inv}\nSince {A}*{A_inv} = I (identity): {X}*I = {B}*{A_inv}\nSolution: {X} = {B}*{A_inv}",
109            &["X", "A", "B", "A_inv"],
110        ),
111    );
112
113    registry.insert(
114        MessageKey::new(
115            MessageCategory::NoncommutativeAlgebra,
116            MessageType::RightMultiplyInverse,
117            3,
118        ),
119        MessageTemplate::new(
120            "Right Division Educational Note",
121            "Why multiply on the RIGHT?\nIn {X}*{A} = {B}, the variable {X} appears on the LEFT of {A}.\nFor noncommutative objects, {B}*{A_inv} is NOT equal to {A_inv}*{B}.\nTherefore, we must multiply on the RIGHT to preserve equation validity.",
122            &["X", "A", "B", "A_inv"],
123        ),
124    );
125}
126
127/// Initialize commutativity explanation messages
128fn initialize_commutativity_messages(registry: &mut HashMap<MessageKey, MessageTemplate>) {
129    registry.insert(
130        MessageKey::new(
131            MessageCategory::NoncommutativeAlgebra,
132            MessageType::NoncommutativeWarning,
133            0,
134        ),
135        MessageTemplate::new(
136            "Noncommutative Object Warning",
137            "WARNING: {symbol} is noncommutative (type: {symbol_type})\nThis means the order of multiplication matters: {symbol}*{other} may NOT equal {other}*{symbol}",
138            &["symbol", "symbol_type", "other"],
139        ),
140    );
141
142    registry.insert(
143        MessageKey::new(
144            MessageCategory::NoncommutativeAlgebra,
145            MessageType::NoncommutativeWarning,
146            1,
147        ),
148        MessageTemplate::new(
149            "Matrix Noncommutativity",
150            "Matrices are noncommutative: A*B is generally NOT equal to B*A\nExample: For 2x2 matrices, A*B and B*A often give different results.\nAlways preserve multiplication order in matrix equations.",
151            &[],
152        ),
153    );
154
155    registry.insert(
156        MessageKey::new(
157            MessageCategory::NoncommutativeAlgebra,
158            MessageType::NoncommutativeWarning,
159            2,
160        ),
161        MessageTemplate::new(
162            "Operator Noncommutativity",
163            "Quantum operators are noncommutative: operators do not commute in general\nExample: Position and momentum operators satisfy [x,p] = xp - px = i*hbar (Heisenberg uncertainty)\nOrder matters critically in quantum mechanics.",
164            &[],
165        ),
166    );
167
168    registry.insert(
169        MessageKey::new(
170            MessageCategory::NoncommutativeAlgebra,
171            MessageType::NoncommutativeWarning,
172            3,
173        ),
174        MessageTemplate::new(
175            "Quaternion Noncommutativity",
176            "Quaternions are noncommutative: ij is NOT equal to ji\nExample: i*j = k, but j*i = -k (opposite sign)\nQuaternion multiplication follows strict order rules.",
177            &[],
178        ),
179    );
180
181    registry.insert(
182        MessageKey::new(
183            MessageCategory::NoncommutativeAlgebra,
184            MessageType::CommutatorExplanation,
185            0,
186        ),
187        MessageTemplate::new(
188            "Commutator Definition",
189            "The commutator [{A},{B}] = {A}*{B} - {B}*{A} measures how much {A} and {B} fail to commute.\nIf [{A},{B}] = 0, then {A} and {B} commute (order doesn't matter).\nIf [{A},{B}] is not 0, then order matters.",
190            &["A", "B"],
191        ),
192    );
193
194    registry.insert(
195        MessageKey::new(
196            MessageCategory::NoncommutativeAlgebra,
197            MessageType::CommutatorExplanation,
198            1,
199        ),
200        MessageTemplate::new(
201            "Commutator Significance",
202            "Commutators reveal fundamental properties:\nIn quantum mechanics, [{position},{momentum}] = i*hbar (uncertainty principle)\nIn matrix algebra, commutators determine if matrices can be simultaneously diagonalized\nCommutators are central to Lie algebra theory.",
203            &[],
204        ),
205    );
206}
207
208/// Initialize order-matters messages
209fn initialize_order_messages(registry: &mut HashMap<MessageKey, MessageTemplate>) {
210    registry.insert(
211        MessageKey::new(
212            MessageCategory::NoncommutativeAlgebra,
213            MessageType::OrderMatters,
214            0,
215        ),
216        MessageTemplate::new(
217            "Order Matters",
218            "Order matters because {symbol} is {symbol_type}\nIn noncommutative algebra: {A}*{B} is generally NOT equal to {B}*{A}\nAlways preserve the exact order of multiplication.",
219            &["symbol", "symbol_type", "A", "B"],
220        ),
221    );
222
223    registry.insert(
224        MessageKey::new(
225            MessageCategory::NoncommutativeAlgebra,
226            MessageType::OrderMatters,
227            1,
228        ),
229        MessageTemplate::new(
230            "Left vs Right Division Choice",
231            "Choosing left or right division:\n- If variable appears as {A}*{X}, use LEFT division by {A_inv}\n- If variable appears as {X}*{A}, use RIGHT division by {A_inv}\nThe position of the variable determines the multiplication side.",
232            &["A", "X", "A_inv"],
233        ),
234    );
235
236    registry.insert(
237        MessageKey::new(
238            MessageCategory::NoncommutativeAlgebra,
239            MessageType::OrderMatters,
240            2,
241        ),
242        MessageTemplate::new(
243            "Associativity Still Valid",
244            "Important: While order matters, associativity still holds:\n({A}*{B})*{C} = {A}*({B}*{C})\nThis allows us to use parentheses to regroup (but not reorder) multiplications.\nAssociativity is the key to solving matrix equations.",
245            &["A", "B", "C"],
246        ),
247    );
248
249    registry.insert(
250        MessageKey::new(
251            MessageCategory::NoncommutativeAlgebra,
252            MessageType::OrderMatters,
253            3,
254        ),
255        MessageTemplate::new(
256            "Common Errors to Avoid",
257            "Common mistakes in noncommutative algebra:\n1. Swapping order: {A}*{B} to {B}*{A} (WRONG)\n2. Distributing incorrectly: ({A}+{B})*{C} is NOT {A}*{C}+{C}*{B}\n3. Canceling carelessly: {A}*{X}*{B} = {A}*{Y}*{B} does NOT imply {X} = {Y}\nAlways respect order constraints.",
258            &["A", "B", "C", "X", "Y"],
259        ),
260    );
261}