Data.Colour.RGB:hslsv from colour-2.3.3, D

Percentage Accurate: 100.0% → 100.0%
Time: 5.6s
Alternatives: 7
Speedup: 1.0×

Specification

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

\\
\frac{x - y}{x + y}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

\\
\frac{x - y}{x + y}
\end{array}

Alternative 1: 100.0% accurate, 0.6× speedup?

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

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

    \[\frac{x - y}{x + y} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{x - y}{x + y}} \]
    2. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{x - y}}{x + y} \]
    3. div-subN/A

      \[\leadsto \color{blue}{\frac{x}{x + y} - \frac{y}{x + y}} \]
    4. lower--.f64N/A

      \[\leadsto \color{blue}{\frac{x}{x + y} - \frac{y}{x + y}} \]
    5. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{x}{x + y}} - \frac{y}{x + y} \]
    6. lift-+.f64N/A

      \[\leadsto \frac{x}{\color{blue}{x + y}} - \frac{y}{x + y} \]
    7. +-commutativeN/A

      \[\leadsto \frac{x}{\color{blue}{y + x}} - \frac{y}{x + y} \]
    8. lower-+.f64N/A

      \[\leadsto \frac{x}{\color{blue}{y + x}} - \frac{y}{x + y} \]
    9. lower-/.f64100.0

      \[\leadsto \frac{x}{y + x} - \color{blue}{\frac{y}{x + y}} \]
    10. lift-+.f64N/A

      \[\leadsto \frac{x}{y + x} - \frac{y}{\color{blue}{x + y}} \]
    11. +-commutativeN/A

      \[\leadsto \frac{x}{y + x} - \frac{y}{\color{blue}{y + x}} \]
    12. lower-+.f64100.0

      \[\leadsto \frac{x}{y + x} - \frac{y}{\color{blue}{y + x}} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{x}{y + x} - \frac{y}{y + x}} \]
  5. Add Preprocessing

Alternative 2: 98.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (/ (- x y) (+ y x)) -0.5)
   (fma (/ 2.0 y) x -1.0)
   (fma (/ y x) -2.0 1.0)))
double code(double x, double y) {
	double tmp;
	if (((x - y) / (y + x)) <= -0.5) {
		tmp = fma((2.0 / y), x, -1.0);
	} else {
		tmp = fma((y / x), -2.0, 1.0);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(x - y) / Float64(y + x)) <= -0.5)
		tmp = fma(Float64(2.0 / y), x, -1.0);
	else
		tmp = fma(Float64(y / x), -2.0, 1.0);
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision], -0.5], N[(N[(2.0 / y), $MachinePrecision] * x + -1.0), $MachinePrecision], N[(N[(y / x), $MachinePrecision] * -2.0 + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\
\;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 x y) (+.f64 x y)) < -0.5

    1. Initial program 99.9%

      \[\frac{x - y}{x + y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{\frac{x}{y} - \left(1 + -1 \cdot \frac{x}{y}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{x}{y} - \color{blue}{\left(-1 \cdot \frac{x}{y} + 1\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(\frac{x}{y} - -1 \cdot \frac{x}{y}\right) - 1} \]
      3. associate-*r/N/A

        \[\leadsto \left(\frac{x}{y} - \color{blue}{\frac{-1 \cdot x}{y}}\right) - 1 \]
      4. div-subN/A

        \[\leadsto \color{blue}{\frac{x - -1 \cdot x}{y}} - 1 \]
      5. cancel-sign-sub-invN/A

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

        \[\leadsto \frac{x + \color{blue}{1} \cdot x}{y} - 1 \]
      7. distribute-rgt1-inN/A

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

        \[\leadsto \frac{\color{blue}{2} \cdot x}{y} - 1 \]
      9. associate-*r/N/A

        \[\leadsto \color{blue}{2 \cdot \frac{x}{y}} - 1 \]
      10. sub-negN/A

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

        \[\leadsto 2 \cdot \frac{x}{y} + \color{blue}{-1} \]
      12. *-lft-identityN/A

        \[\leadsto 2 \cdot \frac{\color{blue}{1 \cdot x}}{y} + -1 \]
      13. associate-*l/N/A

        \[\leadsto 2 \cdot \color{blue}{\left(\frac{1}{y} \cdot x\right)} + -1 \]
      14. associate-*l*N/A

        \[\leadsto \color{blue}{\left(2 \cdot \frac{1}{y}\right) \cdot x} + -1 \]
      15. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \frac{1}{y}, x, -1\right)} \]
      16. associate-*r/N/A

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

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{2}}{y}, x, -1\right) \]
      18. lower-/.f6498.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{2}{y}}, x, -1\right) \]
    5. Applied rewrites98.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{2}{y}, x, -1\right)} \]

    if -0.5 < (/.f64 (-.f64 x y) (+.f64 x y))

    1. Initial program 100.0%

      \[\frac{x - y}{x + y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + -2 \cdot \frac{y}{x}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto \color{blue}{\frac{y}{x} \cdot -2} + 1 \]
      3. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)} \]
      4. lower-/.f6498.6

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{x}}, -2, 1\right) \]
    5. Applied rewrites98.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (/ (- x y) (+ y x)) -0.5) (fma (/ 2.0 y) x -1.0) 1.0))
