Average Error: 9.8 → 0.1
Time: 12.3s
Precision: binary64
Cost: 19712
\[\left(x \cdot \log y + z \cdot \log \left(1 - y\right)\right) - t \]
\[\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), x \cdot \log y - t\right) \]
(FPCore (x y z t)
 :precision binary64
 (- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))
(FPCore (x y z t)
 :precision binary64
 (fma z (log1p (- y)) (- (* x (log y)) t)))
double code(double x, double y, double z, double t) {
	return ((x * log(y)) + (z * log((1.0 - y)))) - t;
}
double code(double x, double y, double z, double t) {
	return fma(z, log1p(-y), ((x * log(y)) - t));
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x * log(y)) + Float64(z * log(Float64(1.0 - y)))) - t)
end
function code(x, y, z, t)
	return fma(z, log1p(Float64(-y)), Float64(Float64(x * log(y)) - t))
end
code[x_, y_, z_, t_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(z * N[Log[1 + (-y)], $MachinePrecision] + N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\left(x \cdot \log y + z \cdot \log \left(1 - y\right)\right) - t
\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), x \cdot \log y - t\right)

Error

Target

Original9.8
Target0.3
Herbie0.1
\[\left(-z\right) \cdot \left(\left(0.5 \cdot \left(y \cdot y\right) + y\right) + \frac{0.3333333333333333}{1 \cdot \left(1 \cdot 1\right)} \cdot \left(y \cdot \left(y \cdot y\right)\right)\right) - \left(t - x \cdot \log y\right) \]

Derivation

  1. Initial program 9.8

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), x \cdot \log y - t\right)} \]
    Proof
    (fma.f64 z (log1p.f64 (neg.f64 y)) (-.f64 (*.f64 x (log.f64 y)) t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 y)))) (-.f64 (*.f64 x (log.f64 y)) t)): 49 points increase in error, 0 points decrease in error
    (fma.f64 z (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 y))) (-.f64 (*.f64 x (log.f64 y)) t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (log.f64 (-.f64 1 y)) (Rewrite<= unsub-neg_binary64 (+.f64 (*.f64 x (log.f64 y)) (neg.f64 t)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (log.f64 (-.f64 1 y))) (+.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 z (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 z (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 x (log.f64 y)) (*.f64 z (log.f64 (-.f64 1 y)))) t)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error7.1
Cost7048
\[\begin{array}{l} t_1 := x \cdot \log y - t\\ \mathbf{if}\;x \leq -6.662260349771423 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.6551756062212416 \cdot 10^{+21}:\\ \;\;\;\;z \cdot \mathsf{log1p}\left(-y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error7.2
Cost6984
\[\begin{array}{l} t_1 := x \cdot \log y - t\\ \mathbf{if}\;x \leq -6.662260349771423 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.6551756062212416 \cdot 10^{+21}:\\ \;\;\;\;z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot \left(y \cdot -0.25 + -0.3333333333333333\right)\right) - y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error0.6
Cost6976
\[\left(x \cdot \log y - z \cdot y\right) - t \]
Alternative 4
Error14.7
Cost6856
\[\begin{array}{l} t_1 := x \cdot \log y\\ \mathbf{if}\;x \leq -2.0555872631394794 \cdot 10^{+109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.331211528927208 \cdot 10^{+30}:\\ \;\;\;\;z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot \left(y \cdot -0.25 + -0.3333333333333333\right)\right) - y\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error27.0
Cost1216
\[z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot \left(y \cdot -0.25 + -0.3333333333333333\right)\right) - y\right) - t \]
Alternative 6
Error27.0
Cost960
\[z \cdot \left(\left(y \cdot y\right) \cdot \left(-0.5 + y \cdot -0.3333333333333333\right) - y\right) - t \]
Alternative 7
Error27.1
Cost704
\[z \cdot \left(y \cdot \left(-1 + y \cdot -0.5\right)\right) - t \]
Alternative 8
Error32.9
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7371604739032891 \cdot 10^{-68}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 2.206964934511602 \cdot 10^{-86}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 9
Error27.3
Cost384
\[z \cdot \left(-y\right) - t \]
Alternative 10
Error37.0
Cost128
\[-t \]

Error

Reproduce

herbie shell --seed 2022316 
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, B"
  :precision binary64

  :herbie-target
  (- (* (- z) (+ (+ (* 0.5 (* y y)) y) (* (/ 0.3333333333333333 (* 1.0 (* 1.0 1.0))) (* y (* y y))))) (- t (* x (log y))))

  (- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))