Data.Approximate.Numerics:blog from approximate-0.2.2.1

Percentage Accurate: 99.7% → 99.9%
Time: 7.4s
Alternatives: 7
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 7 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.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}
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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
    2. sub-neg99.9%

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

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

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

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

Alternative 2: 99.9% accurate, 1.0× speedup?

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

\\
-6 \cdot \frac{x + -1}{\sqrt{x} \cdot -4 + \left(-1 - x\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. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 94.8% accurate, 10.3× speedup?

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

\\
\left(6 \cdot \left(1 - x\right)\right) \cdot \frac{1}{-1 - x}
\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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
    2. sub-neg99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 95.1% accurate, 16.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;6 \cdot \left(x + -1\right)\\

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


\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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-1} \cdot \left(6 \cdot \left(1 - x\right)\right) \]
      3. neg-mul-194.6%

        \[\leadsto \color{blue}{-6 \cdot \left(1 - x\right)} \]
      4. *-commutative94.6%

        \[\leadsto -\color{blue}{\left(1 - x\right) \cdot 6} \]
      5. distribute-lft-neg-in94.6%

        \[\leadsto \color{blue}{\left(-\left(1 - x\right)\right) \cdot 6} \]
      6. sub-neg94.6%

        \[\leadsto \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \cdot 6 \]
      7. distribute-neg-in94.6%

        \[\leadsto \color{blue}{\left(\left(-1\right) + \left(-\left(-x\right)\right)\right)} \cdot 6 \]
      8. metadata-eval94.6%

        \[\leadsto \left(\color{blue}{-1} + \left(-\left(-x\right)\right)\right) \cdot 6 \]
      9. remove-double-neg94.6%

        \[\leadsto \left(-1 + \color{blue}{x}\right) \cdot 6 \]
      10. +-commutative94.6%

        \[\leadsto \color{blue}{\left(x + -1\right)} \cdot 6 \]
    12. Applied egg-rr94.6%

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

    if 2 < x

    1. Initial program 99.6%

      \[\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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

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

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

Alternative 5: 95.2% accurate, 16.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;6 \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;6 - \frac{6}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 1.0) (* 6.0 (+ x -1.0)) (- 6.0 (/ 6.0 x))))
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 6.0 * (x + -1.0);
	} else {
		tmp = 6.0 - (6.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 * (x + (-1.0d0))
    else
        tmp = 6.0d0 - (6.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 6.0 * (x + -1.0);
	} else {
		tmp = 6.0 - (6.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = 6.0 * (x + -1.0)
	else:
		tmp = 6.0 - (6.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = Float64(6.0 * Float64(x + -1.0));
	else
		tmp = Float64(6.0 - Float64(6.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = 6.0 * (x + -1.0);
	else
		tmp = 6.0 - (6.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 1.0], N[(6.0 * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(6.0 - N[(6.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;6 \cdot \left(x + -1\right)\\

\mathbf{else}:\\
\;\;\;\;6 - \frac{6}{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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-1} \cdot \left(6 \cdot \left(1 - x\right)\right) \]
      3. neg-mul-195.2%

        \[\leadsto \color{blue}{-6 \cdot \left(1 - x\right)} \]
      4. *-commutative95.2%

        \[\leadsto -\color{blue}{\left(1 - x\right) \cdot 6} \]
      5. distribute-lft-neg-in95.2%

        \[\leadsto \color{blue}{\left(-\left(1 - x\right)\right) \cdot 6} \]
      6. sub-neg95.2%

        \[\leadsto \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \cdot 6 \]
      7. distribute-neg-in95.2%

        \[\leadsto \color{blue}{\left(\left(-1\right) + \left(-\left(-x\right)\right)\right)} \cdot 6 \]
      8. metadata-eval95.2%

        \[\leadsto \left(\color{blue}{-1} + \left(-\left(-x\right)\right)\right) \cdot 6 \]
      9. remove-double-neg95.2%

        \[\leadsto \left(-1 + \color{blue}{x}\right) \cdot 6 \]
      10. +-commutative95.2%

        \[\leadsto \color{blue}{\left(x + -1\right)} \cdot 6 \]
    12. Applied egg-rr95.2%

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

    if 1 < x

    1. Initial program 99.6%

      \[\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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

      \[\leadsto \frac{6}{\frac{\color{blue}{x}}{x + -1}} \]
    5. Taylor expanded in x around 0 95.5%

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

        \[\leadsto 6 - \color{blue}{\frac{6 \cdot 1}{x}} \]
      2. metadata-eval95.5%

        \[\leadsto 6 - \frac{\color{blue}{6}}{x} \]
    7. Simplified95.5%

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

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

Alternative 6: 95.1% 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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

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

    if 1 < x

    1. Initial program 99.6%

      \[\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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
      2. sub-neg99.9%

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

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

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

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

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

Alternative 7: 49.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}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}} \]
    2. sub-neg99.9%

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

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

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

    \[\leadsto \color{blue}{-6} \]
  5. Final simplification45.1%

    \[\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 2023308 
(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)))))