
(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 (let* ((t_0 (fmod (exp x) (sqrt (cos x))))) (if (<= (* (exp (- x)) t_0) 2.0) (/ t_0 (exp x)) (* 1.0 (fmod 1.0 1.0)))))
double code(double x) {
double t_0 = fmod(exp(x), sqrt(cos(x)));
double tmp;
if ((exp(-x) * t_0) <= 2.0) {
tmp = t_0 / exp(x);
} else {
tmp = 1.0 * fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = mod(exp(x), sqrt(cos(x)))
if ((exp(-x) * t_0) <= 2.0d0) then
tmp = t_0 / exp(x)
else
tmp = 1.0d0 * mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): t_0 = math.fmod(math.exp(x), math.sqrt(math.cos(x))) tmp = 0 if (math.exp(-x) * t_0) <= 2.0: tmp = t_0 / math.exp(x) else: tmp = 1.0 * math.fmod(1.0, 1.0) return tmp
function code(x) t_0 = rem(exp(x), sqrt(cos(x))) tmp = 0.0 if (Float64(exp(Float64(-x)) * t_0) <= 2.0) tmp = Float64(t_0 / exp(x)); else tmp = Float64(1.0 * rem(1.0, 1.0)); 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[(N[Exp[(-x)], $MachinePrecision] * t$95$0), $MachinePrecision], 2.0], N[(t$95$0 / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;e^{-x} \cdot t\_0 \leq 2:\\
\;\;\;\;\frac{t\_0}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(1 \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.1%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
un-div-invN/A
lower-/.f649.1
Applied rewrites9.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Final simplification27.2%
(FPCore (x) :precision binary64 (let* ((t_0 (* (exp (- x)) (fmod (exp x) (sqrt (cos x)))))) (if (<= t_0 2.0) t_0 (* 1.0 (fmod 1.0 1.0)))))
double code(double x) {
double t_0 = exp(-x) * fmod(exp(x), sqrt(cos(x)));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = 1.0 * fmod(1.0, 1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x) * mod(exp(x), sqrt(cos(x)))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = 1.0d0 * mod(1.0d0, 1.0d0)
end if
code = tmp
end function
def code(x): t_0 = math.exp(-x) * math.fmod(math.exp(x), math.sqrt(math.cos(x))) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = 1.0 * math.fmod(1.0, 1.0) return tmp
function code(x) t_0 = Float64(exp(Float64(-x)) * rem(exp(x), sqrt(cos(x)))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(1.0 * rem(1.0, 1.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Exp[(-x)], $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(1 \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Final simplification27.2%
(FPCore (x)
:precision binary64
(if (<= (* (exp (- x)) (fmod (exp x) (sqrt (cos x)))) 2.0)
(/
1.0
(/
(exp x)
(fmod
(exp x)
(sqrt
(fma
(fma
(fma -0.001388888888888889 (* x x) 0.041666666666666664)
(* x x)
-0.5)
(* x x)
1.0)))))
(* 1.0 (fmod 1.0 1.0))))
double code(double x) {
double tmp;
if ((exp(-x) * fmod(exp(x), sqrt(cos(x)))) <= 2.0) {
tmp = 1.0 / (exp(x) / fmod(exp(x), sqrt(fma(fma(fma(-0.001388888888888889, (x * x), 0.041666666666666664), (x * x), -0.5), (x * x), 1.0))));
} else {
tmp = 1.0 * fmod(1.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(exp(Float64(-x)) * rem(exp(x), sqrt(cos(x)))) <= 2.0) tmp = Float64(1.0 / Float64(exp(x) / rem(exp(x), sqrt(fma(fma(fma(-0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), -0.5), Float64(x * x), 1.0))))); else tmp = Float64(1.0 * rem(1.0, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[Exp[(-x)], $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], 2.0], N[(1.0 / N[(N[Exp[x], $MachinePrecision] / N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[(N[(N[(-0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2:\\
\;\;\;\;\frac{1}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right), x \cdot x, 1\right)}\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(1 \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f648.7
Applied rewrites8.7%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
un-div-invN/A
clear-numN/A
lower-/.f64N/A
lower-/.f648.7
Applied rewrites8.7%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Final simplification26.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (* t_0 (fmod (exp x) (sqrt (cos x)))) 2.0)
(*
(fmod
(exp x)
(sqrt
(fma
(fma
(fma -0.001388888888888889 (* x x) 0.041666666666666664)
(* x x)
-0.5)
(* x x)
1.0)))
t_0)
(* 1.0 (fmod 1.0 1.0)))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if ((t_0 * fmod(exp(x), sqrt(cos(x)))) <= 2.0) {
tmp = fmod(exp(x), sqrt(fma(fma(fma(-0.001388888888888889, (x * x), 0.041666666666666664), (x * x), -0.5), (x * x), 1.0))) * t_0;
} else {
tmp = 1.0 * fmod(1.0, 1.0);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(t_0 * rem(exp(x), sqrt(cos(x)))) <= 2.0) tmp = Float64(rem(exp(x), sqrt(fma(fma(fma(-0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), -0.5), Float64(x * x), 1.0))) * t_0); else tmp = Float64(1.0 * rem(1.0, 1.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(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]), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[(N[(N[(-0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$0), $MachinePrecision], N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;t\_0 \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 2:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right), x \cdot x, 1\right)}\right)\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(1 \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f648.7
Applied rewrites8.7%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
Final simplification26.9%
(FPCore (x) :precision binary64 (* (- 1.0 x) (fmod (+ 1.0 x) 1.0)))
double code(double x) {
return (1.0 - x) * fmod((1.0 + x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - x) * mod((1.0d0 + x), 1.0d0)
end function
def code(x): return (1.0 - x) * math.fmod((1.0 + x), 1.0)
function code(x) return Float64(Float64(1.0 - x) * rem(Float64(1.0 + x), 1.0)) end
code[x_] := 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}
\\
\left(1 - x\right) \cdot \left(\left(1 + x\right) \bmod 1\right)
\end{array}
Initial program 7.3%
Taylor expanded in x around 0
Applied rewrites6.3%
Taylor expanded in x around 0
Applied rewrites5.8%
Taylor expanded in x around 0
lower-+.f6425.0
Applied rewrites25.0%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6425.3
Applied rewrites25.3%
Final simplification25.3%
(FPCore (x) :precision binary64 (* (fmod (+ 1.0 x) 1.0) 1.0))
double code(double x) {
return fmod((1.0 + x), 1.0) * 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((1.0d0 + x), 1.0d0) * 1.0d0
end function
def code(x): return math.fmod((1.0 + x), 1.0) * 1.0
function code(x) return Float64(rem(Float64(1.0 + x), 1.0) * 1.0) end
code[x_] := N[(N[With[{TMP1 = N[(1.0 + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(1 + x\right) \bmod 1\right) \cdot 1
\end{array}
Initial program 7.3%
Taylor expanded in x around 0
Applied rewrites6.3%
Taylor expanded in x around 0
Applied rewrites5.8%
Taylor expanded in x around 0
lower-+.f6425.0
Applied rewrites25.0%
(FPCore (x) :precision binary64 (* 1.0 (fmod 1.0 1.0)))
double code(double x) {
return 1.0 * fmod(1.0, 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 * mod(1.0d0, 1.0d0)
end function
def code(x): return 1.0 * math.fmod(1.0, 1.0)
function code(x) return Float64(1.0 * rem(1.0, 1.0)) end
code[x_] := N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot \left(1 \bmod 1\right)
\end{array}
Initial program 7.3%
Taylor expanded in x around 0
Applied rewrites23.5%
Taylor expanded in x around 0
Applied rewrites23.2%
Taylor expanded in x around 0
Applied rewrites23.2%
Final simplification23.2%
herbie shell --seed 2024268
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))