
(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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (let* ((t_0 (- x (tan x)))) (if (<= x 0.0056) (fma 0.225 (* x x) -0.5) (- (/ x t_0) (/ (sin x) t_0)))))
x = abs(x);
double code(double x) {
double t_0 = x - tan(x);
double tmp;
if (x <= 0.0056) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = (x / t_0) - (sin(x) / t_0);
}
return tmp;
}
x = abs(x) function code(x) t_0 = Float64(x - tan(x)) tmp = 0.0 if (x <= 0.0056) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(Float64(x / t_0) - Float64(sin(x) / t_0)); end return tmp end
NOTE: x should be positive before calling this function
code[x_] := Block[{t$95$0 = N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.0056], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(x / t$95$0), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := x - \tan x\\
\mathbf{if}\;x \leq 0.0056:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{t_0} - \frac{\sin x}{t_0}\\
\end{array}
\end{array}
if x < 0.00559999999999999994Initial program 40.6%
Taylor expanded in x around 0 62.4%
fma-neg62.4%
unpow262.4%
metadata-eval62.4%
Simplified62.4%
if 0.00559999999999999994 < x Initial program 99.9%
div-sub100.0%
Applied egg-rr100.0%
Final simplification70.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.5) (fma 0.225 (* x x) -0.5) (+ 1.0 (/ (- (tan x) (sin x)) x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.5) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = 1.0 + ((tan(x) - sin(x)) / x);
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.5) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x)); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.5], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(1.0 + N[(N[(N[Tan[x], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.5:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.5Initial program 40.6%
Taylor expanded in x around 0 62.4%
fma-neg62.4%
unpow262.4%
metadata-eval62.4%
Simplified62.4%
if 2.5 < x Initial program 99.9%
Taylor expanded in x around inf 100.0%
associate--l+100.0%
sub-neg100.0%
*-lft-identity100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
distribute-lft-out--100.0%
mul-1-neg100.0%
remove-double-neg100.0%
associate-/l/100.0%
div-sub100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
tan-quot100.0%
sub-neg100.0%
Applied egg-rr100.0%
sub-neg100.0%
Simplified100.0%
Final simplification70.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0039) (fma 0.225 (* x x) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0039) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = (x - sin(x)) / (x - tan(x));
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0039) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(Float64(x - sin(x)) / Float64(x - tan(x))); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0039], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0039:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.0038999999999999998Initial program 40.6%
Taylor expanded in x around 0 62.4%
fma-neg62.4%
unpow262.4%
metadata-eval62.4%
Simplified62.4%
if 0.0038999999999999998 < x Initial program 99.9%
Final simplification70.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.3) -0.5 (/ x (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.3) {
tmp = -0.5;
} else {
tmp = x / (x - tan(x));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.3d0) then
tmp = -0.5d0
else
tmp = x / (x - tan(x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.3) {
tmp = -0.5;
} else {
tmp = x / (x - Math.tan(x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.3: tmp = -0.5 else: tmp = x / (x - math.tan(x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.3) tmp = -0.5; else tmp = Float64(x / Float64(x - tan(x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.3) tmp = -0.5; else tmp = x / (x - tan(x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.3], -0.5, N[(x / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.3:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - \tan x}\\
\end{array}
\end{array}
if x < 1.30000000000000004Initial program 40.6%
Taylor expanded in x around 0 61.0%
if 1.30000000000000004 < x Initial program 99.9%
Taylor expanded in x around inf 98.8%
Final simplification69.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.2) (fma 0.225 (* x x) -0.5) (/ x (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.2) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = x / (x - tan(x));
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.2) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(x / Float64(x - tan(x))); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.2], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(x / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - \tan x}\\
\end{array}
\end{array}
if x < 2.2000000000000002Initial program 40.6%
Taylor expanded in x around 0 62.4%
fma-neg62.4%
unpow262.4%
metadata-eval62.4%
Simplified62.4%
if 2.2000000000000002 < x Initial program 99.9%
Taylor expanded in x around inf 98.8%
Final simplification70.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.6) -0.5 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.6) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.6d0) then
tmp = -0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.6) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.6: tmp = -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.6) tmp = -0.5; else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.6) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.6], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.6000000000000001Initial program 40.6%
Taylor expanded in x around 0 61.0%
if 1.6000000000000001 < x Initial program 99.9%
Taylor expanded in x around inf 98.7%
Final simplification69.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 -0.5)
x = abs(x);
double code(double x) {
return -0.5;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = -0.5d0
end function
x = Math.abs(x);
public static double code(double x) {
return -0.5;
}
x = abs(x) def code(x): return -0.5
x = abs(x) function code(x) return -0.5 end
x = abs(x) function tmp = code(x) tmp = -0.5; end
NOTE: x should be positive before calling this function code[x_] := -0.5
\begin{array}{l}
x = |x|\\
\\
-0.5
\end{array}
Initial program 54.0%
Taylor expanded in x around 0 47.5%
Final simplification47.5%
herbie shell --seed 2023283
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))