
(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 14 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 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in69.4%
exp-neg69.4%
rgt-mult-inverse99.1%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
add-exp-log99.8%
log-rec99.8%
log1p-udef99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (or (<= (exp b) 0.1) (not (<= (exp b) 1.00000002))) (/ 1.0 (+ 1.0 (exp b))) (/ 1.0 (+ 1.0 (exp (- a))))))
double code(double a, double b) {
double tmp;
if ((exp(b) <= 0.1) || !(exp(b) <= 1.00000002)) {
tmp = 1.0 / (1.0 + exp(b));
} else {
tmp = 1.0 / (1.0 + exp(-a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((exp(b) <= 0.1d0) .or. (.not. (exp(b) <= 1.00000002d0))) then
tmp = 1.0d0 / (1.0d0 + exp(b))
else
tmp = 1.0d0 / (1.0d0 + exp(-a))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((Math.exp(b) <= 0.1) || !(Math.exp(b) <= 1.00000002)) {
tmp = 1.0 / (1.0 + Math.exp(b));
} else {
tmp = 1.0 / (1.0 + Math.exp(-a));
}
return tmp;
}
def code(a, b): tmp = 0 if (math.exp(b) <= 0.1) or not (math.exp(b) <= 1.00000002): tmp = 1.0 / (1.0 + math.exp(b)) else: tmp = 1.0 / (1.0 + math.exp(-a)) return tmp
function code(a, b) tmp = 0.0 if ((exp(b) <= 0.1) || !(exp(b) <= 1.00000002)) tmp = Float64(1.0 / Float64(1.0 + exp(b))); else tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((exp(b) <= 0.1) || ~((exp(b) <= 1.00000002))) tmp = 1.0 / (1.0 + exp(b)); else tmp = 1.0 / (1.0 + exp(-a)); end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[N[Exp[b], $MachinePrecision], 0.1], N[Not[LessEqual[N[Exp[b], $MachinePrecision], 1.00000002]], $MachinePrecision]], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 0.1 \lor \neg \left(e^{b} \leq 1.00000002\right):\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\end{array}
\end{array}
if (exp.f64 b) < 0.10000000000000001 or 1.0000000200000001 < (exp.f64 b) Initial program 97.2%
*-lft-identity97.2%
associate-/l*97.2%
remove-double-div97.2%
exp-neg97.2%
associate-/r/97.2%
/-rgt-identity97.2%
*-commutative97.2%
distribute-rgt-in78.2%
exp-neg78.2%
rgt-mult-inverse98.1%
prod-exp99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
if 0.10000000000000001 < (exp.f64 b) < 1.0000000200000001Initial program 97.8%
*-lft-identity97.8%
associate-/l*97.8%
remove-double-div97.8%
exp-neg97.7%
associate-/r/97.7%
/-rgt-identity97.7%
*-commutative97.7%
distribute-rgt-in61.4%
exp-neg61.5%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 99.8%
Final simplification99.8%
(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 69.4%
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 96.6%
*-lft-identity96.6%
associate-/l*96.5%
remove-double-div96.5%
exp-neg96.5%
associate-/r/96.5%
/-rgt-identity96.5%
*-commutative96.5%
distribute-rgt-in96.5%
exp-neg96.5%
rgt-mult-inverse98.7%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in a around 0 97.0%
Final simplification97.9%
(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 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in69.4%
exp-neg69.4%
rgt-mult-inverse99.1%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (a b) :precision binary64 (if (<= a -0.115) (/ (exp a) b) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -0.115) {
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 (a <= (-0.115d0)) 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 (a <= -0.115) {
tmp = Math.exp(a) / b;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.115: tmp = math.exp(a) / b else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.115) 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 (a <= -0.115) tmp = exp(a) / b; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.115], N[(N[Exp[a], $MachinePrecision] / b), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.115:\\
\;\;\;\;\frac{e^{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -0.115000000000000005Initial 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-in4.0%
exp-neg4.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.9%
distribute-rgt1-in96.3%
rec-exp96.3%
associate-*r/96.3%
+-commutative96.3%
*-rgt-identity96.3%
Simplified96.3%
Taylor expanded in b around inf 96.3%
if -0.115000000000000005 < a Initial program 96.5%
*-lft-identity96.5%
associate-/l*96.5%
remove-double-div96.5%
exp-neg96.5%
associate-/r/96.5%
/-rgt-identity96.5%
*-commutative96.5%
distribute-rgt-in96.5%
exp-neg96.5%
rgt-mult-inverse98.7%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 53.4%
Taylor expanded in a around 0 50.9%
*-commutative50.9%
Simplified50.9%
Final simplification64.2%
(FPCore (a b) :precision binary64 (if (<= b -0.95) 0.5 (/ 1.0 (+ 2.0 (+ b (* a (- -1.0 b)))))))
double code(double a, double b) {
double tmp;
if (b <= -0.95) {
tmp = 0.5;
} else {
tmp = 1.0 / (2.0 + (b + (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 <= (-0.95d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / (2.0d0 + (b + (a * ((-1.0d0) - b))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.95) {
tmp = 0.5;
} else {
tmp = 1.0 / (2.0 + (b + (a * (-1.0 - b))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.95: tmp = 0.5 else: tmp = 1.0 / (2.0 + (b + (a * (-1.0 - b)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.95) tmp = 0.5; else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(a * Float64(-1.0 - b))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.95) tmp = 0.5; else tmp = 1.0 / (2.0 + (b + (a * (-1.0 - b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.95], 0.5, N[(1.0 / N[(2.0 + N[(b + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.95:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + a \cdot \left(-1 - b\right)\right)}\\
\end{array}
\end{array}
if b < -0.94999999999999996Initial program 97.6%
*-lft-identity97.6%
associate-/l*97.6%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in97.5%
exp-neg97.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 18.8%
if -0.94999999999999996 < b Initial program 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in64.0%
exp-neg64.0%
rgt-mult-inverse98.9%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 65.4%
distribute-rgt1-in75.6%
rec-exp75.7%
associate-*r/75.7%
+-commutative75.7%
*-rgt-identity75.7%
Simplified75.7%
Taylor expanded in a around 0 48.6%
mul-1-neg48.6%
unsub-neg48.6%
Simplified48.6%
Final simplification43.8%
(FPCore (a b) :precision binary64 (if (<= b -1.15) 0.5 (/ 1.0 (+ 1.0 (* (- 1.0 a) (+ b 1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -1.15) {
tmp = 0.5;
} else {
tmp = 1.0 / (1.0 + ((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 <= (-1.15d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / (1.0d0 + ((1.0d0 - a) * (b + 1.0d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.15) {
tmp = 0.5;
} else {
tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.15: tmp = 0.5 else: tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0))) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.15) tmp = 0.5; else tmp = Float64(1.0 / Float64(1.0 + Float64(Float64(1.0 - a) * Float64(b + 1.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.15) tmp = 0.5; else tmp = 1.0 / (1.0 + ((1.0 - a) * (b + 1.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.15], 0.5, N[(1.0 / N[(1.0 + N[(N[(1.0 - a), $MachinePrecision] * N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \left(1 - a\right) \cdot \left(b + 1\right)}\\
\end{array}
\end{array}
if b < -1.1499999999999999Initial program 97.6%
*-lft-identity97.6%
associate-/l*97.6%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in97.5%
exp-neg97.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 18.8%
if -1.1499999999999999 < b Initial program 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in64.0%
exp-neg64.0%
rgt-mult-inverse98.9%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 65.4%
distribute-rgt1-in75.6%
rec-exp75.7%
associate-*r/75.7%
+-commutative75.7%
*-rgt-identity75.7%
Simplified75.7%
Taylor expanded in a around 0 48.6%
associate-+r+48.6%
associate-*r*48.6%
distribute-rgt1-in48.6%
neg-mul-148.6%
Simplified48.6%
Final simplification43.8%
(FPCore (a b) :precision binary64 (if (<= a -0.115) (/ -1.0 (* a (+ b 1.0))) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -0.115) {
tmp = -1.0 / (a * (b + 1.0));
} 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 <= (-0.115d0)) then
tmp = (-1.0d0) / (a * (b + 1.0d0))
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 <= -0.115) {
tmp = -1.0 / (a * (b + 1.0));
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.115: tmp = -1.0 / (a * (b + 1.0)) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.115) tmp = Float64(-1.0 / Float64(a * Float64(b + 1.0))); else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -0.115) tmp = -1.0 / (a * (b + 1.0)); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.115], N[(-1.0 / N[(a * N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.115:\\
\;\;\;\;\frac{-1}{a \cdot \left(b + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -0.115000000000000005Initial 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-in4.0%
exp-neg4.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.9%
distribute-rgt1-in96.3%
rec-exp96.3%
associate-*r/96.3%
+-commutative96.3%
*-rgt-identity96.3%
Simplified96.3%
Taylor expanded in a around 0 24.5%
mul-1-neg24.5%
unsub-neg24.5%
Simplified24.5%
Taylor expanded in a around inf 24.5%
if -0.115000000000000005 < a Initial program 96.5%
*-lft-identity96.5%
associate-/l*96.5%
remove-double-div96.5%
exp-neg96.5%
associate-/r/96.5%
/-rgt-identity96.5%
*-commutative96.5%
distribute-rgt-in96.5%
exp-neg96.5%
rgt-mult-inverse98.7%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 53.4%
Taylor expanded in a around 0 50.9%
*-commutative50.9%
Simplified50.9%
Final simplification43.2%
(FPCore (a b) :precision binary64 (if (<= b 2.0) (/ 1.0 (- 2.0 a)) (/ 1.0 (* b (- 1.0 a)))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 1.0 / (2.0 - a);
} 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 <= 2.0d0) then
tmp = 1.0d0 / (2.0d0 - a)
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 <= 2.0) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 1.0 / (b * (1.0 - a));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 1.0 / (2.0 - a) else: tmp = 1.0 / (b * (1.0 - a)) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(1.0 / Float64(b * Float64(1.0 - a))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.0) tmp = 1.0 / (2.0 - a); else tmp = 1.0 / (b * (1.0 - a)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b \cdot \left(1 - a\right)}\\
\end{array}
\end{array}
if b < 2Initial program 97.7%
*-lft-identity97.7%
associate-/l*97.7%
remove-double-div97.7%
exp-neg97.7%
associate-/r/97.7%
/-rgt-identity97.7%
*-commutative97.7%
distribute-rgt-in70.2%
exp-neg70.2%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 81.0%
Taylor expanded in a around 0 52.0%
neg-mul-152.0%
unsub-neg52.0%
Simplified52.0%
if 2 < b Initial program 97.0%
*-lft-identity97.0%
associate-/l*97.0%
remove-double-div97.0%
exp-neg97.0%
associate-/r/97.0%
/-rgt-identity97.0%
*-commutative97.0%
distribute-rgt-in67.5%
exp-neg67.5%
rgt-mult-inverse97.0%
prod-exp99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in b around 0 33.3%
distribute-rgt1-in33.3%
rec-exp33.3%
associate-*r/33.3%
+-commutative33.3%
*-rgt-identity33.3%
Simplified33.3%
Taylor expanded in a around 0 23.7%
mul-1-neg23.7%
unsub-neg23.7%
Simplified23.7%
Taylor expanded in b around inf 23.7%
Final simplification43.4%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (- -1.0 b)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 - b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((-1.0d0) - b)))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 - b)));
}
def code(a, b): return 1.0 / (2.0 + (a * (-1.0 - b)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 - b)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (-1.0 - b))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(-1.0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(-1 - b\right)}
\end{array}
Initial program 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in69.4%
exp-neg69.4%
rgt-mult-inverse99.1%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 55.7%
distribute-rgt1-in64.3%
rec-exp64.3%
associate-*r/64.3%
+-commutative64.3%
*-rgt-identity64.3%
Simplified64.3%
Taylor expanded in a around 0 41.2%
mul-1-neg41.2%
unsub-neg41.2%
Simplified41.2%
Taylor expanded in a around inf 42.0%
mul-1-neg42.0%
distribute-rgt-neg-out42.0%
distribute-neg-in42.0%
metadata-eval42.0%
unsub-neg42.0%
Simplified42.0%
Final simplification42.0%
(FPCore (a b) :precision binary64 (if (<= a -0.115) (/ -1.0 (* b a)) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -0.115) {
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 <= (-0.115d0)) 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 <= -0.115) {
tmp = -1.0 / (b * a);
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.115: tmp = -1.0 / (b * a) else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.115) 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 <= -0.115) tmp = -1.0 / (b * a); else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.115], 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 -0.115:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -0.115000000000000005Initial 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-in4.0%
exp-neg4.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 66.9%
distribute-rgt1-in96.3%
rec-exp96.3%
associate-*r/96.3%
+-commutative96.3%
*-rgt-identity96.3%
Simplified96.3%
Taylor expanded in a around 0 24.5%
mul-1-neg24.5%
unsub-neg24.5%
Simplified24.5%
Taylor expanded in a around inf 24.5%
mul-1-neg24.5%
distribute-rgt-neg-out24.5%
distribute-neg-in24.5%
metadata-eval24.5%
unsub-neg24.5%
Simplified24.5%
Taylor expanded in b around inf 23.2%
if -0.115000000000000005 < a Initial program 96.5%
*-lft-identity96.5%
associate-/l*96.5%
remove-double-div96.5%
exp-neg96.5%
associate-/r/96.5%
/-rgt-identity96.5%
*-commutative96.5%
distribute-rgt-in96.5%
exp-neg96.5%
rgt-mult-inverse98.7%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 53.4%
Taylor expanded in a around 0 50.9%
*-commutative50.9%
Simplified50.9%
Final simplification42.8%
(FPCore (a b) :precision binary64 (if (<= b 3.3e+90) (/ 1.0 (- 2.0 a)) (/ -1.0 (* b a))))
double code(double a, double b) {
double tmp;
if (b <= 3.3e+90) {
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 <= 3.3d+90) 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 <= 3.3e+90) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = -1.0 / (b * a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.3e+90: tmp = 1.0 / (2.0 - a) else: tmp = -1.0 / (b * a) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.3e+90) 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 <= 3.3e+90) tmp = 1.0 / (2.0 - a); else tmp = -1.0 / (b * a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.3e+90], 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 3.3 \cdot 10^{+90}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{b \cdot a}\\
\end{array}
\end{array}
if b < 3.30000000000000008e90Initial program 97.4%
*-lft-identity97.4%
associate-/l*97.4%
remove-double-div97.3%
exp-neg97.3%
associate-/r/97.3%
/-rgt-identity97.3%
*-commutative97.3%
distribute-rgt-in70.2%
exp-neg70.3%
rgt-mult-inverse99.3%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 74.3%
Taylor expanded in a around 0 46.0%
neg-mul-146.0%
unsub-neg46.0%
Simplified46.0%
if 3.30000000000000008e90 < b Initial program 98.1%
*-lft-identity98.1%
associate-/l*98.1%
remove-double-div98.1%
exp-neg98.1%
associate-/r/98.1%
/-rgt-identity98.1%
*-commutative98.1%
distribute-rgt-in66.0%
exp-neg66.0%
rgt-mult-inverse98.1%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 36.5%
distribute-rgt1-in36.5%
rec-exp36.5%
associate-*r/36.5%
+-commutative36.5%
*-rgt-identity36.5%
Simplified36.5%
Taylor expanded in a around 0 33.1%
mul-1-neg33.1%
unsub-neg33.1%
Simplified33.1%
Taylor expanded in a around inf 31.6%
mul-1-neg31.6%
distribute-rgt-neg-out31.6%
distribute-neg-in31.6%
metadata-eval31.6%
unsub-neg31.6%
Simplified31.6%
Taylor expanded in b around inf 31.6%
Final simplification43.0%
(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 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in69.4%
exp-neg69.4%
rgt-mult-inverse99.1%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in b around 0 66.0%
Taylor expanded in a around 0 36.7%
*-commutative36.7%
Simplified36.7%
Final simplification36.7%
(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 97.5%
*-lft-identity97.5%
associate-/l*97.5%
remove-double-div97.5%
exp-neg97.5%
associate-/r/97.5%
/-rgt-identity97.5%
*-commutative97.5%
distribute-rgt-in69.4%
exp-neg69.4%
rgt-mult-inverse99.1%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in a around 0 79.3%
Taylor expanded in b around 0 36.5%
Final simplification36.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 2023333
(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))))