
(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 7 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
(let* ((t_0 (cbrt (sin x))))
(if (<= x 0.0066)
(+ (* 0.225 (* x x)) -0.5)
(/ (fma (pow t_0 2.0) t_0 (- x)) (- (tan x) x)))))x = abs(x);
double code(double x) {
double t_0 = cbrt(sin(x));
double tmp;
if (x <= 0.0066) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = fma(pow(t_0, 2.0), t_0, -x) / (tan(x) - x);
}
return tmp;
}
x = abs(x) function code(x) t_0 = cbrt(sin(x)) tmp = 0.0 if (x <= 0.0066) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(fma((t_0 ^ 2.0), t_0, Float64(-x)) / Float64(tan(x) - x)); end return tmp end
NOTE: x should be positive before calling this function
code[x_] := Block[{t$95$0 = N[Power[N[Sin[x], $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 0.0066], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] * t$95$0 + (-x)), $MachinePrecision] / N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := \sqrt[3]{\sin x}\\
\mathbf{if}\;x \leq 0.0066:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left({t_0}^{2}, t_0, -x\right)}{\tan x - x}\\
\end{array}
\end{array}
if x < 0.0066Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 65.6%
fma-neg65.6%
unpow265.6%
metadata-eval65.6%
Simplified65.6%
fma-udef65.6%
Applied egg-rr65.6%
if 0.0066 < 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%
add-cube-cbrt100.0%
fma-neg100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification74.8%
NOTE: x should be positive before calling this function
(FPCore (x)
:precision binary64
(let* ((t_0 (- (tan x) x)))
(if (<= x 0.0048)
(+ (* 0.225 (* x x)) -0.5)
(- (/ (sin x) t_0) (/ x t_0)))))x = abs(x);
double code(double x) {
double t_0 = tan(x) - x;
double tmp;
if (x <= 0.0048) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (sin(x) / t_0) - (x / t_0);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = tan(x) - x
if (x <= 0.0048d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = (sin(x) / t_0) - (x / t_0)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double t_0 = Math.tan(x) - x;
double tmp;
if (x <= 0.0048) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (Math.sin(x) / t_0) - (x / t_0);
}
return tmp;
}
x = abs(x) def code(x): t_0 = math.tan(x) - x tmp = 0 if x <= 0.0048: tmp = (0.225 * (x * x)) + -0.5 else: tmp = (math.sin(x) / t_0) - (x / t_0) return tmp
x = abs(x) function code(x) t_0 = Float64(tan(x) - x) tmp = 0.0 if (x <= 0.0048) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(Float64(sin(x) / t_0) - Float64(x / t_0)); end return tmp end
x = abs(x) function tmp_2 = code(x) t_0 = tan(x) - x; tmp = 0.0; if (x <= 0.0048) tmp = (0.225 * (x * x)) + -0.5; else tmp = (sin(x) / t_0) - (x / t_0); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function
code[x_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, 0.0048], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := \tan x - x\\
\mathbf{if}\;x \leq 0.0048:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x}{t_0} - \frac{x}{t_0}\\
\end{array}
\end{array}
if x < 0.00479999999999999958Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 65.6%
fma-neg65.6%
unpow265.6%
metadata-eval65.6%
Simplified65.6%
fma-udef65.6%
Applied egg-rr65.6%
if 0.00479999999999999958 < 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-sub100.0%
Applied egg-rr100.0%
Final simplification74.8%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0044) (+ (* 0.225 (* x x)) -0.5) (/ 1.0 (/ (- (tan x) x) (- (sin x) x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((tan(x) - 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 <= 0.0044d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = 1.0d0 / ((tan(x) - x) / (sin(x) - x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((Math.tan(x) - x) / (Math.sin(x) - x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0044: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 / ((math.tan(x) - x) / (math.sin(x) - x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0044) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(1.0 / Float64(Float64(tan(x) - x) / Float64(sin(x) - x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0044) tmp = (0.225 * (x * x)) + -0.5; else tmp = 1.0 / ((tan(x) - x) / (sin(x) - x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0044], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(1.0 / N[(N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0044:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\tan x - x}{\sin x - x}}\\
\end{array}
\end{array}
if x < 0.00440000000000000027Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 65.6%
fma-neg65.6%
unpow265.6%
metadata-eval65.6%
Simplified65.6%
fma-udef65.6%
Applied egg-rr65.6%
if 0.00440000000000000027 < 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%
clear-num100.0%
associate-/r/99.7%
Applied egg-rr99.7%
add-cube-cbrt100.0%
fma-neg100.0%
pow2100.0%
Applied egg-rr99.7%
*-commutative99.7%
fma-udef99.7%
unpow299.7%
add-cube-cbrt99.7%
sub-neg99.7%
pow199.7%
metadata-eval99.7%
pow-pow49.9%
div-inv50.0%
clear-num50.0%
pow-pow100.0%
metadata-eval100.0%
pow1100.0%
Applied egg-rr100.0%
Final simplification74.8%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0044) (+ (* 0.225 (* x x)) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = (0.225 * (x * x)) + -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 = (0.225d0 * (x * x)) + (-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 = (0.225 * (x * x)) + -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 = (0.225 * (x * x)) + -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(0.225 * Float64(x * x)) + -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 = (0.225 * (x * x)) + -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[(0.225 * N[(x * x), $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:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.00440000000000000027Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 65.6%
fma-neg65.6%
unpow265.6%
metadata-eval65.6%
Simplified65.6%
fma-udef65.6%
Applied egg-rr65.6%
if 0.00440000000000000027 < x Initial program 100.0%
Final simplification74.8%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 4.5) (+ (* 0.225 (* x x)) -0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 4.5) {
tmp = (0.225 * (x * x)) + -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 <= 4.5d0) then
tmp = (0.225d0 * (x * x)) + (-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 <= 4.5) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 4.5: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 4.5) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 4.5) tmp = (0.225 * (x * x)) + -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, 4.5], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.5:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 4.5Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 65.6%
fma-neg65.6%
unpow265.6%
metadata-eval65.6%
Simplified65.6%
fma-udef65.6%
Applied egg-rr65.6%
if 4.5 < 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.7%
Final simplification74.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.56) -0.5 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.56) {
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.56d0) 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.56) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.56: tmp = -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.56) 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.56) 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.56], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.56:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.5600000000000001Initial program 36.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
sub-neg36.5%
+-commutative36.5%
neg-sub036.5%
associate-+l-36.5%
sub0-neg36.5%
neg-mul-136.5%
times-frac36.5%
metadata-eval36.5%
*-lft-identity36.5%
Simplified36.5%
Taylor expanded in x around 0 64.4%
if 1.5600000000000001 < 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.7%
Final simplification73.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 53.3%
sub-neg53.3%
+-commutative53.3%
neg-sub053.3%
associate-+l-53.3%
sub0-neg53.3%
neg-mul-153.3%
sub-neg53.3%
+-commutative53.3%
neg-sub053.3%
associate-+l-53.3%
sub0-neg53.3%
neg-mul-153.3%
times-frac53.3%
metadata-eval53.3%
*-lft-identity53.3%
Simplified53.3%
Taylor expanded in x around 0 47.7%
Final simplification47.7%
herbie shell --seed 2023224
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))