
(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 (if (<= a -400000000000.0) (/ (exp a) 2.0) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -400000000000.0) {
tmp = exp(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 (a <= (-400000000000.0d0)) then
tmp = exp(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 (a <= -400000000000.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -400000000000.0: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -400000000000.0) tmp = Float64(exp(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 (a <= -400000000000.0) tmp = exp(a) / 2.0; else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -400000000000.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -400000000000:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -4e11Initial program 100.0%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified100.0%
if -4e11 < a Initial program 97.8%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6499.2%
Simplified99.2%
Final simplification99.4%
(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 98.4%
(FPCore (a b) :precision binary64 (if (<= b 1.9e+96) (/ (exp a) 2.0) (/ -4.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 1.9e+96) {
tmp = exp(a) / 2.0;
} else {
tmp = -4.0 / (b * (b * b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.9d+96) then
tmp = exp(a) / 2.0d0
else
tmp = (-4.0d0) / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.9e+96) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = -4.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.9e+96: tmp = math.exp(a) / 2.0 else: tmp = -4.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.9e+96) tmp = Float64(exp(a) / 2.0); else tmp = Float64(-4.0 / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.9e+96) tmp = exp(a) / 2.0; else tmp = -4.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.9e+96], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(-4.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+96}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-4}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 1.9000000000000001e96Initial program 99.0%
Taylor expanded in b around 0
Simplified71.3%
Taylor expanded in a around 0
Simplified70.6%
if 1.9000000000000001e96 < b Initial program 96.3%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6474.3%
Simplified74.3%
Taylor expanded in b around inf
/-lowering-/.f64N/A
sub-negN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
metadata-evalN/A
unpow2N/A
*-lowering-*.f6474.3%
Simplified74.3%
Taylor expanded in b around 0
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6496.7%
Simplified96.7%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (+ 1.0 (* b 0.5)))))
(if (<= b -0.05)
(/ 1.0 (+ 2.0 (/ b (+ 1.0 (* b (+ -0.5 (* b 0.25)))))))
(if (<= b 1.6e+77)
(/ (+ 4.0 (* t_0 (+ t_0 -2.0))) (+ 8.0 (* t_0 (* t_0 t_0))))
(/ -4.0 (* b (* b b)))))))
double code(double a, double b) {
double t_0 = b * (1.0 + (b * 0.5));
double tmp;
if (b <= -0.05) {
tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25))))));
} else if (b <= 1.6e+77) {
tmp = (4.0 + (t_0 * (t_0 + -2.0))) / (8.0 + (t_0 * (t_0 * t_0)));
} else {
tmp = -4.0 / (b * (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 = b * (1.0d0 + (b * 0.5d0))
if (b <= (-0.05d0)) then
tmp = 1.0d0 / (2.0d0 + (b / (1.0d0 + (b * ((-0.5d0) + (b * 0.25d0))))))
else if (b <= 1.6d+77) then
tmp = (4.0d0 + (t_0 * (t_0 + (-2.0d0)))) / (8.0d0 + (t_0 * (t_0 * t_0)))
else
tmp = (-4.0d0) / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b * (1.0 + (b * 0.5));
double tmp;
if (b <= -0.05) {
tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25))))));
} else if (b <= 1.6e+77) {
tmp = (4.0 + (t_0 * (t_0 + -2.0))) / (8.0 + (t_0 * (t_0 * t_0)));
} else {
tmp = -4.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): t_0 = b * (1.0 + (b * 0.5)) tmp = 0 if b <= -0.05: tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25)))))) elif b <= 1.6e+77: tmp = (4.0 + (t_0 * (t_0 + -2.0))) / (8.0 + (t_0 * (t_0 * t_0))) else: tmp = -4.0 / (b * (b * b)) return tmp
function code(a, b) t_0 = Float64(b * Float64(1.0 + Float64(b * 0.5))) tmp = 0.0 if (b <= -0.05) tmp = Float64(1.0 / Float64(2.0 + Float64(b / Float64(1.0 + Float64(b * Float64(-0.5 + Float64(b * 0.25))))))); elseif (b <= 1.6e+77) tmp = Float64(Float64(4.0 + Float64(t_0 * Float64(t_0 + -2.0))) / Float64(8.0 + Float64(t_0 * Float64(t_0 * t_0)))); else tmp = Float64(-4.0 / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) t_0 = b * (1.0 + (b * 0.5)); tmp = 0.0; if (b <= -0.05) tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25)))))); elseif (b <= 1.6e+77) tmp = (4.0 + (t_0 * (t_0 + -2.0))) / (8.0 + (t_0 * (t_0 * t_0))); else tmp = -4.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -0.05], N[(1.0 / N[(2.0 + N[(b / N[(1.0 + N[(b * N[(-0.5 + N[(b * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.6e+77], N[(N[(4.0 + N[(t$95$0 * N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(8.0 + N[(t$95$0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(1 + b \cdot 0.5\right)\\
\mathbf{if}\;b \leq -0.05:\\
\;\;\;\;\frac{1}{2 + \frac{b}{1 + b \cdot \left(-0.5 + b \cdot 0.25\right)}}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;\frac{4 + t\_0 \cdot \left(t\_0 + -2\right)}{8 + t\_0 \cdot \left(t\_0 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-4}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < -0.050000000000000003Initial program 96.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f645.4%
Simplified5.4%
flip-+N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f645.4%
Applied egg-rr5.4%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6419.2%
Simplified19.2%
if -0.050000000000000003 < b < 1.6000000000000001e77Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6468.0%
Simplified68.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.7%
Simplified55.7%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
Applied egg-rr61.0%
if 1.6000000000000001e77 < b Initial program 96.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6471.8%
Simplified71.8%
Taylor expanded in b around inf
/-lowering-/.f64N/A
sub-negN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
metadata-evalN/A
unpow2N/A
*-lowering-*.f6471.8%
Simplified71.8%
Taylor expanded in b around 0
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6493.5%
Simplified93.5%
Final simplification59.0%
(FPCore (a b) :precision binary64 (if (<= b -1.25) (/ 1.0 (+ 2.0 (/ b (+ 1.0 (* b (+ -0.5 (* b 0.25))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= -1.25) {
tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-1.25d0)) then
tmp = 1.0d0 / (2.0d0 + (b / (1.0d0 + (b * ((-0.5d0) + (b * 0.25d0))))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.25) {
tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.25: tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25)))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.25) tmp = Float64(1.0 / Float64(2.0 + Float64(b / Float64(1.0 + Float64(b * Float64(-0.5 + Float64(b * 0.25))))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.25) tmp = 1.0 / (2.0 + (b / (1.0 + (b * (-0.5 + (b * 0.25)))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.25], N[(1.0 / N[(2.0 + N[(b / N[(1.0 + N[(b * N[(-0.5 + N[(b * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25:\\
\;\;\;\;\frac{1}{2 + \frac{b}{1 + b \cdot \left(-0.5 + b \cdot 0.25\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < -1.25Initial program 96.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f644.7%
Simplified4.7%
flip-+N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f644.7%
Applied egg-rr4.7%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6418.8%
Simplified18.8%
if -1.25 < b Initial program 99.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6477.1%
Simplified77.1%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6466.3%
Simplified66.3%
Final simplification56.1%
(FPCore (a b) :precision binary64 (if (<= b -2.0) 0.5 (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
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 = 0.5d0
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 0.5 else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 0.5; else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], 0.5, N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < -2Initial program 96.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
Simplified18.8%
if -2 < b Initial program 99.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6477.1%
Simplified77.1%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6466.3%
Simplified66.3%
(FPCore (a b) :precision binary64 (if (<= b 2450.0) 0.5 (/ -4.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 2450.0) {
tmp = 0.5;
} else {
tmp = -4.0 / (b * (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 <= 2450.0d0) then
tmp = 0.5d0
else
tmp = (-4.0d0) / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2450.0) {
tmp = 0.5;
} else {
tmp = -4.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2450.0: tmp = 0.5 else: tmp = -4.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 2450.0) tmp = 0.5; else tmp = Float64(-4.0 / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2450.0) tmp = 0.5; else tmp = -4.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2450.0], 0.5, N[(-4.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2450:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-4}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 2450Initial program 98.9%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6474.7%
Simplified74.7%
Taylor expanded in b around 0
Simplified48.9%
if 2450 < b Initial program 97.3%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.3%
Simplified55.3%
Taylor expanded in b around inf
/-lowering-/.f64N/A
sub-negN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
metadata-evalN/A
unpow2N/A
*-lowering-*.f6455.3%
Simplified55.3%
Taylor expanded in b around 0
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6471.9%
Simplified71.9%
(FPCore (a b) :precision binary64 (if (<= b 2.0) 0.5 (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.0d0) then
tmp = 0.5d0
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 0.5 else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = 0.5; else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.0) tmp = 0.5; else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], 0.5, N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2Initial program 98.9%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6474.7%
Simplified74.7%
Taylor expanded in b around 0
Simplified48.9%
if 2 < b Initial program 97.3%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f64100.0%
Simplified100.0%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.3%
Simplified55.3%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6455.3%
Simplified55.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 98.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6482.0%
Simplified82.0%
Taylor expanded in b around 0
Simplified35.7%
(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 2024155
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))