sintan (problem 3.4.5)

Percentage Accurate: 50.9% → 100.0%
Time: 13.5s
Alternatives: 8
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 8 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: 50.9% 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 0.027:\\ \;\;\;\;\left(-0.009642857142857142 \cdot {x_m}^{4} + 0.225 \cdot {x_m}^{2}\right) - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x_m - \sin x_m}{x_m - \tan x_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 0.027)
   (- (+ (* -0.009642857142857142 (pow x_m 4.0)) (* 0.225 (pow x_m 2.0))) 0.5)
   (/ (- x_m (sin x_m)) (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 0.027) {
		tmp = ((-0.009642857142857142 * pow(x_m, 4.0)) + (0.225 * pow(x_m, 2.0))) - 0.5;
	} else {
		tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 0.027d0) then
        tmp = (((-0.009642857142857142d0) * (x_m ** 4.0d0)) + (0.225d0 * (x_m ** 2.0d0))) - 0.5d0
    else
        tmp = (x_m - sin(x_m)) / (x_m - tan(x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 0.027) {
		tmp = ((-0.009642857142857142 * Math.pow(x_m, 4.0)) + (0.225 * Math.pow(x_m, 2.0))) - 0.5;
	} else {
		tmp = (x_m - Math.sin(x_m)) / (x_m - Math.tan(x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 0.027:
		tmp = ((-0.009642857142857142 * math.pow(x_m, 4.0)) + (0.225 * math.pow(x_m, 2.0))) - 0.5
	else:
		tmp = (x_m - math.sin(x_m)) / (x_m - math.tan(x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 0.027)
		tmp = Float64(Float64(Float64(-0.009642857142857142 * (x_m ^ 4.0)) + Float64(0.225 * (x_m ^ 2.0))) - 0.5);
	else
		tmp = Float64(Float64(x_m - sin(x_m)) / Float64(x_m - tan(x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 0.027)
		tmp = ((-0.009642857142857142 * (x_m ^ 4.0)) + (0.225 * (x_m ^ 2.0))) - 0.5;
	else
		tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 0.027], N[(N[(N[(-0.009642857142857142 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.027:\\
\;\;\;\;\left(-0.009642857142857142 \cdot {x_m}^{4} + 0.225 \cdot {x_m}^{2}\right) - 0.5\\

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


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 62.9%

      \[\leadsto \color{blue}{\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) - 0.5} \]

    if 0.0269999999999999997 < x

    1. Initial program 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.027:\\ \;\;\;\;\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x - \sin x}{x - \tan x}\\ \end{array} \]

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 0.0044:\\ \;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x_m - \sin x_m}{x_m - \tan x_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 0.0044)
   (- (* 0.225 (pow x_m 2.0)) 0.5)
   (/ (- x_m (sin x_m)) (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 0.0044) {
		tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 0.0044d0) then
        tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
    else
        tmp = (x_m - sin(x_m)) / (x_m - tan(x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 0.0044) {
		tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = (x_m - Math.sin(x_m)) / (x_m - Math.tan(x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 0.0044:
		tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5
	else:
		tmp = (x_m - math.sin(x_m)) / (x_m - math.tan(x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 0.0044)
		tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5);
	else
		tmp = Float64(Float64(x_m - sin(x_m)) / Float64(x_m - tan(x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 0.0044)
		tmp = (0.225 * (x_m ^ 2.0)) - 0.5;
	else
		tmp = (x_m - sin(x_m)) / (x_m - tan(x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 0.0044], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(N[(x$95$m - N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0044:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\

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


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 64.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]

    if 0.00440000000000000027 < x

    1. Initial program 100.0%

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

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

Alternative 3: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.45:\\ \;\;\;\;{\left(x_m \cdot \sqrt{0.225}\right)}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{\tan x_m}{x_m}}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 1.45)
   (- (pow (* x_m (sqrt 0.225)) 2.0) 0.5)
   (/ 1.0 (- 1.0 (/ (tan x_m) x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = pow((x_m * sqrt(0.225)), 2.0) - 0.5;
	} else {
		tmp = 1.0 / (1.0 - (tan(x_m) / x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 1.45d0) then
        tmp = ((x_m * sqrt(0.225d0)) ** 2.0d0) - 0.5d0
    else
        tmp = 1.0d0 / (1.0d0 - (tan(x_m) / x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = Math.pow((x_m * Math.sqrt(0.225)), 2.0) - 0.5;
	} else {
		tmp = 1.0 / (1.0 - (Math.tan(x_m) / x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 1.45:
		tmp = math.pow((x_m * math.sqrt(0.225)), 2.0) - 0.5
	else:
		tmp = 1.0 / (1.0 - (math.tan(x_m) / x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.45)
		tmp = Float64((Float64(x_m * sqrt(0.225)) ^ 2.0) - 0.5);
	else
		tmp = Float64(1.0 / Float64(1.0 - Float64(tan(x_m) / x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 1.45)
		tmp = ((x_m * sqrt(0.225)) ^ 2.0) - 0.5;
	else
		tmp = 1.0 / (1.0 - (tan(x_m) / x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.45], N[(N[Power[N[(x$95$m * N[Sqrt[0.225], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - 0.5), $MachinePrecision], N[(1.0 / N[(1.0 - N[(N[Tan[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.45:\\
\;\;\;\;{\left(x_m \cdot \sqrt{0.225}\right)}^{2} - 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 - \frac{\tan x_m}{x_m}}\\


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 64.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt64.2%

        \[\leadsto \color{blue}{\sqrt{0.225 \cdot {x}^{2}} \cdot \sqrt{0.225 \cdot {x}^{2}}} - 0.5 \]
      2. pow264.2%

        \[\leadsto \color{blue}{{\left(\sqrt{0.225 \cdot {x}^{2}}\right)}^{2}} - 0.5 \]
      3. *-commutative64.2%

        \[\leadsto {\left(\sqrt{\color{blue}{{x}^{2} \cdot 0.225}}\right)}^{2} - 0.5 \]
      4. sqrt-prod64.2%

        \[\leadsto {\color{blue}{\left(\sqrt{{x}^{2}} \cdot \sqrt{0.225}\right)}}^{2} - 0.5 \]
      5. unpow264.2%

        \[\leadsto {\left(\sqrt{\color{blue}{x \cdot x}} \cdot \sqrt{0.225}\right)}^{2} - 0.5 \]
      6. sqrt-prod32.8%

        \[\leadsto {\left(\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{0.225}\right)}^{2} - 0.5 \]
      7. add-sqr-sqrt64.2%

        \[\leadsto {\left(\color{blue}{x} \cdot \sqrt{0.225}\right)}^{2} - 0.5 \]
    4. Applied egg-rr64.2%

      \[\leadsto \color{blue}{{\left(x \cdot \sqrt{0.225}\right)}^{2}} - 0.5 \]

    if 1.44999999999999996 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around inf 97.6%

      \[\leadsto \frac{\color{blue}{x}}{x - \tan x} \]
    3. Step-by-step derivation
      1. clear-num97.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{x - \tan x}{x}}} \]
      2. associate-/r/97.4%

        \[\leadsto \color{blue}{\frac{1}{x - \tan x} \cdot x} \]
    4. Applied egg-rr97.4%

      \[\leadsto \color{blue}{\frac{1}{x - \tan x} \cdot x} \]
    5. Step-by-step derivation
      1. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{x - \tan x}{x}}} \]
      2. div-sub97.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{x} - \frac{\tan x}{x}}} \]
      3. *-inverses97.6%

        \[\leadsto \frac{1}{\color{blue}{1} - \frac{\tan x}{x}} \]
    6. Applied egg-rr97.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.45:\\ \;\;\;\;{\left(x \cdot \sqrt{0.225}\right)}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{\tan x}{x}}\\ \end{array} \]

Alternative 4: 98.8% accurate, 1.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.45:\\ \;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{\tan x_m}{x_m}}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 1.45)
   (- (* 0.225 (pow x_m 2.0)) 0.5)
   (/ 1.0 (- 1.0 (/ (tan x_m) x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = 1.0 / (1.0 - (tan(x_m) / x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 1.45d0) then
        tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
    else
        tmp = 1.0d0 / (1.0d0 - (tan(x_m) / x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = 1.0 / (1.0 - (Math.tan(x_m) / x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 1.45:
		tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5
	else:
		tmp = 1.0 / (1.0 - (math.tan(x_m) / x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.45)
		tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5);
	else
		tmp = Float64(1.0 / Float64(1.0 - Float64(tan(x_m) / x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 1.45)
		tmp = (0.225 * (x_m ^ 2.0)) - 0.5;
	else
		tmp = 1.0 / (1.0 - (tan(x_m) / x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.45], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(1.0 / N[(1.0 - N[(N[Tan[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.45:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 - \frac{\tan x_m}{x_m}}\\


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 64.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]

    if 1.44999999999999996 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around inf 97.6%

      \[\leadsto \frac{\color{blue}{x}}{x - \tan x} \]
    3. Step-by-step derivation
      1. clear-num97.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{x - \tan x}{x}}} \]
      2. associate-/r/97.4%

        \[\leadsto \color{blue}{\frac{1}{x - \tan x} \cdot x} \]
    4. Applied egg-rr97.4%

      \[\leadsto \color{blue}{\frac{1}{x - \tan x} \cdot x} \]
    5. Step-by-step derivation
      1. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{x - \tan x}{x}}} \]
      2. div-sub97.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{x} - \frac{\tan x}{x}}} \]
      3. *-inverses97.6%

        \[\leadsto \frac{1}{\color{blue}{1} - \frac{\tan x}{x}} \]
    6. Applied egg-rr97.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.45:\\ \;\;\;\;0.225 \cdot {x}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 - \frac{\tan x}{x}}\\ \end{array} \]

Alternative 5: 98.8% accurate, 1.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.45:\\ \;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x_m}{x_m - \tan x_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 1.45) (- (* 0.225 (pow x_m 2.0)) 0.5) (/ x_m (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = (0.225 * pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = x_m / (x_m - tan(x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 1.45d0) then
        tmp = (0.225d0 * (x_m ** 2.0d0)) - 0.5d0
    else
        tmp = x_m / (x_m - tan(x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.45) {
		tmp = (0.225 * Math.pow(x_m, 2.0)) - 0.5;
	} else {
		tmp = x_m / (x_m - Math.tan(x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 1.45:
		tmp = (0.225 * math.pow(x_m, 2.0)) - 0.5
	else:
		tmp = x_m / (x_m - math.tan(x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.45)
		tmp = Float64(Float64(0.225 * (x_m ^ 2.0)) - 0.5);
	else
		tmp = Float64(x_m / Float64(x_m - tan(x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 1.45)
		tmp = (0.225 * (x_m ^ 2.0)) - 0.5;
	else
		tmp = x_m / (x_m - tan(x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.45], N[(N[(0.225 * N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[(x$95$m / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.45:\\
\;\;\;\;0.225 \cdot {x_m}^{2} - 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{x_m}{x_m - \tan x_m}\\


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 64.2%

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]

    if 1.44999999999999996 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around inf 97.6%

      \[\leadsto \frac{\color{blue}{x}}{x - \tan x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.2%

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

Alternative 6: 98.5% accurate, 1.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.35:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x_m}{x_m - \tan x_m}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m)
 :precision binary64
 (if (<= x_m 1.35) -0.5 (/ x_m (- x_m (tan x_m)))))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.35) {
		tmp = -0.5;
	} else {
		tmp = x_m / (x_m - tan(x_m));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 1.35d0) then
        tmp = -0.5d0
    else
        tmp = x_m / (x_m - tan(x_m))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.35) {
		tmp = -0.5;
	} else {
		tmp = x_m / (x_m - Math.tan(x_m));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 1.35:
		tmp = -0.5
	else:
		tmp = x_m / (x_m - math.tan(x_m))
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.35)
		tmp = -0.5;
	else
		tmp = Float64(x_m / Float64(x_m - tan(x_m)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 1.35)
		tmp = -0.5;
	else
		tmp = x_m / (x_m - tan(x_m));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.35], -0.5, N[(x$95$m / N[(x$95$m - N[Tan[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.35:\\
\;\;\;\;-0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{x_m}{x_m - \tan x_m}\\


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

    1. Initial program 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 63.0%

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

    if 1.3500000000000001 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around inf 97.6%

      \[\leadsto \frac{\color{blue}{x}}{x - \tan x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.2%

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

Alternative 7: 98.5% accurate, 67.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 1.6:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 (if (<= x_m 1.6) -0.5 1.0))
x_m = fabs(x);
double code(double x_m) {
	double tmp;
	if (x_m <= 1.6) {
		tmp = -0.5;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    real(8) :: tmp
    if (x_m <= 1.6d0) then
        tmp = -0.5d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	double tmp;
	if (x_m <= 1.6) {
		tmp = -0.5;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m):
	tmp = 0
	if x_m <= 1.6:
		tmp = -0.5
	else:
		tmp = 1.0
	return tmp
x_m = abs(x)
function code(x_m)
	tmp = 0.0
	if (x_m <= 1.6)
		tmp = -0.5;
	else
		tmp = 1.0;
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m)
	tmp = 0.0;
	if (x_m <= 1.6)
		tmp = -0.5;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := If[LessEqual[x$95$m, 1.6], -0.5, 1.0]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x_m \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 38.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around 0 63.0%

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

    if 1.6000000000000001 < x

    1. Initial program 100.0%

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Taylor expanded in x around inf 97.6%

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

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

Alternative 8: 50.2% accurate, 207.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ -0.5 \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m) :precision binary64 -0.5)
x_m = fabs(x);
double code(double x_m) {
	return -0.5;
}
x_m = abs(x)
real(8) function code(x_m)
    real(8), intent (in) :: x_m
    code = -0.5d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
	return -0.5;
}
x_m = math.fabs(x)
def code(x_m):
	return -0.5
x_m = abs(x)
function code(x_m)
	return -0.5
end
x_m = abs(x);
function tmp = code(x_m)
	tmp = -0.5;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := -0.5
\begin{array}{l}
x_m = \left|x\right|

\\
-0.5
\end{array}
Derivation
  1. Initial program 52.7%

    \[\frac{x - \sin x}{x - \tan x} \]
  2. Taylor expanded in x around 0 48.3%

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

    \[\leadsto -0.5 \]

Reproduce

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