
(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 (- a (log (+ (exp a) (exp b))))))
double code(double a, double b) {
return exp((a - log((exp(a) + exp(b)))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp((a - log((exp(a) + exp(b)))))
end function
public static double code(double a, double b) {
return Math.exp((a - Math.log((Math.exp(a) + Math.exp(b)))));
}
def code(a, b): return math.exp((a - math.log((math.exp(a) + math.exp(b)))))
function code(a, b) return exp(Float64(a - log(Float64(exp(a) + exp(b))))) end
function tmp = code(a, b) tmp = exp((a - log((exp(a) + exp(b))))); end
code[a_, b_] := N[Exp[N[(a - N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{a - \log \left(e^{a} + e^{b}\right)}
\end{array}
Initial program 99.6%
add-exp-log99.6%
div-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ (exp a) (+ (exp a) (+ b 1.0))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
tmp = exp(a) / (exp(a) + (b + 1.0));
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 1.0d0) then
tmp = exp(a) / (exp(a) + (b + 1.0d0))
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1.0) {
tmp = Math.exp(a) / (Math.exp(a) + (b + 1.0));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 1.0: tmp = math.exp(a) / (math.exp(a) + (b + 1.0)) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 1.0) tmp = Float64(exp(a) / Float64(exp(a) + Float64(b + 1.0))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 1.0) tmp = exp(a) / (exp(a) + (b + 1.0)); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1.0], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{e^{a} + \left(b + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 100.0%
Taylor expanded in b around 0 67.9%
associate-+r+67.9%
+-commutative67.9%
associate-+l+67.9%
Simplified67.9%
if 1 < (exp.f64 a) Initial program 88.7%
Taylor expanded in a around 0 86.0%
Final simplification68.6%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
tmp = exp(a) / (exp(a) + 1.0);
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 1.0d0) then
tmp = exp(a) / (exp(a) + 1.0d0)
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1.0) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 1.0: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 1.0) tmp = Float64(exp(a) / Float64(exp(a) + 1.0)); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 1.0) tmp = exp(a) / (exp(a) + 1.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1.0], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 100.0%
Taylor expanded in b around 0 69.3%
if 1 < (exp.f64 a) Initial program 88.7%
Taylor expanded in a around 0 86.0%
Final simplification69.9%
(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}
Initial program 99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (* (exp a) (/ 1.0 (+ a (+ b 2.0)))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
tmp = exp(a) * (1.0 / (a + (b + 2.0)));
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 1.0d0) then
tmp = exp(a) * (1.0d0 / (a + (b + 2.0d0)))
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1.0) {
tmp = Math.exp(a) * (1.0 / (a + (b + 2.0)));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 1.0: tmp = math.exp(a) * (1.0 / (a + (b + 2.0))) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 1.0) tmp = Float64(exp(a) * Float64(1.0 / Float64(a + Float64(b + 2.0)))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 1.0) tmp = exp(a) * (1.0 / (a + (b + 2.0))); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1.0], N[(N[Exp[a], $MachinePrecision] * N[(1.0 / N[(a + N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;e^{a} \cdot \frac{1}{a + \left(b + 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 100.0%
Taylor expanded in b around 0 67.9%
associate-+r+67.9%
+-commutative67.9%
associate-+l+67.9%
Simplified67.9%
Taylor expanded in a around 0 67.8%
associate-+r+67.8%
Simplified67.8%
clear-num67.8%
associate-/r/67.8%
+-commutative67.8%
associate-+l+67.8%
Applied egg-rr67.8%
if 1 < (exp.f64 a) Initial program 88.7%
Taylor expanded in a around 0 86.0%
Final simplification68.4%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ (exp a) (+ b (+ a 2.0))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
tmp = exp(a) / (b + (a + 2.0));
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 1.0d0) then
tmp = exp(a) / (b + (a + 2.0d0))
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1.0) {
tmp = Math.exp(a) / (b + (a + 2.0));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 1.0: tmp = math.exp(a) / (b + (a + 2.0)) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 1.0) tmp = Float64(exp(a) / Float64(b + Float64(a + 2.0))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 1.0) tmp = exp(a) / (b + (a + 2.0)); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1.0], N[(N[Exp[a], $MachinePrecision] / N[(b + N[(a + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{b + \left(a + 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 100.0%
Taylor expanded in b around 0 67.9%
associate-+r+67.9%
+-commutative67.9%
associate-+l+67.9%
Simplified67.9%
Taylor expanded in a around 0 67.8%
associate-+r+67.8%
Simplified67.8%
if 1 < (exp.f64 a) Initial program 88.7%
Taylor expanded in a around 0 86.0%
Final simplification68.4%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a);
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 0.0d0) then
tmp = exp(a)
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
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);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = exp(a); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0 98.6%
Final simplification99.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 1.0) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 1.0) {
tmp = exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (exp(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 (exp(a) <= 1.0d0) then
tmp = exp(a) / (a + 2.0d0)
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 1.0) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 1.0: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 1.0) tmp = Float64(exp(a) / Float64(a + 2.0)); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 1.0) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1.0], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 1Initial program 100.0%
Taylor expanded in b around 0 67.9%
associate-+r+67.9%
+-commutative67.9%
associate-+l+67.9%
Simplified67.9%
Taylor expanded in a around 0 67.8%
associate-+r+67.8%
Simplified67.8%
Taylor expanded in b around 0 69.2%
if 1 < (exp.f64 a) Initial program 88.7%
Taylor expanded in a around 0 86.0%
Final simplification69.8%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (exp a) (/ 1.0 (+ 2.0 (+ b (* 0.5 (* b b)))))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a);
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * 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)
else
tmp = 1.0d0 / (2.0d0 + (b + (0.5d0 * (b * 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);
} else {
tmp = 1.0 / (2.0 + (b + (0.5 * (b * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) else: tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = exp(a); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(0.5 * Float64(b * b))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a); else tmp = 1.0 / (2.0 + (b + (0.5 * (b * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[Exp[a], $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0 100.0%
log1p-def100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if 0.0 < (exp.f64 a) Initial program 99.4%
Taylor expanded in a around 0 98.6%
Taylor expanded in b around 0 68.5%
unpow268.5%
Simplified68.5%
Final simplification77.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* 0.5 (* b b))))
(if (<= b 390.0)
(+ 0.5 (* a 0.25))
(if (<= b 4.7e+100)
(* (* a (* a a)) -0.020833333333333332)
(if (<= b 1.35e+154) (/ (- t_0 b) (* b t_0)) (/ -2.0 (* b b)))))))
double code(double a, double b) {
double t_0 = 0.5 * (b * b);
double tmp;
if (b <= 390.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 4.7e+100) {
tmp = (a * (a * a)) * -0.020833333333333332;
} else if (b <= 1.35e+154) {
tmp = (t_0 - b) / (b * t_0);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (b * b)
if (b <= 390.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 4.7d+100) then
tmp = (a * (a * a)) * (-0.020833333333333332d0)
else if (b <= 1.35d+154) then
tmp = (t_0 - b) / (b * t_0)
else
tmp = (-2.0d0) / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 0.5 * (b * b);
double tmp;
if (b <= 390.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 4.7e+100) {
tmp = (a * (a * a)) * -0.020833333333333332;
} else if (b <= 1.35e+154) {
tmp = (t_0 - b) / (b * t_0);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): t_0 = 0.5 * (b * b) tmp = 0 if b <= 390.0: tmp = 0.5 + (a * 0.25) elif b <= 4.7e+100: tmp = (a * (a * a)) * -0.020833333333333332 elif b <= 1.35e+154: tmp = (t_0 - b) / (b * t_0) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) t_0 = Float64(0.5 * Float64(b * b)) tmp = 0.0 if (b <= 390.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 4.7e+100) tmp = Float64(Float64(a * Float64(a * a)) * -0.020833333333333332); elseif (b <= 1.35e+154) tmp = Float64(Float64(t_0 - b) / Float64(b * t_0)); else tmp = Float64(-2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) t_0 = 0.5 * (b * b); tmp = 0.0; if (b <= 390.0) tmp = 0.5 + (a * 0.25); elseif (b <= 4.7e+100) tmp = (a * (a * a)) * -0.020833333333333332; elseif (b <= 1.35e+154) tmp = (t_0 - b) / (b * t_0); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 390.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.7e+100], N[(N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] * -0.020833333333333332), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(N[(t$95$0 - b), $MachinePrecision] / N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;b \leq 390:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 4.7 \cdot 10^{+100}:\\
\;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{t_0 - b}{b \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 390Initial program 100.0%
Taylor expanded in b around 0 81.4%
Taylor expanded in a around 0 57.5%
*-commutative57.5%
Simplified57.5%
if 390 < b < 4.7e100Initial program 100.0%
Taylor expanded in b around 0 51.6%
Taylor expanded in a around 0 2.4%
Taylor expanded in a around inf 26.9%
*-commutative26.9%
Simplified26.9%
unpow326.9%
Applied egg-rr26.9%
if 4.7e100 < b < 1.35000000000000003e154Initial program 92.3%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 4.3%
+-commutative4.3%
Simplified4.3%
Taylor expanded in b around inf 4.3%
associate-*r/4.3%
metadata-eval4.3%
unpow24.3%
Simplified4.3%
clear-num4.3%
frac-sub92.6%
*-un-lft-identity92.6%
div-inv92.6%
metadata-eval92.6%
*-commutative92.6%
*-un-lft-identity92.6%
div-inv92.6%
metadata-eval92.6%
Applied egg-rr92.6%
if 1.35000000000000003e154 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 8.1%
+-commutative8.1%
Simplified8.1%
Taylor expanded in b around inf 8.1%
associate-*r/8.1%
metadata-eval8.1%
unpow28.1%
Simplified8.1%
Taylor expanded in b around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification64.0%
(FPCore (a b)
:precision binary64
(if (<= b 390.0)
(+ 0.5 (* a 0.25))
(if (<= b 1.8e+152)
(* (* a (* a a)) -0.020833333333333332)
(/ -2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 390.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1.8e+152) {
tmp = (a * (a * a)) * -0.020833333333333332;
} 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 <= 390.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 1.8d+152) then
tmp = (a * (a * a)) * (-0.020833333333333332d0)
else
tmp = (-2.0d0) / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 390.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 1.8e+152) {
tmp = (a * (a * a)) * -0.020833333333333332;
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 390.0: tmp = 0.5 + (a * 0.25) elif b <= 1.8e+152: tmp = (a * (a * a)) * -0.020833333333333332 else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 390.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 1.8e+152) tmp = Float64(Float64(a * Float64(a * a)) * -0.020833333333333332); else tmp = Float64(-2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 390.0) tmp = 0.5 + (a * 0.25); elseif (b <= 1.8e+152) tmp = (a * (a * a)) * -0.020833333333333332; else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 390.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+152], N[(N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] * -0.020833333333333332), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 390:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+152}:\\
\;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 390Initial program 100.0%
Taylor expanded in b around 0 81.4%
Taylor expanded in a around 0 57.5%
*-commutative57.5%
Simplified57.5%
if 390 < b < 1.7999999999999999e152Initial program 96.8%
Taylor expanded in b around 0 43.7%
Taylor expanded in a around 0 2.5%
Taylor expanded in a around inf 27.9%
*-commutative27.9%
Simplified27.9%
unpow327.9%
Applied egg-rr27.9%
if 1.7999999999999999e152 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 7.9%
+-commutative7.9%
Simplified7.9%
Taylor expanded in b around inf 7.9%
associate-*r/7.9%
metadata-eval7.9%
unpow27.9%
Simplified7.9%
Taylor expanded in b around 0 96.2%
unpow296.2%
Simplified96.2%
Final simplification60.7%
(FPCore (a b) :precision binary64 (if (<= b 600.0) (+ 0.5 (* a 0.25)) (/ -2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 600.0) {
tmp = 0.5 + (a * 0.25);
} 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 <= 600.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = (-2.0d0) / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 600.0) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = -2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 600.0: tmp = 0.5 + (a * 0.25) else: tmp = -2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 600.0) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(-2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 600.0) tmp = 0.5 + (a * 0.25); else tmp = -2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 600.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 600:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{b \cdot b}\\
\end{array}
\end{array}
if b < 600Initial program 100.0%
Taylor expanded in b around 0 81.4%
Taylor expanded in a around 0 57.5%
*-commutative57.5%
Simplified57.5%
if 600 < b Initial program 98.7%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 6.3%
+-commutative6.3%
Simplified6.3%
Taylor expanded in b around inf 6.3%
associate-*r/6.3%
metadata-eval6.3%
unpow26.3%
Simplified6.3%
Taylor expanded in b around 0 59.0%
unpow259.0%
Simplified59.0%
Final simplification57.9%
(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%
Taylor expanded in b around 0 68.0%
Taylor expanded in a around 0 41.3%
*-commutative41.3%
Simplified41.3%
Final simplification41.3%
(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%
Taylor expanded in a around 0 82.7%
Taylor expanded in b around 0 40.9%
Final simplification40.9%
(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 2023222
(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))))