sintan (problem 3.4.5)

Percentage Accurate: 51.3% → 99.9%
Time: 17.3s
Alternatives: 5
Speedup: 67.6×

Specification

?
\[\begin{array}{l} \\ \frac{x - \sin x}{x - \tan x} \end{array} \]
(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:

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.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 51.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x - \sin x}{x - \tan x} \end{array} \]
(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}

Alternative 1: 99.9% accurate, 0.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.0048:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x)
 :precision binary64
 (if (<= x 0.0048)
   (fma 0.225 (* x x) -0.5)
   (pow (/ (- (tan x) x) (- (sin x) x)) -1.0)))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 0.0048) {
		tmp = fma(0.225, (x * x), -0.5);
	} else {
		tmp = pow(((tan(x) - x) / (sin(x) - x)), -1.0);
	}
	return tmp;
}
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 0.0048)
		tmp = fma(0.225, Float64(x * x), -0.5);
	else
		tmp = Float64(Float64(tan(x) - x) / Float64(sin(x) - x)) ^ -1.0;
	end
	return tmp
end
NOTE: x should be positive before calling this function
code[x_] := If[LessEqual[x, 0.0048], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], N[Power[N[(N[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision] / N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0048:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.00479999999999999958

    1. Initial program 37.2%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg37.2%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative37.2%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub037.2%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-37.2%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg37.2%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-137.2%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub037.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-137.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac37.2%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval37.2%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity37.2%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified37.2%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around 0 65.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]
    5. Step-by-step derivation
      1. fma-neg65.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, {x}^{2}, -0.5\right)} \]
      2. unpow265.2%

        \[\leadsto \mathsf{fma}\left(0.225, \color{blue}{x \cdot x}, -0.5\right) \]
      3. metadata-eval65.2%

        \[\leadsto \mathsf{fma}\left(0.225, x \cdot x, \color{blue}{-0.5}\right) \]
    6. Simplified65.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)} \]

    if 0.00479999999999999958 < x

    1. Initial program 99.9%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg99.9%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub099.9%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-99.9%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg99.9%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-199.9%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg99.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative99.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub099.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-99.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg99.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-199.9%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac99.9%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval99.9%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity99.9%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\tan x - x}{\sin x - x}}} \]
      2. inv-pow99.8%

        \[\leadsto \color{blue}{{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}} \]
    5. Applied egg-rr99.8%

      \[\leadsto \color{blue}{{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.0048:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{\tan x - x}{\sin x - x}\right)}^{-1}\\ \end{array} \]

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.0048:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x - \sin x}{x - \tan x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x)
 :precision binary64
 (if (<= x 0.0048) (fma 0.225 (* x x) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 0.0048) {
		tmp = fma(0.225, (x * x), -0.5);
	} else {
		tmp = (x - sin(x)) / (x - tan(x));
	}
	return tmp;
}
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 0.0048)
		tmp = fma(0.225, Float64(x * x), -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.0048], N[(0.225 * N[(x * x), $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.0048:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.00479999999999999958

    1. Initial program 37.2%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg37.2%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative37.2%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub037.2%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-37.2%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg37.2%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-137.2%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub037.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg37.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-137.2%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac37.2%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval37.2%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity37.2%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified37.2%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around 0 65.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]
    5. Step-by-step derivation
      1. fma-neg65.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, {x}^{2}, -0.5\right)} \]
      2. unpow265.2%

        \[\leadsto \mathsf{fma}\left(0.225, \color{blue}{x \cdot x}, -0.5\right) \]
      3. metadata-eval65.2%

        \[\leadsto \mathsf{fma}\left(0.225, x \cdot x, \color{blue}{-0.5}\right) \]
    6. Simplified65.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)} \]

    if 0.00479999999999999958 < x

    1. Initial program 99.9%

      \[\frac{x - \sin x}{x - \tan x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.0048:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x - \sin x}{x - \tan x}\\ \end{array} \]

Alternative 3: 98.8% accurate, 1.9× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 2.55:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 (if (<= x 2.55) (fma 0.225 (* x x) -0.5) 1.0))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 2.55) {
		tmp = fma(0.225, (x * x), -0.5);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 2.55)
		tmp = fma(0.225, Float64(x * x), -0.5);
	else
		tmp = 1.0;
	end
	return tmp
