
(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}
(FPCore (x)
:precision binary64
(let* ((t_0 (- (tan x) x)))
(if (<= (/ (- x (sin x)) (- x (tan x))) 2.0)
(- (/ (sin x) t_0) (/ x t_0))
-0.5)))
double code(double x) {
double t_0 = tan(x) - x;
double tmp;
if (((x - sin(x)) / (x - tan(x))) <= 2.0) {
tmp = (sin(x) / t_0) - (x / t_0);
} else {
tmp = -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = tan(x) - x
if (((x - sin(x)) / (x - tan(x))) <= 2.0d0) then
tmp = (sin(x) / t_0) - (x / t_0)
else
tmp = -0.5d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.tan(x) - x;
double tmp;
if (((x - Math.sin(x)) / (x - Math.tan(x))) <= 2.0) {
tmp = (Math.sin(x) / t_0) - (x / t_0);
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): t_0 = math.tan(x) - x tmp = 0 if ((x - math.sin(x)) / (x - math.tan(x))) <= 2.0: tmp = (math.sin(x) / t_0) - (x / t_0) else: tmp = -0.5 return tmp
function code(x) t_0 = Float64(tan(x) - x) tmp = 0.0 if (Float64(Float64(x - sin(x)) / Float64(x - tan(x))) <= 2.0) tmp = Float64(Float64(sin(x) / t_0) - Float64(x / t_0)); else tmp = -0.5; end return tmp end
function tmp_2 = code(x) t_0 = tan(x) - x; tmp = 0.0; if (((x - sin(x)) / (x - tan(x))) <= 2.0) tmp = (sin(x) / t_0) - (x / t_0); else tmp = -0.5; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision], -0.5]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x - x\\
\mathbf{if}\;\frac{x - \sin x}{x - \tan x} \leq 2:\\
\;\;\;\;\frac{\sin x}{t_0} - \frac{x}{t_0}\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\end{array}
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
div-sub100.0%
Applied egg-rr100.0%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
times-frac0.0%
metadata-eval0.0%
*-lft-identity0.0%
Simplified0.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= (/ (- x (sin x)) (- x (tan x))) 2.0) (pow (/ (- (tan x) x) (- (sin x) x)) -1.0) -0.5))
double code(double x) {
double tmp;
if (((x - sin(x)) / (x - tan(x))) <= 2.0) {
tmp = pow(((tan(x) - x) / (sin(x) - x)), -1.0);
} else {
tmp = -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x - sin(x)) / (x - tan(x))) <= 2.0d0) then
tmp = ((tan(x) - x) / (sin(x) - x)) ** (-1.0d0)
else
tmp = -0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x - Math.sin(x)) / (x - Math.tan(x))) <= 2.0) {
tmp = Math.pow(((Math.tan(x) - x) / (Math.sin(x) - x)), -1.0);
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): tmp = 0 if ((x - math.sin(x)) / (x - math.tan(x))) <= 2.0: tmp = math.pow(((math.tan(x) - x) / (math.sin(x) - x)), -1.0) else: tmp = -0.5 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x - sin(x)) / Float64(x - tan(x))) <= 2.0) tmp = Float64(Float64(tan(x) - x) / Float64(sin(x) - x)) ^ -1.0; else tmp = -0.5; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x - sin(x)) / (x - tan(x))) <= 2.0) tmp = ((tan(x) - x) / (sin(x) - x)) ^ -1.0; else tmp = -0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[Power[N[(N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], -0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x - \sin x}{x - \tan x} \leq 2:\\
\;\;\;\;{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\end{array}
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
times-frac0.0%
metadata-eval0.0%
*-lft-identity0.0%
Simplified0.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x (sin x)) (- x (tan x))))) (if (<= t_0 2.0) t_0 -0.5)))
double code(double x) {
double t_0 = (x - sin(x)) / (x - tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x - sin(x)) / (x - tan(x))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = -0.5d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x - Math.sin(x)) / (x - Math.tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): t_0 = (x - math.sin(x)) / (x - math.tan(x)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = -0.5 return tmp
function code(x) t_0 = Float64(Float64(x - sin(x)) / Float64(x - tan(x))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = -0.5; end return tmp end
function tmp_2 = code(x) t_0 = (x - sin(x)) / (x - tan(x)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = -0.5; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, -0.5]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - \sin x}{x - \tan x}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\end{array}
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 100.0%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
times-frac0.0%
metadata-eval0.0%
*-lft-identity0.0%
Simplified0.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x 1.55) -0.5 (- (/ 3.0 (* x x)) (/ x (- (tan x) x)))))
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = (3.0 / (x * x)) - (x / (tan(x) - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = -0.5d0
else
tmp = (3.0d0 / (x * x)) - (x / (tan(x) - x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = (3.0 / (x * x)) - (x / (Math.tan(x) - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.55: tmp = -0.5 else: tmp = (3.0 / (x * x)) - (x / (math.tan(x) - x)) return tmp
function code(x) tmp = 0.0 if (x <= 1.55) tmp = -0.5; else tmp = Float64(Float64(3.0 / Float64(x * x)) - Float64(x / Float64(tan(x) - x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = -0.5; else tmp = (3.0 / (x * x)) - (x / (tan(x) - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.55], -0.5, N[(N[(3.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] - N[(x / N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{3}{x \cdot x} - \frac{x}{\tan x - x}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 35.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
times-frac35.8%
metadata-eval35.8%
*-lft-identity35.8%
Simplified35.8%
Taylor expanded in x around 0 64.7%
if 1.55000000000000004 < x Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
times-frac99.9%
metadata-eval99.9%
*-lft-identity99.9%
Simplified99.9%
div-sub100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.2%
unpow299.2%
Simplified99.2%
Final simplification74.0%
(FPCore (x) :precision binary64 (if (<= x 1.55) -0.5 (/ (- x (sin x)) x)))
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = (x - sin(x)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = -0.5d0
else
tmp = (x - sin(x)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = (x - Math.sin(x)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.55: tmp = -0.5 else: tmp = (x - math.sin(x)) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.55) tmp = -0.5; else tmp = Float64(Float64(x - sin(x)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = -0.5; else tmp = (x - sin(x)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.55], -0.5, N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x}\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 35.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
times-frac35.8%
metadata-eval35.8%
*-lft-identity35.8%
Simplified35.8%
Taylor expanded in x around 0 64.7%
if 1.55000000000000004 < x Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
times-frac99.9%
metadata-eval99.9%
*-lft-identity99.9%
Simplified99.9%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
Simplified99.1%
frac-2neg99.1%
div-inv98.9%
sub-neg98.9%
distribute-neg-in98.9%
remove-double-neg98.9%
remove-double-neg98.9%
Applied egg-rr98.9%
associate-*r/99.1%
*-rgt-identity99.1%
+-commutative99.1%
unsub-neg99.1%
Simplified99.1%
Final simplification74.0%
(FPCore (x) :precision binary64 (if (<= x 1.55) -0.5 1.0))
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = -0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.55: tmp = -0.5 else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.55) tmp = -0.5; else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.55], -0.5, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 35.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
sub-neg35.8%
+-commutative35.8%
neg-sub035.8%
associate-+l-35.8%
sub0-neg35.8%
neg-mul-135.8%
times-frac35.8%
metadata-eval35.8%
*-lft-identity35.8%
Simplified35.8%
Taylor expanded in x around 0 64.7%
if 1.55000000000000004 < x Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
sub-neg99.9%
+-commutative99.9%
neg-sub099.9%
associate-+l-99.9%
sub0-neg99.9%
neg-mul-199.9%
times-frac99.9%
metadata-eval99.9%
*-lft-identity99.9%
Simplified99.9%
Taylor expanded in x around inf 99.1%
Final simplification74.0%
(FPCore (x) :precision binary64 -0.5)
double code(double x) {
return -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -0.5d0
end function
public static double code(double x) {
return -0.5;
}
def code(x): return -0.5
function code(x) return -0.5 end
function tmp = code(x) tmp = -0.5; end
code[x_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 53.1%
sub-neg53.1%
+-commutative53.1%
neg-sub053.1%
associate-+l-53.1%
sub0-neg53.1%
neg-mul-153.1%
sub-neg53.1%
+-commutative53.1%
neg-sub053.1%
associate-+l-53.1%
sub0-neg53.1%
neg-mul-153.1%
times-frac53.1%
metadata-eval53.1%
*-lft-identity53.1%
Simplified53.1%
Taylor expanded in x around 0 47.7%
Final simplification47.7%
herbie shell --seed 2023261
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))