?

Average Error: 0.0 → 0.0
Time: 9.5s
Precision: binary64
Cost: 7168

?

\[x + \left(y - z\right) \cdot \left(t - x\right) \]
\[x + \mathsf{fma}\left(t - x, -z, \left(t - x\right) \cdot y\right) \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
(FPCore (x y z t) :precision binary64 (+ x (fma (- t x) (- z) (* (- t x) 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 x + fma((t - x), -z, ((t - x) * 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 Float64(x + fma(Float64(t - x), Float64(-z), Float64(Float64(t - x) * 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[(x + N[(N[(t - x), $MachinePrecision] * (-z) + N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x + \left(y - z\right) \cdot \left(t - x\right)
x + \mathsf{fma}\left(t - x, -z, \left(t - x\right) \cdot y\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 y around 0 0.0

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

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

    [Start]0.0

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

    mul-1-neg [=>]0.0

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

    *-commutative [=>]0.0

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

    distribute-rgt-neg-out [<=]0.0

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

    fma-def [=>]0.0

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

    *-commutative [=>]0.0

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

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

Alternatives

Alternative 1
Error40.4
Cost1576
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ t_2 := x \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+219}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-16}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -3.15 \cdot 10^{-77}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.5 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-302}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+42}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.37 \cdot 10^{+228}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 2
Error30.6
Cost1112
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ t_2 := \left(t - x\right) \cdot y\\ \mathbf{if}\;y \leq -9.6 \cdot 10^{-17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-77}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-195}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.2 \cdot 10^{-303}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-140}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{-58}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error26.3
Cost1112
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ t_2 := \left(t - x\right) \cdot y\\ t_3 := x + t \cdot y\\ \mathbf{if}\;y \leq -4.6 \cdot 10^{+44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-161}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{-303}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-216}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error40.3
Cost984
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -3.4 \cdot 10^{-16}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-77}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-303}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-58}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 5
Error15.1
Cost976
\[\begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ t_2 := x + t \cdot \left(y - z\right)\\ \mathbf{if}\;y \leq -7 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-211}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-307}:\\ \;\;\;\;x + x \cdot z\\ \mathbf{elif}\;y \leq 2.95 \cdot 10^{+28}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error10.5
Cost976
\[\begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ t_2 := x + t \cdot \left(y - z\right)\\ \mathbf{if}\;y \leq -1.05 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-87}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-110}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+28}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error10.1
Cost976
\[\begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ t_2 := x + t \cdot \left(y - z\right)\\ \mathbf{if}\;y \leq -5.5 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-106}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-9}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x + t_1\\ \end{array} \]
Alternative 8
Error20.0
Cost848
\[\begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ t_2 := x - t \cdot z\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-211}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-307}:\\ \;\;\;\;x + x \cdot z\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-57}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error21.3
Cost716
\[\begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ \mathbf{if}\;y \leq -7.6 \cdot 10^{-16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-111}:\\ \;\;\;\;x + x \cdot z\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x + t \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error13.3
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+15} \lor \neg \left(x \leq 1.35 \cdot 10^{-12}\right):\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot \left(y - z\right)\\ \end{array} \]
Alternative 11
Error0.0
Cost576
\[x + \left(t - x\right) \cdot \left(y - z\right) \]
Alternative 12
Error38.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{-17}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-57}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
Alternative 13
Error47.7
Cost64
\[x \]

Error

Reproduce?

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