Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.3s
Alternatives: 8
Speedup: 2.0×

Specification

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

\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}

Alternative 1: 100.0% accurate, 2.0× speedup?

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

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

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-fabs100.0%

      \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
    2. div-sub100.0%

      \[\leadsto \left|\color{blue}{\frac{x}{y} - \frac{y}{y}}\right| \]
    3. pow1100.0%

      \[\leadsto \left|\frac{x}{y} - \frac{\color{blue}{{y}^{1}}}{y}\right| \]
    4. pow1100.0%

      \[\leadsto \left|\frac{x}{y} - \frac{{y}^{1}}{\color{blue}{{y}^{1}}}\right| \]
    5. pow-div100.0%

      \[\leadsto \left|\frac{x}{y} - \color{blue}{{y}^{\left(1 - 1\right)}}\right| \]
    6. metadata-eval100.0%

      \[\leadsto \left|\frac{x}{y} - {y}^{\color{blue}{0}}\right| \]
    7. metadata-eval100.0%

      \[\leadsto \left|\frac{x}{y} - \color{blue}{1}\right| \]
  4. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\left|\frac{x}{y} - 1\right|} \]
  5. Final simplification100.0%

    \[\leadsto \left|\frac{x}{y} + -1\right| \]
  6. Add Preprocessing

Alternative 2: 57.2% accurate, 7.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-x}{y}\\ \mathbf{if}\;x \leq -2.65 \cdot 10^{+144}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{+36}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.62 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{+136}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (- x) y)))
   (if (<= x -2.65e+144)
     (/ x y)
     (if (<= x -9.5e+46)
       t_0
       (if (<= x 4.3e+36)
         1.0
         (if (<= x 1.62e+59) t_0 (if (<= x 1.2e+136) 1.0 (/ x y))))))))
