
(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.092)
(-
(+
(* 0.225 (pow x 2.0))
(+
(* -0.009642857142857142 (pow x 4.0))
(* 0.00024107142857142857 (pow x 6.0))))
0.5)
(/ (- x (sin x)) (- x (tan x)))))x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.092) {
tmp = ((0.225 * pow(x, 2.0)) + ((-0.009642857142857142 * pow(x, 4.0)) + (0.00024107142857142857 * pow(x, 6.0)))) - 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.092d0) then
tmp = ((0.225d0 * (x ** 2.0d0)) + (((-0.009642857142857142d0) * (x ** 4.0d0)) + (0.00024107142857142857d0 * (x ** 6.0d0)))) - 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.092) {
tmp = ((0.225 * Math.pow(x, 2.0)) + ((-0.009642857142857142 * Math.pow(x, 4.0)) + (0.00024107142857142857 * Math.pow(x, 6.0)))) - 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.092: tmp = ((0.225 * math.pow(x, 2.0)) + ((-0.009642857142857142 * math.pow(x, 4.0)) + (0.00024107142857142857 * math.pow(x, 6.0)))) - 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.092) tmp = Float64(Float64(Float64(0.225 * (x ^ 2.0)) + Float64(Float64(-0.009642857142857142 * (x ^ 4.0)) + Float64(0.00024107142857142857 * (x ^ 6.0)))) - 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.092) tmp = ((0.225 * (x ^ 2.0)) + ((-0.009642857142857142 * (x ^ 4.0)) + (0.00024107142857142857 * (x ^ 6.0)))) - 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.092], N[(N[(N[(0.225 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.009642857142857142 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.00024107142857142857 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $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.092:\\
\;\;\;\;\left(0.225 \cdot {x}^{2} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.091999999999999998Initial program 30.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
times-frac30.4%
metadata-eval30.4%
*-lft-identity30.4%
Simplified30.4%
Taylor expanded in x around 0 72.1%
if 0.091999999999999998 < x Initial program 100.0%
Final simplification79.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.4) (+ (* x (* x 0.225)) -0.5) (+ 1.0 (/ (- (tan x) (sin x)) x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = (x * (x * 0.225)) + -0.5;
} else {
tmp = 1.0 + ((tan(x) - sin(x)) / 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 <= 2.4d0) then
tmp = (x * (x * 0.225d0)) + (-0.5d0)
else
tmp = 1.0d0 + ((tan(x) - sin(x)) / x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = (x * (x * 0.225)) + -0.5;
} else {
tmp = 1.0 + ((Math.tan(x) - Math.sin(x)) / x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.4: tmp = (x * (x * 0.225)) + -0.5 else: tmp = 1.0 + ((math.tan(x) - math.sin(x)) / x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.4) tmp = Float64(Float64(x * Float64(x * 0.225)) + -0.5); else tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.4) tmp = (x * (x * 0.225)) + -0.5; else tmp = 1.0 + ((tan(x) - sin(x)) / x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.4], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $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.4:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.39999999999999991Initial program 30.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
times-frac30.4%
metadata-eval30.4%
*-lft-identity30.4%
Simplified30.4%
Taylor expanded in x around 0 72.7%
fma-neg72.7%
unpow272.7%
metadata-eval72.7%
Simplified72.7%
fma-udef72.7%
*-commutative72.7%
associate-*l*72.7%
Applied egg-rr72.7%
if 2.39999999999999991 < 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.6%
associate--l+99.6%
associate-*r/99.6%
associate-/r*99.6%
associate-*r/99.6%
div-sub99.6%
distribute-lft-out--99.6%
associate-*r/99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
tan-quot99.6%
sub-neg99.6%
Applied egg-rr99.6%
sub-neg99.6%
Simplified99.6%
Final simplification79.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0045) (+ (* x (* x 0.225)) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0045) {
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.0045d0) 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.0045) {
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.0045: 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.0045) 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.0045) 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.0045], 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.0045:\\
\;\;\;\;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.00449999999999999966Initial program 30.1%
sub-neg30.1%
+-commutative30.1%
neg-sub030.1%
associate-+l-30.1%
sub0-neg30.1%
neg-mul-130.1%
sub-neg30.1%
+-commutative30.1%
neg-sub030.1%
associate-+l-30.1%
sub0-neg30.1%
neg-mul-130.1%
times-frac30.1%
metadata-eval30.1%
*-lft-identity30.1%
Simplified30.1%
Taylor expanded in x around 0 72.8%
fma-neg72.8%
unpow272.8%
metadata-eval72.8%
Simplified72.8%
fma-udef72.8%
*-commutative72.8%
associate-*l*72.8%
Applied egg-rr72.8%
if 0.00449999999999999966 < x Initial program 99.7%
Final simplification79.8%
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 30.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
times-frac30.4%
metadata-eval30.4%
*-lft-identity30.4%
Simplified30.4%
Taylor expanded in x around 0 72.7%
fma-neg72.7%
unpow272.7%
metadata-eval72.7%
Simplified72.7%
fma-udef72.7%
*-commutative72.7%
associate-*l*72.7%
Applied egg-rr72.7%
if 2.60000000000000009 < 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 98.2%
Final simplification79.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.55) -0.5 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.55) {
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.55d0) 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.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.55: tmp = -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.55) 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.55) 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.55], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 30.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
sub-neg30.4%
+-commutative30.4%
neg-sub030.4%
associate-+l-30.4%
sub0-neg30.4%
neg-mul-130.4%
times-frac30.4%
metadata-eval30.4%
*-lft-identity30.4%
Simplified30.4%
Taylor expanded in x around 0 71.3%
if 1.55000000000000004 < 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 98.2%
Final simplification78.1%
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.1%
sub-neg48.1%
+-commutative48.1%
neg-sub048.1%
associate-+l-48.1%
sub0-neg48.1%
neg-mul-148.1%
sub-neg48.1%
+-commutative48.1%
neg-sub048.1%
associate-+l-48.1%
sub0-neg48.1%
neg-mul-148.1%
times-frac48.1%
metadata-eval48.1%
*-lft-identity48.1%
Simplified48.1%
Taylor expanded in x around 0 53.6%
Final simplification53.6%
herbie shell --seed 2023192
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))