sqrt sqr

Percentage Accurate: 50.6% → 100.0%
Time: 8.8s
Alternatives: 6
Speedup: 111.0×

Specification

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

\\
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot 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 6 alternatives:

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

Initial Program: 50.6% accurate, 1.0× speedup?

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

\\
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\end{array}

Alternative 1: 100.0% accurate, 1.1× speedup?

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

\\
1 - \frac{\left|x\right|}{x}
\end{array}
Derivation
  1. Initial program 49.7%

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
  2. Step-by-step derivation
    1. cancel-sign-sub-inv49.7%

      \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
    2. *-inverses49.7%

      \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
    3. distribute-frac-neg249.7%

      \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
    4. sqr-neg49.7%

      \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    5. *-inverses49.7%

      \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    6. cancel-sign-sub49.7%

      \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
    7. *-inverses49.7%

      \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    8. *-inverses49.7%

      \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    9. distribute-neg-frac49.7%

      \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    10. *-inverses49.7%

      \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    11. metadata-eval49.7%

      \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    12. associate-*l/51.2%

      \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
    13. neg-mul-151.2%

      \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
    14. distribute-neg-frac51.2%

      \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
    15. distribute-neg-frac251.2%

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

    \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 58.9% accurate, 5.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1 - \frac{\frac{1 + \left(-1 - x \cdot -2\right)}{2 - x}}{x}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 50.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv50.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses50.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg250.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg50.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses50.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub50.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses50.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses50.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac50.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses50.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval50.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/50.7%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-150.7%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac50.7%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac250.7%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u96.4%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine52.4%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine52.4%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt10.1%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log11.5%

        \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right)} - 1}{x} \]
    6. Applied egg-rr11.5%

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. associate--l+11.6%

        \[\leadsto 1 - \frac{\color{blue}{1 + \left(x - 1\right)}}{x} \]
      2. flip-+11.1%

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

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

        \[\leadsto 1 - \frac{\frac{1 - \color{blue}{\left(x + \left(-1\right)\right)} \cdot \left(x - 1\right)}{1 - \left(x - 1\right)}}{x} \]
      5. metadata-eval11.1%

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

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

        \[\leadsto 1 - \frac{\frac{1 - \left(x + -1\right) \cdot \left(x + \color{blue}{-1}\right)}{1 - \left(x - 1\right)}}{x} \]
      8. sub-neg11.1%

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

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

      \[\leadsto 1 - \frac{\color{blue}{\frac{1 - \left(x + -1\right) \cdot \left(x + -1\right)}{1 - \left(x + -1\right)}}}{x} \]
    9. Step-by-step derivation
      1. metadata-eval11.1%

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

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

        \[\leadsto 1 - \frac{\frac{1 - \left(x + -1\right) \cdot \left(x + -1\right)}{2 - \color{blue}{\left(\left(x + -1\right) + 1\right)}}}{x} \]
      4. associate-+l+11.1%

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

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

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

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

      \[\leadsto 1 - \frac{\frac{1 - \color{blue}{\left(1 + -2 \cdot x\right)}}{2 - x}}{x} \]
    12. Step-by-step derivation
      1. *-commutative18.6%

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

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

    if -3.999999999999988e-310 < x

    1. Initial program 48.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub48.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac48.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses48.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/51.6%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-151.6%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac51.6%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac251.6%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\frac{x - \left|x\right|}{x}} \]
    6. Step-by-step derivation
      1. div-sub100.0%

        \[\leadsto \color{blue}{\frac{x}{x} - \frac{\left|x\right|}{x}} \]
      2. rem-square-sqrt49.1%

        \[\leadsto \frac{x}{x} - \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x} \]
      3. fabs-sqr49.1%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x} \]
      4. rem-square-sqrt100.0%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{x}}{x} \]
      5. *-inverses100.0%

        \[\leadsto \color{blue}{1} - \frac{x}{x} \]
      6. *-inverses100.0%

        \[\leadsto 1 - \color{blue}{1} \]
      7. metadata-eval100.0%

        \[\leadsto \color{blue}{0} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;1 - \frac{\frac{1 + \left(-1 - x \cdot -2\right)}{2 - x}}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 57.0% accurate, 5.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+16}:\\
