Data.Approximate.Numerics:blog from approximate-0.2.2.1

Percentage Accurate: 99.7% → 99.7%
Time: 5.9s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x):
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x)
	return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))))
end
function tmp = code(x)
	tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{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 9 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: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x):
	return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x)
	return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))))
end
function tmp = code(x)
	tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\end{array}

Alternative 1: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 6 \cdot \frac{x + -1}{1 + \left(x + \sqrt{x \cdot 16}\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (* 6.0 (/ (+ x -1.0) (+ 1.0 (+ x (sqrt (* x 16.0)))))))
double code(double x) {
	return 6.0 * ((x + -1.0) / (1.0 + (x + sqrt((x * 16.0)))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 6.0d0 * ((x + (-1.0d0)) / (1.0d0 + (x + sqrt((x * 16.0d0)))))
end function
public static double code(double x) {
	return 6.0 * ((x + -1.0) / (1.0 + (x + Math.sqrt((x * 16.0)))));
}
def code(x):
	return 6.0 * ((x + -1.0) / (1.0 + (x + math.sqrt((x * 16.0)))))
function code(x)
	return Float64(6.0 * Float64(Float64(x + -1.0) / Float64(1.0 + Float64(x + sqrt(Float64(x * 16.0))))))
end
function tmp = code(x)
	tmp = 6.0 * ((x + -1.0) / (1.0 + (x + sqrt((x * 16.0)))));
end
code[x_] := N[(6.0 * N[(N[(x + -1.0), $MachinePrecision] / N[(1.0 + N[(x + N[Sqrt[N[(x * 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
6 \cdot \frac{x + -1}{1 + \left(x + \sqrt{x \cdot 16}\right)}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-un-lft-identity99.8%

      \[\leadsto \frac{6 \cdot \left(x - 1\right)}{\color{blue}{1 \cdot \left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \]
    2. times-frac99.9%

      \[\leadsto \color{blue}{\frac{6}{1} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \]
    3. metadata-eval99.9%

      \[\leadsto \color{blue}{6} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    4. sub-neg99.9%

      \[\leadsto 6 \cdot \frac{\color{blue}{x + \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    5. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + \color{blue}{-1}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    6. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    7. associate-+r+99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + x\right) + 1}} \]
    8. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)} + 1} \]
    9. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  3. Applied egg-rr99.9%

    \[\leadsto \color{blue}{6 \cdot \frac{x + -1}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  4. Step-by-step derivation
    1. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
    2. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} + x\right)} \]
    3. sqrt-unprod99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} + x\right)} \]
    4. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} + x\right)} \]
    5. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} + x\right)} \]
    6. swap-sqr99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} + x\right)} \]
    7. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} + x\right)} \]
    8. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{x \cdot \color{blue}{16}} + x\right)} \]
  5. Applied egg-rr99.9%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(\sqrt{x \cdot 16} + x\right)}} \]
  6. Final simplification99.9%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(x + \sqrt{x \cdot 16}\right)} \]

