
(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 15 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.998) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.998) {
tmp = 1.0 / (1.0 + 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.998d0) then
tmp = 1.0d0 / (1.0d0 + 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.998) {
tmp = 1.0 / (1.0 + 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.998: tmp = 1.0 / (1.0 + 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.998) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-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.998) tmp = 1.0 / (1.0 + 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.998], N[(1.0 / N[(1.0 + N[Exp[(-a)], $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 0.998:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.998Initial program 96.8%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6496.9
Applied rewrites96.9%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6498.4
Applied rewrites98.4%
if 0.998 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6499.4
Applied rewrites99.4%
Final simplification99.2%
(FPCore (a b) :precision binary64 (exp (fma (log (+ (exp a) (exp b))) -1.0 a)))
double code(double a, double b) {
return exp(fma(log((exp(a) + exp(b))), -1.0, a));
}
function code(a, b) return exp(fma(log(Float64(exp(a) + exp(b))), -1.0, a)) end
code[a_, b_] := N[Exp[N[(N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -1.0 + a), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}
\end{array}
Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.8
Applied rewrites98.8%
(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.0%
(FPCore (a b) :precision binary64 (if (<= a -4.2e+24) (* (exp a) 0.5) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -4.2e+24) {
tmp = exp(a) * 0.5;
} 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 <= (-4.2d+24)) then
tmp = exp(a) * 0.5d0
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 <= -4.2e+24) {
tmp = Math.exp(a) * 0.5;
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -4.2e+24: tmp = math.exp(a) * 0.5 else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -4.2e+24) tmp = Float64(exp(a) * 0.5); 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 <= -4.2e+24) tmp = exp(a) * 0.5; else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -4.2e+24], N[(N[Exp[a], $MachinePrecision] * 0.5), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.2 \cdot 10^{+24}:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -4.2000000000000003e24Initial program 98.3%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in a around 0
Applied rewrites100.0%
lift-exp.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64100.0
Applied rewrites100.0%
if -4.2000000000000003e24 < a Initial program 97.9%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.7
Applied rewrites98.7%
Final simplification99.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (fma b (* b 0.5) b)))
(if (<= b -7400.0)
(+ (exp b) 1.0)
(if (<= b 1.6e+77) (* (exp a) 0.5) (/ -2.0 (fma t_0 t_0 -4.0))))))
double code(double a, double b) {
double t_0 = fma(b, (b * 0.5), b);
double tmp;
if (b <= -7400.0) {
tmp = exp(b) + 1.0;
} else if (b <= 1.6e+77) {
tmp = exp(a) * 0.5;
} else {
tmp = -2.0 / fma(t_0, t_0, -4.0);
}
return tmp;
}
function code(a, b) t_0 = fma(b, Float64(b * 0.5), b) tmp = 0.0 if (b <= -7400.0) tmp = Float64(exp(b) + 1.0); elseif (b <= 1.6e+77) tmp = Float64(exp(a) * 0.5); else tmp = Float64(-2.0 / fma(t_0, t_0, -4.0)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5), $MachinePrecision] + b), $MachinePrecision]}, If[LessEqual[b, -7400.0], N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[b, 1.6e+77], N[(N[Exp[a], $MachinePrecision] * 0.5), $MachinePrecision], N[(-2.0 / N[(t$95$0 * t$95$0 + -4.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, b \cdot 0.5, b\right)\\
\mathbf{if}\;b \leq -7400:\\
\;\;\;\;e^{b} + 1\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;e^{a} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{\mathsf{fma}\left(t\_0, t\_0, -4\right)}\\
\end{array}
\end{array}
if b < -7400Initial program 98.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
if -7400 < b < 1.6000000000000001e77Initial program 97.9%
Taylor expanded in b around 0
Applied rewrites90.9%
Taylor expanded in a around 0
Applied rewrites89.7%
lift-exp.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6489.7
Applied rewrites89.7%
if 1.6000000000000001e77 < b Initial program 98.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6471.2
Applied rewrites71.2%
lift-fma.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval31.0
Applied rewrites31.0%
Taylor expanded in b around 0
Applied rewrites100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (fma b (* b 0.5) b)))
(if (<= b -7400.0)
(+ (exp b) 1.0)
(if (<= b 1.6e+77)
(/ 1.0 (fma a (fma a (fma a -0.16666666666666666 0.5) -1.0) 2.0))
(/ -2.0 (fma t_0 t_0 -4.0))))))
double code(double a, double b) {
double t_0 = fma(b, (b * 0.5), b);
double tmp;
if (b <= -7400.0) {
tmp = exp(b) + 1.0;
} else if (b <= 1.6e+77) {
tmp = 1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0);
} else {
tmp = -2.0 / fma(t_0, t_0, -4.0);
}
return tmp;
}
function code(a, b) t_0 = fma(b, Float64(b * 0.5), b) tmp = 0.0 if (b <= -7400.0) tmp = Float64(exp(b) + 1.0); elseif (b <= 1.6e+77) tmp = Float64(1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0)); else tmp = Float64(-2.0 / fma(t_0, t_0, -4.0)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5), $MachinePrecision] + b), $MachinePrecision]}, If[LessEqual[b, -7400.0], N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[b, 1.6e+77], N[(1.0 / N[(a * N[(a * N[(a * -0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(t$95$0 * t$95$0 + -4.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, b \cdot 0.5, b\right)\\
\mathbf{if}\;b \leq -7400:\\
\;\;\;\;e^{b} + 1\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, -0.16666666666666666, 0.5\right), -1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{\mathsf{fma}\left(t\_0, t\_0, -4\right)}\\
\end{array}
\end{array}
if b < -7400Initial program 98.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
if -7400 < b < 1.6000000000000001e77Initial program 97.9%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.7
Applied rewrites98.7%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6491.6
Applied rewrites91.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6481.5
Applied rewrites81.5%
if 1.6000000000000001e77 < b Initial program 98.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6471.2
Applied rewrites71.2%
lift-fma.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval31.0
Applied rewrites31.0%
Taylor expanded in b around 0
Applied rewrites100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (fma b (* b 0.5) b)))
(if (<= b 1.6e+77)
(/ 1.0 (fma a (fma a (fma a -0.16666666666666666 0.5) -1.0) 2.0))
(/ -2.0 (fma t_0 t_0 -4.0)))))
double code(double a, double b) {
double t_0 = fma(b, (b * 0.5), b);
double tmp;
if (b <= 1.6e+77) {
tmp = 1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0);
} else {
tmp = -2.0 / fma(t_0, t_0, -4.0);
}
return tmp;
}
function code(a, b) t_0 = fma(b, Float64(b * 0.5), b) tmp = 0.0 if (b <= 1.6e+77) tmp = Float64(1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0)); else tmp = Float64(-2.0 / fma(t_0, t_0, -4.0)); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.5), $MachinePrecision] + b), $MachinePrecision]}, If[LessEqual[b, 1.6e+77], N[(1.0 / N[(a * N[(a * N[(a * -0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(t$95$0 * t$95$0 + -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, b \cdot 0.5, b\right)\\
\mathbf{if}\;b \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, -0.16666666666666666, 0.5\right), -1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{\mathsf{fma}\left(t\_0, t\_0, -4\right)}\\
\end{array}
\end{array}
if b < 1.6000000000000001e77Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.5
Applied rewrites98.5%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6473.1
Applied rewrites73.1%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6465.6
Applied rewrites65.6%
if 1.6000000000000001e77 < b Initial program 98.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6471.2
Applied rewrites71.2%
lift-fma.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval31.0
Applied rewrites31.0%
Taylor expanded in b around 0
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= b 5.2e+81) (/ 1.0 (fma a (fma a (fma a -0.16666666666666666 0.5) -1.0) 2.0)) (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 5.2e+81) {
tmp = 1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0);
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 5.2e+81) tmp = Float64(1.0 / fma(a, fma(a, fma(a, -0.16666666666666666, 0.5), -1.0), 2.0)); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
code[a_, b_] := If[LessEqual[b, 5.2e+81], N[(1.0 / N[(a * N[(a * N[(a * -0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, -0.16666666666666666, 0.5\right), -1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 5.19999999999999984e81Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.5
Applied rewrites98.5%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6465.8
Applied rewrites65.8%
if 5.19999999999999984e81 < b Initial program 98.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
Taylor expanded in b around inf
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6495.1
Applied rewrites95.1%
(FPCore (a b) :precision binary64 (if (<= b 4.1e+81) (/ 1.0 (fma a (fma 0.5 a -1.0) 2.0)) (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 4.1e+81) {
tmp = 1.0 / fma(a, fma(0.5, a, -1.0), 2.0);
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 4.1e+81) tmp = Float64(1.0 / fma(a, fma(0.5, a, -1.0), 2.0)); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
code[a_, b_] := If[LessEqual[b, 4.1e+81], N[(1.0 / N[(a * N[(0.5 * a + -1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.1 \cdot 10^{+81}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(0.5, a, -1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 4.10000000000000012e81Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.5
Applied rewrites98.5%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6462.4
Applied rewrites62.4%
if 4.10000000000000012e81 < b Initial program 98.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
Taylor expanded in b around inf
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6495.1
Applied rewrites95.1%
(FPCore (a b) :precision binary64 (if (<= b 1.6e+18) (/ 1.0 (- 2.0 a)) (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 1.6e+18) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 6.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.6d+18) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 6.0d0 / (b * (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.6e+18) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.6e+18: tmp = 1.0 / (2.0 - a) else: tmp = 6.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.6e+18) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(6.0 / Float64(b * Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.6e+18) tmp = 1.0 / (2.0 - a); else tmp = 6.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.6e+18], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.6 \cdot 10^{+18}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 1.6e18Initial program 98.4%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.4
Applied rewrites98.4%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6475.5
Applied rewrites75.5%
Taylor expanded in a around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6453.5
Applied rewrites53.5%
if 1.6e18 < b Initial program 97.1%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6478.4
Applied rewrites78.4%
Taylor expanded in b around inf
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.4
Applied rewrites78.4%
(FPCore (a b) :precision binary64 (if (<= b 1.15e+79) (/ 1.0 (- 2.0 a)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.15e+79) {
tmp = 1.0 / (2.0 - a);
} 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 <= 1.15d+79) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.15e+79) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.15e+79: tmp = 1.0 / (2.0 - a) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.15e+79) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.15e+79) tmp = 1.0 / (2.0 - a); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.15e+79], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.15 \cdot 10^{+79}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.15e79Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.5
Applied rewrites98.5%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in a around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6450.3
Applied rewrites50.3%
if 1.15e79 < b Initial program 98.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6472.4
Applied rewrites72.4%
Taylor expanded in b around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6472.4
Applied rewrites72.4%
(FPCore (a b) :precision binary64 (if (<= a -4.2e+24) (* b (* (* b b) 0.020833333333333332)) (fma a 0.25 0.5)))
double code(double a, double b) {
double tmp;
if (a <= -4.2e+24) {
tmp = b * ((b * b) * 0.020833333333333332);
} else {
tmp = fma(a, 0.25, 0.5);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -4.2e+24) tmp = Float64(b * Float64(Float64(b * b) * 0.020833333333333332)); else tmp = fma(a, 0.25, 0.5); end return tmp end
code[a_, b_] := If[LessEqual[a, -4.2e+24], N[(b * N[(N[(b * b), $MachinePrecision] * 0.020833333333333332), $MachinePrecision]), $MachinePrecision], N[(a * 0.25 + 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.2 \cdot 10^{+24}:\\
\;\;\;\;b \cdot \left(\left(b \cdot b\right) \cdot 0.020833333333333332\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, 0.25, 0.5\right)\\
\end{array}
\end{array}
if a < -4.2000000000000003e24Initial program 98.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6436.0
Applied rewrites36.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f642.7
Applied rewrites2.7%
Taylor expanded in b around inf
unpow3N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6442.7
Applied rewrites42.7%
if -4.2000000000000003e24 < a Initial program 97.9%
Taylor expanded in b around 0
Applied rewrites51.3%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6450.4
Applied rewrites50.4%
Final simplification48.6%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 98.0%
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.8
Applied rewrites98.8%
Taylor expanded in b around 0
mul-1-negN/A
unsub-negN/A
exp-diffN/A
remove-double-divN/A
exp-negN/A
rem-exp-logN/A
associate-/r*N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
exp-negN/A
lft-mult-inverseN/A
*-rgt-identityN/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6462.9
Applied rewrites62.9%
Taylor expanded in a around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6439.9
Applied rewrites39.9%
(FPCore (a b) :precision binary64 (fma a 0.25 0.5))
double code(double a, double b) {
return fma(a, 0.25, 0.5);
}
function code(a, b) return fma(a, 0.25, 0.5) end
code[a_, b_] := N[(a * 0.25 + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, 0.25, 0.5\right)
\end{array}
Initial program 98.0%
Taylor expanded in b around 0
Applied rewrites62.5%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6439.3
Applied rewrites39.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.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6484.2
Applied rewrites84.2%
Taylor expanded in b around 0
Applied rewrites39.3%
(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 2024214
(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))))