Average Error: 0.0 → 0.0
Time: 13.2s
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
    (fma.f64 (-.f64 y z) (-.f64 t x) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y z) (-.f64 t x)) x)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (-.f64 y z) (-.f64 t x)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error30.3
Cost1883
\[\begin{array}{l} \mathbf{if}\;y - z \leq -5 \cdot 10^{-53} \lor \neg \left(y - z \leq -6 \cdot 10^{-87} \lor \neg \left(y - z \leq -5 \cdot 10^{-139}\right) \land \left(y - z \leq 2 \cdot 10^{-79} \lor \neg \left(y - z \leq 10^{-57}\right) \land y - z \leq 5 \cdot 10^{-32}\right)\right):\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error41.1
Cost1313
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -7.6 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-53}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-97}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-179}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-170}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-44}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+63} \lor \neg \left(z \leq 5.6 \cdot 10^{+141}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error23.9
Cost1112
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y \leq -1.25 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{-56}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{-198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-244}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+30}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error19.4
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y \leq -1.25 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.6 \cdot 10^{-54}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{-101}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-121}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-79}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{+30}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error41.0
Cost1049
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-178}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3 \cdot 10^{-43}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+59} \lor \neg \left(z \leq 5.6 \cdot 10^{+141}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Error11.0
Cost978
\[\begin{array}{l} \mathbf{if}\;z \leq -3.1 \cdot 10^{-7} \lor \neg \left(z \leq 4.4 \cdot 10^{-25} \lor \neg \left(z \leq 0.0062\right) \land z \leq 4.6 \cdot 10^{+25}\right):\\ \;\;\;\;x - z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 7
Error25.6
Cost849
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-33}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-92} \lor \neg \left(x \leq 2 \cdot 10^{+90}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 8
Error25.3
Cost848
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -8.8 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-30}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{+73}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 9
Error0.0
Cost832
\[x + \left(y \cdot \left(t - x\right) - z \cdot \left(t - x\right)\right) \]
Alternative 10
Error11.6
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+34} \lor \neg \left(z \leq 7 \cdot 10^{+27}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error25.6
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -6.1 \cdot 10^{+24} \lor \neg \left(x \leq 2 \cdot 10^{+90}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.7
Cost457
\[\begin{array}{l} \mathbf{if}\;y \leq -1.02 \cdot 10^{-55} \lor \neg \left(y \leq 1.35 \cdot 10^{-79}\right):\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error47.5
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022340 
(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))))