
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
Initial program 99.2%
*-lft-identity99.2%
associate-/l*99.2%
remove-double-div99.2%
exp-neg99.2%
associate-/r/99.2%
/-rgt-identity99.2%
*-commutative99.2%
distribute-rgt-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -1.35e-12) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -1.35e-12) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.35d-12)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.35e-12) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.35e-12: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.35e-12) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.35e-12) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.35e-12], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.35 \cdot 10^{-12}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -1.3499999999999999e-12Initial program 98.7%
*-lft-identity98.7%
associate-/l*98.7%
remove-double-div98.7%
exp-neg98.7%
associate-/r/98.7%
/-rgt-identity98.7%
*-commutative98.7%
distribute-rgt-in2.6%
exp-neg2.6%
rgt-mult-inverse98.7%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if -1.3499999999999999e-12 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.4%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.5%
Final simplification99.0%
(FPCore (a b) :precision binary64 (if (<= a -740.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -740.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-740.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -740.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -740.0: tmp = math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -740.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -740.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -740.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -740:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -740Initial program 98.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -740 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.4%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.9%
Final simplification98.5%
(FPCore (a b) :precision binary64 (if (<= a -2.7e-11) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -2.7e-11) {
tmp = exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2.7d-11)) then
tmp = exp(a) / (a + 2.0d0)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2.7e-11) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.7e-11: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.7e-11) tmp = Float64(exp(a) / Float64(a + 2.0)); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.7e-11) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.7e-11], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.7 \cdot 10^{-11}:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -2.70000000000000005e-11Initial program 98.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 98.7%
+-commutative98.7%
Simplified98.7%
if -2.70000000000000005e-11 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.4%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.5%
Final simplification98.6%
(FPCore (a b) :precision binary64 (if (<= a -2.2) (/ (exp a) a) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -2.2) {
tmp = exp(a) / a;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2.2d0)) then
tmp = exp(a) / a
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2.2) {
tmp = Math.exp(a) / a;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.2: tmp = math.exp(a) / a else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.2) tmp = Float64(exp(a) / a); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.2) tmp = exp(a) / a; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.2], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.2:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -2.2000000000000002Initial program 98.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in a around inf 98.7%
if -2.2000000000000002 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.4%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 50.4%
Taylor expanded in a around 0 48.7%
Final simplification63.5%
(FPCore (a b)
:precision binary64
(let* ((t_0 (- 4.0 (* a a))))
(if (<= a -1.35e+154)
(* (+ a 2.0) (/ -1.0 (* a a)))
(/ t_0 (* t_0 (- 2.0 a))))))
double code(double a, double b) {
double t_0 = 4.0 - (a * a);
double tmp;
if (a <= -1.35e+154) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else {
tmp = t_0 / (t_0 * (2.0 - a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = 4.0d0 - (a * a)
if (a <= (-1.35d+154)) then
tmp = (a + 2.0d0) * ((-1.0d0) / (a * a))
else
tmp = t_0 / (t_0 * (2.0d0 - a))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 4.0 - (a * a);
double tmp;
if (a <= -1.35e+154) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else {
tmp = t_0 / (t_0 * (2.0 - a));
}
return tmp;
}
def code(a, b): t_0 = 4.0 - (a * a) tmp = 0 if a <= -1.35e+154: tmp = (a + 2.0) * (-1.0 / (a * a)) else: tmp = t_0 / (t_0 * (2.0 - a)) return tmp
function code(a, b) t_0 = Float64(4.0 - Float64(a * a)) tmp = 0.0 if (a <= -1.35e+154) tmp = Float64(Float64(a + 2.0) * Float64(-1.0 / Float64(a * a))); else tmp = Float64(t_0 / Float64(t_0 * Float64(2.0 - a))); end return tmp end
function tmp_2 = code(a, b) t_0 = 4.0 - (a * a); tmp = 0.0; if (a <= -1.35e+154) tmp = (a + 2.0) * (-1.0 / (a * a)); else tmp = t_0 / (t_0 * (2.0 - a)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(4.0 - N[(a * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -1.35e+154], N[(N[(a + 2.0), $MachinePrecision] * N[(-1.0 / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(t$95$0 * N[(2.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 - a \cdot a\\
\mathbf{if}\;a \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(a + 2\right) \cdot \frac{-1}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{t_0 \cdot \left(2 - a\right)}\\
\end{array}
\end{array}
if a < -1.35000000000000003e154Initial program 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse97.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 6.7%
mul-1-neg6.7%
unsub-neg6.7%
Simplified6.7%
flip--100.0%
+-commutative100.0%
associate-/r/100.0%
metadata-eval100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 100.0%
unpow2100.0%
Simplified100.0%
if -1.35000000000000003e154 < a Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.5%
remove-double-div99.5%
exp-neg99.5%
associate-/r/99.5%
/-rgt-identity99.5%
*-commutative99.5%
distribute-rgt-in83.3%
exp-neg83.3%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 58.7%
Taylor expanded in a around 0 41.0%
mul-1-neg41.0%
unsub-neg41.0%
Simplified41.0%
flip--41.0%
+-commutative41.0%
associate-/r/41.0%
metadata-eval41.0%
+-commutative41.0%
Applied egg-rr41.0%
flip-+41.0%
metadata-eval41.0%
frac-times45.9%
*-un-lft-identity45.9%
Applied egg-rr45.9%
Final simplification54.3%
(FPCore (a b) :precision binary64 (if (<= a -2.0) (* (+ a 2.0) (/ -1.0 (* a a))) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -2.0) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2.0d0)) then
tmp = (a + 2.0d0) * ((-1.0d0) / (a * a))
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2.0) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.0: tmp = (a + 2.0) * (-1.0 / (a * a)) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.0) tmp = Float64(Float64(a + 2.0) * Float64(-1.0 / Float64(a * a))); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.0) tmp = (a + 2.0) * (-1.0 / (a * a)); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.0], N[(N[(a + 2.0), $MachinePrecision] * N[(-1.0 / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2:\\
\;\;\;\;\left(a + 2\right) \cdot \frac{-1}{a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -2Initial program 98.7%
*-lft-identity98.7%
associate-/l*98.7%
remove-double-div98.7%
exp-neg98.7%
associate-/r/98.7%
/-rgt-identity98.7%
*-commutative98.7%
distribute-rgt-in1.3%
exp-neg1.3%
rgt-mult-inverse98.7%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 5.4%
mul-1-neg5.4%
unsub-neg5.4%
Simplified5.4%
flip--54.5%
+-commutative54.5%
associate-/r/54.5%
metadata-eval54.5%
+-commutative54.5%
Applied egg-rr54.5%
Taylor expanded in a around inf 54.5%
unpow254.5%
Simplified54.5%
if -2 < a Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.4%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 50.4%
Taylor expanded in a around 0 48.7%
Final simplification50.4%
(FPCore (a b) :precision binary64 (/ (+ a 2.0) (- 4.0 (* a a))))
double code(double a, double b) {
return (a + 2.0) / (4.0 - (a * a));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a + 2.0d0) / (4.0d0 - (a * a))
end function
public static double code(double a, double b) {
return (a + 2.0) / (4.0 - (a * a));
}
def code(a, b): return (a + 2.0) / (4.0 - (a * a))
function code(a, b) return Float64(Float64(a + 2.0) / Float64(4.0 - Float64(a * a))) end
function tmp = code(a, b) tmp = (a + 2.0) / (4.0 - (a * a)); end
code[a_, b_] := N[(N[(a + 2.0), $MachinePrecision] / N[(4.0 - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a + 2}{4 - a \cdot a}
\end{array}
Initial program 99.2%
*-lft-identity99.2%
associate-/l*99.2%
remove-double-div99.2%
exp-neg99.2%
associate-/r/99.2%
/-rgt-identity99.2%
*-commutative99.2%
distribute-rgt-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 65.1%
Taylor expanded in a around 0 35.6%
mul-1-neg35.6%
unsub-neg35.6%
Simplified35.6%
flip--50.2%
+-commutative50.2%
associate-/r/50.2%
metadata-eval50.2%
+-commutative50.2%
Applied egg-rr50.2%
associate-*l/50.2%
*-lft-identity50.2%
+-commutative50.2%
Simplified50.2%
Final simplification50.2%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 99.2%
*-lft-identity99.2%
associate-/l*99.2%
remove-double-div99.2%
exp-neg99.2%
associate-/r/99.2%
/-rgt-identity99.2%
*-commutative99.2%
distribute-rgt-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 65.1%
Taylor expanded in a around 0 35.6%
mul-1-neg35.6%
unsub-neg35.6%
Simplified35.6%
Final simplification35.6%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.2%
*-lft-identity99.2%
associate-/l*99.2%
remove-double-div99.2%
exp-neg99.2%
associate-/r/99.2%
/-rgt-identity99.2%
*-commutative99.2%
distribute-rgt-in70.3%
exp-neg70.3%
rgt-mult-inverse99.2%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 81.9%
Taylor expanded in b around 0 35.0%
Final simplification35.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2023268
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:herbie-target
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))