Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 6.4s
Alternatives: 5
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 5 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|1 - \frac{x}{y}\right| \end{array} \]
(FPCore (x y) :precision binary64 (fabs (- 1.0 (/ x y))))
double code(double x, double y) {
	return fabs((1.0 - (x / y)));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = abs((1.0d0 - (x / y)))
end function
public static double code(double x, double y) {
	return Math.abs((1.0 - (x / y)));
}
def code(x, y):
	return math.fabs((1.0 - (x / y)))
function code(x, y)
	return abs(Float64(1.0 - Float64(x / y)))
end
function tmp = code(x, y)
	tmp = abs((1.0 - (x / y)));
end
code[x_, y_] := N[Abs[N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\left|1 - \frac{x}{y}\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. neg-fabsN/A

      \[\leadsto \frac{\left|\mathsf{neg}\left(\left(x - y\right)\right)\right|}{\left|\color{blue}{y}\right|} \]
    2. div-fabsN/A

      \[\leadsto \left|\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right| \]
    3. fabs-lowering-fabs.f64N/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x + \left(\mathsf{neg}\left(y\right)\right)\right)\right)}{y}\right)\right) \]
    5. +-commutativeN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(y\right)\right) + x\right)\right)}{y}\right)\right) \]
    6. distribute-neg-inN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
    7. remove-double-negN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
    8. sub-negN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y - x}{y}\right)\right) \]
    9. div-subN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y}{y} - \frac{x}{y}\right)\right) \]
    10. *-inversesN/A

      \[\leadsto \mathsf{fabs.f64}\left(\left(1 - \frac{x}{y}\right)\right) \]
    11. --lowering--.f64N/A

      \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \left(\frac{x}{y}\right)\right)\right) \]
    12. /-lowering-/.f64100.0%

      \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(x, y\right)\right)\right) \]
  4. Applied egg-rr100.0%

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