Alternative 2: 95.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 6 \cdot {\left(\frac{x + 1}{x + -1}\right)}^{-1} \end{array} \]
(FPCore (x) :precision binary64 (* 6.0 (pow (/ (+ x 1.0) (+ x -1.0)) -1.0)))
double code(double x) {
	return 6.0 * pow(((x + 1.0) / (x + -1.0)), -1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 6.0d0 * (((x + 1.0d0) / (x + (-1.0d0))) ** (-1.0d0))
end function
public static double code(double x) {
	return 6.0 * Math.pow(((x + 1.0) / (x + -1.0)), -1.0);
}
def code(x):
	return 6.0 * math.pow(((x + 1.0) / (x + -1.0)), -1.0)
function code(x)
	return Float64(6.0 * (Float64(Float64(x + 1.0) / Float64(x + -1.0)) ^ -1.0))
end
function tmp = code(x)
	tmp = 6.0 * (((x + 1.0) / (x + -1.0)) ^ -1.0);
end
code[x_] := N[(6.0 * N[Power[N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
6 \cdot {\left(\frac{x + 1}{x + -1}\right)}^{-1}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-un-lft-identity99.8%

      \[\leadsto \frac{6 \cdot \left(x - 1\right)}{\color{blue}{1 \cdot \left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \]
    2. times-frac99.9%

      \[\leadsto \color{blue}{\frac{6}{1} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \]
    3. metadata-eval99.9%

      \[\leadsto \color{blue}{6} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    4. sub-neg99.9%

      \[\leadsto 6 \cdot \frac{\color{blue}{x + \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    5. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + \color{blue}{-1}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    6. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    7. associate-+r+99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + x\right) + 1}} \]
    8. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)} + 1} \]
    9. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  3. Applied egg-rr99.9%

    \[\leadsto \color{blue}{6 \cdot \frac{x + -1}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  4. Step-by-step derivation
    1. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
    2. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} + x\right)} \]
    3. sqrt-unprod99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} + x\right)} \]
    4. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} + x\right)} \]
    5. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} + x\right)} \]
    6. swap-sqr99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} + x\right)} \]
    7. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} + x\right)} \]
    8. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{x \cdot \color{blue}{16}} + x\right)} \]
  5. Applied egg-rr99.9%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(\sqrt{x \cdot 16} + x\right)}} \]
  6. Taylor expanded in x around inf 96.1%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{x}} \]
  7. Step-by-step derivation
    1. clear-num96.1%

      \[\leadsto 6 \cdot \color{blue}{\frac{1}{\frac{1 + x}{x + -1}}} \]
    2. inv-pow96.1%

      \[\leadsto 6 \cdot \color{blue}{{\left(\frac{1 + x}{x + -1}\right)}^{-1}} \]
    3. +-commutative96.1%

      \[\leadsto 6 \cdot {\left(\frac{\color{blue}{x + 1}}{x + -1}\right)}^{-1} \]
  8. Applied egg-rr96.1%

    \[\leadsto 6 \cdot \color{blue}{{\left(\frac{x + 1}{x + -1}\right)}^{-1}} \]
  9. Final simplification96.1%

    \[\leadsto 6 \cdot {\left(\frac{x + 1}{x + -1}\right)}^{-1} \]

