Average Error: 0.0 → 0.0
Time: 10.4s
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)): 1 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
Error27.1
Cost2168
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(1 - y\right)\\ t_3 := z \cdot \left(x - t\right)\\ t_4 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;t \leq -6.2 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.7 \cdot 10^{+76}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq -5.4 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -9.8 \cdot 10^{-119}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -6.4 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -6.8 \cdot 10^{-183}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq -1.6 \cdot 10^{-185}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.5 \cdot 10^{-222}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -8.2 \cdot 10^{-238}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{-181}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.1 \cdot 10^{-148}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.35 \cdot 10^{-91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.7 \cdot 10^{-68}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{-48}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error40.9
Cost1444
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := z \cdot \left(-t\right)\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-49}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-141}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-238}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-272}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-76}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.18 \cdot 10^{+52}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+55}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error26.1
Cost1112
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+152}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9 \cdot 10^{+55}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.06 \cdot 10^{-78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error24.0
Cost1112
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -1.32 \cdot 10^{-11}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-127}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-240}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-17}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error20.3
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -1.8 \cdot 10^{-26}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-160}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{-280}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-75}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-6}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10.5:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error10.5
Cost976
\[\begin{array}{l} t_1 := x + z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-121}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{-45}:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq 9.4 \cdot 10^{-34}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error39.0
Cost916
\[\begin{array}{l} \mathbf{if}\;y \leq -1.75 \cdot 10^{-26}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{-216}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-279}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 1.08 \cdot 10^{-35}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+199}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 8
Error22.3
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -5.3 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-164}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-258}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 0.0022:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error39.4
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 1.08 \cdot 10^{-252}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{-101}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 10
Error29.0
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9 \cdot 10^{+52}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 9 \cdot 10^{+52}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error17.8
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -2.75 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-48}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 10^{-17}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error13.2
Cost712
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -52000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+39}:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error11.0
Cost712
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 14.5:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 15
Error38.2
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{-26}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-37}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 16
Error47.5
Cost64
\[x \]

Error

Reproduce

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