
(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 4 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 (* (fmod (exp x) (sqrt (cos x))) (+ (- 1.0 x) (* 0.5 (pow x 2.0)))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * ((1.0 - x) + (0.5 * pow(x, 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * ((1.0d0 - x) + (0.5d0 * (x ** 2.0d0)))
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * ((1.0 - x) + (0.5 * math.pow(x, 2.0)))
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * Float64(Float64(1.0 - x) + Float64(0.5 * (x ^ 2.0)))) 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[(N[(1.0 - x), $MachinePrecision] + N[(0.5 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(\left(1 - x\right) + 0.5 \cdot {x}^{2}\right)
\end{array}
Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
Taylor expanded in x around 0 5.1%
+-commutative5.1%
associate-+r+5.1%
+-commutative5.1%
*-lft-identity5.1%
associate-*r*5.1%
neg-mul-15.1%
distribute-rgt-out5.1%
Simplified5.1%
Final simplification5.1%
(FPCore (x) :precision binary64 (+ (+ 1.0 (* (fmod (exp x) (sqrt (cos x))) (- 1.0 x))) -1.0))
double code(double x) {
return (1.0 + (fmod(exp(x), sqrt(cos(x))) * (1.0 - x))) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (mod(exp(x), sqrt(cos(x))) * (1.0d0 - x))) + (-1.0d0)
end function
def code(x): return (1.0 + (math.fmod(math.exp(x), math.sqrt(math.cos(x))) * (1.0 - x))) + -1.0
function code(x) return Float64(Float64(1.0 + Float64(rem(exp(x), sqrt(cos(x))) * Float64(1.0 - 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[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)\right) + -1
\end{array}
Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
Taylor expanded in x around 0 5.0%
+-commutative5.0%
mul-1-neg5.0%
unsub-neg5.0%
*-lft-identity5.0%
distribute-rgt-out--5.0%
Simplified5.0%
add-log-exp5.0%
add-sqr-sqrt5.0%
log-prod5.0%
Applied egg-rr5.0%
count-25.0%
Simplified5.0%
pow1/25.0%
pow-exp5.0%
Applied egg-rr5.0%
*-commutative5.0%
rem-log-exp5.0%
associate-*l*5.0%
metadata-eval5.0%
associate-*r*5.0%
*-un-lft-identity5.0%
expm1-log1p-u5.0%
expm1-define5.0%
log1p-undefine5.0%
rem-exp-log5.0%
Applied egg-rr5.0%
Final simplification5.0%
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (- 1.0 x)))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * (1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x))) * (1.0d0 - x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * (1.0 - x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * Float64(1.0 - 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[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \left(1 - x\right)
\end{array}
Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
Taylor expanded in x around 0 5.0%
+-commutative5.0%
mul-1-neg5.0%
unsub-neg5.0%
*-lft-identity5.0%
distribute-rgt-out--5.0%
Simplified5.0%
Final simplification5.0%
(FPCore (x) :precision binary64 (fmod (exp x) (sqrt (cos x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), sqrt(cos(x)))
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x)))
function code(x) return rem(exp(x), sqrt(cos(x))) end
code[x_] := N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)
\end{array}
Initial program 5.0%
/-rgt-identity5.0%
associate-/r/5.0%
exp-neg5.0%
remove-double-neg5.0%
Simplified5.0%
Taylor expanded in x around 0 4.6%
Final simplification4.6%
herbie shell --seed 2024040
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))