Alternative 3: 95.2% accurate, 12.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.49:\\ \;\;\;\;x \cdot 12 - 6\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(1 - \frac{2}{x}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.49) (- (* x 12.0) 6.0) (* 6.0 (- 1.0 (/ 2.0 x)))))
double code(double x) {
	double tmp;
	if (x <= 0.49) {
		tmp = (x * 12.0) - 6.0;
	} else {
		tmp = 6.0 * (1.0 - (2.0 / x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.49d0) then
        tmp = (x * 12.0d0) - 6.0d0
    else
        tmp = 6.0d0 * (1.0d0 - (2.0d0 / x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.49) {
		tmp = (x * 12.0) - 6.0;
	} else {
		tmp = 6.0 * (1.0 - (2.0 / x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.49:
		tmp = (x * 12.0) - 6.0
	else:
		tmp = 6.0 * (1.0 - (2.0 / x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.49)
		tmp = Float64(Float64(x * 12.0) - 6.0);
	else
		tmp = Float64(6.0 * Float64(1.0 - Float64(2.0 / x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.49)
		tmp = (x * 12.0) - 6.0;
	else
		tmp = 6.0 * (1.0 - (2.0 / x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.49], N[(N[(x * 12.0), $MachinePrecision] - 6.0), $MachinePrecision], N[(6.0 * N[(1.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.49:\\
\;\;\;\;x \cdot 12 - 6\\

\mathbf{else}:\\
\;\;\;\;6 \cdot \left(1 - \frac{2}{x}\right)\\


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

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.9%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.9%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.9%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}} \]
      7. associate-+l+99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{1 + \left(x + 4 \cdot \sqrt{x}\right)}} \]
      8. +-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      9. fma-def99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. flip-+99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}}} \]
      3. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      4. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      5. swap-sqr99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      6. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x} \cdot \left(4 \cdot 4\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot \color{blue}{16} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      8. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} - x}} \]
      9. sqrt-unprod99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} - x}} \]
      10. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} - x}} \]
      11. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} - x}} \]
      12. swap-sqr99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} - x}} \]
      13. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} - x}} \]
      14. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot \color{blue}{16}} - x}} \]
    5. Applied egg-rr99.9%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot 16} - x}}} \]
    6. Step-by-step derivation
      1. distribute-lft-out--99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x \cdot \left(16 - x\right)}}{\sqrt{x \cdot 16} - x}} \]
    7. Simplified99.9%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot \left(16 - x\right)}{\sqrt{x \cdot 16} - x}}} \]
    8. Taylor expanded in x around inf 96.2%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{x}} \]
    9. Taylor expanded in x around 0 96.2%

      \[\leadsto \color{blue}{12 \cdot x - 6} \]

    if 0.48999999999999999 < x

    1. Initial program 99.7%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. *-un-lft-identity99.7%

        \[\leadsto \frac{6 \cdot \left(x - 1\right)}{\color{blue}{1 \cdot \left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \]
      2. times-frac100.0%

        \[\leadsto \color{blue}{\frac{6}{1} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \]
      3. metadata-eval100.0%

        \[\leadsto \color{blue}{6} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. sub-neg100.0%

        \[\leadsto 6 \cdot \frac{\color{blue}{x + \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval100.0%

        \[\leadsto 6 \cdot \frac{x + \color{blue}{-1}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
      7. associate-+r+100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + x\right) + 1}} \]
      8. fma-udef100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)} + 1} \]
      9. +-commutative100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Applied egg-rr100.0%

      \[\leadsto \color{blue}{6 \cdot \frac{x + -1}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. add-sqr-sqrt100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} + x\right)} \]
      3. sqrt-unprod100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} + x\right)} \]
      4. *-commutative100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} + x\right)} \]
      5. *-commutative100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} + x\right)} \]
      6. swap-sqr100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} + x\right)} \]
      7. add-sqr-sqrt100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} + x\right)} \]
      8. metadata-eval100.0%

        \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{x \cdot \color{blue}{16}} + x\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(\sqrt{x \cdot 16} + x\right)}} \]
    6. Taylor expanded in x around inf 96.0%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{x}} \]
    7. Taylor expanded in x around inf 96.0%

      \[\leadsto 6 \cdot \color{blue}{\left(1 - 2 \cdot \frac{1}{x}\right)} \]
    8. Step-by-step derivation
      1. associate-*r/96.0%

        \[\leadsto 6 \cdot \left(1 - \color{blue}{\frac{2 \cdot 1}{x}}\right) \]
      2. metadata-eval96.0%

        \[\leadsto 6 \cdot \left(1 - \frac{\color{blue}{2}}{x}\right) \]
    9. Simplified96.0%

      \[\leadsto 6 \cdot \color{blue}{\left(1 - \frac{2}{x}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.49:\\ \;\;\;\;x \cdot 12 - 6\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(1 - \frac{2}{x}\right)\\ \end{array} \]

Alternative 4: 95.2% accurate, 12.6× speedup?

\[\begin{array}{l} \\ 6 \cdot \frac{x + -1}{x + 1} \end{array} \]
(FPCore (x) :precision binary64 (* 6.0 (/ (+ x -1.0) (+ x 1.0))))
double code(double x) {
	return 6.0 * ((x + -1.0) / (x + 1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 6.0d0 * ((x + (-1.0d0)) / (x + 1.0d0))
end function
public static double code(double x) {
	return 6.0 * ((x + -1.0) / (x + 1.0));
}
def code(x):
	return 6.0 * ((x + -1.0) / (x + 1.0))
function code(x)
	return Float64(6.0 * Float64(Float64(x + -1.0) / Float64(x + 1.0)))
end
function tmp = code(x)
	tmp = 6.0 * ((x + -1.0) / (x + 1.0));
end
code[x_] := N[(6.0 * N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
6 \cdot \frac{x + -1}{x + 1}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. *-un-lft-identity99.8%

      \[\leadsto \frac{6 \cdot \left(x - 1\right)}{\color{blue}{1 \cdot \left(\left(x + 1\right) + 4 \cdot \sqrt{x}\right)}} \]
    2. times-frac99.9%

      \[\leadsto \color{blue}{\frac{6}{1} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \]
    3. metadata-eval99.9%

      \[\leadsto \color{blue}{6} \cdot \frac{x - 1}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    4. sub-neg99.9%

      \[\leadsto 6 \cdot \frac{\color{blue}{x + \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    5. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + \color{blue}{-1}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    6. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \]
    7. associate-+r+99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + x\right) + 1}} \]
    8. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)} + 1} \]
    9. +-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{\color{blue}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  3. Applied egg-rr99.9%

    \[\leadsto \color{blue}{6 \cdot \frac{x + -1}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
  4. Step-by-step derivation
    1. fma-udef99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
    2. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} + x\right)} \]
    3. sqrt-unprod99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} + x\right)} \]
    4. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} + x\right)} \]
    5. *-commutative99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} + x\right)} \]
    6. swap-sqr99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} + x\right)} \]
    7. add-sqr-sqrt99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} + x\right)} \]
    8. metadata-eval99.9%

      \[\leadsto 6 \cdot \frac{x + -1}{1 + \left(\sqrt{x \cdot \color{blue}{16}} + x\right)} \]
  5. Applied egg-rr99.9%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{\left(\sqrt{x \cdot 16} + x\right)}} \]
  6. Taylor expanded in x around inf 96.1%

    \[\leadsto 6 \cdot \frac{x + -1}{1 + \color{blue}{x}} \]
  7. Final simplification96.1%

    \[\leadsto 6 \cdot \frac{x + -1}{x + 1} \]

