
(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 4 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) (+ (* x (* x 0.225)) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = (x * (x * 0.225)) + -0.5;
} else {
tmp = (x - sin(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 <= 0.0044d0) then
tmp = (x * (x * 0.225d0)) + (-0.5d0)
else
tmp = (x - sin(x)) / (x - tan(x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = (x * (x * 0.225)) + -0.5;
} else {
tmp = (x - Math.sin(x)) / (x - Math.tan(x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0044: tmp = (x * (x * 0.225)) + -0.5 else: tmp = (x - math.sin(x)) / (x - math.tan(x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0044) tmp = Float64(Float64(x * Float64(x * 0.225)) + -0.5); else tmp = Float64(Float64(x - sin(x)) / Float64(x - tan(x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0044) tmp = (x * (x * 0.225)) + -0.5; else tmp = (x - sin(x)) / (x - tan(x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0044], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $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.0044:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.00440000000000000027Initial program 35.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
times-frac35.7%
metadata-eval35.7%
*-lft-identity35.7%
Simplified35.7%
Taylor expanded in x around 0 66.7%
fma-neg66.7%
unpow266.7%
metadata-eval66.7%
Simplified66.7%
fma-udef66.7%
associate-*r*66.7%
Applied egg-rr66.7%
if 0.00440000000000000027 < x Initial program 99.9%
Final simplification74.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.6) (+ (* x (* x 0.225)) -0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.6) {
tmp = (x * (x * 0.225)) + -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 <= 2.6d0) then
tmp = (x * (x * 0.225d0)) + (-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 <= 2.6) {
tmp = (x * (x * 0.225)) + -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.6: tmp = (x * (x * 0.225)) + -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.6) tmp = Float64(Float64(x * Float64(x * 0.225)) + -0.5); else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.6) tmp = (x * (x * 0.225)) + -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, 2.6], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.6:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.60000000000000009Initial program 35.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
times-frac35.7%
metadata-eval35.7%
*-lft-identity35.7%
Simplified35.7%
Taylor expanded in x around 0 66.7%
fma-neg66.7%
unpow266.7%
metadata-eval66.7%
Simplified66.7%
fma-udef66.7%
associate-*r*66.7%
Applied egg-rr66.7%
if 2.60000000000000009 < 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 96.5%
Final simplification73.7%
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 35.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
sub-neg35.7%
+-commutative35.7%
neg-sub035.7%
associate-+l-35.7%
sub0-neg35.7%
neg-mul-135.7%
times-frac35.7%
metadata-eval35.7%
*-lft-identity35.7%
Simplified35.7%
Taylor expanded in x around 0 65.4%
if 1.6000000000000001 < 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 96.5%
Final simplification72.7%
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 50.8%
sub-neg50.8%
+-commutative50.8%
neg-sub050.8%
associate-+l-50.8%
sub0-neg50.8%
neg-mul-150.8%
sub-neg50.8%
+-commutative50.8%
neg-sub050.8%
associate-+l-50.8%
sub0-neg50.8%
neg-mul-150.8%
times-frac50.8%
metadata-eval50.8%
*-lft-identity50.8%
Simplified50.8%
Taylor expanded in x around 0 50.4%
Final simplification50.4%
herbie shell --seed 2023229
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))