
(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 13 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 (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 log(exp(Float64(rem(exp(x), sqrt(cos(x))) / exp(x)))) end
code[x_] := N[Log[N[Exp[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]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}}\right)
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
add-log-exp8.7%
Applied egg-rr8.7%
Final simplification8.7%
(FPCore (x) :precision binary64 (exp (- (log (fmod (exp x) (sqrt (cos x)))) x)))
double code(double x) {
return exp((log(fmod(exp(x), sqrt(cos(x)))) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((log(mod(exp(x), sqrt(cos(x)))) - x))
end function
def code(x): return math.exp((math.log(math.fmod(math.exp(x), math.sqrt(math.cos(x)))) - x))
function code(x) return exp(Float64(log(rem(exp(x), sqrt(cos(x)))) - x)) end
code[x_] := 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]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) - x}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
add-exp-log8.6%
div-exp8.6%
Applied egg-rr8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (+ (+ (/ (fmod (exp x) (sqrt (cos x))) (exp x)) 1.0) -1.0))
double code(double x) {
return ((fmod(exp(x), sqrt(cos(x))) / exp(x)) + 1.0) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((mod(exp(x), sqrt(cos(x))) / exp(x)) + 1.0d0) + (-1.0d0)
end function
def code(x): return ((math.fmod(math.exp(x), math.sqrt(math.cos(x))) / math.exp(x)) + 1.0) + -1.0
function code(x) return Float64(Float64(Float64(rem(exp(x), sqrt(cos(x))) / exp(x)) + 1.0) + -1.0) 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] / N[Exp[x], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} + 1\right) + -1
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
expm1-log1p-u8.6%
expm1-udef8.6%
Applied egg-rr8.6%
sub-neg8.6%
log1p-udef8.6%
add-exp-log8.6%
+-commutative8.6%
metadata-eval8.6%
Applied egg-rr8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (/ 1.0 (/ (exp x) (fmod (exp x) (sqrt (cos x))))))
double code(double x) {
return 1.0 / (exp(x) / fmod(exp(x), sqrt(cos(x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (exp(x) / mod(exp(x), sqrt(cos(x))))
end function
def code(x): return 1.0 / (math.exp(x) / math.fmod(math.exp(x), math.sqrt(math.cos(x))))
function code(x) return Float64(1.0 / Float64(exp(x) / rem(exp(x), sqrt(cos(x))))) end
code[x_] := N[(1.0 / 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]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
add-log-exp8.7%
Applied egg-rr8.7%
add-log-exp8.6%
clear-num8.6%
Applied egg-rr8.6%
Final simplification8.6%
(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 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Final simplification8.6%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 1.0 (+ 1.0 (+ -1.0 (* (pow x 2.0) -0.25))))) (exp x)))
double code(double x) {
return fmod(exp(x), (1.0 + (1.0 + (-1.0 + (pow(x, 2.0) * -0.25))))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + (1.0d0 + ((-1.0d0) + ((x ** 2.0d0) * (-0.25d0)))))) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + (1.0 + (-1.0 + (math.pow(x, 2.0) * -0.25))))) / math.exp(x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64(1.0 + Float64(-1.0 + Float64((x ^ 2.0) * -0.25))))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(1.0 + N[(-1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $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(1 + \left(-1 + {x}^{2} \cdot -0.25\right)\right)\right)\right)}{e^{x}}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 8.1%
*-commutative7.4%
Simplified8.1%
expm1-log1p-u7.3%
log1p-def7.3%
expm1-udef7.3%
add-exp-log7.4%
associate--l+7.4%
Applied egg-rr8.1%
Final simplification8.1%
(FPCore (x) :precision binary64 (/ 1.0 (/ (exp x) (fmod (exp x) (+ 1.0 (* (pow x 2.0) -0.25))))))
double code(double x) {
return 1.0 / (exp(x) / fmod(exp(x), (1.0 + (pow(x, 2.0) * -0.25))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (exp(x) / mod(exp(x), (1.0d0 + ((x ** 2.0d0) * (-0.25d0)))))
end function
def code(x): return 1.0 / (math.exp(x) / math.fmod(math.exp(x), (1.0 + (math.pow(x, 2.0) * -0.25))))
function code(x) return Float64(1.0 / Float64(exp(x) / rem(exp(x), Float64(1.0 + Float64((x ^ 2.0) * -0.25))))) end
code[x_] := N[(1.0 / N[(N[Exp[x], $MachinePrecision] / N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{e^{x}}{\left(\left(e^{x}\right) \bmod \left(1 + {x}^{2} \cdot -0.25\right)\right)}}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
add-log-exp8.7%
Applied egg-rr8.7%
add-log-exp8.6%
clear-num8.6%
Applied egg-rr8.6%
Taylor expanded in x around 0 8.1%
*-commutative7.4%
Simplified8.1%
Final simplification8.1%
(FPCore (x) :precision binary64 (/ (fmod (exp x) (+ 1.0 (* (pow x 2.0) -0.25))) (exp x)))
double code(double x) {
return fmod(exp(x), (1.0 + (pow(x, 2.0) * -0.25))) / exp(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + ((x ** 2.0d0) * (-0.25d0)))) / exp(x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + (math.pow(x, 2.0) * -0.25))) / math.exp(x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64((x ^ 2.0) * -0.25))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(N[Power[x, 2.0], $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 + {x}^{2} \cdot -0.25\right)\right)}{e^{x}}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 8.1%
*-commutative7.4%
Simplified8.1%
Final simplification8.1%
(FPCore (x) :precision binary64 (exp (- (log (fmod (exp x) 1.0)) x)))
double code(double x) {
return exp((log(fmod(exp(x), 1.0)) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((log(mod(exp(x), 1.0d0)) - x))
end function
def code(x): return math.exp((math.log(math.fmod(math.exp(x), 1.0)) - x))
function code(x) return exp(Float64(log(rem(exp(x), 1.0)) - x)) end
code[x_] := N[Exp[N[(N[Log[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\left(e^{x}\right) \bmod 1\right) - x}
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 7.5%
add-exp-log7.5%
div-exp7.5%
Applied egg-rr7.5%
Final simplification7.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 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 7.5%
Final simplification7.5%
(FPCore (x) :precision binary64 (* (fmod (exp x) (+ 1.0 (* x (* x -0.25)))) (- 1.0 x)))
double code(double x) {
return fmod(exp(x), (1.0 + (x * (x * -0.25)))) * (1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), (1.0d0 + (x * (x * (-0.25d0))))) * (1.0d0 - x)
end function
def code(x): return math.fmod(math.exp(x), (1.0 + (x * (x * -0.25)))) * (1.0 - x)
function code(x) return Float64(rem(exp(x), Float64(1.0 + Float64(x * Float64(x * -0.25)))) * Float64(1.0 - x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(1.0 + N[(x * N[(x * -0.25), $MachinePrecision]), $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(1 + x \cdot \left(x \cdot -0.25\right)\right)\right) \cdot \left(1 - x\right)
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 7.4%
+-commutative7.4%
*-lft-identity7.4%
associate-*r*7.4%
neg-mul-17.4%
distribute-rgt-out7.4%
neg-sub07.4%
associate-+r-7.4%
metadata-eval7.4%
Simplified7.4%
Taylor expanded in x around 0 7.4%
*-commutative7.4%
Simplified7.4%
expm1-log1p-u7.3%
log1p-def7.3%
expm1-udef7.3%
add-exp-log7.4%
associate--l+7.4%
Applied egg-rr7.4%
associate-+r-7.4%
add-exp-log7.3%
expm1-def7.3%
log1p-def7.3%
expm1-log1p-u7.4%
*-commutative7.4%
unpow27.4%
associate-*r*7.4%
Applied egg-rr7.4%
Final simplification7.4%
(FPCore (x) :precision binary64 (* (fmod (exp x) 1.0) (- 1.0 x)))
double code(double x) {
return fmod(exp(x), 1.0) * (1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = mod(exp(x), 1.0d0) * (1.0d0 - x)
end function
def code(x): return math.fmod(math.exp(x), 1.0) * (1.0 - x)
function code(x) return Float64(rem(exp(x), 1.0) * Float64(1.0 - x)) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = 1.0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod 1\right) \cdot \left(1 - x\right)
\end{array}
Initial program 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 7.5%
Taylor expanded in x around 0 7.2%
+-commutative7.2%
*-lft-identity7.2%
associate-*r*7.2%
neg-mul-17.2%
distribute-rgt-out7.1%
sub-neg7.1%
Simplified7.1%
Final simplification7.1%
(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 8.6%
/-rgt-identity8.6%
associate-/r/8.6%
exp-neg8.6%
remove-double-neg8.6%
Simplified8.6%
Taylor expanded in x around 0 7.5%
Taylor expanded in x around 0 6.5%
Final simplification6.5%
herbie shell --seed 2023326
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))