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.
// 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ódikImplicit multiplication
2x, 3sin(x), (x+1)(x-1), 2piPowers (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==2Domain 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 = 4Sum, 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)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.
This site uses Google Analytics to measure visits. This requires your consent - see the privacy policy for details. Privacy Policy