
(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 8 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-310)
(fmod 1.0 (pow (fma -0.5 x 1.0) 2.0))
(if (<= x 50.0)
(fmod
(*
(/
(* (pow (fma -0.5 x -1.0) -1.0) (fma 0.015625 (pow x 6.0) -1.0))
(fma -0.25 (hypot (* (* x x) 0.5) x) 1.0))
x)
(sqrt (cos x)))
(fmod 1.0 1.0))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(1.0, pow(fma(-0.5, x, 1.0), 2.0));
} else if (x <= 50.0) {
tmp = fmod((((pow(fma(-0.5, x, -1.0), -1.0) * fma(0.015625, pow(x, 6.0), -1.0)) / fma(-0.25, hypot(((x * x) * 0.5), x), 1.0)) * x), sqrt(cos(x)));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = rem(1.0, (fma(-0.5, x, 1.0) ^ 2.0)); elseif (x <= 50.0) tmp = rem(Float64(Float64(Float64((fma(-0.5, x, -1.0) ^ -1.0) * fma(0.015625, (x ^ 6.0), -1.0)) / fma(-0.25, hypot(Float64(Float64(x * x) * 0.5), x), 1.0)) * x), sqrt(cos(x))); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[With[{TMP1 = 1.0, TMP2 = N[Power[N[(-0.5 * x + 1.0), $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], If[LessEqual[x, 50.0], N[With[{TMP1 = N[(N[(N[(N[Power[N[(-0.5 * x + -1.0), $MachinePrecision], -1.0], $MachinePrecision] * N[(0.015625 * N[Power[x, 6.0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-0.25 * N[Sqrt[N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 \bmod \left({\left(\mathsf{fma}\left(-0.5, x, 1\right)\right)}^{2}\right)\right)\\
\mathbf{elif}\;x \leq 50:\\
\;\;\;\;\left(\left(\frac{{\left(\mathsf{fma}\left(-0.5, x, -1\right)\right)}^{-1} \cdot \mathsf{fma}\left(0.015625, {x}^{6}, -1\right)}{\mathsf{fma}\left(-0.25, \mathsf{hypot}\left(\left(x \cdot x\right) \cdot 0.5, x\right), 1\right)} \cdot x\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 11.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
Applied rewrites4.0%
Taylor expanded in x around 0
Applied rewrites7.8%
Applied rewrites13.4%
if -4.999999999999985e-310 < x < 50Initial program 6.8%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.8
Applied rewrites6.8%
Taylor expanded in x around 0
Applied rewrites6.8%
Taylor expanded in x around inf
Applied rewrites99.4%
Applied rewrites100.0%
if 50 < x Initial program 0.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f640.0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification61.8%
(FPCore (x)
:precision binary64
(if (<= x -5e-310)
(fmod 1.0 (pow (fma -0.5 x 1.0) 2.0))
(if (<= x 50.0)
(fmod
(*
(/
(fma 0.015625 (pow x 6.0) -1.0)
(* (fma -0.25 (hypot (* (* x x) 0.5) x) 1.0) (fma -0.5 x -1.0)))
x)
(sqrt (cos x)))
(fmod 1.0 1.0))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(1.0, pow(fma(-0.5, x, 1.0), 2.0));
} else if (x <= 50.0) {
tmp = fmod(((fma(0.015625, pow(x, 6.0), -1.0) / (fma(-0.25, hypot(((x * x) * 0.5), x), 1.0) * fma(-0.5, x, -1.0))) * x), sqrt(cos(x)));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = rem(1.0, (fma(-0.5, x, 1.0) ^ 2.0)); elseif (x <= 50.0) tmp = rem(Float64(Float64(fma(0.015625, (x ^ 6.0), -1.0) / Float64(fma(-0.25, hypot(Float64(Float64(x * x) * 0.5), x), 1.0) * fma(-0.5, x, -1.0))) * x), sqrt(cos(x))); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[With[{TMP1 = 1.0, TMP2 = N[Power[N[(-0.5 * x + 1.0), $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], If[LessEqual[x, 50.0], N[With[{TMP1 = N[(N[(N[(0.015625 * N[Power[x, 6.0], $MachinePrecision] + -1.0), $MachinePrecision] / N[(N[(-0.25 * N[Sqrt[N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision] + 1.0), $MachinePrecision] * N[(-0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 \bmod \left({\left(\mathsf{fma}\left(-0.5, x, 1\right)\right)}^{2}\right)\right)\\
\mathbf{elif}\;x \leq 50:\\
\;\;\;\;\left(\left(\frac{\mathsf{fma}\left(0.015625, {x}^{6}, -1\right)}{\mathsf{fma}\left(-0.25, \mathsf{hypot}\left(\left(x \cdot x\right) \cdot 0.5, x\right), 1\right) \cdot \mathsf{fma}\left(-0.5, x, -1\right)} \cdot x\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 11.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
Applied rewrites4.0%
Taylor expanded in x around 0
Applied rewrites7.8%
Applied rewrites13.4%
if -4.999999999999985e-310 < x < 50Initial program 6.8%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.8
Applied rewrites6.8%
Taylor expanded in x around 0
Applied rewrites6.8%
Taylor expanded in x around inf
Applied rewrites99.4%
Applied rewrites100.0%
if 50 < x Initial program 0.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f640.0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification61.8%
(FPCore (x) :precision binary64 (if (<= x -5e-310) (fmod 1.0 (pow (fma -0.5 x 1.0) 2.0)) (if (<= x 50.0) (fmod (* 1.0 x) (sqrt (cos x))) (fmod 1.0 1.0))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = fmod(1.0, pow(fma(-0.5, x, 1.0), 2.0));
} else if (x <= 50.0) {
tmp = fmod((1.0 * x), sqrt(cos(x)));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = rem(1.0, (fma(-0.5, x, 1.0) ^ 2.0)); elseif (x <= 50.0) tmp = rem(Float64(1.0 * x), sqrt(cos(x))); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, -5e-310], N[With[{TMP1 = 1.0, TMP2 = N[Power[N[(-0.5 * x + 1.0), $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], If[LessEqual[x, 50.0], N[With[{TMP1 = N[(1.0 * x), $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(1 \bmod \left({\left(\mathsf{fma}\left(-0.5, x, 1\right)\right)}^{2}\right)\right)\\
\mathbf{elif}\;x \leq 50:\\
\;\;\;\;\left(\left(1 \cdot x\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 11.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
Applied rewrites4.0%
Taylor expanded in x around 0
Applied rewrites7.8%
Applied rewrites13.4%
if -4.999999999999985e-310 < x < 50Initial program 6.8%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.8
Applied rewrites6.8%
Taylor expanded in x around 0
Applied rewrites6.8%
Taylor expanded in x around inf
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites99.4%
if 50 < x Initial program 0.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f640.0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= x 50.0) (fmod 1.0 (pow (fma -0.5 x 1.0) 2.0)) (fmod 1.0 1.0)))
double code(double x) {
double tmp;
if (x <= 50.0) {
tmp = fmod(1.0, pow(fma(-0.5, x, 1.0), 2.0));
} else {
tmp = fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 50.0) tmp = rem(1.0, (fma(-0.5, x, 1.0) ^ 2.0)); else tmp = rem(1.0, 1.0); end return tmp end
code[x_] := If[LessEqual[x, 50.0], N[With[{TMP1 = 1.0, TMP2 = N[Power[N[(-0.5 * x + 1.0), $MachinePrecision], 2.0], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 50:\\
\;\;\;\;\left(1 \bmod \left({\left(\mathsf{fma}\left(-0.5, x, 1\right)\right)}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right)\\
\end{array}
\end{array}
if x < 50Initial program 9.4%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.2
Applied rewrites6.2%
Taylor expanded in x around 0
Applied rewrites4.9%
Taylor expanded in x around 0
Applied rewrites6.9%
Applied rewrites10.4%
if 50 < x Initial program 0.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f640.0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= x -0.9) (fmod 1.0 (fma (* x x) -0.25 1.0)) (* (- 1.0 x) (fmod (+ 1.0 x) 1.0))))
double code(double x) {
double tmp;
if (x <= -0.9) {
tmp = fmod(1.0, fma((x * x), -0.25, 1.0));
} else {
tmp = (1.0 - x) * fmod((1.0 + x), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.9) tmp = rem(1.0, fma(Float64(x * x), -0.25, 1.0)); else tmp = Float64(Float64(1.0 - x) * rem(Float64(1.0 + x), 1.0)); end return tmp end
code[x_] := If[LessEqual[x, -0.9], N[With[{TMP1 = 1.0, TMP2 = N[(N[(x * x), $MachinePrecision] * -0.25 + 1.0), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * N[With[{TMP1 = N[(1.0 + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.9:\\
\;\;\;\;\left(1 \bmod \left(\mathsf{fma}\left(x \cdot x, -0.25, 1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot \left(\left(1 + x\right) \bmod 1\right)\\
\end{array}
\end{array}
if x < -0.900000000000000022Initial program 60.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.9
Applied rewrites5.9%
Taylor expanded in x around 0
Applied rewrites15.2%
Taylor expanded in x around 0
Applied rewrites100.0%
if -0.900000000000000022 < x Initial program 6.6%
Taylor expanded in x around 0
Applied rewrites6.6%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f645.7
Applied rewrites5.7%
Taylor expanded in x around 0
lower-+.f6424.8
Applied rewrites24.8%
Final simplification26.3%
(FPCore (x) :precision binary64 (if (<= x -0.82) (fmod 1.0 (fma (* x x) -0.25 1.0)) (fmod (- x -1.0) 1.0)))
double code(double x) {
double tmp;
if (x <= -0.82) {
tmp = fmod(1.0, fma((x * x), -0.25, 1.0));
} else {
tmp = fmod((x - -1.0), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.82) tmp = rem(1.0, fma(Float64(x * x), -0.25, 1.0)); else tmp = rem(Float64(x - -1.0), 1.0); end return tmp end
code[x_] := If[LessEqual[x, -0.82], N[With[{TMP1 = 1.0, TMP2 = N[(N[(x * x), $MachinePrecision] * -0.25 + 1.0), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision], N[With[{TMP1 = N[(x - -1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.82:\\
\;\;\;\;\left(1 \bmod \left(\mathsf{fma}\left(x \cdot x, -0.25, 1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x - -1\right) \bmod 1\right)\\
\end{array}
\end{array}
if x < -0.819999999999999951Initial program 60.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.9
Applied rewrites5.9%
Taylor expanded in x around 0
Applied rewrites15.2%
Taylor expanded in x around 0
Applied rewrites100.0%
if -0.819999999999999951 < x Initial program 6.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites24.1%
(FPCore (x) :precision binary64 (fmod (- x -1.0) 1.0))
double code(double x) {
return fmod((x - -1.0), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((x - (-1.0d0)), 1.0d0)
end function
def code(x): return math.fmod((x - -1.0), 1.0)
function code(x) return rem(Float64(x - -1.0), 1.0) end
code[x_] := N[With[{TMP1 = N[(x - -1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - -1\right) \bmod 1\right)
\end{array}
Initial program 7.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites23.7%
(FPCore (x) :precision binary64 (fmod 1.0 1.0))
double code(double x) {
return fmod(1.0, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(1.0d0, 1.0d0)
end function
def code(x): return math.fmod(1.0, 1.0)
function code(x) return rem(1.0, 1.0) end
code[x_] := N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(1 \bmod 1\right)
\end{array}
Initial program 7.6%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f645.0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites5.0%
Taylor expanded in x around 0
Applied rewrites22.7%
herbie shell --seed 2024249
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))