?

Average Error: 3.2 → 0.4
Time: 6.8s
Precision: binary64
Cost: 7305

?

\[ \begin{array}{c}[y, z] = \mathsf{sort}([y, z])\\ \end{array} \]
\[x \cdot \left(1 - y \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+202} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+143}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= (* y z) -5e+202) (not (<= (* y z) 2e+143)))
   (* y (* z (- x)))
   (* x (fma z (- y) 1.0))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -5e+202) || !((y * z) <= 2e+143)) {
		tmp = y * (z * -x);
	} else {
		tmp = x * fma(z, -y, 1.0);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function code(x, y, z)
	tmp = 0.0
	if ((Float64(y * z) <= -5e+202) || !(Float64(y * z) <= 2e+143))
		tmp = Float64(y * Float64(z * Float64(-x)));
	else
		tmp = Float64(x * fma(z, Float64(-y), 1.0));
	end
	return tmp
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -5e+202], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+143]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(z * (-y) + 1.0), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+202} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+143}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 y z) < -4.9999999999999999e202 or 2e143 < (*.f64 y z)

    1. Initial program 20.1

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Simplified20.1

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

      [Start]20.1

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

      cancel-sign-sub-inv [=>]20.1

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

      +-commutative [=>]20.1

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

      *-commutative [=>]20.1

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

      fma-def [=>]20.1

      \[ x \cdot \color{blue}{\mathsf{fma}\left(z, -y, 1\right)} \]
    3. Taylor expanded in z around inf 2.3

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(z \cdot x\right)\right)} \]
    4. Simplified2.3

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

      [Start]2.3

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

      associate-*r* [=>]2.3

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

      *-commutative [=>]2.3

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

      mul-1-neg [=>]2.3

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

    if -4.9999999999999999e202 < (*.f64 y z) < 2e143

    1. Initial program 0.1

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Simplified0.1

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

      [Start]0.1

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

      cancel-sign-sub-inv [=>]0.1

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

      +-commutative [=>]0.1

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

      *-commutative [=>]0.1

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

      fma-def [=>]0.1

      \[ x \cdot \color{blue}{\mathsf{fma}\left(z, -y, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+202} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+143}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost969
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+202} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+143}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \end{array} \]
Alternative 2
Error18.5
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{-59} \lor \neg \left(z \leq 1.56 \cdot 10^{+149}\right):\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error18.0
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{-50}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+148}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \end{array} \]
Alternative 4
Error17.9
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{-59}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{+148}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \end{array} \]
Alternative 5
Error25.7
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023187 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
  :precision binary64
  (* x (- 1.0 (* y z))))