
(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 12 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 99.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in73.4%
exp-neg73.4%
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.5) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.5) {
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 (exp(a) <= 0.5d0) 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 (Math.exp(a) <= 0.5) {
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 math.exp(a) <= 0.5: 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 (exp(a) <= 0.5) 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 (exp(a) <= 0.5) 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[N[Exp[a], $MachinePrecision], 0.5], 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}\;e^{a} \leq 0.5:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.5Initial program 98.5%
*-lft-identity98.5%
associate-/l*98.5%
remove-double-div98.5%
exp-neg98.5%
associate-/r/98.5%
/-rgt-identity98.5%
*-commutative98.5%
distribute-rgt-in2.8%
exp-neg2.8%
rgt-mult-inverse98.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if 0.5 < (exp.f64 a) 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.3%
Final simplification99.5%
(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.5%
*-lft-identity98.5%
associate-/l*98.5%
remove-double-div98.5%
exp-neg98.5%
associate-/r/98.5%
/-rgt-identity98.5%
*-commutative98.5%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse98.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 72.1%
distribute-rgt1-in100.0%
rec-exp100.0%
associate-*r/100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
Final simplification98.9%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) b) (/ 1.0 (+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / b;
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
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 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
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 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / b else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) 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(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); 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 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); 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[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.5%
*-lft-identity98.5%
associate-/l*98.5%
remove-double-div98.5%
exp-neg98.5%
associate-/r/98.5%
/-rgt-identity98.5%
*-commutative98.5%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse98.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 72.1%
distribute-rgt1-in100.0%
rec-exp100.0%
associate-*r/100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
if 0.0 < (exp.f64 a) 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.4%
Taylor expanded in b around 0 67.4%
unpow267.4%
Simplified67.4%
*-un-lft-identity67.4%
associate-*r*67.4%
distribute-rgt-out67.4%
*-commutative67.4%
Applied egg-rr67.4%
*-commutative67.4%
flip-+67.4%
associate-*l/70.8%
metadata-eval70.8%
swap-sqr70.8%
metadata-eval70.8%
*-commutative70.8%
cancel-sign-sub-inv70.8%
metadata-eval70.8%
Applied egg-rr70.8%
Final simplification78.5%
(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 99.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in73.4%
exp-neg73.4%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b 0.5))))
(if (<= b 1.65e+77)
(/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a)))
(if (<= b 1e+103)
(/ 1.0 (+ 2.0 (/ (- (* b b) (* t_0 t_0)) (- b t_0))))
(/
1.0
(+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))))
double code(double a, double b) {
double t_0 = b * (b * 0.5);
double tmp;
if (b <= 1.65e+77) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0)));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
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 = b * (b * 0.5d0)
if (b <= 1.65d+77) then
tmp = 1.0d0 / (2.0d0 + ((a * (a * 0.5d0)) - a))
else if (b <= 1d+103) then
tmp = 1.0d0 / (2.0d0 + (((b * b) - (t_0 * t_0)) / (b - t_0)))
else
tmp = 1.0d0 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b * (b * 0.5);
double tmp;
if (b <= 1.65e+77) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0)));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): t_0 = b * (b * 0.5) tmp = 0 if b <= 1.65e+77: tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)) elif b <= 1e+103: tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0))) else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * 0.5)) tmp = 0.0 if (b <= 1.65e+77) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(a * Float64(a * 0.5)) - a))); elseif (b <= 1e+103) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(Float64(b * b) - Float64(t_0 * t_0)) / Float64(b - t_0)))); else tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); end return tmp end
function tmp_2 = code(a, b) t_0 = b * (b * 0.5); tmp = 0.0; if (b <= 1.65e+77) tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)); elseif (b <= 1e+103) tmp = 1.0 / (2.0 + (((b * b) - (t_0 * t_0)) / (b - t_0))); else tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.65e+77], N[(1.0 / N[(2.0 + N[(N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+103], N[(1.0 / N[(2.0 + N[(N[(N[(b * b), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot 0.5\right)\\
\mathbf{if}\;b \leq 1.65 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{2 + \left(a \cdot \left(a \cdot 0.5\right) - a\right)}\\
\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot b - t_0 \cdot t_0}{b - t_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if b < 1.6499999999999999e77Initial 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-in76.6%
exp-neg76.6%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 77.3%
Taylor expanded in a around 0 62.2%
+-commutative62.2%
neg-mul-162.2%
unsub-neg62.2%
*-commutative62.2%
unpow262.2%
associate-*l*62.2%
Simplified62.2%
if 1.6499999999999999e77 < b < 1e103Initial 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-in60.0%
exp-neg60.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 5.0%
unpow25.0%
Simplified5.0%
*-un-lft-identity5.0%
associate-*r*5.0%
distribute-rgt-out5.0%
*-commutative5.0%
Applied egg-rr5.0%
distribute-lft-in5.0%
*-rgt-identity5.0%
flip-+100.0%
Applied egg-rr100.0%
if 1e103 < 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-in63.0%
exp-neg63.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 76.1%
unpow276.1%
Simplified76.1%
*-un-lft-identity76.1%
associate-*r*76.1%
distribute-rgt-out76.1%
*-commutative76.1%
Applied egg-rr76.1%
*-commutative76.1%
flip-+76.1%
associate-*l/100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification70.9%
(FPCore (a b) :precision binary64 (if (<= b 4e+87) (/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a))) (/ 1.0 (+ 2.0 (/ (* b (- 1.0 (* (* b b) 0.25))) (+ 1.0 (* b -0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 4e+87) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 4d+87) then
tmp = 1.0d0 / (2.0d0 + ((a * (a * 0.5d0)) - a))
else
tmp = 1.0d0 / (2.0d0 + ((b * (1.0d0 - ((b * b) * 0.25d0))) / (1.0d0 + (b * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 4e+87) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else {
tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4e+87: tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)) else: tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 4e+87) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(a * Float64(a * 0.5)) - a))); else tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(b * Float64(1.0 - Float64(Float64(b * b) * 0.25))) / Float64(1.0 + Float64(b * -0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4e+87) tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)); else tmp = 1.0 / (2.0 + ((b * (1.0 - ((b * b) * 0.25))) / (1.0 + (b * -0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4e+87], N[(1.0 / N[(2.0 + N[(N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(N[(b * N[(1.0 - N[(N[(b * b), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4 \cdot 10^{+87}:\\
\;\;\;\;\frac{1}{2 + \left(a \cdot \left(a \cdot 0.5\right) - a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \frac{b \cdot \left(1 - \left(b \cdot b\right) \cdot 0.25\right)}{1 + b \cdot -0.5}}\\
\end{array}
\end{array}
if b < 3.9999999999999998e87Initial 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-in76.3%
exp-neg76.4%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 77.0%
Taylor expanded in a around 0 61.7%
+-commutative61.7%
neg-mul-161.7%
unsub-neg61.7%
*-commutative61.7%
unpow261.7%
associate-*l*61.7%
Simplified61.7%
if 3.9999999999999998e87 < 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-in63.2%
exp-neg63.2%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 72.4%
unpow272.4%
Simplified72.4%
*-un-lft-identity72.4%
associate-*r*72.4%
distribute-rgt-out72.4%
*-commutative72.4%
Applied egg-rr72.4%
*-commutative72.4%
flip-+72.4%
associate-*l/95.0%
metadata-eval95.0%
swap-sqr95.0%
metadata-eval95.0%
*-commutative95.0%
cancel-sign-sub-inv95.0%
metadata-eval95.0%
Applied egg-rr95.0%
Final simplification69.1%
(FPCore (a b) :precision binary64 (if (<= b 6.6e+149) (/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a))) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 6.6e+149) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 6.6d+149) then
tmp = 1.0d0 / (2.0d0 + ((a * (a * 0.5d0)) - a))
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.6e+149) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.6e+149: tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.6e+149) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(a * Float64(a * 0.5)) - a))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.6e+149) tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.6e+149], N[(1.0 / N[(2.0 + N[(N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{+149}:\\
\;\;\;\;\frac{1}{2 + \left(a \cdot \left(a \cdot 0.5\right) - a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 6.6e149Initial 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-in74.4%
exp-neg74.4%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 75.1%
Taylor expanded in a around 0 59.6%
+-commutative59.6%
neg-mul-159.6%
unsub-neg59.6%
*-commutative59.6%
unpow259.6%
associate-*l*59.6%
Simplified59.6%
if 6.6e149 < 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-in68.3%
exp-neg68.3%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 97.8%
unpow297.8%
Simplified97.8%
Taylor expanded in b around inf 97.8%
unpow297.8%
Simplified97.8%
Final simplification65.7%
(FPCore (a b) :precision binary64 (if (<= b 1.75e+146) (/ (+ a 2.0) (- 4.0 (* a a))) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.75e+146) {
tmp = (a + 2.0) / (4.0 - (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.75d+146) then
tmp = (a + 2.0d0) / (4.0d0 - (a * a))
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.75e+146) {
tmp = (a + 2.0) / (4.0 - (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.75e+146: tmp = (a + 2.0) / (4.0 - (a * a)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.75e+146) tmp = Float64(Float64(a + 2.0) / Float64(4.0 - Float64(a * a))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.75e+146) tmp = (a + 2.0) / (4.0 - (a * a)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.75e+146], N[(N[(a + 2.0), $MachinePrecision] / N[(4.0 - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.75 \cdot 10^{+146}:\\
\;\;\;\;\frac{a + 2}{4 - a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.7500000000000001e146Initial 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-in74.4%
exp-neg74.4%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 75.1%
Taylor expanded in a around 0 49.7%
neg-mul-149.7%
unsub-neg49.7%
Simplified49.7%
flip--59.2%
associate-/r/59.2%
metadata-eval59.2%
Applied egg-rr59.2%
associate-*l/59.2%
*-lft-identity59.2%
Simplified59.2%
if 1.7500000000000001e146 < 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-in68.3%
exp-neg68.3%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 97.8%
unpow297.8%
Simplified97.8%
Taylor expanded in b around inf 97.8%
unpow297.8%
Simplified97.8%
Final simplification65.4%
(FPCore (a b) :precision binary64 (if (<= b 1.45e+75) (/ 1.0 (- 2.0 a)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.45e+75) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.45d+75) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.45e+75) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.45e+75: tmp = 1.0 / (2.0 - a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.45e+75) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.45e+75) tmp = 1.0 / (2.0 - a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.45e+75], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.45 \cdot 10^{+75}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.4499999999999999e75Initial 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-in76.6%
exp-neg76.6%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 77.3%
Taylor expanded in a around 0 53.9%
neg-mul-153.9%
unsub-neg53.9%
Simplified53.9%
if 1.4499999999999999e75 < 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 a around 0 100.0%
Taylor expanded in b around 0 70.1%
unpow270.1%
Simplified70.1%
Taylor expanded in b around inf 70.1%
unpow270.1%
Simplified70.1%
Final simplification57.6%
(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.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in73.4%
exp-neg73.4%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 68.5%
Taylor expanded in a around 0 42.4%
neg-mul-142.4%
unsub-neg42.4%
Simplified42.4%
Final simplification42.4%
(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.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in73.4%
exp-neg73.4%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 84.1%
Taylor expanded in b around 0 41.7%
Final simplification41.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 2023282
(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))))