Alternative 5: 95.2% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 1.0) -6.0 (- 6.0 (/ 12.0 x))))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = -6.0d0
    else
        tmp = 6.0d0 - (12.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = -6.0
	else:
		tmp = 6.0 - (12.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = Float64(6.0 - Float64(12.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = 6.0 - (12.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.0], -6.0, N[(6.0 - N[(12.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;-6\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{12}{x}\\


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

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right) \]
      3. fma-def99.9%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right) \]
      4. sub-neg99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
    4. Taylor expanded in x around 0 96.2%

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

    if 1 < x

    1. Initial program 99.7%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.7%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.7%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.7%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}} \]
      7. associate-+l+99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{1 + \left(x + 4 \cdot \sqrt{x}\right)}} \]
      8. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      9. fma-def99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. flip-+49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}}} \]
      3. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      4. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      5. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      6. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x} \cdot \left(4 \cdot 4\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      7. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot \color{blue}{16} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      8. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} - x}} \]
      9. sqrt-unprod49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} - x}} \]
      10. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} - x}} \]
      11. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} - x}} \]
      12. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} - x}} \]
      13. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} - x}} \]
      14. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot \color{blue}{16}} - x}} \]
    5. Applied egg-rr49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot 16} - x}}} \]
    6. Step-by-step derivation
      1. distribute-lft-out--49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x \cdot \left(16 - x\right)}}{\sqrt{x \cdot 16} - x}} \]
    7. Simplified49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot \left(16 - x\right)}{\sqrt{x \cdot 16} - x}}} \]
    8. Taylor expanded in x around inf 95.7%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{x}} \]
    9. Taylor expanded in x around inf 96.0%

      \[\leadsto \color{blue}{6 - 12 \cdot \frac{1}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/96.0%

        \[\leadsto 6 - \color{blue}{\frac{12 \cdot 1}{x}} \]
      2. metadata-eval96.0%

        \[\leadsto 6 - \frac{\color{blue}{12}}{x} \]
    11. Simplified96.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \]

Alternative 6: 95.2% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;6 \cdot x - 6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 2.0) (- (* 6.0 x) 6.0) (- 6.0 (/ 12.0 x))))
double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = (6.0 * x) - 6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.0d0) then
        tmp = (6.0d0 * x) - 6.0d0
    else
        tmp = 6.0d0 - (12.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.0) {
		tmp = (6.0 * x) - 6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.0:
		tmp = (6.0 * x) - 6.0
	else:
		tmp = 6.0 - (12.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.0)
		tmp = Float64(Float64(6.0 * x) - 6.0);
	else
		tmp = Float64(6.0 - Float64(12.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.0)
		tmp = (6.0 * x) - 6.0;
	else
		tmp = 6.0 - (12.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.0], N[(N[(6.0 * x), $MachinePrecision] - 6.0), $MachinePrecision], N[(6.0 - N[(12.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;6 \cdot x - 6\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{12}{x}\\


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

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right) \]
      3. fma-def99.9%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right) \]
      4. sub-neg99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
    4. Taylor expanded in x around 0 96.2%

      \[\leadsto \frac{6}{\color{blue}{1}} \cdot \left(x + -1\right) \]
    5. Taylor expanded in x around 0 96.2%

      \[\leadsto \color{blue}{6 \cdot x - 6} \]

    if 2 < x

    1. Initial program 99.7%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.7%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.7%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.7%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}} \]
      7. associate-+l+99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{1 + \left(x + 4 \cdot \sqrt{x}\right)}} \]
      8. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      9. fma-def99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. flip-+49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}}} \]
      3. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      4. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      5. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      6. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x} \cdot \left(4 \cdot 4\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      7. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot \color{blue}{16} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      8. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} - x}} \]
      9. sqrt-unprod49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} - x}} \]
      10. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} - x}} \]
      11. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} - x}} \]
      12. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} - x}} \]
      13. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} - x}} \]
      14. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot \color{blue}{16}} - x}} \]
    5. Applied egg-rr49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot 16} - x}}} \]
    6. Step-by-step derivation
      1. distribute-lft-out--49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x \cdot \left(16 - x\right)}}{\sqrt{x \cdot 16} - x}} \]
    7. Simplified49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot \left(16 - x\right)}{\sqrt{x \cdot 16} - x}}} \]
    8. Taylor expanded in x around inf 95.7%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{x}} \]
    9. Taylor expanded in x around inf 96.0%

      \[\leadsto \color{blue}{6 - 12 \cdot \frac{1}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/96.0%

        \[\leadsto 6 - \color{blue}{\frac{12 \cdot 1}{x}} \]
      2. metadata-eval96.0%

        \[\leadsto 6 - \frac{\color{blue}{12}}{x} \]
    11. Simplified96.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;6 \cdot x - 6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \]

Alternative 7: 95.2% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.49:\\ \;\;\;\;x \cdot 12 - 6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.49) (- (* x 12.0) 6.0) (- 6.0 (/ 12.0 x))))
double code(double x) {
	double tmp;
	if (x <= 0.49) {
		tmp = (x * 12.0) - 6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.49d0) then
        tmp = (x * 12.0d0) - 6.0d0
    else
        tmp = 6.0d0 - (12.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.49) {
		tmp = (x * 12.0) - 6.0;
	} else {
		tmp = 6.0 - (12.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.49:
		tmp = (x * 12.0) - 6.0
	else:
		tmp = 6.0 - (12.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.49)
		tmp = Float64(Float64(x * 12.0) - 6.0);
	else
		tmp = Float64(6.0 - Float64(12.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.49)
		tmp = (x * 12.0) - 6.0;
	else
		tmp = 6.0 - (12.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.49], N[(N[(x * 12.0), $MachinePrecision] - 6.0), $MachinePrecision], N[(6.0 - N[(12.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.49:\\
\;\;\;\;x \cdot 12 - 6\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{12}{x}\\


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

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.9%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.9%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.9%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}} \]
      7. associate-+l+99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{1 + \left(x + 4 \cdot \sqrt{x}\right)}} \]
      8. +-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      9. fma-def99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. flip-+99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}}} \]
      3. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      4. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      5. swap-sqr99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      6. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x} \cdot \left(4 \cdot 4\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      7. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot \color{blue}{16} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      8. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} - x}} \]
      9. sqrt-unprod99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} - x}} \]
      10. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} - x}} \]
      11. *-commutative99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} - x}} \]
      12. swap-sqr99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} - x}} \]
      13. add-sqr-sqrt99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} - x}} \]
      14. metadata-eval99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot \color{blue}{16}} - x}} \]
    5. Applied egg-rr99.9%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot 16} - x}}} \]
    6. Step-by-step derivation
      1. distribute-lft-out--99.9%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x \cdot \left(16 - x\right)}}{\sqrt{x \cdot 16} - x}} \]
    7. Simplified99.9%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot \left(16 - x\right)}{\sqrt{x \cdot 16} - x}}} \]
    8. Taylor expanded in x around inf 96.2%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{x}} \]
    9. Taylor expanded in x around 0 96.2%

      \[\leadsto \color{blue}{12 \cdot x - 6} \]

    if 0.48999999999999999 < x

    1. Initial program 99.7%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. sub-neg99.7%

        \[\leadsto \frac{6 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      2. distribute-lft-in99.7%

        \[\leadsto \frac{\color{blue}{6 \cdot x + 6 \cdot \left(-1\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      3. fma-def99.7%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(6, x, 6 \cdot \left(-1\right)\right)}}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      4. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, 6 \cdot \color{blue}{-1}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      5. metadata-eval99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, \color{blue}{-6}\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
      6. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{\left(1 + x\right)} + 4 \cdot \sqrt{x}} \]
      7. associate-+l+99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{\color{blue}{1 + \left(x + 4 \cdot \sqrt{x}\right)}} \]
      8. +-commutative99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      9. fma-def99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \mathsf{fma}\left(4, \sqrt{x}, x\right)}} \]
    4. Step-by-step derivation
      1. fma-udef99.7%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\left(4 \cdot \sqrt{x} + x\right)}} \]
      2. flip-+49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}}} \]
      3. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      4. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      5. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      6. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x} \cdot \left(4 \cdot 4\right) - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      7. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot \color{blue}{16} - x \cdot x}{4 \cdot \sqrt{x} - x}} \]
      8. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{4 \cdot \sqrt{x}} \cdot \sqrt{4 \cdot \sqrt{x}}} - x}} \]
      9. sqrt-unprod49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\color{blue}{\sqrt{\left(4 \cdot \sqrt{x}\right) \cdot \left(4 \cdot \sqrt{x}\right)}} - x}} \]
      10. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot 4\right)} \cdot \left(4 \cdot \sqrt{x}\right)} - x}} \]
      11. *-commutative49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\left(\sqrt{x} \cdot 4\right) \cdot \color{blue}{\left(\sqrt{x} \cdot 4\right)}} - x}} \]
      12. swap-sqr49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \left(4 \cdot 4\right)}} - x}} \]
      13. add-sqr-sqrt49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{\color{blue}{x} \cdot \left(4 \cdot 4\right)} - x}} \]
      14. metadata-eval49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot \color{blue}{16}} - x}} \]
    5. Applied egg-rr49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot 16 - x \cdot x}{\sqrt{x \cdot 16} - x}}} \]
    6. Step-by-step derivation
      1. distribute-lft-out--49.0%

        \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \frac{\color{blue}{x \cdot \left(16 - x\right)}}{\sqrt{x \cdot 16} - x}} \]
    7. Simplified49.0%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{\frac{x \cdot \left(16 - x\right)}{\sqrt{x \cdot 16} - x}}} \]
    8. Taylor expanded in x around inf 95.7%

      \[\leadsto \frac{\mathsf{fma}\left(6, x, -6\right)}{1 + \color{blue}{x}} \]
    9. Taylor expanded in x around inf 96.0%

      \[\leadsto \color{blue}{6 - 12 \cdot \frac{1}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/96.0%

        \[\leadsto 6 - \color{blue}{\frac{12 \cdot 1}{x}} \]
      2. metadata-eval96.0%

        \[\leadsto 6 - \frac{\color{blue}{12}}{x} \]
    11. Simplified96.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.49:\\ \;\;\;\;x \cdot 12 - 6\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{12}{x}\\ \end{array} \]

Alternative 8: 95.2% accurate, 36.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-6\\ \mathbf{else}:\\ \;\;\;\;6\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 1.0) -6.0 6.0))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = -6.0d0
    else
        tmp = 6.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = -6.0;
	} else {
		tmp = 6.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = -6.0
	else:
		tmp = 6.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = 6.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = -6.0;
	else
		tmp = 6.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.0], -6.0, 6.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;-6\\

