\[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\]
↓
\[x \cdot e^{\mathsf{fma}\left(a, \mathsf{log1p}\left(-z\right) - b, y \cdot \left(\log z - t\right)\right)}
\]
(FPCore (x y z t a b)
:precision binary64
(* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
↓
(FPCore (x y z t a b)
:precision binary64
(* x (exp (fma a (- (log1p (- z)) b) (* y (- (log z) t))))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
↓
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(fma(a, (log1p(-z) - b), (y * (log(z) - t))));
}
function code(x, y, z, t, a, b)
return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b)))))
end
↓
function code(x, y, z, t, a, b)
return Float64(x * exp(fma(a, Float64(log1p(Float64(-z)) - b), Float64(y * Float64(log(z) - t)))))
end
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
↓
x \cdot e^{\mathsf{fma}\left(a, \mathsf{log1p}\left(-z\right) - b, y \cdot \left(\log z - t\right)\right)}
Error
Derivation
Initial program 2.0
\[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\]
Simplified0.3
\[\leadsto \color{blue}{x \cdot e^{\mathsf{fma}\left(a, \mathsf{log1p}\left(-z\right) - b, y \cdot \left(\log z - t\right)\right)}}
\]
Proof
(*.f64 x (exp.f64 (fma.f64 a (-.f64 (log1p.f64 (neg.f64 z)) b) (*.f64 y (-.f64 (log.f64 z) t))))): 0 points increase in error, 0 points decrease in error
(*.f64 x (exp.f64 (fma.f64 a (-.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 z)))) b) (*.f64 y (-.f64 (log.f64 z) t))))): 2 points increase in error, 0 points decrease in error
(*.f64 x (exp.f64 (fma.f64 a (-.f64 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 z))) b) (*.f64 y (-.f64 (log.f64 z) t))))): 0 points increase in error, 0 points decrease in error
(*.f64 x (exp.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (-.f64 (log.f64 (-.f64 1 z)) b)) (*.f64 y (-.f64 (log.f64 z) t)))))): 0 points increase in error, 0 points decrease in error
(*.f64 x (exp.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 1 z)) b)))))): 0 points increase in error, 0 points decrease in error
Final simplification0.3
\[\leadsto x \cdot e^{\mathsf{fma}\left(a, \mathsf{log1p}\left(-z\right) - b, y \cdot \left(\log z - t\right)\right)}
\]
Alternatives
Alternative 1
Error
2.0
Cost
20160
\[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\]
herbie shell --seed 2022291
(FPCore (x y z t a b)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, B"
:precision binary64
(* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))