Numeric.SpecFunctions:logGammaL from math-functions-0.1.5.2

?

Percentage Accurate: 99.6% → 99.6%
Time: 26.2s
Precision: binary64
Cost: 26304

?

\[\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t \]
\[\log \left(x + y\right) + \mathsf{fma}\left(a + -0.5, \log t, \log z - t\right) \]
(FPCore (x y z t a)
 :precision binary64
 (+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))
(FPCore (x y z t a)
 :precision binary64
 (+ (log (+ x y)) (fma (+ a -0.5) (log t) (- (log z) t))))
double code(double x, double y, double z, double t, double a) {
	return ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t));
}
double code(double x, double y, double z, double t, double a) {
	return log((x + y)) + fma((a + -0.5), log(t), (log(z) - t));
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(log(Float64(x + y)) + log(z)) - t) + Float64(Float64(a - 0.5) * log(t)))
end
function code(x, y, z, t, a)
	return Float64(log(Float64(x + y)) + fma(Float64(a + -0.5), log(t), Float64(log(z) - t)))
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[(N[(a + -0.5), $MachinePrecision] * N[Log[t], $MachinePrecision] + N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t
\log \left(x + y\right) + \mathsf{fma}\left(a + -0.5, \log t, \log z - t\right)

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.

Herbie found 17 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Target

Original99.6%
Target99.6%
Herbie99.6%
\[\log \left(x + y\right) + \left(\left(\log z - t\right) + \left(a - 0.5\right) \cdot \log t\right) \]

Derivation?

  1. Initial program 99.6%

    \[\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t \]
  2. Simplified99.6%

    \[\leadsto \color{blue}{\log \left(x + y\right) + \mathsf{fma}\left(a + -0.5, \log t, \log z - t\right)} \]
    Step-by-step derivation

    [Start]99.6%

    \[ \left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t \]

    associate--l+ [=>]99.6%

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

    associate-+l+ [=>]99.6%

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

    +-commutative [=>]99.6%

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

    fma-def [=>]99.6%

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

    remove-double-neg [<=]99.6%

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

    remove-double-neg [=>]99.6%

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

    sub-neg [=>]99.6%

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

    metadata-eval [=>]99.6%

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

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

Alternatives

Alternative 1
Accuracy99.6%
Cost26304
\[\log \left(x + y\right) + \mathsf{fma}\left(a + -0.5, \log t, \log z - t\right) \]
Alternative 2
Accuracy75.4%
Cost20108
\[\begin{array}{l} t_1 := \mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \mathbf{if}\;a \leq -1.86 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.7 \cdot 10^{-125}:\\ \;\;\;\;\left(\log t \cdot \left(a - 0.5\right) + \log \left(y \cdot z\right)\right) - t\\ \mathbf{elif}\;a \leq 1:\\ \;\;\;\;\left(\log y + \log \left(z \cdot {t}^{-0.5}\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy99.6%
Cost20032
\[\left(\log \left(x + y\right) + \left(\log z - t\right)\right) + \left(a + -0.5\right) \cdot \log t \]
Alternative 4
Accuracy80.3%
Cost19908
\[\begin{array}{l} \mathbf{if}\;t \leq 480:\\ \;\;\;\;\log z + \left(\log t \cdot \left(a - 0.5\right) + \log y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \end{array} \]
Alternative 5
Accuracy80.4%
Cost19908
\[\begin{array}{l} \mathbf{if}\;t \leq 220:\\ \;\;\;\;\log t \cdot \left(a - 0.5\right) + \left(\log z + \log y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \end{array} \]
Alternative 6
Accuracy68.8%
Cost19904
\[\left(\log z - t\right) + \left(\log t \cdot \left(a - 0.5\right) + \log y\right) \]
Alternative 7
Accuracy84.2%
Cost13900
\[\begin{array}{l} t_1 := \left(a + -0.5\right) \cdot \log t\\ t_2 := t_1 + \log \left(z \cdot \left(x + y\right)\right)\\ \mathbf{if}\;t \leq 1.16 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 10^{-109}:\\ \;\;\;\;t_1 + \log y\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{-26}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \end{array} \]
Alternative 8
Accuracy73.6%
Cost13708
\[\begin{array}{l} t_1 := \log \left(\left(y \cdot z\right) \cdot {t}^{\left(a + -0.5\right)}\right)\\ \mathbf{if}\;t \leq 1.25 \cdot 10^{-264}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.2 \cdot 10^{-45}:\\ \;\;\;\;\log \left(x + y\right) + a \cdot \log t\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \end{array} \]
Alternative 9
Accuracy73.1%
Cost13641
\[\begin{array}{l} \mathbf{if}\;a \leq -9.2 \cdot 10^{-8} \lor \neg \left(a \leq 4.8 \cdot 10^{-18}\right):\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(y \cdot z\right) + -0.5 \cdot \log t\right) - t\\ \end{array} \]
Alternative 10
Accuracy66.2%
Cost13636
\[\begin{array}{l} \mathbf{if}\;z \leq 2.4 \cdot 10^{+75}:\\ \;\;\;\;\left(\log t \cdot \left(a - 0.5\right) + \log \left(y \cdot z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \end{array} \]
Alternative 11
Accuracy73.0%
Cost13577
\[\begin{array}{l} \mathbf{if}\;a \leq -1.9 \cdot 10^{-160} \lor \neg \left(a \leq 4 \cdot 10^{-18}\right):\\ \;\;\;\;\mathsf{fma}\left(a + -0.5, \log t, -t\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(y \cdot \left(z \cdot {t}^{-0.5}\right)\right) - t\\ \end{array} \]
Alternative 12
Accuracy77.2%
Cost13184
\[\mathsf{fma}\left(a + -0.5, \log t, -t\right) \]
Alternative 13
Accuracy56.6%
Cost7048
\[\begin{array}{l} \mathbf{if}\;a \leq -5.4 \cdot 10^{+53}:\\ \;\;\;\;a \cdot \log t\\ \mathbf{elif}\;a \leq 7.8 \cdot 10^{+72}:\\ \;\;\;\;\log y - t\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{1}{t}\right) \cdot \left(-a\right)\\ \end{array} \]
Alternative 14
Accuracy56.6%
Cost6857
\[\begin{array}{l} \mathbf{if}\;a \leq -1.22 \cdot 10^{+54} \lor \neg \left(a \leq 7.8 \cdot 10^{+72}\right):\\ \;\;\;\;a \cdot \log t\\ \mathbf{else}:\\ \;\;\;\;\log y - t\\ \end{array} \]
Alternative 15
Accuracy40.6%
Cost6724
\[\begin{array}{l} \mathbf{if}\;t \leq 60000000:\\ \;\;\;\;\log \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 16
Accuracy62.0%
Cost6724
\[\begin{array}{l} \mathbf{if}\;t \leq 1.6 \cdot 10^{+42}:\\ \;\;\;\;a \cdot \log t\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 17
Accuracy37.4%
Cost128
\[-t \]

Reproduce?

herbie shell --seed 2023171 
(FPCore (x y z t a)
  :name "Numeric.SpecFunctions:logGammaL from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (+ (log (+ x y)) (+ (- (log z) t) (* (- a 0.5) (log t))))

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