Average Error: 0.0 → 0.0
Time: 11.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
Error32.2
Cost1361
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{+200}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -2 \cdot 10^{+164}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;y - z \leq -4 \cdot 10^{-197} \lor \neg \left(y - z \leq 2 \cdot 10^{-37}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error44.6
Cost1313
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;t \leq -1.75 \cdot 10^{+117}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.6 \cdot 10^{+24}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;t \leq -1.48 \cdot 10^{-117}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.8 \cdot 10^{-287}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.75 \cdot 10^{-216}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 2.9 \cdot 10^{-126}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{+172} \lor \neg \left(t \leq 4.4 \cdot 10^{+195}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 3
Error26.6
Cost1112
\[\begin{array}{l} t_1 := x + z \cdot x\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;t \leq -1.16 \cdot 10^{-63}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.15 \cdot 10^{-96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1 \cdot 10^{-117}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.45 \cdot 10^{-213}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 7.9 \cdot 10^{-215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.5 \cdot 10^{-38}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error18.6
Cost980
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -4.2 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.5 \cdot 10^{-16}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-73}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 0.0003:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq 3.25 \cdot 10^{+44}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error18.6
Cost978
\[\begin{array}{l} \mathbf{if}\;t \leq -6.8 \cdot 10^{-63} \lor \neg \left(t \leq -8 \cdot 10^{-97} \lor \neg \left(t \leq -1.85 \cdot 10^{-116}\right) \land t \leq 5.8 \cdot 10^{-36}\right):\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \end{array} \]
Alternative 6
Error11.9
Cost976
\[\begin{array}{l} t_1 := x \cdot \left(\left(z + 1\right) - y\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := x + t_2\\ \mathbf{if}\;t \leq -1.2 \cdot 10^{-63}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -8 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.5 \cdot 10^{-116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-126}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error27.2
Cost848
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;t \leq -3.25 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.4 \cdot 10^{-265}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5.1 \cdot 10^{-219}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 1.3 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error27.1
Cost848
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;t \leq -2.1 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.2 \cdot 10^{-265}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5.3 \cdot 10^{-219}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;t \leq 3.8 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error38.2
Cost588
\[\begin{array}{l} \mathbf{if}\;y \leq -1.42 \cdot 10^{+32}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;y \leq -3.9 \cdot 10^{-16}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 10
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 11
Error38.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{-16}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{-67}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 12
Error47.4
Cost64
\[x \]

Error

Reproduce

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