Qurak

Equal

Доступно

Compare values for equality.

`a == b` compares values, and it is the natural way to check an answer: substitute a solution back into its equation and read the truth value. That check is not reliable here, in two ways. On exact algebraic values it can be wrong outright. Both roots of `x^2 == x + 1` satisfy it, and only one of them says so: ```wolfram Simplify[(x^2 == x + 1) /. x -> (1 + Sqrt[5])/2] (* True *) Simplify[(x^2 == x + 1) /. x -> (1 - Sqrt[5])/2] (* False - but it is a root *) ``` On machine numbers it is exact rather than tolerant, so a numeric root of its own polynomial - correct to the last digit the arithmetic carries - also reads `False`. Check by subtraction instead. The residual `lhs - rhs` is reliable in both cases, and both spellings below give the right answer for both roots above: ```wolfram Simplify[(x^2 - (x + 1)) /. x -> (1 - Sqrt[5])/2] (* 0 *) PossibleZeroQ[(x^2 - (x + 1)) /. x -> (1 - Sqrt[5])/2] (* True *) ``` For a machine-precision root, compare the residual against a tolerance rather than against zero: `Chop[Abs[residual], 10^-9]`. The rule is subtract, never compare - and it applies to any route that leaves an `Equal` for the engine to evaluate, including writing the check as `(lhs - rhs == 0) /. solution`.

== Check if values are equal to each other.
Equal[1, 1] → TrueEqual[1, 2] → FalseEqual[1, 1, 1] → True2 == 2 → Truex = 2; x == 2 → True2 == 3 → False1 == True → 1 == True1 == Null → 1 == NullTrue == False → FalseNull == Null → True2 > 1 == True → 1 == True

Темы

Связанное

Все 6300 функций · Использовать из MCP-клиента