| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 448 |
\[b \cdot \frac{1}{\frac{1}{a}}
\]
(FPCore (a b) :precision binary64 (exp (+ (log a) (log b))))
(FPCore (a b) :precision binary64 (* (/ 1.0 (/ 1.0 b)) a))
double code(double a, double b) {
return exp((log(a) + log(b)));
}
double code(double a, double b) {
return (1.0 / (1.0 / b)) * a;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp((log(a) + log(b)))
end function
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (1.0d0 / (1.0d0 / b)) * a
end function
public static double code(double a, double b) {
return Math.exp((Math.log(a) + Math.log(b)));
}
public static double code(double a, double b) {
return (1.0 / (1.0 / b)) * a;
}
def code(a, b): return math.exp((math.log(a) + math.log(b)))
def code(a, b): return (1.0 / (1.0 / b)) * a
function code(a, b) return exp(Float64(log(a) + log(b))) end
function code(a, b) return Float64(Float64(1.0 / Float64(1.0 / b)) * a) end
function tmp = code(a, b) tmp = exp((log(a) + log(b))); end
function tmp = code(a, b) tmp = (1.0 / (1.0 / b)) * a; end
code[a_, b_] := N[Exp[N[(N[Log[a], $MachinePrecision] + N[Log[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := N[(N[(1.0 / N[(1.0 / b), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]
e^{\log a + \log b}
\frac{1}{\frac{1}{b}} \cdot a
Results
| Original | 5.7 |
|---|---|
| Target | 0 |
| Herbie | 0.1 |
Initial program 5.7
Applied egg-rr5.4
Taylor expanded in b around inf 4.7
Simplified4.7
Taylor expanded in a around inf 0.2
Simplified0.2
Taylor expanded in a around 0 0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 448 |
herbie shell --seed 2023010
(FPCore (a b)
:name "Exp of sum of logs"
:precision binary64
:herbie-target
(* a b)
(exp (+ (log a) (log b))))