Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2

?

Percentage Accurate: 89.4% → 99.8%
Time: 23.2s
Precision: binary64
Cost: 19968

?

\[\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t \]
\[\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \left(x + -1\right) \cdot \log y - t\right) \]
(FPCore (x y z t)
 :precision binary64
 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
(FPCore (x y z t)
 :precision binary64
 (fma (+ z -1.0) (log1p (- y)) (- (* (+ x -1.0) (log y)) t)))
double code(double x, double y, double z, double t) {
	return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
double code(double x, double y, double z, double t) {
	return fma((z + -1.0), log1p(-y), (((x + -1.0) * log(y)) - t));
}
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t)
end
function code(x, y, z, t)
	return fma(Float64(z + -1.0), log1p(Float64(-y)), Float64(Float64(Float64(x + -1.0) * log(y)) - t))
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(z + -1.0), $MachinePrecision] * N[Log[1 + (-y)], $MachinePrecision] + N[(N[(N[(x + -1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \left(x + -1\right) \cdot \log y - 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

Derivation?

  1. Initial program 90.6%

    \[\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t \]
  2. Simplified99.9%

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

    [Start]90.6%

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

    +-commutative [=>]90.6%

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

    associate--l+ [=>]90.6%

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

    fma-def [=>]90.6%

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

    sub-neg [=>]90.6%

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

    log1p-def [=>]99.9%

    \[ \mathsf{fma}\left(z - 1, \color{blue}{\mathsf{log1p}\left(-y\right)}, \left(x - 1\right) \cdot \log y - t\right) \]
  3. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy99.8%
Cost19968
\[\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \left(x + -1\right) \cdot \log y - t\right) \]
Alternative 2
Accuracy99.8%
Cost19968
\[\mathsf{log1p}\left(-y\right) \cdot \left(z + -1\right) - \mathsf{fma}\left(\log y, 1 - x, t\right) \]
Alternative 3
Accuracy99.5%
Cost14144
\[\left(\mathsf{fma}\left(\log y, x + -1, \left(y \cdot y\right) \cdot \left(\left(z + -1\right) \cdot -0.5\right)\right) - y \cdot \left(z + -1\right)\right) - t \]
Alternative 4
Accuracy99.5%
Cost7616
\[\left(\left(z + -1\right) \cdot \left(y \cdot \left(y \cdot -0.5\right) - y\right) + \left(x + -1\right) \cdot \log y\right) - t \]
Alternative 5
Accuracy88.3%
Cost7497
\[\begin{array}{l} \mathbf{if}\;x + -1 \leq -1 \lor \neg \left(x + -1 \leq -0.99999986\right):\\ \;\;\;\;\left(x + -1\right) \cdot \log y - t\\ \mathbf{else}:\\ \;\;\;\;\left(y - z \cdot y\right) - \left(\log y + t\right)\\ \end{array} \]
Alternative 6
Accuracy88.3%
Cost7433
\[\begin{array}{l} \mathbf{if}\;x + -1 \leq -1 \lor \neg \left(x + -1 \leq -0.99999986\right):\\ \;\;\;\;\left(x + -1\right) \cdot \log y - t\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-\log y\right) - z \cdot y\right) - t\\ \end{array} \]
Alternative 7
Accuracy77.0%
Cost7248
\[\begin{array}{l} t_1 := \left(x + -1\right) \cdot \log y\\ t_2 := \left(-t\right) - z \cdot y\\ \mathbf{if}\;t \leq -1.25 \cdot 10^{+27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 14000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{+129}:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot \left(z + -1\right)\right)\right) + \left(\left(y - z \cdot y\right) - t\right)\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{+165}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Accuracy99.2%
Cost7232
\[\left(\left(x + -1\right) \cdot \log y - y \cdot \left(z + -1\right)\right) - t \]
Alternative 9
Accuracy99.0%
Cost7104
\[\left(\left(x + -1\right) \cdot \log y - z \cdot y\right) - t \]
Alternative 10
Accuracy73.7%
Cost6921
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+157} \lor \neg \left(x \leq 1.7 \cdot 10^{+27}\right):\\ \;\;\;\;x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\left(-\log y\right) - t\\ \end{array} \]
Alternative 11
Accuracy65.2%
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+157} \lor \neg \left(x \leq 10^{+26}\right):\\ \;\;\;\;x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot \left(z + -1\right)\right)\right) + \left(\left(y - z \cdot y\right) - t\right)\\ \end{array} \]
Alternative 12
Accuracy88.3%
Cost6848
\[\left(x + -1\right) \cdot \log y - t \]
Alternative 13
Accuracy46.7%
Cost1088
\[-0.5 \cdot \left(y \cdot \left(y \cdot \left(z + -1\right)\right)\right) + \left(\left(y - z \cdot y\right) - t\right) \]
Alternative 14
Accuracy42.9%
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -1.6 \cdot 10^{+27}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 210000000:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 15
Accuracy46.4%
Cost448
\[y \cdot \left(1 - z\right) - t \]
Alternative 16
Accuracy46.2%
Cost384
\[\left(-t\right) - z \cdot y \]
Alternative 17
Accuracy36.1%
Cost128
\[-t \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (x y z t)
  :name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
  :precision binary64
  (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))