\;\;\;\;1 - x \cdot \left(\left(x + 2\right) \cdot \frac{1}{x \cdot \left(x + 2\right)}\right)\\

\mathbf{elif}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 48.9%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.9%

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

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.9%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.9%

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

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

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.9%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.9%

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

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

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.9%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/48.9%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-148.9%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac48.9%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac248.9%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u92.0%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine92.0%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine92.0%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log3.1%

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

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. clear-num3.1%

        \[\leadsto 1 - \color{blue}{\frac{1}{\frac{x}{\left(1 + x\right) - 1}}} \]
      2. associate-/r/4.1%

        \[\leadsto 1 - \color{blue}{\frac{1}{x} \cdot \left(\left(1 + x\right) - 1\right)} \]
      3. add-exp-log0.0%

        \[\leadsto 1 - \frac{1}{x} \cdot \left(\color{blue}{e^{\log \left(1 + x\right)}} - 1\right) \]
      4. expm1-define0.0%

        \[\leadsto 1 - \frac{1}{x} \cdot \color{blue}{\mathsf{expm1}\left(\log \left(1 + x\right)\right)} \]
      5. log1p-define0.0%

        \[\leadsto 1 - \frac{1}{x} \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(x\right)}\right) \]
      6. expm1-log1p-u4.1%

        \[\leadsto 1 - \frac{1}{x} \cdot \color{blue}{x} \]
    8. Applied egg-rr4.1%

      \[\leadsto 1 - \color{blue}{\frac{1}{x} \cdot x} \]
    9. Step-by-step derivation
      1. *-inverses4.1%

        \[\leadsto 1 - \frac{\color{blue}{\frac{x + 2}{x + 2}}}{x} \cdot x \]
      2. associate-/r*12.1%

        \[\leadsto 1 - \color{blue}{\frac{x + 2}{\left(x + 2\right) \cdot x}} \cdot x \]
      3. clear-num12.2%

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

        \[\leadsto 1 - \color{blue}{\left(\frac{1}{\left(x + 2\right) \cdot x} \cdot \left(x + 2\right)\right)} \cdot x \]
      5. *-commutative12.1%

        \[\leadsto 1 - \left(\frac{1}{\color{blue}{x \cdot \left(x + 2\right)}} \cdot \left(x + 2\right)\right) \cdot x \]
    10. Applied egg-rr12.1%

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

    if -5e16 < x < -3.999999999999988e-310

    1. Initial program 52.2%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv52.2%

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

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg252.2%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg52.2%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses52.2%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub52.2%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses52.2%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses52.2%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac52.2%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses52.2%

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

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/52.2%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-152.2%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac52.2%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac252.2%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u99.9%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine20.3%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine20.3%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt18.2%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log18.3%

        \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right)} - 1}{x} \]
    6. Applied egg-rr18.3%

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. associate--l+18.4%

        \[\leadsto 1 - \frac{\color{blue}{1 + \left(x - 1\right)}}{x} \]
      2. +-commutative18.4%

        \[\leadsto 1 - \frac{\color{blue}{\left(x - 1\right) + 1}}{x} \]
      3. sub-neg18.4%

        \[\leadsto 1 - \frac{\color{blue}{\left(x + \left(-1\right)\right)} + 1}{x} \]
      4. metadata-eval18.4%

        \[\leadsto 1 - \frac{\left(x + \color{blue}{-1}\right) + 1}{x} \]
    8. Applied egg-rr18.4%

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

    if -3.999999999999988e-310 < x

    1. Initial program 48.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub48.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac48.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses48.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/51.6%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-151.6%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac51.6%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac251.6%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\frac{x - \left|x\right|}{x}} \]
    6. Step-by-step derivation
      1. div-sub100.0%

        \[\leadsto \color{blue}{\frac{x}{x} - \frac{\left|x\right|}{x}} \]
      2. rem-square-sqrt49.1%

        \[\leadsto \frac{x}{x} - \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x} \]
      3. fabs-sqr49.1%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x} \]
      4. rem-square-sqrt100.0%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{x}}{x} \]
      5. *-inverses100.0%

        \[\leadsto \color{blue}{1} - \frac{x}{x} \]
      6. *-inverses100.0%

        \[\leadsto 1 - \color{blue}{1} \]
      7. metadata-eval100.0%

        \[\leadsto \color{blue}{0} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+16}:\\ \;\;\;\;1 - x \cdot \left(\left(x + 2\right) \cdot \frac{1}{x \cdot \left(x + 2\right)}\right)\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 57.0% accurate, 5.8× speedup?

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

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

