Project 5: Function Grapher and Analysis Workbench

A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.

  • Difficulty: Intermediate-Advanced
  • Time: 16-28 hours
  • Language: Python (alternatives: JavaScript, Julia, R)
  • Prerequisites: Projects 3-4
  • Merged from: HS P02, HS P19; ML-Math P02

What You Will Build

Build a safe multi-function graphing and analysis workbench. Parse expressions without arbitrary execution, establish a requested plotting window, determine valid sample points, and draw functions with axes and labels. Then add structural diagnostics: approximate roots and intercepts, increasing/decreasing sample intervals, piecewise boundaries, composition, candidate inverse windows, asymptotic trends, singularities, holes, and jump discontinuities. Parameter sweeps should show how transformations such as a*f(b(x-h))+k affect shape. Every feature report must state whether it is exact from structure or estimated from sampling.

Real World Outcome

A command can compare 1/x, (x^2-1)/(x-1), and a piecewise function on the same fixed grid. The output saves a plot without drawing false lines across singularities and prints domain exclusions, approximate zeros, suspicious discontinuities, and confidence/step-size notes. A parameter animation or set of plots demonstrates horizontal/vertical scale, reflection, and translation with reproducible colors and bounds.

Core Question

What can a graph reveal about a function’s structure, and which apparent features are artifacts of finite sampling rather than mathematical facts?

Concepts You Must Understand First

  1. Function, domain, and range: a rule plus permitted inputs, not merely a formula.
  2. Composition and inverses: inverses require one-to-one behavior on the chosen domain.
  3. Transformations and piecewise definitions: shifts, scales, reflections, and boundary rules. See Orland, Math for Programmers.
  4. Continuity and asymptotes: holes, jumps, vertical singularities, and end behavior.
  5. Sampling and numerical feature detection: a sign change suggests a root but can miss tangencies or cross a pole.

Build Milestones

  1. Reuse or adapt the safe expression parser, evaluate over a deterministic grid, and mask domain errors.
  2. Plot multiple functions while splitting line segments around invalid values or implausibly large jumps.
  3. Detect approximate intercepts, sign changes, local direction changes, and suspicious discontinuities.
  4. Add piecewise definitions, composition, domain diagnostics, and interval-based inverse checks.
  5. Implement parameter sweeps and generate a structured analysis report with accuracy caveats.

Hints in Layers

  1. Return (value, status) for every sample so an invalid domain is data, not an exception that ends the run.
  2. Detect features with brackets first, then refine them; never call a coarse-grid estimate exact.
  3. Keep symbolic domain rules for common functions (sqrt, denominator, log) alongside numerical probes.

Common Pitfalls and Debugging

  • Symptom: a vertical line appears across x=0 for 1/x. Cause: the plot connected samples on opposite sides of a pole. Fix: break segments at invalid points and large jumps.
  • Symptom: (x-1)^2 has no reported root. Cause: sign-change detection misses tangent roots. Fix: also search local minima of |f(x)| and label them candidates.
  • Symptom: an inverse is claimed for x^2 over all reals. Cause: global one-to-one behavior was not checked. Fix: require a monotonic restricted interval.

Definition of Done

  • Expressions are evaluated safely on a deterministic grid with domain failures isolated.
  • Plots avoid connecting across known or detected discontinuities.
  • Reports cover roots/intercepts, transformations, domain, piecewise boundaries, and asymptotic clues.
  • Composition and restricted inverse behavior have tested examples.
  • Every numerical inference includes resolution or tolerance limitations.
  • Parameter sweeps are reproducible and visibly demonstrate transformations.

Previous: Project 4 · Complete learning path · Next: Project 6