?

Average Error: 3.4 → 0.6
Time: 7.2s
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 -1 \cdot 10^{+220} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+107}\right):\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\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) -1e+220) (not (<= (* y z) 2e+107)))
   (* y (* x (- z)))
   (* 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) <= -1e+220) || !((y * z) <= 2e+107)) {
		tmp = y * (x * -z);
	} 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) <= -1e+220) || !(Float64(y * z) <= 2e+107))
		tmp = Float64(y * Float64(x * Float64(-z)));
	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], -1e+220], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e+107]], $MachinePrecision]], N[(y * N[(x * (-z)), $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 -1 \cdot 10^{+220} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+107}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\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) < -1e220 or 1.9999999999999999e107 < (*.f64 y z)

    1. Initial program 19.7

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

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

      [Start]19.7

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

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

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

      +-commutative [=>]19.7

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

      *-commutative [=>]19.7

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

      fma-def [=>]19.7

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

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

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

      [Start]3.1

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

      associate-*r* [=>]3.1

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

      *-commutative [=>]3.1

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

      mul-1-neg [=>]3.1

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

    if -1e220 < (*.f64 y z) < 1.9999999999999999e107

    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.6

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

Alternatives

Alternative 1
Error18.7
Cost1176
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{if}\;y \leq -6 \cdot 10^{+167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.7 \cdot 10^{+103}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{+55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-34}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 3.65 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.6
Cost969
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+220} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{+107}\right):\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \end{array} \]
Alternative 3
Error17.7
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{-124} \lor \neg \left(z \leq 9 \cdot 10^{+89}\right):\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error16.4
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{-124}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;z \leq 10^{+120}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \]
Alternative 5
Error24.8
Cost64
\[x \]

Error

Reproduce?

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