
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
(FPCore (x)
:precision binary64
(if (<= x -2e-310)
1.0
(if (<= x 10.0)
(pow (exp -1.0) (- x (log (log (exp (fmod (exp x) (sqrt (cos x))))))))
(pow (exp -1.0) x))))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else if (x <= 10.0) {
tmp = pow(exp(-1.0), (x - log(log(exp(fmod(exp(x), sqrt(cos(x))))))));
} else {
tmp = pow(exp(-1.0), x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else if (x <= 10.0d0) then
tmp = exp((-1.0d0)) ** (x - log(log(exp(mod(exp(x), sqrt(cos(x)))))))
else
tmp = exp((-1.0d0)) ** x
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 elif x <= 10.0: tmp = math.pow(math.exp(-1.0), (x - math.log(math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x)))))))) else: tmp = math.pow(math.exp(-1.0), x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; elseif (x <= 10.0) tmp = exp(-1.0) ^ Float64(x - log(log(exp(rem(exp(x), sqrt(cos(x))))))); else tmp = exp(-1.0) ^ x; end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[Power[N[Exp[-1.0], $MachinePrecision], N[(x - N[Log[N[Log[N[Exp[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 10:\\
\;\;\;\;{\left(e^{-1}\right)}^{\left(x - \log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 9.0%
exp-neg9.0%
associate-*r/9.0%
*-rgt-identity9.0%
Simplified9.0%
pow1/29.0%
metadata-eval9.0%
metadata-eval9.0%
pow-pow9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Applied egg-rr97.7%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < x < 10Initial program 11.3%
exp-neg11.3%
associate-*r/11.3%
*-rgt-identity11.3%
Simplified11.3%
clear-num11.3%
inv-pow11.3%
pow-to-exp11.3%
*-commutative11.3%
exp-prod11.3%
log-div11.3%
rem-log-exp11.3%
Applied egg-rr11.3%
add-log-exp_binary6411.3%
Applied rewrite-once11.3%
if 10 < x Initial program 0.0%
exp-neg0.0%
associate-*r/0.0%
*-rgt-identity0.0%
Simplified0.0%
clear-num0.0%
inv-pow0.0%
pow-to-exp0.0%
*-commutative0.0%
exp-prod0.0%
log-div0.0%
rem-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
Final simplification62.9%
(FPCore (x)
:precision binary64
(if (<= x -2e-310)
1.0
(if (<= x 10.0)
(/ (log (exp (fmod (exp x) (sqrt (cos x))))) (exp x))
(pow (exp -1.0) x))))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else if (x <= 10.0) {
tmp = log(exp(fmod(exp(x), sqrt(cos(x))))) / exp(x);
} else {
tmp = pow(exp(-1.0), x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else if (x <= 10.0d0) then
tmp = log(exp(mod(exp(x), sqrt(cos(x))))) / exp(x)
else
tmp = exp((-1.0d0)) ** x
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 elif x <= 10.0: tmp = math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))) / math.exp(x) else: tmp = math.pow(math.exp(-1.0), x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; elseif (x <= 10.0) tmp = Float64(log(exp(rem(exp(x), sqrt(cos(x))))) / exp(x)); else tmp = exp(-1.0) ^ x; end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[(N[Log[N[Exp[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 10:\\
\;\;\;\;\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 9.0%
exp-neg9.0%
associate-*r/9.0%
*-rgt-identity9.0%
Simplified9.0%
pow1/29.0%
metadata-eval9.0%
metadata-eval9.0%
pow-pow9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Applied egg-rr97.7%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < x < 10Initial program 11.3%
exp-neg11.3%
associate-*r/11.3%
*-rgt-identity11.3%
Simplified11.3%
add-log-exp_binary6411.3%
Applied rewrite-once11.3%
if 10 < x Initial program 0.0%
exp-neg0.0%
associate-*r/0.0%
*-rgt-identity0.0%
Simplified0.0%
clear-num0.0%
inv-pow0.0%
pow-to-exp0.0%
*-commutative0.0%
exp-prod0.0%
log-div0.0%
rem-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
Final simplification62.9%
(FPCore (x)
:precision binary64
(if (<= x -2e-310)
1.0
(if (<= x 10.0)
(exp (- (log (fmod (exp x) (sqrt (cos x)))) x))
(pow (exp -1.0) x))))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else if (x <= 10.0) {
tmp = exp((log(fmod(exp(x), sqrt(cos(x)))) - x));
} else {
tmp = pow(exp(-1.0), x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else if (x <= 10.0d0) then
tmp = exp((log(mod(exp(x), sqrt(cos(x)))) - x))
else
tmp = exp((-1.0d0)) ** x
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 elif x <= 10.0: tmp = math.exp((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x)) else: tmp = math.pow(math.exp(-1.0), x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; elseif (x <= 10.0) tmp = exp(Float64(log(rem(exp(x), sqrt(cos(x)))) - x)); else tmp = exp(-1.0) ^ x; end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 10:\\
\;\;\;\;e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\\
\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 9.0%
exp-neg9.0%
associate-*r/9.0%
*-rgt-identity9.0%
Simplified9.0%
pow1/29.0%
metadata-eval9.0%
metadata-eval9.0%
pow-pow9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Applied egg-rr97.7%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < x < 10Initial program 11.3%
exp-neg11.3%
associate-*r/11.3%
*-rgt-identity11.3%
Simplified11.3%
clear-num11.3%
inv-pow11.3%
pow-to-exp11.3%
*-commutative11.3%
log-pow11.3%
inv-pow11.3%
clear-num11.3%
log-div11.3%
rem-log-exp11.3%
Applied egg-rr11.3%
if 10 < x Initial program 0.0%
exp-neg0.0%
associate-*r/0.0%
*-rgt-identity0.0%
Simplified0.0%
clear-num0.0%
inv-pow0.0%
pow-to-exp0.0%
*-commutative0.0%
exp-prod0.0%
log-div0.0%
rem-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
Final simplification62.9%
(FPCore (x)
:precision binary64
(if (<= x -2e-310)
1.0
(if (<= x 10.0)
(/ (fmod (exp x) (sqrt (cos x))) (exp x))
(pow (exp -1.0) x))))
double code(double x) {
double tmp;
if (x <= -2e-310) {
tmp = 1.0;
} else if (x <= 10.0) {
tmp = fmod(exp(x), sqrt(cos(x))) / exp(x);
} else {
tmp = pow(exp(-1.0), x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = 1.0d0
else if (x <= 10.0d0) then
tmp = mod(exp(x), sqrt(cos(x))) / exp(x)
else
tmp = exp((-1.0d0)) ** x
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -2e-310: tmp = 1.0 elif x <= 10.0: tmp = math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x) else: tmp = math.pow(math.exp(-1.0), x) return tmp
function code(x) tmp = 0.0 if (x <= -2e-310) tmp = 1.0; elseif (x <= 10.0) tmp = Float64(rem(exp(x), sqrt(cos(x))) / exp(x)); else tmp = exp(-1.0) ^ x; end return tmp end
code[x_] := If[LessEqual[x, -2e-310], 1.0, If[LessEqual[x, 10.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 10:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 9.0%
exp-neg9.0%
associate-*r/9.0%
*-rgt-identity9.0%
Simplified9.0%
pow1/29.0%
metadata-eval9.0%
metadata-eval9.0%
pow-pow9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Applied egg-rr97.7%
Taylor expanded in x around 0 100.0%
if -1.999999999999994e-310 < x < 10Initial program 11.3%
exp-neg11.3%
associate-*r/11.3%
*-rgt-identity11.3%
Simplified11.3%
if 10 < x Initial program 0.0%
exp-neg0.0%
associate-*r/0.0%
*-rgt-identity0.0%
Simplified0.0%
clear-num0.0%
inv-pow0.0%
pow-to-exp0.0%
*-commutative0.0%
exp-prod0.0%
log-div0.0%
rem-log-exp0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 100.0%
Final simplification62.9%
(FPCore (x) :precision binary64 (if (<= x 5e-300) 1.0 (pow (exp -1.0) x)))
double code(double x) {
double tmp;
if (x <= 5e-300) {
tmp = 1.0;
} else {
tmp = pow(exp(-1.0), x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d-300) then
tmp = 1.0d0
else
tmp = exp((-1.0d0)) ** x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e-300) {
tmp = 1.0;
} else {
tmp = Math.pow(Math.exp(-1.0), x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e-300: tmp = 1.0 else: tmp = math.pow(math.exp(-1.0), x) return tmp
function code(x) tmp = 0.0 if (x <= 5e-300) tmp = 1.0; else tmp = exp(-1.0) ^ x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e-300) tmp = 1.0; else tmp = exp(-1.0) ^ x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e-300], 1.0, N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-300}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;{\left(e^{-1}\right)}^{x}\\
\end{array}
\end{array}
if x < 4.99999999999999996e-300Initial program 9.1%
exp-neg9.1%
associate-*r/9.1%
*-rgt-identity9.1%
Simplified9.1%
pow1/29.1%
metadata-eval9.1%
metadata-eval9.1%
pow-pow9.1%
metadata-eval9.1%
Applied egg-rr9.1%
Applied egg-rr94.1%
Taylor expanded in x around 0 96.2%
if 4.99999999999999996e-300 < x Initial program 7.6%
exp-neg7.6%
associate-*r/7.6%
*-rgt-identity7.6%
Simplified7.6%
clear-num7.6%
inv-pow7.6%
pow-to-exp7.6%
*-commutative7.6%
exp-prod7.6%
log-div7.6%
rem-log-exp7.6%
Applied egg-rr7.6%
Taylor expanded in x around inf 36.7%
Final simplification60.6%
(FPCore (x) :precision binary64 (pow (+ 1.0 (* (* x x) -0.25)) -1.0))
double code(double x) {
return pow((1.0 + ((x * x) * -0.25)), -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + ((x * x) * (-0.25d0))) ** (-1.0d0)
end function
public static double code(double x) {
return Math.pow((1.0 + ((x * x) * -0.25)), -1.0);
}
def code(x): return math.pow((1.0 + ((x * x) * -0.25)), -1.0)
function code(x) return Float64(1.0 + Float64(Float64(x * x) * -0.25)) ^ -1.0 end
function tmp = code(x) tmp = (1.0 + ((x * x) * -0.25)) ^ -1.0; end
code[x_] := N[Power[N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(1 + \left(x \cdot x\right) \cdot -0.25\right)}^{-1}
\end{array}
Initial program 8.2%
exp-neg8.2%
associate-*r/8.2%
*-rgt-identity8.2%
Simplified8.2%
pow1/28.2%
metadata-eval8.2%
metadata-eval8.2%
pow-pow8.2%
metadata-eval8.2%
Applied egg-rr8.2%
Applied egg-rr40.8%
Taylor expanded in x around 0 50.4%
*-commutative50.4%
unpow250.4%
Simplified50.4%
Final simplification50.4%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 8.2%
exp-neg8.2%
associate-*r/8.2%
*-rgt-identity8.2%
Simplified8.2%
pow1/28.2%
metadata-eval8.2%
metadata-eval8.2%
pow-pow8.2%
metadata-eval8.2%
Applied egg-rr8.2%
Applied egg-rr40.8%
Taylor expanded in x around 0 41.7%
Final simplification41.7%
herbie shell --seed 2023297
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))