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

Percentage Accurate: 99.8% → 99.8%
Time: 2.4s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\begin{array}{l} \\ \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (+ (+ x y) z) (* z (log t))) (* (- a 0.5) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (((x + y) + z) - (z * log(t))) + ((a - 0.5d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * Math.log(t))) + ((a - 0.5) * b);
}
def code(x, y, z, t, a, b):
	return (((x + y) + z) - (z * math.log(t))) + ((a - 0.5) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(Float64(x + y) + z) - Float64(z * log(t))) + Float64(Float64(a - 0.5) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - N[(z * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b
\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 9 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: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (+ (+ x y) z) (* z (log t))) (* (- a 0.5) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (((x + y) + z) - (z * log(t))) + ((a - 0.5d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * Math.log(t))) + ((a - 0.5) * b);
}
def code(x, y, z, t, a, b):
	return (((x + y) + z) - (z * math.log(t))) + ((a - 0.5) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(Float64(x + y) + z) - Float64(z * log(t))) + Float64(Float64(a - 0.5) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - N[(z * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (+ (+ x y) z) (* z (log t))) (* (- a 0.5) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (((x + y) + z) - (z * log(t))) + ((a - 0.5d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return (((x + y) + z) - (z * Math.log(t))) + ((a - 0.5) * b);
}
def code(x, y, z, t, a, b):
	return (((x + y) + z) - (z * math.log(t))) + ((a - 0.5) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(Float64(x + y) + z) - Float64(z * log(t))) + Float64(Float64(a - 0.5) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = (((x + y) + z) - (z * log(t))) + ((a - 0.5) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - N[(z * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 90.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(a - 0.5\right) \cdot b\\ t_2 := \left(x + y\right) + z\\ t_3 := t\_2 + t\_1\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+125}:\\ \;\;\;\;t\_2 - z \cdot \log t\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (- a 0.5) b)) (t_2 (+ (+ x y) z)) (t_3 (+ t_2 t_1)))
   (if (<= t_1 -5e+96) t_3 (if (<= t_1 2e+125) (- t_2 (* z (log t))) t_3))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = (x + y) + z;
	double t_3 = t_2 + t_1;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_3;
	} else if (t_1 <= 2e+125) {
		tmp = t_2 - (z * log(t));
	} else {
		tmp = t_3;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_1 = (a - 0.5d0) * b
    t_2 = (x + y) + z
    t_3 = t_2 + t_1
    if (t_1 <= (-5d+96)) then
        tmp = t_3
    else if (t_1 <= 2d+125) then
        tmp = t_2 - (z * log(t))
    else
        tmp = t_3
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = (x + y) + z;
	double t_3 = t_2 + t_1;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_3;
	} else if (t_1 <= 2e+125) {
		tmp = t_2 - (z * Math.log(t));
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a - 0.5) * b
	t_2 = (x + y) + z
	t_3 = t_2 + t_1
	tmp = 0
	if t_1 <= -5e+96:
		tmp = t_3
	elif t_1 <= 2e+125:
		tmp = t_2 - (z * math.log(t))
	else:
		tmp = t_3
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a - 0.5) * b)
	t_2 = Float64(Float64(x + y) + z)
	t_3 = Float64(t_2 + t_1)
	tmp = 0.0
	if (t_1 <= -5e+96)
		tmp = t_3;
	elseif (t_1 <= 2e+125)
		tmp = Float64(t_2 - Float64(z * log(t)));
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a - 0.5) * b;
	t_2 = (x + y) + z;
	t_3 = t_2 + t_1;
	tmp = 0.0;
	if (t_1 <= -5e+96)
		tmp = t_3;
	elseif (t_1 <= 2e+125)
		tmp = t_2 - (z * log(t));
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 + t$95$1), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+96], t$95$3, If[LessEqual[t$95$1, 2e+125], N[(t$95$2 - N[(z * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(a - 0.5\right) \cdot b\\
t_2 := \left(x + y\right) + z\\
t_3 := t\_2 + t\_1\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+125}:\\
\;\;\;\;t\_2 - z \cdot \log t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < -5.0000000000000004e96 or 1.9999999999999998e125 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b)

    1. Initial program 100.0%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(\left(y + z\right) - z \cdot \log t\right)} + \left(a - \frac{1}{2}\right) \cdot b \]
    4. Applied rewrites93.2%

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

    if -5.0000000000000004e96 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < 1.9999999999999998e125

    1. Initial program 99.8%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites92.2%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 66.4% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(a - 0.5\right) \cdot b\\ t_2 := \left(t\_1 + z\right) + z\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\ \;\;\;\;\left(x + y\right) + z\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (- a 0.5) b)) (t_2 (+ (+ t_1 z) z)))
   (if (<= t_1 -5e+96) t_2 (if (<= t_1 2e+144) (+ (+ x y) z) t_2))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = (t_1 + z) + z;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_2;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (a - 0.5d0) * b
    t_2 = (t_1 + z) + z
    if (t_1 <= (-5d+96)) then
        tmp = t_2
    else if (t_1 <= 2d+144) then
        tmp = (x + y) + z
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = (t_1 + z) + z;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_2;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a - 0.5) * b
	t_2 = (t_1 + z) + z
	tmp = 0
	if t_1 <= -5e+96:
		tmp = t_2
	elif t_1 <= 2e+144:
		tmp = (x + y) + z
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a - 0.5) * b)
	t_2 = Float64(Float64(t_1 + z) + z)
	tmp = 0.0
	if (t_1 <= -5e+96)
		tmp = t_2;
	elseif (t_1 <= 2e+144)
		tmp = Float64(Float64(x + y) + z);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a - 0.5) * b;
	t_2 = (t_1 + z) + z;
	tmp = 0.0;
	if (t_1 <= -5e+96)
		tmp = t_2;
	elseif (t_1 <= 2e+144)
		tmp = (x + y) + z;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 + z), $MachinePrecision] + z), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+96], t$95$2, If[LessEqual[t$95$1, 2e+144], N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(a - 0.5\right) \cdot b\\
t_2 := \left(t\_1 + z\right) + z\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\
\;\;\;\;\left(x + y\right) + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < -5.0000000000000004e96 or 2.00000000000000005e144 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b)

    1. Initial program 100.0%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites22.0%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
    6. Applied rewrites15.6%

      \[\leadsto \left(x + y\right) + \color{blue}{z} \]
    7. Taylor expanded in x around 0

      \[\leadsto \left(x + y\right) + z \]
    8. Applied rewrites80.0%

      \[\leadsto \left(\left(a - 0.5\right) \cdot b + z\right) + z \]

    if -5.0000000000000004e96 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < 2.00000000000000005e144

    1. Initial program 99.8%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites92.3%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
    6. Applied rewrites63.9%

      \[\leadsto \left(x + y\right) + \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 66.3% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(a - 0.5\right) \cdot b\\ t_2 := t\_1 + z\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\ \;\;\;\;\left(x + y\right) + z\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (- a 0.5) b)) (t_2 (+ t_1 z)))
   (if (<= t_1 -5e+96) t_2 (if (<= t_1 2e+144) (+ (+ x y) z) t_2))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = t_1 + z;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_2;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (a - 0.5d0) * b
    t_2 = t_1 + z
    if (t_1 <= (-5d+96)) then
        tmp = t_2
    else if (t_1 <= 2d+144) then
        tmp = (x + y) + z
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double t_2 = t_1 + z;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_2;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a - 0.5) * b
	t_2 = t_1 + z
	tmp = 0
	if t_1 <= -5e+96:
		tmp = t_2
	elif t_1 <= 2e+144:
		tmp = (x + y) + z
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a - 0.5) * b)
	t_2 = Float64(t_1 + z)
	tmp = 0.0
	if (t_1 <= -5e+96)
		tmp = t_2;
	elseif (t_1 <= 2e+144)
		tmp = Float64(Float64(x + y) + z);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a - 0.5) * b;
	t_2 = t_1 + z;
	tmp = 0.0;
	if (t_1 <= -5e+96)
		tmp = t_2;
	elseif (t_1 <= 2e+144)
		tmp = (x + y) + z;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + z), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+96], t$95$2, If[LessEqual[t$95$1, 2e+144], N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(a - 0.5\right) \cdot b\\
t_2 := t\_1 + z\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\
\;\;\;\;\left(x + y\right) + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < -5.0000000000000004e96 or 2.00000000000000005e144 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b)

    1. Initial program 100.0%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites22.0%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - z \cdot \log t \]
    6. Applied rewrites87.0%

      \[\leadsto \left(\left(a - 0.5\right) \cdot b + z\right) - z \cdot \log t \]
    7. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
    8. Applied rewrites80.0%

      \[\leadsto \left(a - 0.5\right) \cdot b + \color{blue}{z} \]

    if -5.0000000000000004e96 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < 2.00000000000000005e144

    1. Initial program 99.8%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites92.3%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
    6. Applied rewrites63.9%

      \[\leadsto \left(x + y\right) + \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 66.2% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(a - 0.5\right) \cdot b\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\ \;\;\;\;\left(x + y\right) + z\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (- a 0.5) b)))
   (if (<= t_1 -5e+96) t_1 (if (<= t_1 2e+144) (+ (+ x y) z) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_1;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (a - 0.5d0) * b
    if (t_1 <= (-5d+96)) then
        tmp = t_1
    else if (t_1 <= 2d+144) then
        tmp = (x + y) + z
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a - 0.5) * b;
	double tmp;
	if (t_1 <= -5e+96) {
		tmp = t_1;
	} else if (t_1 <= 2e+144) {
		tmp = (x + y) + z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a - 0.5) * b
	tmp = 0
	if t_1 <= -5e+96:
		tmp = t_1
	elif t_1 <= 2e+144:
		tmp = (x + y) + z
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a - 0.5) * b)
	tmp = 0.0
	if (t_1 <= -5e+96)
		tmp = t_1;
	elseif (t_1 <= 2e+144)
		tmp = Float64(Float64(x + y) + z);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a - 0.5) * b;
	tmp = 0.0;
	if (t_1 <= -5e+96)
		tmp = t_1;
	elseif (t_1 <= 2e+144)
		tmp = (x + y) + z;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+96], t$95$1, If[LessEqual[t$95$1, 2e+144], N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(a - 0.5\right) \cdot b\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+96}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+144}:\\
