
(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 12 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 (<= (exp a) 0.0) (* (exp a) 0.5) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) * 0.5;
} 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) * 0.5d0
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) * 0.5;
} 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) * 0.5 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) * 0.5); 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) * 0.5; 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] * 0.5), $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:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
Taylor expanded in b around 0
Simplified100.0%
Taylor expanded in a around 0
Simplified100.0%
div-invN/A
metadata-evalN/A
*-lowering-*.f64N/A
exp-lowering-exp.f64100.0
Applied egg-rr100.0%
if 0.0 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6498.9
Simplified98.9%
(FPCore (a b)
:precision binary64
(if (<= (/ (exp a) (+ (exp a) (exp b))) 0.49999961)
(/
1.0
(*
(* b b)
(*
b
(- 0.16666666666666666 (/ (+ (+ -0.5 (/ -1.0 b)) (/ -2.0 (* b b))) b)))))
(fma a 0.25 0.5)))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.49999961) {
tmp = 1.0 / ((b * b) * (b * (0.16666666666666666 - (((-0.5 + (-1.0 / b)) + (-2.0 / (b * b))) / b))));
} else {
tmp = fma(a, 0.25, 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.49999961) tmp = Float64(1.0 / Float64(Float64(b * b) * Float64(b * Float64(0.16666666666666666 - Float64(Float64(Float64(-0.5 + Float64(-1.0 / b)) + Float64(-2.0 / Float64(b * b))) / b))))); else tmp = fma(a, 0.25, 0.5); end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.49999961], N[(1.0 / N[(N[(b * b), $MachinePrecision] * N[(b * N[(0.16666666666666666 - N[(N[(N[(-0.5 + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision] + N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * 0.25 + 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.49999961:\\
\;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot \left(b \cdot \left(0.16666666666666666 - \frac{\left(-0.5 + \frac{-1}{b}\right) + \frac{-2}{b \cdot b}}{b}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.499999609999999983Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6465.1
Simplified65.1%
Taylor expanded in b around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6445.7
Simplified45.7%
Taylor expanded in b around -inf
mul-1-negN/A
unpow3N/A
unpow2N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
Simplified52.1%
if 0.499999609999999983 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 98.4%
Taylor expanded in b around 0
Simplified65.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6464.5
Simplified64.5%
(FPCore (a b) :precision binary64 (* (exp a) (/ 1.0 (+ (exp a) (exp b)))))
double code(double a, double b) {
return exp(a) * (1.0 / (exp(a) + exp(b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) * (1.0d0 / (exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.exp(a) * (1.0 / (Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.exp(a) * (1.0 / (math.exp(a) + math.exp(b)))
function code(a, b) return Float64(exp(a) * Float64(1.0 / Float64(exp(a) + exp(b)))) end
function tmp = code(a, b) tmp = exp(a) * (1.0 / (exp(a) + exp(b))); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] * N[(1.0 / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{a} \cdot \frac{1}{e^{a} + e^{b}}
\end{array}
Initial program 99.2%
div-invN/A
flip3-+N/A
clear-numN/A
*-commutativeN/A
*-lowering-*.f64N/A
Applied egg-rr99.2%
Final simplification99.2%
(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.2%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (fma b 0.5 1.0))))
(if (<= b 1.6e+77)
(* (exp a) 0.5)
(if (<= b 2e+153)
(/ (fma b (fma b 0.5 1.0) -2.0) (fma t_0 t_0 -4.0))
(/ 2.0 (* b b))))))
double code(double a, double b) {
double t_0 = b * fma(b, 0.5, 1.0);
double tmp;
if (b <= 1.6e+77) {
tmp = exp(a) * 0.5;
} else if (b <= 2e+153) {
tmp = fma(b, fma(b, 0.5, 1.0), -2.0) / fma(t_0, t_0, -4.0);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
function code(a, b) t_0 = Float64(b * fma(b, 0.5, 1.0)) tmp = 0.0 if (b <= 1.6e+77) tmp = Float64(exp(a) * 0.5); elseif (b <= 2e+153) tmp = Float64(fma(b, fma(b, 0.5, 1.0), -2.0) / fma(t_0, t_0, -4.0)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.6e+77], N[(N[Exp[a], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[b, 2e+153], N[(N[(b * N[(b * 0.5 + 1.0), $MachinePrecision] + -2.0), $MachinePrecision] / N[(t$95$0 * t$95$0 + -4.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \mathsf{fma}\left(b, 0.5, 1\right)\\
\mathbf{if}\;b \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.5, 1\right), -2\right)}{\mathsf{fma}\left(t\_0, t\_0, -4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.6000000000000001e77Initial program 98.9%
Taylor expanded in b around 0
Simplified72.4%
Taylor expanded in a around 0
Simplified71.4%
div-invN/A
metadata-evalN/A
*-lowering-*.f64N/A
exp-lowering-exp.f6471.4
Applied egg-rr71.4%
if 1.6000000000000001e77 < b < 2e153Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f646.5
Simplified6.5%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
metadata-eval100.0
Applied egg-rr100.0%
if 2e153 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (fma b (fma b 0.16666666666666666 0.5) 1.0)))
(if (<= b 26000000000000.0)
(fma a 0.25 0.5)
(if (<= b 1.65e+38)
(* -0.020833333333333332 (* a (* a a)))
(if (<= b 5e+102)
(/ (fma b t_0 -2.0) (fma t_0 (* (* b b) t_0) -4.0))
(/ 6.0 (* b (* b b))))))))
double code(double a, double b) {
double t_0 = fma(b, fma(b, 0.16666666666666666, 0.5), 1.0);
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else if (b <= 1.65e+38) {
tmp = -0.020833333333333332 * (a * (a * a));
} else if (b <= 5e+102) {
tmp = fma(b, t_0, -2.0) / fma(t_0, ((b * b) * t_0), -4.0);
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
function code(a, b) t_0 = fma(b, fma(b, 0.16666666666666666, 0.5), 1.0) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); elseif (b <= 1.65e+38) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); elseif (b <= 5e+102) tmp = Float64(fma(b, t_0, -2.0) / fma(t_0, Float64(Float64(b * b) * t_0), -4.0)); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], If[LessEqual[b, 1.65e+38], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+102], N[(N[(b * t$95$0 + -2.0), $MachinePrecision] / N[(t$95$0 * N[(N[(b * b), $MachinePrecision] * t$95$0), $MachinePrecision] + -4.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right)\\
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{+38}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, t\_0, -2\right)}{\mathsf{fma}\left(t\_0, \left(b \cdot b\right) \cdot t\_0, -4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b < 1.65e38Initial program 100.0%
Taylor expanded in b around 0
Simplified32.2%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.7
Simplified2.7%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6470.5
Simplified70.5%
if 1.65e38 < b < 5e102Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f647.5
Simplified7.5%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
sub-negN/A
Applied egg-rr85.3%
if 5e102 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
Final simplification61.4%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (fma b 0.16666666666666666 0.5))))
(if (<= b 26000000000000.0)
(fma a 0.25 0.5)
(if (<= b 1.65e+38)
(* -0.020833333333333332 (* a (* a a)))
(if (<= b 2e+153)
(/
1.0
(fma
b
(/ (fma t_0 t_0 -1.0) (fma b (fma b 0.16666666666666666 0.5) -1.0))
2.0))
(/ 2.0 (* b b)))))))
double code(double a, double b) {
double t_0 = b * fma(b, 0.16666666666666666, 0.5);
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else if (b <= 1.65e+38) {
tmp = -0.020833333333333332 * (a * (a * a));
} else if (b <= 2e+153) {
tmp = 1.0 / fma(b, (fma(t_0, t_0, -1.0) / fma(b, fma(b, 0.16666666666666666, 0.5), -1.0)), 2.0);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
function code(a, b) t_0 = Float64(b * fma(b, 0.16666666666666666, 0.5)) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); elseif (b <= 1.65e+38) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); elseif (b <= 2e+153) tmp = Float64(1.0 / fma(b, Float64(fma(t_0, t_0, -1.0) / fma(b, fma(b, 0.16666666666666666, 0.5), -1.0)), 2.0)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], If[LessEqual[b, 1.65e+38], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e+153], N[(1.0 / N[(b * N[(N[(t$95$0 * t$95$0 + -1.0), $MachinePrecision] / N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right)\\
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{+38}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+153}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \frac{\mathsf{fma}\left(t\_0, t\_0, -1\right)}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), -1\right)}, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b < 1.65e38Initial program 100.0%
Taylor expanded in b around 0
Simplified32.2%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.7
Simplified2.7%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6470.5
Simplified70.5%
if 1.65e38 < b < 2e153Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6462.4
Simplified62.4%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
sub-negN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6485.2
Applied egg-rr85.2%
if 2e153 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (fma b 0.5 1.0))))
(if (<= b 26000000000000.0)
(fma a 0.25 0.5)
(if (<= b 1.65e+38)
(* -0.020833333333333332 (* a (* a a)))
(if (<= b 2e+153)
(/ (fma b (fma b 0.5 1.0) -2.0) (fma t_0 t_0 -4.0))
(/ 2.0 (* b b)))))))
double code(double a, double b) {
double t_0 = b * fma(b, 0.5, 1.0);
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else if (b <= 1.65e+38) {
tmp = -0.020833333333333332 * (a * (a * a));
} else if (b <= 2e+153) {
tmp = fma(b, fma(b, 0.5, 1.0), -2.0) / fma(t_0, t_0, -4.0);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
function code(a, b) t_0 = Float64(b * fma(b, 0.5, 1.0)) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); elseif (b <= 1.65e+38) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); elseif (b <= 2e+153) tmp = Float64(fma(b, fma(b, 0.5, 1.0), -2.0) / fma(t_0, t_0, -4.0)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], If[LessEqual[b, 1.65e+38], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e+153], N[(N[(b * N[(b * 0.5 + 1.0), $MachinePrecision] + -2.0), $MachinePrecision] / N[(t$95$0 * t$95$0 + -4.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \mathsf{fma}\left(b, 0.5, 1\right)\\
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{+38}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.5, 1\right), -2\right)}{\mathsf{fma}\left(t\_0, t\_0, -4\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b < 1.65e38Initial program 100.0%
Taylor expanded in b around 0
Simplified32.2%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.7
Simplified2.7%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6470.5
Simplified70.5%
if 1.65e38 < b < 2e153Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f646.1
Simplified6.1%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
metadata-eval85.0
Applied egg-rr85.0%
if 2e153 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
(FPCore (a b)
:precision binary64
(if (<= b 26000000000000.0)
(fma a 0.25 0.5)
(if (<= b 2.55e+101)
(* -0.020833333333333332 (* a (* a a)))
(/ 6.0 (* b (* b b))))))
double code(double a, double b) {
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else if (b <= 2.55e+101) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); elseif (b <= 2.55e+101) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
code[a_, b_] := If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], If[LessEqual[b, 2.55e+101], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{elif}\;b \leq 2.55 \cdot 10^{+101}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b < 2.54999999999999997e101Initial program 100.0%
Taylor expanded in b around 0
Simplified49.3%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.5
Simplified2.5%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6448.7
Simplified48.7%
if 2.54999999999999997e101 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6496.8
Simplified96.8%
Taylor expanded in b around inf
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6496.8
Simplified96.8%
(FPCore (a b)
:precision binary64
(if (<= b 26000000000000.0)
(fma a 0.25 0.5)
(if (<= b 1.4e+154)
(* -0.020833333333333332 (* a (* a a)))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else if (b <= 1.4e+154) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); elseif (b <= 1.4e+154) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
code[a_, b_] := If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], If[LessEqual[b, 1.4e+154], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b < 1.4e154Initial program 100.0%
Taylor expanded in b around 0
Simplified35.4%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.7
Simplified2.7%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6453.6
Simplified53.6%
if 1.4e154 < b Initial program 100.0%
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
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64100.0
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= b 26000000000000.0) (fma a 0.25 0.5) (* -0.020833333333333332 (* a (* a a)))))
double code(double a, double b) {
double tmp;
if (b <= 26000000000000.0) {
tmp = fma(a, 0.25, 0.5);
} else {
tmp = -0.020833333333333332 * (a * (a * a));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 26000000000000.0) tmp = fma(a, 0.25, 0.5); else tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); end return tmp end
code[a_, b_] := If[LessEqual[b, 26000000000000.0], N[(a * 0.25 + 0.5), $MachinePrecision], N[(-0.020833333333333332 * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 26000000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;-0.020833333333333332 \cdot \left(a \cdot \left(a \cdot a\right)\right)\\
\end{array}
\end{array}
if b < 2.6e13Initial program 98.9%
Taylor expanded in b around 0
Simplified73.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6447.9
Simplified47.9%
if 2.6e13 < b Initial program 100.0%
Taylor expanded in b around 0
Simplified37.5%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f642.6
Simplified2.6%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6447.5
Simplified47.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 99.2%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6482.2
Simplified82.2%
Taylor expanded in b around 0
Simplified34.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 2024196
(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))))