Linear.Projection:inversePerspective from linear-1.19.1.3, C

Percentage Accurate: 76.7% → 99.9%
Time: 7.2s
Alternatives: 6
Speedup: 1.4×

Specification

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

\\
\frac{x + y}{\left(x \cdot 2\right) \cdot 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 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: 76.7% accurate, 1.0× speedup?

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

\\
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
\end{array}

Alternative 1: 99.9% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 6.8 \cdot 10^{+20}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{y} \cdot \left(y + x\right)}{x}\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= y 6.8e+20) (/ (fma (/ 0.5 x) y 0.5) y) (/ (* (/ 0.5 y) (+ y x)) x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 6.8e+20) {
		tmp = fma((0.5 / x), y, 0.5) / y;
	} else {
		tmp = ((0.5 / y) * (y + x)) / x;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 6.8e+20)
		tmp = Float64(fma(Float64(0.5 / x), y, 0.5) / y);
	else
		tmp = Float64(Float64(Float64(0.5 / y) * Float64(y + x)) / x);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, 6.8e+20], N[(N[(N[(0.5 / x), $MachinePrecision] * y + 0.5), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(0.5 / y), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.8 \cdot 10^{+20}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 6.8e20

    1. Initial program 72.6%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(0.5, \color{blue}{\frac{y}{x}}, 0.5\right)}{y} \]
    5. Applied rewrites91.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}} \]
    6. Step-by-step derivation
      1. clear-numN/A

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\frac{1}{2}}{x}} \cdot y + \frac{1}{2}}{y} \]
      5. lower-fma.f6491.8

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}}{y} \]
    7. Applied rewrites91.8%

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

    if 6.8e20 < y

    1. Initial program 73.9%

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{x + y}{x \cdot 2}}{y}} \]
      4. div-invN/A

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{x + y}{2} \cdot \frac{1}{y}}}{x} \]
      10. div-invN/A

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

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

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

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

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

        \[\leadsto \frac{\left(\left(x + y\right) \cdot 0.5\right) \cdot \color{blue}{\frac{1}{y}}}{x} \]
    4. Applied rewrites99.8%

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

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

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot \frac{1}{2}\right)} \cdot \frac{1}{y}}{x} \]
      3. un-div-invN/A

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\frac{1}{2}}{y}} \cdot \left(x + y\right)}{x} \]
      8. lower-*.f6499.8

        \[\leadsto \frac{\color{blue}{\frac{0.5}{y} \cdot \left(x + y\right)}}{x} \]
    6. Applied rewrites99.8%

      \[\leadsto \frac{\color{blue}{\frac{0.5}{y} \cdot \left(x + y\right)}}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.3%

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

Alternative 2: 89.1% accurate, 0.6× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.75 \cdot 10^{-174}:\\ \;\;\;\;\frac{0.5}{y}\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-137}:\\ \;\;\;\;\frac{0.5}{x}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+122}:\\ \;\;\;\;\frac{y + x}{y \cdot \left(x \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= y 1.75e-174)
   (/ 0.5 y)
   (if (<= y 1.55e-137)
     (/ 0.5 x)
     (if (<= y 3.5e+122) (/ (+ y x) (* y (* x 2.0))) (/ 0.5 x)))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-174) {
		tmp = 0.5 / y;
	} else if (y <= 1.55e-137) {
		tmp = 0.5 / x;
	} else if (y <= 3.5e+122) {
		tmp = (y + x) / (y * (x * 2.0));
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.75d-174) then
        tmp = 0.5d0 / y
    else if (y <= 1.55d-137) then
        tmp = 0.5d0 / x
    else if (y <= 3.5d+122) then
        tmp = (y + x) / (y * (x * 2.0d0))
    else
        tmp = 0.5d0 / x
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-174) {
		tmp = 0.5 / y;
	} else if (y <= 1.55e-137) {
		tmp = 0.5 / x;
	} else if (y <= 3.5e+122) {
		tmp = (y + x) / (y * (x * 2.0));
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if y <= 1.75e-174:
		tmp = 0.5 / y
	elif y <= 1.55e-137:
		tmp = 0.5 / x
	elif y <= 3.5e+122:
		tmp = (y + x) / (y * (x * 2.0))
	else:
		tmp = 0.5 / x
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 1.75e-174)
		tmp = Float64(0.5 / y);
	elseif (y <= 1.55e-137)
		tmp = Float64(0.5 / x);
	elseif (y <= 3.5e+122)
		tmp = Float64(Float64(y + x) / Float64(y * Float64(x * 2.0)));
	else
		tmp = Float64(0.5 / x);
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.75e-174)
		tmp = 0.5 / y;
	elseif (y <= 1.55e-137)
		tmp = 0.5 / x;
	elseif (y <= 3.5e+122)
		tmp = (y + x) / (y * (x * 2.0));
	else
		tmp = 0.5 / x;
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, 1.75e-174], N[(0.5 / y), $MachinePrecision], If[LessEqual[y, 1.55e-137], N[(0.5 / x), $MachinePrecision], If[LessEqual[y, 3.5e+122], N[(N[(y + x), $MachinePrecision] / N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-174}:\\
\;\;\;\;\frac{0.5}{y}\\

\mathbf{elif}\;y \leq 1.55 \cdot 10^{-137}:\\
\;\;\;\;\frac{0.5}{x}\\

\mathbf{elif}\;y \leq 3.5 \cdot 10^{+122}:\\
\;\;\;\;\frac{y + x}{y \cdot \left(x \cdot 2\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 1.74999999999999994e-174

    1. Initial program 70.5%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{y}} \]
    4. Step-by-step derivation
      1. lower-/.f6461.2

        \[\leadsto \color{blue}{\frac{0.5}{y}} \]
    5. Applied rewrites61.2%

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

    if 1.74999999999999994e-174 < y < 1.54999999999999989e-137 or 3.50000000000000014e122 < y

    1. Initial program 62.0%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6479.5

        \[\leadsto \color{blue}{\frac{0.5}{x}} \]
    5. Applied rewrites79.5%

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

    if 1.54999999999999989e-137 < y < 3.50000000000000014e122

    1. Initial program 94.8%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification69.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.75 \cdot 10^{-174}:\\ \;\;\;\;\frac{0.5}{y}\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-137}:\\ \;\;\;\;\frac{0.5}{x}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+122}:\\ \;\;\;\;\frac{y + x}{y \cdot \left(x \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.9% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 3.9 \cdot 10^{+122}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= y 3.9e+122) (/ (fma (/ 0.5 x) y 0.5) y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 3.9e+122) {
		tmp = fma((0.5 / x), y, 0.5) / y;
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 3.9e+122)
		tmp = Float64(fma(Float64(0.5 / x), y, 0.5) / y);
	else
		tmp = Float64(0.5 / x);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, 3.9e+122], N[(N[(N[(0.5 / x), $MachinePrecision] * y + 0.5), $MachinePrecision] / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{+122}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 3.8999999999999999e122

    1. Initial program 74.1%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(0.5, \color{blue}{\frac{y}{x}}, 0.5\right)}{y} \]
    5. Applied rewrites92.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}} \]
    6. Step-by-step derivation
      1. clear-numN/A

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\frac{1}{2}}{x}} \cdot y + \frac{1}{2}}{y} \]
      5. lower-fma.f6492.0

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{0.5}{x}, y, 0.5\right)}}{y} \]
    7. Applied rewrites92.0%

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

    if 3.8999999999999999e122 < y

    1. Initial program 64.1%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6494.0

        \[\leadsto \color{blue}{\frac{0.5}{x}} \]
    5. Applied rewrites94.0%

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 95.8% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 3.9 \cdot 10^{+122}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= y 3.9e+122) (/ (fma 0.5 (/ y x) 0.5) y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 3.9e+122) {
		tmp = fma(0.5, (y / x), 0.5) / y;
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 3.9e+122)
		tmp = Float64(fma(0.5, Float64(y / x), 0.5) / y);
	else
		tmp = Float64(0.5 / x);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, 3.9e+122], N[(N[(0.5 * N[(y / x), $MachinePrecision] + 0.5), $MachinePrecision] / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{+122}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 3.8999999999999999e122

    1. Initial program 74.1%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(0.5, \color{blue}{\frac{y}{x}}, 0.5\right)}{y} \]
    5. Applied rewrites92.0%

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

    if 3.8999999999999999e122 < y

    1. Initial program 64.1%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6494.0

        \[\leadsto \color{blue}{\frac{0.5}{x}} \]
    5. Applied rewrites94.0%

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 81.4% accurate, 1.4× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.75 \cdot 10^{-174}:\\ \;\;\;\;\frac{0.5}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (if (<= y 1.75e-174) (/ 0.5 y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-174) {
		tmp = 0.5 / y;
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.75d-174) then
        tmp = 0.5d0 / y
    else
        tmp = 0.5d0 / x
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-174) {
		tmp = 0.5 / y;
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if y <= 1.75e-174:
		tmp = 0.5 / y
	else:
		tmp = 0.5 / x
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 1.75e-174)
		tmp = Float64(0.5 / y);
	else
		tmp = Float64(0.5 / x);
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.75e-174)
		tmp = 0.5 / y;
	else
		tmp = 0.5 / x;
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, 1.75e-174], N[(0.5 / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-174}:\\
\;\;\;\;\frac{0.5}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.74999999999999994e-174

    1. Initial program 70.5%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{y}} \]
    4. Step-by-step derivation
      1. lower-/.f6461.2

        \[\leadsto \color{blue}{\frac{0.5}{y}} \]
    5. Applied rewrites61.2%

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

    if 1.74999999999999994e-174 < y

    1. Initial program 77.5%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6463.1

        \[\leadsto \color{blue}{\frac{0.5}{x}} \]
    5. Applied rewrites63.1%

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 50.0% accurate, 2.1× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \frac{0.5}{x} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (/ 0.5 x))
assert(x < y);
double code(double x, double y) {
	return 0.5 / x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 0.5d0 / x
end function
assert x < y;
public static double code(double x, double y) {
	return 0.5 / x;
}
[x, y] = sort([x, y])
def code(x, y):
	return 0.5 / x
x, y = sort([x, y])
function code(x, y)
	return Float64(0.5 / x)
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = 0.5 / x;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(0.5 / x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{0.5}{x}
\end{array}
Derivation
  1. Initial program 72.8%

    \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{\frac{1}{2}}{x}} \]
  4. Step-by-step derivation
    1. lower-/.f6447.5

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  5. Applied rewrites47.5%

    \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  6. Add Preprocessing

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

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

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

Reproduce

?
herbie shell --seed 2024216 
(FPCore (x y)
  :name "Linear.Projection:inversePerspective from linear-1.19.1.3, C"
  :precision binary64

  :alt
  (! :herbie-platform default (+ (/ 1/2 x) (/ 1/2 y)))

  (/ (+ x y) (* (* x 2.0) y)))