
(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 9 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
(let* ((t_0 (sqrt (cos x))))
(/
(fmod (exp x) (+ (* t_0 0.6666666666666666) (log (cbrt (exp t_0)))))
(exp x))))
double code(double x) {
double t_0 = sqrt(cos(x));
return fmod(exp(x), ((t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x);
}
function code(x) t_0 = sqrt(cos(x)) return Float64(rem(exp(x), Float64(Float64(t_0 * 0.6666666666666666) + log(cbrt(exp(t_0))))) / exp(x)) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(t$95$0 * 0.6666666666666666), $MachinePrecision] + N[Log[N[Power[N[Exp[t$95$0], $MachinePrecision], 1/3], $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{\cos x}\\
\frac{\left(\left(e^{x}\right) \bmod \left(t\_0 \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e^{t\_0}}\right)\right)\right)}{e^{x}}
\end{array}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
add-log-exp7.7%
add-cube-cbrt44.6%
log-prod44.6%
pow244.6%
Applied egg-rr44.6%
Taylor expanded in x around inf 44.7%
unpow1/344.7%
unpow244.7%
prod-exp44.7%
exp-prod44.7%
count-244.7%
associate-*r*44.7%
*-commutative44.7%
log1p-expm144.7%
log1p-define44.7%
rem-exp-log44.7%
log1p-define44.7%
log1p-expm144.7%
count-244.7%
distribute-rgt-out44.7%
metadata-eval44.7%
Simplified44.7%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ (* (sqrt (cos x)) 0.6666666666666666) (log (cbrt E)))) (exp x)))
double code(double x) {
return fmod(exp(x), ((sqrt(cos(x)) * 0.6666666666666666) + log(cbrt(((double) M_E))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(Float64(sqrt(cos(x)) * 0.6666666666666666) + log(cbrt(exp(1))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision] * 0.6666666666666666), $MachinePrecision] + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x} \cdot 0.6666666666666666 + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
add-log-exp7.7%
add-cube-cbrt44.6%
log-prod44.6%
pow244.6%
Applied egg-rr44.6%
Taylor expanded in x around inf 44.7%
unpow1/344.7%
unpow244.7%
prod-exp44.7%
exp-prod44.7%
count-244.7%
associate-*r*44.7%
*-commutative44.7%
log1p-expm144.7%
log1p-define44.7%
rem-exp-log44.7%
log1p-define44.7%
log1p-expm144.7%
count-244.7%
distribute-rgt-out44.7%
metadata-eval44.7%
Simplified44.7%
Taylor expanded in x around 0 44.0%
exp-1-e44.0%
Simplified44.0%
(FPCore (x) :precision binary64 (exp (- (log (fmod (exp x) (sqrt (cos x)))) x)))
double code(double x) {
return exp((log(fmod(exp(x), sqrt(cos(x)))) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((log(mod(exp(x), sqrt(cos(x)))) - x))
end function
def code(x): return math.exp((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x))
function code(x) return exp(Float64(log(rem(exp(x), sqrt(cos(x)))) - x)) end
code[x_] := 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]
\begin{array}{l}
\\
e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
add-exp-log7.7%
div-exp7.8%
Applied egg-rr7.8%
(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(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}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 1.0 (* -0.25 (pow x 2.0)))) (exp x)))
double code(double x) {
return fmod(exp(x), (1.0 + (-0.25 * pow(x, 2.0)))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + (-0.25 * math.pow(x, 2.0)))) / math.exp(x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
Taylor expanded in x around 0 7.3%
(FPCore (x) :precision binary64 (exp (- (log (fmod (exp x) 1.0)) x)))
double code(double x) {
return exp((log(fmod(exp(x), 1.0)) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((log(mod(exp(x), 1.0d0)) - x))
end function
def code(x): return math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x))
function code(x) return exp(Float64(log(rem(exp(x), 1.0)) - x)) end
code[x_] := N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
Taylor expanded in x around 0 7.0%
add-exp-log7.0%
div-exp7.0%
Applied egg-rr7.0%
(FPCore (x) :precision binary64 (/ (fmod (exp x) 1.0) (exp x)))
double code(double x) {
return fmod(exp(x), 1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), 1.0) / math.exp(x)
function code(x) return Float64(rem(exp(x), 1.0) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(e^{x}\right) \bmod 1\right)}{e^{x}}
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
Taylor expanded in x around 0 7.0%
(FPCore (x) :precision binary64 (* (fmod (exp x) 1.0) (- 1.0 x)))
double code(double x) {
return fmod(exp(x), 1.0) * (1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0) * (1.0d0 - x)
end function
def code(x): return math.fmod(math.exp(x), 1.0) * (1.0 - x)
function code(x) return Float64(rem(exp(x), 1.0) * Float64(1.0 - x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
Taylor expanded in x around 0 7.0%
Taylor expanded in x around 0 6.5%
+-commutative6.5%
*-lft-identity6.5%
associate-*r*6.5%
neg-mul-16.5%
distribute-rgt-out6.5%
sub-neg6.5%
Simplified6.5%
(FPCore (x) :precision binary64 (fmod (exp x) 1.0))
double code(double x) {
return fmod(exp(x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0)
end function
def code(x): return math.fmod(math.exp(x), 1.0)
function code(x) return rem(exp(x), 1.0) end
code[x_] := N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right)
\end{array}
Initial program 7.7%
/-rgt-identity7.7%
associate-/r/7.7%
exp-neg7.7%
remove-double-neg7.7%
Simplified7.7%
Taylor expanded in x around 0 7.0%
Taylor expanded in x around 0 6.0%
herbie shell --seed 2024096
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))