Linear.Quaternion:$clog from linear-1.19.1.3

Percentage Accurate: 68.4% → 99.8%
Time: 3.5s
Alternatives: 8
Speedup: 1.0×

Specification

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

\\
\sqrt{x \cdot 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 8 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: 68.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{x \cdot x + y} \end{array} \]
(FPCore (x y) :precision binary64 (sqrt (+ (* x x) y)))
double code(double x, double y) {
	return sqrt(((x * x) + y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = sqrt(((x * x) + y))
end function
public static double code(double x, double y) {
	return Math.sqrt(((x * x) + y));
}
def code(x, y):
	return math.sqrt(((x * x) + y))
function code(x, y)
	return sqrt(Float64(Float64(x * x) + y))
end
function tmp = code(x, y)
	tmp = sqrt(((x * x) + y));
end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{x \cdot x + y}
\end{array}

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+102}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x, x, y\right)}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -2e+154)
   (- x)
   (if (<= x 2.8e+102) (sqrt (fma x x y)) (+ x (* 0.5 (/ y x))))))
double code(double x, double y) {
	double tmp;
	if (x <= -2e+154) {
		tmp = -x;
	} else if (x <= 2.8e+102) {
		tmp = sqrt(fma(x, x, y));
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (x <= -2e+154)
		tmp = Float64(-x);
	elseif (x <= 2.8e+102)
		tmp = sqrt(fma(x, x, y));
	else
		tmp = Float64(x + Float64(0.5 * Float64(y / x)));
	end
	return tmp
end
code[x_, y_] := If[LessEqual[x, -2e+154], (-x), If[LessEqual[x, 2.8e+102], N[Sqrt[N[(x * x + y), $MachinePrecision]], $MachinePrecision], N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq 2.8 \cdot 10^{+102}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x, x, y\right)}\\

\mathbf{else}:\\
\;\;\;\;x + 0.5 \cdot \frac{y}{x}\\


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

    1. Initial program 6.6%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified100.0%

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

    if -2.00000000000000007e154 < x < 2.80000000000000018e102

    1. Initial program 100.0%

      \[\sqrt{x \cdot x + y} \]
    2. Step-by-step derivation
      1. fma-def100.0%

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(x, x, y\right)}} \]
    3. Simplified100.0%

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

    if 2.80000000000000018e102 < x

    1. Initial program 29.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{x} + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+102}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x, x, y\right)}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \]

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+102}:\\ \;\;\;\;\sqrt{y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -2e+154)
   (- x)
   (if (<= x 2e+102) (sqrt (+ y (* x x))) (+ x (* 0.5 (/ y x))))))
