| Alternative 1 | |
|---|---|
| Error | 0.64% |
| Cost | 13513 |
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
:precision binary64
(let* ((t_0 (- (tan x) x)))
(if (<= x -3.0)
(+ 1.0 (/ (- (tan x) (sin x)) x))
(if (<= x 0.094)
(+
(+
(* (* x x) 0.225)
(*
(pow x 4.0)
(+ (* (* x x) 0.00024107142857142857) -0.009642857142857142)))
-0.5)
(- (/ (sin x) t_0) (/ x t_0))))))double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
double t_0 = tan(x) - x;
double tmp;
if (x <= -3.0) {
tmp = 1.0 + ((tan(x) - sin(x)) / x);
} else if (x <= 0.094) {
tmp = (((x * x) * 0.225) + (pow(x, 4.0) * (((x * x) * 0.00024107142857142857) + -0.009642857142857142))) + -0.5;
} else {
tmp = (sin(x) / t_0) - (x / t_0);
}
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 = tan(x) - x
if (x <= (-3.0d0)) then
tmp = 1.0d0 + ((tan(x) - sin(x)) / x)
else if (x <= 0.094d0) then
tmp = (((x * x) * 0.225d0) + ((x ** 4.0d0) * (((x * x) * 0.00024107142857142857d0) + (-0.009642857142857142d0)))) + (-0.5d0)
else
tmp = (sin(x) / t_0) - (x / t_0)
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 = Math.tan(x) - x;
double tmp;
if (x <= -3.0) {
tmp = 1.0 + ((Math.tan(x) - Math.sin(x)) / x);
} else if (x <= 0.094) {
tmp = (((x * x) * 0.225) + (Math.pow(x, 4.0) * (((x * x) * 0.00024107142857142857) + -0.009642857142857142))) + -0.5;
} else {
tmp = (Math.sin(x) / t_0) - (x / t_0);
}
return tmp;
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
def code(x): t_0 = math.tan(x) - x tmp = 0 if x <= -3.0: tmp = 1.0 + ((math.tan(x) - math.sin(x)) / x) elif x <= 0.094: tmp = (((x * x) * 0.225) + (math.pow(x, 4.0) * (((x * x) * 0.00024107142857142857) + -0.009642857142857142))) + -0.5 else: tmp = (math.sin(x) / t_0) - (x / t_0) return tmp
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function code(x) t_0 = Float64(tan(x) - x) tmp = 0.0 if (x <= -3.0) tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x)); elseif (x <= 0.094) tmp = Float64(Float64(Float64(Float64(x * x) * 0.225) + Float64((x ^ 4.0) * Float64(Float64(Float64(x * x) * 0.00024107142857142857) + -0.009642857142857142))) + -0.5); else tmp = Float64(Float64(sin(x) / t_0) - Float64(x / t_0)); end return tmp end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
function tmp_2 = code(x) t_0 = tan(x) - x; tmp = 0.0; if (x <= -3.0) tmp = 1.0 + ((tan(x) - sin(x)) / x); elseif (x <= 0.094) tmp = (((x * x) * 0.225) + ((x ^ 4.0) * (((x * x) * 0.00024107142857142857) + -0.009642857142857142))) + -0.5; else tmp = (sin(x) / t_0) - (x / t_0); 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[Tan[x], $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -3.0], N[(1.0 + N[(N[(N[Tan[x], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.094], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.225), $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * N[(N[(N[(x * x), $MachinePrecision] * 0.00024107142857142857), $MachinePrecision] + -0.009642857142857142), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := \tan x - x\\
\mathbf{if}\;x \leq -3:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\mathbf{elif}\;x \leq 0.094:\\
\;\;\;\;\left(\left(x \cdot x\right) \cdot 0.225 + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot 0.00024107142857142857 + -0.009642857142857142\right)\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin x}{t_0} - \frac{x}{t_0}\\
\end{array}
Results
if x < -3Initial program 0.03
Simplified0.03
[Start]0.03 | \[ \frac{x - \sin x}{x - \tan x}
\] |
|---|---|
sub-neg [=>]0.03 | \[ \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x}
\] |
+-commutative [=>]0.03 | \[ \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x}
\] |
neg-sub0 [=>]0.03 | \[ \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x}
\] |
associate-+l- [=>]0.03 | \[ \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x}
\] |
sub0-neg [=>]0.03 | \[ \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x}
\] |
neg-mul-1 [=>]0.03 | \[ \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x}
\] |
sub-neg [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}}
\] |
+-commutative [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}}
\] |
neg-sub0 [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x}
\] |
associate-+l- [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}}
\] |
sub0-neg [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}}
\] |
neg-mul-1 [=>]0.03 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}}
\] |
times-frac [=>]0.03 | \[ \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}}
\] |
metadata-eval [=>]0.03 | \[ \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x}
\] |
*-lft-identity [=>]0.03 | \[ \color{blue}{\frac{\sin x - x}{\tan x - x}}
\] |
Taylor expanded in x around -inf 0.9
Simplified0.9
[Start]0.9 | \[ 1 + -1 \cdot \frac{\sin x - \frac{\sin x}{\cos x}}{x}
\] |
|---|---|
associate-*r/ [=>]0.9 | \[ 1 + \color{blue}{\frac{-1 \cdot \left(\sin x - \frac{\sin x}{\cos x}\right)}{x}}
\] |
distribute-lft-out-- [<=]0.9 | \[ 1 + \frac{\color{blue}{-1 \cdot \sin x - -1 \cdot \frac{\sin x}{\cos x}}}{x}
\] |
cancel-sign-sub-inv [=>]0.9 | \[ 1 + \frac{\color{blue}{-1 \cdot \sin x + \left(--1\right) \cdot \frac{\sin x}{\cos x}}}{x}
\] |
+-commutative [=>]0.9 | \[ 1 + \frac{\color{blue}{\left(--1\right) \cdot \frac{\sin x}{\cos x} + -1 \cdot \sin x}}{x}
\] |
metadata-eval [=>]0.9 | \[ 1 + \frac{\color{blue}{1} \cdot \frac{\sin x}{\cos x} + -1 \cdot \sin x}{x}
\] |
*-commutative [=>]0.9 | \[ 1 + \frac{\color{blue}{\frac{\sin x}{\cos x} \cdot 1} + -1 \cdot \sin x}{x}
\] |
associate-/r/ [<=]0.9 | \[ 1 + \frac{\color{blue}{\frac{\sin x}{\frac{\cos x}{1}}} + -1 \cdot \sin x}{x}
\] |
/-rgt-identity [=>]0.9 | \[ 1 + \frac{\frac{\sin x}{\color{blue}{\cos x}} + -1 \cdot \sin x}{x}
\] |
mul-1-neg [=>]0.9 | \[ 1 + \frac{\frac{\sin x}{\cos x} + \color{blue}{\left(-\sin x\right)}}{x}
\] |
Applied egg-rr0.9
if -3 < x < 0.094Initial program 98.23
Simplified98.23
[Start]98.23 | \[ \frac{x - \sin x}{x - \tan x}
\] |
|---|---|
sub-neg [=>]98.23 | \[ \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x}
\] |
+-commutative [=>]98.23 | \[ \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x}
\] |
neg-sub0 [=>]98.23 | \[ \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x}
\] |
associate-+l- [=>]98.23 | \[ \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x}
\] |
sub0-neg [=>]98.23 | \[ \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x}
\] |
neg-mul-1 [=>]98.23 | \[ \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x}
\] |
sub-neg [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}}
\] |
+-commutative [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}}
\] |
neg-sub0 [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x}
\] |
associate-+l- [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}}
\] |
sub0-neg [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}}
\] |
neg-mul-1 [=>]98.23 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}}
\] |
times-frac [=>]98.23 | \[ \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}}
\] |
metadata-eval [=>]98.23 | \[ \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x}
\] |
*-lft-identity [=>]98.23 | \[ \color{blue}{\frac{\sin x - x}{\tan x - x}}
\] |
Taylor expanded in x around 0 0.16
Applied egg-rr0.19
Simplified0.16
[Start]0.19 | \[ \left(\left(e^{\mathsf{log1p}\left(0.225 \cdot \left(x \cdot x\right)\right)} - 1\right) + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5
\] |
|---|---|
expm1-def [=>]0.16 | \[ \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.225 \cdot \left(x \cdot x\right)\right)\right)} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5
\] |
expm1-log1p [=>]0.16 | \[ \left(\color{blue}{0.225 \cdot \left(x \cdot x\right)} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5
\] |
*-commutative [=>]0.16 | \[ \left(\color{blue}{\left(x \cdot x\right) \cdot 0.225} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5
\] |
Applied egg-rr0.16
if 0.094 < x Initial program 0.05
Simplified0.05
[Start]0.05 | \[ \frac{x - \sin x}{x - \tan x}
\] |
|---|---|
sub-neg [=>]0.05 | \[ \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x}
\] |
+-commutative [=>]0.05 | \[ \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x}
\] |
neg-sub0 [=>]0.05 | \[ \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x}
\] |
associate-+l- [=>]0.05 | \[ \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x}
\] |
sub0-neg [=>]0.05 | \[ \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x}
\] |
neg-mul-1 [=>]0.05 | \[ \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x}
\] |
sub-neg [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}}
\] |
+-commutative [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}}
\] |
neg-sub0 [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x}
\] |
associate-+l- [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}}
\] |
sub0-neg [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}}
\] |
neg-mul-1 [=>]0.05 | \[ \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}}
\] |
times-frac [=>]0.05 | \[ \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}}
\] |
metadata-eval [=>]0.05 | \[ \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x}
\] |
*-lft-identity [=>]0.05 | \[ \color{blue}{\frac{\sin x - x}{\tan x - x}}
\] |
Applied egg-rr0.04
Final simplification0.31
| Alternative 1 | |
|---|---|
| Error | 0.64% |
| Cost | 13513 |
| Alternative 2 | |
|---|---|
| Error | 0.31% |
| Cost | 13512 |
| Alternative 3 | |
|---|---|
| Error | 1.12% |
| Cost | 7816 |
| Alternative 4 | |
|---|---|
| Error | 1.17% |
| Cost | 7432 |
| Alternative 5 | |
|---|---|
| Error | 1.28% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 1.28% |
| Cost | 7048 |
| Alternative 7 | |
|---|---|
| Error | 1.27% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 1.28% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 1.61% |
| Cost | 328 |
| Alternative 10 | |
|---|---|
| Error | 49.95% |
| Cost | 64 |
herbie shell --seed 2023089
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))