| Alternative 1 | |
|---|---|
| Error | 1.31% |
| Cost | 7049 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \lor \neg \left(x \leq 1.45\right):\\
\;\;\;\;\frac{-x}{\tan x - x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x) :precision binary64 (if (or (<= x -0.0045) (not (<= x 0.0053))) (/ (- x (sin x)) (- x (tan x))) (+ (* x (* x 0.225)) -0.5)))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
double tmp;
if ((x <= -0.0045) || !(x <= 0.0053)) {
tmp = (x - sin(x)) / (x - tan(x));
} else {
tmp = (x * (x * 0.225)) + -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / (x - tan(x))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.0045d0)) .or. (.not. (x <= 0.0053d0))) then
tmp = (x - sin(x)) / (x - tan(x))
else
tmp = (x * (x * 0.225d0)) + (-0.5d0)
end if
code = tmp
end function
public static double code(double x) {
return (x - Math.sin(x)) / (x - Math.tan(x));
}
public static double code(double x) {
double tmp;
if ((x <= -0.0045) || !(x <= 0.0053)) {
tmp = (x - Math.sin(x)) / (x - Math.tan(x));
} else {
tmp = (x * (x * 0.225)) + -0.5;
}
return tmp;
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
def code(x): tmp = 0 if (x <= -0.0045) or not (x <= 0.0053): tmp = (x - math.sin(x)) / (x - math.tan(x)) else: tmp = (x * (x * 0.225)) + -0.5 return tmp
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function code(x) tmp = 0.0 if ((x <= -0.0045) || !(x <= 0.0053)) tmp = Float64(Float64(x - sin(x)) / Float64(x - tan(x))); else tmp = Float64(Float64(x * Float64(x * 0.225)) + -0.5); end return tmp end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.0045) || ~((x <= 0.0053))) tmp = (x - sin(x)) / (x - tan(x)); else tmp = (x * (x * 0.225)) + -0.5; end tmp_2 = tmp; end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[Or[LessEqual[x, -0.0045], N[Not[LessEqual[x, 0.0053]], $MachinePrecision]], N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.0045 \lor \neg \left(x \leq 0.0053\right):\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\
\end{array}
Results
if x < -0.00449999999999999966 or 0.00530000000000000002 < x Initial program 0.12
if -0.00449999999999999966 < x < 0.00530000000000000002Initial program 98.83
Simplified98.83
[Start]98.83 | \[ \frac{x - \sin x}{x - \tan x}
\] |
|---|---|
sub-neg [=>]98.83 | \[ \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x}
\] |
+-commutative [=>]98.83 | \[ \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x}
\] |
neg-sub0 [=>]98.83 | \[ \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x}
\] |
associate-+l- [=>]98.83 | \[ \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x}
\] |
sub0-neg [=>]98.83 | \[ \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x}
\] |
neg-mul-1 [=>]98.83 | \[ \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x}
\] |
sub-neg [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}}
\] |
+-commutative [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}}
\] |
neg-sub0 [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x}
\] |
associate-+l- [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}}
\] |
sub0-neg [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}}
\] |
neg-mul-1 [=>]98.83 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}}
\] |
times-frac [=>]98.83 | \[ \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}}
\] |
metadata-eval [=>]98.83 | \[ \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x}
\] |
*-lft-identity [=>]98.83 | \[ \color{blue}{\frac{\sin x - x}{\tan x - x}}
\] |
Taylor expanded in x around 0 0.08
Simplified0.08
[Start]0.08 | \[ 0.225 \cdot {x}^{2} - 0.5
\] |
|---|---|
unpow2 [=>]0.08 | \[ 0.225 \cdot \color{blue}{\left(x \cdot x\right)} - 0.5
\] |
fma-neg [=>]0.08 | \[ \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)}
\] |
metadata-eval [=>]0.08 | \[ \mathsf{fma}\left(0.225, x \cdot x, \color{blue}{-0.5}\right)
\] |
Applied egg-rr0.08
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 1.31% |
| Cost | 7049 |
| Alternative 2 | |
|---|---|
| Error | 1.33% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 1.66% |
| Cost | 328 |
| Alternative 4 | |
|---|---|
| Error | 49.5% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))