Math function plotter

Enter one or more expressions (e.g. sin(x)/x, 2x^2 - 3, (cos(t), sin(3t)), r = 1 + cos(θ), x^2 + y^2 = 4) - the server parses and samples the curves in PHP with its OWN, hand-written expression parser (tokenizer → syntax tree → safe, whitelisted evaluation). No eval(): the input never becomes executed code.

The PHP code that actually runs (excerpt)
// Elsőbbség: az unáris mínusz a hatvány FÖLÖTT él, a kitevő jobbra köt
//   unary := ('-'|'+') unary | power
//   power := postfix ('^' unary)?        // -2^2 = -4, 2^3^2 = 512
// Implicit szorzás (2x, 3sin(x), (x+1)(x-1)) a '*'-gal azonos szinten:
if ($this->startsPrimary($this->current())) {
    $node = Node::binary('*', $node, $this->parsePower(), true);
}

// Fehérlistás dispatch - SOSEM dinamikus "$name(...)" hívás vagy eval()
return match ($name) {
    'sin' => sin($x),
    'gamma' => SpecialFunctions::gamma($x),
    'log' => count($a) === 1 ? log10($x) : self::logBase($a[0], $a[1]),
    // ...
};

// Szakadás-keresés: ha két szomszédos minta közt nagy az ugrás, felezzük
for ($k = 0; $k < 44; $k++) {
    $mid = ($xl + $xr) / 2;
    $ym = $f($mid);
    if (abs($ym - $yl) >= abs($yr - $ym)) { $xr = $mid; $yr = $ym; } else { $xl = $mid; $yl = $ym; }
}
// az ugrás nem csökkent: pólus vagy ugrás, a két ág NEM kapcsolódik

Functions

Decimals: use the dot (0.5); outside function calls a comma works too (0,5). Function arguments are separated by , or ;
-10-8-6-4-20246810-4-2024
Wheel or pinch: zoom. Drag: pan. Tap / hover over the graph: value readout. Keys: arrows, +, -, 0.

Analysis

Roots
Extrema
Intersections
Derivative curve
Definite integral

View

Examples

Parabola
Cubic
Reciprocal (1/x)
Root and square
Absolute value
exp, ln and y = x
Bell and erf
The line breaks wherever the function is undefined (division by zero, negative root...). At an asymptote the two branches are never joined: the server locates the break by interval bisection. The full state (expressions, parameters, view, analysis) is part of the link.

Implicit multiplication

2x, 3sin(x), (x+1)(x-1), 2pi

Powers (right-associative)

x^2, x**2, x², 2^3^2 = 512, -x^2 = -(x²)

Absolute value, factorial

|x - 1|, 5!, x!

Roots, Unicode

√(x+1), π, ×, ·, −, ≤, ≥, ≠

Conditions, piecewise

if(x<0, -x, x^2), piecewise(x<-1, -1, x<1, x, 1)

Comparison, logic

0 < x < 5, x>0 and x<3, not x==2

Domain restriction

x^2 {x > 0}, sin(x) {0 <= x <= 3}

Parametric curve

(cos(t), sin(3t))

Polar curve

r = 1 + cos(θ)

Implicit curve

x^2 + y^2 = 4

Sum, product

sum(k, 1, 20, sin(k*x)/k)

Parameters (sliders)

a*sin(b*x + c)

Hungarian and English names

tg, ctg, arctg, sh, ch, lg, ln, log(2, 8)

How do you safely evaluate a formula typed in by a user?

The simplest, but dangerous, option would be eval(): it would run the typed text directly as PHP code, which would allow arbitrary code execution on the server - this page never uses eval() for that reason.

The safe approach is a hand-written expression parser: it breaks the text into tokens (numbers, operators, function names, parentheses, Unicode signs), then builds a syntax tree that handles precedence (-x^2 means -(x²), 2^3^2 binds right to left), implicit multiplication (2x, 3sin(x)) and the absolute value bars correctly. The math preview above draws exactly the tree the server built.

Evaluating that tree only allows a strictly whitelisted set of functions - an unknown name throws an error immediately (telling you where, and even what you may have meant). Every numeric input is clamped: at most 8 expressions, 200 characters each, a bounded sample count, grid size and time budget.

Discontinuities are detected on the server: where the function is undefined the line breaks; at an asymptote (1/x, tan x) or a jump (floor) interval bisection tells whether a real break lies between two samples, and if so the two sides are never joined. sin(x)/x at 0 is filled in from the two-sided limit. Roots use bisection, implicit curves marching squares, the integral Gauss-Legendre quadrature.