Linear.Projection:perspective from linear-1.19.1.3, A

Percentage Accurate: 100.0% → 100.0%
Time: 38.7s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\frac{x + y}{x - y} \]
(FPCore (x y)
  :precision binary64
  (/ (+ x y) (- x y)))
double code(double x, double y) {
	return (x + y) / (x - y);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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]
\frac{x + y}{x - y}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 6 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

\[\frac{x + y}{x - y} \]
(FPCore (x y)
  :precision binary64
  (/ (+ x y) (- x y)))
double code(double x, double y) {
	return (x + y) / (x - y);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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]
\frac{x + y}{x - y}

Alternative 1: 100.0% accurate, 0.6× speedup?

\[\frac{y}{x - y} - \frac{x}{y - x} \]
(FPCore (x y)
  :precision binary64
  (- (/ y (- x y)) (/ x (- y x))))
double code(double x, double y) {
	return (y / (x - y)) - (x / (y - x));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x + y\right)\right)}{\mathsf{neg}\left(\left(x - y\right)\right)}} \]
    3. lift-+.f64N/A

      \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x + y\right)}\right)}{\mathsf{neg}\left(\left(x - y\right)\right)} \]
    4. add-flipN/A

      \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(x - \left(\mathsf{neg}\left(y\right)\right)\right)}\right)}{\mathsf{neg}\left(\left(x - y\right)\right)} \]
    5. sub-negateN/A

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

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

      \[\leadsto \color{blue}{\frac{y}{x - y}} - \frac{x}{\mathsf{neg}\left(\left(x - y\right)\right)} \]
    8. lower--.f64N/A

      \[\leadsto \color{blue}{\frac{y}{x - y} - \frac{x}{\mathsf{neg}\left(\left(x - y\right)\right)}} \]
    9. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{y}{x - y}} - \frac{x}{\mathsf{neg}\left(\left(x - y\right)\right)} \]
    10. lower-/.f64N/A

      \[\leadsto \frac{y}{x - y} - \color{blue}{\frac{x}{\mathsf{neg}\left(\left(x - y\right)\right)}} \]
    11. lift--.f64N/A

      \[\leadsto \frac{y}{x - y} - \frac{x}{\mathsf{neg}\left(\color{blue}{\left(x - y\right)}\right)} \]
    12. sub-negate-revN/A

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

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

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

Alternative 2: 98.5% accurate, 0.4× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\ \;\;\;\;\frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y + y\right) + x}{x}\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (if (<= (/ (+ x y) (- x y)) -1/2) (/ y (- x y)) (/ (+ (+ y y) x) x)))
double code(double x, double y) {
	double tmp;
	if (((x + y) / (x - y)) <= -0.5) {
		tmp = y / (x - y);
	} else {
		tmp = ((y + y) + x) / x;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (((x + y) / (x - y)) <= (-0.5d0)) then
        tmp = y / (x - y)
    else
        tmp = ((y + y) + x) / x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (((x + y) / (x - y)) <= -0.5) {
		tmp = y / (x - y);
	} else {
		tmp = ((y + y) + x) / x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if ((x + y) / (x - y)) <= -0.5:
		tmp = y / (x - y)
	else:
		tmp = ((y + y) + x) / x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(x + y) / Float64(x - y)) <= -0.5)
		tmp = Float64(y / Float64(x - y));
	else
		tmp = Float64(Float64(Float64(y + y) + x) / x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (((x + y) / (x - y)) <= -0.5)
		tmp = y / (x - y);
	else
		tmp = ((y + y) + x) / x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision], -1/2], N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y + y), $MachinePrecision] + x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\
