
(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 (/ 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 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-in73.0%
exp-neg73.0%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -490000000.0) (/ (exp a) b) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -490000000.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 (a <= (-490000000.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 (a <= -490000000.0) {
tmp = Math.exp(a) / b;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -490000000.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 (a <= -490000000.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 (a <= -490000000.0) tmp = exp(a) / b; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -490000000.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}\;a \leq -490000000:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -4.9e8Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in b around inf 100.0%
if -4.9e8 < a Initial 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-in97.4%
exp-neg97.4%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.0%
Final simplification97.7%
(FPCore (a b) :precision binary64 (if (<= a -1200.0) (/ (exp a) b) (/ 1.0 (+ 2.0 (+ b (* (* b b) 0.5))))))
double code(double a, double b) {
double tmp;
if (a <= -1200.0) {
tmp = exp(a) / b;
} else {
tmp = 1.0 / (2.0 + (b + ((b * 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 (a <= (-1200.0d0)) then
tmp = exp(a) / b
else
tmp = 1.0d0 / (2.0d0 + (b + ((b * b) * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1200.0) {
tmp = Math.exp(a) / b;
} else {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1200.0: tmp = math.exp(a) / b else: tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (a <= -1200.0) tmp = Float64(exp(a) / b); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(Float64(b * b) * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1200.0) tmp = exp(a) / b; else tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1200.0], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1200:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + \left(b \cdot b\right) \cdot 0.5\right)}\\
\end{array}
\end{array}
if a < -1200Initial program 98.5%
Taylor expanded in b around 0 98.5%
Taylor expanded in b around inf 98.5%
if -1200 < 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.4%
exp-neg98.4%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.4%
Taylor expanded in b around 0 62.5%
*-commutative62.5%
unpow262.5%
Simplified62.5%
Final simplification71.8%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b -0.5))))
(if (<= b 2.5e+75)
(/ (+ a 2.0) (- 4.0 (* a a)))
(if (<= b 1.35e+154)
(/ 1.0 (- (/ (- (* t_0 t_0) (* b b)) (- (- b) t_0)) -2.0))
(/ 2.0 (* b b))))))
double code(double a, double b) {
double t_0 = b * (b * -0.5);
double tmp;
if (b <= 2.5e+75) {
tmp = (a + 2.0) / (4.0 - (a * a));
} else if (b <= 1.35e+154) {
tmp = 1.0 / ((((t_0 * t_0) - (b * b)) / (-b - t_0)) - -2.0);
} 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) :: t_0
real(8) :: tmp
t_0 = b * (b * (-0.5d0))
if (b <= 2.5d+75) then
tmp = (a + 2.0d0) / (4.0d0 - (a * a))
else if (b <= 1.35d+154) then
tmp = 1.0d0 / ((((t_0 * t_0) - (b * b)) / (-b - t_0)) - (-2.0d0))
else
tmp = 2.0d0 / (b * b)
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 <= 2.5e+75) {
tmp = (a + 2.0) / (4.0 - (a * a));
} else if (b <= 1.35e+154) {
tmp = 1.0 / ((((t_0 * t_0) - (b * b)) / (-b - t_0)) - -2.0);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): t_0 = b * (b * -0.5) tmp = 0 if b <= 2.5e+75: tmp = (a + 2.0) / (4.0 - (a * a)) elif b <= 1.35e+154: tmp = 1.0 / ((((t_0 * t_0) - (b * b)) / (-b - t_0)) - -2.0) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * -0.5)) tmp = 0.0 if (b <= 2.5e+75) tmp = Float64(Float64(a + 2.0) / Float64(4.0 - Float64(a * a))); elseif (b <= 1.35e+154) tmp = Float64(1.0 / Float64(Float64(Float64(Float64(t_0 * t_0) - Float64(b * b)) / Float64(Float64(-b) - t_0)) - -2.0)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) t_0 = b * (b * -0.5); tmp = 0.0; if (b <= 2.5e+75) tmp = (a + 2.0) / (4.0 - (a * a)); elseif (b <= 1.35e+154) tmp = 1.0 / ((((t_0 * t_0) - (b * b)) / (-b - t_0)) - -2.0); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.5e+75], N[(N[(a + 2.0), $MachinePrecision] / N[(4.0 - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(1.0 / N[(N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision] - -2.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot -0.5\right)\\
\mathbf{if}\;b \leq 2.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{a + 2}{4 - a \cdot a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\frac{t_0 \cdot t_0 - b \cdot b}{\left(-b\right) - t_0} - -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.5000000000000001e75Initial 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-in74.7%
exp-neg74.7%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 74.6%
Taylor expanded in a around 0 49.9%
neg-mul-149.9%
unsub-neg49.9%
Simplified49.9%
flip--64.2%
associate-/r/64.2%
metadata-eval64.2%
Applied egg-rr64.2%
associate-*l/64.2%
*-lft-identity64.2%
Simplified64.2%
if 2.5000000000000001e75 < b < 1.35000000000000003e154Initial 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 7.1%
*-commutative7.1%
unpow27.1%
Simplified7.1%
/-rgt-identity7.1%
frac-2neg7.1%
+-commutative7.1%
associate-+l+7.1%
associate-*l*7.1%
fma-def7.1%
metadata-eval7.1%
Applied egg-rr7.1%
distribute-frac-neg7.1%
*-lft-identity7.1%
associate-/l*7.1%
metadata-eval7.1%
associate-/r*7.1%
neg-mul-17.1%
remove-double-div7.1%
+-commutative7.1%
fma-udef7.1%
+-commutative7.1%
associate-+r+7.1%
fma-udef7.1%
distribute-neg-in7.1%
metadata-eval7.1%
fma-udef7.1%
+-commutative7.1%
distribute-neg-in7.1%
neg-mul-17.1%
*-commutative7.1%
distribute-rgt-neg-in7.1%
*-commutative7.1%
Simplified7.1%
distribute-rgt-in7.1%
flip-+100.0%
mul-1-neg100.0%
mul-1-neg100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
mul-1-neg100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
if 1.35000000000000003e154 < 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.6%
exp-neg68.6%
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 100.0%
*-commutative100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification71.7%
(FPCore (a b)
:precision binary64
(if (<= a -1.4e+154)
(* (+ a 2.0) (/ -1.0 (* a a)))
(if (<= a -2.5e+58)
(* (+ a 2.0) (/ 1.0 (/ (- 16.0 (* (* a a) (* a a))) (+ 4.0 (* a a)))))
(/ 1.0 (+ 2.0 (+ b (* (* b b) 0.5)))))))
double code(double a, double b) {
double tmp;
if (a <= -1.4e+154) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else if (a <= -2.5e+58) {
tmp = (a + 2.0) * (1.0 / ((16.0 - ((a * a) * (a * a))) / (4.0 + (a * a))));
} else {
tmp = 1.0 / (2.0 + (b + ((b * 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 (a <= (-1.4d+154)) then
tmp = (a + 2.0d0) * ((-1.0d0) / (a * a))
else if (a <= (-2.5d+58)) then
tmp = (a + 2.0d0) * (1.0d0 / ((16.0d0 - ((a * a) * (a * a))) / (4.0d0 + (a * a))))
else
tmp = 1.0d0 / (2.0d0 + (b + ((b * b) * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.4e+154) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else if (a <= -2.5e+58) {
tmp = (a + 2.0) * (1.0 / ((16.0 - ((a * a) * (a * a))) / (4.0 + (a * a))));
} else {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.4e+154: tmp = (a + 2.0) * (-1.0 / (a * a)) elif a <= -2.5e+58: tmp = (a + 2.0) * (1.0 / ((16.0 - ((a * a) * (a * a))) / (4.0 + (a * a)))) else: tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.4e+154) tmp = Float64(Float64(a + 2.0) * Float64(-1.0 / Float64(a * a))); elseif (a <= -2.5e+58) tmp = Float64(Float64(a + 2.0) * Float64(1.0 / Float64(Float64(16.0 - Float64(Float64(a * a) * Float64(a * a))) / Float64(4.0 + Float64(a * a))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(Float64(b * b) * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.4e+154) tmp = (a + 2.0) * (-1.0 / (a * a)); elseif (a <= -2.5e+58) tmp = (a + 2.0) * (1.0 / ((16.0 - ((a * a) * (a * a))) / (4.0 + (a * a)))); else tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.4e+154], N[(N[(a + 2.0), $MachinePrecision] * N[(-1.0 / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, -2.5e+58], N[(N[(a + 2.0), $MachinePrecision] * N[(1.0 / N[(N[(16.0 - N[(N[(a * a), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(4.0 + N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.4 \cdot 10^{+154}:\\
\;\;\;\;\left(a + 2\right) \cdot \frac{-1}{a \cdot a}\\
\mathbf{elif}\;a \leq -2.5 \cdot 10^{+58}:\\
\;\;\;\;\left(a + 2\right) \cdot \frac{1}{\frac{16 - \left(a \cdot a\right) \cdot \left(a \cdot a\right)}{4 + a \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + \left(b \cdot b\right) \cdot 0.5\right)}\\
\end{array}
\end{array}
if a < -1.4e154Initial 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-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 6.7%
neg-mul-16.7%
unsub-neg6.7%
Simplified6.7%
flip--100.0%
associate-/r/100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 100.0%
unpow2100.0%
Simplified100.0%
if -1.4e154 < a < -2.49999999999999993e58Initial 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-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 4.0%
neg-mul-14.0%
unsub-neg4.0%
Simplified4.0%
flip--4.0%
associate-/r/4.0%
metadata-eval4.0%
Applied egg-rr4.0%
sub-neg4.0%
flip-+85.2%
metadata-eval85.2%
distribute-rgt-neg-in85.2%
distribute-rgt-neg-in85.2%
distribute-rgt-neg-in85.2%
Applied egg-rr85.2%
if -2.49999999999999993e58 < a Initial 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-in92.1%
exp-neg92.1%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 94.7%
Taylor expanded in b around 0 61.1%
*-commutative61.1%
unpow261.1%
Simplified61.1%
Final simplification68.4%
(FPCore (a b) :precision binary64 (if (<= a -9.4e+64) (* (+ a 2.0) (/ -1.0 (* a a))) (if (<= a -0.75) (/ 2.0 (* b b)) (+ 0.5 (* a 0.25)))))
double code(double a, double b) {
double tmp;
if (a <= -9.4e+64) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else if (a <= -0.75) {
tmp = 2.0 / (b * 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 (a <= (-9.4d+64)) then
tmp = (a + 2.0d0) * ((-1.0d0) / (a * a))
else if (a <= (-0.75d0)) then
tmp = 2.0d0 / (b * 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 (a <= -9.4e+64) {
tmp = (a + 2.0) * (-1.0 / (a * a));
} else if (a <= -0.75) {
tmp = 2.0 / (b * b);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9.4e+64: tmp = (a + 2.0) * (-1.0 / (a * a)) elif a <= -0.75: tmp = 2.0 / (b * b) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -9.4e+64) tmp = Float64(Float64(a + 2.0) * Float64(-1.0 / Float64(a * a))); elseif (a <= -0.75) tmp = Float64(2.0 / Float64(b * b)); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -9.4e+64) tmp = (a + 2.0) * (-1.0 / (a * a)); elseif (a <= -0.75) tmp = 2.0 / (b * b); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9.4e+64], N[(N[(a + 2.0), $MachinePrecision] * N[(-1.0 / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, -0.75], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.4 \cdot 10^{+64}:\\
\;\;\;\;\left(a + 2\right) \cdot \frac{-1}{a \cdot a}\\
\mathbf{elif}\;a \leq -0.75:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -9.40000000000000058e64Initial 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-in0.0%
exp-neg0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 6.0%
neg-mul-16.0%
unsub-neg6.0%
Simplified6.0%
flip--76.4%
associate-/r/76.4%
metadata-eval76.4%
Applied egg-rr76.4%
Taylor expanded in a around inf 76.4%
unpow276.4%
Simplified76.4%
if -9.40000000000000058e64 < a < -0.75Initial program 93.3%
*-lft-identity93.3%
associate-/l*93.3%
remove-double-div93.3%
exp-neg93.3%
associate-/r/93.3%
/-rgt-identity93.3%
*-commutative93.3%
distribute-rgt-in6.7%
exp-neg6.7%
rgt-mult-inverse93.3%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 61.3%
Taylor expanded in b around 0 48.5%
*-commutative48.5%
unpow248.5%
Simplified48.5%
Taylor expanded in b around inf 48.1%
unpow248.1%
Simplified48.1%
if -0.75 < 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 55.2%
Taylor expanded in a around 0 53.2%
*-commutative53.2%
Simplified53.2%
Final simplification57.8%
(FPCore (a b) :precision binary64 (if (<= b 3.7e+152) (/ (+ a 2.0) (- 4.0 (* a a))) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 3.7e+152) {
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 <= 3.7d+152) 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 <= 3.7e+152) {
tmp = (a + 2.0) / (4.0 - (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.7e+152: 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 <= 3.7e+152) 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 <= 3.7e+152) 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, 3.7e+152], 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 3.7 \cdot 10^{+152}:\\
\;\;\;\;\frac{a + 2}{4 - a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 3.69999999999999996e152Initial 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-in73.6%
exp-neg73.6%
rgt-mult-inverse99.5%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 71.9%
Taylor expanded in a around 0 46.1%
neg-mul-146.1%
unsub-neg46.1%
Simplified46.1%
flip--61.0%
associate-/r/61.0%
metadata-eval61.0%
Applied egg-rr61.0%
associate-*l/61.0%
*-lft-identity61.0%
Simplified61.0%
if 3.69999999999999996e152 < 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-in69.4%
exp-neg69.4%
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.7%
*-commutative97.7%
unpow297.7%
Simplified97.7%
Taylor expanded in b around inf 97.7%
unpow297.7%
Simplified97.7%
Final simplification66.1%
(FPCore (a b) :precision binary64 (if (<= b 1.35e+24) (/ 1.0 (- 2.0 a)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.35e+24) {
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.35d+24) 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.35e+24) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.35e+24: tmp = 1.0 / (2.0 - a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.35e+24) 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.35e+24) tmp = 1.0 / (2.0 - a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.35e+24], 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.35 \cdot 10^{+24}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.35e24Initial program 98.4%
*-lft-identity98.4%
associate-/l*98.4%
remove-double-div98.4%
exp-neg98.3%
associate-/r/98.4%
/-rgt-identity98.4%
*-commutative98.4%
distribute-rgt-in74.6%
exp-neg74.6%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 78.0%
Taylor expanded in a around 0 53.0%
neg-mul-153.0%
unsub-neg53.0%
Simplified53.0%
if 1.35e24 < 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.7%
exp-neg68.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 55.0%
*-commutative55.0%
unpow255.0%
Simplified55.0%
Taylor expanded in b around inf 55.0%
unpow255.0%
Simplified55.0%
Final simplification53.5%
(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-in73.0%
exp-neg73.0%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.4%
Taylor expanded in a around 0 39.7%
*-commutative39.7%
Simplified39.7%
Final simplification39.7%
(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-in73.0%
exp-neg73.0%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.4%
Taylor expanded in a around 0 40.1%
neg-mul-140.1%
unsub-neg40.1%
Simplified40.1%
Final simplification40.1%
(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-in73.0%
exp-neg73.0%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 81.4%
Taylor expanded in b around 0 39.5%
Final simplification39.5%
(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 2023273
(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))))