Educational API
The Educational API provides programmatic access to MathHook's educational features for external applications. Integrate step-by-step explanations, assessment tools, and adaptive learning systems into Learning Management Systems (LMS), mobile apps, and educational platforms.
Code Examples
Basic Dual-Format Output
Generate both human and machine-readable educational content
let x = symbol!(x);
let equation = expr!(2*x + 3);
// Get enhanced explanation
let explanation = EnhancedStepExplanation::new(steps);
// Display for students
for step in &explanation.steps {
println!("{}", step.human_message);
}
// Export structured data
let json = explanation.to_json()?;
// Parse in external application
let data: serde_json::Value = serde_json::from_str(&json)?;
SmartStepFactory Context-Aware Generation
Generate educational steps based on operation context and difficulty
// Generate introduction step for linear equation
let intro_step = EnhancedStepBuilder::new("step_1")
.with_human_message(
"Identify Equation Type",
"We have a linear equation in one variable"
)
.with_api_data("linear_equation", "identification", "classify")
.with_input("equation", "2x + 3 = 0")
.with_input("variable", "x")
.with_output("equation_type", "linear")
.with_output("degree", "1")
.with_math_context("2x + 3 = 0", "x", 0.25)
.with_message_key("linear_equation", "introduction", 0)
.build();
Educational Operation Trait Implementation
Add educational capabilities to mathematical operations
struct LinearEquationSolver {
equation: Expression,
variable: Symbol,
}
impl EducationalOperation for LinearEquationSolver {
type Output = Vec<Expression>;
fn execute_with_steps(&self) -> (Self::Output, StepByStepExplanation) {
let mut steps = Vec::new();
// Step 1: Identify equation type
steps.push(Step::new(
"Identify Equation Type",
"This is a linear equation ax + b = 0"
));
// Step 2: Isolate variable term
steps.push(Step::new(
"Isolate Variable Term",
"Subtract constant from both sides"
));
// Step 3: Solve for variable
steps.push(Step::new(
"Solve for Variable",
"Divide both sides by coefficient"
));
// Perform actual solving
let solution = self.solve_internal();
let explanation = StepByStepExplanation::new(steps);
(solution, explanation)
}
fn educational_context(&self) -> OperationContext {
OperationContext::equation_solving(3) // difficulty level 3
}
fn execute_fast(&self) -> Self::Output {
// Optimized path without explanation generation
self.solve_internal()
}
fn estimated_steps(&self) -> Option<usize> {
Some(3) // Known step count for linear equations
}
}
LMS Integration with Progress Tracking
Export educational content to Learning Management System
// Generate explanation
let explanation = EnhancedStepExplanation::new(steps);
// Export to JSON
let json = explanation.to_json()?;
// Send to LMS via REST API
let client = reqwest::Client::new();
let response = client
.post("https://lms.example.com/api/lessons")
.json(&serde_json::from_str::<serde_json::Value>(&json)?)
.send()
.await?;
// Track which steps student has viewed
for step in &explanation.steps {
lms_api.mark_step_viewed(
student_id,
lesson_id,
&step.step_id
).await?;
}
Assessment and Verification
Verify student answers and provide feedback
// Verify student's answer against expected solution
fn verify_answer(
student_answer: &str,
expected_solution: &Expression,
variable: &Symbol
) -> VerificationResult {
let student_expr = parse_latex(student_answer)?;
// Substitute student's answer into original equation
let substituted = original_equation.substitute(variable, &student_expr);
let simplified = substituted.simplify();
VerificationResult {
correct: simplified == Expression::integer(0),
student_expression: student_expr,
substituted_form: substituted,
explanation: generate_verification_explanation(&simplified),
}
}