Update explainers/explainer_algebra.py
Browse files1234541 unmodified lines47484950515253545556575859602 unmodified lines6364656667686970717218 unmodified lines91929394959697989910010110210310410510610710810911011112 unmodified lines1241251261271281291301311321331341351361371381391401411421431449 unmodified lines1541551561571581591601611621631641651661671681691701711721731749 unmodified lines1841851861871881891901911921931941951961971981992002012022032049 unmodified lines2142152162172182192202212222232242252262272282292302312322332349 unmodified lines244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274from __future__ import annotationsimport refrom .explainer_types import ExplainerResult, ExplainerScaffold41 unmodified linesreturn Nonesubtype = _infer_algebra_subtype(text)result = ExplainerResult(understood=True,topic="algebra",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."),)scaffold = ExplainerScaffold(2 unmodified linestarget="Set up the simplest correct equation or relation before manipulating it.",answer_hidden=True,solution_path_type=subtype,reveal_threshold=3,)teaching_points = ["Most algebra errors happen before the solving starts: either the variable is misdefined, or the equation is set up incorrectly.","A clean equation makes the solving steps much easier.","You should always check whether the question asks for x itself or for something derived from x.",18 unmodified linesscaffold.equations_to_form = ["Build one equation from the stated relationship.",]scaffold.common_traps = ["Moving terms across the equals sign incorrectly.","Trying to isolate the variable before simplifying.","Finding x and forgetting the question asks for something like 2x or x + 3.",]scaffold.key_operations = ["rewrite as equation","simplify both sides","use inverse operations",]scaffold.hint_ladder = ["Start by spotting the equation you need to work with.","Simplify both sides before you try to isolate the variable.","Undo the operation attached to the variable on both sides.","Keep simplifying until only the variable remains.",]elif subtype == "system":12 unmodified linesscaffold.equations_to_form = ["Use the two given equations together to reduce to one unknown.",]scaffold.common_traps = ["Mixing substitution and elimination without a clear plan.","Arithmetic mistakes when substituting back.","Stopping after finding one variable when the question asks for something else.",]scaffold.key_operations = ["choose elimination or substitution","reduce to one variable","substitute back",]scaffold.hint_ladder = ["Pick the variable that looks easiest to remove.","Use substitution or elimination to make a one-variable equation.","Solve that reduced equation first.","Then substitute back into the other equation.",]elif subtype == "inequality":9 unmodified lines]scaffold.first_move = "Set up the inequality carefully from the wording."scaffold.next_hint = "Solve it step by step, watching for any operation that would reverse the sign."scaffold.common_traps = ["Forgetting to reverse the inequality when dividing or multiplying by a negative.","Treating phrase-based conditions like at least or no more than incorrectly.","Reporting a single number when the solution is actually a range.",]scaffold.key_operations = ["translate wording","simplify","track sign reversal",]scaffold.hint_ladder = ["Translate the words into an inequality first.","Simplify before isolating the variable.","Watch carefully for multiplication or division by a negative.","Express the result as the correct range or set.",]elif subtype == "quadratic":9 unmodified lines]scaffold.first_move = "Put the expression into a standard structured form before solving."scaffold.next_hint = "Then look for a factorable pattern or another clean route."scaffold.common_traps = ["Trying to factor before the expression is fully simplified.","Dropping one valid case.","Giving roots when the question asks for a derived expression instead.",]scaffold.key_operations = ["rewrite to zero","factor or restructure","check cases",]scaffold.hint_ladder = ["Rewrite the equation in a standard form first.","Look for a common factor or factorable pattern.","Use the structure to split into cases or solve the quadratic.","Check whether all resulting values fit the original problem.",]elif subtype == "expression_evaluation":9 unmodified lines]scaffold.first_move = "Work out whether you need to solve for the variable first or can rewrite the target expression directly."scaffold.next_hint = "Once the relationship is clear, substitute only into the exact expression the question asks for."scaffold.common_traps = ["Stopping at x when the question asks for something built from x.","Substituting incorrectly into expressions with multiple terms.","Ignoring an easier algebraic simplification path.",]scaffold.key_operations = ["solve or rewrite relationship","substitute into target expression","simplify target",]scaffold.hint_ladder = ["Check whether the question wants x or something built from x.","Use the given relationship to find or rewrite the target expression.","Substitute only into the exact expression asked for.","Simplify the resulting expression carefully.",]else:9 unmodified lines]scaffold.first_move = "Start by translating the words into one clean symbolic statement."scaffold.next_hint = "Then simplify the structure before solving."scaffold.common_traps = ["Poor variable definition.","Messy setup before solving.","Answering the wrong final quantity.",]scaffold.key_operations = ["define unknown","translate relationship","simplify and isolate",]scaffold.hint_ladder = ["Define the unknown clearly.","Translate the words into one symbolic relationship.","Simplify before solving.","Then isolate the target quantity.",]result.teaching_points = teaching_pointsresult.scaffold = scaffoldresult.meta = {"intent": "explain_question","bridge_ready": True,"hint_style": "progressive","subtype": subtype,"solution_path_type": scaffold.solution_path_type,"key_operations": list(scaffold.key_operations),}return result12341 unmodified lines45464748495051525354555657582 unmodified lines6162636465666768697071727374757677787980818283848586878889909118 unmodified lines11011111211311411511611711811912012112212312412 unmodified lines1371381391401411421431441451461471481491501519 unmodified lines1611621631641651661671681691701711721731741759 unmodified lines1851861871881891901911921931941951961971981999 unmodified lines2092102112122132142152162172182192202212222239 unmodified lines233234235236237238239240241242243244245246247248249250251252253254import refrom .explainer_types import ExplainerResult, ExplainerScaffold41 unmodified linesreturn Nonesubtype = _infer_algebra_subtype(text)low = (text or "").lower()result = ExplainerResult(understood=True,topic="algebra",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.",asks_for="the value of the variable or the requested expression built from it",plain_english="Algebra questions usually become easier once you write one clean equation and then reverse the operations in order.",)scaffold = ExplainerScaffold(2 unmodified linestarget="Set up the simplest correct equation or relation before manipulating it.",answer_hidden=True,solution_path_type=subtype,)result.givens = ["A symbolic relationship or equation is implied by the wording.",]if "=" in low:result.givens.append("An equals sign or equation structure is present.")result.relationships = ["Both sides of an equation must stay balanced.","Each algebra step should simplify or isolate the target quantity.",]result.needed_concepts = ["equation balancing","inverse operations","checking what the question actually asks for",]result.trap_notes = ["Moving terms across the equals sign incorrectly.","Trying to isolate the variable before simplifying.","Finding x and forgetting the question asks for something like 2x or x + 3.",]result.strategy_hint = "Rewrite the relationship as one clean equation before doing any manipulation."result.teaching_points = ["Most algebra errors happen before the solving starts: either the variable is misdefined, or the equation is set up incorrectly.","A clean equation makes the solving steps much easier.","You should always check whether the question asks for x itself or for something derived from x.",18 unmodified linesscaffold.equations_to_form = ["Build one equation from the stated relationship.",]scaffold.key_operations = ["Simplify","undo addition/subtraction","undo multiplication/division",]scaffold.hint_ladder = ["What operation is attached to the variable?","What inverse operation would undo it?","Apply that same operation to both sides.",]elif subtype == "system":12 unmodified linesscaffold.equations_to_form = ["Use the two given equations together to reduce to one unknown.",]scaffold.key_operations = ["substitute","eliminate","back-substitute",]scaffold.hint_ladder = ["Which variable looks easier to isolate?","Can you align coefficients for elimination?","After finding one variable, plug it back into the other equation.",]elif subtype == "inequality":9 unmodified lines]scaffold.first_move = "Set up the inequality carefully from the wording."scaffold.next_hint = "Solve it step by step, watching for any operation that would reverse the sign."scaffold.key_operations = ["translate wording to an inequality","simplify","watch for sign reversal with negatives",]scaffold.hint_ladder = ["What phrase tells you the direction of the inequality?","Can you simplify both sides first?","Did you divide or multiply by a negative at any point?",]elif subtype == "quadratic":9 unmodified lines]scaffold.first_move = "Put the expression into a standard structured form before solving."scaffold.next_hint = "Then look for a factorable pattern or another clean route."scaffold.key_operations = ["standardize the expression","factor or use structure","check all roots back in context",]scaffold.hint_ladder = ["Can you move everything to one side first?","Does the expression factor neatly?","Do all candidate solutions actually fit the original question?",]elif subtype == "expression_evaluation":9 unmodified lines]scaffold.first_move = "Work out whether you need to solve for the variable first or can rewrite the target expression directly."scaffold.next_hint = "Once the relationship is clear, substitute only into the exact expression the question asks for."scaffold.key_operations = ["solve or rewrite the relationship","substitute carefully","simplify the requested expression",]scaffold.hint_ladder = ["What expression does the question actually want?","Do you already have enough information to rewrite that expression?","Only substitute after the target expression is clear.",]else:9 unmodified lines]scaffold.first_move = "Start by translating the words into one clean symbolic statement."scaffold.next_hint = "Then simplify the structure before solving."scaffold.key_operations = ["translate","simplify","isolate",]scaffold.hint_ladder = ["What is the unknown?","What relationship connects the quantities?","What is the cleanest first algebra step?",]result.scaffold = scaffoldresult.meta = {"intent": "explain_question","bridge_ready": True,"hint_style": "step_ready","subtype": subtype,}return result
explainers/explainer_algebra.py+63-83