# PolymathPlus Examples ## Purpose This file gives representative, validated examples for students, engineers, and AI agents that need to convert natural-language problems into valid PolymathPlus source. Use these examples for modeling patterns and prompt grounding. Use the detailed specs for exact syntax: - `spec_leq.md` - `spec_nle.md` - `spec_deq.md` - `spec_reg.md` - `spec_nlp.md` This file is intentionally not exhaustive. For less common subtypes such as REG `mlinfit`, REG `integrate`, and NLP `fit:`, use the detailed specs. Each example is one singular program type. Do not combine examples into a composite source file. ## LEQ: Linear Algebraic System Natural-language problem: Solve a two-equation linear balance system where `2*A + B = 10` and `A - B = 1`. Program type: `LEQ` ```polymathplus 2*A + B = 10 A - B = 1 ``` Modeling notes: - This is LEQ because all unknowns are linear. - There are no products of unknowns, derivatives, tables, or optimization statements. ## NLE0: Expression Evaluation Natural-language problem: Evaluate an engineering expression for pressure drop from known flow and resistance values. Program type: `NLE` ```polymathplus flow = 3.2 resistance = 4.5 pressure_drop = resistance*flow^2 ``` Modeling notes: - This is expression evaluation, not root solving. - No initial guesses or bounds are needed because there is no nonlinear root variable. ## NLE1: Single Nonlinear Root Natural-language problem: Find `x` such that `x*log(x/2) + 4*x^2 - 1620 = 0` on the interval from `0.1` to `100`. Program type: `NLE` ```polymathplus f(x) = x*log(x/2) + 4*x^2 - 1620 x(min) = 0.1 x(max) = 100 ``` Modeling notes: - This is NLE1 because there is one nonlinear root variable. - Bounds are required for the root variable. ## NLES: Simultaneous Nonlinear Roots Natural-language problem: Solve the nonlinear system `x^2 + y^2 = 25` and `x - y = 1`, using initial guesses near `x = 4` and `y = 3`. Program type: `NLE` ```polymathplus f(x) = x^2 + y^2 - 25 f(y) = x - y - 1 x(0) = 4 y(0) = 3 ``` Modeling notes: - This is NLES because there are simultaneous nonlinear root equations. - Initial guesses are required. - Use one `f(variable)` root line per nonlinear variable. ## DEQ: Ordinary Differential Equation Natural-language problem: A tank concentration `A` decays with first-order rate constant `k = 0.3`. The initial concentration is `10`. Simulate from `t = 0` to `t = 5`. Program type: `DEQ` ```polymathplus d(A)/d(t) = -k*A k = 0.3 A(0) = 10 t(0) = 0 t(f) = 5 ``` Modeling notes: - This is DEQ because it contains a derivative. - Initial and final values are required. ## REG: Polynomial Regression Natural-language problem: Fit a second-order polynomial to measured `x, y` data. Program type: `REG` ```polymathplus [ x y 1 2.1 2 4.2 3 8.1 4 16.3 5 25.2 ] polyfit x y 2 ``` Modeling notes: - This is REG because it uses a data table and a regression command. - Use REG for ordinary table-based fitting before considering NLP `fit:`. ## REG: Nonlinear Regression Natural-language problem: Fit the model `y = a*x/(b + x)` to measured data, starting from `a = 2` and `b = 1`. Program type: `REG` ```polymathplus [ x y 0.5 1.255 0.387 1.25 0.24 1.189 0.136 1.124 0.04 0.783 0.011 0.402 ] nlinfit y = a*x/(b + x) m(a)=2 m(b)=1 ``` Modeling notes: - This is REG `nlinfit`. - Initial guesses are required for fitted parameters. ## NLP: Unconstrained Optimization Natural-language problem: Find `x` and `y` that minimize the squared distance from the point `(2, 3)`. Program type: `NLP` ```polymathplus min: (x - 2)^2 + (y - 3)^2 x| 1 0 10 y| 1 0 10 ``` Modeling notes: - This is NLP because it minimizes an objective. - Guess/bounds lines are required for model variables. ## NLP: Constrained Optimization Natural-language problem: Minimize distance from `(1, 1)` subject to `x + y = 1` and inside the circle `x^2 + y^2 <= 1.5`. Program type: `NLP` ```polymathplus min: (x - 1)^2 + (y - 1)^2 x + y - 1 = 0 1.5 - (x^2 + y^2) > 0 x| 0.5 -2 2 y| 0.5 -2 2 ``` Modeling notes: - Equality constraints use residual form: `residual = 0`. - Inequality constraints use residual form: `residual > 0`. - Do not use `>=`, `<=`, or nonzero inequality right-hand sides. ## Unsupported Example: PDE Request Natural-language problem: Solve a heat equation PDE in one spatial dimension and time. Program type: unsupported directly Recommended agent response: ```txt PolymathPlus does not directly support PDE source programs. It supports LEQ, NLE, DEQ, REG, and NLP. If you discretize the PDE into algebraic equations or ODEs, I can help build a supported LEQ, NLE, or DEQ formulation. Please specify the discretization or confirm that you want help choosing one. ``` Modeling notes: - Do not invent PDE syntax. - A supported source program can be generated only after a valid reformulation is selected. ## Missing Input Example: NLES Without Guesses Natural-language problem: Solve `x^2 + y^2 = 25` and `x - y = 1`. Program type: `NLE`, but blocked until initial guesses are provided. Recommended agent response: ```txt This is a supported NLES problem, but PolymathPlus requires an initial guess for each nonlinear variable. I should not invent those as known data. Provide starting guesses for x and y, or confirm that I should use heuristic guesses based on the scale of the equations. ``` Modeling notes: - Do not generate final NLES source without required guesses. - Heuristic guesses may be offered only as assumptions.