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

Error

Target

Original9.6
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.6

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

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

Alternatives

Alternative 1
Error6.5
Cost6984
\[\begin{array}{l} t_1 := \log y \cdot x - t\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.36 \cdot 10^{-38}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-0.5 \cdot y\right) + \left(-z\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.6
Cost6976
\[\left(x \cdot \log y - y \cdot z\right) - t \]
Alternative 3
Error26.8
Cost768
\[y \cdot \left(z \cdot \left(-0.5 \cdot y\right) + \left(-z\right)\right) - t \]
Alternative 4
Error26.8
Cost768
\[z \cdot \left(-0.5 \cdot \left(y \cdot y\right) + \left(-y\right)\right) - t \]
Alternative 5
Error32.7
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -7.2 \cdot 10^{-31}:\\ \;\;\;\;-t\\ \mathbf{elif}\;t \leq 4.9 \cdot 10^{-34}:\\ \;\;\;\;-y \cdot z\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 6
Error27.0
Cost384
\[z \cdot \left(-y\right) - t \]
Alternative 7
Error36.5
Cost128
\[-t \]

Error

Reproduce

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