?

Average Error: 5.21% → 0.94%
Time: 6.0s
Precision: binary64
Cost: 7304

?

\[ \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^{+161}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;y \cdot z \leq 10^{+124}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* y z) -5e+161)
   (* z (* y (- x)))
   (if (<= (* y z) 1e+124) (* x (fma z (- y) 1.0)) (* y (* z (- x))))))
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+161) {
		tmp = z * (y * -x);
	} else if ((y * z) <= 1e+124) {
		tmp = x * fma(z, -y, 1.0);
	} else {
		tmp = y * (z * -x);
	}
	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+161)
		tmp = Float64(z * Float64(y * Float64(-x)));
	elseif (Float64(y * z) <= 1e+124)
		tmp = Float64(x * fma(z, Float64(-y), 1.0));
	else
		tmp = Float64(y * Float64(z * Float64(-x)));
	end
	return tmp
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+161], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e+124], N[(x * N[(z * (-y) + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+161}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\

\mathbf{elif}\;y \cdot z \leq 10^{+124}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, -y, 1\right)\\

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


\end{array}

Error?

Derivation?

  1. Split input into 3 regimes
  2. if (*.f64 y z) < -4.9999999999999997e161

    1. Initial program 30.16

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Taylor expanded in y around inf 3.32

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

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

      [Start]3.32

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

      mul-1-neg [=>]3.32

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

      *-commutative [=>]3.32

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

      associate-*l* [=>]4.27

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

      distribute-rgt-neg-in [=>]4.27

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

      *-commutative [<=]4.27

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

      distribute-rgt-neg-in [=>]4.27

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

    if -4.9999999999999997e161 < (*.f64 y z) < 9.99999999999999948e123

    1. Initial program 0.13

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

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

      [Start]0.13

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

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

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

      +-commutative [=>]0.13

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

      *-commutative [=>]0.13

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

      fma-def [=>]0.13

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

    if 9.99999999999999948e123 < (*.f64 y z)

    1. Initial program 26.83

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

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

      [Start]26.83

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

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

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

      +-commutative [=>]26.83

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

      *-commutative [=>]26.83

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

      fma-def [=>]26.83

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

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

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

      [Start]4.9

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

      associate-*r* [=>]4.9

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

      *-commutative [=>]4.9

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

      mul-1-neg [=>]4.9

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

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

Alternatives

Alternative 1
Error0.94%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+161}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;y \cdot z \leq 10^{+124}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]
Alternative 2
Error27.88%
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{-74} \lor \neg \left(z \leq 4.3 \cdot 10^{+142}\right):\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error25.87%
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-51} \lor \neg \left(z \leq 2.1 \cdot 10^{+139}\right):\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error26.3%
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-55}:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+148}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]
Alternative 5
Error39.03%
Cost64
\[x \]

Error

Reproduce?

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