
(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
(if (<= (* (exp (- x)) (fmod (exp x) (sqrt (cos x)))) 0.2)
(*
(fma (fma 0.5 x -1.0) x 1.0)
(fmod (fma (fma 0.16666666666666666 x 0.5) (* x x) x) 1.0))
(* (- 1.0 x) (fmod (+ 1.0 x) 1.0))))
double code(double x) {
double tmp;
if ((exp(-x) * fmod(exp(x), sqrt(cos(x)))) <= 0.2) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod(fma(fma(0.16666666666666666, x, 0.5), (x * x), x), 1.0);
} else {
tmp = (1.0 - x) * fmod((1.0 + x), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(exp(Float64(-x)) * rem(exp(x), sqrt(cos(x)))) <= 0.2) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(fma(fma(0.16666666666666666, x, 0.5), Float64(x * x), x), 1.0)); else tmp = Float64(Float64(1.0 - x) * rem(Float64(1.0 + x), 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], 0.2], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \leq 0.2:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x \cdot x, x\right)\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot \left(\left(1 + x\right) \bmod 1\right)\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 0.20000000000000001Initial program 5.7%
Taylor expanded in x around 0
Applied rewrites4.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f644.7
Applied rewrites4.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f644.7
Applied rewrites4.7%
Taylor expanded in x around inf
Applied rewrites43.1%
if 0.20000000000000001 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 10.3%
Taylor expanded in x around 0
Applied rewrites10.3%
Taylor expanded in x around 0
Applied rewrites7.3%
Taylor expanded in x around 0
lower-+.f6493.5
Applied rewrites93.5%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6496.5
Applied rewrites96.5%
Final simplification55.2%
(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 6.8%
Taylor expanded in x around 0
Applied rewrites6.0%
Taylor expanded in x around 0
Applied rewrites5.3%
Taylor expanded in x around 0
lower-+.f6424.9
Applied rewrites24.9%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f6425.5
Applied rewrites25.5%
Final simplification25.5%
(FPCore (x) :precision binary64 (* 1.0 (fmod (+ 1.0 x) 1.0)))
double code(double x) {
return 1.0 * fmod((1.0 + x), 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 * mod((1.0d0 + x), 1.0d0)
end function
def code(x): return 1.0 * math.fmod((1.0 + x), 1.0)
function code(x) return Float64(1.0 * rem(Float64(1.0 + x), 1.0)) end
code[x_] := N[(1.0 * N[With[{TMP1 = N[(1.0 + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot \left(\left(1 + x\right) \bmod 1\right)
\end{array}
Initial program 6.8%
Taylor expanded in x around 0
Applied rewrites6.0%
Taylor expanded in x around 0
Applied rewrites5.3%
Taylor expanded in x around 0
lower-+.f6424.9
Applied rewrites24.9%
Final simplification24.9%
(FPCore (x) :precision binary64 (* (fmod 1.0 1.0) 1.0))
double code(double x) {
return fmod(1.0, 1.0) * 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(1.0d0, 1.0d0) * 1.0d0
end function
def code(x): return math.fmod(1.0, 1.0) * 1.0
function code(x) return Float64(rem(1.0, 1.0) * 1.0) end
code[x_] := N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 \bmod 1\right) \cdot 1
\end{array}
Initial program 6.8%
Taylor expanded in x around 0
Applied rewrites23.3%
Taylor expanded in x around 0
Applied rewrites23.1%
Taylor expanded in x around 0
Applied rewrites23.2%
herbie shell --seed 2024243
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))