double code(double x, double y) {
	double t_0 = -x / y;
	double tmp;
	if (x <= -2.65e+144) {
		tmp = x / y;
	} else if (x <= -9.5e+46) {
		tmp = t_0;
	} else if (x <= 4.3e+36) {
		tmp = 1.0;
	} else if (x <= 1.62e+59) {
		tmp = t_0;
	} else if (x <= 1.2e+136) {
		tmp = 1.0;
	} else {
		tmp = x / y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -x / y
    if (x <= (-2.65d+144)) then
        tmp = x / y
    else if (x <= (-9.5d+46)) then
        tmp = t_0
    else if (x <= 4.3d+36) then
        tmp = 1.0d0
    else if (x <= 1.62d+59) then
        tmp = t_0
    else if (x <= 1.2d+136) then
        tmp = 1.0d0
    else
        tmp = x / y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = -x / y;
	double tmp;
	if (x <= -2.65e+144) {
		tmp = x / y;
	} else if (x <= -9.5e+46) {
		tmp = t_0;
	} else if (x <= 4.3e+36) {
		tmp = 1.0;
	} else if (x <= 1.62e+59) {
		tmp = t_0;
	} else if (x <= 1.2e+136) {
		tmp = 1.0;
	} else {
		tmp = x / y;
	}
	return tmp;
}
def code(x, y):
	t_0 = -x / y
	tmp = 0
	if x <= -2.65e+144:
		tmp = x / y
	elif x <= -9.5e+46:
		tmp = t_0
	elif x <= 4.3e+36:
		tmp = 1.0
	elif x <= 1.62e+59:
		tmp = t_0
	elif x <= 1.2e+136:
		tmp = 1.0
	else:
		tmp = x / y
	return tmp
function code(x, y)
	t_0 = Float64(Float64(-x) / y)
	tmp = 0.0
	if (x <= -2.65e+144)
		tmp = Float64(x / y);
	elseif (x <= -9.5e+46)
		tmp = t_0;
	elseif (x <= 4.3e+36)
		tmp = 1.0;
	elseif (x <= 1.62e+59)
		tmp = t_0;
	elseif (x <= 1.2e+136)
		tmp = 1.0;
	else
		tmp = Float64(x / y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = -x / y;
	tmp = 0.0;
	if (x <= -2.65e+144)
		tmp = x / y;
	elseif (x <= -9.5e+46)
		tmp = t_0;
	elseif (x <= 4.3e+36)
		tmp = 1.0;
	elseif (x <= 1.62e+59)
		tmp = t_0;
	elseif (x <= 1.2e+136)
		tmp = 1.0;
	else
		tmp = x / y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[((-x) / y), $MachinePrecision]}, If[LessEqual[x, -2.65e+144], N[(x / y), $MachinePrecision], If[LessEqual[x, -9.5e+46], t$95$0, If[LessEqual[x, 4.3e+36], 1.0, If[LessEqual[x, 1.62e+59], t$95$0, If[LessEqual[x, 1.2e+136], 1.0, N[(x / y), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-x}{y}\\
\mathbf{if}\;x \leq -2.65 \cdot 10^{+144}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -9.5 \cdot 10^{+46}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 4.3 \cdot 10^{+36}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 1.62 \cdot 10^{+59}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.2 \cdot 10^{+136}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.6499999999999998e144 or 1.2e136 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt45.3%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt45.7%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt26.5%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr26.5%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt61.9%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/62.0%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr62.0%

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

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if -2.6499999999999998e144 < x < -9.5000000000000008e46 or 4.30000000000000005e36 < x < 1.6200000000000001e59

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.8%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt55.1%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt55.7%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt3.9%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr3.9%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt23.0%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/22.8%

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/23.0%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity23.0%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. frac-2neg23.0%

        \[\leadsto \color{blue}{\frac{-\left(x - y\right)}{-y}} \]
      4. sub-neg23.0%

        \[\leadsto \frac{-\color{blue}{\left(x + \left(-y\right)\right)}}{-y} \]
      5. distribute-neg-in23.0%

        \[\leadsto \frac{\color{blue}{\left(-x\right) + \left(-\left(-y\right)\right)}}{-y} \]
      6. remove-double-neg23.0%

        \[\leadsto \frac{\left(-x\right) + \color{blue}{y}}{-y} \]
      7. add-sqr-sqrt18.7%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      8. sqrt-unprod56.9%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      9. sqr-neg56.9%

        \[\leadsto \frac{\left(-x\right) + y}{\sqrt{\color{blue}{y \cdot y}}} \]
      10. sqrt-unprod51.4%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      11. add-sqr-sqrt77.9%

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

      \[\leadsto \color{blue}{\frac{\left(-x\right) + y}{y}} \]
    7. Taylor expanded in x around inf 60.4%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{y}} \]
      2. mul-1-neg60.4%

        \[\leadsto \frac{\color{blue}{-x}}{y} \]
    9. Simplified60.4%

      \[\leadsto \color{blue}{\frac{-x}{y}} \]

    if -9.5000000000000008e46 < x < 4.30000000000000005e36 or 1.6200000000000001e59 < x < 1.2e136

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt46.1%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt47.2%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt9.3%

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

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt14.8%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/14.9%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr14.9%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/14.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity14.9%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. sub-neg14.9%

        \[\leadsto \frac{\color{blue}{x + \left(-y\right)}}{y} \]
      4. add-sqr-sqrt5.6%

        \[\leadsto \frac{x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y} \]
      5. sqrt-unprod28.7%

        \[\leadsto \frac{x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y} \]
      6. sqr-neg28.7%

        \[\leadsto \frac{x + \sqrt{\color{blue}{y \cdot y}}}{y} \]
      7. sqrt-unprod37.9%

        \[\leadsto \frac{x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y} \]
      8. add-sqr-sqrt81.5%

        \[\leadsto \frac{x + \color{blue}{y}}{y} \]
    6. Applied egg-rr81.5%

      \[\leadsto \color{blue}{\frac{x + y}{y}} \]
    7. Taylor expanded in x around 0 69.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{+144}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{+46}:\\ \;\;\;\;\frac{-x}{y}\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{+36}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.62 \cdot 10^{+59}:\\ \;\;\;\;\frac{-x}{y}\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{+136}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 73.2% accurate, 8.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+104} \lor \neg \left(x \leq -4.5 \cdot 10^{+49} \lor \neg \left(x \leq -3 \cdot 10^{-56}\right) \land x \leq 2.2 \cdot 10^{+49}\right):\\ \;\;\;\;\frac{x + y}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.5e+104)
         (not (or (<= x -4.5e+49) (and (not (<= x -3e-56)) (<= x 2.2e+49)))))
   (/ (+ x y) y)
   (- 1.0 (/ x y))))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.5e+104) || !((x <= -4.5e+49) || (!(x <= -3e-56) && (x <= 2.2e+49)))) {
		tmp = (x + y) / y;
	} else {
		tmp = 1.0 - (x / y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.5d+104)) .or. (.not. (x <= (-4.5d+49)) .or. (.not. (x <= (-3d-56))) .and. (x <= 2.2d+49))) then
        tmp = (x + y) / y
    else
        tmp = 1.0d0 - (x / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.5e+104) || !((x <= -4.5e+49) || (!(x <= -3e-56) && (x <= 2.2e+49)))) {
		tmp = (x + y) / y;
	} else {
		tmp = 1.0 - (x / y);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.5e+104) or not ((x <= -4.5e+49) or (not (x <= -3e-56) and (x <= 2.2e+49))):
		tmp = (x + y) / y
	else:
		tmp = 1.0 - (x / y)
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.5e+104) || !((x <= -4.5e+49) || (!(x <= -3e-56) && (x <= 2.2e+49))))
		tmp = Float64(Float64(x + y) / y);
	else
		tmp = Float64(1.0 - Float64(x / y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.5e+104) || ~(((x <= -4.5e+49) || (~((x <= -3e-56)) && (x <= 2.2e+49)))))
		tmp = (x + y) / y;
	else
		tmp = 1.0 - (x / y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.5e+104], N[Not[Or[LessEqual[x, -4.5e+49], And[N[Not[LessEqual[x, -3e-56]], $MachinePrecision], LessEqual[x, 2.2e+49]]]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+104} \lor \neg \left(x \leq -4.5 \cdot 10^{+49} \lor \neg \left(x \leq -3 \cdot 10^{-56}\right) \land x \leq 2.2 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{x + y}{y}\\

\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.49999999999999984e104 or -4.49999999999999982e49 < x < -2.99999999999999989e-56 or 2.2000000000000001e49 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.8%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt42.4%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt43.0%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt20.7%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr20.7%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt49.2%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/49.2%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr49.2%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/49.3%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity49.3%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. sub-neg49.3%

        \[\leadsto \frac{\color{blue}{x + \left(-y\right)}}{y} \]
      4. add-sqr-sqrt28.6%

        \[\leadsto \frac{x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y} \]
      5. sqrt-unprod48.3%

        \[\leadsto \frac{x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y} \]
      6. sqr-neg48.3%

        \[\leadsto \frac{x + \sqrt{\color{blue}{y \cdot y}}}{y} \]
      7. sqrt-unprod31.3%

        \[\leadsto \frac{x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y} \]
      8. add-sqr-sqrt79.2%

        \[\leadsto \frac{x + \color{blue}{y}}{y} \]
    6. Applied egg-rr79.2%

      \[\leadsto \color{blue}{\frac{x + y}{y}} \]

    if -1.49999999999999984e104 < x < -4.49999999999999982e49 or -2.99999999999999989e-56 < x < 2.2000000000000001e49

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt50.6%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt51.7%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt7.0%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr7.0%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt10.6%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/10.6%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr10.6%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/10.6%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity10.6%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. frac-2neg10.6%

        \[\leadsto \color{blue}{\frac{-\left(x - y\right)}{-y}} \]
      4. sub-neg10.6%

        \[\leadsto \frac{-\color{blue}{\left(x + \left(-y\right)\right)}}{-y} \]
      5. distribute-neg-in10.6%

        \[\leadsto \frac{\color{blue}{\left(-x\right) + \left(-\left(-y\right)\right)}}{-y} \]
      6. remove-double-neg10.6%

        \[\leadsto \frac{\left(-x\right) + \color{blue}{y}}{-y} \]
      7. add-sqr-sqrt3.5%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      8. sqrt-unprod24.7%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      9. sqr-neg24.7%

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

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      11. add-sqr-sqrt90.7%

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

      \[\leadsto \color{blue}{\frac{\left(-x\right) + y}{y}} \]
    7. Taylor expanded in x around 0 90.7%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg90.7%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x}{y}\right)} \]
      2. unsub-neg90.7%

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    9. Simplified90.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+104} \lor \neg \left(x \leq -4.5 \cdot 10^{+49} \lor \neg \left(x \leq -3 \cdot 10^{-56}\right) \land x \leq 2.2 \cdot 10^{+49}\right):\\ \;\;\;\;\frac{x + y}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 70.6% accurate, 13.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{+144} \lor \neg \left(x \leq 1.15 \cdot 10^{+137}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.1e+144) (not (<= x 1.15e+137))) (/ x y) (- 1.0 (/ x y))))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.1e+144) || !(x <= 1.15e+137)) {
		tmp = x / y;
	} else {
		tmp = 1.0 - (x / y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.1d+144)) .or. (.not. (x <= 1.15d+137))) then
        tmp = x / y
    else
        tmp = 1.0d0 - (x / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.1e+144) || !(x <= 1.15e+137)) {
		tmp = x / y;
	} else {
		tmp = 1.0 - (x / y);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.1e+144) or not (x <= 1.15e+137):
		tmp = x / y
	else:
		tmp = 1.0 - (x / y)
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.1e+144) || !(x <= 1.15e+137))
		tmp = Float64(x / y);
	else
		tmp = Float64(1.0 - Float64(x / y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.1e+144) || ~((x <= 1.15e+137)))
		tmp = x / y;
	else
		tmp = 1.0 - (x / y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.1e+144], N[Not[LessEqual[x, 1.15e+137]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+144} \lor \neg \left(x \leq 1.15 \cdot 10^{+137}\right):\\
\;\;\;\;\frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.09999999999999994e144 or 1.15e137 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt45.3%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt45.7%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt26.5%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr26.5%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt61.9%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/62.0%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr62.0%

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

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if -1.09999999999999994e144 < x < 1.15e137

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt47.4%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt48.4%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt8.5%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr8.5%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt16.0%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/16.0%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr16.0%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/16.1%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity16.1%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. frac-2neg16.1%

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

        \[\leadsto \frac{-\color{blue}{\left(x + \left(-y\right)\right)}}{-y} \]
      5. distribute-neg-in16.1%

        \[\leadsto \frac{\color{blue}{\left(-x\right) + \left(-\left(-y\right)\right)}}{-y} \]
      6. remove-double-neg16.1%

        \[\leadsto \frac{\left(-x\right) + \color{blue}{y}}{-y} \]
      7. add-sqr-sqrt7.5%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      8. sqrt-unprod23.7%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      9. sqr-neg23.7%

        \[\leadsto \frac{\left(-x\right) + y}{\sqrt{\color{blue}{y \cdot y}}} \]
      10. sqrt-unprod39.6%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      11. add-sqr-sqrt85.2%

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

      \[\leadsto \color{blue}{\frac{\left(-x\right) + y}{y}} \]
    7. Taylor expanded in x around 0 85.2%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg85.2%

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

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    9. Simplified85.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{+144} \lor \neg \left(x \leq 1.15 \cdot 10^{+137}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 70.5% accurate, 13.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+144}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq 3.3 \cdot 10^{+136}:\\
\;\;\;\;1 - \frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y} + -1\\


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

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.8%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt27.4%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt27.9%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt0.2%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr0.2%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt60.3%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/60.4%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr60.4%

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

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if -2.3000000000000001e144 < x < 3.29999999999999992e136

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt47.4%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt48.4%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt8.5%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr8.5%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt16.0%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/16.0%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr16.0%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/16.1%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity16.1%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. frac-2neg16.1%

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

        \[\leadsto \frac{-\color{blue}{\left(x + \left(-y\right)\right)}}{-y} \]
      5. distribute-neg-in16.1%

        \[\leadsto \frac{\color{blue}{\left(-x\right) + \left(-\left(-y\right)\right)}}{-y} \]
      6. remove-double-neg16.1%

        \[\leadsto \frac{\left(-x\right) + \color{blue}{y}}{-y} \]
      7. add-sqr-sqrt7.5%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      8. sqrt-unprod23.7%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      9. sqr-neg23.7%

        \[\leadsto \frac{\left(-x\right) + y}{\sqrt{\color{blue}{y \cdot y}}} \]
      10. sqrt-unprod39.6%

        \[\leadsto \frac{\left(-x\right) + y}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      11. add-sqr-sqrt85.2%

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

      \[\leadsto \color{blue}{\frac{\left(-x\right) + y}{y}} \]
    7. Taylor expanded in x around 0 85.2%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg85.2%

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

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    9. Simplified85.2%

      \[\leadsto \color{blue}{1 - \frac{x}{y}} \]

    if 3.29999999999999992e136 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt92.3%

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

        \[\leadsto \frac{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}{\left|y\right|} \]
      3. add-sqr-sqrt63.9%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \]
      4. fabs-sqr63.9%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt64.2%

        \[\leadsto \frac{\color{blue}{x - y}}{\sqrt{y} \cdot \sqrt{y}} \]
      6. add-sqr-sqrt64.6%

        \[\leadsto \frac{x - y}{\color{blue}{y}} \]
      7. div-sub64.6%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      8. pow164.6%

        \[\leadsto \frac{x}{y} - \frac{\color{blue}{{y}^{1}}}{y} \]
      9. pow164.6%

        \[\leadsto \frac{x}{y} - \frac{{y}^{1}}{\color{blue}{{y}^{1}}} \]
      10. pow-div64.6%

        \[\leadsto \frac{x}{y} - \color{blue}{{y}^{\left(1 - 1\right)}} \]
      11. metadata-eval64.6%

        \[\leadsto \frac{x}{y} - {y}^{\color{blue}{0}} \]
      12. metadata-eval64.6%

        \[\leadsto \frac{x}{y} - \color{blue}{1} \]
    4. Applied egg-rr64.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{+144}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{+136}:\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 58.2% accurate, 15.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+69} \lor \neg \left(x \leq 9.6 \cdot 10^{+135}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.8e+69) (not (<= x 9.6e+135))) (/ x y) 1.0))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.8e+69) || !(x <= 9.6e+135)) {
		tmp = x / y;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.8d+69)) .or. (.not. (x <= 9.6d+135))) then
        tmp = x / y
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.8e+69) || !(x <= 9.6e+135)) {
		tmp = x / y;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.8e+69) or not (x <= 9.6e+135):
		tmp = x / y
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.8e+69) || !(x <= 9.6e+135))
		tmp = Float64(x / y);
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.8e+69) || ~((x <= 9.6e+135)))
		tmp = x / y;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.8e+69], N[Not[LessEqual[x, 9.6e+135]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+69} \lor \neg \left(x \leq 9.6 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8000000000000001e69 or 9.59999999999999989e135 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt48.4%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt48.9%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt22.5%

        \[\leadsto \frac{1}{\frac{y}{\left|\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}\right|}} \]
      6. fabs-sqr22.5%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt57.7%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/57.7%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Applied egg-rr57.7%

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

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if -1.8000000000000001e69 < x < 9.59999999999999989e135

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
      2. add-sqr-sqrt46.1%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
      4. add-sqr-sqrt47.2%

        \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
      5. add-sqr-sqrt9.1%

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

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
      7. add-sqr-sqrt14.8%

        \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
      8. associate-/r/14.8%

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    5. Step-by-step derivation
      1. associate-*l/14.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
      2. *-un-lft-identity14.9%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
      3. sub-neg14.9%

        \[\leadsto \frac{\color{blue}{x + \left(-y\right)}}{y} \]
      4. add-sqr-sqrt5.8%

        \[\leadsto \frac{x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y} \]
      5. sqrt-unprod28.6%

        \[\leadsto \frac{x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y} \]
      6. sqr-neg28.6%

        \[\leadsto \frac{x + \sqrt{\color{blue}{y \cdot y}}}{y} \]
      7. sqrt-unprod36.9%

        \[\leadsto \frac{x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y} \]
      8. add-sqr-sqrt77.7%

        \[\leadsto \frac{x + \color{blue}{y}}{y} \]
    6. Applied egg-rr77.7%

      \[\leadsto \color{blue}{\frac{x + y}{y}} \]
    7. Taylor expanded in x around 0 66.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+69} \lor \neg \left(x \leq 9.6 \cdot 10^{+135}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 1.3% accurate, 205.0× speedup?

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

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

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. clear-num99.8%

      \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
    2. add-sqr-sqrt46.8%

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
    4. add-sqr-sqrt47.7%

      \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
    5. add-sqr-sqrt13.3%

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

      \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
    7. add-sqr-sqrt28.2%

      \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
    8. associate-/r/28.2%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
  4. Applied egg-rr28.2%

    \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
  5. Taylor expanded in y around inf 1.3%

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification1.3%

    \[\leadsto -1 \]
  7. Add Preprocessing

Alternative 8: 51.5% accurate, 205.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. clear-num99.8%

      \[\leadsto \color{blue}{\frac{1}{\frac{\left|y\right|}{\left|x - y\right|}}} \]
    2. add-sqr-sqrt46.8%

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\left|x - y\right|}} \]
    4. add-sqr-sqrt47.7%

      \[\leadsto \frac{1}{\frac{\color{blue}{y}}{\left|x - y\right|}} \]
    5. add-sqr-sqrt13.3%

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

      \[\leadsto \frac{1}{\frac{y}{\color{blue}{\sqrt{x - y} \cdot \sqrt{x - y}}}} \]
    7. add-sqr-sqrt28.2%

      \[\leadsto \frac{1}{\frac{y}{\color{blue}{x - y}}} \]
    8. associate-/r/28.2%

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
  4. Applied egg-rr28.2%

    \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
  5. Step-by-step derivation
    1. associate-*l/28.3%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(x - y\right)}{y}} \]
    2. *-un-lft-identity28.3%

      \[\leadsto \frac{\color{blue}{x - y}}{y} \]
    3. sub-neg28.3%

      \[\leadsto \frac{\color{blue}{x + \left(-y\right)}}{y} \]
    4. add-sqr-sqrt15.0%

      \[\leadsto \frac{x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y} \]
    5. sqrt-unprod36.6%

      \[\leadsto \frac{x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y} \]
    6. sqr-neg36.6%

      \[\leadsto \frac{x + \sqrt{\color{blue}{y \cdot y}}}{y} \]
    7. sqrt-unprod34.3%

      \[\leadsto \frac{x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y} \]
    8. add-sqr-sqrt75.9%

      \[\leadsto \frac{x + \color{blue}{y}}{y} \]
  6. Applied egg-rr75.9%

    \[\leadsto \color{blue}{\frac{x + y}{y}} \]
  7. Taylor expanded in x around 0 51.4%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification51.4%

    \[\leadsto 1 \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2024019 
(FPCore (x y)
  :name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
  :precision binary64
  (/ (fabs (- x y)) (fabs y)))