Average Error: 6.7 → 0.1
Time: 13.3s
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{log1p}\left(-y\right) \cdot \left(z + -1\right) - \mathsf{fma}\left(\log y, 1 - x, 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
 (- (* (log1p (- y)) (+ z -1.0)) (fma (log y) (- 1.0 x) 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 (log1p(-y) * (z + -1.0)) - fma(log(y), (1.0 - x), 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 Float64(Float64(log1p(Float64(-y)) * Float64(z + -1.0)) - fma(log(y), Float64(1.0 - x), 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[(N[Log[1 + (-y)], $MachinePrecision] * N[(z + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * N[(1.0 - x), $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{log1p}\left(-y\right) \cdot \left(z + -1\right) - \mathsf{fma}\left(\log y, 1 - x, t\right)

Error

Derivation

  1. Initial program 6.7

    \[\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}{\left(z + -1\right) \cdot \mathsf{log1p}\left(-y\right) - \mathsf{fma}\left(\log y, 1 - x, t\right)} \]
    Proof
    (-.f64 (*.f64 (+.f64 z -1) (log1p.f64 (neg.f64 y))) (fma.f64 (log.f64 y) (-.f64 1 x) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (+.f64 z (Rewrite<= metadata-eval (neg.f64 1))) (log1p.f64 (neg.f64 y))) (fma.f64 (log.f64 y) (-.f64 1 x) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (Rewrite<= sub-neg_binary64 (-.f64 z 1)) (log1p.f64 (neg.f64 y))) (fma.f64 (log.f64 y) (-.f64 1 x) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 y))))) (fma.f64 (log.f64 y) (-.f64 1 x) t)): 26 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 y)))) (fma.f64 (log.f64 y) (-.f64 1 x) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 x))) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 x) 1)) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 x)) 1) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 x 1))) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 x 1))) t)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (fma.f64 (log.f64 y) (neg.f64 (-.f64 x 1)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 t))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 (log.f64 y) (neg.f64 (-.f64 x 1))) (neg.f64 t)))): 1 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (-.f64 x 1)) (log.f64 y))) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (*.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (-.f64 x 1))) (log.f64 y)) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (*.f64 (Rewrite=> associate--r-_binary64 (+.f64 (-.f64 0 x) 1)) (log.f64 y)) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (*.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 x)) 1) (log.f64 y)) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 (log.f64 y) (*.f64 (neg.f64 x) (log.f64 y)))) (neg.f64 t))): 2 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (log.f64 y) (*.f64 x (log.f64 y)))) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (Rewrite<= associate--r+_binary64 (-.f64 (log.f64 y) (+.f64 (*.f64 x (log.f64 y)) (neg.f64 t))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (-.f64 (log.f64 y) (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 t) (*.f64 x (log.f64 y)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (log.f64 y)) (+.f64 (neg.f64 t) (*.f64 x (log.f64 y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (-.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (Rewrite<= *-lft-identity_binary64 (*.f64 1 (log.f64 y)))) (+.f64 (neg.f64 t) (*.f64 x (log.f64 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> cancel-sign-sub-inv_binary64 (+.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (*.f64 (neg.f64 1) (log.f64 y)))) (+.f64 (neg.f64 t) (*.f64 x (log.f64 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))) (Rewrite<= *-commutative_binary64 (*.f64 (log.f64 y) (neg.f64 1)))) (+.f64 (neg.f64 t) (*.f64 x (log.f64 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (log.f64 y) (neg.f64 1)) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))))) (+.f64 (neg.f64 t) (*.f64 x (log.f64 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (log.f64 y) (neg.f64 1)) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x (log.f64 y)) (neg.f64 t)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 (*.f64 (log.f64 y) (neg.f64 1)) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) (*.f64 x (log.f64 y))) (neg.f64 t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x (log.f64 y)) (+.f64 (*.f64 (log.f64 y) (neg.f64 1)) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))))) (neg.f64 t)): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x (log.f64 y)) (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 (neg.f64 1) (log.f64 y))) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))))) (neg.f64 t)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) (*.f64 (neg.f64 1) (log.f64 y))) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y))))) (neg.f64 t)): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 (log.f64 y) (+.f64 x (neg.f64 1)))) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) (neg.f64 t)): 0 points increase in error, 2 points decrease in error
    (+.f64 (+.f64 (*.f64 (log.f64 y) (Rewrite<= sub-neg_binary64 (-.f64 x 1))) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) (neg.f64 t)): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x 1) (log.f64 y))) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) (neg.f64 t)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sub-neg_binary64 (-.f64 (+.f64 (*.f64 (-.f64 x 1) (log.f64 y)) (*.f64 (-.f64 z 1) (log.f64 (-.f64 1 y)))) t)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost13952
