?

Average Error: 6.8 → 0.1
Time: 17.5s
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
Error1.8
Cost7497
\[\begin{array}{l} \mathbf{if}\;-1 + x \leq -1 \cdot 10^{+34} \lor \neg \left(-1 + x \leq -1\right):\\ \;\;\;\;\left(x \cdot \log y - z \cdot y\right) - t\\ \mathbf{else}:\\ \;\;\;\;\left(-t\right) - \left(\log y + z \cdot y\right)\\ \end{array} \]
Alternative 3
Error3.6
Cost7433
\[\begin{array}{l} \mathbf{if}\;-1 + x \leq -1 \cdot 10^{+34} \lor \neg \left(-1 + x \leq 10^{+20}\right):\\ \;\;\;\;\log y \cdot \left(x + 1\right) - t\\ \mathbf{else}:\\ \;\;\;\;\left(-t\right) - \left(\log y + z \cdot y\right)\\ \end{array} \]
Alternative 4
Error9.1
Cost7376
\[\begin{array}{l} t_1 := \left(-t\right) - \log y\\ t_2 := \log y \cdot \left(x + 1\right) - t\\ \mathbf{if}\;x \leq -2:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-276}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-232}:\\ \;\;\;\;\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + y \cdot \left(1 - z\right)\right) - t\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error15.0
Cost7248
\[\begin{array}{l} t_1 := \log y \cdot \left(-1 + x\right)\\ t_2 := y \cdot \left(1 - z\right)\\ \mathbf{if}\;t \leq -5.1 \cdot 10^{+109}:\\ \;\;\;\;t_2 - t\\ \mathbf{elif}\;t \leq -4.8 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -6.5 \cdot 10^{-109}:\\ \;\;\;\;z \cdot \mathsf{log1p}\left(-y\right)\\ \mathbf{elif}\;t \leq 9.8 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + t_2\right) - t\\ \end{array} \]
Alternative 6
Error15.6
Cost7184
\[\begin{array}{l} t_1 := x \cdot \log y\\ t_2 := \left(-t\right) - \log y\\ \mathbf{if}\;x \leq -3.5 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-276}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-232}:\\ \;\;\;\;\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + y \cdot \left(1 - z\right)\right) - t\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+16}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error0.6
Cost7104
\[\left(\log y \cdot \left(-1 + x\right) - z \cdot y\right) - t \]
Alternative 8
Error7.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+196}:\\ \;\;\;\;\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + y \cdot \left(1 - z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;\log y \cdot \left(-1 + x\right) - t\\ \end{array} \]
Alternative 9
Error21.0
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+82} \lor \neg \left(x \leq 3.6 \cdot 10^{+32}\right):\\ \;\;\;\;x \cdot \log y\\ \mathbf{else}:\\ \;\;\;\;\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + y \cdot \left(1 - z\right)\right) - t\\ \end{array} \]
Alternative 10
Error34.1
Cost1088
\[\left(\left(z + -1\right) \cdot \left(\left(y \cdot y\right) \cdot -0.5\right) + y \cdot \left(1 - z\right)\right) - t \]
Alternative 11
Error36.5
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -4 \cdot 10^{+20}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{+30}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 12
Error36.7
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -4 \cdot 10^{+20}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{+30}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 13
Error34.2
Cost448
\[y \cdot \left(1 - z\right) - t \]
Alternative 14
Error40.8
Cost128
\[-t \]

Error

Reproduce?

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