Update explainers/explainer_percent.py
Browse files- explainers/explainer_percent.py +63 -83
explainers/explainer_percent.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
import re
|
| 4 |
from .explainer_types import ExplainerResult, ExplainerScaffold
|
| 5 |
|
|
@@ -47,14 +45,14 @@ def explain_algebra_question(text: str):
|
|
| 47 |
return None
|
| 48 |
|
| 49 |
subtype = _infer_algebra_subtype(text)
|
|
|
|
| 50 |
|
| 51 |
result = ExplainerResult(
|
| 52 |
understood=True,
|
| 53 |
topic="algebra",
|
| 54 |
-
summary=
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
),
|
| 58 |
)
|
| 59 |
|
| 60 |
scaffold = ExplainerScaffold(
|
|
@@ -63,10 +61,31 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.",
|
|
@@ -91,21 +110,15 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
"
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
]
|
| 104 |
scaffold.hint_ladder = [
|
| 105 |
-
"
|
| 106 |
-
"
|
| 107 |
-
"
|
| 108 |
-
"Keep simplifying until only the variable remains.",
|
| 109 |
]
|
| 110 |
|
| 111 |
elif subtype == "system":
|
|
@@ -124,21 +137,15 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
"
|
| 134 |
-
"
|
| 135 |
-
"
|
| 136 |
]
|
| 137 |
scaffold.hint_ladder = [
|
| 138 |
-
"
|
| 139 |
-
"
|
| 140 |
-
"
|
| 141 |
-
"Then substitute back into the other equation.",
|
| 142 |
]
|
| 143 |
|
| 144 |
elif subtype == "inequality":
|
|
@@ -154,21 +161,15 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
"
|
| 166 |
]
|
| 167 |
scaffold.hint_ladder = [
|
| 168 |
-
"
|
| 169 |
-
"
|
| 170 |
-
"
|
| 171 |
-
"Express the result as the correct range or set.",
|
| 172 |
]
|
| 173 |
|
| 174 |
elif subtype == "quadratic":
|
|
@@ -184,21 +185,15 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
"
|
| 194 |
-
"factor or
|
| 195 |
-
"check
|
| 196 |
]
|
| 197 |
scaffold.hint_ladder = [
|
| 198 |
-
"
|
| 199 |
-
"
|
| 200 |
-
"
|
| 201 |
-
"Check whether all resulting values fit the original problem.",
|
| 202 |
]
|
| 203 |
|
| 204 |
elif subtype == "expression_evaluation":
|
|
@@ -214,21 +209,15 @@ def explain_algebra_question(text: str):
|
|
| 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
|
| 225 |
-
"simplify
|
| 226 |
]
|
| 227 |
scaffold.hint_ladder = [
|
| 228 |
-
"
|
| 229 |
-
"
|
| 230 |
-
"
|
| 231 |
-
"Simplify the resulting expression carefully.",
|
| 232 |
]
|
| 233 |
|
| 234 |
else:
|
|
@@ -244,31 +233,22 @@ def explain_algebra_question(text: str):
|
|
| 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 |
-
"
|
| 254 |
-
"
|
| 255 |
-
"
|
| 256 |
]
|
| 257 |
scaffold.hint_ladder = [
|
| 258 |
-
"
|
| 259 |
-
"
|
| 260 |
-
"
|
| 261 |
-
"Then isolate the target quantity.",
|
| 262 |
]
|
| 263 |
|
| 264 |
-
result.teaching_points = teaching_points
|
| 265 |
result.scaffold = scaffold
|
| 266 |
result.meta = {
|
| 267 |
"intent": "explain_question",
|
| 268 |
"bridge_ready": True,
|
| 269 |
-
"hint_style": "
|
| 270 |
"subtype": subtype,
|
| 271 |
-
"solution_path_type": scaffold.solution_path_type,
|
| 272 |
-
"key_operations": list(scaffold.key_operations),
|
| 273 |
}
|
| 274 |
return result
|
|
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
from .explainer_types import ExplainerResult, ExplainerScaffold
|
| 3 |
|
|
|
|
| 45 |
return None
|
| 46 |
|
| 47 |
subtype = _infer_algebra_subtype(text)
|
| 48 |
+
low = (text or "").lower()
|
| 49 |
|
| 50 |
result = ExplainerResult(
|
| 51 |
understood=True,
|
| 52 |
topic="algebra",
|
| 53 |
+
summary="This is an algebra problem. The main goal is to translate the wording into a clean symbolic relationship and isolate the requested quantity step by step.",
|
| 54 |
+
asks_for="the value of the variable or the requested expression built from it",
|
| 55 |
+
plain_english="Algebra questions usually become easier once you write one clean equation and then reverse the operations in order.",
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
scaffold = ExplainerScaffold(
|
|
|
|
| 61 |
target="Set up the simplest correct equation or relation before manipulating it.",
|
| 62 |
answer_hidden=True,
|
| 63 |
solution_path_type=subtype,
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
+
result.givens = [
|
| 67 |
+
"A symbolic relationship or equation is implied by the wording.",
|
| 68 |
+
]
|
| 69 |
+
if "=" in low:
|
| 70 |
+
result.givens.append("An equals sign or equation structure is present.")
|
| 71 |
+
|
| 72 |
+
result.relationships = [
|
| 73 |
+
"Both sides of an equation must stay balanced.",
|
| 74 |
+
"Each algebra step should simplify or isolate the target quantity.",
|
| 75 |
+
]
|
| 76 |
+
result.needed_concepts = [
|
| 77 |
+
"equation balancing",
|
| 78 |
+
"inverse operations",
|
| 79 |
+
"checking what the question actually asks for",
|
| 80 |
+
]
|
| 81 |
+
result.trap_notes = [
|
| 82 |
+
"Moving terms across the equals sign incorrectly.",
|
| 83 |
+
"Trying to isolate the variable before simplifying.",
|
| 84 |
+
"Finding x and forgetting the question asks for something like 2x or x + 3.",
|
| 85 |
+
]
|
| 86 |
+
result.strategy_hint = "Rewrite the relationship as one clean equation before doing any manipulation."
|
| 87 |
+
|
| 88 |
+
result.teaching_points = [
|
| 89 |
"Most algebra errors happen before the solving starts: either the variable is misdefined, or the equation is set up incorrectly.",
|
| 90 |
"A clean equation makes the solving steps much easier.",
|
| 91 |
"You should always check whether the question asks for x itself or for something derived from x.",
|
|
|
|
| 110 |
scaffold.equations_to_form = [
|
| 111 |
"Build one equation from the stated relationship.",
|
| 112 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
scaffold.key_operations = [
|
| 114 |
+
"Simplify",
|
| 115 |
+
"undo addition/subtraction",
|
| 116 |
+
"undo multiplication/division",
|
| 117 |
]
|
| 118 |
scaffold.hint_ladder = [
|
| 119 |
+
"What operation is attached to the variable?",
|
| 120 |
+
"What inverse operation would undo it?",
|
| 121 |
+
"Apply that same operation to both sides.",
|
|
|
|
| 122 |
]
|
| 123 |
|
| 124 |
elif subtype == "system":
|
|
|
|
| 137 |
scaffold.equations_to_form = [
|
| 138 |
"Use the two given equations together to reduce to one unknown.",
|
| 139 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
scaffold.key_operations = [
|
| 141 |
+
"substitute",
|
| 142 |
+
"eliminate",
|
| 143 |
+
"back-substitute",
|
| 144 |
]
|
| 145 |
scaffold.hint_ladder = [
|
| 146 |
+
"Which variable looks easier to isolate?",
|
| 147 |
+
"Can you align coefficients for elimination?",
|
| 148 |
+
"After finding one variable, plug it back into the other equation.",
|
|
|
|
| 149 |
]
|
| 150 |
|
| 151 |
elif subtype == "inequality":
|
|
|
|
| 161 |
]
|
| 162 |
scaffold.first_move = "Set up the inequality carefully from the wording."
|
| 163 |
scaffold.next_hint = "Solve it step by step, watching for any operation that would reverse the sign."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
scaffold.key_operations = [
|
| 165 |
+
"translate wording to an inequality",
|
| 166 |
"simplify",
|
| 167 |
+
"watch for sign reversal with negatives",
|
| 168 |
]
|
| 169 |
scaffold.hint_ladder = [
|
| 170 |
+
"What phrase tells you the direction of the inequality?",
|
| 171 |
+
"Can you simplify both sides first?",
|
| 172 |
+
"Did you divide or multiply by a negative at any point?",
|
|
|
|
| 173 |
]
|
| 174 |
|
| 175 |
elif subtype == "quadratic":
|
|
|
|
| 185 |
]
|
| 186 |
scaffold.first_move = "Put the expression into a standard structured form before solving."
|
| 187 |
scaffold.next_hint = "Then look for a factorable pattern or another clean route."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
scaffold.key_operations = [
|
| 189 |
+
"standardize the expression",
|
| 190 |
+
"factor or use structure",
|
| 191 |
+
"check all roots back in context",
|
| 192 |
]
|
| 193 |
scaffold.hint_ladder = [
|
| 194 |
+
"Can you move everything to one side first?",
|
| 195 |
+
"Does the expression factor neatly?",
|
| 196 |
+
"Do all candidate solutions actually fit the original question?",
|
|
|
|
| 197 |
]
|
| 198 |
|
| 199 |
elif subtype == "expression_evaluation":
|
|
|
|
| 209 |
]
|
| 210 |
scaffold.first_move = "Work out whether you need to solve for the variable first or can rewrite the target expression directly."
|
| 211 |
scaffold.next_hint = "Once the relationship is clear, substitute only into the exact expression the question asks for."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
scaffold.key_operations = [
|
| 213 |
+
"solve or rewrite the relationship",
|
| 214 |
+
"substitute carefully",
|
| 215 |
+
"simplify the requested expression",
|
| 216 |
]
|
| 217 |
scaffold.hint_ladder = [
|
| 218 |
+
"What expression does the question actually want?",
|
| 219 |
+
"Do you already have enough information to rewrite that expression?",
|
| 220 |
+
"Only substitute after the target expression is clear.",
|
|
|
|
| 221 |
]
|
| 222 |
|
| 223 |
else:
|
|
|
|
| 233 |
]
|
| 234 |
scaffold.first_move = "Start by translating the words into one clean symbolic statement."
|
| 235 |
scaffold.next_hint = "Then simplify the structure before solving."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
scaffold.key_operations = [
|
| 237 |
+
"translate",
|
| 238 |
+
"simplify",
|
| 239 |
+
"isolate",
|
| 240 |
]
|
| 241 |
scaffold.hint_ladder = [
|
| 242 |
+
"What is the unknown?",
|
| 243 |
+
"What relationship connects the quantities?",
|
| 244 |
+
"What is the cleanest first algebra step?",
|
|
|
|
| 245 |
]
|
| 246 |
|
|
|
|
| 247 |
result.scaffold = scaffold
|
| 248 |
result.meta = {
|
| 249 |
"intent": "explain_question",
|
| 250 |
"bridge_ready": True,
|
| 251 |
+
"hint_style": "step_ready",
|
| 252 |
"subtype": subtype,
|
|
|
|
|
|
|
| 253 |
}
|
| 254 |
return result
|