Spaces:
Sleeping
Sleeping
Precalculus Studio: placement, worked examples, retrieval quizzes, peer instruction (part 5)
1289247 verified Download src/edtech_core/curriculum.py from BenjaminKaindu0506/ed-tech-studio: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/spaces/BenjaminKaindu0506/ed-tech-studio/resolve/main/src/edtech_core/curriculum.py
- Command line
-
hf download hf://spaces/BenjaminKaindu0506/ed-tech-studio/src/edtech_core/curriculum.py
-
curl -L -o curriculum.py https://huggingface.co/spaces/BenjaminKaindu0506/ed-tech-studio/resolve/main/src/edtech_core/curriculum.py
11.3 kB
| """Precalculus curriculum map — the shared vocabulary every agent and the quiz engine use. | |
| Topics follow OpenStax *Precalculus 2e* order (that order defines "covered so far"). | |
| Each topic lists: | |
| - `sections`: textbook sections it spans (textbook chunks are tagged by section on ingest) | |
| - `keywords`: regexes used to tag dataset problems that don't carry a usable label | |
| - `confusable_with`: topics whose problems look alike on the surface but need a different | |
| method. Interleaving pays off mainly by forcing learners to pick the method | |
| (discriminative contrast; Rohrer 2012; Brunmair & Richter 2019 meta-analysis), so review | |
| slots favor these pairings. | |
| `coordinate_geometry` and `circles` have no dedicated Precalculus 2e section (they are | |
| review content assumed from College Algebra) but make up a large share of the | |
| MathCanvas analytic-geometry bank, so they are explicit topics here. | |
| """ | |
| from __future__ import annotations | |
| import re | |
| from dataclasses import dataclass, field | |
| class Topic: | |
| id: str | |
| title: str | |
| chapter: int | |
| sections: tuple[str, ...] | |
| keywords: tuple[str, ...] = () | |
| confusable_with: tuple[str, ...] = field(default_factory=tuple) | |
| TOPICS: tuple[Topic, ...] = ( | |
| Topic("functions_basics", "Functions, notation, domain & range", 1, ("1.1", "1.2"), | |
| (r"\bdomain\b", r"\brange\b", r"function notation", r"\bis .* a function\b", r"vertical line test"), | |
| ("rates_and_graph_behavior", "inverse_functions")), | |
| Topic("rates_and_graph_behavior", "Rates of change & behavior of graphs", 1, ("1.3",), | |
| (r"average rate of change", r"increasing", r"decreasing", r"local (max|min)", r"\bextrema\b"), | |
| ("linear_functions", "functions_basics")), | |
| Topic("composition_and_transformations", "Composition, transformations, absolute value", 1, ("1.4", "1.5", "1.6"), | |
| (r"composit", r"f\s*\(\s*(\\left\()?\s*g\s*\(", r"\\circ", r"shift(ed)?", r"translat", r"reflect", r"stretch", r"compress", | |
| r"absolute value", r"\|x"), | |
| ("inverse_functions", "functions_basics")), | |
| Topic("inverse_functions", "Inverse functions", 1, ("1.7", "3.8"), | |
| (r"inverse function", r"f\^\{?-1\}?", r"one-to-one", r"radical function"), | |
| ("composition_and_transformations", "logarithmic_functions")), | |
| Topic("linear_functions", "Linear functions & lines", 2, ("2.1", "2.2", "2.3", "2.4"), | |
| (r"\bslope\b", r"\bline\b", r"linear", r"intercept", r"parallel", r"perpendicular", r"point-slope"), | |
| ("quadratic_functions", "coordinate_geometry")), | |
| Topic("coordinate_geometry", "Coordinate geometry (distance, midpoint, points & figures)", 2, ("2.2",), | |
| (r"distance between", r"midpoint", r"coordinate", r"quadrant", r"\btriangle\b", r"area of"), | |
| ("linear_functions", "circles")), | |
| Topic("quadratic_functions", "Quadratic functions", 3, ("3.2",), | |
| (r"quadratic", r"parabola .* vertex", r"\bvertex\b", r"axis of symmetry", r"x\^2"), | |
| ("polynomial_functions", "parabolas")), | |
| Topic("polynomial_functions", "Complex numbers & polynomial functions", 3, ("3.1", "3.3", "3.4", "3.5", "3.6"), | |
| (r"polynomial", r"\bzeros?\b", r"\broots?\b", r"long division", r"synthetic division", r"end behavior", | |
| r"complex number", r"\bdegree\b", r"x\^[3-9]"), | |
| ("rational_functions", "quadratic_functions")), | |
| Topic("rational_functions", "Rational functions & variation", 3, ("3.7", "3.9"), | |
| (r"rational function", r"asymptote", r"\\frac\{[^}]*\}\{[^}]*x", r"varies (directly|inversely)", | |
| r"inverse(ly)? proportional", r"\bhole\b"), | |
| ("polynomial_functions", "exponential_functions")), | |
| Topic("exponential_functions", "Exponential functions & graphs", 4, ("4.1", "4.2"), | |
| (r"exponential", r"compound(ed)? interest", r"\be\^", r"\d\^\{?x\}?", r"growth", r"decay"), | |
| ("logarithmic_functions", "exp_log_equations_models")), | |
| Topic("logarithmic_functions", "Logarithmic functions, graphs & properties", 4, ("4.3", "4.4", "4.5"), | |
| (r"\\log", r"\\ln", r"logarithm", r"\blog\b", r"\bln\b"), | |
| ("exponential_functions", "inverse_functions")), | |
| Topic("exp_log_equations_models", "Exponential & logarithmic equations and models", 4, ("4.6", "4.7", "4.8"), | |
| (r"half-life", r"doubling time", r"newton's law of cooling", r"logistic", r"solve .*e\^"), | |
| ("exponential_functions", "logarithmic_functions")), | |
| Topic("angles_and_unit_circle", "Angles, radians & the unit circle", 5, ("5.1", "5.2", "5.3"), | |
| (r"radian", r"unit circle", r"arc length", r"angular", r"reference angle", r"coterminal", r"\\sec", r"\\csc", r"\\cot"), | |
| ("right_triangle_trig", "trig_graphs_and_inverses")), | |
| Topic("right_triangle_trig", "Right-triangle trigonometry", 5, ("5.4",), | |
| (r"right triangle", r"hypotenuse", r"angle of elevation", r"angle of depression", r"opposite", r"adjacent"), | |
| ("non_right_triangles", "angles_and_unit_circle")), | |
| Topic("trig_graphs_and_inverses", "Graphs of trig functions & inverse trig", 6, ("6.1", "6.2", "6.3"), | |
| (r"amplitude", r"period", r"phase shift", r"midline", r"\\arcsin", r"\\arccos", r"\\arctan", r"sin\^\{-1\}", | |
| r"\\sin", r"\\cos", r"\\tan"), | |
| ("trig_identities_and_equations", "angles_and_unit_circle")), | |
| Topic("trig_identities_and_equations", "Trig identities & equations", 7, ("7.1", "7.2", "7.3", "7.4", "7.5", "7.6"), | |
| (r"identit", r"double[- ]angle", r"half[- ]angle", r"sum[- ]to[- ]product", r"\\sin\^2", r"\\cos\^2", | |
| r"solve .*\\(sin|cos|tan)"), | |
| ("trig_graphs_and_inverses", "angles_and_unit_circle")), | |
| Topic("non_right_triangles", "Law of Sines & Law of Cosines", 8, ("8.1", "8.2"), | |
| (r"law of sines", r"law of cosines", r"oblique", r"heron"), | |
| ("right_triangle_trig", "vectors")), | |
| Topic("polar_and_parametric", "Polar coordinates, polar complex form, parametric equations", 8, | |
| ("8.3", "8.4", "8.5", "8.6", "8.7"), | |
| (r"polar", r"parametric", r"\br\s*=", r"de ?moivre", r"rectangular coordinates"), | |
| ("conics_rotation_and_polar", "vectors")), | |
| Topic("vectors", "Vectors", 8, ("8.8",), | |
| (r"vector", r"dot product", r"magnitude", r"\\vec", r"\\overrightarrow", r"unit vector"), | |
| ("non_right_triangles", "coordinate_geometry")), | |
| Topic("systems_and_matrices", "Systems of equations, partial fractions & matrices", 9, | |
| ("9.1", "9.2", "9.3", "9.4", "9.5", "9.6", "9.7", "9.8"), | |
| (r"system of", r"matri", r"determinant", r"gaussian", r"cramer", r"partial fraction", r"inequalit"), | |
| ("linear_functions", "rational_functions")), | |
| Topic("circles", "Circles in the coordinate plane", 10, ("10.1",), | |
| (r"\bcircle\b", r"radius", r"tangent line", r"chord", r"\(x\s*-\s*\w+\)\^2\s*\+\s*\(y"), | |
| ("ellipses", "coordinate_geometry")), | |
| Topic("ellipses", "The ellipse", 10, ("10.1",), | |
| (r"ellipse", r"major axis", r"minor axis", r"eccentricity"), | |
| ("hyperbolas", "circles")), | |
| Topic("hyperbolas", "The hyperbola", 10, ("10.2",), | |
| (r"hyperbola", r"asymptotes? of the hyperbola", r"transverse axis", r"conjugate axis"), | |
| ("ellipses", "parabolas")), | |
| Topic("parabolas", "The parabola (focus & directrix)", 10, ("10.3",), | |
| (r"parabola", r"directrix", r"\bfocus\b", r"latus rectum", r"y\^2\s*=", r"x\^2\s*=\s*\d*\s*y"), | |
| ("quadratic_functions", "hyperbolas")), | |
| Topic("conics_rotation_and_polar", "Rotation of axes & conics in polar form", 10, ("10.4", "10.5"), | |
| (r"rotation of axes", r"rotate", r"\bxy\b term", r"discriminant .*conic"), | |
| ("polar_and_parametric", "ellipses")), | |
| Topic("sequences_and_series", "Sequences & series", 11, ("11.1", "11.2", "11.3", "11.4"), | |
| (r"sequence", r"series", r"arithmetic", r"geometric", r"\\sum", r"n-th term", r"common (ratio|difference)"), | |
| ("counting_and_probability", "exponential_functions")), | |
| Topic("counting_and_probability", "Counting, binomial theorem & probability", 11, ("11.5", "11.6", "11.7"), | |
| (r"permutation", r"combination", r"binomial", r"probability", r"how many ways", r"\\binom"), | |
| ("sequences_and_series",)), | |
| Topic("intro_to_calculus", "Limits, continuity & derivatives", 12, ("12.1", "12.2", "12.3", "12.4"), | |
| (r"\\lim", r"limit", r"continu", r"derivative", r"instantaneous rate"), | |
| ("rates_and_graph_behavior",)), | |
| ) | |
| TOPIC_BY_ID: dict[str, Topic] = {t.id: t for t in TOPICS} | |
| TOPIC_ORDER: dict[str, int] = {t.id: i for i, t in enumerate(TOPICS)} | |
| _SECTION_TO_TOPIC: dict[str, str] = {} | |
| for _t in TOPICS: | |
| for _s in _t.sections: | |
| _SECTION_TO_TOPIC.setdefault(_s, _t.id) | |
| # A few sections are shared by two topics; pin each to its primary owner. | |
| _SECTION_TO_TOPIC["10.1"] = "ellipses" | |
| _SECTION_TO_TOPIC["2.2"] = "linear_functions" | |
| _SECTION_TO_TOPIC["3.8"] = "inverse_functions" | |
| def topic_for_section(section: str | None) -> str | None: | |
| return _SECTION_TO_TOPIC.get(section) if section else None | |
| _COMPILED = {t.id: [re.compile(k, re.IGNORECASE) for k in t.keywords] for t in TOPICS} | |
| def classify_text(text: str, candidates: tuple[str, ...] | None = None, default: str = "functions_basics") -> str: | |
| """Keyword-vote topic tagger for dataset problems. Deterministic and inspectable on | |
| purpose: a mis-tag only affects which quiz slot a problem fills, never its answer key.""" | |
| pool = candidates or tuple(TOPIC_BY_ID) | |
| scores = {tid: sum(1 for rx in _COMPILED[tid] if rx.search(text)) for tid in pool} | |
| best = max(pool, key=lambda tid: (scores[tid], -TOPIC_ORDER[tid])) | |
| return best if scores[best] > 0 else (default if default in pool else pool[0]) | |
| # MathCanvas `subknowledge` → candidate topics (keyword vote picks among them). | |
| MATHCANVAS_SUBKNOWLEDGE_TOPICS: dict[str, tuple[str, ...]] = { | |
| "Coordinate System Basics": ("coordinate_geometry", "linear_functions", "quadratic_functions", "rational_functions", | |
| "functions_basics", "circles", "parabolas"), | |
| "Linear Equations & Properties": ("linear_functions", "coordinate_geometry"), | |
| "Conic Sections (Ellipse, Hyperbola, Parabola)": ("ellipses", "hyperbolas", "parabolas", "circles"), | |
| # MathCanvas files many ellipse/hyperbola/parabola problems under "Circular Equations". | |
| "Circular Equations & Properties": ("circles", "ellipses", "hyperbolas", "parabolas", "quadratic_functions", | |
| "coordinate_geometry"), | |
| "Quadratic Functions": ("quadratic_functions",), | |
| "Quadratic Equations & Properties": ("quadratic_functions",), | |
| "Function Basics (Domain, Range, Properties)": ("functions_basics", "rates_and_graph_behavior"), | |
| "Piecewise & Other Functions": ("composition_and_transformations", "functions_basics"), | |
| "Inverse Proportional Functions": ("rational_functions",), | |
| "Vector Basics & Operations": ("vectors",), | |
| } | |
| def topic_catalog() -> list[dict]: | |
| """Compact listing for agents/UI.""" | |
| return [ | |
| {"id": t.id, "title": t.title, "chapter": t.chapter, "sections": list(t.sections), | |
| "confusable_with": list(t.confusable_with)} | |
| for t in TOPICS | |
| ] | |