Linear.Projection:inversePerspective from linear-1.19.1.3, C

Percentage Accurate: 77.3% → 99.8%
Time: 4.8s
Alternatives: 5
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 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: 77.3% 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.8% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 10^{-38}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{x}{y}, 0.5\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 1e-38) (/ (fma 0.5 (/ y x) 0.5) y) (/ (fma 0.5 (/ x y) 0.5) x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= 1e-38) {
		tmp = fma(0.5, (y / x), 0.5) / y;
	} else {
		tmp = fma(0.5, (x / y), 0.5) / x;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= 1e-38)
		tmp = Float64(fma(0.5, Float64(y / x), 0.5) / y);
	else
		tmp = Float64(fma(0.5, Float64(x / y), 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, 1e-38], N[(N[(0.5 * N[(y / x), $MachinePrecision] + 0.5), $MachinePrecision] / y), $MachinePrecision], N[(N[(0.5 * N[(x / y), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-38}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\

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


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

    1. Initial program 73.8%

      \[\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-/.f6489.1

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

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

    if 9.9999999999999996e-39 < y

    1. Initial program 84.3%

      \[\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} + \frac{1}{2} \cdot \frac{x}{y}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(0.5, \frac{x}{y}, 0.5\right)}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.2% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} t_0 := \frac{y + x}{y \cdot \left(x \cdot 2\right)}\\ t_1 := \frac{\mathsf{fma}\left(0.5, \frac{x}{y}, 0.5\right)}{x}\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+40}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+19}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+307}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (+ y x) (* y (* x 2.0)))) (t_1 (/ (fma 0.5 (/ x y) 0.5) x)))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -1e+40)
       t_0
       (if (<= t_0 5e+19) t_1 (if (<= t_0 1e+307) t_0 t_1))))))
assert(x < y);
double code(double x, double y) {
	double t_0 = (y + x) / (y * (x * 2.0));
	double t_1 = fma(0.5, (x / y), 0.5) / x;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -1e+40) {
		tmp = t_0;
	} else if (t_0 <= 5e+19) {
		tmp = t_1;
	} else if (t_0 <= 1e+307) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	t_0 = Float64(Float64(y + x) / Float64(y * Float64(x * 2.0)))
	t_1 = Float64(fma(0.5, Float64(x / y), 0.5) / x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -1e+40)
		tmp = t_0;
	elseif (t_0 <= 5e+19)
		tmp = t_1;
	elseif (t_0 <= 1e+307)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] / N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[(x / y), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -1e+40], t$95$0, If[LessEqual[t$95$0, 5e+19], t$95$1, If[LessEqual[t$95$0, 1e+307], t$95$0, t$95$1]]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \frac{y + x}{y \cdot \left(x \cdot 2\right)}\\
t_1 := \frac{\mathsf{fma}\left(0.5, \frac{x}{y}, 0.5\right)}{x}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+19}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 10^{+307}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < -inf.0 or -1.00000000000000003e40 < (/.f64 (+.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 5e19 or 9.99999999999999986e306 < (/.f64 (+.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y))

    1. Initial program 46.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} + \frac{1}{2} \cdot \frac{x}{y}}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

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

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < -1.00000000000000003e40 or 5e19 < (/.f64 (+.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 9.99999999999999986e306

    1. Initial program 99.1%

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

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

Alternative 3: 90.3% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+160}:\\ \;\;\;\;\frac{0.5}{y}\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-165}:\\ \;\;\;\;\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 (<= x -1.7e+160)
   (/ 0.5 y)
   (if (<= x -1.45e-165) (/ (+ y x) (* y (* x 2.0))) (/ 0.5 x))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -1.7e+160) {
		tmp = 0.5 / y;
	} else if (x <= -1.45e-165) {
		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 (x <= (-1.7d+160)) then
        tmp = 0.5d0 / y
    else if (x <= (-1.45d-165)) 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 (x <= -1.7e+160) {
		tmp = 0.5 / y;
	} else if (x <= -1.45e-165) {
		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 x <= -1.7e+160:
		tmp = 0.5 / y
	elif x <= -1.45e-165:
		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 (x <= -1.7e+160)
		tmp = Float64(0.5 / y);
	elseif (x <= -1.45e-165)
		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 (x <= -1.7e+160)
		tmp = 0.5 / y;
	elseif (x <= -1.45e-165)
		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[x, -1.7e+160], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, -1.45e-165], 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}\;x \leq -1.7 \cdot 10^{+160}:\\
\;\;\;\;\frac{0.5}{y}\\

\mathbf{elif}\;x \leq -1.45 \cdot 10^{-165}:\\
\;\;\;\;\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 x < -1.70000000000000015e160

    1. Initial program 61.2%

      \[\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-/.f6479.7

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

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

    if -1.70000000000000015e160 < x < -1.45e-165

    1. Initial program 91.5%

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y} \]
    2. Add Preprocessing

    if -1.45e-165 < x

    1. Initial program 74.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-/.f6462.9

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

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+160}:\\ \;\;\;\;\frac{0.5}{y}\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-165}:\\ \;\;\;\;\frac{y + x}{y \cdot \left(x \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 81.9% accurate, 1.4× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-140}:\\ \;\;\;\;\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 (<= x -2.3e-140) (/ 0.5 y) (/ 0.5 x)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -2.3e-140) {
		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 (x <= (-2.3d-140)) 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 (x <= -2.3e-140) {
		tmp = 0.5 / y;
	} else {
		tmp = 0.5 / x;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if x <= -2.3e-140:
		tmp = 0.5 / y
	else:
		tmp = 0.5 / x
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (x <= -2.3e-140)
		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 (x <= -2.3e-140)
		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[x, -2.3e-140], N[(0.5 / y), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-140}:\\
\;\;\;\;\frac{0.5}{y}\\

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


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

    1. Initial program 81.3%

      \[\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-/.f6458.0

        \[\leadsto \color{blue}{\frac{0.5}{y}} \]
    5. Applied rewrites58.0%

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

    if -2.3000000000000001e-140 < x

    1. Initial program 74.6%

      \[\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.5

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

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

Alternative 5: 50.8% 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 76.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-/.f6456.0

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

    \[\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 2024233 
(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)))