
(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 5 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 (if (<= x 0.0048) (fma 0.225 (* x x) -0.5) (pow (/ (- (tan x) x) (- (sin x) x)) -1.0)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0048) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = pow(((tan(x) - x) / (sin(x) - x)), -1.0);
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0048) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(Float64(tan(x) - x) / Float64(sin(x) - x)) ^ -1.0; end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0048], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[Power[N[(N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0048:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}\\
\end{array}
\end{array}
if x < 0.00479999999999999958Initial program 37.2%
sub-neg37.2%
+-commutative37.2%
neg-sub037.2%
associate-+l-37.2%
sub0-neg37.2%
neg-mul-137.2%
sub-neg37.2%
+-commutative37.2%
neg-sub037.2%
associate-+l-37.2%
sub0-neg37.2%
neg-mul-137.2%
times-frac37.2%
metadata-eval37.2%
*-lft-identity37.2%
Simplified37.2%
Taylor expanded in x around 0 65.2%
fma-neg65.2%
unpow265.2%
metadata-eval65.2%
Simplified65.2%
if 0.00479999999999999958 < 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%
clear-num99.9%
inv-pow99.8%
Applied egg-rr99.8%
Final simplification73.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0048) (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.0048) {
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.0048) 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.0048], 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.0048:\\
\;\;\;\;\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.00479999999999999958Initial program 37.2%
sub-neg37.2%
+-commutative37.2%
neg-sub037.2%
associate-+l-37.2%
sub0-neg37.2%
neg-mul-137.2%
sub-neg37.2%
+-commutative37.2%
neg-sub037.2%
associate-+l-37.2%
sub0-neg37.2%
neg-mul-137.2%
times-frac37.2%
metadata-eval37.2%
*-lft-identity37.2%
Simplified37.2%
Taylor expanded in x around 0 65.2%
fma-neg65.2%
unpow265.2%
metadata-eval65.2%
Simplified65.2%
if 0.00479999999999999958 < x Initial program 99.9%
Final simplification73.8%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.55) (fma 0.225 (* x x) -0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.55) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.55) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = 1.0; end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.55], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.55:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.5499999999999998Initial program 37.5%
sub-neg37.5%
+-commutative37.5%
neg-sub037.5%
associate-+l-37.5%
sub0-neg37.5%
neg-mul-137.5%
sub-neg37.5%
+-commutative37.5%
neg-sub037.5%
associate-+l-37.5%
sub0-neg37.5%
neg-mul-137.5%
times-frac37.5%
metadata-eval37.5%
*-lft-identity37.5%
Simplified37.5%
Taylor expanded in x around 0 65.1%
fma-neg65.1%
unpow265.1%
metadata-eval65.1%
Simplified65.1%
if 2.5499999999999998 < x Initial 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%
Taylor expanded in x around inf 100.0%
Final simplification73.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 37.5%
sub-neg37.5%
+-commutative37.5%
neg-sub037.5%
associate-+l-37.5%
sub0-neg37.5%
neg-mul-137.5%
sub-neg37.5%
+-commutative37.5%
neg-sub037.5%
associate-+l-37.5%
sub0-neg37.5%
neg-mul-137.5%
times-frac37.5%
metadata-eval37.5%
*-lft-identity37.5%
Simplified37.5%
Taylor expanded in x around 0 64.1%
if 1.6000000000000001 < x Initial 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%
Taylor expanded in x around inf 100.0%
Final simplification72.8%
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 52.6%
sub-neg52.6%
+-commutative52.6%
neg-sub052.6%
associate-+l-52.6%
sub0-neg52.6%
neg-mul-152.6%
sub-neg52.6%
+-commutative52.6%
neg-sub052.6%
associate-+l-52.6%
sub0-neg52.6%
neg-mul-152.6%
times-frac52.6%
metadata-eval52.6%
*-lft-identity52.6%
Simplified52.6%
Taylor expanded in x around 0 48.9%
Final simplification48.9%
herbie shell --seed 2023201
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))