
(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
(let* ((t_0 (- x_m (sin x_m))))
(if (<= x_m 0.0039)
(- (* 0.225 (pow x_m 2.0)) 0.5)
(/ 1.0 (- (/ x_m t_0) (/ (tan x_m) t_0))))))x_m = fabs(x);
double code(double x_m) {
double t_0 = x_m - sin(x_m);
double tmp;
if (x_m <= 0.0039) {
tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
} else {
tmp = 1.0 / ((x_m / t_0) - (tan(x_m) / t_0));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = x_m - sin(x_m)
if (x_m <= 0.0039d0) then
tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
else
tmp = 1.0d0 / ((x_m / t_0) - (tan(x_m) / t_0))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double t_0 = x_m - Math.sin(x_m);
double tmp;
if (x_m <= 0.0039) {
tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
} else {
tmp = 1.0 / ((x_m / t_0) - (Math.tan(x_m) / t_0));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): t_0 = x_m - math.sin(x_m) tmp = 0 if x_m <= 0.0039: tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5 else: tmp = 1.0 / ((x_m / t_0) - (math.tan(x_m) / t_0)) return tmp
x_m = abs(x) function code(x_m) t_0 = Float64(x_m - sin(x_m)) tmp = 0.0 if (x_m <= 0.0039) tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5); else tmp = Float64(1.0 / Float64(Float64(x_m / t_0) - Float64(tan(x_m) / t_0))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) t_0 = x_m - sin(x_m); tmp = 0.0; if (x_m <= 0.0039) tmp = (0.225 * (x_m ^ 2.0)) - 0.5; else tmp = 1.0 / ((x_m / t_0) - (tan(x_m) / t_0)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 0.0039], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(1.0 / N[(N[(x$95$m / t$95$0), $MachinePrecision] - N[(N[Tan[x$95$m], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := x_m - \sin x_m\\
\mathbf{if}\;x_m \leq 0.0039:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x_m}{t_0} - \frac{\tan x_m}{t_0}}\\
\end{array}
\end{array}
if x < 0.0038999999999999998Initial program 31.3%
Taylor expanded in x around 0 70.1%
if 0.0038999999999999998 < x Initial program 99.9%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Applied egg-rr100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification77.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0042) (- (* 0.225 (pow x_m 2.0)) 0.5) (/ 1.0 (/ (- x_m (tan x_m)) (- x_m (sin x_m))))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.0042) {
tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
} else {
tmp = 1.0 / ((x_m - tan(x_m)) / (x_m - sin(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.0042d0) then
tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
else
tmp = 1.0d0 / ((x_m - tan(x_m)) / (x_m - sin(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.0042) {
tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
} else {
tmp = 1.0 / ((x_m - Math.tan(x_m)) / (x_m - Math.sin(x_m)));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.0042: tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5 else: tmp = 1.0 / ((x_m - math.tan(x_m)) / (x_m - math.sin(x_m))) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.0042) tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5); else tmp = Float64(1.0 / Float64(Float64(x_m - tan(x_m)) / Float64(x_m - sin(x_m)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.0042) tmp = (0.225 * (x_m ^ 2.0)) - 0.5; else tmp = 1.0 / ((x_m - tan(x_m)) / (x_m - sin(x_m))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.0042], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(1.0 / N[(N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0042:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x_m - \tan x_m}{x_m - \sin x_m}}\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 31.3%
Taylor expanded in x around 0 70.1%
if 0.00419999999999999974 < x Initial program 99.9%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Applied egg-rr100.0%
Final simplification77.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0042) (- (* 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.0042) {
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.0042d0) 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.0042) {
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.0042: 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.0042) 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.0042) 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.0042], 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.0042:\\
\;\;\;\;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.00419999999999999974Initial program 31.3%
Taylor expanded in x around 0 70.1%
if 0.00419999999999999974 < x Initial program 99.9%
Final simplification77.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.5) (- (pow (* x_m (sqrt 0.225)) 2.0) 0.5) 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.5) {
tmp = pow((x_m * sqrt(0.225)), 2.0) - 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 <= 2.5d0) then
tmp = ((x_m * sqrt(0.225d0)) ** 2.0d0) - 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 <= 2.5) {
tmp = Math.pow((x_m * Math.sqrt(0.225)), 2.0) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.5: tmp = math.pow((x_m * math.sqrt(0.225)), 2.0) - 0.5 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.5) tmp = Float64((Float64(x_m * sqrt(0.225)) ^ 2.0) - 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 <= 2.5) tmp = ((x_m * sqrt(0.225)) ^ 2.0) - 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, 2.5], N[(N[Power[N[(x$95$m * N[Sqrt[0.225], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.5:\\
\;\;\;\;{\left(x_m \cdot \sqrt{0.225}\right)}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.5Initial program 31.6%
Taylor expanded in x around 0 69.9%
add-sqr-sqrt69.9%
pow269.9%
*-commutative69.9%
sqrt-prod69.9%
unpow269.9%
sqrt-prod41.0%
add-sqr-sqrt69.9%
Applied egg-rr69.9%
if 2.5 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
Final simplification77.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.5) (- (* 0.225 (pow x_m 2.0)) 0.5) 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.5) {
tmp = (0.225 * pow(x_m, 2.0)) - 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 <= 2.5d0) then
tmp = (0.225d0 * (x_m ** 2.0d0)) - 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 <= 2.5) {
tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.5: tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.5) tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 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 <= 2.5) tmp = (0.225 * (x_m ^ 2.0)) - 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, 2.5], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.5:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.5Initial program 31.6%
Taylor expanded in x around 0 69.9%
if 2.5 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
Final simplification77.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 4.8) -0.5 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 4.8) {
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 <= 4.8d0) 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 <= 4.8) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 4.8: tmp = -0.5 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 4.8) 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 <= 4.8) 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, 4.8], -0.5, 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 4.8:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 4.79999999999999982Initial program 31.6%
Taylor expanded in x around 0 69.0%
if 4.79999999999999982 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
Final simplification76.7%
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 49.0%
Taylor expanded in x around 0 51.9%
Final simplification51.9%
herbie shell --seed 2024021
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))