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

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

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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    mul-1-neg [=>]0.0

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

    unsub-neg [=>]0.0

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

    *-commutative [=>]0.0

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

    +-commutative [=>]0.0

    \[ t \cdot \left(y - z\right) - x \cdot \left(y - \color{blue}{\left(z + 1\right)}\right) \]
  4. Applied egg-rr0.2

    \[\leadsto \color{blue}{\frac{1}{\frac{1}{t \cdot \left(y - z\right) - x \cdot \left(y + \left(-1 - z\right)\right)}}} \]
  5. Applied egg-rr0.0

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

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

    [Start]0.0

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

    *-commutative [<=]0.0

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

    *-commutative [<=]0.0

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

    fma-def [=>]0.0

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

    *-commutative [=>]0.0

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

    associate-+l- [=>]0.0

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

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

Alternatives

Alternative 1
Error41.0
Cost1180
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := t \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -0.14:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-261}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-279}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-275}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-94}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+135}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error29.7
Cost1180
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{+200}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{+96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{+51}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+45}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error23.8
Cost1112
\[\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 -2.4 \cdot 10^{-5}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-213}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-251}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 13000000:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error25.1
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y \leq -3.5 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-262}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-278}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-275}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{-94}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq 7.3 \cdot 10^{+40}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error40.2
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{-14}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{-184}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-252}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.25 \cdot 10^{-167}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Error18.6
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x - t \cdot z\\ \mathbf{if}\;y \leq -12:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{-160}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-36}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error0.0
Cost832
\[t \cdot \left(y - z\right) + x \cdot \left(\left(z + 1\right) - y\right) \]
Alternative 8
Error13.4
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -430 \lor \neg \left(y \leq 7 \cdot 10^{+39}\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot \left(y - z\right)\\ \end{array} \]
Alternative 9
Error10.5
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{-5} \lor \neg \left(z \leq 16000000\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 10
Error10.5
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2.3 \cdot 10^{-5} \lor \neg \left(z \leq 13500000\right):\\ \;\;\;\;z \cdot x - t \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error38.7
Cost652
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-37}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+136}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error23.4
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-104} \lor \neg \left(x \leq 6 \cdot 10^{-70}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \end{array} \]
Alternative 13
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 14
Error38.0
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8 \cdot 10^{-65}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-37}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 15
Error47.4
Cost64
\[x \]

Error

Reproduce

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