?

Average Error: 3.0 → 0.7
Time: 6.9s
Precision: binary64
Cost: 969

?

\[ \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^{+116} \lor \neg \left(y \cdot z \leq 10^{+126}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \left(y \cdot z\right) \cdot x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= (* y z) -1e+116) (not (<= (* y z) 1e+126)))
   (* y (* z (- x)))
   (- x (* (* 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) <= -1e+116) || !((y * z) <= 1e+126)) {
		tmp = y * (z * -x);
	} else {
		tmp = x - ((y * z) * x);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (((y * z) <= (-1d+116)) .or. (.not. ((y * z) <= 1d+126))) then
        tmp = y * (z * -x)
    else
        tmp = x - ((y * z) * x)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
public static double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -1e+116) || !((y * z) <= 1e+126)) {
		tmp = y * (z * -x);
	} else {
		tmp = x - ((y * z) * x);
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - (y * z))
def code(x, y, z):
	tmp = 0
	if ((y * z) <= -1e+116) or not ((y * z) <= 1e+126):
		tmp = y * (z * -x)
	else:
		tmp = x - ((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) <= -1e+116) || !(Float64(y * z) <= 1e+126))
		tmp = Float64(y * Float64(z * Float64(-x)));
	else
		tmp = Float64(x - Float64(Float64(y * z) * x));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((y * z) <= -1e+116) || ~(((y * z) <= 1e+126)))
		tmp = y * (z * -x);
	else
		tmp = x - ((y * z) * x);
	end
	tmp_2 = 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+116], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1e+126]], $MachinePrecision]], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+116} \lor \neg \left(y \cdot z \leq 10^{+126}\right):\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 y z) < -1.00000000000000002e116 or 9.99999999999999925e125 < (*.f64 y z)

    1. Initial program 14.6

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

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

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

      [Start]3.0

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

      mul-1-neg [=>]3.0

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

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

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

      distribute-lft-neg-in [=>]3.0

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

    if -1.00000000000000002e116 < (*.f64 y z) < 9.99999999999999925e125

    1. Initial program 0.1

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Applied egg-rr4.5

      \[\leadsto \color{blue}{\frac{\left(1 - {\left(y \cdot z\right)}^{3}\right) \cdot x}{1 + \left(y \cdot z + {\left(y \cdot z\right)}^{2}\right)}} \]
    3. Taylor expanded in y around 0 5.3

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

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

      [Start]5.3

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

      +-commutative [=>]5.3

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

      mul-1-neg [=>]5.3

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

      unsub-neg [=>]5.3

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

      associate-*r* [=>]0.1

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

      *-commutative [=>]0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+116} \lor \neg \left(y \cdot z \leq 10^{+126}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - \left(y \cdot z\right) \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost969
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+116} \lor \neg \left(y \cdot z \leq 10^{+126}\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.7
Cost649
\[\begin{array}{l} \mathbf{if}\;y \leq -6 \cdot 10^{+45} \lor \neg \left(y \leq 5.9 \cdot 10^{-142}\right):\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error17.7
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+46}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \mathbf{elif}\;y \leq 5.9 \cdot 10^{-142}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \end{array} \]
Alternative 4
Error25.6
Cost64
\[x \]

Error

Reproduce?

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