double code(double x, double y) {
	double tmp;
	if (x <= -2e+154) {
		tmp = -x;
	} else if (x <= 2e+102) {
		tmp = sqrt((y + (x * x)));
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-2d+154)) then
        tmp = -x
    else if (x <= 2d+102) then
        tmp = sqrt((y + (x * x)))
    else
        tmp = x + (0.5d0 * (y / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -2e+154) {
		tmp = -x;
	} else if (x <= 2e+102) {
		tmp = Math.sqrt((y + (x * x)));
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -2e+154:
		tmp = -x
	elif x <= 2e+102:
		tmp = math.sqrt((y + (x * x)))
	else:
		tmp = x + (0.5 * (y / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -2e+154)
		tmp = Float64(-x);
	elseif (x <= 2e+102)
		tmp = sqrt(Float64(y + Float64(x * x)));
	else
		tmp = Float64(x + Float64(0.5 * Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -2e+154)
		tmp = -x;
	elseif (x <= 2e+102)
		tmp = sqrt((y + (x * x)));
	else
		tmp = x + (0.5 * (y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -2e+154], (-x), If[LessEqual[x, 2e+102], N[Sqrt[N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq 2 \cdot 10^{+102}:\\
\;\;\;\;\sqrt{y + x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;x + 0.5 \cdot \frac{y}{x}\\


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

    1. Initial program 6.6%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg100.0%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified100.0%

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

    if -2.00000000000000007e154 < x < 1.99999999999999995e102

    1. Initial program 100.0%

      \[\sqrt{x \cdot x + y} \]

    if 1.99999999999999995e102 < x

    1. Initial program 29.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{x} + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+102}:\\ \;\;\;\;\sqrt{y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \]

Alternative 3: 89.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{-58}:\\ \;\;\;\;y \cdot \frac{-0.5}{x} - x\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-43}:\\ \;\;\;\;\sqrt{y}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.5e-58)
   (- (* y (/ -0.5 x)) x)
   (if (<= x 3.2e-43) (sqrt y) (+ x (* 0.5 (/ y x))))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.5e-58) {
		tmp = (y * (-0.5 / x)) - x;
	} else if (x <= 3.2e-43) {
		tmp = sqrt(y);
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1.5d-58)) then
        tmp = (y * ((-0.5d0) / x)) - x
    else if (x <= 3.2d-43) then
        tmp = sqrt(y)
    else
        tmp = x + (0.5d0 * (y / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.5e-58) {
		tmp = (y * (-0.5 / x)) - x;
	} else if (x <= 3.2e-43) {
		tmp = Math.sqrt(y);
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.5e-58:
		tmp = (y * (-0.5 / x)) - x
	elif x <= 3.2e-43:
		tmp = math.sqrt(y)
	else:
		tmp = x + (0.5 * (y / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.5e-58)
		tmp = Float64(Float64(y * Float64(-0.5 / x)) - x);
	elseif (x <= 3.2e-43)
		tmp = sqrt(y);
	else
		tmp = Float64(x + Float64(0.5 * Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.5e-58)
		tmp = (y * (-0.5 / x)) - x;
	elseif (x <= 3.2e-43)
		tmp = sqrt(y);
	else
		tmp = x + (0.5 * (y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.5e-58], N[(N[(y * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 3.2e-43], N[Sqrt[y], $MachinePrecision], N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-58}:\\
\;\;\;\;y \cdot \frac{-0.5}{x} - x\\

\mathbf{elif}\;x \leq 3.2 \cdot 10^{-43}:\\
\;\;\;\;\sqrt{y}\\

\mathbf{else}:\\
\;\;\;\;x + 0.5 \cdot \frac{y}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.50000000000000004e-58

    1. Initial program 61.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 90.2%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x} + -1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg90.2%

        \[\leadsto -0.5 \cdot \frac{y}{x} + \color{blue}{\left(-x\right)} \]
      2. unsub-neg90.2%

        \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x} - x} \]
      3. *-commutative90.2%

        \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5} - x \]
    4. Simplified90.2%

      \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5 - x} \]
    5. Taylor expanded in y around 0 90.2%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x}} - x \]
    6. Step-by-step derivation
      1. associate-*r/90.2%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot y}{x}} - x \]
      2. *-commutative90.2%

        \[\leadsto \frac{\color{blue}{y \cdot -0.5}}{x} - x \]
      3. associate-*r/90.2%

        \[\leadsto \color{blue}{y \cdot \frac{-0.5}{x}} - x \]
    7. Simplified90.2%

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

    if -1.50000000000000004e-58 < x < 3.19999999999999985e-43

    1. Initial program 100.0%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around 0 92.6%

      \[\leadsto \color{blue}{\sqrt{y}} \]

    if 3.19999999999999985e-43 < x

    1. Initial program 57.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 88.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{-58}:\\ \;\;\;\;y \cdot \frac{-0.5}{x} - x\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-43}:\\ \;\;\;\;\sqrt{y}\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \]

