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

Percentage Accurate: 99.8% → 99.8%
Time: 13.0s
Alternatives: 15
Speedup: 1.0×

Specification

?
\[\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 15 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} \\ \mathsf{fma}\left(a - 0.5, b, \mathsf{fma}\left(-z, \log t, y + x\right)\right) + z \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (fma (- a 0.5) b (fma (- z) (log t) (+ y x))) z))
double code(double x, double y, double z, double t, double a, double b) {
	return fma((a - 0.5), b, fma(-z, log(t), (y + x))) + z;
}
function code(x, y, z, t, a, b)
	return Float64(fma(Float64(a - 0.5), b, fma(Float64(-z), log(t), Float64(y + x))) + z)
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(a - 0.5), $MachinePrecision] * b + N[((-z) * N[Log[t], $MachinePrecision] + N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(a - 0.5, b, \mathsf{fma}\left(-z, \log t, y + x\right)\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. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - \frac{1}{2}\right) \cdot b} \]
    2. flip-+N/A

      \[\leadsto \color{blue}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}} \]
    3. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}}} \]
    4. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}}} \]
    5. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}}}} \]
    6. flip-+N/A

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - \frac{1}{2}\right) \cdot b}}} \]
    7. lift-+.f64N/A

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

    \[\leadsto \color{blue}{\frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-z, \log t, \left(z + x\right) + y\right)\right)}}} \]
  5. Step-by-step derivation
    1. lift-fma.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(\left(z + x\right) + y\right)}\right)}} \]
    2. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(\left(z + x\right) + y\right)}\right)}} \]
    3. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(\color{blue}{\left(z + x\right)} + y\right)\right)}} \]
    4. associate-+l+N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(z + \left(x + y\right)\right)}\right)}} \]
    5. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(z + \color{blue}{\left(x + y\right)}\right)\right)}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(\left(x + y\right) + z\right)}\right)}} \]
    7. associate-+r+N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(x + y\right)\right) + z}\right)}} \]
    8. lower-+.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(x + y\right)\right) + z}\right)}} \]
    9. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\log t \cdot \left(\mathsf{neg}\left(z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
    10. lift-neg.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\log t \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
    11. distribute-rgt-neg-inN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\left(\mathsf{neg}\left(\log t \cdot z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\left(\mathsf{neg}\left(\log t\right)\right) \cdot z} + \left(x + y\right)\right) + z\right)}} \]
    13. lower-fma.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, x + y\right)} + z\right)}} \]
    14. lower-neg.f6499.7

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(\color{blue}{-\log t}, z, x + y\right) + z\right)}} \]
    15. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, \color{blue}{x + y}\right) + z\right)}} \]
    16. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, \color{blue}{y + x}\right) + z\right)}} \]
    17. lower-+.f6499.7

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-\log t, z, \color{blue}{y + x}\right) + z\right)}} \]
  6. Applied rewrites99.7%

    \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \color{blue}{\mathsf{fma}\left(-\log t, z, y + x\right) + z}\right)}} \]
  7. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)}}} \]
    2. lift-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)}}} \]
    3. remove-double-div99.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-\log t, z, y + x\right) + z\right)} \]
    4. lift-fma.f64N/A

      \[\leadsto \color{blue}{b \cdot \left(a - \frac{1}{2}\right) + \left(\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)} \]
    5. lift-+.f64N/A

      \[\leadsto b \cdot \left(a - \frac{1}{2}\right) + \color{blue}{\left(\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)} \]
    6. associate-+r+N/A

      \[\leadsto \color{blue}{\left(b \cdot \left(a - \frac{1}{2}\right) + \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right)\right) + z} \]
    7. lower-+.f64N/A

      \[\leadsto \color{blue}{\left(b \cdot \left(a - \frac{1}{2}\right) + \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right)\right) + z} \]
  8. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(a - 0.5, b, \mathsf{fma}\left(-z, \log t, x + y\right)\right) + z} \]
  9. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(a - 0.5, b, \mathsf{fma}\left(-z, \log t, y + x\right)\right) + z \]
  10. Add Preprocessing

