
(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 11 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 (exp (- (log1p (exp (- b a))))))
double code(double a, double b) {
return exp(-log1p(exp((b - a))));
}
public static double code(double a, double b) {
return Math.exp(-Math.log1p(Math.exp((b - a))));
}
def code(a, b): return math.exp(-math.log1p(math.exp((b - a))))
function code(a, b) return exp(Float64(-log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[(-N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{b - a}\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) b) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / b;
} 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 (exp(a) <= 0.0d0) then
tmp = exp(a) / b
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 (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / b;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / b else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / b); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) / b; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse98.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 73.0%
distribute-rgt1-in100.0%
rec-exp100.0%
associate-*r/100.0%
+-commutative100.0%
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.7%
Final simplification98.2%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.8) (/ (exp a) b) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.8) {
tmp = exp(a) / b;
} 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 (exp(a) <= 0.8d0) then
tmp = exp(a) / b
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.8) {
tmp = Math.exp(a) / b;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.8: tmp = math.exp(a) / b else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.8) tmp = Float64(exp(a) / b); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.8) tmp = exp(a) / b; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.8], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.8:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if (exp.f64 a) < 0.80000000000000004Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in1.6%
exp-neg1.6%
rgt-mult-inverse98.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 71.9%
distribute-rgt1-in98.5%
rec-exp98.5%
associate-*r/98.5%
+-commutative98.5%
*-rgt-identity98.5%
Simplified98.5%
Taylor expanded in b around inf 98.5%
if 0.80000000000000004 < (exp.f64 a) Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in98.9%
exp-neg98.9%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 59.9%
Taylor expanded in a around 0 58.0%
*-commutative58.0%
Simplified58.0%
Final simplification68.2%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.0 / (exp((b - a)) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 1}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b -16500000.0) (+ 1.0 (exp b)) (/ 1.0 (+ (+ b 2.0) (* a (- -1.0 b))))))
double code(double a, double b) {
double tmp;
if (b <= -16500000.0) {
tmp = 1.0 + exp(b);
} else {
tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-16500000.0d0)) then
tmp = 1.0d0 + exp(b)
else
tmp = 1.0d0 / ((b + 2.0d0) + (a * ((-1.0d0) - b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -16500000.0) {
tmp = 1.0 + Math.exp(b);
} else {
tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -16500000.0: tmp = 1.0 + math.exp(b) else: tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b))) return tmp
function code(a, b) tmp = 0.0 if (b <= -16500000.0) tmp = Float64(1.0 + exp(b)); else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(a * Float64(-1.0 - b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -16500000.0) tmp = 1.0 + exp(b); else tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -16500000.0], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -16500000:\\
\;\;\;\;1 + e^{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + a \cdot \left(-1 - b\right)}\\
\end{array}
\end{array}
if b < -1.65e7Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg99.9%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
Taylor expanded in a around 0 100.0%
log1p-def100.0%
Simplified100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
log1p-udef100.0%
rem-exp-log100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -1.65e7 < b Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in69.5%
exp-neg69.5%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 72.5%
distribute-rgt1-in80.5%
rec-exp80.5%
associate-*r/80.5%
+-commutative80.5%
*-rgt-identity80.5%
Simplified80.5%
Taylor expanded in a around 0 54.7%
associate-+r+54.7%
+-commutative54.7%
mul-1-neg54.7%
distribute-rgt-neg-in54.7%
distribute-neg-in54.7%
metadata-eval54.7%
unsub-neg54.7%
Simplified54.7%
Final simplification62.3%
(FPCore (a b) :precision binary64 (if (<= b -1e-151) (+ 0.5 (* a 0.25)) (/ 1.0 (+ (+ b 2.0) (* a (- -1.0 b))))))
double code(double a, double b) {
double tmp;
if (b <= -1e-151) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-1d-151)) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 1.0d0 / ((b + 2.0d0) + (a * ((-1.0d0) - b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1e-151) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1e-151: tmp = 0.5 + (a * 0.25) else: tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b))) return tmp
function code(a, b) tmp = 0.0 if (b <= -1e-151) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(a * Float64(-1.0 - b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1e-151) tmp = 0.5 + (a * 0.25); else tmp = 1.0 / ((b + 2.0) + (a * (-1.0 - b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1e-151], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-151}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + a \cdot \left(-1 - b\right)}\\
\end{array}
\end{array}
if b < -9.9999999999999994e-152Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in93.4%
exp-neg93.3%
rgt-mult-inverse98.6%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 53.0%
Taylor expanded in a around 0 45.1%
*-commutative45.1%
Simplified45.1%
if -9.9999999999999994e-152 < b Initial program 98.9%
*-lft-identity98.9%
associate-/l*98.9%
remove-double-div98.9%
exp-neg98.9%
associate-/r/98.9%
/-rgt-identity98.9%
*-commutative98.9%
distribute-rgt-in66.7%
exp-neg66.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 71.0%
distribute-rgt1-in77.7%
rec-exp77.7%
associate-*r/77.7%
+-commutative77.7%
*-rgt-identity77.7%
Simplified77.7%
Taylor expanded in a around 0 50.4%
associate-+r+50.4%
+-commutative50.4%
mul-1-neg50.4%
distribute-rgt-neg-in50.4%
distribute-neg-in50.4%
metadata-eval50.4%
unsub-neg50.4%
Simplified50.4%
Final simplification48.8%
(FPCore (a b) :precision binary64 (if (<= b 75000000000000.0) (+ 0.5 (* a 0.25)) (/ -1.0 (* a (+ b 1.0)))))
double code(double a, double b) {
double tmp;
if (b <= 75000000000000.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = -1.0 / (a * (b + 1.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 75000000000000.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = (-1.0d0) / (a * (b + 1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 75000000000000.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = -1.0 / (a * (b + 1.0));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 75000000000000.0: tmp = 0.5 + (a * 0.25) else: tmp = -1.0 / (a * (b + 1.0)) return tmp
function code(a, b) tmp = 0.0 if (b <= 75000000000000.0) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(-1.0 / Float64(a * Float64(b + 1.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 75000000000000.0) tmp = 0.5 + (a * 0.25); else tmp = -1.0 / (a * (b + 1.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 75000000000000.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(a * N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 75000000000000:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{a \cdot \left(b + 1\right)}\\
\end{array}
\end{array}
if b < 7.5e13Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in78.7%
exp-neg78.7%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 79.2%
Taylor expanded in a around 0 57.6%
*-commutative57.6%
Simplified57.6%
if 7.5e13 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in61.9%
exp-neg61.9%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 41.8%
distribute-rgt1-in41.8%
rec-exp41.8%
associate-*r/41.8%
+-commutative41.8%
*-rgt-identity41.8%
Simplified41.8%
Taylor expanded in a around 0 19.4%
associate-+r+19.4%
+-commutative19.4%
mul-1-neg19.4%
distribute-rgt-neg-in19.4%
distribute-neg-in19.4%
metadata-eval19.4%
unsub-neg19.4%
Simplified19.4%
Taylor expanded in a around inf 17.9%
Final simplification47.8%
(FPCore (a b) :precision binary64 (if (<= b 1.4) (+ 0.5 (* a 0.25)) (/ (/ 1.0 b) (- 1.0 a))))
double code(double a, double b) {
double tmp;
if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = (1.0 / b) / (1.0 - a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.4d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = (1.0d0 / b) / (1.0d0 - a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = (1.0 / b) / (1.0 - a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.4: tmp = 0.5 + (a * 0.25) else: tmp = (1.0 / b) / (1.0 - a) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.4) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(Float64(1.0 / b) / Float64(1.0 - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.4) tmp = 0.5 + (a * 0.25); else tmp = (1.0 / b) / (1.0 - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.4], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / b), $MachinePrecision] / N[(1.0 - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.4:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{b}}{1 - a}\\
\end{array}
\end{array}
if b < 1.3999999999999999Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.4%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in78.8%
exp-neg78.8%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 80.3%
Taylor expanded in a around 0 58.7%
*-commutative58.7%
Simplified58.7%
if 1.3999999999999999 < b Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in62.7%
exp-neg62.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 41.0%
distribute-rgt1-in41.0%
rec-exp41.0%
associate-*r/41.0%
+-commutative41.0%
*-rgt-identity41.0%
Simplified41.0%
Taylor expanded in a around 0 18.4%
associate-+r+18.4%
+-commutative18.4%
mul-1-neg18.4%
distribute-rgt-neg-in18.4%
distribute-neg-in18.4%
metadata-eval18.4%
unsub-neg18.4%
Simplified18.4%
Taylor expanded in b around inf 18.4%
associate-/r*18.4%
mul-1-neg18.4%
unsub-neg18.4%
Simplified18.4%
Final simplification48.2%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.5%
Taylor expanded in a around 0 44.1%
*-commutative44.1%
Simplified44.1%
Final simplification44.1%
(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 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 69.5%
Taylor expanded in a around 0 44.3%
neg-mul-144.3%
unsub-neg44.3%
Simplified44.3%
Final simplification44.3%
(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 98.8%
*-lft-identity98.8%
associate-/l*98.8%
remove-double-div98.8%
exp-neg98.8%
associate-/r/98.8%
/-rgt-identity98.8%
*-commutative98.8%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 83.5%
Taylor expanded in b around 0 43.7%
Final simplification43.7%
(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 2023309
(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))))