Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A

Percentage Accurate: 100.0% → 100.0%
Time: 4.2s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot \left(y + -1\right) - y \cdot 0.5\right) + 0.918938533204673 \end{array} \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (+ y -1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
	return ((x * (y + -1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * (y + (-1.0d0))) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
	return ((x * (y + -1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y):
	return ((x * (y + -1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y + -1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function tmp = code(x, y)
	tmp = ((x * (y + -1.0)) - (y * 0.5)) + 0.918938533204673;
end
code[x_, y_] := N[(N[(N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot \left(y + -1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  2. Add Preprocessing
  3. Final simplification100.0%

    \[\leadsto \left(x \cdot \left(y + -1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  4. Add Preprocessing

Alternative 2: 73.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.2 \cdot 10^{+123}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -8:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+114} \lor \neg \left(y \leq 6.8 \cdot 10^{+225}\right) \land \left(y \leq 1.2 \cdot 10^{+268} \lor \neg \left(y \leq 5.8 \cdot 10^{+292}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -4.2e+123)
   (* x y)
   (if (<= y -8.0)
     (* y -0.5)
     (if (<= y 1.0)
       (- 0.918938533204673 x)
       (if (or (<= y 7.5e+114)
               (and (not (<= y 6.8e+225))
                    (or (<= y 1.2e+268) (not (<= y 5.8e+292)))))
         (* x y)
         (* y -0.5))))))
double code(double x, double y) {
	double tmp;
	if (y <= -4.2e+123) {
		tmp = x * y;
	} else if (y <= -8.0) {
		tmp = y * -0.5;
	} else if (y <= 1.0) {
		tmp = 0.918938533204673 - x;
	} else if ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292)))) {
		tmp = x * y;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-4.2d+123)) then
        tmp = x * y
    else if (y <= (-8.0d0)) then
        tmp = y * (-0.5d0)
    else if (y <= 1.0d0) then
        tmp = 0.918938533204673d0 - x
    else if ((y <= 7.5d+114) .or. (.not. (y <= 6.8d+225)) .and. (y <= 1.2d+268) .or. (.not. (y <= 5.8d+292))) then
        tmp = x * y
    else
        tmp = y * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -4.2e+123) {
		tmp = x * y;
	} else if (y <= -8.0) {
		tmp = y * -0.5;
	} else if (y <= 1.0) {
		tmp = 0.918938533204673 - x;
	} else if ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292)))) {
		tmp = x * y;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -4.2e+123:
		tmp = x * y
	elif y <= -8.0:
		tmp = y * -0.5
	elif y <= 1.0:
		tmp = 0.918938533204673 - x
	elif (y <= 7.5e+114) or (not (y <= 6.8e+225) and ((y <= 1.2e+268) or not (y <= 5.8e+292))):
		tmp = x * y
	else:
		tmp = y * -0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -4.2e+123)
		tmp = Float64(x * y);
	elseif (y <= -8.0)
		tmp = Float64(y * -0.5);
	elseif (y <= 1.0)
		tmp = Float64(0.918938533204673 - x);
	elseif ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292))))
		tmp = Float64(x * y);
	else
		tmp = Float64(y * -0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -4.2e+123)
		tmp = x * y;
	elseif (y <= -8.0)
		tmp = y * -0.5;
	elseif (y <= 1.0)
		tmp = 0.918938533204673 - x;
	elseif ((y <= 7.5e+114) || (~((y <= 6.8e+225)) && ((y <= 1.2e+268) || ~((y <= 5.8e+292)))))
		tmp = x * y;
	else
		tmp = y * -0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -4.2e+123], N[(x * y), $MachinePrecision], If[LessEqual[y, -8.0], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 1.0], N[(0.918938533204673 - x), $MachinePrecision], If[Or[LessEqual[y, 7.5e+114], And[N[Not[LessEqual[y, 6.8e+225]], $MachinePrecision], Or[LessEqual[y, 1.2e+268], N[Not[LessEqual[y, 5.8e+292]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+123}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq -8:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;y \leq 1:\\
\;\;\;\;0.918938533204673 - x\\

\mathbf{elif}\;y \leq 7.5 \cdot 10^{+114} \lor \neg \left(y \leq 6.8 \cdot 10^{+225}\right) \land \left(y \leq 1.2 \cdot 10^{+268} \lor \neg \left(y \leq 5.8 \cdot 10^{+292}\right)\right):\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.19999999999999988e123 or 1 < y < 7.5000000000000001e114 or 6.80000000000000037e225 < y < 1.2e268 or 5.79999999999999981e292 < y

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 97.9%

      \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
    6. Taylor expanded in x around inf 63.0%

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Step-by-step derivation
      1. *-commutative63.0%

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified63.0%

      \[\leadsto \color{blue}{y \cdot x} \]

    if -4.19999999999999988e123 < y < -8 or 7.5000000000000001e114 < y < 6.80000000000000037e225 or 1.2e268 < y < 5.79999999999999981e292

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 99.1%

      \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
    6. Taylor expanded in x around 0 63.5%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]

    if -8 < y < 1

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 97.0%

      \[\leadsto \color{blue}{0.918938533204673 + -1 \cdot x} \]
    6. Step-by-step derivation
      1. neg-mul-197.0%

        \[\leadsto 0.918938533204673 + \color{blue}{\left(-x\right)} \]
      2. sub-neg97.0%

        \[\leadsto \color{blue}{0.918938533204673 - x} \]
    7. Simplified97.0%

      \[\leadsto \color{blue}{0.918938533204673 - x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.2 \cdot 10^{+123}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -8:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+114} \lor \neg \left(y \leq 6.8 \cdot 10^{+225}\right) \land \left(y \leq 1.2 \cdot 10^{+268} \lor \neg \left(y \leq 5.8 \cdot 10^{+292}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y + -1\right)\\ \mathbf{if}\;x \leq -0.0034:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-298}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-188}:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-142}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 55:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* x (+ y -1.0))))
   (if (<= x -0.0034)
     t_0
     (if (<= x -2.3e-298)
       (* y -0.5)
       (if (<= x 5.3e-188)
         (- 0.918938533204673 x)
         (if (<= x 1.6e-142)
           (* y -0.5)
           (if (<= x 55.0) (- 0.918938533204673 x) t_0)))))))
