sintan (problem 3.4.5)

?

Percentage Accurate: 50.8% → 99.6%
Time: 14.0s
Precision: binary64
Cost: 26564

?

\[\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} \]
(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}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2

    1. Initial program 99.6%

      \[\frac{x - \sin x}{x - \tan x} \]

    if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x)))

    1. Initial program 0.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
      Step-by-step derivation

      [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}} \]
    3. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - \sin x}{x - \tan x} \leq 2:\\ \;\;\;\;\frac{x - \sin x}{x - \tan x}\\ \mathbf{else}:\\ \;\;\;\;-0.5\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.6%
Cost26564
\[\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} \]
Alternative 2
Accuracy99.2%
Cost13513
\[\begin{array}{l} \mathbf{if}\;x \leq -2.45 \lor \neg \left(x \leq 2.4\right):\\ \;\;\;\;1 + \frac{\tan x - \sin x}{x}\\ \mathbf{else}:\\ \;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 3
Accuracy98.7%
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.2:\\ \;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(1 + \left(1 - \left(2 + \frac{\sin x}{x}\right)\right)\right)\\ \end{array} \]
Alternative 4
Accuracy98.7%
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.2:\\ \;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(1 - \left(1 + \frac{\sin x}{x}\right)\right)\\ \end{array} \]
Alternative 5
Accuracy98.7%
Cost6984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.2:\\ \;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{\sin x}{x}\\ \end{array} \]
Alternative 6
Accuracy98.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.5:\\ \;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Accuracy98.4%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -14.2:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 8
Accuracy50.3%
Cost64
\[-0.5 \]

Reproduce?

herbie shell --seed 2023256 
(FPCore (x)
  :name "sintan (problem 3.4.5)"
  :precision binary64
  (/ (- x (sin x)) (- x (tan x))))