\mathbf{else}:\\
\;\;\;\;6\\


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

    1. Initial program 99.9%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right) \]
      3. fma-def99.9%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right) \]
      4. sub-neg99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
    4. Taylor expanded in x around 0 96.2%

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

    if 1 < x

    1. Initial program 99.7%

      \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
    2. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
      2. +-commutative99.9%

        \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right) \]
      3. fma-def99.9%

        \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right) \]
      4. sub-neg99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
    4. Taylor expanded in x around inf 96.0%

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

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

Alternative 9: 48.3% accurate, 113.0× speedup?

\[\begin{array}{l} \\ -6 \end{array} \]
(FPCore (x) :precision binary64 -6.0)
double code(double x) {
	return -6.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = -6.0d0
end function
public static double code(double x) {
	return -6.0;
}
def code(x):
	return -6.0
function code(x)
	return -6.0
end
function tmp = code(x)
	tmp = -6.0;
end
code[x_] := -6.0
\begin{array}{l}

\\
-6
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \]
  2. Step-by-step derivation
    1. associate-*l/99.9%

      \[\leadsto \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)} \]
    2. +-commutative99.9%

      \[\leadsto \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right) \]
    3. fma-def99.9%

      \[\leadsto \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right) \]
    4. sub-neg99.9%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    5. metadata-eval99.9%

      \[\leadsto \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)} \]
  4. Taylor expanded in x around 0 50.4%

    \[\leadsto \color{blue}{-6} \]
  5. Final simplification50.4%

    \[\leadsto -6 \]

Developer target: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0))))
double code(double x) {
	return 6.0 / (((x + 1.0) + (4.0 * sqrt(x))) / (x - 1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 6.0d0 / (((x + 1.0d0) + (4.0d0 * sqrt(x))) / (x - 1.0d0))
end function
public static double code(double x) {
	return 6.0 / (((x + 1.0) + (4.0 * Math.sqrt(x))) / (x - 1.0));
}
def code(x):
	return 6.0 / (((x + 1.0) + (4.0 * math.sqrt(x))) / (x - 1.0))
function code(x)
	return Float64(6.0 / Float64(Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x))) / Float64(x - 1.0)))
end
function tmp = code(x)
	tmp = 6.0 / (((x + 1.0) + (4.0 * sqrt(x))) / (x - 1.0));
end
code[x_] := N[(6.0 / N[(N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}
\end{array}

Reproduce

?
herbie shell --seed 2023242 
(FPCore (x)
  :name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
  :precision binary64

  :herbie-target
  (/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0)))

  (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))