?

Average Error: 0.0 → 0.0
Time: 12.5s
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
Error34.8
Cost1905
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := t \cdot \left(y - z\right)\\ \mathbf{if}\;t \leq -1.35 \cdot 10^{-5}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.55 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -4.4 \cdot 10^{-120}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.05 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{-163}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -6.5 \cdot 10^{-181}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 1.1 \cdot 10^{-308}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.3 \cdot 10^{-230}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9 \cdot 10^{-187}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 5.4 \cdot 10^{-58} \lor \neg \left(t \leq 5.2 \cdot 10^{+39}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error31.0
Cost1113
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{+178}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{+120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.2:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-158}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+155} \lor \neg \left(z \leq 4.2 \cdot 10^{+224}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error0.0
Cost832
\[x + \left(y \cdot \left(t - x\right) + z \cdot \left(x - t\right)\right) \]
Alternative 5
Error38.8
Cost785
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-73}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+154} \lor \neg \left(z \leq 1.8 \cdot 10^{+226}\right):\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Error23.4
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-153}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+75}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error20.0
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-189}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-73}:\\ \;\;\;\;x + t \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error20.0
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.56 \cdot 10^{-189}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-73}:\\ \;\;\;\;x + t \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error13.0
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.25 \cdot 10^{-11} \lor \neg \left(z \leq 4.4 \cdot 10^{-73}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 10
Error11.3
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -5.6 \cdot 10^{-16} \lor \neg \left(z \leq 3.9 \cdot 10^{-74}\right):\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error40.4
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-147}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+77}:\\ \;\;\;\;t \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.2 \cdot 10^{-16}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{-15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 14
Error47.6
Cost64
\[x \]

Error

Reproduce?

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