
(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 11 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 (<= x -4e-310)
(*
1.0
(fmod
1.0
(*
(*
(* (pow (+ (cos (* 2.0 x)) 1.0) 0.25) (pow 0.5 0.125))
(pow 0.5 0.0625))
(pow 0.5 0.0625))))
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = 1.0 * fmod(1.0, (((pow((cos((2.0 * x)) + 1.0), 0.25) * pow(0.5, 0.125)) * pow(0.5, 0.0625)) * pow(0.5, 0.0625)));
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(1.0 * rem(1.0, Float64(Float64(Float64((Float64(cos(Float64(2.0 * x)) + 1.0) ^ 0.25) * (0.5 ^ 0.125)) * (0.5 ^ 0.0625)) * (0.5 ^ 0.0625)))); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(1.0 * N[With[{TMP1 = 1.0, TMP2 = N[(N[(N[(N[Power[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision], 0.25], $MachinePrecision] * N[Power[0.5, 0.125], $MachinePrecision]), $MachinePrecision] * N[Power[0.5, 0.0625], $MachinePrecision]), $MachinePrecision] * N[Power[0.5, 0.0625], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1 \cdot \left(1 \bmod \left(\left(\left({\left(\cos \left(2 \cdot x\right) + 1\right)}^{0.25} \cdot {0.5}^{0.125}\right) \cdot {0.5}^{0.0625}\right) \cdot {0.5}^{0.0625}\right)\right)\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites3.5%
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
metadata-evalN/A
lift-*.f64N/A
lift-cos.f64N/A
distribute-lft-inN/A
lift-+.f64N/A
pow-prod-downN/A
sqr-powN/A
lift-pow.f64N/A
associate-*l*N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites96.1%
Taylor expanded in x around 0
Applied rewrites96.5%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification98.5%
(FPCore (x) :precision binary64 (if (<= (* (fmod (exp x) (sqrt (cos x))) (exp (- x))) 2e-10) (* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0)) (* (- 1.0 x) (fmod (+ 1.0 x) 1.0))))
double code(double x) {
double tmp;
if ((fmod(exp(x), sqrt(cos(x))) * exp(-x)) <= 2e-10) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = (1.0 - x) * fmod((1.0 + x), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) <= 2e-10) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * 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[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], 2e-10], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $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}\;\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \leq 2 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\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))) < 2.00000000000000007e-10Initial program 4.9%
Taylor expanded in x around 0
Applied rewrites4.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f644.9
Applied rewrites4.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f644.9
Applied rewrites4.9%
Taylor expanded in x around inf
Applied rewrites53.7%
if 2.00000000000000007e-10 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 10.2%
Taylor expanded in x around 0
Applied rewrites10.2%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f646.8
Applied rewrites6.8%
Taylor expanded in x around 0
lower-+.f6491.6
Applied rewrites91.6%
Final simplification62.4%
(FPCore (x)
:precision binary64
(if (<= x -4e-310)
(* (exp (- x)) (fmod (exp x) (* (pow 0.5 0.25) (pow 2.0 0.25))))
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = exp(-x) * fmod(exp(x), (pow(0.5, 0.25) * pow(2.0, 0.25)));
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(exp(Float64(-x)) * rem(exp(x), Float64((0.5 ^ 0.25) * (2.0 ^ 0.25)))); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(N[Exp[(-x)], $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Power[0.5, 0.25], $MachinePrecision] * N[Power[2.0, 0.25], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;e^{-x} \cdot \left(\left(e^{x}\right) \bmod \left({0.5}^{0.25} \cdot {2}^{0.25}\right)\right)\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
pow-prod-downN/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
div-invN/A
metadata-evalN/A
unpow-prod-downN/A
lower-*.f64N/A
Applied rewrites15.3%
Taylor expanded in x around 0
Applied rewrites15.3%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification67.1%
(FPCore (x)
:precision binary64
(if (<= x -4e-310)
(* (fmod (exp x) (* (pow 0.5 0.25) (pow 2.0 0.25))) 1.0)
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = fmod(exp(x), (pow(0.5, 0.25) * pow(2.0, 0.25))) * 1.0;
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(rem(exp(x), Float64((0.5 ^ 0.25) * (2.0 ^ 0.25))) * 1.0); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[Power[0.5, 0.25], $MachinePrecision] * N[Power[2.0, 0.25], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod \left({0.5}^{0.25} \cdot {2}^{0.25}\right)\right) \cdot 1\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
pow-prod-downN/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
div-invN/A
metadata-evalN/A
unpow-prod-downN/A
lower-*.f64N/A
Applied rewrites15.3%
Taylor expanded in x around 0
Applied rewrites15.3%
Taylor expanded in x around 0
Applied rewrites12.2%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification65.9%
(FPCore (x)
:precision binary64
(if (<= x -4e-310)
(* (fmod (exp x) 1.0) (exp (- x)))
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = fmod(exp(x), 1.0) * exp(-x);
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(rem(exp(x), 1.0) * exp(Float64(-x))); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\left(\left(e^{x}\right) \bmod 1\right) \cdot e^{-x}\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites9.0%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification64.7%
(FPCore (x)
:precision binary64
(if (<= x -4e-310)
(*
(fma (fma (fma -0.16666666666666666 x 0.5) x -1.0) x 1.0)
(fmod (exp x) 1.0))
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = fma(fma(fma(-0.16666666666666666, x, 0.5), x, -1.0), x, 1.0) * fmod(exp(x), 1.0);
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(fma(fma(fma(-0.16666666666666666, x, 0.5), x, -1.0), x, 1.0) * rem(exp(x), 1.0)); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right), x, -1\right), x, 1\right) \cdot \left(\left(e^{x}\right) \bmod 1\right)\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites9.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f648.2
Applied rewrites8.2%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification64.4%
(FPCore (x)
:precision binary64
(if (<= x -4e-310)
(*
(fmod (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0) 1.0)
(fma (fma (fma -0.16666666666666666 x 0.5) x -1.0) x 1.0))
(if (<= x 0.04)
(* (fma (fma 0.5 x -1.0) x 1.0) (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = fmod(fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0), 1.0) * fma(fma(fma(-0.16666666666666666, x, 0.5), x, -1.0), x, 1.0);
} else if (x <= 0.04) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(rem(fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0), 1.0) * fma(fma(fma(-0.16666666666666666, x, 0.5), x, -1.0), x, 1.0)); elseif (x <= 0.04) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := If[LessEqual[x, -4e-310], N[(N[With[{TMP1 = N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.04], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)\right) \bmod 1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right), x, -1\right), x, 1\right)\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites9.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f648.2
Applied rewrites8.2%
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.f648.1
Applied rewrites8.1%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification64.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma (fma 0.5 x -1.0) x 1.0)))
(if (<= x -4e-310)
(* (fmod (fma (fma 0.5 x 1.0) x 1.0) 1.0) t_0)
(if (<= x 0.04)
(* t_0 (fmod (* (fma 0.5 x 1.0) x) 1.0))
(* (fmod 1.0 1.0) 1.0)))))
double code(double x) {
double t_0 = fma(fma(0.5, x, -1.0), x, 1.0);
double tmp;
if (x <= -4e-310) {
tmp = fmod(fma(fma(0.5, x, 1.0), x, 1.0), 1.0) * t_0;
} else if (x <= 0.04) {
tmp = t_0 * fmod((fma(0.5, x, 1.0) * x), 1.0);
} else {
tmp = fmod(1.0, 1.0) * 1.0;
}
return tmp;
}
function code(x) t_0 = fma(fma(0.5, x, -1.0), x, 1.0) tmp = 0.0 if (x <= -4e-310) tmp = Float64(rem(fma(fma(0.5, x, 1.0), x, 1.0), 1.0) * t_0); elseif (x <= 0.04) tmp = Float64(t_0 * rem(Float64(fma(0.5, x, 1.0) * x), 1.0)); else tmp = Float64(rem(1.0, 1.0) * 1.0); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]}, If[LessEqual[x, -4e-310], N[(N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[x, 0.04], N[(t$95$0 * N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right)\\
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)\right) \bmod 1\right) \cdot t\_0\\
\mathbf{elif}\;x \leq 0.04:\\
\;\;\;\;t\_0 \cdot \left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \bmod 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod 1\right) \cdot 1\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites9.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f647.8
Applied rewrites7.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f648.1
Applied rewrites8.1%
if -3.999999999999988e-310 < x < 0.0400000000000000008Initial program 6.5%
Taylor expanded in x around 0
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f646.5
Applied rewrites6.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 0.0400000000000000008 < x Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Final simplification64.3%
(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.1%
Taylor expanded in x around 0
Applied rewrites6.1%
Taylor expanded in x around 0
neg-mul-1N/A
unsub-negN/A
lower--.f645.3
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 x) 1.0) 1.0))
double code(double x) {
return fmod((1.0 + x), 1.0) * 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod((1.0d0 + x), 1.0d0) * 1.0d0
end function
def code(x): return math.fmod((1.0 + x), 1.0) * 1.0
function code(x) return Float64(rem(Float64(1.0 + x), 1.0) * 1.0) end
code[x_] := N[(N[With[{TMP1 = N[(1.0 + x), $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(1 + x\right) \bmod 1\right) \cdot 1
\end{array}
Initial program 6.1%
Taylor expanded in x around 0
Applied rewrites6.1%
Taylor expanded in x around 0
Applied rewrites4.9%
Taylor expanded in x around 0
lower-+.f6424.5
Applied rewrites24.5%
(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.1%
Taylor expanded in x around 0
Applied rewrites6.1%
Taylor expanded in x around 0
Applied rewrites4.9%
Taylor expanded in x around 0
Applied rewrites24.2%
herbie shell --seed 2024242
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))