?

Average Error: 0.0 → 0.0
Time: 9.6s
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
Error39.6
Cost1576
\[\begin{array}{l} t_1 := -z \cdot t\\ \mathbf{if}\;z \leq -2 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-73}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-234}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-265}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-240}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.35 \cdot 10^{-206}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.08 \cdot 10^{-151}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-111}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 10000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+106}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error28.6
Cost1508
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -6.8 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-77}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-232}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-264}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-240}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.95 \cdot 10^{-204}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.05 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 7800000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error23.0
Cost1508
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -1.85 \cdot 10^{+15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-73}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.75 \cdot 10^{-259}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-240}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-206}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 7800000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error39.9
Cost1380
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+15}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{-72}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-233}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{-264}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-240}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-206}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-152}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-111}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 10000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error30.1
Cost1244
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;x \leq -17000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{+23}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.16 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+74}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error22.4
Cost980
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{-76}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.6 \cdot 10^{-208}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 10000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error19.4
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -1.85 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-276}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6.9 \cdot 10^{-242}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 12500000:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error10.8
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.85 \cdot 10^{+15} \lor \neg \left(z \leq 31000000\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 9
Error10.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+15}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;z \leq 23000000:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot x - z \cdot t\\ \end{array} \]
Alternative 10
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 11
Error38.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-31}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 3.15 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 12
Error47.6
Cost64
\[x \]

Error

Reproduce?

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