\[\left(\log y \cdot \left(-1 + x\right) + \left(1 - z\right) \cdot \left(3 \cdot \left(\mathsf{log1p}\left(-y\right) \cdot -0.3333333333333333\right)\right)\right) - t \]
Alternative 2
Error0.5
Cost13504
\[y \cdot \left(1 - z\right) - \mathsf{fma}\left(\log y, 1 - x, t\right) \]
Alternative 3
Error1.2
Cost7496
\[\begin{array}{l} t_1 := \left(\log y \cdot x - t\right) - z \cdot y\\ \mathbf{if}\;-1 + x \leq -20000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;-1 + x \leq -0.995:\\ \;\;\;\;\left(-\left(\log y + t\right)\right) - z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error1.2
Cost7496
\[\begin{array}{l} t_1 := \left(\log y \cdot x - t\right) - z \cdot y\\ \mathbf{if}\;-1 + x \leq -20000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;-1 + x \leq -0.995:\\ \;\;\;\;\left(\left(y - \log y\right) - z \cdot y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error2.8
Cost7432
\[\begin{array}{l} t_1 := \log y \cdot \left(-1 + x\right) - t\\ \mathbf{if}\;-1 + x \leq -20000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;-1 + x \leq -0.99991:\\ \;\;\;\;\left(-\left(\log y + t\right)\right) - z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error6.6
Cost7244
\[\begin{array}{l} t_1 := \log y \cdot \left(-1 + x\right) - t\\ \mathbf{if}\;z \leq -8.5 \cdot 10^{+224}:\\ \;\;\;\;z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - t\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+259}:\\ \;\;\;\;\log y \cdot x - z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error0.5
Cost7232
\[\left(\log y \cdot \left(-1 + x\right) + \left(y - z \cdot y\right)\right) - t \]
Alternative 8
Error0.5
Cost7232
\[\left(\left(y + \log y \cdot \left(-1 + x\right)\right) - t\right) - z \cdot y \]
Alternative 9
Error0.6
Cost7104
\[\left(\log y \cdot \left(-1 + x\right) - t\right) - z \cdot y \]
Alternative 10
Error8.1
Cost6984
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x \leq -7.5 \cdot 10^{-16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.0085:\\ \;\;\;\;-\left(\log y + t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error25.3
Cost6920
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{+157}:\\ \;\;\;\;z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - t\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+64}:\\ \;\;\;\;-\left(\log y + t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-t\right) - z \cdot y\\ \end{array} \]
Alternative 12
Error28.3
Cost6792
\[\begin{array}{l} \mathbf{if}\;t \leq -5 \cdot 10^{-11}:\\ \;\;\;\;z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - t\\ \mathbf{elif}\;t \leq 30000000:\\ \;\;\;\;-\log y\\ \mathbf{else}:\\ \;\;\;\;\left(-t\right) - z \cdot y\\ \end{array} \]
Alternative 13
Error34.4
Cost960
\[z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - t \]
Alternative 14
Error34.5
Cost704
\[y \cdot \left(z \cdot \left(y \cdot -0.5\right) - z\right) - t \]
Alternative 15
Error36.9
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -5.5 \cdot 10^{+38}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 5000000000000:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 16
Error36.9
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -1.1 \cdot 10^{+35}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 780000000:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 17
Error34.6
Cost384
\[\left(-t\right) - z \cdot y \]
Alternative 18
Error41.1
Cost128
\[-t \]
Alternative 19
Error62.2
Cost64
\[y \]

Error

Reproduce

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