end
NOTE: x should be positive before calling this function
code[x_] := If[LessEqual[x, 2.55], N[(0.225 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.55:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.5499999999999998

    1. Initial program 37.5%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg37.5%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative37.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub037.5%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-37.5%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg37.5%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-137.5%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub037.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-137.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac37.5%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval37.5%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity37.5%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified37.5%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around 0 65.1%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]
    5. Step-by-step derivation
      1. fma-neg65.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, {x}^{2}, -0.5\right)} \]
      2. unpow265.1%

        \[\leadsto \mathsf{fma}\left(0.225, \color{blue}{x \cdot x}, -0.5\right) \]
      3. metadata-eval65.1%

        \[\leadsto \mathsf{fma}\left(0.225, x \cdot x, \color{blue}{-0.5}\right) \]
    6. Simplified65.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)} \]

    if 2.5499999999999998 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg100.0%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative100.0%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub0100.0%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-100.0%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg100.0%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-1100.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub0100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-1100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac100.0%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval100.0%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity100.0%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.55:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 4: 98.5% accurate, 67.6× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1.6:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 (if (<= x 1.6) -0.5 1.0))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 1.6) {
		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.6d0) 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.6) {
		tmp = -0.5;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x = abs(x)
def code(x):
	tmp = 0
	if x <= 1.6:
		tmp = -0.5
	else:
		tmp = 1.0
	return tmp
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 1.6)
		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.6)
		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.6], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6:\\
\;\;\;\;-0.5\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.6000000000000001

    1. Initial program 37.5%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg37.5%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative37.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub037.5%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-37.5%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg37.5%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-137.5%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub037.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg37.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-137.5%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac37.5%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval37.5%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity37.5%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified37.5%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around 0 64.1%

      \[\leadsto \color{blue}{-0.5} \]

    if 1.6000000000000001 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Step-by-step derivation
      1. sub-neg100.0%

        \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
      2. +-commutative100.0%

        \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
      3. neg-sub0100.0%

        \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
      4. associate-+l-100.0%

        \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
      5. sub0-neg100.0%

        \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
      6. neg-mul-1100.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
      7. sub-neg100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
      8. +-commutative100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
      9. neg-sub0100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
      10. associate-+l-100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
      11. sub0-neg100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
      12. neg-mul-1100.0%

        \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
      13. times-frac100.0%

        \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
      14. metadata-eval100.0%

        \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
      15. *-lft-identity100.0%

        \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
    4. Taylor expanded in x around inf 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.6:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 5: 49.8% accurate, 207.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ -0.5 \end{array} \]
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}
Derivation
  1. Initial program 52.6%

    \[\frac{x - \sin x}{x - \tan x} \]
  2. Step-by-step derivation
    1. sub-neg52.6%

      \[\leadsto \frac{\color{blue}{x + \left(-\sin x\right)}}{x - \tan x} \]
    2. +-commutative52.6%

      \[\leadsto \frac{\color{blue}{\left(-\sin x\right) + x}}{x - \tan x} \]
    3. neg-sub052.6%

      \[\leadsto \frac{\color{blue}{\left(0 - \sin x\right)} + x}{x - \tan x} \]
    4. associate-+l-52.6%

      \[\leadsto \frac{\color{blue}{0 - \left(\sin x - x\right)}}{x - \tan x} \]
    5. sub0-neg52.6%

      \[\leadsto \frac{\color{blue}{-\left(\sin x - x\right)}}{x - \tan x} \]
    6. neg-mul-152.6%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin x - x\right)}}{x - \tan x} \]
    7. sub-neg52.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{x + \left(-\tan x\right)}} \]
    8. +-commutative52.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(-\tan x\right) + x}} \]
    9. neg-sub052.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{\left(0 - \tan x\right)} + x} \]
    10. associate-+l-52.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{0 - \left(\tan x - x\right)}} \]
    11. sub0-neg52.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-\left(\tan x - x\right)}} \]
    12. neg-mul-152.6%

      \[\leadsto \frac{-1 \cdot \left(\sin x - x\right)}{\color{blue}{-1 \cdot \left(\tan x - x\right)}} \]
    13. times-frac52.6%

      \[\leadsto \color{blue}{\frac{-1}{-1} \cdot \frac{\sin x - x}{\tan x - x}} \]
    14. metadata-eval52.6%

      \[\leadsto \color{blue}{1} \cdot \frac{\sin x - x}{\tan x - x} \]
    15. *-lft-identity52.6%

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
  3. Simplified52.6%

    \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
  4. Taylor expanded in x around 0 48.9%

    \[\leadsto \color{blue}{-0.5} \]
  5. Final simplification48.9%

    \[\leadsto -0.5 \]

Reproduce

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