
(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 9 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 99.6%
add-cbrt-cube99.0%
pow1/399.6%
pow399.6%
clear-num99.6%
inv-pow99.6%
pow-pow99.6%
metadata-eval99.6%
Applied egg-rr99.6%
unpow1/399.0%
+-commutative99.0%
Simplified99.0%
expm1-log1p-u99.0%
expm1-udef99.5%
pow1/399.5%
pow-pow99.5%
metadata-eval99.5%
Applied egg-rr99.5%
expm1-def99.6%
expm1-log1p99.6%
unpow-199.6%
rem-exp-log99.6%
exp-diff100.0%
sub-neg100.0%
prod-exp99.6%
rem-exp-log99.6%
*-commutative99.6%
+-commutative99.6%
distribute-lft-in77.3%
rec-exp77.3%
lft-mult-inverse99.6%
prod-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -5.8e-15) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -5.8e-15) {
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 <= (-5.8d-15)) 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 <= -5.8e-15) {
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 <= -5.8e-15: 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 <= -5.8e-15) 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 <= -5.8e-15) 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, -5.8e-15], 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 -5.8 \cdot 10^{-15}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -5.80000000000000037e-15Initial program 100.0%
add-cbrt-cube99.9%
pow1/399.9%
pow3100.0%
clear-num99.9%
inv-pow99.9%
pow-pow99.9%
metadata-eval99.9%
Applied egg-rr99.9%
unpow1/399.9%
+-commutative99.9%
Simplified99.9%
expm1-log1p-u99.9%
expm1-udef99.9%
pow1/399.9%
pow-pow99.9%
metadata-eval99.9%
Applied egg-rr99.9%
expm1-def99.9%
expm1-log1p99.9%
unpow-199.9%
rem-exp-log99.9%
exp-diff100.0%
sub-neg100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in5.0%
rec-exp5.0%
lft-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if -5.80000000000000037e-15 < a Initial program 99.5%
Taylor expanded in a around 0 98.9%
Final simplification99.2%
(FPCore (a b) :precision binary64 (if (<= a -720.0) 0.0 (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -720.0) {
tmp = 0.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 <= (-720.0d0)) then
tmp = 0.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 <= -720.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -720.0: tmp = 0.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -720.0) tmp = 0.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 <= -720.0) tmp = 0.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -720.0], 0.0, N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -720:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -720Initial program 100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/3100.0%
+-commutative100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
pow1/3100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
unpow-1100.0%
rem-exp-log100.0%
exp-diff100.0%
sub-neg100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in0.0%
rec-exp0.0%
lft-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Applied egg-rr100.0%
if -720 < a Initial program 99.5%
Taylor expanded in a around 0 98.4%
Final simplification98.8%
(FPCore (a b) :precision binary64 (if (<= a -5.8e-15) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -5.8e-15) {
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 <= (-5.8d-15)) 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 <= -5.8e-15) {
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 <= -5.8e-15: 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 <= -5.8e-15) 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 <= -5.8e-15) 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, -5.8e-15], 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 -5.8 \cdot 10^{-15}:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -5.80000000000000037e-15Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 99.5%
+-commutative99.5%
Simplified99.5%
if -5.80000000000000037e-15 < a Initial program 99.5%
Taylor expanded in a around 0 98.9%
Final simplification99.1%
(FPCore (a b) :precision binary64 (if (<= b -1.05) 1.0 (if (<= b 1.4) (+ 0.5 (* a 0.25)) 0.0)))
double code(double a, double b) {
double tmp;
if (b <= -1.05) {
tmp = 1.0;
} else if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 0.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.05d0)) then
tmp = 1.0d0
else if (b <= 1.4d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.05) {
tmp = 1.0;
} else if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.05: tmp = 1.0 elif b <= 1.4: tmp = 0.5 + (a * 0.25) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.05) tmp = 1.0; elseif (b <= 1.4) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.05) tmp = 1.0; elseif (b <= 1.4) tmp = 0.5 + (a * 0.25); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.05], 1.0, If[LessEqual[b, 1.4], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.4:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.05000000000000004Initial program 100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/3100.0%
+-commutative100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
pow1/3100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
unpow-1100.0%
rem-exp-log100.0%
exp-diff100.0%
sub-neg100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
rec-exp100.0%
lft-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 18.8%
Applied egg-rr100.0%
if -1.05000000000000004 < b < 1.3999999999999999Initial program 100.0%
Taylor expanded in b around 0 98.9%
Taylor expanded in a around 0 69.7%
*-commutative69.7%
Simplified69.7%
if 1.3999999999999999 < b Initial program 98.5%
add-cbrt-cube98.5%
pow1/398.5%
pow398.5%
clear-num98.5%
inv-pow98.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
unpow1/398.5%
+-commutative98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef98.5%
pow1/398.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
expm1-def98.5%
expm1-log1p98.5%
unpow-198.5%
rem-exp-log98.5%
exp-diff100.0%
sub-neg100.0%
prod-exp98.5%
rem-exp-log98.5%
*-commutative98.5%
+-commutative98.5%
distribute-lft-in75.4%
rec-exp75.4%
lft-mult-inverse98.5%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 25.5%
Applied egg-rr100.0%
Final simplification82.8%
(FPCore (a b) :precision binary64 (if (<= b -1.1) 1.0 (if (<= b 1.75) 0.5 0.0)))
double code(double a, double b) {
double tmp;
if (b <= -1.1) {
tmp = 1.0;
} else if (b <= 1.75) {
tmp = 0.5;
} else {
tmp = 0.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.1d0)) then
tmp = 1.0d0
else if (b <= 1.75d0) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.1) {
tmp = 1.0;
} else if (b <= 1.75) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.1: tmp = 1.0 elif b <= 1.75: tmp = 0.5 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.1) tmp = 1.0; elseif (b <= 1.75) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.1) tmp = 1.0; elseif (b <= 1.75) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.1], 1.0, If[LessEqual[b, 1.75], 0.5, 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.75:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.1000000000000001Initial program 100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/3100.0%
+-commutative100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
pow1/3100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
unpow-1100.0%
rem-exp-log100.0%
exp-diff100.0%
sub-neg100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
rec-exp100.0%
lft-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 18.8%
Applied egg-rr100.0%
if -1.1000000000000001 < b < 1.75Initial program 100.0%
Taylor expanded in a around 0 69.8%
Taylor expanded in b around 0 68.7%
if 1.75 < b Initial program 98.5%
add-cbrt-cube98.5%
pow1/398.5%
pow398.5%
clear-num98.5%
inv-pow98.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
unpow1/398.5%
+-commutative98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef98.5%
pow1/398.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
expm1-def98.5%
expm1-log1p98.5%
unpow-198.5%
rem-exp-log98.5%
exp-diff100.0%
sub-neg100.0%
prod-exp98.5%
rem-exp-log98.5%
*-commutative98.5%
+-commutative98.5%
distribute-lft-in75.4%
rec-exp75.4%
lft-mult-inverse98.5%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 25.5%
Applied egg-rr100.0%
Final simplification82.3%
(FPCore (a b) :precision binary64 (if (<= b -3.4e-15) 0.16666666666666666 0.0))
double code(double a, double b) {
double tmp;
if (b <= -3.4e-15) {
tmp = 0.16666666666666666;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-3.4d-15)) then
tmp = 0.16666666666666666d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -3.4e-15) {
tmp = 0.16666666666666666;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -3.4e-15: tmp = 0.16666666666666666 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -3.4e-15) tmp = 0.16666666666666666; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -3.4e-15) tmp = 0.16666666666666666; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -3.4e-15], 0.16666666666666666, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.4 \cdot 10^{-15}:\\
\;\;\;\;0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -3.4e-15Initial program 100.0%
add-cbrt-cube99.9%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/399.9%
+-commutative99.9%
Simplified99.9%
expm1-log1p-u99.9%
expm1-udef100.0%
pow1/3100.0%
pow-pow100.0%
metadata-eval100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
unpow-1100.0%
rem-exp-log100.0%
exp-diff100.0%
sub-neg100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
rec-exp100.0%
lft-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 22.3%
Applied egg-rr16.6%
if -3.4e-15 < b Initial program 99.5%
add-cbrt-cube98.8%
pow1/399.5%
pow399.5%
clear-num99.5%
inv-pow99.5%
pow-pow99.5%
metadata-eval99.5%
Applied egg-rr99.5%
unpow1/398.8%
+-commutative98.8%
Simplified98.8%
expm1-log1p-u98.8%
expm1-udef99.4%
pow1/399.4%
pow-pow99.4%
metadata-eval99.4%
Applied egg-rr99.4%
expm1-def99.5%
expm1-log1p99.5%
unpow-199.5%
rem-exp-log99.5%
exp-diff100.0%
sub-neg100.0%
prod-exp99.5%
rem-exp-log99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in72.0%
rec-exp72.0%
lft-mult-inverse99.5%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.2%
Applied egg-rr53.2%
Final simplification46.2%
(FPCore (a b) :precision binary64 (if (<= b 2.05) 0.5 0.0))
double code(double a, double b) {
double tmp;
if (b <= 2.05) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.05d0) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.05) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.05: tmp = 0.5 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 2.05) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.05) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.05], 0.5, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 2.0499999999999998Initial program 100.0%
Taylor expanded in a around 0 77.1%
Taylor expanded in b around 0 56.7%
if 2.0499999999999998 < b Initial program 98.5%
add-cbrt-cube98.5%
pow1/398.5%
pow398.5%
clear-num98.5%
inv-pow98.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
unpow1/398.5%
+-commutative98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef98.5%
pow1/398.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
expm1-def98.5%
expm1-log1p98.5%
unpow-198.5%
rem-exp-log98.5%
exp-diff100.0%
sub-neg100.0%
prod-exp98.5%
rem-exp-log98.5%
*-commutative98.5%
+-commutative98.5%
distribute-lft-in75.4%
rec-exp75.4%
lft-mult-inverse98.5%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 25.5%
Applied egg-rr100.0%
Final simplification67.7%
(FPCore (a b) :precision binary64 0.0)
double code(double a, double b) {
return 0.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.0d0
end function
public static double code(double a, double b) {
return 0.0;
}
def code(a, b): return 0.0
function code(a, b) return 0.0 end
function tmp = code(a, b) tmp = 0.0; end
code[a_, b_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.6%
add-cbrt-cube99.0%
pow1/399.6%
pow399.6%
clear-num99.6%
inv-pow99.6%
pow-pow99.6%
metadata-eval99.6%
Applied egg-rr99.6%
unpow1/399.0%
+-commutative99.0%
Simplified99.0%
expm1-log1p-u99.0%
expm1-udef99.5%
pow1/399.5%
pow-pow99.5%
metadata-eval99.5%
Applied egg-rr99.5%
expm1-def99.6%
expm1-log1p99.6%
unpow-199.6%
rem-exp-log99.6%
exp-diff100.0%
sub-neg100.0%
prod-exp99.6%
rem-exp-log99.6%
*-commutative99.6%
+-commutative99.6%
distribute-lft-in77.3%
rec-exp77.3%
lft-mult-inverse99.6%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 65.8%
Applied egg-rr43.6%
Final simplification43.6%
(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 2024011
(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))))