Average Error: 0.0 → 0.0
Time: 11.9s
Precision: binary64
Cost: 7104
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
\[\mathsf{fma}\left(t, y - z, x \cdot \left(1 + \left(z - y\right)\right)\right) \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
(FPCore (x y z t) :precision binary64 (fma t (- y z) (* x (+ 1.0 (- z y)))))
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(t, (y - z), (x * (1.0 + (z - y))));
}
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(t, Float64(y - z), Float64(x * Float64(1.0 + Float64(z - y))))
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[(t * N[(y - z), $MachinePrecision] + N[(x * N[(1.0 + N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x + \left(y - z\right) \cdot \left(t - x\right)
\mathsf{fma}\left(t, y - z, x \cdot \left(1 + \left(z - y\right)\right)\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. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{t \cdot \left(y - z\right) + \left(1 + -1 \cdot \left(y - z\right)\right) \cdot x} \]
  3. Simplified0.0

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

    [Start]0.0

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

    fma-def [=>]0.0

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

    *-commutative [=>]0.0

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

    mul-1-neg [=>]0.0

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

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

Alternatives

Alternative 1
Error0.0
Cost6848
\[\mathsf{fma}\left(y - z, t - x, x\right) \]
Alternative 2
Error29.0
Cost2920
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := t \cdot \left(y - z\right)\\ t_3 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{+187}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq -1 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{-51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 10^{-61}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y - z \leq 0.2:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+46}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{+49}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 10^{+258}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error18.0
Cost1505
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ t_2 := x + y \cdot \left(t - x\right)\\ \mathbf{if}\;t \leq -1.4 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.5 \cdot 10^{-96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{-174}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 3.1 \cdot 10^{-58}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;t \leq 4 \cdot 10^{-15} \lor \neg \left(t \leq 5.5 \cdot 10^{+87}\right) \land t \leq 1.45 \cdot 10^{+151}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error22.7
Cost1376
\[\begin{array}{l} t_1 := x + t \cdot y\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := z \cdot \left(x - t\right)\\ t_4 := x + z \cdot x\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{+23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-39}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-221}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-100}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-87}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-73}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 5.3 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error29.2
Cost1360
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 10^{-61}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y - z \leq 0.2:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error23.3
Cost1244
\[\begin{array}{l} t_1 := x + z \cdot x\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := t \cdot \left(y - z\right)\\ \mathbf{if}\;y \leq -5.7 \cdot 10^{+23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-86}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -4.7 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.2 \cdot 10^{-221}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-61}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 0.00036:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error29.9
Cost1112
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -8 \cdot 10^{+190}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{-101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-234}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-170}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.05 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+244}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 8
Error38.7
Cost1048
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+104}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -0.108:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-235}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-172}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-48}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+243}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 9
Error25.3
Cost980
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -0.86:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-234}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-15}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+219}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error0.0
Cost832
\[x \cdot \left(\left(z + 1\right) - y\right) - t \cdot \left(z - y\right) \]
Alternative 11
Error38.9
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{-87}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-73}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-62}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-21}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 12
Error10.7
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3 \lor \neg \left(z \leq 5.3 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 13
Error11.5
Cost712
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -6.4 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-73}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + t_1\\ \end{array} \]
Alternative 14
Error0.0
Cost576
\[x + \left(z - y\right) \cdot \left(x - t\right) \]
Alternative 15
Error47.5
Cost64
\[x \]

Error

Reproduce

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