
(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 6 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.0044) (fma 0.225 (* x x) -0.5) (/ (- (sin x) x) (fma (sin x) (/ 1.0 (cos x)) (- x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = (sin(x) - x) / fma(sin(x), (1.0 / cos(x)), -x);
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0044) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(Float64(sin(x) - x) / fma(sin(x), Float64(1.0 / cos(x)), Float64(-x))); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0044], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] * N[(1.0 / N[Cos[x], $MachinePrecision]), $MachinePrecision] + (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0044:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x - x}{\mathsf{fma}\left(\sin x, \frac{1}{\cos x}, -x\right)}\\
\end{array}
\end{array}
if x < 0.00440000000000000027Initial program 34.4%
sub-neg34.4%
+-commutative34.4%
neg-sub034.4%
associate-+l-34.4%
sub0-neg34.4%
neg-mul-134.4%
sub-neg34.4%
+-commutative34.4%
neg-sub034.4%
associate-+l-34.4%
sub0-neg34.4%
neg-mul-134.4%
times-frac34.4%
metadata-eval34.4%
*-lft-identity34.4%
Simplified34.4%
Taylor expanded in x around 0 67.3%
fma-neg67.3%
unpow267.3%
metadata-eval67.3%
Simplified67.3%
if 0.00440000000000000027 < 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%
tan-quot99.9%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification74.3%
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 34.4%
sub-neg34.4%
+-commutative34.4%
neg-sub034.4%
associate-+l-34.4%
sub0-neg34.4%
neg-mul-134.4%
sub-neg34.4%
+-commutative34.4%
neg-sub034.4%
associate-+l-34.4%
sub0-neg34.4%
neg-mul-134.4%
times-frac34.4%
metadata-eval34.4%
*-lft-identity34.4%
Simplified34.4%
Taylor expanded in x around 0 67.3%
fma-neg67.3%
unpow267.3%
metadata-eval67.3%
Simplified67.3%
if 0.00479999999999999958 < x Initial program 99.9%
Final simplification74.3%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.9) (fma 0.225 (* x x) -0.5) (- (/ 3.0 (* x x)) -1.0)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.9) {
tmp = fma(0.225, (x * x), -0.5);
} else {
tmp = (3.0 / (x * x)) - -1.0;
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.9) tmp = fma(0.225, Float64(x * x), -0.5); else tmp = Float64(Float64(3.0 / Float64(x * x)) - -1.0); end return tmp end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.9], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(3.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.9:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{3}{x \cdot x} - -1\\
\end{array}
\end{array}
if x < 2.89999999999999991Initial program 34.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
times-frac34.7%
metadata-eval34.7%
*-lft-identity34.7%
Simplified34.7%
Taylor expanded in x around 0 67.1%
fma-neg67.1%
unpow267.1%
metadata-eval67.1%
Simplified67.1%
if 2.89999999999999991 < 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%
div-sub99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 99.2%
unpow299.2%
Simplified99.2%
Taylor expanded in x around inf 99.2%
Final simplification73.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.6) -0.5 (- (/ 3.0 (* x x)) -1.0)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.6) {
tmp = -0.5;
} else {
tmp = (3.0 / (x * x)) - -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 = (3.0d0 / (x * x)) - (-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 = (3.0 / (x * x)) - -1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.6: tmp = -0.5 else: tmp = (3.0 / (x * x)) - -1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.6) tmp = -0.5; else tmp = Float64(Float64(3.0 / Float64(x * x)) - -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 = (3.0 / (x * x)) - -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, N[(N[(3.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{3}{x \cdot x} - -1\\
\end{array}
\end{array}
if x < 1.6000000000000001Initial program 34.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
times-frac34.7%
metadata-eval34.7%
*-lft-identity34.7%
Simplified34.7%
Taylor expanded in x around 0 66.0%
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%
div-sub99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 99.2%
unpow299.2%
Simplified99.2%
Taylor expanded in x around inf 99.2%
Final simplification73.0%
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 34.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
sub-neg34.7%
+-commutative34.7%
neg-sub034.7%
associate-+l-34.7%
sub0-neg34.7%
neg-mul-134.7%
times-frac34.7%
metadata-eval34.7%
*-lft-identity34.7%
Simplified34.7%
Taylor expanded in x around 0 66.0%
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 99.2%
Final simplification73.0%
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 48.5%
sub-neg48.5%
+-commutative48.5%
neg-sub048.5%
associate-+l-48.5%
sub0-neg48.5%
neg-mul-148.5%
sub-neg48.5%
+-commutative48.5%
neg-sub048.5%
associate-+l-48.5%
sub0-neg48.5%
neg-mul-148.5%
times-frac48.5%
metadata-eval48.5%
*-lft-identity48.5%
Simplified48.5%
Taylor expanded in x around 0 52.4%
Final simplification52.4%
herbie shell --seed 2023230
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))