Alternative 4: 68.0% accurate, 11.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -5e-310) (- x) (+ x (* 0.5 (/ y x)))))
double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -x;
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-5d-310)) then
        tmp = -x
    else
        tmp = x + (0.5d0 * (y / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -x;
	} else {
		tmp = x + (0.5 * (y / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -5e-310:
		tmp = -x
	else:
		tmp = x + (0.5 * (y / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(-x);
	else
		tmp = Float64(x + Float64(0.5 * Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -5e-310)
		tmp = -x;
	else
		tmp = x + (0.5 * (y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -5e-310], (-x), N[(x + N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-x\\

\mathbf{else}:\\
\;\;\;\;x + 0.5 \cdot \frac{y}{x}\\


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

    1. Initial program 72.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 65.9%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg65.9%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified65.9%

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

    if -4.999999999999985e-310 < x

    1. Initial program 70.4%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 66.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x + 0.5 \cdot \frac{y}{x}\\ \end{array} \]

Alternative 5: 68.0% accurate, 11.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3 \cdot 10^{-309}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{0.5}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x 3e-309) (- x) (+ x (* y (/ 0.5 x)))))
double code(double x, double y) {
	double tmp;
	if (x <= 3e-309) {
		tmp = -x;
	} else {
		tmp = x + (y * (0.5 / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= 3d-309) then
        tmp = -x
    else
        tmp = x + (y * (0.5d0 / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= 3e-309) {
		tmp = -x;
	} else {
		tmp = x + (y * (0.5 / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= 3e-309:
		tmp = -x
	else:
		tmp = x + (y * (0.5 / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= 3e-309)
		tmp = Float64(-x);
	else
		tmp = Float64(x + Float64(y * Float64(0.5 / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= 3e-309)
		tmp = -x;
	else
		tmp = x + (y * (0.5 / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, 3e-309], (-x), N[(x + N[(y * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3 \cdot 10^{-309}:\\
\;\;\;\;-x\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{0.5}{x}\\


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

    1. Initial program 72.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 65.9%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg65.9%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified65.9%

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

    if 3.000000000000001e-309 < x

    1. Initial program 70.4%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 66.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{x} + x} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt46.8%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \frac{y}{x}} \cdot \sqrt{0.5 \cdot \frac{y}{x}}} + x \]
      2. sqrt-unprod66.0%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \frac{y}{x}\right) \cdot \left(0.5 \cdot \frac{y}{x}\right)}} + x \]
      3. *-commutative66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot 0.5\right)} \cdot \left(0.5 \cdot \frac{y}{x}\right)} + x \]
      4. *-commutative66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot 0.5\right) \cdot \color{blue}{\left(\frac{y}{x} \cdot 0.5\right)}} + x \]
      5. swap-sqr66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \left(0.5 \cdot 0.5\right)}} + x \]
      6. metadata-eval66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \color{blue}{0.25}} + x \]
      7. metadata-eval66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \color{blue}{\left(-0.5 \cdot -0.5\right)}} + x \]
      8. swap-sqr66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot -0.5\right) \cdot \left(\frac{y}{x} \cdot -0.5\right)}} + x \]
      9. sqrt-unprod38.9%

        \[\leadsto \color{blue}{\sqrt{\frac{y}{x} \cdot -0.5} \cdot \sqrt{\frac{y}{x} \cdot -0.5}} + x \]
      10. add-sqr-sqrt64.3%

        \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5} + x \]
      11. *-commutative64.3%

        \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x}} + x \]
      12. clear-num64.3%

        \[\leadsto -0.5 \cdot \color{blue}{\frac{1}{\frac{x}{y}}} + x \]
      13. un-div-inv64.3%

        \[\leadsto \color{blue}{\frac{-0.5}{\frac{x}{y}}} + x \]
    4. Applied egg-rr64.3%

      \[\leadsto \color{blue}{\frac{-0.5}{\frac{x}{y}}} + x \]
    5. Step-by-step derivation
      1. associate-/r/64.3%

        \[\leadsto \color{blue}{\frac{-0.5}{x} \cdot y} + x \]
      2. *-commutative64.3%

        \[\leadsto \color{blue}{y \cdot \frac{-0.5}{x}} + x \]
      3. add-sqr-sqrt38.9%

        \[\leadsto \color{blue}{\sqrt{y \cdot \frac{-0.5}{x}} \cdot \sqrt{y \cdot \frac{-0.5}{x}}} + x \]
      4. sqrt-unprod66.0%

        \[\leadsto \color{blue}{\sqrt{\left(y \cdot \frac{-0.5}{x}\right) \cdot \left(y \cdot \frac{-0.5}{x}\right)}} + x \]
      5. *-commutative66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{-0.5}{x} \cdot y\right)} \cdot \left(y \cdot \frac{-0.5}{x}\right)} + x \]
      6. associate-/r/66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{-0.5}{\frac{x}{y}}} \cdot \left(y \cdot \frac{-0.5}{x}\right)} + x \]
      7. *-commutative66.0%

        \[\leadsto \sqrt{\frac{-0.5}{\frac{x}{y}} \cdot \color{blue}{\left(\frac{-0.5}{x} \cdot y\right)}} + x \]
      8. associate-/r/66.0%

        \[\leadsto \sqrt{\frac{-0.5}{\frac{x}{y}} \cdot \color{blue}{\frac{-0.5}{\frac{x}{y}}}} + x \]
      9. frac-times66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{-0.5 \cdot -0.5}{\frac{x}{y} \cdot \frac{x}{y}}}} + x \]
      10. metadata-eval66.0%

        \[\leadsto \sqrt{\frac{\color{blue}{0.25}}{\frac{x}{y} \cdot \frac{x}{y}}} + x \]
      11. metadata-eval66.0%

        \[\leadsto \sqrt{\frac{\color{blue}{0.5 \cdot 0.5}}{\frac{x}{y} \cdot \frac{x}{y}}} + x \]
      12. frac-times66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{x}{y}} \cdot \frac{0.5}{\frac{x}{y}}}} + x \]
      13. sqrt-unprod48.3%

        \[\leadsto \color{blue}{\sqrt{\frac{0.5}{\frac{x}{y}}} \cdot \sqrt{\frac{0.5}{\frac{x}{y}}}} + x \]
      14. add-sqr-sqrt66.4%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{x}{y}}} + x \]
      15. associate-/r/66.4%

        \[\leadsto \color{blue}{\frac{0.5}{x} \cdot y} + x \]
    6. Applied egg-rr66.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3 \cdot 10^{-309}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{0.5}{x}\\ \end{array} \]