Alternative 2: 91.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := b \cdot \left(a - 0.5\right)\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+54}:\\ \;\;\;\;\mathsf{fma}\left(a - 0.5, b, y + x\right) + z\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+58}:\\ \;\;\;\;\mathsf{fma}\left(1 - \log t, z, y + x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a - 0.5, b, x\right) + y\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* b (- a 0.5))))
   (if (<= t_1 -2e+54)
     (+ (fma (- a 0.5) b (+ y x)) z)
     (if (<= t_1 2e+58)
       (fma (- 1.0 (log t)) z (+ y x))
       (+ (fma (- a 0.5) b x) y)))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = b * (a - 0.5);
	double tmp;
	if (t_1 <= -2e+54) {
		tmp = fma((a - 0.5), b, (y + x)) + z;
	} else if (t_1 <= 2e+58) {
		tmp = fma((1.0 - log(t)), z, (y + x));
	} else {
		tmp = fma((a - 0.5), b, x) + y;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = Float64(b * Float64(a - 0.5))
	tmp = 0.0
	if (t_1 <= -2e+54)
		tmp = Float64(fma(Float64(a - 0.5), b, Float64(y + x)) + z);
	elseif (t_1 <= 2e+58)
		tmp = fma(Float64(1.0 - log(t)), z, Float64(y + x));
	else
		tmp = Float64(fma(Float64(a - 0.5), b, x) + y);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(a - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+54], N[(N[(N[(a - 0.5), $MachinePrecision] * b + N[(y + x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[t$95$1, 2e+58], N[(N[(1.0 - N[Log[t], $MachinePrecision]), $MachinePrecision] * z + N[(y + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a - 0.5), $MachinePrecision] * b + x), $MachinePrecision] + y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := b \cdot \left(a - 0.5\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+54}:\\
\;\;\;\;\mathsf{fma}\left(a - 0.5, b, y + x\right) + z\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a - 0.5, b, x\right) + y\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < -2.0000000000000002e54

    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. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - \frac{1}{2}\right) \cdot b} \]
      2. flip-+N/A

        \[\leadsto \color{blue}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}} \]
      3. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}}} \]
      5. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) \cdot \left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(\left(a - \frac{1}{2}\right) \cdot b\right) \cdot \left(\left(a - \frac{1}{2}\right) \cdot b\right)}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) - \left(a - \frac{1}{2}\right) \cdot b}}}} \]
      6. flip-+N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\left(\left(\left(x + y\right) + z\right) - z \cdot \log t\right) + \left(a - \frac{1}{2}\right) \cdot b}}} \]
      7. lift-+.f64N/A

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-z, \log t, \left(z + x\right) + y\right)\right)}}} \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(\left(z + x\right) + y\right)}\right)}} \]
      2. lift-+.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(\left(z + x\right) + y\right)}\right)}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(\color{blue}{\left(z + x\right)} + y\right)\right)}} \]
      4. associate-+l+N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(z + \left(x + y\right)\right)}\right)}} \]
      5. lift-+.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(z + \color{blue}{\left(x + y\right)}\right)\right)}} \]
      6. +-commutativeN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \color{blue}{\left(\left(x + y\right) + z\right)}\right)}} \]
      7. associate-+r+N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(x + y\right)\right) + z}\right)}} \]
      8. lower-+.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \log t + \left(x + y\right)\right) + z}\right)}} \]
      9. *-commutativeN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\log t \cdot \left(\mathsf{neg}\left(z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
      10. lift-neg.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\log t \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
      11. distribute-rgt-neg-inN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\left(\mathsf{neg}\left(\log t \cdot z\right)\right)} + \left(x + y\right)\right) + z\right)}} \]
      12. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \left(\color{blue}{\left(\mathsf{neg}\left(\log t\right)\right) \cdot z} + \left(x + y\right)\right) + z\right)}} \]
      13. lower-fma.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, x + y\right)} + z\right)}} \]
      14. lower-neg.f6499.7

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(\color{blue}{-\log t}, z, x + y\right) + z\right)}} \]
      15. lift-+.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, \color{blue}{x + y}\right) + z\right)}} \]
      16. +-commutativeN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, \color{blue}{y + x}\right) + z\right)}} \]
      17. lower-+.f6499.7

        \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-\log t, z, \color{blue}{y + x}\right) + z\right)}} \]
    6. Applied rewrites99.7%

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(b, a - 0.5, \color{blue}{\mathsf{fma}\left(-\log t, z, y + x\right) + z}\right)}} \]
    7. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)}}} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\mathsf{fma}\left(b, a - \frac{1}{2}, \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)}}} \]
      3. remove-double-div99.9

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a - 0.5, \mathsf{fma}\left(-\log t, z, y + x\right) + z\right)} \]
      4. lift-fma.f64N/A

        \[\leadsto \color{blue}{b \cdot \left(a - \frac{1}{2}\right) + \left(\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)} \]
      5. lift-+.f64N/A

        \[\leadsto b \cdot \left(a - \frac{1}{2}\right) + \color{blue}{\left(\mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right) + z\right)} \]
      6. associate-+r+N/A

        \[\leadsto \color{blue}{\left(b \cdot \left(a - \frac{1}{2}\right) + \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right)\right) + z} \]
      7. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(b \cdot \left(a - \frac{1}{2}\right) + \mathsf{fma}\left(\mathsf{neg}\left(\log t\right), z, y + x\right)\right) + z} \]
    8. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(a - 0.5, b, \mathsf{fma}\left(-z, \log t, x + y\right)\right) + z} \]
    9. Taylor expanded in z around 0

      \[\leadsto \mathsf{fma}\left(a - \frac{1}{2}, b, \color{blue}{x + y}\right) + z \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(a - \frac{1}{2}, b, \color{blue}{y + x}\right) + z \]
      2. lower-+.f6489.0

        \[\leadsto \mathsf{fma}\left(a - 0.5, b, \color{blue}{y + x}\right) + z \]
    11. Applied rewrites89.0%

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

    if -2.0000000000000002e54 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b) < 1.99999999999999989e58

    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 b around 0

      \[\leadsto \color{blue}{\left(x + \left(y + z\right)\right) - z \cdot \log t} \]
    4. Step-by-step derivation
      1. cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(x + \left(y + z\right)\right) + \left(\mathsf{neg}\left(z\right)\right) \cdot \log t} \]
      2. associate-+r+N/A

        \[\leadsto \color{blue}{\left(\left(x + y\right) + z\right)} + \left(\mathsf{neg}\left(z\right)\right) \cdot \log t \]
      3. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + y\right) + \left(z + \left(\mathsf{neg}\left(z\right)\right) \cdot \log t\right)} \]
      4. cancel-sign-sub-invN/A

        \[\leadsto \left(x + y\right) + \color{blue}{\left(z - z \cdot \log t\right)} \]
      5. *-rgt-identityN/A

        \[\leadsto \left(x + y\right) + \left(\color{blue}{z \cdot 1} - z \cdot \log t\right) \]
      6. distribute-lft-out--N/A

        \[\leadsto \left(x + y\right) + \color{blue}{z \cdot \left(1 - \log t\right)} \]
      7. +-commutativeN/A

        \[\leadsto \color{blue}{z \cdot \left(1 - \log t\right) + \left(x + y\right)} \]
      8. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 - \log t\right) \cdot z} + \left(x + y\right) \]
      9. sub-negN/A

        \[\leadsto \color{blue}{\left(1 + \left(\mathsf{neg}\left(\log t\right)\right)\right)} \cdot z + \left(x + y\right) \]
      10. mul-1-negN/A

        \[\leadsto \left(1 + \color{blue}{-1 \cdot \log t}\right) \cdot z + \left(x + y\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 + -1 \cdot \log t, z, x + y\right)} \]
      12. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(1 + \color{blue}{\left(\mathsf{neg}\left(\log t\right)\right)}, z, x + y\right) \]
      13. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{1 - \log t}, z, x + y\right) \]
      14. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{1 - \log t}, z, x + y\right) \]
      15. lower-log.f64N/A

        \[\leadsto \mathsf{fma}\left(1 - \color{blue}{\log t}, z, x + y\right) \]
      16. lower-+.f6493.4

        \[\leadsto \mathsf{fma}\left(1 - \log t, z, \color{blue}{x + y}\right) \]
    5. Applied rewrites93.4%

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

    if 1.99999999999999989e58 < (*.f64 (-.f64 a #s(literal 1/2 binary64)) b)

    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 z around 0

      \[\leadsto \color{blue}{x + \left(y + b \cdot \left(a - \frac{1}{2}\right)\right)} \]
    4. Step-by-step derivation
      1. associate-+r+N/A

        \[\leadsto \color{blue}{\left(x + y\right) + b \cdot \left(a - \frac{1}{2}\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{b \cdot \left(a - \frac{1}{2}\right) + \left(x + y\right)} \]
      3. *-commutativeN/A

        \[\leadsto \color{blue}{\left(a - \frac{1}{2}\right) \cdot b} + \left(x + y\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(a - \frac{1}{2}, b, x + y\right)} \]
      5. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{a - \frac{1}{2}}, b, x + y\right) \]
      6. lower-+.f6488.7

        \[\leadsto \mathsf{fma}\left(a - 0.5, b, \color{blue}{x + y}\right) \]
    5. Applied rewrites88.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(a - 0.5, b, x + y\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites88.7%

        \[\leadsto \mathsf{fma}\left(a - 0.5, b, x\right) + \color{blue}{y} \]
    7. Recombined 3 regimes into one program.
    8. Final simplification91.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \cdot \left(a - 0.5\right) \leq -2 \cdot 10^{+54}:\\ \;\;\;\;\mathsf{fma}\left(a - 0.5, b, y + x\right) + z\\ \mathbf{elif}\;b \cdot \left(a - 0.5\right) \leq 2 \cdot 10^{+58}:\\ \;\;\;\;\mathsf{fma}\left(1 - \log t, z, y + x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a - 0.5, b, x\right) + y\\ \end{array} \]
    9. 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 2024230 
    (FPCore (x y z t a b)
      :name "Numeric.SpecFunctions:logBeta from math-functions-0.1.5.2, A"
      :precision binary64
    
      :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)))