
(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 (let* ((t_0 (sqrt (/ (fmod (exp x) (sqrt (cos x))) (exp x))))) (fma (+ t_0 1.0) (+ t_0 -1.0) 1.0)))
double code(double x) {
double t_0 = sqrt((fmod(exp(x), sqrt(cos(x))) / exp(x)));
return fma((t_0 + 1.0), (t_0 + -1.0), 1.0);
}
function code(x) t_0 = sqrt(Float64(rem(exp(x), sqrt(cos(x))) / exp(x))) return fma(Float64(t_0 + 1.0), Float64(t_0 + -1.0), 1.0) end
code[x_] := Block[{t$95$0 = N[Sqrt[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]], $MachinePrecision]}, N[(N[(t$95$0 + 1.0), $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}\\
\mathsf{fma}\left(t_0 + 1, t_0 + -1, 1\right)
\end{array}
\end{array}
Initial program 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
add-cbrt-cube6.8%
pow1/36.8%
add-sqr-sqrt6.8%
pow16.8%
pow1/26.8%
pow-prod-up6.8%
metadata-eval6.8%
Applied egg-rr6.8%
unpow1/36.8%
Simplified6.8%
pow1/36.8%
pow-pow6.8%
metadata-eval6.8%
pow1/26.8%
expm1-log1p-u6.8%
expm1-udef6.8%
log1p-udef6.8%
add-exp-log6.8%
associate--l+6.8%
+-commutative6.8%
add-sqr-sqrt6.8%
difference-of-sqr-16.8%
Applied egg-rr6.8%
Final simplification6.8%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (cbrt (pow (cos x) 1.5))) (exp x)))
double code(double x) {
return fmod(exp(x), cbrt(pow(cos(x), 1.5))) / exp(x);
}
function code(x) return Float64(rem(exp(x), cbrt((cos(x) ^ 1.5))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], 1.5], $MachinePrecision], 1/3], $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[3]{{\cos x}^{1.5}}\right)\right)}{e^{x}}
\end{array}
Initial program 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
add-cbrt-cube6.8%
pow1/36.8%
add-sqr-sqrt6.8%
pow16.8%
pow1/26.8%
pow-prod-up6.8%
metadata-eval6.8%
Applied egg-rr6.8%
unpow1/36.8%
Simplified6.8%
Final simplification6.8%
(FPCore (x) :precision binary64 (+ (+ (/ (fmod (exp x) (sqrt (cos x))) (exp x)) 1.0) -1.0))
double code(double x) {
return ((fmod(exp(x), sqrt(cos(x))) / exp(x)) + 1.0) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((mod(exp(x), sqrt(cos(x))) / exp(x)) + 1.0d0) + (-1.0d0)
end function
def code(x): return ((math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x)) + 1.0) + -1.0
function code(x) return Float64(Float64(Float64(rem(exp(x), sqrt(cos(x))) / exp(x)) + 1.0) + -1.0) end
code[x_] := N[(N[(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] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} + 1\right) + -1
\end{array}
Initial program 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
expm1-log1p-u6.8%
expm1-udef6.8%
log1p-udef6.8%
add-exp-log6.8%
Applied egg-rr6.8%
Final simplification6.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 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
Final simplification6.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 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
Taylor expanded in x around 0 6.6%
Final simplification6.6%
(FPCore (x) :precision binary64 (/ (+ 1.0 (* x x)) (/ (+ x 1.0) (fmod (exp x) 1.0))))
double code(double x) {
return (1.0 + (x * x)) / ((x + 1.0) / fmod(exp(x), 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (x * x)) / ((x + 1.0d0) / mod(exp(x), 1.0d0))
end function
def code(x): return (1.0 + (x * x)) / ((x + 1.0) / math.fmod(math.exp(x), 1.0))
function code(x) return Float64(Float64(1.0 + Float64(x * x)) / Float64(Float64(x + 1.0) / rem(exp(x), 1.0))) end
code[x_] := N[(N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] / N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 + x \cdot x}{\frac{x + 1}{\left(\left(e^{x}\right) \bmod 1\right)}}
\end{array}
Initial program 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
Taylor expanded in x around 0 6.6%
Taylor expanded in x around 0 5.7%
+-commutative5.7%
*-lft-identity5.7%
associate-*r*5.7%
neg-mul-15.7%
distribute-rgt-out5.7%
Simplified5.7%
flip-+5.7%
associate-*r/5.7%
metadata-eval5.7%
sub-neg5.7%
add-sqr-sqrt3.1%
sqrt-unprod5.8%
sqr-neg5.8%
sqrt-unprod2.6%
add-sqr-sqrt5.8%
distribute-rgt-neg-out5.8%
sqr-neg5.8%
neg-sub05.8%
metadata-eval5.8%
associate--r-5.8%
metadata-eval5.8%
metadata-eval5.8%
Applied egg-rr5.8%
*-commutative5.8%
associate-/l*5.8%
+-commutative5.8%
Simplified5.8%
Final simplification5.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 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
Taylor expanded in x around 0 6.6%
Taylor expanded in x around 0 5.7%
+-commutative5.7%
*-lft-identity5.7%
associate-*r*5.7%
neg-mul-15.7%
distribute-rgt-out5.7%
Simplified5.7%
Taylor expanded in x around 0 5.7%
+-commutative5.7%
mul-1-neg5.7%
*-commutative5.7%
sub-neg5.7%
*-rgt-identity5.7%
distribute-lft-out--5.7%
Simplified5.7%
Final simplification5.7%
(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 6.8%
exp-neg6.8%
associate-*r/6.8%
*-rgt-identity6.8%
Simplified6.8%
Taylor expanded in x around 0 6.6%
Taylor expanded in x around 0 5.1%
Final simplification5.1%
herbie shell --seed 2023293
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))