
(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 10 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%
*-lft-identity98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
times-frac98.8%
exp-neg98.8%
/-rgt-identity98.8%
distribute-lft-in68.7%
exp-neg68.7%
lft-mult-inverse99.6%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -6e-8) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -6e-8) {
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 (a <= (-6d-8)) 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 (a <= -6e-8) {
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 a <= -6e-8: 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 (a <= -6e-8) 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 (a <= -6e-8) 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[a, -6e-8], 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}\;a \leq -6 \cdot 10^{-8}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -5.99999999999999946e-8Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
times-frac100.0%
exp-neg99.9%
/-rgt-identity99.9%
distribute-lft-in4.9%
exp-neg4.9%
lft-mult-inverse100.0%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 99.0%
if -5.99999999999999946e-8 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
*-lft-identity98.3%
metadata-eval98.3%
times-frac98.3%
*-commutative98.3%
times-frac98.3%
exp-neg98.3%
/-rgt-identity98.3%
distribute-lft-in98.3%
exp-neg98.3%
lft-mult-inverse99.4%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 98.3%
Final simplification98.5%
(FPCore (a b) :precision binary64 (if (<= a -720.0) (/ (exp a) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -720.0) {
tmp = exp(a) / 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 (a <= (-720.0d0)) then
tmp = exp(a) / 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 (a <= -720.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -720.0: tmp = math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -720.0) tmp = Float64(exp(a) / 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 (a <= -720.0) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -720.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -720:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -720Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -720 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
*-lft-identity98.3%
metadata-eval98.3%
times-frac98.3%
*-commutative98.3%
times-frac98.3%
exp-neg98.3%
/-rgt-identity98.3%
distribute-lft-in98.3%
exp-neg98.3%
lft-mult-inverse99.4%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.3%
Final simplification98.1%
(FPCore (a b) :precision binary64 (if (<= a -0.52) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -0.52) {
tmp = exp(a) / (a + 2.0);
} 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 <= (-0.52d0)) then
tmp = exp(a) / (a + 2.0d0)
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 <= -0.52) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -0.52: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -0.52) tmp = Float64(exp(a) / Float64(a + 2.0)); 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 <= -0.52) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -0.52], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.52:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -0.52000000000000002Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 99.0%
+-commutative99.0%
Simplified99.0%
if -0.52000000000000002 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
*-lft-identity98.3%
metadata-eval98.3%
times-frac98.3%
*-commutative98.3%
times-frac98.3%
exp-neg98.3%
/-rgt-identity98.3%
distribute-lft-in98.3%
exp-neg98.3%
lft-mult-inverse99.4%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 97.7%
Final simplification98.1%
(FPCore (a b) :precision binary64 (if (<= a -2.2) (/ (exp a) a) (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (a <= -2.2) {
tmp = exp(a) / 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 <= (-2.2d0)) then
tmp = exp(a) / 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 <= -2.2) {
tmp = Math.exp(a) / a;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.2: tmp = math.exp(a) / a else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.2) tmp = Float64(exp(a) / 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 <= -2.2) tmp = exp(a) / a; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.2], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.2:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -2.2000000000000002Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -2.2000000000000002 < a Initial program 98.3%
*-lft-identity98.3%
associate-/l*98.3%
*-lft-identity98.3%
metadata-eval98.3%
times-frac98.3%
*-commutative98.3%
times-frac98.3%
exp-neg98.3%
/-rgt-identity98.3%
distribute-lft-in98.3%
exp-neg98.3%
lft-mult-inverse99.4%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 57.1%
Taylor expanded in a around 0 55.2%
*-commutative55.2%
Simplified55.2%
Final simplification68.7%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 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 (b <= (-1.0d0)) then
tmp = 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 (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 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 (b <= -1.0) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -1Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
times-frac100.0%
exp-neg100.0%
/-rgt-identity100.0%
distribute-lft-in100.0%
exp-neg100.0%
lft-mult-inverse100.0%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
rec-exp100.0%
log1p-def100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
associate-/l*100.0%
*-un-lft-identity100.0%
add-sqr-sqrt100.0%
associate-/l*100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -1 < b Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
*-lft-identity98.6%
metadata-eval98.6%
times-frac98.6%
*-commutative98.6%
times-frac98.6%
exp-neg98.6%
/-rgt-identity98.6%
distribute-lft-in64.1%
exp-neg64.1%
lft-mult-inverse99.5%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 77.6%
Taylor expanded in a around 0 42.3%
*-commutative42.3%
Simplified42.3%
Final simplification49.8%
(FPCore (a b) :precision binary64 (if (<= b -2.0) 1.0 (+ 0.5 (* b -0.25))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (b * -0.25);
}
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
else
tmp = 0.5d0 + (b * (-0.25d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (b * -0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 1.0 else: tmp = 0.5 + (b * -0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = 1.0; else tmp = Float64(0.5 + Float64(b * -0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 1.0; else tmp = 0.5 + (b * -0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], 1.0, N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\end{array}
\end{array}
if b < -2Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
times-frac100.0%
exp-neg100.0%
/-rgt-identity100.0%
distribute-lft-in100.0%
exp-neg100.0%
lft-mult-inverse100.0%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
rec-exp100.0%
log1p-def100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
associate-/l*100.0%
*-un-lft-identity100.0%
add-sqr-sqrt100.0%
associate-/l*100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -2 < b Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
*-lft-identity98.6%
metadata-eval98.6%
times-frac98.6%
*-commutative98.6%
times-frac98.6%
exp-neg98.6%
/-rgt-identity98.6%
distribute-lft-in64.1%
exp-neg64.1%
lft-mult-inverse99.5%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 76.5%
Taylor expanded in b around 0 43.2%
*-commutative43.2%
Simplified43.2%
Final simplification50.5%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.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.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.0) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -1Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
times-frac100.0%
exp-neg100.0%
/-rgt-identity100.0%
distribute-lft-in100.0%
exp-neg100.0%
lft-mult-inverse100.0%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
rec-exp100.0%
log1p-def100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
associate-/l*100.0%
*-un-lft-identity100.0%
add-sqr-sqrt100.0%
associate-/l*100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -1 < b Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
*-lft-identity98.6%
metadata-eval98.6%
times-frac98.6%
*-commutative98.6%
times-frac98.6%
exp-neg98.6%
/-rgt-identity98.6%
distribute-lft-in64.1%
exp-neg64.1%
lft-mult-inverse99.5%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 76.5%
Taylor expanded in b around 0 43.8%
+-commutative43.8%
Simplified43.8%
Final simplification51.1%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 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 <= (-1.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.0) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -1Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
times-frac100.0%
exp-neg100.0%
/-rgt-identity100.0%
distribute-lft-in100.0%
exp-neg100.0%
lft-mult-inverse100.0%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
add-exp-log100.0%
rec-exp100.0%
log1p-def100.0%
Applied egg-rr100.0%
*-un-lft-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
associate-/l*100.0%
*-un-lft-identity100.0%
add-sqr-sqrt100.0%
associate-/l*100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -1 < b Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
*-lft-identity98.6%
metadata-eval98.6%
times-frac98.6%
*-commutative98.6%
times-frac98.6%
exp-neg98.6%
/-rgt-identity98.6%
distribute-lft-in64.1%
exp-neg64.1%
lft-mult-inverse99.5%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 76.5%
Taylor expanded in b around 0 42.0%
Final simplification49.5%
(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%
*-lft-identity98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
times-frac98.8%
exp-neg98.8%
/-rgt-identity98.8%
distribute-lft-in68.7%
exp-neg68.7%
lft-mult-inverse99.6%
prod-exp100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 79.6%
Taylor expanded in b around 0 39.0%
Final simplification39.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 2023305
(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))))