double code(double x, double y) {
	double tmp;
	if (((x - y) / (y + x)) <= -0.5) {
		tmp = fma((2.0 / y), x, -1.0);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(x - y) / Float64(y + x)) <= -0.5)
		tmp = fma(Float64(2.0 / y), x, -1.0);
	else
		tmp = 1.0;
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision], -0.5], N[(N[(2.0 / y), $MachinePrecision] * x + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\
\;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 x y) (+.f64 x y)) < -0.5

    1. Initial program 99.9%

      \[\frac{x - y}{x + y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{\frac{x}{y} - \left(1 + -1 \cdot \frac{x}{y}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{x}{y} - \color{blue}{\left(-1 \cdot \frac{x}{y} + 1\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(\frac{x}{y} - -1 \cdot \frac{x}{y}\right) - 1} \]
      3. associate-*r/N/A

        \[\leadsto \left(\frac{x}{y} - \color{blue}{\frac{-1 \cdot x}{y}}\right) - 1 \]
      4. div-subN/A

        \[\leadsto \color{blue}{\frac{x - -1 \cdot x}{y}} - 1 \]
      5. cancel-sign-sub-invN/A

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

        \[\leadsto \frac{x + \color{blue}{1} \cdot x}{y} - 1 \]
      7. distribute-rgt1-inN/A

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

        \[\leadsto \frac{\color{blue}{2} \cdot x}{y} - 1 \]
      9. associate-*r/N/A

        \[\leadsto \color{blue}{2 \cdot \frac{x}{y}} - 1 \]
      10. sub-negN/A

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

        \[\leadsto 2 \cdot \frac{x}{y} + \color{blue}{-1} \]
      12. *-lft-identityN/A

        \[\leadsto 2 \cdot \frac{\color{blue}{1 \cdot x}}{y} + -1 \]
      13. associate-*l/N/A

        \[\leadsto 2 \cdot \color{blue}{\left(\frac{1}{y} \cdot x\right)} + -1 \]
      14. associate-*l*N/A

        \[\leadsto \color{blue}{\left(2 \cdot \frac{1}{y}\right) \cdot x} + -1 \]
      15. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \frac{1}{y}, x, -1\right)} \]
      16. associate-*r/N/A

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

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{2}}{y}, x, -1\right) \]
      18. lower-/.f6498.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{2}{y}}, x, -1\right) \]
    5. Applied rewrites98.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{2}{y}, x, -1\right)} \]

    if -0.5 < (/.f64 (-.f64 x y) (+.f64 x y))

    1. Initial program 100.0%

      \[\frac{x - y}{x + y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1} \]
    4. Step-by-step derivation
      1. Applied rewrites98.2%

        \[\leadsto \color{blue}{1} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification98.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\mathsf{fma}\left(\frac{2}{y}, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
    7. Add Preprocessing

    Alternative 4: 97.7% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\frac{-y}{y + x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (if (<= (/ (- x y) (+ y x)) -0.5) (/ (- y) (+ y x)) 1.0))
    double code(double x, double y) {
    	double tmp;
    	if (((x - y) / (y + x)) <= -0.5) {
    		tmp = -y / (y + x);
    	} 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 - y) / (y + x)) <= (-0.5d0)) then
            tmp = -y / (y + x)
        else
            tmp = 1.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if (((x - y) / (y + x)) <= -0.5) {
    		tmp = -y / (y + x);
    	} else {
    		tmp = 1.0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if ((x - y) / (y + x)) <= -0.5:
    		tmp = -y / (y + x)
    	else:
    		tmp = 1.0
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(x - y) / Float64(y + x)) <= -0.5)
    		tmp = Float64(Float64(-y) / Float64(y + x));
    	else
    		tmp = 1.0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (((x - y) / (y + x)) <= -0.5)
    		tmp = -y / (y + x);
    	else
    		tmp = 1.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision], -0.5], N[((-y) / N[(y + x), $MachinePrecision]), $MachinePrecision], 1.0]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\
    \;\;\;\;\frac{-y}{y + x}\\
    
    \mathbf{else}:\\
    \;\;\;\;1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (-.f64 x y) (+.f64 x y)) < -0.5

      1. Initial program 99.9%

        \[\frac{x - y}{x + y} \]
      2. Add Preprocessing
      3. Taylor expanded in y around inf

        \[\leadsto \frac{\color{blue}{-1 \cdot y}}{x + y} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(y\right)}}{x + y} \]
        2. lower-neg.f6497.1

          \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
      5. Applied rewrites97.1%

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

      if -0.5 < (/.f64 (-.f64 x y) (+.f64 x y))

      1. Initial program 100.0%

        \[\frac{x - y}{x + y} \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

        \[\leadsto \color{blue}{1} \]
      4. Step-by-step derivation
        1. Applied rewrites98.2%

          \[\leadsto \color{blue}{1} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification97.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -0.5:\\ \;\;\;\;\frac{-y}{y + x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
      7. Add Preprocessing

      Alternative 5: 97.7% accurate, 0.7× speedup?

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

        1. Initial program 99.9%

          \[\frac{x - y}{x + y} \]
        2. Add Preprocessing
        3. Taylor expanded in y around inf

          \[\leadsto \color{blue}{-1} \]
        4. Step-by-step derivation
          1. Applied rewrites97.0%

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

          if -1.000000000000002e-309 < (/.f64 (-.f64 x y) (+.f64 x y))

          1. Initial program 100.0%

            \[\frac{x - y}{x + y} \]
          2. Add Preprocessing
          3. Taylor expanded in y around 0

            \[\leadsto \color{blue}{1} \]
          4. Step-by-step derivation
            1. Applied rewrites98.2%

              \[\leadsto \color{blue}{1} \]
          5. Recombined 2 regimes into one program.
          6. Final simplification97.6%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{y + x} \leq -1 \cdot 10^{-309}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
          7. Add Preprocessing

          Alternative 6: 100.0% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \frac{x - y}{y + x} \end{array} \]
          (FPCore (x y) :precision binary64 (/ (- x y) (+ y x)))
          double code(double x, double y) {
          	return (x - y) / (y + x);
          }
          
          real(8) function code(x, y)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              code = (x - y) / (y + x)
          end function
          
          public static double code(double x, double y) {
          	return (x - y) / (y + x);
          }
          
          def code(x, y):
          	return (x - y) / (y + x)
          
          function code(x, y)
          	return Float64(Float64(x - y) / Float64(y + x))
          end
          
          function tmp = code(x, y)
          	tmp = (x - y) / (y + x);
          end
          
          code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{x - y}{y + x}
          \end{array}
          
          Derivation
          1. Initial program 100.0%

            \[\frac{x - y}{x + y} \]
          2. Add Preprocessing
          3. Final simplification100.0%

            \[\leadsto \frac{x - y}{y + x} \]
          4. Add Preprocessing

          Alternative 7: 49.1% accurate, 18.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{x - y}{x + y} \]
          2. Add Preprocessing
          3. Taylor expanded in y around inf

            \[\leadsto \color{blue}{-1} \]
          4. Step-by-step derivation
            1. Applied rewrites50.4%

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

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

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

            Reproduce

            ?
            herbie shell --seed 2024254 
            (FPCore (x y)
              :name "Data.Colour.RGB:hslsv from colour-2.3.3, D"
              :precision binary64
            
              :alt
              (! :herbie-platform default (- (/ x (+ x y)) (/ y (+ x y))))
            
              (/ (- x y) (+ x y)))