Alternative 6: 68.2% accurate, 11.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;y \cdot \frac{-0.5}{x} - x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{0.5}{x}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -5e-310) (- (* y (/ -0.5 x)) x) (+ x (* y (/ 0.5 x)))))
double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = (y * (-0.5 / x)) - x;
	} else {
		tmp = x + (y * (0.5 / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-5d-310)) then
        tmp = (y * ((-0.5d0) / x)) - x
    else
        tmp = x + (y * (0.5d0 / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = (y * (-0.5 / x)) - x;
	} else {
		tmp = x + (y * (0.5 / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -5e-310:
		tmp = (y * (-0.5 / x)) - x
	else:
		tmp = x + (y * (0.5 / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(Float64(y * Float64(-0.5 / x)) - x);
	else
		tmp = Float64(x + Float64(y * Float64(0.5 / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -5e-310)
		tmp = (y * (-0.5 / x)) - x;
	else
		tmp = x + (y * (0.5 / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -5e-310], N[(N[(y * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(x + N[(y * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;y \cdot \frac{-0.5}{x} - x\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{0.5}{x}\\


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

    1. Initial program 72.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 66.8%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x} + -1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg66.8%

        \[\leadsto -0.5 \cdot \frac{y}{x} + \color{blue}{\left(-x\right)} \]
      2. unsub-neg66.8%

        \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x} - x} \]
      3. *-commutative66.8%

        \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5} - x \]
    4. Simplified66.8%

      \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5 - x} \]
    5. Taylor expanded in y around 0 66.8%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x}} - x \]
    6. Step-by-step derivation
      1. associate-*r/66.8%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot y}{x}} - x \]
      2. *-commutative66.8%

        \[\leadsto \frac{\color{blue}{y \cdot -0.5}}{x} - x \]
      3. associate-*r/66.8%

        \[\leadsto \color{blue}{y \cdot \frac{-0.5}{x}} - x \]
    7. Simplified66.8%

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

    if -4.999999999999985e-310 < x

    1. Initial program 70.4%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 66.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{x} + x} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt46.8%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \frac{y}{x}} \cdot \sqrt{0.5 \cdot \frac{y}{x}}} + x \]
      2. sqrt-unprod66.0%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \frac{y}{x}\right) \cdot \left(0.5 \cdot \frac{y}{x}\right)}} + x \]
      3. *-commutative66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot 0.5\right)} \cdot \left(0.5 \cdot \frac{y}{x}\right)} + x \]
      4. *-commutative66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot 0.5\right) \cdot \color{blue}{\left(\frac{y}{x} \cdot 0.5\right)}} + x \]
      5. swap-sqr66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \left(0.5 \cdot 0.5\right)}} + x \]
      6. metadata-eval66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \color{blue}{0.25}} + x \]
      7. metadata-eval66.0%

        \[\leadsto \sqrt{\left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot \color{blue}{\left(-0.5 \cdot -0.5\right)}} + x \]
      8. swap-sqr66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{y}{x} \cdot -0.5\right) \cdot \left(\frac{y}{x} \cdot -0.5\right)}} + x \]
      9. sqrt-unprod38.9%

        \[\leadsto \color{blue}{\sqrt{\frac{y}{x} \cdot -0.5} \cdot \sqrt{\frac{y}{x} \cdot -0.5}} + x \]
      10. add-sqr-sqrt64.3%

        \[\leadsto \color{blue}{\frac{y}{x} \cdot -0.5} + x \]
      11. *-commutative64.3%

        \[\leadsto \color{blue}{-0.5 \cdot \frac{y}{x}} + x \]
      12. clear-num64.3%

        \[\leadsto -0.5 \cdot \color{blue}{\frac{1}{\frac{x}{y}}} + x \]
      13. un-div-inv64.3%

        \[\leadsto \color{blue}{\frac{-0.5}{\frac{x}{y}}} + x \]
    4. Applied egg-rr64.3%

      \[\leadsto \color{blue}{\frac{-0.5}{\frac{x}{y}}} + x \]
    5. Step-by-step derivation
      1. associate-/r/64.3%

        \[\leadsto \color{blue}{\frac{-0.5}{x} \cdot y} + x \]
      2. *-commutative64.3%

        \[\leadsto \color{blue}{y \cdot \frac{-0.5}{x}} + x \]
      3. add-sqr-sqrt38.9%

        \[\leadsto \color{blue}{\sqrt{y \cdot \frac{-0.5}{x}} \cdot \sqrt{y \cdot \frac{-0.5}{x}}} + x \]
      4. sqrt-unprod66.0%

        \[\leadsto \color{blue}{\sqrt{\left(y \cdot \frac{-0.5}{x}\right) \cdot \left(y \cdot \frac{-0.5}{x}\right)}} + x \]
      5. *-commutative66.0%

        \[\leadsto \sqrt{\color{blue}{\left(\frac{-0.5}{x} \cdot y\right)} \cdot \left(y \cdot \frac{-0.5}{x}\right)} + x \]
      6. associate-/r/66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{-0.5}{\frac{x}{y}}} \cdot \left(y \cdot \frac{-0.5}{x}\right)} + x \]
      7. *-commutative66.0%

        \[\leadsto \sqrt{\frac{-0.5}{\frac{x}{y}} \cdot \color{blue}{\left(\frac{-0.5}{x} \cdot y\right)}} + x \]
      8. associate-/r/66.0%

        \[\leadsto \sqrt{\frac{-0.5}{\frac{x}{y}} \cdot \color{blue}{\frac{-0.5}{\frac{x}{y}}}} + x \]
      9. frac-times66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{-0.5 \cdot -0.5}{\frac{x}{y} \cdot \frac{x}{y}}}} + x \]
      10. metadata-eval66.0%

        \[\leadsto \sqrt{\frac{\color{blue}{0.25}}{\frac{x}{y} \cdot \frac{x}{y}}} + x \]
      11. metadata-eval66.0%

        \[\leadsto \sqrt{\frac{\color{blue}{0.5 \cdot 0.5}}{\frac{x}{y} \cdot \frac{x}{y}}} + x \]
      12. frac-times66.0%

        \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{x}{y}} \cdot \frac{0.5}{\frac{x}{y}}}} + x \]
      13. sqrt-unprod48.3%

        \[\leadsto \color{blue}{\sqrt{\frac{0.5}{\frac{x}{y}}} \cdot \sqrt{\frac{0.5}{\frac{x}{y}}}} + x \]
      14. add-sqr-sqrt66.4%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{x}{y}}} + x \]
      15. associate-/r/66.4%

        \[\leadsto \color{blue}{\frac{0.5}{x} \cdot y} + x \]
    6. Applied egg-rr66.4%

      \[\leadsto \color{blue}{\frac{0.5}{x} \cdot y} + x \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;y \cdot \frac{-0.5}{x} - x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{0.5}{x}\\ \end{array} \]