\;\;\;\;\left(x + y\right) + z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < -5.0000000000000004e96 or 2.00000000000000005e144 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b)

    1. Initial program 100.0%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites22.0%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - z \cdot \log t \]
    6. Applied rewrites87.0%

      \[\leadsto \left(\left(a - 0.5\right) \cdot b + z\right) - z \cdot \log t \]
    7. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(\left(1 + \left(\frac{y}{x} + \left(\frac{z}{x} + \frac{b \cdot \left(a - \frac{1}{2}\right)}{x}\right)\right)\right) - \frac{z \cdot \log t}{x}\right)} \]
    8. Applied rewrites79.4%

      \[\leadsto \color{blue}{\left(a - 0.5\right) \cdot b} \]

    if -5.0000000000000004e96 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < 2.00000000000000005e144

    1. Initial program 99.8%

      \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
    4. Applied rewrites92.3%

      \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
    5. Taylor expanded in x around 0

      \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
    6. Applied rewrites63.9%

      \[\leadsto \left(x + y\right) + \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 79.8% accurate, 7.0× speedup?

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

\\
\left(\left(x + y\right) + z\right) + \left(a - 0.5\right) \cdot b
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\left(\left(y + z\right) - z \cdot \log t\right)} + \left(a - \frac{1}{2}\right) \cdot b \]
  4. Applied rewrites80.1%

    \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right)} + \left(a - 0.5\right) \cdot b \]
  5. Add Preprocessing

