Update explainers/explainer_algebra.py
Browse files- explainers/explainer_algebra.py +99 -24
explainers/explainer_algebra.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
from .explainer_types import ExplainerResult, ExplainerScaffold
|
| 3 |
|
|
@@ -49,7 +51,10 @@ def explain_algebra_question(text: str):
|
|
| 49 |
result = ExplainerResult(
|
| 50 |
understood=True,
|
| 51 |
topic="algebra",
|
| 52 |
-
summary=
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
scaffold = ExplainerScaffold(
|
|
@@ -57,135 +62,203 @@ def explain_algebra_question(text: str):
|
|
| 57 |
ask="Identify the unknown, identify the governing relationship, and check whether the question wants the variable itself or an expression built from it.",
|
| 58 |
target="Set up the simplest correct equation or relation before manipulating it.",
|
| 59 |
answer_hidden=True,
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
teaching_points = [
|
| 63 |
"Most algebra errors happen before the solving starts: either the variable is misdefined, or the equation is set up incorrectly.",
|
| 64 |
"A clean equation makes the solving steps much easier.",
|
| 65 |
-
"You should always check whether the question asks for x itself or for something derived from x."
|
| 66 |
]
|
| 67 |
|
| 68 |
if subtype == "linear_equation":
|
| 69 |
scaffold.setup_actions = [
|
| 70 |
"Identify the unknown and write the equation cleanly.",
|
| 71 |
"Simplify each side if needed.",
|
| 72 |
-
"Undo operations in a logical order to isolate the variable."
|
| 73 |
]
|
| 74 |
scaffold.intermediate_steps = [
|
| 75 |
"Combine like terms first when possible.",
|
| 76 |
"Move variable terms and constant terms carefully.",
|
| 77 |
-
"Check whether the final result should be the variable or a substituted expression."
|
| 78 |
]
|
| 79 |
scaffold.first_move = "Rewrite the relationship as one clean equation if it is not already in that form."
|
| 80 |
scaffold.next_hint = "Simplify both sides before isolating the variable."
|
| 81 |
scaffold.variables_to_define = [
|
| 82 |
-
"Let the unknown quantity be x if the question has not already named it."
|
| 83 |
]
|
| 84 |
scaffold.equations_to_form = [
|
| 85 |
-
"Build one equation from the stated relationship."
|
| 86 |
]
|
| 87 |
scaffold.common_traps = [
|
| 88 |
"Moving terms across the equals sign incorrectly.",
|
| 89 |
"Trying to isolate the variable before simplifying.",
|
| 90 |
-
"Finding x and forgetting the question asks for something like 2x or x + 3."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
]
|
| 92 |
|
| 93 |
elif subtype == "system":
|
| 94 |
scaffold.setup_actions = [
|
| 95 |
"Identify the separate equations and unknowns.",
|
| 96 |
"Decide whether substitution or elimination is the cleaner method.",
|
| 97 |
-
"Reduce the system to one variable before solving completely."
|
| 98 |
]
|
| 99 |
scaffold.intermediate_steps = [
|
| 100 |
"Make one variable easy to substitute, or align coefficients for elimination.",
|
| 101 |
"After finding one variable, substitute back carefully.",
|
| 102 |
-
"Check whether the question asks for one variable, both variables, or a combination of them."
|
| 103 |
]
|
| 104 |
scaffold.first_move = "Choose one variable to eliminate or substitute."
|
| 105 |
scaffold.next_hint = "Turn the system into a single-variable equation before solving."
|
| 106 |
scaffold.equations_to_form = [
|
| 107 |
-
"Use the two given equations together to reduce to one unknown."
|
| 108 |
]
|
| 109 |
scaffold.common_traps = [
|
| 110 |
"Mixing substitution and elimination without a clear plan.",
|
| 111 |
"Arithmetic mistakes when substituting back.",
|
| 112 |
-
"Stopping after finding one variable when the question asks for something else."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
]
|
| 114 |
|
| 115 |
elif subtype == "inequality":
|
| 116 |
scaffold.setup_actions = [
|
| 117 |
"Translate the condition into an inequality.",
|
| 118 |
"Manipulate it like an equation, but track the inequality direction carefully.",
|
| 119 |
-
"Reverse the sign only if multiplying or dividing by a negative number."
|
| 120 |
]
|
| 121 |
scaffold.intermediate_steps = [
|
| 122 |
"Simplify both sides first if possible.",
|
| 123 |
"Isolate the variable systematically.",
|
| 124 |
-
"Interpret the final solution set in the form the question wants."
|
| 125 |
]
|
| 126 |
scaffold.first_move = "Set up the inequality carefully from the wording."
|
| 127 |
scaffold.next_hint = "Solve it step by step, watching for any operation that would reverse the sign."
|
| 128 |
scaffold.common_traps = [
|
| 129 |
"Forgetting to reverse the inequality when dividing or multiplying by a negative.",
|
| 130 |
"Treating phrase-based conditions like at least or no more than incorrectly.",
|
| 131 |
-
"Reporting a single number when the solution is actually a range."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
]
|
| 133 |
|
| 134 |
elif subtype == "quadratic":
|
| 135 |
scaffold.setup_actions = [
|
| 136 |
"Rewrite the equation so one side is zero if needed.",
|
| 137 |
"Look for factoring, structure, or another simplifying method.",
|
| 138 |
-
"Treat each factor or case carefully once the equation is structured properly."
|
| 139 |
]
|
| 140 |
scaffold.intermediate_steps = [
|
| 141 |
"Factor if the form allows it.",
|
| 142 |
"Otherwise identify another clean solving route.",
|
| 143 |
-
"Check whether all resulting values are allowed in the original context."
|
| 144 |
]
|
| 145 |
scaffold.first_move = "Put the expression into a standard structured form before solving."
|
| 146 |
scaffold.next_hint = "Then look for a factorable pattern or another clean route."
|
| 147 |
scaffold.common_traps = [
|
| 148 |
"Trying to factor before the expression is fully simplified.",
|
| 149 |
"Dropping one valid case.",
|
| 150 |
-
"Giving roots when the question asks for a derived expression instead."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
]
|
| 152 |
|
| 153 |
elif subtype == "expression_evaluation":
|
| 154 |
scaffold.setup_actions = [
|
| 155 |
"Find the variable or relationship first.",
|
| 156 |
"Only then substitute into the requested expression.",
|
| 157 |
-
"Simplify the final expression carefully."
|
| 158 |
]
|
| 159 |
scaffold.intermediate_steps = [
|
| 160 |
"Do not stop when you find the variable unless that is exactly what the question asks.",
|
| 161 |
"Preserve parentheses during substitution.",
|
| 162 |
-
"Check whether there is a shortcut using the given relationship directly."
|
| 163 |
]
|
| 164 |
scaffold.first_move = "Work out whether you need to solve for the variable first or can rewrite the target expression directly."
|
| 165 |
scaffold.next_hint = "Once the relationship is clear, substitute only into the exact expression the question asks for."
|
| 166 |
scaffold.common_traps = [
|
| 167 |
"Stopping at x when the question asks for something built from x.",
|
| 168 |
"Substituting incorrectly into expressions with multiple terms.",
|
| 169 |
-
"Ignoring an easier algebraic simplification path."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
]
|
| 171 |
|
| 172 |
else:
|
| 173 |
scaffold.setup_actions = [
|
| 174 |
"Define the unknown clearly.",
|
| 175 |
"Translate the wording into a symbolic relationship.",
|
| 176 |
-
"Manipulate the relationship only after the setup is clean."
|
| 177 |
]
|
| 178 |
scaffold.intermediate_steps = [
|
| 179 |
"Simplify before isolating.",
|
| 180 |
"Keep track of what the question actually asks for.",
|
| 181 |
-
"Check the final quantity against the prompt."
|
| 182 |
]
|
| 183 |
scaffold.first_move = "Start by translating the words into one clean symbolic statement."
|
| 184 |
scaffold.next_hint = "Then simplify the structure before solving."
|
| 185 |
scaffold.common_traps = [
|
| 186 |
"Poor variable definition.",
|
| 187 |
"Messy setup before solving.",
|
| 188 |
-
"Answering the wrong final quantity."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
]
|
| 190 |
|
| 191 |
result.teaching_points = teaching_points
|
|
@@ -193,7 +266,9 @@ def explain_algebra_question(text: str):
|
|
| 193 |
result.meta = {
|
| 194 |
"intent": "explain_question",
|
| 195 |
"bridge_ready": True,
|
| 196 |
-
"hint_style": "
|
| 197 |
"subtype": subtype,
|
|
|
|
|
|
|
| 198 |
}
|
| 199 |
return result
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
import re
|
| 4 |
from .explainer_types import ExplainerResult, ExplainerScaffold
|
| 5 |
|
|
|
|
| 51 |
result = ExplainerResult(
|
| 52 |
understood=True,
|
| 53 |
topic="algebra",
|
| 54 |
+
summary=(
|
| 55 |
+
"This is an algebra problem. The main goal is to translate the wording into a clean "
|
| 56 |
+
"symbolic relationship and isolate the requested quantity step by step."
|
| 57 |
+
),
|
| 58 |
)
|
| 59 |
|
| 60 |
scaffold = ExplainerScaffold(
|
|
|
|
| 62 |
ask="Identify the unknown, identify the governing relationship, and check whether the question wants the variable itself or an expression built from it.",
|
| 63 |
target="Set up the simplest correct equation or relation before manipulating it.",
|
| 64 |
answer_hidden=True,
|
| 65 |
+
solution_path_type=subtype,
|
| 66 |
+
reveal_threshold=3,
|
| 67 |
)
|
| 68 |
|
| 69 |
teaching_points = [
|
| 70 |
"Most algebra errors happen before the solving starts: either the variable is misdefined, or the equation is set up incorrectly.",
|
| 71 |
"A clean equation makes the solving steps much easier.",
|
| 72 |
+
"You should always check whether the question asks for x itself or for something derived from x.",
|
| 73 |
]
|
| 74 |
|
| 75 |
if subtype == "linear_equation":
|
| 76 |
scaffold.setup_actions = [
|
| 77 |
"Identify the unknown and write the equation cleanly.",
|
| 78 |
"Simplify each side if needed.",
|
| 79 |
+
"Undo operations in a logical order to isolate the variable.",
|
| 80 |
]
|
| 81 |
scaffold.intermediate_steps = [
|
| 82 |
"Combine like terms first when possible.",
|
| 83 |
"Move variable terms and constant terms carefully.",
|
| 84 |
+
"Check whether the final result should be the variable or a substituted expression.",
|
| 85 |
]
|
| 86 |
scaffold.first_move = "Rewrite the relationship as one clean equation if it is not already in that form."
|
| 87 |
scaffold.next_hint = "Simplify both sides before isolating the variable."
|
| 88 |
scaffold.variables_to_define = [
|
| 89 |
+
"Let the unknown quantity be x if the question has not already named it.",
|
| 90 |
]
|
| 91 |
scaffold.equations_to_form = [
|
| 92 |
+
"Build one equation from the stated relationship.",
|
| 93 |
]
|
| 94 |
scaffold.common_traps = [
|
| 95 |
"Moving terms across the equals sign incorrectly.",
|
| 96 |
"Trying to isolate the variable before simplifying.",
|
| 97 |
+
"Finding x and forgetting the question asks for something like 2x or x + 3.",
|
| 98 |
+
]
|
| 99 |
+
scaffold.key_operations = [
|
| 100 |
+
"rewrite as equation",
|
| 101 |
+
"simplify both sides",
|
| 102 |
+
"use inverse operations",
|
| 103 |
+
]
|
| 104 |
+
scaffold.hint_ladder = [
|
| 105 |
+
"Start by spotting the equation you need to work with.",
|
| 106 |
+
"Simplify both sides before you try to isolate the variable.",
|
| 107 |
+
"Undo the operation attached to the variable on both sides.",
|
| 108 |
+
"Keep simplifying until only the variable remains.",
|
| 109 |
]
|
| 110 |
|
| 111 |
elif subtype == "system":
|
| 112 |
scaffold.setup_actions = [
|
| 113 |
"Identify the separate equations and unknowns.",
|
| 114 |
"Decide whether substitution or elimination is the cleaner method.",
|
| 115 |
+
"Reduce the system to one variable before solving completely.",
|
| 116 |
]
|
| 117 |
scaffold.intermediate_steps = [
|
| 118 |
"Make one variable easy to substitute, or align coefficients for elimination.",
|
| 119 |
"After finding one variable, substitute back carefully.",
|
| 120 |
+
"Check whether the question asks for one variable, both variables, or a combination of them.",
|
| 121 |
]
|
| 122 |
scaffold.first_move = "Choose one variable to eliminate or substitute."
|
| 123 |
scaffold.next_hint = "Turn the system into a single-variable equation before solving."
|
| 124 |
scaffold.equations_to_form = [
|
| 125 |
+
"Use the two given equations together to reduce to one unknown.",
|
| 126 |
]
|
| 127 |
scaffold.common_traps = [
|
| 128 |
"Mixing substitution and elimination without a clear plan.",
|
| 129 |
"Arithmetic mistakes when substituting back.",
|
| 130 |
+
"Stopping after finding one variable when the question asks for something else.",
|
| 131 |
+
]
|
| 132 |
+
scaffold.key_operations = [
|
| 133 |
+
"choose elimination or substitution",
|
| 134 |
+
"reduce to one variable",
|
| 135 |
+
"substitute back",
|
| 136 |
+
]
|
| 137 |
+
scaffold.hint_ladder = [
|
| 138 |
+
"Pick the variable that looks easiest to remove.",
|
| 139 |
+
"Use substitution or elimination to make a one-variable equation.",
|
| 140 |
+
"Solve that reduced equation first.",
|
| 141 |
+
"Then substitute back into the other equation.",
|
| 142 |
]
|
| 143 |
|
| 144 |
elif subtype == "inequality":
|
| 145 |
scaffold.setup_actions = [
|
| 146 |
"Translate the condition into an inequality.",
|
| 147 |
"Manipulate it like an equation, but track the inequality direction carefully.",
|
| 148 |
+
"Reverse the sign only if multiplying or dividing by a negative number.",
|
| 149 |
]
|
| 150 |
scaffold.intermediate_steps = [
|
| 151 |
"Simplify both sides first if possible.",
|
| 152 |
"Isolate the variable systematically.",
|
| 153 |
+
"Interpret the final solution set in the form the question wants.",
|
| 154 |
]
|
| 155 |
scaffold.first_move = "Set up the inequality carefully from the wording."
|
| 156 |
scaffold.next_hint = "Solve it step by step, watching for any operation that would reverse the sign."
|
| 157 |
scaffold.common_traps = [
|
| 158 |
"Forgetting to reverse the inequality when dividing or multiplying by a negative.",
|
| 159 |
"Treating phrase-based conditions like at least or no more than incorrectly.",
|
| 160 |
+
"Reporting a single number when the solution is actually a range.",
|
| 161 |
+
]
|
| 162 |
+
scaffold.key_operations = [
|
| 163 |
+
"translate wording",
|
| 164 |
+
"simplify",
|
| 165 |
+
"track sign reversal",
|
| 166 |
+
]
|
| 167 |
+
scaffold.hint_ladder = [
|
| 168 |
+
"Translate the words into an inequality first.",
|
| 169 |
+
"Simplify before isolating the variable.",
|
| 170 |
+
"Watch carefully for multiplication or division by a negative.",
|
| 171 |
+
"Express the result as the correct range or set.",
|
| 172 |
]
|
| 173 |
|
| 174 |
elif subtype == "quadratic":
|
| 175 |
scaffold.setup_actions = [
|
| 176 |
"Rewrite the equation so one side is zero if needed.",
|
| 177 |
"Look for factoring, structure, or another simplifying method.",
|
| 178 |
+
"Treat each factor or case carefully once the equation is structured properly.",
|
| 179 |
]
|
| 180 |
scaffold.intermediate_steps = [
|
| 181 |
"Factor if the form allows it.",
|
| 182 |
"Otherwise identify another clean solving route.",
|
| 183 |
+
"Check whether all resulting values are allowed in the original context.",
|
| 184 |
]
|
| 185 |
scaffold.first_move = "Put the expression into a standard structured form before solving."
|
| 186 |
scaffold.next_hint = "Then look for a factorable pattern or another clean route."
|
| 187 |
scaffold.common_traps = [
|
| 188 |
"Trying to factor before the expression is fully simplified.",
|
| 189 |
"Dropping one valid case.",
|
| 190 |
+
"Giving roots when the question asks for a derived expression instead.",
|
| 191 |
+
]
|
| 192 |
+
scaffold.key_operations = [
|
| 193 |
+
"rewrite to zero",
|
| 194 |
+
"factor or restructure",
|
| 195 |
+
"check cases",
|
| 196 |
+
]
|
| 197 |
+
scaffold.hint_ladder = [
|
| 198 |
+
"Rewrite the equation in a standard form first.",
|
| 199 |
+
"Look for a common factor or factorable pattern.",
|
| 200 |
+
"Use the structure to split into cases or solve the quadratic.",
|
| 201 |
+
"Check whether all resulting values fit the original problem.",
|
| 202 |
]
|
| 203 |
|
| 204 |
elif subtype == "expression_evaluation":
|
| 205 |
scaffold.setup_actions = [
|
| 206 |
"Find the variable or relationship first.",
|
| 207 |
"Only then substitute into the requested expression.",
|
| 208 |
+
"Simplify the final expression carefully.",
|
| 209 |
]
|
| 210 |
scaffold.intermediate_steps = [
|
| 211 |
"Do not stop when you find the variable unless that is exactly what the question asks.",
|
| 212 |
"Preserve parentheses during substitution.",
|
| 213 |
+
"Check whether there is a shortcut using the given relationship directly.",
|
| 214 |
]
|
| 215 |
scaffold.first_move = "Work out whether you need to solve for the variable first or can rewrite the target expression directly."
|
| 216 |
scaffold.next_hint = "Once the relationship is clear, substitute only into the exact expression the question asks for."
|
| 217 |
scaffold.common_traps = [
|
| 218 |
"Stopping at x when the question asks for something built from x.",
|
| 219 |
"Substituting incorrectly into expressions with multiple terms.",
|
| 220 |
+
"Ignoring an easier algebraic simplification path.",
|
| 221 |
+
]
|
| 222 |
+
scaffold.key_operations = [
|
| 223 |
+
"solve or rewrite relationship",
|
| 224 |
+
"substitute into target expression",
|
| 225 |
+
"simplify target",
|
| 226 |
+
]
|
| 227 |
+
scaffold.hint_ladder = [
|
| 228 |
+
"Check whether the question wants x or something built from x.",
|
| 229 |
+
"Use the given relationship to find or rewrite the target expression.",
|
| 230 |
+
"Substitute only into the exact expression asked for.",
|
| 231 |
+
"Simplify the resulting expression carefully.",
|
| 232 |
]
|
| 233 |
|
| 234 |
else:
|
| 235 |
scaffold.setup_actions = [
|
| 236 |
"Define the unknown clearly.",
|
| 237 |
"Translate the wording into a symbolic relationship.",
|
| 238 |
+
"Manipulate the relationship only after the setup is clean.",
|
| 239 |
]
|
| 240 |
scaffold.intermediate_steps = [
|
| 241 |
"Simplify before isolating.",
|
| 242 |
"Keep track of what the question actually asks for.",
|
| 243 |
+
"Check the final quantity against the prompt.",
|
| 244 |
]
|
| 245 |
scaffold.first_move = "Start by translating the words into one clean symbolic statement."
|
| 246 |
scaffold.next_hint = "Then simplify the structure before solving."
|
| 247 |
scaffold.common_traps = [
|
| 248 |
"Poor variable definition.",
|
| 249 |
"Messy setup before solving.",
|
| 250 |
+
"Answering the wrong final quantity.",
|
| 251 |
+
]
|
| 252 |
+
scaffold.key_operations = [
|
| 253 |
+
"define unknown",
|
| 254 |
+
"translate relationship",
|
| 255 |
+
"simplify and isolate",
|
| 256 |
+
]
|
| 257 |
+
scaffold.hint_ladder = [
|
| 258 |
+
"Define the unknown clearly.",
|
| 259 |
+
"Translate the words into one symbolic relationship.",
|
| 260 |
+
"Simplify before solving.",
|
| 261 |
+
"Then isolate the target quantity.",
|
| 262 |
]
|
| 263 |
|
| 264 |
result.teaching_points = teaching_points
|
|
|
|
| 266 |
result.meta = {
|
| 267 |
"intent": "explain_question",
|
| 268 |
"bridge_ready": True,
|
| 269 |
+
"hint_style": "progressive",
|
| 270 |
"subtype": subtype,
|
| 271 |
+
"solution_path_type": scaffold.solution_path_type,
|
| 272 |
+
"key_operations": list(scaffold.key_operations),
|
| 273 |
}
|
| 274 |
return result
|