\mathbf{elif}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 48.9%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.9%

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

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.9%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.9%

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

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

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.9%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.9%

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

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

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.9%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/48.9%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-148.9%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac48.9%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac248.9%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u92.0%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine92.0%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine92.0%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log3.1%

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

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. add-exp-log3.1%

        \[\leadsto 1 - \color{blue}{e^{\log \left(\frac{\left(1 + x\right) - 1}{x}\right)}} \]
      2. log-div0.0%

        \[\leadsto 1 - e^{\color{blue}{\log \left(\left(1 + x\right) - 1\right) - \log x}} \]
      3. associate--l+0.0%

        \[\leadsto 1 - e^{\log \color{blue}{\left(1 + \left(x - 1\right)\right)} - \log x} \]
      4. log1p-define0.0%

        \[\leadsto 1 - e^{\color{blue}{\mathsf{log1p}\left(x - 1\right)} - \log x} \]
      5. add-exp-log0.0%

        \[\leadsto 1 - e^{\mathsf{log1p}\left(\color{blue}{e^{\log x}} - 1\right) - \log x} \]
      6. expm1-define0.0%

        \[\leadsto 1 - e^{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log x\right)}\right) - \log x} \]
      7. log1p-expm1-u0.0%

        \[\leadsto 1 - e^{\color{blue}{\log x} - \log x} \]
      8. log1p-expm1-u0.0%

        \[\leadsto 1 - e^{\log x - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log x\right)\right)}} \]
      9. expm1-define0.0%

        \[\leadsto 1 - e^{\log x - \mathsf{log1p}\left(\color{blue}{e^{\log x} - 1}\right)} \]
      10. add-exp-log0.0%

        \[\leadsto 1 - e^{\log x - \mathsf{log1p}\left(\color{blue}{x} - 1\right)} \]
      11. log1p-define0.0%

        \[\leadsto 1 - e^{\log x - \color{blue}{\log \left(1 + \left(x - 1\right)\right)}} \]
      12. associate--l+0.0%

        \[\leadsto 1 - e^{\log x - \log \color{blue}{\left(\left(1 + x\right) - 1\right)}} \]
      13. div-exp0.0%

        \[\leadsto 1 - \color{blue}{\frac{e^{\log x}}{e^{\log \left(\left(1 + x\right) - 1\right)}}} \]
      14. add-exp-log0.0%

        \[\leadsto 1 - \frac{\color{blue}{x}}{e^{\log \left(\left(1 + x\right) - 1\right)}} \]
      15. add-exp-log3.1%

        \[\leadsto 1 - \frac{x}{\color{blue}{\left(1 + x\right) - 1}} \]
      16. flip--11.8%

        \[\leadsto 1 - \frac{x}{\color{blue}{\frac{\left(1 + x\right) \cdot \left(1 + x\right) - 1 \cdot 1}{\left(1 + x\right) + 1}}} \]
      17. associate-/r/12.1%

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

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

    if -1e20 < x < -3.999999999999988e-310

    1. Initial program 52.2%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv52.2%

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

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg252.2%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg52.2%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses52.2%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub52.2%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses52.2%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses52.2%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac52.2%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses52.2%

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

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/52.2%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-152.2%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac52.2%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac252.2%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u99.9%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine20.3%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine20.3%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt18.2%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log18.3%

        \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right)} - 1}{x} \]
    6. Applied egg-rr18.3%

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. associate--l+18.4%

        \[\leadsto 1 - \frac{\color{blue}{1 + \left(x - 1\right)}}{x} \]
      2. +-commutative18.4%

        \[\leadsto 1 - \frac{\color{blue}{\left(x - 1\right) + 1}}{x} \]
      3. sub-neg18.4%

        \[\leadsto 1 - \frac{\color{blue}{\left(x + \left(-1\right)\right)} + 1}{x} \]
      4. metadata-eval18.4%

        \[\leadsto 1 - \frac{\left(x + \color{blue}{-1}\right) + 1}{x} \]
    8. Applied egg-rr18.4%

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

    if -3.999999999999988e-310 < x

    1. Initial program 48.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub48.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac48.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses48.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/51.6%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-151.6%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac51.6%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac251.6%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\frac{x - \left|x\right|}{x}} \]
    6. Step-by-step derivation
      1. div-sub100.0%

        \[\leadsto \color{blue}{\frac{x}{x} - \frac{\left|x\right|}{x}} \]
      2. rem-square-sqrt49.1%

        \[\leadsto \frac{x}{x} - \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x} \]
      3. fabs-sqr49.1%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x} \]
      4. rem-square-sqrt100.0%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{x}}{x} \]
      5. *-inverses100.0%

        \[\leadsto \color{blue}{1} - \frac{x}{x} \]
      6. *-inverses100.0%

        \[\leadsto 1 - \color{blue}{1} \]
      7. metadata-eval100.0%

        \[\leadsto \color{blue}{0} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+20}:\\ \;\;\;\;1 - \left(x + 2\right) \cdot \frac{x}{x \cdot \left(x + 2\right)}\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 54.9% accurate, 7.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 50.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv50.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses50.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg250.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg50.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses50.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub50.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses50.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses50.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac50.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses50.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval50.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/50.7%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-150.7%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac50.7%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac250.7%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u96.4%

        \[\leadsto 1 - \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left|x\right|\right)\right)}}{x} \]
      2. expm1-undefine52.4%

        \[\leadsto 1 - \frac{\color{blue}{e^{\mathsf{log1p}\left(\left|x\right|\right)} - 1}}{x} \]
      3. log1p-undefine52.4%

        \[\leadsto 1 - \frac{e^{\color{blue}{\log \left(1 + \left|x\right|\right)}} - 1}{x} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)} - 1}{x} \]
      5. fabs-sqr0.0%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)} - 1}{x} \]
      6. add-sqr-sqrt10.1%

        \[\leadsto 1 - \frac{e^{\log \left(1 + \color{blue}{x}\right)} - 1}{x} \]
      7. rem-exp-log11.5%

        \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right)} - 1}{x} \]
    6. Applied egg-rr11.5%

      \[\leadsto 1 - \frac{\color{blue}{\left(1 + x\right) - 1}}{x} \]
    7. Step-by-step derivation
      1. associate--l+11.6%

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

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

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

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

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

    if -3.999999999999988e-310 < x

    1. Initial program 48.7%

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Step-by-step derivation
      1. cancel-sign-sub-inv48.7%

        \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
      2. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
      3. distribute-frac-neg248.7%

        \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
      4. sqr-neg48.7%

        \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
      5. *-inverses48.7%

        \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      6. cancel-sign-sub48.7%

        \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      7. *-inverses48.7%

        \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      8. *-inverses48.7%

        \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      9. distribute-neg-frac48.7%

        \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      10. *-inverses48.7%

        \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      11. metadata-eval48.7%

        \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
      12. associate-*l/51.6%

        \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
      13. neg-mul-151.6%

        \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
      14. distribute-neg-frac51.6%

        \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
      15. distribute-neg-frac251.6%

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

      \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\frac{x - \left|x\right|}{x}} \]
    6. Step-by-step derivation
      1. div-sub100.0%

        \[\leadsto \color{blue}{\frac{x}{x} - \frac{\left|x\right|}{x}} \]
      2. rem-square-sqrt49.1%

        \[\leadsto \frac{x}{x} - \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x} \]
      3. fabs-sqr49.1%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x} \]
      4. rem-square-sqrt100.0%

        \[\leadsto \frac{x}{x} - \frac{\color{blue}{x}}{x} \]
      5. *-inverses100.0%

        \[\leadsto \color{blue}{1} - \frac{x}{x} \]
      6. *-inverses100.0%

        \[\leadsto 1 - \color{blue}{1} \]
      7. metadata-eval100.0%

        \[\leadsto \color{blue}{0} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification57.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;1 - \frac{1 + \left(x + -1\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 51.1% accurate, 111.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 49.7%

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
  2. Step-by-step derivation
    1. cancel-sign-sub-inv49.7%

      \[\leadsto \color{blue}{\frac{x}{x} + \left(-\frac{1}{x}\right) \cdot \sqrt{x \cdot x}} \]
    2. *-inverses49.7%

      \[\leadsto \frac{x}{x} + \left(-\frac{\color{blue}{\frac{x}{x}}}{x}\right) \cdot \sqrt{x \cdot x} \]
    3. distribute-frac-neg249.7%

      \[\leadsto \frac{x}{x} + \color{blue}{\frac{\frac{x}{x}}{-x}} \cdot \sqrt{x \cdot x} \]
    4. sqr-neg49.7%

      \[\leadsto \frac{x}{x} + \frac{\frac{x}{x}}{-x} \cdot \sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    5. *-inverses49.7%

      \[\leadsto \frac{x}{x} + \frac{\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    6. cancel-sign-sub49.7%

      \[\leadsto \color{blue}{\frac{x}{x} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
    7. *-inverses49.7%

      \[\leadsto \color{blue}{1} - \left(-\frac{1}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    8. *-inverses49.7%

      \[\leadsto 1 - \left(-\frac{\color{blue}{\frac{x}{x}}}{-x}\right) \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    9. distribute-neg-frac49.7%

      \[\leadsto 1 - \color{blue}{\frac{-\frac{x}{x}}{-x}} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    10. *-inverses49.7%

      \[\leadsto 1 - \frac{-\color{blue}{1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    11. metadata-eval49.7%

      \[\leadsto 1 - \frac{\color{blue}{-1}}{-x} \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)} \]
    12. associate-*l/51.2%

      \[\leadsto 1 - \color{blue}{\frac{-1 \cdot \sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}} \]
    13. neg-mul-151.2%

      \[\leadsto 1 - \frac{\color{blue}{-\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{-x} \]
    14. distribute-neg-frac51.2%

      \[\leadsto 1 - \color{blue}{\left(-\frac{\sqrt{\left(-x\right) \cdot \left(-x\right)}}{-x}\right)} \]
    15. distribute-neg-frac251.2%

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

    \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 100.0%

    \[\leadsto \color{blue}{\frac{x - \left|x\right|}{x}} \]
  6. Step-by-step derivation
    1. div-sub100.0%

      \[\leadsto \color{blue}{\frac{x}{x} - \frac{\left|x\right|}{x}} \]
    2. rem-square-sqrt25.5%

      \[\leadsto \frac{x}{x} - \frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{x} \]
    3. fabs-sqr25.5%

      \[\leadsto \frac{x}{x} - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{x} \]
    4. rem-square-sqrt53.5%

      \[\leadsto \frac{x}{x} - \frac{\color{blue}{x}}{x} \]
    5. *-inverses53.5%

      \[\leadsto \color{blue}{1} - \frac{x}{x} \]
    6. *-inverses53.5%

      \[\leadsto 1 - \color{blue}{1} \]
    7. metadata-eval53.5%

      \[\leadsto \color{blue}{0} \]
  7. Simplified53.5%

    \[\leadsto \color{blue}{0} \]
  8. Add Preprocessing

Developer Target 1: 100.0% accurate, 18.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x < 0:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024179 
(FPCore (x)
  :name "sqrt sqr"
  :precision binary64

  :alt
  (! :herbie-platform default (if (< x 0) 2 0))

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))