
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* t_0 (cos x)) (* (cos (* 0.5 eps)) (sin x)))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * cos(x)) + (cos((0.5 * eps)) * sin(x))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * ((t_0 * cos(x)) + (cos((0.5d0 * eps)) * sin(x))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * Math.cos(x)) + (Math.cos((0.5 * eps)) * Math.sin(x))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((t_0 * math.cos(x)) + (math.cos((0.5 * eps)) * math.sin(x))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(t_0 * cos(x)) + Float64(cos(Float64(0.5 * eps)) * sin(x))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((t_0 * cos(x)) + (cos((0.5 * eps)) * sin(x)))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \left(t_0 \cdot \cos x + \cos \left(0.5 \cdot \varepsilon\right) \cdot \sin x\right)\right)
\end{array}
\end{array}
Initial program 39.9%
diff-cos49.2%
div-inv49.2%
metadata-eval49.2%
div-inv49.2%
+-commutative49.2%
metadata-eval49.2%
Applied egg-rr49.2%
associate-*r*49.2%
*-commutative49.2%
associate-*l*49.2%
*-commutative49.2%
+-commutative49.2%
associate--l+79.3%
+-inverses79.3%
*-commutative79.3%
associate-+r+79.3%
+-commutative79.3%
Simplified79.3%
distribute-rgt-in79.3%
*-commutative79.3%
+-rgt-identity79.3%
sin-sum99.4%
+-rgt-identity99.4%
+-rgt-identity99.4%
Applied egg-rr99.4%
Taylor expanded in eps around inf 99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= eps -0.0078) (not (<= eps 0.008)))
(- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps))))
(*
t_0
(*
-2.0
(+
(* t_0 (cos (* 0.5 (+ x x))))
(* (sin x) (+ (* (* eps eps) -0.125) 1.0))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((eps <= -0.0078) || !(eps <= 0.008)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} else {
tmp = t_0 * (-2.0 * ((t_0 * cos((0.5 * (x + x)))) + (sin(x) * (((eps * eps) * -0.125) + 1.0))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((0.5d0 * eps))
if ((eps <= (-0.0078d0)) .or. (.not. (eps <= 0.008d0))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
else
tmp = t_0 * ((-2.0d0) * ((t_0 * cos((0.5d0 * (x + x)))) + (sin(x) * (((eps * eps) * (-0.125d0)) + 1.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
double tmp;
if ((eps <= -0.0078) || !(eps <= 0.008)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} else {
tmp = t_0 * (-2.0 * ((t_0 * Math.cos((0.5 * (x + x)))) + (Math.sin(x) * (((eps * eps) * -0.125) + 1.0))));
}
return tmp;
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) tmp = 0 if (eps <= -0.0078) or not (eps <= 0.008): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) else: tmp = t_0 * (-2.0 * ((t_0 * math.cos((0.5 * (x + x)))) + (math.sin(x) * (((eps * eps) * -0.125) + 1.0)))) return tmp
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((eps <= -0.0078) || !(eps <= 0.008)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); else tmp = Float64(t_0 * Float64(-2.0 * Float64(Float64(t_0 * cos(Float64(0.5 * Float64(x + x)))) + Float64(sin(x) * Float64(Float64(Float64(eps * eps) * -0.125) + 1.0))))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((0.5 * eps)); tmp = 0.0; if ((eps <= -0.0078) || ~((eps <= 0.008))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = t_0 * (-2.0 * ((t_0 * cos((0.5 * (x + x)))) + (sin(x) * (((eps * eps) * -0.125) + 1.0)))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[eps, -0.0078], N[Not[LessEqual[eps, 0.008]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(-2.0 * N[(N[(t$95$0 * N[Cos[N[(0.5 * N[(x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(N[(eps * eps), $MachinePrecision] * -0.125), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;\varepsilon \leq -0.0078 \lor \neg \left(\varepsilon \leq 0.008\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(-2 \cdot \left(t_0 \cdot \cos \left(0.5 \cdot \left(x + x\right)\right) + \sin x \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot -0.125 + 1\right)\right)\right)\\
\end{array}
\end{array}
if eps < -0.0077999999999999996 or 0.0080000000000000002 < eps Initial program 58.6%
sub-neg58.6%
cos-sum98.6%
associate-+l-98.6%
fma-neg98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 98.6%
if -0.0077999999999999996 < eps < 0.0080000000000000002Initial program 20.6%
diff-cos38.5%
div-inv38.5%
metadata-eval38.5%
div-inv38.5%
+-commutative38.5%
metadata-eval38.5%
Applied egg-rr38.5%
associate-*r*38.5%
*-commutative38.5%
associate-*l*38.5%
*-commutative38.5%
+-commutative38.5%
associate--l+98.2%
+-inverses98.2%
*-commutative98.2%
associate-+r+98.2%
+-commutative98.2%
Simplified98.2%
distribute-rgt-in98.2%
*-commutative98.2%
+-rgt-identity98.2%
sin-sum99.8%
+-rgt-identity99.8%
+-rgt-identity99.8%
Applied egg-rr99.8%
Taylor expanded in eps around 0 99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
*-commutative99.8%
unpow299.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -2e-7) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (- (* -0.5 (* (cos x) (* eps eps))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -2e-7) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = (-0.5 * (cos(x) * (eps * eps))) - (eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-2d-7)) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = ((-0.5d0) * (cos(x) * (eps * eps))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -2e-7) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = (-0.5 * (Math.cos(x) * (eps * eps))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -2e-7: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = (-0.5 * (math.cos(x) * (eps * eps))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -2e-7) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(Float64(-0.5 * Float64(cos(x) * Float64(eps * eps))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -2e-7) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = (-0.5 * (cos(x) * (eps * eps))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -2e-7], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(N[Cos[x], $MachinePrecision] * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -2 \cdot 10^{-7}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\cos x \cdot \left(\varepsilon \cdot \varepsilon\right)\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -1.9999999999999999e-7Initial program 83.3%
diff-cos84.0%
div-inv84.0%
metadata-eval84.0%
div-inv84.0%
+-commutative84.0%
metadata-eval84.0%
Applied egg-rr84.0%
associate-*r*84.0%
*-commutative84.0%
associate-*l*84.0%
*-commutative84.0%
+-commutative84.0%
associate--l+83.7%
+-inverses83.7%
*-commutative83.7%
associate-+r+83.7%
+-commutative83.7%
Simplified83.7%
Taylor expanded in x around 0 84.2%
if -1.9999999999999999e-7 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 16.8%
Taylor expanded in eps around 0 75.1%
+-commutative75.1%
mul-1-neg75.1%
unsub-neg75.1%
*-commutative75.1%
unpow275.1%
Simplified75.1%
Final simplification78.3%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* t_0 (cos x)) (sin x))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * cos(x)) + sin(x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * ((t_0 * cos(x)) + sin(x)))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * Math.cos(x)) + Math.sin(x)));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((t_0 * math.cos(x)) + math.sin(x)))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(t_0 * cos(x)) + sin(x)))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((t_0 * cos(x)) + sin(x))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \left(t_0 \cdot \cos x + \sin x\right)\right)
\end{array}
\end{array}
Initial program 39.9%
diff-cos49.2%
div-inv49.2%
metadata-eval49.2%
div-inv49.2%
+-commutative49.2%
metadata-eval49.2%
Applied egg-rr49.2%
associate-*r*49.2%
*-commutative49.2%
associate-*l*49.2%
*-commutative49.2%
+-commutative49.2%
associate--l+79.3%
+-inverses79.3%
*-commutative79.3%
associate-+r+79.3%
+-commutative79.3%
Simplified79.3%
distribute-rgt-in79.3%
*-commutative79.3%
+-rgt-identity79.3%
sin-sum99.4%
+-rgt-identity99.4%
+-rgt-identity99.4%
Applied egg-rr99.4%
Taylor expanded in eps around inf 99.4%
Taylor expanded in eps around 0 80.5%
Final simplification80.5%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -5e-15) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -5e-15) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-5d-15)) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -5e-15) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -5e-15: tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -5e-15) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -5e-15) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-15], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -5 \cdot 10^{-15}:\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -4.99999999999999999e-15Initial program 82.7%
Taylor expanded in x around 0 82.8%
if -4.99999999999999999e-15 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 16.7%
Taylor expanded in eps around 0 61.9%
mul-1-neg61.9%
*-commutative61.9%
distribute-rgt-neg-in61.9%
Simplified61.9%
Final simplification69.2%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (* 0.5 (- eps (* -2.0 x)))))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (-2.0 * x)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * eps)) * sin((0.5d0 * (eps - ((-2.0d0) * x)))))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin((0.5 * (eps - (-2.0 * x)))));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin((0.5 * (eps - (-2.0 * x)))))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(0.5 * Float64(eps - Float64(-2.0 * x)))))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin((0.5 * (eps - (-2.0 * x))))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * N[(eps - N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)\right)
\end{array}
Initial program 39.9%
diff-cos49.2%
div-inv49.2%
metadata-eval49.2%
div-inv49.2%
+-commutative49.2%
metadata-eval49.2%
Applied egg-rr49.2%
associate-*r*49.2%
*-commutative49.2%
associate-*l*49.2%
*-commutative49.2%
+-commutative49.2%
associate--l+79.3%
+-inverses79.3%
*-commutative79.3%
associate-+r+79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in x around -inf 79.3%
Final simplification79.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -8e-39) (not (<= x 3.3e-6)))
(* t_0 (* -2.0 (sin x)))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -8e-39) || !(x <= 3.3e-6)) {
tmp = t_0 * (-2.0 * sin(x));
} else {
tmp = -2.0 * pow(t_0, 2.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin((0.5d0 * eps))
if ((x <= (-8d-39)) .or. (.not. (x <= 3.3d-6))) then
tmp = t_0 * ((-2.0d0) * sin(x))
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
double tmp;
if ((x <= -8e-39) || !(x <= 3.3e-6)) {
tmp = t_0 * (-2.0 * Math.sin(x));
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) tmp = 0 if (x <= -8e-39) or not (x <= 3.3e-6): tmp = t_0 * (-2.0 * math.sin(x)) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((x <= -8e-39) || !(x <= 3.3e-6)) tmp = Float64(t_0 * Float64(-2.0 * sin(x))); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((0.5 * eps)); tmp = 0.0; if ((x <= -8e-39) || ~((x <= 3.3e-6))) tmp = t_0 * (-2.0 * sin(x)); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -8e-39], N[Not[LessEqual[x, 3.3e-6]], $MachinePrecision]], N[(t$95$0 * N[(-2.0 * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq -8 \cdot 10^{-39} \lor \neg \left(x \leq 3.3 \cdot 10^{-6}\right):\\
\;\;\;\;t_0 \cdot \left(-2 \cdot \sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -7.99999999999999943e-39 or 3.30000000000000017e-6 < x Initial program 8.4%
diff-cos10.0%
div-inv10.0%
metadata-eval10.0%
div-inv10.0%
+-commutative10.0%
metadata-eval10.0%
Applied egg-rr10.0%
associate-*r*10.0%
*-commutative10.0%
associate-*l*10.0%
*-commutative10.0%
+-commutative10.0%
associate--l+61.4%
+-inverses61.4%
*-commutative61.4%
associate-+r+61.4%
+-commutative61.4%
Simplified61.4%
Taylor expanded in eps around 0 59.1%
if -7.99999999999999943e-39 < x < 3.30000000000000017e-6Initial program 73.9%
diff-cos91.5%
div-inv91.5%
metadata-eval91.5%
div-inv91.5%
+-commutative91.5%
metadata-eval91.5%
Applied egg-rr91.5%
associate-*r*91.5%
*-commutative91.5%
associate-*l*91.5%
*-commutative91.5%
+-commutative91.5%
associate--l+98.6%
+-inverses98.6%
*-commutative98.6%
associate-+r+98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in x around 0 88.8%
Final simplification73.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.55e-40) (not (<= eps 5e-9))) (* -2.0 (pow (sin (* 0.5 eps)) 2.0)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.55e-40) || !(eps <= 5e-9)) {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-1.55d-40)) .or. (.not. (eps <= 5d-9))) then
tmp = (-2.0d0) * (sin((0.5d0 * eps)) ** 2.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.55e-40) || !(eps <= 5e-9)) {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.55e-40) or not (eps <= 5e-9): tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.55e-40) || !(eps <= 5e-9)) tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.55e-40) || ~((eps <= 5e-9))) tmp = -2.0 * (sin((0.5 * eps)) ^ 2.0); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.55e-40], N[Not[LessEqual[eps, 5e-9]], $MachinePrecision]], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.55 \cdot 10^{-40} \lor \neg \left(\varepsilon \leq 5 \cdot 10^{-9}\right):\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.55000000000000005e-40 or 5.0000000000000001e-9 < eps Initial program 54.3%
diff-cos60.2%
div-inv60.2%
metadata-eval60.2%
div-inv60.2%
+-commutative60.2%
metadata-eval60.2%
Applied egg-rr60.2%
associate-*r*60.2%
*-commutative60.2%
associate-*l*60.2%
*-commutative60.2%
+-commutative60.2%
associate--l+63.6%
+-inverses63.6%
*-commutative63.6%
associate-+r+63.6%
+-commutative63.6%
Simplified63.6%
Taylor expanded in x around 0 60.7%
if -1.55000000000000005e-40 < eps < 5.0000000000000001e-9Initial program 21.7%
Taylor expanded in eps around 0 86.5%
mul-1-neg86.5%
*-commutative86.5%
distribute-rgt-neg-in86.5%
Simplified86.5%
Final simplification72.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* (* eps eps) -0.5)))
(if (<= eps -3.25e-6)
t_0
(if (<= eps -6e-143)
t_1
(if (<= eps 1.1e-137) (* eps (- x)) (if (<= eps 0.000116) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = (eps * eps) * -0.5;
double tmp;
if (eps <= -3.25e-6) {
tmp = t_0;
} else if (eps <= -6e-143) {
tmp = t_1;
} else if (eps <= 1.1e-137) {
tmp = eps * -x;
} else if (eps <= 0.000116) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos(eps) + (-1.0d0)
t_1 = (eps * eps) * (-0.5d0)
if (eps <= (-3.25d-6)) then
tmp = t_0
else if (eps <= (-6d-143)) then
tmp = t_1
else if (eps <= 1.1d-137) then
tmp = eps * -x
else if (eps <= 0.000116d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) + -1.0;
double t_1 = (eps * eps) * -0.5;
double tmp;
if (eps <= -3.25e-6) {
tmp = t_0;
} else if (eps <= -6e-143) {
tmp = t_1;
} else if (eps <= 1.1e-137) {
tmp = eps * -x;
} else if (eps <= 0.000116) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = (eps * eps) * -0.5 tmp = 0 if eps <= -3.25e-6: tmp = t_0 elif eps <= -6e-143: tmp = t_1 elif eps <= 1.1e-137: tmp = eps * -x elif eps <= 0.000116: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(Float64(eps * eps) * -0.5) tmp = 0.0 if (eps <= -3.25e-6) tmp = t_0; elseif (eps <= -6e-143) tmp = t_1; elseif (eps <= 1.1e-137) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.000116) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; t_1 = (eps * eps) * -0.5; tmp = 0.0; if (eps <= -3.25e-6) tmp = t_0; elseif (eps <= -6e-143) tmp = t_1; elseif (eps <= 1.1e-137) tmp = eps * -x; elseif (eps <= 0.000116) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[eps, -3.25e-6], t$95$0, If[LessEqual[eps, -6e-143], t$95$1, If[LessEqual[eps, 1.1e-137], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.000116], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := \left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\mathbf{if}\;\varepsilon \leq -3.25 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -6 \cdot 10^{-143}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 1.1 \cdot 10^{-137}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000116:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -3.2499999999999998e-6 or 1.16e-4 < eps Initial program 58.3%
Taylor expanded in x around 0 60.1%
if -3.2499999999999998e-6 < eps < -5.9999999999999997e-143 or 1.1000000000000001e-137 < eps < 1.16e-4Initial program 4.7%
Taylor expanded in x around 0 4.9%
Taylor expanded in eps around 0 34.8%
*-commutative34.8%
unpow234.8%
Simplified34.8%
if -5.9999999999999997e-143 < eps < 1.1000000000000001e-137Initial program 34.6%
Taylor expanded in eps around 0 98.0%
mul-1-neg98.0%
*-commutative98.0%
distribute-rgt-neg-in98.0%
Simplified98.0%
Taylor expanded in x around 0 49.3%
Final simplification51.5%
(FPCore (x eps) :precision binary64 (if (<= x -1.65e-140) (* eps (- x)) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -1.65e-140) {
tmp = eps * -x;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-1.65d-140)) then
tmp = eps * -x
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -1.65e-140) {
tmp = eps * -x;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -1.65e-140: tmp = eps * -x else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if (x <= -1.65e-140) tmp = Float64(eps * Float64(-x)); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -1.65e-140) tmp = eps * -x; else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -1.65e-140], N[(eps * (-x)), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-140}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if x < -1.64999999999999994e-140Initial program 17.8%
Taylor expanded in eps around 0 53.8%
mul-1-neg53.8%
*-commutative53.8%
distribute-rgt-neg-in53.8%
Simplified53.8%
Taylor expanded in x around 0 14.5%
if -1.64999999999999994e-140 < x Initial program 53.2%
Taylor expanded in x around 0 53.8%
Taylor expanded in eps around 0 26.4%
*-commutative26.4%
unpow226.4%
Simplified26.4%
Final simplification21.9%
(FPCore (x eps) :precision binary64 (* eps (- x)))
double code(double x, double eps) {
return eps * -x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * -x
end function
public static double code(double x, double eps) {
return eps * -x;
}
def code(x, eps): return eps * -x
function code(x, eps) return Float64(eps * Float64(-x)) end
function tmp = code(x, eps) tmp = eps * -x; end
code[x_, eps_] := N[(eps * (-x)), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(-x\right)
\end{array}
Initial program 39.9%
Taylor expanded in eps around 0 41.8%
mul-1-neg41.8%
*-commutative41.8%
distribute-rgt-neg-in41.8%
Simplified41.8%
Taylor expanded in x around 0 16.4%
Final simplification16.4%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 39.9%
add-cube-cbrt39.4%
pow339.4%
Applied egg-rr39.4%
Taylor expanded in eps around 0 11.4%
pow-base-111.4%
*-lft-identity11.4%
+-inverses11.4%
Simplified11.4%
Final simplification11.4%
herbie shell --seed 2023264
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))