Alternative 2: 58.9% accurate, 12.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+77}:\\ \;\;\;\;0 - \frac{x}{y}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+59}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{-1}{\frac{x}{y}}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.5e+77)
   (- 0.0 (/ x y))
   (if (<= x 2.1e+59) 1.0 (/ 1.0 (/ -1.0 (/ x y))))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.5e+77) {
		tmp = 0.0 - (x / y);
	} else if (x <= 2.1e+59) {
		tmp = 1.0;
	} else {
		tmp = 1.0 / (-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+77)) then
        tmp = 0.0d0 - (x / y)
    else if (x <= 2.1d+59) then
        tmp = 1.0d0
    else
        tmp = 1.0d0 / ((-1.0d0) / (x / y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.5e+77) {
		tmp = 0.0 - (x / y);
	} else if (x <= 2.1e+59) {
		tmp = 1.0;
	} else {
		tmp = 1.0 / (-1.0 / (x / y));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.5e+77:
		tmp = 0.0 - (x / y)
	elif x <= 2.1e+59:
		tmp = 1.0
	else:
		tmp = 1.0 / (-1.0 / (x / y))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.5e+77)
		tmp = Float64(0.0 - Float64(x / y));
	elseif (x <= 2.1e+59)
		tmp = 1.0;
	else
		tmp = Float64(1.0 / Float64(-1.0 / Float64(x / y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.5e+77)
		tmp = 0.0 - (x / y);
	elseif (x <= 2.1e+59)
		tmp = 1.0;
	else
		tmp = 1.0 / (-1.0 / (x / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.5e+77], N[(0.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e+59], 1.0, N[(1.0 / N[(-1.0 / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+77}:\\
\;\;\;\;0 - \frac{x}{y}\\

\mathbf{elif}\;x \leq 2.1 \cdot 10^{+59}:\\
\;\;\;\;1\\

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


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

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-fabsN/A

        \[\leadsto \left|\frac{x - y}{y}\right| \]
      2. div-invN/A

        \[\leadsto \left|\left(x - y\right) \cdot \frac{1}{y}\right| \]
      3. flip--N/A

        \[\leadsto \left|\frac{x \cdot x - y \cdot y}{x + y} \cdot \frac{1}{y}\right| \]
      4. clear-numN/A

        \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y}} \cdot \frac{1}{y}\right| \]
      5. frac-timesN/A

        \[\leadsto \left|\frac{1 \cdot 1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
      6. metadata-evalN/A

        \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
      7. fabs-divN/A

        \[\leadsto \frac{\left|1\right|}{\color{blue}{\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|}} \]
      8. metadata-evalN/A

        \[\leadsto \frac{1}{\left|\color{blue}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right|} \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|\right)}\right) \]
      10. fabs-lowering-fabs.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y}\right), y\right)\right)\right) \]
      12. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\frac{x \cdot x - y \cdot y}{x + y}}\right), y\right)\right)\right) \]
      13. flip--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{x - y}\right), y\right)\right)\right) \]
      14. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(x - y\right)\right), y\right)\right)\right) \]
      15. --lowering--.f6499.6%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(x, y\right)\right), y\right)\right)\right) \]
    4. Applied egg-rr99.6%

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\color{blue}{\left(\frac{1}{x}\right)}, y\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f6490.0%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, x\right), y\right)\right)\right) \]
    7. Simplified90.0%

      \[\leadsto \frac{1}{\left|\color{blue}{\frac{1}{x}} \cdot y\right|} \]
    8. Step-by-step derivation
      1. inv-powN/A

        \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{-1}} \]
      2. sqr-powN/A

        \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}} \]
      3. pow-prod-downN/A

        \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}} \]
      4. remove-double-negN/A

        \[\leadsto {\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right) \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \]
      5. remove-double-negN/A

        \[\leadsto {\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \]
      6. sqr-negN/A

        \[\leadsto {\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      7. pow-prod-downN/A

        \[\leadsto {\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      8. sqr-powN/A

        \[\leadsto {\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\color{blue}{-1}} \]
      9. inv-powN/A

        \[\leadsto \frac{1}{\color{blue}{\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)}} \]
      10. distribute-frac-neg2N/A

        \[\leadsto \mathsf{neg}\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right) \]
      11. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right)\right) \]
      12. inv-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{-1}\right)\right) \]
      13. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
      14. pow-prod-downN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
      15. sqr-absN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left(\frac{1}{x} \cdot y\right) \cdot \left(\frac{1}{x} \cdot y\right)\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
      16. pow2N/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left({\left(\frac{1}{x} \cdot y\right)}^{2}\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
      17. pow-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{\left(2 \cdot \frac{-1}{2}\right)}\right)\right) \]
      18. metadata-evalN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{\left(2 \cdot \frac{-1}{2}\right)}\right)\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{-1}\right)\right) \]
      20. inv-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{1}{\frac{1}{x} \cdot y}\right)\right) \]
    9. Applied egg-rr56.9%

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

    if -1.4999999999999999e77 < x < 2.09999999999999984e59

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. neg-fabsN/A

        \[\leadsto \frac{\left|\mathsf{neg}\left(\left(x - y\right)\right)\right|}{\left|\color{blue}{y}\right|} \]
      2. div-fabsN/A

        \[\leadsto \left|\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right| \]
      3. fabs-lowering-fabs.f64N/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right)\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x + \left(\mathsf{neg}\left(y\right)\right)\right)\right)}{y}\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(y\right)\right) + x\right)\right)}{y}\right)\right) \]
      6. distribute-neg-inN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
      7. remove-double-negN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
      8. sub-negN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y - x}{y}\right)\right) \]
      9. div-subN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y}{y} - \frac{x}{y}\right)\right) \]
      10. *-inversesN/A

        \[\leadsto \mathsf{fabs.f64}\left(\left(1 - \frac{x}{y}\right)\right) \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \left(\frac{x}{y}\right)\right)\right) \]
      12. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(x, y\right)\right)\right) \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fabs.f64}\left(\color{blue}{1}\right) \]
    6. Step-by-step derivation
      1. Simplified73.4%

        \[\leadsto \left|\color{blue}{1}\right| \]
      2. Step-by-step derivation
        1. metadata-eval73.4%

          \[\leadsto 1 \]
      3. Applied egg-rr73.4%

        \[\leadsto \color{blue}{1} \]

      if 2.09999999999999984e59 < x

      1. Initial program 100.0%

        \[\frac{\left|x - y\right|}{\left|y\right|} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. div-fabsN/A

          \[\leadsto \left|\frac{x - y}{y}\right| \]
        2. div-invN/A

          \[\leadsto \left|\left(x - y\right) \cdot \frac{1}{y}\right| \]
        3. flip--N/A

          \[\leadsto \left|\frac{x \cdot x - y \cdot y}{x + y} \cdot \frac{1}{y}\right| \]
        4. clear-numN/A

          \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y}} \cdot \frac{1}{y}\right| \]
        5. frac-timesN/A

          \[\leadsto \left|\frac{1 \cdot 1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
        6. metadata-evalN/A

          \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
        7. fabs-divN/A

          \[\leadsto \frac{\left|1\right|}{\color{blue}{\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|}} \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{\left|\color{blue}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right|} \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|\right)}\right) \]
        10. fabs-lowering-fabs.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right)\right)\right) \]
        11. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y}\right), y\right)\right)\right) \]
        12. clear-numN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\frac{x \cdot x - y \cdot y}{x + y}}\right), y\right)\right)\right) \]
        13. flip--N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{x - y}\right), y\right)\right)\right) \]
        14. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(x - y\right)\right), y\right)\right)\right) \]
        15. --lowering--.f6499.7%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(x, y\right)\right), y\right)\right)\right) \]
      4. Applied egg-rr99.7%

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\color{blue}{\left(\frac{1}{x}\right)}, y\right)\right)\right) \]
      6. Step-by-step derivation
        1. /-lowering-/.f6488.5%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, x\right), y\right)\right)\right) \]
      7. Simplified88.5%

        \[\leadsto \frac{1}{\left|\color{blue}{\frac{1}{x}} \cdot y\right|} \]
      8. Step-by-step derivation
        1. remove-double-divN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{\color{blue}{\frac{1}{\left|\frac{1}{x} \cdot y\right|}}}\right)\right) \]
        2. frac-2negN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right)}}\right)\right) \]
        3. metadata-evalN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{1}{\left|\frac{1}{x} \cdot y\right|}}\right)}\right)\right) \]
        4. distribute-frac-neg2N/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{\frac{1}{\color{blue}{\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)}}}\right)\right) \]
        5. inv-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\color{blue}{-1}}}\right)\right) \]
        6. sqr-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)}}}\right)\right) \]
        7. pow-prod-downN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}}}\right)\right) \]
        8. sqr-negN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}}\right)\right) \]
        9. remove-double-negN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left|\frac{1}{x} \cdot y\right| \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)}}\right)\right) \]
        10. remove-double-negN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}}\right)\right) \]
        11. pow-prod-downN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}}}\right)\right) \]
        12. sqr-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{-1}}}\right)\right) \]
        13. inv-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{\frac{1}{\color{blue}{\left|\frac{1}{x} \cdot y\right|}}}\right)\right) \]
        14. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(-1, \color{blue}{\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right)}\right)\right) \]
        15. inv-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(-1, \left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{-1}}\right)\right)\right) \]
        16. sqr-powN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(-1, \left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}}\right)\right)\right) \]
        17. pow-prod-downN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(-1, \left({\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)\right)\right) \]
      9. Applied egg-rr48.3%

        \[\leadsto \frac{1}{\color{blue}{\frac{-1}{\frac{x}{y}}}} \]
    7. Recombined 3 regimes into one program.
    8. Final simplification65.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+77}:\\ \;\;\;\;0 - \frac{x}{y}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+59}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{-1}{\frac{x}{y}}}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 59.0% accurate, 13.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0 - \frac{x}{y}\\ \mathbf{if}\;x \leq -7.5 \cdot 10^{+78}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+62}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (let* ((t_0 (- 0.0 (/ x y))))
       (if (<= x -7.5e+78) t_0 (if (<= x 4e+62) 1.0 t_0))))
    double code(double x, double y) {
    	double t_0 = 0.0 - (x / y);
    	double tmp;
    	if (x <= -7.5e+78) {
    		tmp = t_0;
    	} else if (x <= 4e+62) {
    		tmp = 1.0;
    	} else {
    		tmp = t_0;
    	}
    	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 = 0.0d0 - (x / y)
        if (x <= (-7.5d+78)) then
            tmp = t_0
        else if (x <= 4d+62) then
            tmp = 1.0d0
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double t_0 = 0.0 - (x / y);
    	double tmp;
    	if (x <= -7.5e+78) {
    		tmp = t_0;
    	} else if (x <= 4e+62) {
    		tmp = 1.0;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = 0.0 - (x / y)
    	tmp = 0
    	if x <= -7.5e+78:
    		tmp = t_0
    	elif x <= 4e+62:
    		tmp = 1.0
    	else:
    		tmp = t_0
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(0.0 - Float64(x / y))
    	tmp = 0.0
    	if (x <= -7.5e+78)
    		tmp = t_0;
    	elseif (x <= 4e+62)
    		tmp = 1.0;
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = 0.0 - (x / y);
    	tmp = 0.0;
    	if (x <= -7.5e+78)
    		tmp = t_0;
    	elseif (x <= 4e+62)
    		tmp = 1.0;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(0.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.5e+78], t$95$0, If[LessEqual[x, 4e+62], 1.0, t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := 0 - \frac{x}{y}\\
    \mathbf{if}\;x \leq -7.5 \cdot 10^{+78}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;x \leq 4 \cdot 10^{+62}:\\
    \;\;\;\;1\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -7.49999999999999934e78 or 4.00000000000000014e62 < x

      1. Initial program 100.0%

        \[\frac{\left|x - y\right|}{\left|y\right|} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. div-fabsN/A

          \[\leadsto \left|\frac{x - y}{y}\right| \]
        2. div-invN/A

          \[\leadsto \left|\left(x - y\right) \cdot \frac{1}{y}\right| \]
        3. flip--N/A

          \[\leadsto \left|\frac{x \cdot x - y \cdot y}{x + y} \cdot \frac{1}{y}\right| \]
        4. clear-numN/A

          \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y}} \cdot \frac{1}{y}\right| \]
        5. frac-timesN/A

          \[\leadsto \left|\frac{1 \cdot 1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
        6. metadata-evalN/A

          \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
        7. fabs-divN/A

          \[\leadsto \frac{\left|1\right|}{\color{blue}{\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|}} \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{\left|\color{blue}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right|} \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|\right)}\right) \]
        10. fabs-lowering-fabs.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right)\right)\right) \]
        11. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y}\right), y\right)\right)\right) \]
        12. clear-numN/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\frac{x \cdot x - y \cdot y}{x + y}}\right), y\right)\right)\right) \]
        13. flip--N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{x - y}\right), y\right)\right)\right) \]
        14. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(x - y\right)\right), y\right)\right)\right) \]
        15. --lowering--.f6499.7%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(x, y\right)\right), y\right)\right)\right) \]
      4. Applied egg-rr99.7%

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\color{blue}{\left(\frac{1}{x}\right)}, y\right)\right)\right) \]
      6. Step-by-step derivation
        1. /-lowering-/.f6489.1%

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, x\right), y\right)\right)\right) \]
      7. Simplified89.1%

        \[\leadsto \frac{1}{\left|\color{blue}{\frac{1}{x}} \cdot y\right|} \]
      8. Step-by-step derivation
        1. inv-powN/A

          \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{-1}} \]
        2. sqr-powN/A

          \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}} \]
        3. pow-prod-downN/A

          \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}} \]
        4. remove-double-negN/A

          \[\leadsto {\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right) \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \]
        5. remove-double-negN/A

          \[\leadsto {\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \]
        6. sqr-negN/A

          \[\leadsto {\left(\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
        7. pow-prod-downN/A

          \[\leadsto {\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
        8. sqr-powN/A

          \[\leadsto {\left(\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)\right)}^{\color{blue}{-1}} \]
        9. inv-powN/A

          \[\leadsto \frac{1}{\color{blue}{\mathsf{neg}\left(\left|\frac{1}{x} \cdot y\right|\right)}} \]
        10. distribute-frac-neg2N/A

          \[\leadsto \mathsf{neg}\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right) \]
        11. neg-lowering-neg.f64N/A

          \[\leadsto \mathsf{neg.f64}\left(\left(\frac{1}{\left|\frac{1}{x} \cdot y\right|}\right)\right) \]
        12. inv-powN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{-1}\right)\right) \]
        13. sqr-powN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
        14. pow-prod-downN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
        15. sqr-absN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\left(\frac{1}{x} \cdot y\right) \cdot \left(\frac{1}{x} \cdot y\right)\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
        16. pow2N/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left({\left(\frac{1}{x} \cdot y\right)}^{2}\right)}^{\left(\frac{-1}{2}\right)}\right)\right) \]
        17. pow-powN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{\left(2 \cdot \frac{-1}{2}\right)}\right)\right) \]
        18. metadata-evalN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{\left(2 \cdot \frac{-1}{2}\right)}\right)\right) \]
        19. metadata-evalN/A

          \[\leadsto \mathsf{neg.f64}\left(\left({\left(\frac{1}{x} \cdot y\right)}^{-1}\right)\right) \]
        20. inv-powN/A

          \[\leadsto \mathsf{neg.f64}\left(\left(\frac{1}{\frac{1}{x} \cdot y}\right)\right) \]
      9. Applied egg-rr52.0%

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

      if -7.49999999999999934e78 < x < 4.00000000000000014e62

      1. Initial program 100.0%

        \[\frac{\left|x - y\right|}{\left|y\right|} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. neg-fabsN/A

          \[\leadsto \frac{\left|\mathsf{neg}\left(\left(x - y\right)\right)\right|}{\left|\color{blue}{y}\right|} \]
        2. div-fabsN/A

          \[\leadsto \left|\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right| \]
        3. fabs-lowering-fabs.f64N/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right)\right) \]
        4. sub-negN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x + \left(\mathsf{neg}\left(y\right)\right)\right)\right)}{y}\right)\right) \]
        5. +-commutativeN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(y\right)\right) + x\right)\right)}{y}\right)\right) \]
        6. distribute-neg-inN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
        7. remove-double-negN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
        8. sub-negN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y - x}{y}\right)\right) \]
        9. div-subN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y}{y} - \frac{x}{y}\right)\right) \]
        10. *-inversesN/A

          \[\leadsto \mathsf{fabs.f64}\left(\left(1 - \frac{x}{y}\right)\right) \]
        11. --lowering--.f64N/A

          \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \left(\frac{x}{y}\right)\right)\right) \]
        12. /-lowering-/.f64100.0%

          \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(x, y\right)\right)\right) \]
      4. Applied egg-rr100.0%

        \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
      5. Taylor expanded in x around 0

        \[\leadsto \mathsf{fabs.f64}\left(\color{blue}{1}\right) \]
      6. Step-by-step derivation
        1. Simplified73.4%

          \[\leadsto \left|\color{blue}{1}\right| \]
        2. Step-by-step derivation
          1. metadata-eval73.4%

            \[\leadsto 1 \]
        3. Applied egg-rr73.4%

          \[\leadsto \color{blue}{1} \]
      7. Recombined 2 regimes into one program.
      8. Final simplification65.8%

        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{+78}:\\ \;\;\;\;0 - \frac{x}{y}\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+62}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0 - \frac{x}{y}\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 59.2% accurate, 15.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{+131}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+106}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
      (FPCore (x y)
       :precision binary64
       (if (<= x -7.5e+131) (/ x y) (if (<= x 4.1e+106) 1.0 (/ x y))))
      double code(double x, double y) {
      	double tmp;
      	if (x <= -7.5e+131) {
      		tmp = x / y;
      	} else if (x <= 4.1e+106) {
      		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) :: tmp
          if (x <= (-7.5d+131)) then
              tmp = x / y
          else if (x <= 4.1d+106) then
              tmp = 1.0d0
          else
              tmp = x / y
          end if
          code = tmp
      end function
      
      public static double code(double x, double y) {
      	double tmp;
      	if (x <= -7.5e+131) {
      		tmp = x / y;
      	} else if (x <= 4.1e+106) {
      		tmp = 1.0;
      	} else {
      		tmp = x / y;
      	}
      	return tmp;
      }
      
      def code(x, y):
      	tmp = 0
      	if x <= -7.5e+131:
      		tmp = x / y
      	elif x <= 4.1e+106:
      		tmp = 1.0
      	else:
      		tmp = x / y
      	return tmp
      
      function code(x, y)
      	tmp = 0.0
      	if (x <= -7.5e+131)
      		tmp = Float64(x / y);
      	elseif (x <= 4.1e+106)
      		tmp = 1.0;
      	else
      		tmp = Float64(x / y);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y)
      	tmp = 0.0;
      	if (x <= -7.5e+131)
      		tmp = x / y;
      	elseif (x <= 4.1e+106)
      		tmp = 1.0;
      	else
      		tmp = x / y;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_] := If[LessEqual[x, -7.5e+131], N[(x / y), $MachinePrecision], If[LessEqual[x, 4.1e+106], 1.0, N[(x / y), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -7.5 \cdot 10^{+131}:\\
      \;\;\;\;\frac{x}{y}\\
      
      \mathbf{elif}\;x \leq 4.1 \cdot 10^{+106}:\\
      \;\;\;\;1\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{x}{y}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -7.4999999999999995e131 or 4.1000000000000002e106 < x

        1. Initial program 100.0%

          \[\frac{\left|x - y\right|}{\left|y\right|} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. div-fabsN/A

            \[\leadsto \left|\frac{x - y}{y}\right| \]
          2. div-invN/A

            \[\leadsto \left|\left(x - y\right) \cdot \frac{1}{y}\right| \]
          3. flip--N/A

            \[\leadsto \left|\frac{x \cdot x - y \cdot y}{x + y} \cdot \frac{1}{y}\right| \]
          4. clear-numN/A

            \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y}} \cdot \frac{1}{y}\right| \]
          5. frac-timesN/A

            \[\leadsto \left|\frac{1 \cdot 1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
          6. metadata-evalN/A

            \[\leadsto \left|\frac{1}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right| \]
          7. fabs-divN/A

            \[\leadsto \frac{\left|1\right|}{\color{blue}{\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|}} \]
          8. metadata-evalN/A

            \[\leadsto \frac{1}{\left|\color{blue}{\frac{x + y}{x \cdot x - y \cdot y} \cdot y}\right|} \]
          9. /-lowering-/.f64N/A

            \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\left|\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right|\right)}\right) \]
          10. fabs-lowering-fabs.f64N/A

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y} \cdot y\right)\right)\right) \]
          11. *-lowering-*.f64N/A

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{x + y}{x \cdot x - y \cdot y}\right), y\right)\right)\right) \]
          12. clear-numN/A

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\frac{x \cdot x - y \cdot y}{x + y}}\right), y\right)\right)\right) \]
          13. flip--N/A

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{x - y}\right), y\right)\right)\right) \]
          14. /-lowering-/.f64N/A

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(x - y\right)\right), y\right)\right)\right) \]
          15. --lowering--.f6499.6%

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(x, y\right)\right), y\right)\right)\right) \]
        4. Applied egg-rr99.6%

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

          \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\color{blue}{\left(\frac{1}{x}\right)}, y\right)\right)\right) \]
        6. Step-by-step derivation
          1. /-lowering-/.f6492.9%

            \[\leadsto \mathsf{/.f64}\left(1, \mathsf{fabs.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, x\right), y\right)\right)\right) \]
        7. Simplified92.9%

          \[\leadsto \frac{1}{\left|\color{blue}{\frac{1}{x}} \cdot y\right|} \]
        8. Step-by-step derivation
          1. inv-powN/A

            \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{-1}} \]
          2. sqr-powN/A

            \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{x} \cdot y\right|\right)}^{\left(\frac{-1}{2}\right)}} \]
          3. pow-prod-downN/A

            \[\leadsto {\left(\left|\frac{1}{x} \cdot y\right| \cdot \left|\frac{1}{x} \cdot y\right|\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}} \]
          4. sqr-absN/A

            \[\leadsto {\left(\left(\frac{1}{x} \cdot y\right) \cdot \left(\frac{1}{x} \cdot y\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
          5. pow2N/A

            \[\leadsto {\left({\left(\frac{1}{x} \cdot y\right)}^{2}\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
          6. pow-powN/A

            \[\leadsto {\left(\frac{1}{x} \cdot y\right)}^{\color{blue}{\left(2 \cdot \frac{-1}{2}\right)}} \]
          7. metadata-evalN/A

            \[\leadsto {\left(\frac{1}{x} \cdot y\right)}^{\left(2 \cdot \frac{-1}{2}\right)} \]
          8. metadata-evalN/A

            \[\leadsto {\left(\frac{1}{x} \cdot y\right)}^{-1} \]
          9. inv-powN/A

            \[\leadsto \frac{1}{\color{blue}{\frac{1}{x} \cdot y}} \]
          10. *-commutativeN/A

            \[\leadsto \frac{1}{y \cdot \color{blue}{\frac{1}{x}}} \]
          11. un-div-invN/A

            \[\leadsto \frac{1}{\frac{y}{\color{blue}{x}}} \]
          12. clear-numN/A

            \[\leadsto \frac{x}{\color{blue}{y}} \]
          13. /-lowering-/.f6444.2%

            \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{y}\right) \]
        9. Applied egg-rr44.2%

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

        if -7.4999999999999995e131 < x < 4.1000000000000002e106

        1. Initial program 100.0%

          \[\frac{\left|x - y\right|}{\left|y\right|} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. neg-fabsN/A

            \[\leadsto \frac{\left|\mathsf{neg}\left(\left(x - y\right)\right)\right|}{\left|\color{blue}{y}\right|} \]
          2. div-fabsN/A

            \[\leadsto \left|\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right| \]
          3. fabs-lowering-fabs.f64N/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right)\right) \]
          4. sub-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x + \left(\mathsf{neg}\left(y\right)\right)\right)\right)}{y}\right)\right) \]
          5. +-commutativeN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(y\right)\right) + x\right)\right)}{y}\right)\right) \]
          6. distribute-neg-inN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
          7. remove-double-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
          8. sub-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y - x}{y}\right)\right) \]
          9. div-subN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y}{y} - \frac{x}{y}\right)\right) \]
          10. *-inversesN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(1 - \frac{x}{y}\right)\right) \]
          11. --lowering--.f64N/A

            \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \left(\frac{x}{y}\right)\right)\right) \]
          12. /-lowering-/.f64100.0%

            \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(x, y\right)\right)\right) \]
        4. Applied egg-rr100.0%

          \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
        5. Taylor expanded in x around 0

          \[\leadsto \mathsf{fabs.f64}\left(\color{blue}{1}\right) \]
        6. Step-by-step derivation
          1. Simplified68.5%

            \[\leadsto \left|\color{blue}{1}\right| \]
          2. Step-by-step derivation
            1. metadata-eval68.5%

              \[\leadsto 1 \]
          3. Applied egg-rr68.5%

            \[\leadsto \color{blue}{1} \]
        7. Recombined 2 regimes into one program.
        8. Add Preprocessing

        Alternative 5: 52.1% 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. neg-fabsN/A

            \[\leadsto \frac{\left|\mathsf{neg}\left(\left(x - y\right)\right)\right|}{\left|\color{blue}{y}\right|} \]
          2. div-fabsN/A

            \[\leadsto \left|\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right| \]
          3. fabs-lowering-fabs.f64N/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x - y\right)\right)}{y}\right)\right) \]
          4. sub-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(x + \left(\mathsf{neg}\left(y\right)\right)\right)\right)}{y}\right)\right) \]
          5. +-commutativeN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(y\right)\right) + x\right)\right)}{y}\right)\right) \]
          6. distribute-neg-inN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
          7. remove-double-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y + \left(\mathsf{neg}\left(x\right)\right)}{y}\right)\right) \]
          8. sub-negN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y - x}{y}\right)\right) \]
          9. div-subN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(\frac{y}{y} - \frac{x}{y}\right)\right) \]
          10. *-inversesN/A

            \[\leadsto \mathsf{fabs.f64}\left(\left(1 - \frac{x}{y}\right)\right) \]
          11. --lowering--.f64N/A

            \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \left(\frac{x}{y}\right)\right)\right) \]
          12. /-lowering-/.f64100.0%

            \[\leadsto \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{/.f64}\left(x, y\right)\right)\right) \]
        4. Applied egg-rr100.0%

          \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
        5. Taylor expanded in x around 0

          \[\leadsto \mathsf{fabs.f64}\left(\color{blue}{1}\right) \]
        6. Step-by-step derivation
          1. Simplified52.3%

            \[\leadsto \left|\color{blue}{1}\right| \]
          2. Step-by-step derivation
            1. metadata-eval52.3%

              \[\leadsto 1 \]
          3. Applied egg-rr52.3%

            \[\leadsto \color{blue}{1} \]
          4. Add Preprocessing

          Reproduce

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