?

Average Error: 0.0 → 0.0
Time: 12.6s
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
Error22.5
Cost1244
\[\begin{array}{l} t_1 := x + z \cdot x\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -4.5 \cdot 10^{+30}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-48}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-301}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 2.46 \cdot 10^{-175}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-97}:\\ \;\;\;\;x + t \cdot y\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error38.5
Cost1180
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -6.7 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.4 \cdot 10^{-58}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{-204}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-301}:\\ \;\;\;\;t \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{+82}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.26 \cdot 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 3
Error22.8
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-135}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.32 \cdot 10^{-163}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-194}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-252}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-21}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error38.9
Cost1048
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{+116}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-8}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{-176}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-262}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error22.2
Cost980
\[\begin{array}{l} t_1 := x + z \cdot x\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -4.6 \cdot 10^{+30}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-50}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-201}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-299}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 1.48 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error24.3
Cost849
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.36 \cdot 10^{-45}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{+55} \lor \neg \left(x \leq 3.7 \cdot 10^{+145}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error23.8
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -4.1 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.75 \cdot 10^{-134}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-252}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{-20}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error0.0
Cost832
\[t \cdot \left(y - z\right) - x \cdot \left(y - \left(z + 1\right)\right) \]
Alternative 9
Error29.0
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{+67}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{+18}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+145}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error10.9
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{-8} \lor \neg \left(z \leq 6 \cdot 10^{-15}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error10.3
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -4.1 \cdot 10^{-5} \lor \neg \left(y \leq 12.5\right):\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error37.7
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-57}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 14
Error47.1
Cost64
\[x \]

Error

Reproduce?

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