
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / (x - tan(x))
end function
public static double code(double x) {
return (x - Math.sin(x)) / (x - Math.tan(x));
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \sin x}{x - \tan x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / (x - tan(x))
end function
public static double code(double x) {
return (x - Math.sin(x)) / (x - Math.tan(x));
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \sin x}{x - \tan x}
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.085)
(+
(+ (* 0.225 (pow x_m 2.0)) (* 0.00024107142857142857 (pow x_m 6.0)))
(- (* -0.009642857142857142 (pow x_m 4.0)) 0.5))
(/ (- x_m (sin x_m)) (- x_m (tan x_m)))))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.085) {
tmp = ((0.225 * pow(x_m, 2.0)) + (0.00024107142857142857 * pow(x_m, 6.0))) + ((-0.009642857142857142 * pow(x_m, 4.0)) - 0.5);
} else {
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.085d0) then
tmp = ((0.225d0 * (x_m ** 2.0d0)) + (0.00024107142857142857d0 * (x_m ** 6.0d0))) + (((-0.009642857142857142d0) * (x_m ** 4.0d0)) - 0.5d0)
else
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.085) {
tmp = ((0.225 * Math.pow(x_m, 2.0)) + (0.00024107142857142857 * Math.pow(x_m, 6.0))) + ((-0.009642857142857142 * Math.pow(x_m, 4.0)) - 0.5);
} else {
tmp = (x_m - Math.sin(x_m)) / (x_m - Math.tan(x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.085: tmp = ((0.225 * math.pow(x_m, 2.0)) + (0.00024107142857142857 * math.pow(x_m, 6.0))) + ((-0.009642857142857142 * math.pow(x_m, 4.0)) - 0.5) else: tmp = (x_m - math.sin(x_m)) / (x_m - math.tan(x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.085) tmp = Float64(Float64(Float64(0.225 * (x_m ^ 2.0)) + Float64(0.00024107142857142857 * (x_m ^ 6.0))) + Float64(Float64(-0.009642857142857142 * (x_m ^ 4.0)) - 0.5)); else tmp = Float64(Float64(x_m - sin(x_m)) / Float64(x_m - tan(x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.085) tmp = ((0.225 * (x_m ^ 2.0)) + (0.00024107142857142857 * (x_m ^ 6.0))) + ((-0.009642857142857142 * (x_m ^ 4.0)) - 0.5); else tmp = (x_m - sin(x_m)) / (x_m - tan(x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.085], N[(N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.00024107142857142857 * N[Power[x$95$m, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.009642857142857142 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.085:\\
\;\;\;\;\left(0.225 \cdot {x_m}^{2} + 0.00024107142857142857 \cdot {x_m}^{6}\right) + \left(-0.009642857142857142 \cdot {x_m}^{4} - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m - \sin x_m}{x_m - \tan x_m}\\
\end{array}
\end{array}
if x < 0.0850000000000000061Initial program 29.4%
Taylor expanded in x around 0 72.1%
+-commutative72.1%
associate--l+72.1%
+-commutative72.1%
fma-def72.1%
fma-neg72.1%
metadata-eval72.1%
Simplified72.1%
Taylor expanded in x around 0 72.1%
fma-udef72.1%
Applied egg-rr72.1%
if 0.0850000000000000061 < x Initial program 100.0%
Final simplification78.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.03) (- (+ (* 0.225 (pow x_m 2.0)) (* -0.009642857142857142 (pow x_m 4.0))) 0.5) (/ (- x_m (sin x_m)) (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = ((0.225 * pow(x_m, 2.0)) + (-0.009642857142857142 * pow(x_m, 4.0))) - 0.5;
} else {
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.03d0) then
tmp = ((0.225d0 * (x_m ** 2.0d0)) + ((-0.009642857142857142d0) * (x_m ** 4.0d0))) - 0.5d0
else
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = ((0.225 * Math.pow(x_m, 2.0)) + (-0.009642857142857142 * Math.pow(x_m, 4.0))) - 0.5;
} else {
tmp = (x_m - Math.sin(x_m)) / (x_m - Math.tan(x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.03: tmp = ((0.225 * math.pow(x_m, 2.0)) + (-0.009642857142857142 * math.pow(x_m, 4.0))) - 0.5 else: tmp = (x_m - math.sin(x_m)) / (x_m - math.tan(x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.03) tmp = Float64(Float64(Float64(0.225 * (x_m ^ 2.0)) + Float64(-0.009642857142857142 * (x_m ^ 4.0))) - 0.5); else tmp = Float64(Float64(x_m - sin(x_m)) / Float64(x_m - tan(x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.03) tmp = ((0.225 * (x_m ^ 2.0)) + (-0.009642857142857142 * (x_m ^ 4.0))) - 0.5; else tmp = (x_m - sin(x_m)) / (x_m - tan(x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.03], N[(N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-0.009642857142857142 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.03:\\
\;\;\;\;\left(0.225 \cdot {x_m}^{2} + -0.009642857142857142 \cdot {x_m}^{4}\right) - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m - \sin x_m}{x_m - \tan x_m}\\
\end{array}
\end{array}
if x < 0.029999999999999999Initial program 29.1%
Taylor expanded in x around 0 71.9%
if 0.029999999999999999 < x Initial program 99.8%
Final simplification78.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0037) (- (* 0.225 (pow x_m 2.0)) 0.5) (/ (- x_m (sin x_m)) (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.0037) {
tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
} else {
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.0037d0) then
tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
else
tmp = (x_m - sin(x_m)) / (x_m - tan(x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.0037) {
tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
} else {
tmp = (x_m - Math.sin(x_m)) / (x_m - Math.tan(x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.0037: tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5 else: tmp = (x_m - math.sin(x_m)) / (x_m - math.tan(x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.0037) tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5); else tmp = Float64(Float64(x_m - sin(x_m)) / Float64(x_m - tan(x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.0037) tmp = (0.225 * (x_m ^ 2.0)) - 0.5; else tmp = (x_m - sin(x_m)) / (x_m - tan(x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.0037], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0037:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m - \sin x_m}{x_m - \tan x_m}\\
\end{array}
\end{array}
if x < 0.0037000000000000002Initial program 29.1%
Taylor expanded in x around 0 72.8%
if 0.0037000000000000002 < x Initial program 99.8%
Final simplification79.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.45) (- (* 0.225 (pow x_m 2.0)) 0.5) (/ x_m (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.45) {
tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
} else {
tmp = x_m / (x_m - tan(x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.45d0) then
tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
else
tmp = x_m / (x_m - tan(x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.45) {
tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
} else {
tmp = x_m / (x_m - Math.tan(x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.45: tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5 else: tmp = x_m / (x_m - math.tan(x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.45) tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5); else tmp = Float64(x_m / Float64(x_m - tan(x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.45) tmp = (0.225 * (x_m ^ 2.0)) - 0.5; else tmp = x_m / (x_m - tan(x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.45], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(x$95$m / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.45:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m}{x_m - \tan x_m}\\
\end{array}
\end{array}
if x < 1.44999999999999996Initial program 29.4%
Taylor expanded in x around 0 72.7%
if 1.44999999999999996 < x Initial program 100.0%
Taylor expanded in x around inf 95.7%
Final simplification78.1%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.32) -0.5 (/ x_m (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.32) {
tmp = -0.5;
} else {
tmp = x_m / (x_m - tan(x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.32d0) then
tmp = -0.5d0
else
tmp = x_m / (x_m - tan(x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.32) {
tmp = -0.5;
} else {
tmp = x_m / (x_m - Math.tan(x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.32: tmp = -0.5 else: tmp = x_m / (x_m - math.tan(x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.32) tmp = -0.5; else tmp = Float64(x_m / Float64(x_m - tan(x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.32) tmp = -0.5; else tmp = x_m / (x_m - tan(x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.32], -0.5, N[(x$95$m / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.32:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m}{x_m - \tan x_m}\\
\end{array}
\end{array}
if x < 1.32000000000000006Initial program 29.4%
Taylor expanded in x around 0 71.5%
if 1.32000000000000006 < x Initial program 100.0%
Taylor expanded in x around inf 95.7%
Final simplification77.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.55) -0.5 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.55d0) then
tmp = -0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.55: tmp = -0.5 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.55) tmp = -0.5; else tmp = 1.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.55) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.55], -0.5, 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 29.4%
Taylor expanded in x around 0 71.5%
if 1.55000000000000004 < x Initial program 100.0%
Taylor expanded in x around inf 95.6%
Final simplification77.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 -0.5)
x_m = fabs(x);
double code(double x_m) {
return -0.5;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = -0.5d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return -0.5;
}
x_m = math.fabs(x) def code(x_m): return -0.5
x_m = abs(x) function code(x_m) return -0.5 end
x_m = abs(x); function tmp = code(x_m) tmp = -0.5; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := -0.5
\begin{array}{l}
x_m = \left|x\right|
\\
-0.5
\end{array}
Initial program 46.0%
Taylor expanded in x around 0 55.1%
Final simplification55.1%
herbie shell --seed 2023335
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))