double code(double x, double y) {
	double t_0 = x * (y + -1.0);
	double tmp;
	if (x <= -0.0034) {
		tmp = t_0;
	} else if (x <= -2.3e-298) {
		tmp = y * -0.5;
	} else if (x <= 5.3e-188) {
		tmp = 0.918938533204673 - x;
	} else if (x <= 1.6e-142) {
		tmp = y * -0.5;
	} else if (x <= 55.0) {
		tmp = 0.918938533204673 - x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x * (y + (-1.0d0))
    if (x <= (-0.0034d0)) then
        tmp = t_0
    else if (x <= (-2.3d-298)) then
        tmp = y * (-0.5d0)
    else if (x <= 5.3d-188) then
        tmp = 0.918938533204673d0 - x
    else if (x <= 1.6d-142) then
        tmp = y * (-0.5d0)
    else if (x <= 55.0d0) then
        tmp = 0.918938533204673d0 - x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x * (y + -1.0);
	double tmp;
	if (x <= -0.0034) {
		tmp = t_0;
	} else if (x <= -2.3e-298) {
		tmp = y * -0.5;
	} else if (x <= 5.3e-188) {
		tmp = 0.918938533204673 - x;
	} else if (x <= 1.6e-142) {
		tmp = y * -0.5;
	} else if (x <= 55.0) {
		tmp = 0.918938533204673 - x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x * (y + -1.0)
	tmp = 0
	if x <= -0.0034:
		tmp = t_0
	elif x <= -2.3e-298:
		tmp = y * -0.5
	elif x <= 5.3e-188:
		tmp = 0.918938533204673 - x
	elif x <= 1.6e-142:
		tmp = y * -0.5
	elif x <= 55.0:
		tmp = 0.918938533204673 - x
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(x * Float64(y + -1.0))
	tmp = 0.0
	if (x <= -0.0034)
		tmp = t_0;
	elseif (x <= -2.3e-298)
		tmp = Float64(y * -0.5);
	elseif (x <= 5.3e-188)
		tmp = Float64(0.918938533204673 - x);
	elseif (x <= 1.6e-142)
		tmp = Float64(y * -0.5);
	elseif (x <= 55.0)
		tmp = Float64(0.918938533204673 - x);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x * (y + -1.0);
	tmp = 0.0;
	if (x <= -0.0034)
		tmp = t_0;
	elseif (x <= -2.3e-298)
		tmp = y * -0.5;
	elseif (x <= 5.3e-188)
		tmp = 0.918938533204673 - x;
	elseif (x <= 1.6e-142)
		tmp = y * -0.5;
	elseif (x <= 55.0)
		tmp = 0.918938533204673 - x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0034], t$95$0, If[LessEqual[x, -2.3e-298], N[(y * -0.5), $MachinePrecision], If[LessEqual[x, 5.3e-188], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[x, 1.6e-142], N[(y * -0.5), $MachinePrecision], If[LessEqual[x, 55.0], N[(0.918938533204673 - x), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -0.0034:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -2.3 \cdot 10^{-298}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;x \leq 5.3 \cdot 10^{-188}:\\
\;\;\;\;0.918938533204673 - x\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{-142}:\\
\;\;\;\;y \cdot -0.5\\

\mathbf{elif}\;x \leq 55:\\
\;\;\;\;0.918938533204673 - x\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.00339999999999999981 or 55 < x

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 98.7%

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

    if -0.00339999999999999981 < x < -2.3000000000000001e-298 or 5.30000000000000014e-188 < x < 1.5999999999999999e-142

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 68.5%

      \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
    6. Taylor expanded in x around 0 67.1%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]

    if -2.3000000000000001e-298 < x < 5.30000000000000014e-188 or 1.5999999999999999e-142 < x < 55

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 64.5%

      \[\leadsto \color{blue}{0.918938533204673 + -1 \cdot x} \]
    6. Step-by-step derivation
      1. neg-mul-164.5%

        \[\leadsto 0.918938533204673 + \color{blue}{\left(-x\right)} \]
      2. sub-neg64.5%

        \[\leadsto \color{blue}{0.918938533204673 - x} \]
    7. Simplified64.5%

      \[\leadsto \color{blue}{0.918938533204673 - x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0034:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-298}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-188}:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-142}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 55:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.35 \lor \neg \left(y \leq 1.2\right):\\ \;\;\;\;y \cdot \left(x - 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -1.35) (not (<= y 1.2)))
   (* y (- x 0.5))
   (- 0.918938533204673 x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -1.35) || !(y <= 1.2)) {
		tmp = y * (x - 0.5);
	} else {
		tmp = 0.918938533204673 - x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-1.35d0)) .or. (.not. (y <= 1.2d0))) then
        tmp = y * (x - 0.5d0)
    else
        tmp = 0.918938533204673d0 - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -1.35) || !(y <= 1.2)) {
		tmp = y * (x - 0.5);
	} else {
		tmp = 0.918938533204673 - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -1.35) or not (y <= 1.2):
		tmp = y * (x - 0.5)
	else:
		tmp = 0.918938533204673 - x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -1.35) || !(y <= 1.2))
		tmp = Float64(y * Float64(x - 0.5));
	else
		tmp = Float64(0.918938533204673 - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -1.35) || ~((y <= 1.2)))
		tmp = y * (x - 0.5);
	else
		tmp = 0.918938533204673 - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -1.35], N[Not[LessEqual[y, 1.2]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \lor \neg \left(y \leq 1.2\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.3500000000000001 or 1.19999999999999996 < y

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 98.4%

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

    if -1.3500000000000001 < y < 1.19999999999999996

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 97.0%

      \[\leadsto \color{blue}{0.918938533204673 + -1 \cdot x} \]
    6. Step-by-step derivation
      1. neg-mul-197.0%

        \[\leadsto 0.918938533204673 + \color{blue}{\left(-x\right)} \]
      2. sub-neg97.0%

        \[\leadsto \color{blue}{0.918938533204673 - x} \]
    7. Simplified97.0%

      \[\leadsto \color{blue}{0.918938533204673 - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.35 \lor \neg \left(y \leq 1.2\right):\\ \;\;\;\;y \cdot \left(x - 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.68 \lor \neg \left(x \leq 0.65\right):\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - y \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -0.68) (not (<= x 0.65)))
   (* x (+ y -1.0))
   (- 0.918938533204673 (* y 0.5))))
double code(double x, double y) {
	double tmp;
	if ((x <= -0.68) || !(x <= 0.65)) {
		tmp = x * (y + -1.0);
	} else {
		tmp = 0.918938533204673 - (y * 0.5);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-0.68d0)) .or. (.not. (x <= 0.65d0))) then
        tmp = x * (y + (-1.0d0))
    else
        tmp = 0.918938533204673d0 - (y * 0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -0.68) || !(x <= 0.65)) {
		tmp = x * (y + -1.0);
	} else {
		tmp = 0.918938533204673 - (y * 0.5);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -0.68) or not (x <= 0.65):
		tmp = x * (y + -1.0)
	else:
		tmp = 0.918938533204673 - (y * 0.5)
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -0.68) || !(x <= 0.65))
		tmp = Float64(x * Float64(y + -1.0));
	else
		tmp = Float64(0.918938533204673 - Float64(y * 0.5));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -0.68) || ~((x <= 0.65)))
		tmp = x * (y + -1.0);
	else
		tmp = 0.918938533204673 - (y * 0.5);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -0.68], N[Not[LessEqual[x, 0.65]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.68 \lor \neg \left(x \leq 0.65\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\

\mathbf{else}:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.680000000000000049 or 0.650000000000000022 < x

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 99.4%

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

    if -0.680000000000000049 < x < 0.650000000000000022

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 98.4%

      \[\leadsto \color{blue}{0.918938533204673 - 0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.68 \lor \neg \left(x \leq 0.65\right):\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - y \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 49.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.5 \lor \neg \left(x \leq 0.5\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -0.5) (not (<= x 0.5))) (* x y) (* y -0.5)))
double code(double x, double y) {
	double tmp;
	if ((x <= -0.5) || !(x <= 0.5)) {
		tmp = x * y;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-0.5d0)) .or. (.not. (x <= 0.5d0))) then
        tmp = x * y
    else
        tmp = y * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -0.5) || !(x <= 0.5)) {
		tmp = x * y;
	} else {
		tmp = y * -0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -0.5) or not (x <= 0.5):
		tmp = x * y
	else:
		tmp = y * -0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -0.5) || !(x <= 0.5))
		tmp = Float64(x * y);
	else
		tmp = Float64(y * -0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -0.5) || ~((x <= 0.5)))
		tmp = x * y;
	else
		tmp = y * -0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -0.5], N[Not[LessEqual[x, 0.5]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.5 \lor \neg \left(x \leq 0.5\right):\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.5 or 0.5 < x

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 54.2%

      \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
    6. Taylor expanded in x around inf 53.6%

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Step-by-step derivation
      1. *-commutative53.6%

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified53.6%

      \[\leadsto \color{blue}{y \cdot x} \]

    if -0.5 < x < 0.5

    1. Initial program 100.0%

      \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
    2. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
      3. metadata-eval100.0%

        \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 51.5%

      \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
    6. Taylor expanded in x around 0 50.5%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.5 \lor \neg \left(x \leq 0.5\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 26.5% accurate, 3.7× speedup?

\[\begin{array}{l} \\ y \cdot -0.5 \end{array} \]
(FPCore (x y) :precision binary64 (* y -0.5))
double code(double x, double y) {
	return y * -0.5;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = y * (-0.5d0)
end function
public static double code(double x, double y) {
	return y * -0.5;
}
def code(x, y):
	return y * -0.5
function code(x, y)
	return Float64(y * -0.5)
end
function tmp = code(x, y)
	tmp = y * -0.5;
end
code[x_, y_] := N[(y * -0.5), $MachinePrecision]
\begin{array}{l}

\\
y \cdot -0.5
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
  2. Step-by-step derivation
    1. associate-+l-100.0%

      \[\leadsto \color{blue}{x \cdot \left(y - 1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
    2. sub-neg100.0%

      \[\leadsto x \cdot \color{blue}{\left(y + \left(-1\right)\right)} - \left(y \cdot 0.5 - 0.918938533204673\right) \]
    3. metadata-eval100.0%

      \[\leadsto x \cdot \left(y + \color{blue}{-1}\right) - \left(y \cdot 0.5 - 0.918938533204673\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{x \cdot \left(y + -1\right) - \left(y \cdot 0.5 - 0.918938533204673\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in y around inf 52.8%

    \[\leadsto \color{blue}{y \cdot \left(x - 0.5\right)} \]
  6. Taylor expanded in x around 0 27.1%

    \[\leadsto \color{blue}{-0.5 \cdot y} \]
  7. Final simplification27.1%

    \[\leadsto y \cdot -0.5 \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024055 
(FPCore (x y)
  :name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
  :precision binary64
  (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))