
(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 5 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 -5e-311) 1.0 (exp (- (log (fmod (+ x 1.0) (sqrt (cos x)))) x))))
double code(double x) {
double tmp;
if (x <= -5e-311) {
tmp = 1.0;
} else {
tmp = exp((log(fmod((x + 1.0), sqrt(cos(x)))) - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-311)) then
tmp = 1.0d0
else
tmp = exp((log(mod((x + 1.0d0), sqrt(cos(x)))) - x))
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-311: tmp = 1.0 else: tmp = math.exp((math.log(math.fmod((x + 1.0), math.sqrt(math.cos(x)))) - x)) return tmp
function code(x) tmp = 0.0 if (x <= -5e-311) tmp = 1.0; else tmp = exp(Float64(log(rem(Float64(x + 1.0), sqrt(cos(x)))) - x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-311], 1.0, N[Exp[N[(N[Log[N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-311}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left(\left(x + 1\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}\\
\end{array}
\end{array}
if x < -5.00000000000023e-311Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
add-exp-log8.3%
div-exp8.3%
Applied egg-rr8.3%
add-log-exp8.3%
Applied egg-rr8.3%
Taylor expanded in x around inf 97.9%
neg-mul-197.9%
Simplified97.9%
Taylor expanded in x around 0 100.0%
if -5.00000000000023e-311 < x Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
add-exp-log5.1%
div-exp5.1%
Applied egg-rr5.1%
Taylor expanded in x around 0 38.1%
+-commutative37.8%
Simplified38.1%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (exp (cos x))))) (/ (fmod (+ x 1.0) (sqrt (+ (log (pow t_0 2.0)) (log t_0)))) (exp x))))
double code(double x) {
double t_0 = cbrt(exp(cos(x)));
return fmod((x + 1.0), sqrt((log(pow(t_0, 2.0)) + log(t_0)))) / exp(x);
}
function code(x) t_0 = cbrt(exp(cos(x))) return Float64(rem(Float64(x + 1.0), sqrt(Float64(log((t_0 ^ 2.0)) + log(t_0)))) / exp(x)) end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Cos[x], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[Sqrt[N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{e^{\cos x}}\\
\frac{\left(\left(x + 1\right) \bmod \left(\sqrt{\log \left({t\_0}^{2}\right) + \log t\_0}\right)\right)}{e^{x}}
\end{array}
\end{array}
Initial program 6.5%
/-rgt-identity6.5%
associate-/r/6.5%
exp-neg6.5%
remove-double-neg6.5%
Simplified6.5%
add-log-exp6.5%
add-cube-cbrt46.4%
log-prod46.4%
pow246.4%
Applied egg-rr46.4%
Taylor expanded in x around 0 64.5%
+-commutative64.5%
Simplified64.5%
(FPCore (x) :precision binary64 (if (<= x -5e-311) 1.0 (/ (fmod (+ x 1.0) (+ 1.0 (* (pow x 2.0) -0.25))) (exp x))))
double code(double x) {
double tmp;
if (x <= -5e-311) {
tmp = 1.0;
} else {
tmp = fmod((x + 1.0), (1.0 + (pow(x, 2.0) * -0.25))) / exp(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-311)) then
tmp = 1.0d0
else
tmp = mod((x + 1.0d0), (1.0d0 + ((x ** 2.0d0) * (-0.25d0)))) / exp(x)
end if
code = tmp
end function
def code(x): tmp = 0 if x <= -5e-311: tmp = 1.0 else: tmp = math.fmod((x + 1.0), (1.0 + (math.pow(x, 2.0) * -0.25))) / math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= -5e-311) tmp = 1.0; else tmp = Float64(rem(Float64(x + 1.0), Float64(1.0 + Float64((x ^ 2.0) * -0.25))) / exp(x)); end return tmp end
code[x_] := If[LessEqual[x, -5e-311], 1.0, N[(N[With[{TMP1 = N[(x + 1.0), $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-311}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(x + 1\right) \bmod \left(1 + {x}^{2} \cdot -0.25\right)\right)}{e^{x}}\\
\end{array}
\end{array}
if x < -5.00000000000023e-311Initial program 8.3%
/-rgt-identity8.3%
associate-/r/8.3%
exp-neg8.3%
remove-double-neg8.3%
Simplified8.3%
add-exp-log8.3%
div-exp8.3%
Applied egg-rr8.3%
add-log-exp8.3%
Applied egg-rr8.3%
Taylor expanded in x around inf 97.9%
neg-mul-197.9%
Simplified97.9%
Taylor expanded in x around 0 100.0%
if -5.00000000000023e-311 < x Initial program 5.1%
/-rgt-identity5.1%
associate-/r/5.1%
exp-neg5.1%
remove-double-neg5.1%
Simplified5.1%
Taylor expanded in x around 0 5.1%
*-commutative5.1%
Simplified5.1%
Taylor expanded in x around 0 38.1%
+-commutative37.8%
Simplified38.1%
(FPCore (x) :precision binary64 (exp (- x)))
double code(double x) {
return exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-x)
end function
public static double code(double x) {
return Math.exp(-x);
}
def code(x): return math.exp(-x)
function code(x) return exp(Float64(-x)) end
function tmp = code(x) tmp = exp(-x); end
code[x_] := N[Exp[(-x)], $MachinePrecision]
\begin{array}{l}
\\
e^{-x}
\end{array}
Initial program 6.5%
/-rgt-identity6.5%
associate-/r/6.5%
exp-neg6.5%
remove-double-neg6.5%
Simplified6.5%
add-exp-log6.5%
div-exp6.5%
Applied egg-rr6.5%
add-log-exp6.5%
Applied egg-rr6.5%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
(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 6.5%
/-rgt-identity6.5%
associate-/r/6.5%
exp-neg6.5%
remove-double-neg6.5%
Simplified6.5%
add-exp-log6.5%
div-exp6.5%
Applied egg-rr6.5%
add-log-exp6.5%
Applied egg-rr6.5%
Taylor expanded in x around inf 63.6%
neg-mul-163.6%
Simplified63.6%
Taylor expanded in x around 0 46.3%
herbie shell --seed 2024111
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))