Alternative 7: 79.0% accurate, 8.4× speedup?

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

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

    \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\left(\left(x + \left(y + z\right)\right) - z \cdot \log t\right)} + \left(a - \frac{1}{2}\right) \cdot b \]
  4. Applied rewrites79.3%

    \[\leadsto \color{blue}{\left(x + y\right)} + \left(a - 0.5\right) \cdot b \]
  5. Add Preprocessing

Alternative 8: 43.0% accurate, 18.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) + z \end{array} \]
(FPCore (x y z t a b) :precision binary64 (+ (+ x y) z))
double code(double x, double y, double z, double t, double a, double b) {
	return (x + y) + z;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = (x + y) + z
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return (x + y) + z;
}
def code(x, y, z, t, a, b):
	return (x + y) + z
function code(x, y, z, t, a, b)
	return Float64(Float64(x + y) + z)
end
function tmp = code(x, y, z, t, a, b)
	tmp = (x + y) + z;
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) + z
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
  4. Applied rewrites63.8%

    \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
  5. Taylor expanded in x around 0

    \[\leadsto \left(y + z\right) - \color{blue}{z \cdot \log t} \]
  6. Applied rewrites44.3%

    \[\leadsto \left(x + y\right) + \color{blue}{z} \]
  7. Add Preprocessing

