?

Average Error: 0.0 → 0.0
Time: 12.1s
Precision: binary64
Cost: 6848

?

\[x + \left(y - z\right) \cdot \left(t - x\right) \]
\[\mathsf{fma}\left(y - z, t - x, x\right) \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
(FPCore (x y z t) :precision binary64 (fma (- y z) (- t x) x))
double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
double code(double x, double y, double z, double t) {
	return fma((y - z), (t - x), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - z) * Float64(t - x)))
end
function code(x, y, z, t)
	return fma(Float64(y - z), Float64(t - x), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision] + x), $MachinePrecision]
x + \left(y - z\right) \cdot \left(t - x\right)
\mathsf{fma}\left(y - z, t - x, x\right)

Error?

Target

Original0.0
Target0.0
Herbie0.0
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation?

  1. Initial program 0.0

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
    Proof

    [Start]0.0

    \[ x + \left(y - z\right) \cdot \left(t - x\right) \]

    +-commutative [=>]0.0

    \[ \color{blue}{\left(y - z\right) \cdot \left(t - x\right) + x} \]

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(y - z, t - x, x\right) \]

Alternatives

Alternative 1
Error42.8
Cost1644
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{+226}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{+97}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -45000000000000:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-257}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq -8.6 \cdot 10^{-298}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-295}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-149}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+121}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error42.3
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+226}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{+97}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -2500000000000:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{-37}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.25 \cdot 10^{-90}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+120}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error24.2
Cost982
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9 \cdot 10^{+97}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-44} \lor \neg \left(x \leq 8.5 \cdot 10^{-170} \lor \neg \left(x \leq 2.4 \cdot 10^{-160}\right) \land x \leq 4.4 \cdot 10^{-54}\right):\\ \;\;\;\;x + z \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 4
Error40.2
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+101}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{-134}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-248}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-261}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error31.2
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+226}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{+97}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{+27}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-37}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{+120}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error26.2
Cost716
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.75 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-37}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+120}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error12.4
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+101} \lor \neg \left(z \leq 25\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 8
Error10.7
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-51} \lor \neg \left(y \leq 2.2 \cdot 10^{+21}\right):\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 9
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 10
Error37.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{-14}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 0.124:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 11
Error47.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023031 
(FPCore (x y z t)
  :name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
  :precision binary64

  :herbie-target
  (+ x (+ (* t (- y z)) (* (- x) (- y z))))

  (+ x (* (- y z) (- t x))))