
(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 6 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))) 2.0)))) (/ (+ (fma t_0 t_0 -1.0) -1.0) (exp x))))
double code(double x) {
double t_0 = sqrt((fmod(exp(x), sqrt(cos(x))) + 2.0));
return (fma(t_0, t_0, -1.0) + -1.0) / exp(x);
}
function code(x) t_0 = sqrt(Float64(rem(exp(x), sqrt(cos(x))) + 2.0)) return Float64(Float64(fma(t_0, t_0, -1.0) + -1.0) / exp(x)) 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] + 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(t$95$0 * t$95$0 + -1.0), $MachinePrecision] + -1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + 2}\\
\frac{\mathsf{fma}\left(t_0, t_0, -1\right) + -1}{e^{x}}
\end{array}
\end{array}
Initial program 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.7%
expm1-udef5.8%
log1p-udef5.8%
rem-exp-log5.8%
Applied egg-rr5.8%
expm1-log1p-u5.8%
expm1-udef5.7%
log1p-udef5.7%
+-commutative5.7%
add-exp-log5.7%
add-sqr-sqrt8.5%
fma-neg8.5%
Applied egg-rr8.5%
Final simplification8.5%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (+ (fmod (exp x) (sqrt (cos x))) 2.0)))) (/ (fma t_0 t_0 -2.0) (exp x))))
double code(double x) {
double t_0 = sqrt((fmod(exp(x), sqrt(cos(x))) + 2.0));
return fma(t_0, t_0, -2.0) / exp(x);
}
function code(x) t_0 = sqrt(Float64(rem(exp(x), sqrt(cos(x))) + 2.0)) return Float64(fma(t_0, t_0, -2.0) / exp(x)) 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] + 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0 + -2.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + 2}\\
\frac{\mathsf{fma}\left(t_0, t_0, -2\right)}{e^{x}}
\end{array}
\end{array}
Initial program 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.7%
expm1-udef5.8%
log1p-udef5.8%
rem-exp-log5.8%
Applied egg-rr5.8%
expm1-log1p-u5.8%
expm1-udef5.7%
log1p-udef5.7%
+-commutative5.7%
add-exp-log5.7%
add-sqr-sqrt8.5%
fma-neg8.5%
Applied egg-rr8.5%
fma-udef8.5%
difference-of-sqr--18.5%
Applied egg-rr8.5%
difference-of-sqr--18.5%
add-sqr-sqrt5.7%
associate--l+5.7%
metadata-eval5.7%
add-sqr-sqrt8.5%
fma-def8.5%
Applied egg-rr8.5%
Final simplification8.5%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (+ (fmod (exp x) (sqrt (cos x))) 2.0)))) (/ (+ (* (+ t_0 1.0) (+ t_0 -1.0)) -1.0) (exp x))))
double code(double x) {
double t_0 = sqrt((fmod(exp(x), sqrt(cos(x))) + 2.0));
return (((t_0 + 1.0) * (t_0 + -1.0)) + -1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sqrt((mod(exp(x), sqrt(cos(x))) + 2.0d0))
code = (((t_0 + 1.0d0) * (t_0 + (-1.0d0))) + (-1.0d0)) / exp(x)
end function
def code(x): t_0 = math.sqrt((math.fmod(math.exp(x), math.sqrt(math.cos(x))) + 2.0)) return (((t_0 + 1.0) * (t_0 + -1.0)) + -1.0) / math.exp(x)
function code(x) t_0 = sqrt(Float64(rem(exp(x), sqrt(cos(x))) + 2.0)) return Float64(Float64(Float64(Float64(t_0 + 1.0) * Float64(t_0 + -1.0)) + -1.0) / exp(x)) 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] + 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(t$95$0 + 1.0), $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + 2}\\
\frac{\left(t_0 + 1\right) \cdot \left(t_0 + -1\right) + -1}{e^{x}}
\end{array}
\end{array}
Initial program 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.7%
expm1-udef5.8%
log1p-udef5.8%
rem-exp-log5.8%
Applied egg-rr5.8%
expm1-log1p-u5.8%
expm1-udef5.7%
log1p-udef5.7%
+-commutative5.7%
add-exp-log5.7%
add-sqr-sqrt8.5%
fma-neg8.5%
Applied egg-rr8.5%
fma-udef8.5%
difference-of-sqr--18.5%
Applied egg-rr8.5%
Final simplification8.5%
(FPCore (x) :precision binary64 (/ (log (exp (fmod (exp x) (sqrt (cos x))))) (exp x)))
double code(double x) {
return log(exp(fmod(exp(x), sqrt(cos(x))))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = log(exp(mod(exp(x), sqrt(cos(x))))) / exp(x)
end function
def code(x): return math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))) / math.exp(x)
function code(x) return Float64(log(exp(rem(exp(x), sqrt(cos(x))))) / exp(x)) end
code[x_] := N[(N[Log[N[Exp[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}}
\end{array}
Initial program 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
add-log-exp5.8%
Applied egg-rr5.8%
Final simplification5.8%
(FPCore (x) :precision binary64 (/ (+ (+ (fmod (exp x) (sqrt (cos x))) 1.0) -1.0) (exp x)))
double code(double x) {
return ((fmod(exp(x), sqrt(cos(x))) + 1.0) + -1.0) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((mod(exp(x), sqrt(cos(x))) + 1.0d0) + (-1.0d0)) / exp(x)
end function
def code(x): return ((math.fmod(math.exp(x), math.sqrt(math.cos(x))) + 1.0) + -1.0) / math.exp(x)
function code(x) return Float64(Float64(Float64(rem(exp(x), sqrt(cos(x))) + 1.0) + -1.0) / exp(x)) 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] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) + 1\right) + -1}{e^{x}}
\end{array}
Initial program 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.7%
expm1-udef5.8%
log1p-udef5.8%
rem-exp-log5.8%
Applied egg-rr5.8%
Final simplification5.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 5.7%
exp-neg5.7%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
Final simplification5.8%
herbie shell --seed 2023318
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))