
(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 13 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-in74.6%
exp-neg74.6%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
add-log-exp99.6%
*-un-lft-identity99.6%
log-prod99.6%
metadata-eval99.6%
add-log-exp100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.999998) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999998) {
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.999998d0) 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.999998) {
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.999998: 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.999998) 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.999998) 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.999998], 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.999998:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999998000000000054Initial 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-in1.5%
exp-neg1.5%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if 0.999998000000000054 < (exp.f64 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-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.2%
Final simplification99.4%
(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 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 70.3%
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 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.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 99.0%
Final simplification99.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 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-in74.6%
exp-neg74.6%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= b -360.0)
(+ 1.0 (exp b))
(if (<= b 1.06e+138)
(/
1.0
(+
1.0
(+ 1.0 (+ b (- (* a (- -1.0 b)) (* (* a a) (+ -0.5 (* b -0.5))))))))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= -360.0) {
tmp = 1.0 + exp(b);
} else if (b <= 1.06e+138) {
tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5)))))));
} 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 <= (-360.0d0)) then
tmp = 1.0d0 + exp(b)
else if (b <= 1.06d+138) then
tmp = 1.0d0 / (1.0d0 + (1.0d0 + (b + ((a * ((-1.0d0) - b)) - ((a * a) * ((-0.5d0) + (b * (-0.5d0))))))))
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -360.0) {
tmp = 1.0 + Math.exp(b);
} else if (b <= 1.06e+138) {
tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5)))))));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -360.0: tmp = 1.0 + math.exp(b) elif b <= 1.06e+138: tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5))))))) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= -360.0) tmp = Float64(1.0 + exp(b)); elseif (b <= 1.06e+138) tmp = Float64(1.0 / Float64(1.0 + Float64(1.0 + Float64(b + Float64(Float64(a * Float64(-1.0 - b)) - Float64(Float64(a * a) * Float64(-0.5 + Float64(b * -0.5)))))))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -360.0) tmp = 1.0 + exp(b); elseif (b <= 1.06e+138) tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5))))))); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -360.0], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.06e+138], N[(1.0 / N[(1.0 + N[(1.0 + N[(b + N[(N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision] - N[(N[(a * a), $MachinePrecision] * N[(-0.5 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -360:\\
\;\;\;\;1 + e^{b}\\
\mathbf{elif}\;b \leq 1.06 \cdot 10^{+138}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(b + \left(a \cdot \left(-1 - b\right) - \left(a \cdot a\right) \cdot \left(-0.5 + b \cdot -0.5\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < -360Initial 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%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
add-exp-log100.0%
log-rec100.0%
log1p-udef100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.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%
add-exp-log100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -360 < b < 1.05999999999999994e138Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.3%
remove-double-div99.3%
exp-neg99.3%
associate-/r/99.3%
/-rgt-identity99.3%
*-commutative99.3%
distribute-rgt-in67.6%
exp-neg67.6%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 75.4%
distribute-rgt1-in86.8%
rec-exp86.8%
associate-*r/86.8%
*-rgt-identity86.8%
+-commutative86.8%
Simplified86.8%
Taylor expanded in a around 0 72.8%
distribute-lft-out72.8%
unpow272.8%
distribute-rgt-out72.8%
+-commutative72.8%
metadata-eval72.8%
distribute-rgt1-in72.8%
Simplified72.8%
if 1.05999999999999994e138 < 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 92.4%
unpow292.4%
Simplified92.4%
Taylor expanded in b around inf 92.4%
unpow292.4%
Simplified92.4%
Final simplification81.2%
(FPCore (a b)
:precision binary64
(if (<= b -0.0028)
(/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a)))
(if (<= b 1.06e+138)
(/
1.0
(+
1.0
(+ 1.0 (+ b (- (* a (- -1.0 b)) (* (* a a) (+ -0.5 (* b -0.5))))))))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= -0.0028) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else if (b <= 1.06e+138) {
tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5)))))));
} 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 <= (-0.0028d0)) then
tmp = 1.0d0 / (2.0d0 + ((a * (a * 0.5d0)) - a))
else if (b <= 1.06d+138) then
tmp = 1.0d0 / (1.0d0 + (1.0d0 + (b + ((a * ((-1.0d0) - b)) - ((a * a) * ((-0.5d0) + (b * (-0.5d0))))))))
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.0028) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else if (b <= 1.06e+138) {
tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5)))))));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.0028: tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)) elif b <= 1.06e+138: tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5))))))) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.0028) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(a * Float64(a * 0.5)) - a))); elseif (b <= 1.06e+138) tmp = Float64(1.0 / Float64(1.0 + Float64(1.0 + Float64(b + Float64(Float64(a * Float64(-1.0 - b)) - Float64(Float64(a * a) * Float64(-0.5 + Float64(b * -0.5)))))))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.0028) tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)); elseif (b <= 1.06e+138) tmp = 1.0 / (1.0 + (1.0 + (b + ((a * (-1.0 - b)) - ((a * a) * (-0.5 + (b * -0.5))))))); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.0028], N[(1.0 / N[(2.0 + N[(N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.06e+138], N[(1.0 / N[(1.0 + N[(1.0 + N[(b + N[(N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision] - N[(N[(a * a), $MachinePrecision] * N[(-0.5 + N[(b * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0028:\\
\;\;\;\;\frac{1}{2 + \left(a \cdot \left(a \cdot 0.5\right) - a\right)}\\
\mathbf{elif}\;b \leq 1.06 \cdot 10^{+138}:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left(b + \left(a \cdot \left(-1 - b\right) - \left(a \cdot a\right) \cdot \left(-0.5 + b \cdot -0.5\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < -0.00279999999999999997Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in96.4%
exp-neg96.4%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 21.7%
Taylor expanded in a around 0 20.0%
+-commutative20.0%
neg-mul-120.0%
unsub-neg20.0%
*-commutative20.0%
unpow220.0%
associate-*l*20.0%
Simplified20.0%
if -0.00279999999999999997 < b < 1.05999999999999994e138Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.3%
remove-double-div99.3%
exp-neg99.3%
associate-/r/99.3%
/-rgt-identity99.3%
*-commutative99.3%
distribute-rgt-in68.2%
exp-neg68.2%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 76.8%
distribute-rgt1-in87.2%
rec-exp87.2%
associate-*r/87.2%
*-rgt-identity87.2%
+-commutative87.2%
Simplified87.2%
Taylor expanded in a around 0 73.5%
distribute-lft-out73.5%
unpow273.5%
distribute-rgt-out73.5%
+-commutative73.5%
metadata-eval73.5%
distribute-rgt1-in73.5%
Simplified73.5%
if 1.05999999999999994e138 < 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 92.4%
unpow292.4%
Simplified92.4%
Taylor expanded in b around inf 92.4%
unpow292.4%
Simplified92.4%
Final simplification64.4%
(FPCore (a b) :precision binary64 (if (<= b 1.25e+126) (/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a))) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e+126) {
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 <= 1.25d+126) 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 <= 1.25e+126) {
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 <= 1.25e+126: 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 <= 1.25e+126) 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 <= 1.25e+126) 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, 1.25e+126], 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 1.25 \cdot 10^{+126}:\\
\;\;\;\;\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 < 1.24999999999999994e126Initial 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-in75.6%
exp-neg75.6%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 70.3%
Taylor expanded in a around 0 58.3%
+-commutative58.3%
neg-mul-158.3%
unsub-neg58.3%
*-commutative58.3%
unpow258.3%
associate-*l*58.3%
Simplified58.3%
if 1.24999999999999994e126 < 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.4%
exp-neg68.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 87.9%
unpow287.9%
Simplified87.9%
Taylor expanded in b around inf 87.9%
unpow287.9%
Simplified87.9%
Final simplification62.7%
(FPCore (a b) :precision binary64 (if (<= b 1.25e+126) (/ (+ a 2.0) (- 4.0 (* a a))) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e+126) {
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.25d+126) 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.25e+126) {
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.25e+126: 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.25e+126) 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.25e+126) 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.25e+126], 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.25 \cdot 10^{+126}:\\
\;\;\;\;\frac{a + 2}{4 - a \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.24999999999999994e126Initial 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-in75.6%
exp-neg75.6%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 70.3%
Taylor expanded in a around 0 47.2%
neg-mul-147.2%
unsub-neg47.2%
Simplified47.2%
flip--57.9%
associate-/r/57.9%
metadata-eval57.9%
Applied egg-rr57.9%
associate-*l/57.9%
*-lft-identity57.9%
Simplified57.9%
if 1.24999999999999994e126 < 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.4%
exp-neg68.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 87.9%
unpow287.9%
Simplified87.9%
Taylor expanded in b around inf 87.9%
unpow287.9%
Simplified87.9%
Final simplification62.3%
(FPCore (a b) :precision binary64 (if (<= a -1.3e+75) (/ -1.0 (* b a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -1.3e+75) {
tmp = -1.0 / (b * 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 <= (-1.3d+75)) then
tmp = (-1.0d0) / (b * 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 <= -1.3e+75) {
tmp = -1.0 / (b * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.3e+75: tmp = -1.0 / (b * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.3e+75) tmp = Float64(-1.0 / Float64(b * 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 <= -1.3e+75) tmp = -1.0 / (b * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.3e+75], N[(-1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.3 \cdot 10^{+75}:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -1.29999999999999992e75Initial 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 74.5%
distribute-rgt1-in100.0%
rec-exp100.0%
associate-*r/100.0%
*-rgt-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 28.2%
associate-+r+28.2%
+-commutative28.2%
associate-+l+28.2%
mul-1-neg28.2%
distribute-rgt-neg-in28.2%
distribute-neg-in28.2%
metadata-eval28.2%
unsub-neg28.2%
Simplified28.2%
Taylor expanded in a around inf 28.2%
distribute-lft-in28.2%
*-rgt-identity28.2%
Simplified28.2%
Taylor expanded in b around inf 26.9%
*-commutative26.9%
Simplified26.9%
if -1.29999999999999992e75 < a Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in95.0%
exp-neg95.0%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 55.3%
Taylor expanded in a around 0 50.5%
*-commutative50.5%
Simplified50.5%
Final simplification45.4%
(FPCore (a b) :precision binary64 (if (<= b 2.6e+51) (/ 1.0 (- 2.0 a)) (/ -1.0 (* b a))))
double code(double a, double b) {
double tmp;
if (b <= 2.6e+51) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -1.0 / (b * a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.6d+51) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = (-1.0d0) / (b * a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.6e+51) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -1.0 / (b * a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.6e+51: tmp = 1.0 / (2.0 - a) else: tmp = -1.0 / (b * a) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.6e+51) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(-1.0 / Float64(b * a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.6e+51) tmp = 1.0 / (2.0 - a); else tmp = -1.0 / (b * a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.6e+51], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(b * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.6 \cdot 10^{+51}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\end{array}
\end{array}
if b < 2.6000000000000001e51Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in76.8%
exp-neg76.8%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 73.3%
Taylor expanded in a around 0 51.3%
neg-mul-151.3%
unsub-neg51.3%
Simplified51.3%
if 2.6000000000000001e51 < 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-in66.7%
exp-neg66.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 37.2%
distribute-rgt1-in37.2%
rec-exp37.2%
associate-*r/37.2%
*-rgt-identity37.2%
+-commutative37.2%
Simplified37.2%
Taylor expanded in a around 0 27.4%
associate-+r+27.4%
+-commutative27.4%
associate-+l+27.4%
mul-1-neg27.4%
distribute-rgt-neg-in27.4%
distribute-neg-in27.4%
metadata-eval27.4%
unsub-neg27.4%
Simplified27.4%
Taylor expanded in a around inf 25.8%
distribute-lft-in25.8%
*-rgt-identity25.8%
Simplified25.8%
Taylor expanded in b around inf 25.8%
*-commutative25.8%
Simplified25.8%
Final simplification45.6%
(FPCore (a b) :precision binary64 (if (<= b 9.5e+63) (/ 1.0 (- 2.0 a)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 9.5e+63) {
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 <= 9.5d+63) 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 <= 9.5e+63) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 9.5e+63: tmp = 1.0 / (2.0 - a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 9.5e+63) 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 <= 9.5e+63) tmp = 1.0 / (2.0 - a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 9.5e+63], 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 9.5 \cdot 10^{+63}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 9.5000000000000003e63Initial program 99.5%
*-lft-identity99.5%
associate-/l*99.5%
remove-double-div99.5%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in75.3%
exp-neg75.3%
rgt-mult-inverse99.9%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 73.9%
Taylor expanded in a around 0 50.5%
neg-mul-150.5%
unsub-neg50.5%
Simplified50.5%
if 9.5000000000000003e63 < 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-in71.7%
exp-neg71.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 64.6%
unpow264.6%
Simplified64.6%
Taylor expanded in b around inf 64.6%
unpow264.6%
Simplified64.6%
Final simplification53.4%
(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 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-in74.6%
exp-neg74.6%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 40.1%
*-commutative40.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 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-in74.6%
exp-neg74.6%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 82.6%
Taylor expanded in b around 0 40.0%
Final simplification40.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 2023275
(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))))