\;\;\;\;\frac{y}{x - y}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(y + y\right) + x}{x}\\


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{y}}{x - y} \]
    3. Step-by-step derivation
      1. Applied rewrites50.9%

        \[\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. Taylor expanded in y around 0

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

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

          \[\leadsto 1 + 2 \cdot \color{blue}{\frac{y}{x}} \]
        3. lower-/.f6451.0%

          \[\leadsto 1 + 2 \cdot \frac{y}{\color{blue}{x}} \]
      4. Applied rewrites51.0%

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

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

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

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

          \[\leadsto 1 + \frac{2 \cdot y}{\color{blue}{x}} \]
        5. add-to-fractionN/A

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

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

          \[\leadsto \frac{x + 2 \cdot y}{x} \]
        8. +-commutativeN/A

          \[\leadsto \frac{2 \cdot y + x}{x} \]
        9. lower-+.f64N/A

          \[\leadsto \frac{2 \cdot y + x}{x} \]
        10. count-2-revN/A

          \[\leadsto \frac{\left(y + y\right) + x}{x} \]
        11. lower-+.f6451.0%

          \[\leadsto \frac{\left(y + y\right) + x}{x} \]
      6. Applied rewrites51.0%

        \[\leadsto \frac{\left(y + y\right) + x}{\color{blue}{x}} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 3: 98.0% accurate, 0.5× speedup?

    \[\begin{array}{l} \mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\ \;\;\;\;\frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      (if (<= (/ (+ x y) (- x y)) -1/2) (/ y (- x y)) 1))
    double code(double x, double y) {
    	double tmp;
    	if (((x + y) / (x - y)) <= -0.5) {
    		tmp = y / (x - y);
    	} else {
    		tmp = 1.0;
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: tmp
        if (((x + y) / (x - y)) <= (-0.5d0)) then
            tmp = y / (x - y)
        else
            tmp = 1.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if (((x + y) / (x - y)) <= -0.5) {
    		tmp = y / (x - y);
    	} else {
    		tmp = 1.0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if ((x + y) / (x - y)) <= -0.5:
    		tmp = y / (x - y)
    	else:
    		tmp = 1.0
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(x + y) / Float64(x - y)) <= -0.5)
    		tmp = Float64(y / Float64(x - y));
    	else
    		tmp = 1.0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (((x + y) / (x - y)) <= -0.5)
    		tmp = y / (x - y);
    	else
    		tmp = 1.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision], -1/2], N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision], 1]
    
    \begin{array}{l}
    \mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\
    \;\;\;\;\frac{y}{x - y}\\
    
    \mathbf{else}:\\
    \;\;\;\;1\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (+.f64 x y) (-.f64 x y)) < -0.5

      1. Initial program 100.0%

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

        \[\leadsto \frac{\color{blue}{y}}{x - y} \]
      3. Step-by-step derivation
        1. Applied rewrites50.9%

          \[\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. Taylor expanded in x around inf

          \[\leadsto \color{blue}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites49.8%

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

        Alternative 4: 98.0% accurate, 0.7× speedup?

        \[\begin{array}{l} \mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
        (FPCore (x y)
          :precision binary64
          (if (<= (/ (+ x y) (- x y)) -1/2) -1 1))
        double code(double x, double y) {
        	double tmp;
        	if (((x + y) / (x - y)) <= -0.5) {
        		tmp = -1.0;
        	} else {
        		tmp = 1.0;
        	}
        	return tmp;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(x, y)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8) :: tmp
            if (((x + y) / (x - y)) <= (-0.5d0)) 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) / (x - y)) <= -0.5) {
        		tmp = -1.0;
        	} else {
        		tmp = 1.0;
        	}
        	return tmp;
        }
        
        def code(x, y):
        	tmp = 0
        	if ((x + y) / (x - y)) <= -0.5:
        		tmp = -1.0
        	else:
        		tmp = 1.0
        	return tmp
        
        function code(x, y)
        	tmp = 0.0
        	if (Float64(Float64(x + y) / Float64(x - y)) <= -0.5)
        		tmp = -1.0;
        	else
        		tmp = 1.0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y)
        	tmp = 0.0;
        	if (((x + y) / (x - y)) <= -0.5)
        		tmp = -1.0;
        	else
        		tmp = 1.0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision], -1/2], -1, 1]
        
        \begin{array}{l}
        \mathbf{if}\;\frac{x + y}{x - y} \leq \frac{-1}{2}:\\
        \;\;\;\;-1\\
        
        \mathbf{else}:\\
        \;\;\;\;1\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (/.f64 (+.f64 x y) (-.f64 x y)) < -0.5

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{-1} \]
          3. Step-by-step derivation
            1. Applied rewrites49.8%

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

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

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites49.8%

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

            Alternative 5: 49.8% accurate, 18.0× speedup?

            \[-1 \]
            (FPCore (x y)
              :precision binary64
              -1)
            double code(double x, double y) {
            	return -1.0;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(x, y)
            use fmin_fmax_functions
                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
            
            -1
            
            Derivation
            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{-1} \]
            3. Step-by-step derivation
              1. Applied rewrites49.8%

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

              Reproduce

              ?
              herbie shell --seed 2025271 -o generate:evaluate
              (FPCore (x y)
                :name "Linear.Projection:perspective from linear-1.19.1.3, A"
                :precision binary64
                (/ (+ x y) (- x y)))