
(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 12 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 (fmod (exp x) (sqrt (cos x)))))
(if (<= (* t_0 (exp (- x))) 0.0)
(* (fmod (exp x) (+ (log (cbrt (exp 2.0))) (log (cbrt E)))) (- 1.0 x))
(exp (- (log t_0) x)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((t_0 * exp(-x)) <= 0.0) {
tmp = fmod(exp(x), (log(cbrt(exp(2.0))) + log(cbrt(((double) M_E))))) * (1.0 - x);
} else {
tmp = exp((log(t_0) - x));
}
return tmp;
}
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (Float64(t_0 * exp(Float64(-x))) <= 0.0) tmp = Float64(rem(exp(x), Float64(log(cbrt(exp(2.0))) + log(cbrt(exp(1))))) * Float64(1.0 - x)); else tmp = exp(Float64(log(t_0) - x)); end return tmp end
code[x_] := Block[{t$95$0 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[N[Exp[2.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[E, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Log[t$95$0], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_0 \cdot e^{-x} \leq 0:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{e}\right)\right)\right) \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log t\_0 - x}\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.0Initial program 3.1%
/-rgt-identity3.1%
associate-/r/3.1%
exp-neg3.1%
remove-double-neg3.1%
Simplified3.1%
add-log-exp3.1%
add-cube-cbrt100.0%
log-prod100.0%
pow2100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
unpow2100.0%
prod-exp100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
exp-1-e100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
associate-*r*100.0%
neg-mul-1100.0%
distribute-lft1-in100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if 0.0 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 15.8%
exp-neg15.8%
div-inv15.9%
clear-num15.9%
inv-pow15.9%
pow-to-exp15.9%
diff-log15.9%
add-log-exp16.0%
Applied egg-rr16.0%
Final simplification21.2%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (exp (sqrt (cos x)))))) (/ (fmod (exp x) (+ (log (pow t_0 2.0)) (log t_0))) (exp x))))
double code(double x) {
double t_0 = cbrt(exp(sqrt(cos(x))));
return fmod(exp(x), (log(pow(t_0, 2.0)) + log(t_0))) / exp(x);
}
function code(x) t_0 = cbrt(exp(sqrt(cos(x)))) return Float64(rem(exp(x), Float64(log((t_0 ^ 2.0)) + log(t_0))) / exp(x)) end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision] + N[Log[t$95$0], $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^{\sqrt{\cos x}}}\\
\frac{\left(\left(e^{x}\right) \bmod \left(\log \left({t\_0}^{2}\right) + \log t\_0\right)\right)}{e^{x}}
\end{array}
\end{array}
Initial program 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
add-log-exp15.1%
add-cube-cbrt20.9%
log-prod20.9%
pow220.9%
Applied egg-rr20.9%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ (log (cbrt (exp (sqrt (cos x))))) (log (cbrt (exp 2.0))))) (exp x)))
double code(double x) {
return fmod(exp(x), (log(cbrt(exp(sqrt(cos(x))))) + log(cbrt(exp(2.0))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(log(cbrt(exp(sqrt(cos(x))))) + log(cbrt(exp(2.0))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[N[Exp[N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[N[Exp[2.0], $MachinePrecision], 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(\log \left(\sqrt[3]{e^{\sqrt{\cos x}}}\right) + \log \left(\sqrt[3]{e^{2}}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
add-log-exp15.1%
add-cube-cbrt20.9%
log-prod20.9%
pow220.9%
Applied egg-rr20.9%
Taylor expanded in x around 0 19.7%
unpow219.7%
prod-exp19.7%
metadata-eval19.7%
Simplified19.7%
Final simplification19.7%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ (log (cbrt (exp 2.0))) (log (cbrt E)))) (exp x)))
double code(double x) {
return fmod(exp(x), (log(cbrt(exp(2.0))) + log(cbrt(((double) M_E))))) / exp(x);
}
function code(x) return Float64(rem(exp(x), Float64(log(cbrt(exp(2.0))) + log(cbrt(exp(1))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Log[N[Power[N[Exp[2.0], $MachinePrecision], 1/3], $MachinePrecision]], $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(\log \left(\sqrt[3]{e^{2}}\right) + \log \left(\sqrt[3]{e}\right)\right)\right)}{e^{x}}
\end{array}
Initial program 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
add-log-exp15.1%
add-cube-cbrt20.9%
log-prod20.9%
pow220.9%
Applied egg-rr20.9%
Taylor expanded in x around 0 19.7%
unpow219.7%
prod-exp19.7%
metadata-eval19.7%
Simplified19.7%
Taylor expanded in x around 0 19.7%
exp-1-e19.7%
Simplified19.7%
(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 15.0%
exp-neg15.1%
div-inv15.1%
clear-num15.1%
inv-pow15.1%
pow-to-exp15.1%
diff-log15.1%
add-log-exp15.2%
Applied egg-rr15.2%
Final simplification15.2%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
Taylor expanded in x around 0 14.4%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
add-log-exp15.1%
add-cube-cbrt20.9%
log-prod20.9%
pow220.9%
Applied egg-rr20.9%
Taylor expanded in x around 0 19.7%
unpow219.7%
prod-exp19.7%
metadata-eval19.7%
Simplified19.7%
Taylor expanded in x around 0 19.7%
exp-1-e19.7%
Simplified19.7%
metadata-eval19.7%
prod-exp19.7%
e-exp-119.7%
e-exp-119.7%
cbrt-unprod19.6%
log-prod19.6%
add-cube-cbrt13.7%
log-E13.7%
add-exp-log13.7%
log-div13.7%
add-log-exp13.8%
Applied egg-rr13.8%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
Taylor expanded in x around 0 13.7%
(FPCore (x) :precision binary64 (* (fmod (exp x) 1.0) (+ (- 1.0 x) (* x (* x 0.5)))))
double code(double x) {
return fmod(exp(x), 1.0) * ((1.0 - x) + (x * (x * 0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0) * ((1.0d0 - x) + (x * (x * 0.5d0)))
end function
def code(x): return math.fmod(math.exp(x), 1.0) * ((1.0 - x) + (x * (x * 0.5)))
function code(x) return Float64(rem(exp(x), 1.0) * Float64(Float64(1.0 - x) + Float64(x * Float64(x * 0.5)))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(N[(1.0 - x), $MachinePrecision] + N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(\left(1 - x\right) + x \cdot \left(x \cdot 0.5\right)\right)
\end{array}
Initial program 15.0%
Taylor expanded in x around 0 12.4%
+-commutative12.4%
neg-mul-112.4%
distribute-lft-in12.4%
distribute-rgt-neg-in12.4%
mul-1-neg12.4%
associate-+r+12.4%
Simplified12.4%
Taylor expanded in x around 0 11.8%
Final simplification11.8%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
Taylor expanded in x around 0 13.7%
Taylor expanded in x around 0 10.9%
+-commutative10.9%
*-lft-identity10.9%
associate-*r*10.9%
distribute-rgt-out10.9%
mul-1-neg10.9%
unsub-neg10.9%
Simplified10.9%
(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 15.0%
/-rgt-identity15.0%
associate-/r/15.0%
exp-neg15.1%
remove-double-neg15.1%
Simplified15.1%
Taylor expanded in x around 0 13.7%
Taylor expanded in x around 0 8.9%
herbie shell --seed 2024089
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))