
(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.027) (+ (fma 0.225 (* x x) (* -0.009642857142857142 (pow x 4.0))) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.027) {
tmp = fma(0.225, (x * x), (-0.009642857142857142 * pow(x, 4.0))) + -0.5;
} else {
tmp = (x - sin(x)) / (x - tan(x));
}
return tmp;
}
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.027) tmp = Float64(fma(0.225, Float64(x * x), Float64(-0.009642857142857142 * (x ^ 4.0))) + -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.027], N[(N[(0.225 * N[(x * x), $MachinePrecision] + N[(-0.009642857142857142 * N[Power[x, 4.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.027:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.009642857142857142 \cdot {x}^{4}\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.0269999999999999997Initial program 34.6%
sub-neg34.6%
+-commutative34.6%
neg-sub034.6%
associate-+l-34.6%
sub0-neg34.6%
neg-mul-134.6%
sub-neg34.6%
+-commutative34.6%
neg-sub034.6%
associate-+l-34.6%
sub0-neg34.6%
neg-mul-134.6%
times-frac34.6%
metadata-eval34.6%
*-lft-identity34.6%
Simplified34.6%
Taylor expanded in x around 0 67.1%
sub-neg67.1%
fma-def67.1%
unpow267.1%
metadata-eval67.1%
Simplified67.1%
if 0.0269999999999999997 < x Initial program 99.7%
Final simplification74.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.4) (+ -0.5 (* x (* x 0.225))) (+ 1.0 (/ (- (tan x) (sin x)) x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = -0.5 + (x * (x * 0.225));
} 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 = (-0.5d0) + (x * (x * 0.225d0))
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 = -0.5 + (x * (x * 0.225));
} 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 = -0.5 + (x * (x * 0.225)) 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(-0.5 + Float64(x * Float64(x * 0.225))); 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 = -0.5 + (x * (x * 0.225)); 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[(-0.5 + N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision]), $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:\\
\;\;\;\;-0.5 + x \cdot \left(x \cdot 0.225\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.39999999999999991Initial program 35.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
times-frac35.2%
metadata-eval35.2%
*-lft-identity35.2%
Simplified35.2%
Taylor expanded in x around 0 68.0%
fma-neg68.0%
unpow268.0%
metadata-eval68.0%
Simplified68.0%
fma-udef68.0%
associate-*r*68.0%
Applied egg-rr68.0%
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.5%
associate--l+99.5%
associate-*r/99.5%
associate-/r*99.5%
associate-*r/99.5%
div-sub99.5%
distribute-lft-out--99.5%
associate-*r/99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
tan-quot99.5%
sub-neg99.5%
Applied egg-rr99.5%
sub-neg99.5%
Simplified99.5%
Final simplification75.0%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0044) (+ -0.5 (* x (* x 0.225))) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
tmp = -0.5 + (x * (x * 0.225));
} 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.5d0) + (x * (x * 0.225d0))
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.5 + (x * (x * 0.225));
} 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.5 + (x * (x * 0.225)) 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(-0.5 + Float64(x * Float64(x * 0.225))); 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.5 + (x * (x * 0.225)); 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[(-0.5 + N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision]), $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.5 + x \cdot \left(x \cdot 0.225\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.00440000000000000027Initial program 34.6%
sub-neg34.6%
+-commutative34.6%
neg-sub034.6%
associate-+l-34.6%
sub0-neg34.6%
neg-mul-134.6%
sub-neg34.6%
+-commutative34.6%
neg-sub034.6%
associate-+l-34.6%
sub0-neg34.6%
neg-mul-134.6%
times-frac34.6%
metadata-eval34.6%
*-lft-identity34.6%
Simplified34.6%
Taylor expanded in x around 0 68.3%
fma-neg68.3%
unpow268.3%
metadata-eval68.3%
Simplified68.3%
fma-udef68.3%
associate-*r*68.3%
Applied egg-rr68.3%
if 0.00440000000000000027 < x Initial program 99.7%
Final simplification75.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.6) (+ -0.5 (* x (* x 0.225))) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.6) {
tmp = -0.5 + (x * (x * 0.225));
} 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.5d0) + (x * (x * 0.225d0))
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.5 + (x * (x * 0.225));
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.6: tmp = -0.5 + (x * (x * 0.225)) else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.6) tmp = Float64(-0.5 + Float64(x * Float64(x * 0.225))); 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.5 + (x * (x * 0.225)); 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[(-0.5 + N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.6:\\
\;\;\;\;-0.5 + x \cdot \left(x \cdot 0.225\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.60000000000000009Initial program 35.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
times-frac35.2%
metadata-eval35.2%
*-lft-identity35.2%
Simplified35.2%
Taylor expanded in x around 0 68.0%
fma-neg68.0%
unpow268.0%
metadata-eval68.0%
Simplified68.0%
fma-udef68.0%
associate-*r*68.0%
Applied egg-rr68.0%
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.0%
Final simplification74.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.58) -0.5 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.58) {
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.58d0) 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.58) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.58: tmp = -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.58) 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.58) 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.58], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.58:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.5800000000000001Initial program 35.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
sub-neg35.2%
+-commutative35.2%
neg-sub035.2%
associate-+l-35.2%
sub0-neg35.2%
neg-mul-135.2%
times-frac35.2%
metadata-eval35.2%
*-lft-identity35.2%
Simplified35.2%
Taylor expanded in x around 0 66.0%
if 1.5800000000000001 < 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.0%
Final simplification73.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 49.6%
sub-neg49.6%
+-commutative49.6%
neg-sub049.6%
associate-+l-49.6%
sub0-neg49.6%
neg-mul-149.6%
sub-neg49.6%
+-commutative49.6%
neg-sub049.6%
associate-+l-49.6%
sub0-neg49.6%
neg-mul-149.6%
times-frac49.6%
metadata-eval49.6%
*-lft-identity49.6%
Simplified49.6%
Taylor expanded in x around 0 51.7%
Final simplification51.7%
herbie shell --seed 2023278
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))