
(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.03) (- (+ (* -0.009642857142857142 (pow x 4.0)) (* 0.225 (pow x 2.0))) 0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.03) {
tmp = ((-0.009642857142857142 * pow(x, 4.0)) + (0.225 * pow(x, 2.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.03d0) then
tmp = (((-0.009642857142857142d0) * (x ** 4.0d0)) + (0.225d0 * (x ** 2.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.03) {
tmp = ((-0.009642857142857142 * Math.pow(x, 4.0)) + (0.225 * Math.pow(x, 2.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.03: tmp = ((-0.009642857142857142 * math.pow(x, 4.0)) + (0.225 * math.pow(x, 2.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.03) tmp = Float64(Float64(Float64(-0.009642857142857142 * (x ^ 4.0)) + Float64(0.225 * (x ^ 2.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.03) tmp = ((-0.009642857142857142 * (x ^ 4.0)) + (0.225 * (x ^ 2.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.03], N[(N[(N[(-0.009642857142857142 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.225 * N[Power[x, 2.0], $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.03:\\
\;\;\;\;\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.029999999999999999Initial program 27.6%
/-rgt-identity27.6%
metadata-eval27.6%
associate-/r/27.6%
metadata-eval27.6%
metadata-eval27.6%
times-frac27.6%
*-commutative27.6%
*-commutative27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
Simplified27.6%
Taylor expanded in x around 0 73.1%
if 0.029999999999999999 < x Initial program 100.0%
Final simplification79.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0042) (- (* 0.225 (pow x 2.0)) 0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0042) {
tmp = (0.225 * pow(x, 2.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.0042d0) then
tmp = (0.225d0 * (x ** 2.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.0042) {
tmp = (0.225 * Math.pow(x, 2.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.0042: tmp = (0.225 * math.pow(x, 2.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.0042) tmp = Float64(Float64(0.225 * (x ^ 2.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.0042) tmp = (0.225 * (x ^ 2.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.0042], N[(N[(0.225 * N[Power[x, 2.0], $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.0042:\\
\;\;\;\;0.225 \cdot {x}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 27.6%
/-rgt-identity27.6%
metadata-eval27.6%
associate-/r/27.6%
metadata-eval27.6%
metadata-eval27.6%
times-frac27.6%
*-commutative27.6%
*-commutative27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
Simplified27.6%
Taylor expanded in x around 0 74.0%
if 0.00419999999999999974 < x Initial program 100.0%
Final simplification80.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.6) (- (* 0.225 (pow x 2.0)) 0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.6) {
tmp = (0.225 * pow(x, 2.0)) - 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 = (0.225d0 * (x ** 2.0d0)) - 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 = (0.225 * Math.pow(x, 2.0)) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.6: tmp = (0.225 * math.pow(x, 2.0)) - 0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.6) tmp = Float64(Float64(0.225 * (x ^ 2.0)) - 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 = (0.225 * (x ^ 2.0)) - 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[(0.225 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.6:\\
\;\;\;\;0.225 \cdot {x}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.60000000000000009Initial program 27.6%
/-rgt-identity27.6%
metadata-eval27.6%
associate-/r/27.6%
metadata-eval27.6%
metadata-eval27.6%
times-frac27.6%
*-commutative27.6%
*-commutative27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
Simplified27.6%
Taylor expanded in x around 0 74.0%
if 2.60000000000000009 < x Initial program 100.0%
/-rgt-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
metadata-eval100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
Final simplification80.3%
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 27.6%
/-rgt-identity27.6%
metadata-eval27.6%
associate-/r/27.6%
metadata-eval27.6%
metadata-eval27.6%
times-frac27.6%
*-commutative27.6%
*-commutative27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
neg-mul-127.6%
neg-sub027.6%
associate-+l-27.6%
neg-sub027.6%
+-commutative27.6%
unsub-neg27.6%
Simplified27.6%
Taylor expanded in x around 0 73.0%
if 1.55000000000000004 < x Initial program 100.0%
/-rgt-identity100.0%
metadata-eval100.0%
associate-/r/100.0%
metadata-eval100.0%
metadata-eval100.0%
times-frac100.0%
*-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
Final simplification79.5%
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 45.4%
/-rgt-identity45.4%
metadata-eval45.4%
associate-/r/45.4%
metadata-eval45.4%
metadata-eval45.4%
times-frac45.4%
*-commutative45.4%
*-commutative45.4%
neg-mul-145.4%
neg-sub045.4%
associate-+l-45.4%
neg-sub045.4%
+-commutative45.4%
unsub-neg45.4%
neg-mul-145.4%
neg-sub045.4%
associate-+l-45.4%
neg-sub045.4%
+-commutative45.4%
unsub-neg45.4%
Simplified45.4%
Taylor expanded in x around 0 55.4%
Final simplification55.4%
herbie shell --seed 2023310
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))