| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 26564 |
\[\begin{array}{l}
t_0 := \frac{x - \sin x}{x - \tan x}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\]

(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x (sin x)) (- x (tan x))))) (if (<= t_0 2.0) t_0 -0.5)))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
double t_0 = (x - sin(x)) / (x - tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -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) :: t_0
real(8) :: tmp
t_0 = (x - sin(x)) / (x - tan(x))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = -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 t_0 = (x - Math.sin(x)) / (x - Math.tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
def code(x): t_0 = (x - math.sin(x)) / (x - math.tan(x)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = -0.5 return tmp
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function code(x) t_0 = Float64(Float64(x - sin(x)) / Float64(x - tan(x))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = -0.5; end return tmp end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
function tmp_2 = code(x) t_0 = (x - sin(x)) / (x - tan(x)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = -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_] := Block[{t$95$0 = N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, -0.5]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := \frac{x - \sin x}{x - \tan x}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 99.6%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
Simplified0.0%
[Start]0.0% | \[ \frac{x - \sin x}{x - \tan x}
\] |
|---|---|
sub-neg [=>]0.0% | \[ \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x}
\] |
+-commutative [=>]0.0% | \[ \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x}
\] |
neg-sub0 [=>]0.0% | \[ \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x}
\] |
associate-+l- [=>]0.0% | \[ \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x}
\] |
sub0-neg [=>]0.0% | \[ \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x}
\] |
neg-mul-1 [=>]0.0% | \[ \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x}
\] |
sub-neg [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}}
\] |
+-commutative [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}}
\] |
neg-sub0 [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x}
\] |
associate-+l- [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}}
\] |
sub0-neg [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}}
\] |
neg-mul-1 [=>]0.0% | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}}
\] |
times-frac [=>]0.0% | \[ \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}}
\] |
metadata-eval [=>]0.0% | \[ \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x}
\] |
*-lft-identity [=>]0.0% | \[ \color{blue}{\frac{\sin x - x}{\tan x - x}}
\] |
Taylor expanded in x around 0 100.0%
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 26564 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 13513 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 6984 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 328 |
| Alternative 8 | |
|---|---|
| Accuracy | 50.3% |
| Cost | 64 |
herbie shell --seed 2023256
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))