Alternative 7: 67.8% accurate, 25.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= x -5e-310) (- x) x))
double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -x;
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-5d-310)) then
        tmp = -x
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -x;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -5e-310:
		tmp = -x
	else:
		tmp = x
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(-x);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -5e-310)
		tmp = -x;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -5e-310], (-x), x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-x\\

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


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

    1. Initial program 72.1%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around -inf 65.9%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. mul-1-neg65.9%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified65.9%

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

    if -4.999999999999985e-310 < x

    1. Initial program 70.4%

      \[\sqrt{x \cdot x + y} \]
    2. Taylor expanded in x around inf 66.0%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 8: 34.4% accurate, 105.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 71.2%

    \[\sqrt{x \cdot x + y} \]
  2. Taylor expanded in x around inf 34.7%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification34.7%

    \[\leadsto x \]

Developer target: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \frac{y}{x} + x\\ \mathbf{if}\;x < -1.5097698010472593 \cdot 10^{+153}:\\ \;\;\;\;-t_0\\ \mathbf{elif}\;x < 5.582399551122541 \cdot 10^{+57}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (* 0.5 (/ y x)) x)))
   (if (< x -1.5097698010472593e+153)
     (- t_0)
     (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) t_0))))
double code(double x, double y) {
	double t_0 = (0.5 * (y / x)) + x;
	double tmp;
	if (x < -1.5097698010472593e+153) {
		tmp = -t_0;
	} else if (x < 5.582399551122541e+57) {
		tmp = sqrt(((x * x) + y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (0.5d0 * (y / x)) + x
    if (x < (-1.5097698010472593d+153)) then
        tmp = -t_0
    else if (x < 5.582399551122541d+57) then
        tmp = sqrt(((x * x) + y))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (0.5 * (y / x)) + x;
	double tmp;
	if (x < -1.5097698010472593e+153) {
		tmp = -t_0;
	} else if (x < 5.582399551122541e+57) {
		tmp = Math.sqrt(((x * x) + y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = (0.5 * (y / x)) + x
	tmp = 0
	if x < -1.5097698010472593e+153:
		tmp = -t_0
	elif x < 5.582399551122541e+57:
		tmp = math.sqrt(((x * x) + y))
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(Float64(0.5 * Float64(y / x)) + x)
	tmp = 0.0
	if (x < -1.5097698010472593e+153)
		tmp = Float64(-t_0);
	elseif (x < 5.582399551122541e+57)
		tmp = sqrt(Float64(Float64(x * x) + y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (0.5 * (y / x)) + x;
	tmp = 0.0;
	if (x < -1.5097698010472593e+153)
		tmp = -t_0;
	elseif (x < 5.582399551122541e+57)
		tmp = sqrt(((x * x) + y));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[Less[x, -1.5097698010472593e+153], (-t$95$0), If[Less[x, 5.582399551122541e+57], N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{y}{x} + x\\
\mathbf{if}\;x < -1.5097698010472593 \cdot 10^{+153}:\\
\;\;\;\;-t_0\\

\mathbf{elif}\;x < 5.582399551122541 \cdot 10^{+57}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023196 
(FPCore (x y)
  :name "Linear.Quaternion:$clog from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< x -1.5097698010472593e+153) (- (+ (* 0.5 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 0.5 (/ y x)) x)))

  (sqrt (+ (* x x) y)))