
(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 10 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 (- 0.0 (log1p (exp (- b a))))))
double code(double a, double b) {
return exp((0.0 - log1p(exp((b - a)))));
}
public static double code(double a, double b) {
return Math.exp((0.0 - Math.log1p(Math.exp((b - a)))));
}
def code(a, b): return math.exp((0.0 - math.log1p(math.exp((b - a)))))
function code(a, b) return exp(Float64(0.0 - log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[N[(0.0 - N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{0 - \mathsf{log1p}\left(e^{b - a}\right)}
\end{array}
Initial program 98.8%
clear-numN/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
clear-numN/A
exp-lowering-exp.f64N/A
clear-numN/A
log-divN/A
metadata-evalN/A
--lowering--.f64N/A
frac-2negN/A
log-divN/A
*-lft-identityN/A
Applied egg-rr100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.0d0) then
tmp = exp(a) / 2.0d0
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / 2.0;
} 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) / 2.0 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) / 2.0); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) / 2.0; 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] / 2.0), $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:\\
\;\;\;\;\frac{e^{a}}{2}\\
\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%
if 0.0 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6498.7%
Simplified98.7%
(FPCore (a b) :precision binary64 (if (<= b 6e+91) (/ (exp a) 2.0) (/ 6.0 (* b (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 6e+91) {
tmp = exp(a) / 2.0;
} 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 <= 6d+91) then
tmp = exp(a) / 2.0d0
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 <= 6e+91) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6e+91: tmp = math.exp(a) / 2.0 else: tmp = 6.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 6e+91) tmp = Float64(exp(a) / 2.0); 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 <= 6e+91) tmp = exp(a) / 2.0; else tmp = 6.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6e+91], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(6.0 / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6 \cdot 10^{+91}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{b \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < 6.00000000000000012e91Initial program 99.5%
Taylor expanded in b around 0
Simplified73.5%
Taylor expanded in a around 0
Simplified72.0%
if 6.00000000000000012e91 < b Initial program 95.6%
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
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6495.9%
Simplified95.9%
Taylor expanded in b around inf
/-lowering-/.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6495.9%
Simplified95.9%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.0 / (exp((b - a)) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 1}
\end{array}
Initial program 98.8%
clear-numN/A
/-lowering-/.f64N/A
frac-2negN/A
div-invN/A
*-commutativeN/A
distribute-neg-inN/A
distribute-lft-inN/A
lft-mult-inverseN/A
*-commutativeN/A
div-invN/A
+-lowering-+.f64N/A
frac-2negN/A
div-expN/A
exp-lowering-exp.f64N/A
--lowering--.f64100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -1.5e+31) (/ 1.0 (* b (+ 1.0 (/ (- 1.0 (* (/ 2.0 b) (/ -2.0 b))) (/ 2.0 b))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (a <= -1.5e+31) {
tmp = 1.0 / (b * (1.0 + ((1.0 - ((2.0 / b) * (-2.0 / b))) / (2.0 / b))));
} 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 (a <= (-1.5d+31)) then
tmp = 1.0d0 / (b * (1.0d0 + ((1.0d0 - ((2.0d0 / b) * ((-2.0d0) / b))) / (2.0d0 / b))))
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 (a <= -1.5e+31) {
tmp = 1.0 / (b * (1.0 + ((1.0 - ((2.0 / b) * (-2.0 / b))) / (2.0 / b))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.5e+31: tmp = 1.0 / (b * (1.0 + ((1.0 - ((2.0 / b) * (-2.0 / b))) / (2.0 / b)))) 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 (a <= -1.5e+31) tmp = Float64(1.0 / Float64(b * Float64(1.0 + Float64(Float64(1.0 - Float64(Float64(2.0 / b) * Float64(-2.0 / b))) / Float64(2.0 / b))))); 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 (a <= -1.5e+31) tmp = 1.0 / (b * (1.0 + ((1.0 - ((2.0 / b) * (-2.0 / b))) / (2.0 / b)))); 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[a, -1.5e+31], N[(1.0 / N[(b * N[(1.0 + N[(N[(1.0 - N[(N[(2.0 / b), $MachinePrecision] * N[(-2.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 / b), $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}\;a \leq -1.5 \cdot 10^{+31}:\\
\;\;\;\;\frac{1}{b \cdot \left(1 + \frac{1 - \frac{2}{b} \cdot \frac{-2}{b}}{\frac{2}{b}}\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 a < -1.49999999999999995e31Initial program 100.0%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6434.3%
Simplified34.3%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6418.8%
Simplified18.8%
Taylor expanded in b around inf
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-+r+N/A
+-commutativeN/A
associate-+l+N/A
distribute-lft-inN/A
rgt-mult-inverseN/A
+-lowering-+.f64N/A
distribute-rgt-inN/A
associate-/r/N/A
*-rgt-identityN/A
associate-*r/N/A
unpow2N/A
associate-*l*N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
Simplified18.8%
frac-2negN/A
distribute-frac-neg2N/A
unsub-negN/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
/-rgt-identityN/A
frac-subN/A
*-rgt-identityN/A
/-lowering-/.f64N/A
metadata-evalN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
metadata-evalN/A
/-lowering-/.f6450.0%
Applied egg-rr50.0%
if -1.49999999999999995e31 < a Initial program 98.5%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6497.7%
Simplified97.7%
Taylor expanded in b around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6464.0%
Simplified64.0%
(FPCore (a b)
:precision binary64
(if (<= b 380.0)
(+ 0.5 (* a 0.25))
(if (<= b 5.8e+102)
(* -0.020833333333333332 (* a (* a a)))
(/ 6.0 (* b (* b b))))))
double code(double a, double b) {
double tmp;
if (b <= 380.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 5.8e+102) {
tmp = -0.020833333333333332 * (a * (a * 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 <= 380.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 5.8d+102) then
tmp = (-0.020833333333333332d0) * (a * (a * 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 <= 380.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 5.8e+102) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 6.0 / (b * (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 380.0: tmp = 0.5 + (a * 0.25) elif b <= 5.8e+102: tmp = -0.020833333333333332 * (a * (a * a)) else: tmp = 6.0 / (b * (b * b)) return tmp
function code(a, b) tmp = 0.0 if (b <= 380.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 5.8e+102) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * 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 <= 380.0) tmp = 0.5 + (a * 0.25); elseif (b <= 5.8e+102) tmp = -0.020833333333333332 * (a * (a * a)); else tmp = 6.0 / (b * (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 380.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e+102], 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 380:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;-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 < 380Initial program 99.5%
Taylor expanded in b around 0
Simplified77.8%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.4%
Simplified55.4%
if 380 < b < 5.8000000000000005e102Initial program 100.0%
Taylor expanded in b around 0
Simplified29.5%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.9%
Simplified2.9%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6440.5%
Simplified40.5%
if 5.8000000000000005e102 < b Initial program 95.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
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.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%
(FPCore (a b)
:precision binary64
(if (<= b 285.0)
(+ 0.5 (* a 0.25))
(if (<= b 2.65e+132)
(* -0.020833333333333332 (* a (* a a)))
(/ 2.0 (* b b)))))
double code(double a, double b) {
double tmp;
if (b <= 285.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 2.65e+132) {
tmp = -0.020833333333333332 * (a * (a * 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 <= 285.0d0) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 2.65d+132) then
tmp = (-0.020833333333333332d0) * (a * (a * 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 <= 285.0) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 2.65e+132) {
tmp = -0.020833333333333332 * (a * (a * a));
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 285.0: tmp = 0.5 + (a * 0.25) elif b <= 2.65e+132: tmp = -0.020833333333333332 * (a * (a * a)) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 285.0) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 2.65e+132) tmp = Float64(-0.020833333333333332 * Float64(a * Float64(a * a))); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 285.0) tmp = 0.5 + (a * 0.25); elseif (b <= 2.65e+132) tmp = -0.020833333333333332 * (a * (a * a)); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 285.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.65e+132], 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 285:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{+132}:\\
\;\;\;\;-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 < 285Initial program 99.5%
Taylor expanded in b around 0
Simplified77.8%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.4%
Simplified55.4%
if 285 < b < 2.65e132Initial program 100.0%
Taylor expanded in b around 0
Simplified31.8%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.8%
Simplified2.8%
Taylor expanded in a around inf
*-lowering-*.f64N/A
cube-multN/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6440.7%
Simplified40.7%
if 2.65e132 < b Initial program 94.7%
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-*.f6486.0%
Simplified86.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6486.0%
Simplified86.0%
(FPCore (a b) :precision binary64 (if (<= b 1.75) (+ 0.5 (* a 0.25)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.75) {
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 <= 1.75d0) 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 <= 1.75) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.75: tmp = 0.5 + (a * 0.25) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.75) 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 <= 1.75) tmp = 0.5 + (a * 0.25); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.75], 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 1.75:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.75Initial program 99.5%
Taylor expanded in b around 0
Simplified77.8%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6455.4%
Simplified55.4%
if 1.75 < b Initial program 96.9%
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-*.f6452.2%
Simplified52.2%
Taylor expanded in b around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6452.2%
Simplified52.2%
(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 98.8%
Taylor expanded in b around 0
Simplified67.5%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6442.1%
Simplified42.1%
(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.8%
Taylor expanded in a around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
exp-lowering-exp.f6483.1%
Simplified83.1%
Taylor expanded in b around 0
Simplified41.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 2024164
(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))))