Average Error: 6.8 → 0.1
Time: 18.8s
Precision: binary64
Cost: 26304
\[\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), \mathsf{fma}\left(-1 + x, \log y, -t\right)\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)) (fma (+ -1.0 x) (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), fma((-1.0 + x), 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)), fma(Float64(-1.0 + x), log(y), Float64(-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[(-1.0 + x), $MachinePrecision] * N[Log[y], $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), \mathsf{fma}\left(-1 + x, \log y, -t\right)\right)

Error

Derivation

  1. Initial program 6.8

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

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

    [Start]6.8

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

    +-commutative [=>]6.8

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

    associate--l+ [=>]6.8

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

    fma-def [=>]6.8

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

    sub-neg [=>]6.8

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

    metadata-eval [=>]6.8

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

    sub-neg [=>]6.8

    \[ \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 [=>]0.1

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

    fma-neg [=>]0.1

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

    sub-neg [=>]0.1

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

    metadata-eval [=>]0.1

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

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

Alternatives

Alternative 1
Error0.1
Cost19968
\[\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \log y \cdot \left(-1 + x\right)\right) - t \]
Alternative 2
Error0.1
Cost13824
\[\left(\log y \cdot \left(-1 + x\right) + \frac{\mathsf{log1p}\left(-y\right)}{\frac{1}{z + -1}}\right) - t \]
Alternative 3
Error0.3
Cost7616
\[\left(\log y \cdot \left(-1 + x\right) + \left(z + -1\right) \cdot \left(y \cdot \left(y \cdot -0.5\right) - y\right)\right) - t \]
Alternative 4
Error3.0
Cost7497
\[\begin{array}{l} \mathbf{if}\;-1 + x \leq -1.2 \lor \neg \left(-1 + x \leq 2 \cdot 10^{+30}\right):\\ \;\;\;\;\log y \cdot \left(-1 + x\right) - t\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - z \cdot y\right) - \log y\right) - t\\ \end{array} \]
Alternative 5
Error7.8
Cost7496
\[\begin{array}{l} t_1 := \log y \cdot \left(-1 + x\right)\\ \mathbf{if}\;-1 + x \leq -1:\\ \;\;\;\;\left(y + t_1\right) - t\\ \mathbf{elif}\;-1 + x \leq 2 \cdot 10^{+30}:\\ \;\;\;\;\left(\left(y - z \cdot y\right) - \log y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1 - t\\ \end{array} \]
Alternative 6
Error0.5
Cost7360
\[\left(\log \left(\frac{1}{y}\right) \cdot \left(1 - x\right) + y \cdot \left(1 - z\right)\right) - t \]
Alternative 7
Error0.5
Cost7232
\[\left(\log y \cdot \left(-1 + x\right) + y \cdot \left(1 - z\right)\right) - t \]
Alternative 8
Error27.8
Cost7120
\[\begin{array}{l} t_1 := x \cdot \log y\\ \mathbf{if}\;t \leq -48000000000:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 9 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{-38}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 9
Error15.3
Cost7112
\[\begin{array}{l} \mathbf{if}\;t \leq -48000000000:\\ \;\;\;\;\left(-t\right) - \log y\\ \mathbf{elif}\;t \leq 3.5 \cdot 10^{+43}:\\ \;\;\;\;y + \log y \cdot \left(-1 + x\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 10
Error15.3
Cost6984
\[\begin{array}{l} \mathbf{if}\;t \leq -16000000000:\\ \;\;\;\;\left(-t\right) - \log y\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{+43}:\\ \;\;\;\;\log y \cdot \left(-1 + x\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 11
Error15.5
Cost6921
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+29} \lor \neg \left(x \leq 7.2 \cdot 10^{+30}\right):\\ \;\;\;\;x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\left(-t\right) - \log y\\ \end{array} \]
Alternative 12
Error7.5
Cost6848
\[\log y \cdot \left(-1 + x\right) - t \]
Alternative 13
Error36.1
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -1800000000000:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+25}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 14
Error36.3
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -680000000000:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+25}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 15
Error40.9
Cost128
\[-t \]
Alternative 16
Error62.1
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2023016 
(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))