Alternative 9: 42.1% accurate, 31.5× speedup?

\[\begin{array}{l} \\ x + y \end{array} \]
(FPCore (x y z t a b) :precision binary64 (+ x y))
double code(double x, double y, double z, double t, double a, double b) {
	return x + y;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = x + y
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return x + y;
}
def code(x, y, z, t, a, b):
	return x + y
function code(x, y, z, t, a, b)
	return Float64(x + y)
end
function tmp = code(x, y, z, t, a, b)
	tmp = x + y;
end
code[x_, y_, z_, t_, a_, b_] := N[(x + y), $MachinePrecision]
\begin{array}{l}

\\
x + y
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - 0.5\right) \cdot b \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\left(x + \left(y + \left(z + b \cdot \left(a - \frac{1}{2}\right)\right)\right)\right) - z \cdot \log t} \]
  4. Applied rewrites63.8%

    \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right) - z \cdot \log t} \]
  5. Taylor expanded in x around 0

    \[\leadsto \left(x + \left(y + z\right)\right) - \color{blue}{z \cdot \log t} \]
  6. Applied rewrites43.3%

    \[\leadsto x + \color{blue}{y} \]
  7. Add Preprocessing

Developer Target 1: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \left(\left(x + y\right) + \frac{\left(1 - {\log t}^{2}\right) \cdot z}{1 + \log t}\right) + \left(a - 0.5\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+
  (+ (+ x y) (/ (* (- 1.0 (pow (log t) 2.0)) z) (+ 1.0 (log t))))
  (* (- a 0.5) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x + y) + (((1.0 - pow(log(t), 2.0)) * z) / (1.0 + log(t)))) + ((a - 0.5) * b);
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((x + y) + (((1.0d0 - (log(t) ** 2.0d0)) * z) / (1.0d0 + log(t)))) + ((a - 0.5d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((x + y) + (((1.0 - Math.pow(Math.log(t), 2.0)) * z) / (1.0 + Math.log(t)))) + ((a - 0.5) * b);
}
def code(x, y, z, t, a, b):
	return ((x + y) + (((1.0 - math.pow(math.log(t), 2.0)) * z) / (1.0 + math.log(t)))) + ((a - 0.5) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x + y) + Float64(Float64(Float64(1.0 - (log(t) ^ 2.0)) * z) / Float64(1.0 + log(t)))) + Float64(Float64(a - 0.5) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((x + y) + (((1.0 - (log(t) ^ 2.0)) * z) / (1.0 + log(t)))) + ((a - 0.5) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + y), $MachinePrecision] + N[(N[(N[(1.0 - N[Power[N[Log[t], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision] / N[(1.0 + N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x + y\right) + \frac{\left(1 - {\log t}^{2}\right) \cdot z}{1 + \log t}\right) + \left(a - 0.5\right) \cdot b
\end{array}

Reproduce

?
herbie shell --seed 2024321 
(FPCore (x y z t a b)
  :name "Numeric.SpecFunctions:logBeta from math-functions-0.1.5.2, A"
  :precision binary64
  :pre (TRUE)

  :alt
  (! :herbie-platform default (+ (+ (+ x y) (/ (* (- 1 (pow (log t) 2)) z) (+ 1 (log t)))) (* (- a 1/2) b)))

  (+ (- (+ (+ x y) z) (* z (log t))) (* (- a 0.5) b)))