?

Average Error: 0.04% → 0.03%
Time: 11.7s
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.04%
Target0.04%
Herbie0.03%
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation?

  1. Initial program 0.04

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Simplified0.03

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

    [Start]0.04

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

    +-commutative [=>]0.04

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

    fma-def [=>]0.03

    \[ \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
  3. Final simplification0.03

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

Alternatives

Alternative 1
Error31.09%
Cost3440
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x \cdot \left(z - y\right)\\ t_3 := x + \left(y - z\right) \cdot t\\ t_4 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y - z \leq -2 \cdot 10^{+247}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y - z \leq -4 \cdot 10^{+205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{+176}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y - z \leq -2 \cdot 10^{+82}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -4 \cdot 10^{+24}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y - z \leq -2000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 100000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 10^{+161}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+212}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+225}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 2
Error47.03%
Cost1361
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -1 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -2000:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y - z \leq -2 \cdot 10^{-64} \lor \neg \left(y - z \leq 10^{-101}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error30.42%
Cost980
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -1.02 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-220}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-251}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-6}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.47%
Cost976
\[\begin{array}{l} t_1 := x + \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(z - y\right)\\ t_3 := x + t_2\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{-14}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error31.63%
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-219}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-251}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-64}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error0.04%
Cost832
\[x \cdot \left(z - y\right) + \left(x + \left(y - z\right) \cdot t\right) \]
Alternative 7
Error60.98%
Cost785
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 300000000 \lor \neg \left(z \leq 8.4 \cdot 10^{+96}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 8
Error59.83%
Cost720
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{+146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4 \cdot 10^{+23}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -0.0008:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 9
Error35.39%
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -5.8:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-70}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-64}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error16.06%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -0.6 \lor \neg \left(y \leq 1.56\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error36.93%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-81} \lor \neg \left(x \leq 9 \cdot 10^{-16}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 12
Error0.04%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error59.25%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{-17}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-35}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 14
Error59.62%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 15
Error73.86%
Cost64
\[x \]

Error

Reproduce?

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