
(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 9 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 (log (fmod (exp x) (sqrt (cos x)))))
(t_1 (expm1 (+ x t_0)))
(t_2 (expm1 (- t_0 x))))
(/
(-
(/ 1.0 (- 1.0 (pow t_1 3.0)))
(/ (pow t_1 6.0) (- 1.0 (pow (expm1 (+ x (fabs t_0))) 3.0))))
(+ 1.0 (* t_2 (+ t_2 -1.0))))))
double code(double x) {
double t_0 = log(fmod(exp(x), sqrt(cos(x))));
double t_1 = expm1((x + t_0));
double t_2 = expm1((t_0 - x));
return ((1.0 / (1.0 - pow(t_1, 3.0))) - (pow(t_1, 6.0) / (1.0 - pow(expm1((x + fabs(t_0))), 3.0)))) / (1.0 + (t_2 * (t_2 + -1.0)));
}
def code(x): t_0 = math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) t_1 = math.expm1((x + t_0)) t_2 = math.expm1((t_0 - x)) return ((1.0 / (1.0 - math.pow(t_1, 3.0))) - (math.pow(t_1, 6.0) / (1.0 - math.pow(math.expm1((x + math.fabs(t_0))), 3.0)))) / (1.0 + (t_2 * (t_2 + -1.0)))
function code(x) t_0 = log(rem(exp(x), sqrt(cos(x)))) t_1 = expm1(Float64(x + t_0)) t_2 = expm1(Float64(t_0 - x)) return Float64(Float64(Float64(1.0 / Float64(1.0 - (t_1 ^ 3.0))) - Float64((t_1 ^ 6.0) / Float64(1.0 - (expm1(Float64(x + abs(t_0))) ^ 3.0)))) / Float64(1.0 + Float64(t_2 * Float64(t_2 + -1.0)))) end
code[x_] := Block[{t$95$0 = 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]}, Block[{t$95$1 = N[(Exp[N[(x + t$95$0), $MachinePrecision]] - 1), $MachinePrecision]}, Block[{t$95$2 = N[(Exp[N[(t$95$0 - x), $MachinePrecision]] - 1), $MachinePrecision]}, N[(N[(N[(1.0 / N[(1.0 - N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[t$95$1, 6.0], $MachinePrecision] / N[(1.0 - N[Power[N[(Exp[N[(x + N[Abs[t$95$0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(t$95$2 * N[(t$95$2 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\\
t_1 := \mathsf{expm1}\left(x + t_0\right)\\
t_2 := \mathsf{expm1}\left(t_0 - x\right)\\
\frac{\frac{1}{1 - {t_1}^{3}} - \frac{{t_1}^{6}}{1 - {\left(\mathsf{expm1}\left(x + \left|t_0\right|\right)\right)}^{3}}}{1 + t_2 \cdot \left(t_2 + -1\right)}
\end{array}
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.8%
expm1-udef5.8%
log1p-udef5.8%
add-exp-log5.8%
Applied egg-rr5.8%
associate--l+5.8%
flip3-+5.8%
metadata-eval5.8%
add-exp-log5.8%
expm1-def5.8%
log-div5.8%
add-log-exp5.8%
Applied egg-rr5.9%
*-rgt-identity5.9%
distribute-lft-out--5.9%
Simplified5.9%
flip-+5.9%
metadata-eval5.9%
div-sub5.9%
Applied egg-rr5.5%
add-sqr-sqrt0.0%
sqrt-unprod11.0%
pow211.0%
Applied egg-rr11.0%
unpow211.0%
rem-sqrt-square11.0%
Simplified11.0%
Final simplification11.0%
(FPCore (x) :precision binary64 (let* ((t_0 (expm1 (- (log (fmod (exp x) (sqrt (cos x)))) x)))) (/ (+ 1.0 (pow t_0 3.0)) (+ 1.0 (* t_0 (+ t_0 -1.0))))))
double code(double x) {
double t_0 = expm1((log(fmod(exp(x), sqrt(cos(x)))) - x));
return (1.0 + pow(t_0, 3.0)) / (1.0 + (t_0 * (t_0 + -1.0)));
}
def code(x): t_0 = math.expm1((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x)) return (1.0 + math.pow(t_0, 3.0)) / (1.0 + (t_0 * (t_0 + -1.0)))
function code(x) t_0 = expm1(Float64(log(rem(exp(x), sqrt(cos(x)))) - x)) return Float64(Float64(1.0 + (t_0 ^ 3.0)) / Float64(1.0 + Float64(t_0 * Float64(t_0 + -1.0)))) end
code[x_] := Block[{t$95$0 = 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]] - 1), $MachinePrecision]}, N[(N[(1.0 + N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(t$95$0 * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\\
\frac{1 + {t_0}^{3}}{1 + t_0 \cdot \left(t_0 + -1\right)}
\end{array}
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.8%
expm1-udef5.8%
log1p-udef5.8%
add-exp-log5.8%
Applied egg-rr5.8%
associate--l+5.8%
flip3-+5.8%
metadata-eval5.8%
add-exp-log5.8%
expm1-def5.8%
log-div5.8%
add-log-exp5.8%
Applied egg-rr5.9%
*-rgt-identity5.9%
distribute-lft-out--5.9%
Simplified5.9%
Final simplification5.9%
(FPCore (x) :precision binary64 (let* ((t_0 (expm1 (- (log (fmod (exp x) (sqrt (cos x)))) x)))) (/ (- 1.0 (* t_0 t_0)) (- 1.0 t_0))))
double code(double x) {
double t_0 = expm1((log(fmod(exp(x), sqrt(cos(x)))) - x));
return (1.0 - (t_0 * t_0)) / (1.0 - t_0);
}
def code(x): t_0 = math.expm1((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x)) return (1.0 - (t_0 * t_0)) / (1.0 - t_0)
function code(x) t_0 = expm1(Float64(log(rem(exp(x), sqrt(cos(x)))) - x)) return Float64(Float64(1.0 - Float64(t_0 * t_0)) / Float64(1.0 - t_0)) end
code[x_] := Block[{t$95$0 = 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]] - 1), $MachinePrecision]}, N[(N[(1.0 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{expm1}\left(\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x\right)\\
\frac{1 - t_0 \cdot t_0}{1 - t_0}
\end{array}
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.8%
expm1-udef5.8%
log1p-udef5.8%
add-exp-log5.8%
Applied egg-rr5.8%
associate--l+5.8%
flip-+5.8%
Applied egg-rr5.9%
Final simplification5.9%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (pow (pow (cos x) 1.5) 0.3333333333333333)) (exp x)))
double code(double x) {
return fmod(exp(x), pow(pow(cos(x), 1.5), 0.3333333333333333)) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), ((cos(x) ** 1.5d0) ** 0.3333333333333333d0)) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), math.pow(math.pow(math.cos(x), 1.5), 0.3333333333333333)) / math.exp(x)
function code(x) return Float64(rem(exp(x), ((cos(x) ^ 1.5) ^ 0.3333333333333333)) / 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], 0.3333333333333333], $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({\left({\cos x}^{1.5}\right)}^{0.3333333333333333}\right)\right)}{e^{x}}
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
add-cbrt-cube5.8%
pow1/35.8%
add-sqr-sqrt5.8%
pow15.8%
pow1/25.8%
pow-prod-up5.8%
metadata-eval5.8%
Applied egg-rr5.8%
Final simplification5.8%
(FPCore (x) :precision binary64 (+ (+ 1.0 (/ (fmod (exp x) (sqrt (cos x))) (exp x))) -1.0))
double code(double x) {
return (1.0 + (fmod(exp(x), sqrt(cos(x))) / exp(x))) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (mod(exp(x), sqrt(cos(x))) / exp(x))) + (-1.0d0)
end function
def code(x): return (1.0 + (math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x))) + -1.0
function code(x) return Float64(Float64(1.0 + Float64(rem(exp(x), sqrt(cos(x))) / exp(x))) + -1.0) end
code[x_] := N[(N[(1.0 + 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] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}\right) + -1
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
expm1-log1p-u5.8%
expm1-udef5.8%
log1p-udef5.8%
add-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.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
Final simplification5.8%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 1.0 (* (* x x) -0.25))) (exp x)))
double code(double x) {
return fmod(exp(x), (1.0 + ((x * x) * -0.25))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + ((x * x) * (-0.25d0)))) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + ((x * x) * -0.25))) / math.exp(x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64(Float64(x * x) * -0.25))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.25), $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 + \left(x \cdot x\right) \cdot -0.25\right)\right)}{e^{x}}
\end{array}
Initial program 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
Taylor expanded in x around 0 5.5%
*-commutative5.5%
unpow25.5%
Simplified5.5%
Final simplification5.5%
(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 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
Taylor expanded in x around 0 5.5%
Final simplification5.5%
(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 5.8%
exp-neg5.8%
associate-*r/5.8%
*-rgt-identity5.8%
Simplified5.8%
Taylor expanded in x around 0 5.5%
Taylor expanded in x around 0 5.0%
Final simplification5.0%
herbie shell --seed 2023229
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))