Linear.Quaternion:$clog from linear-1.19.1.3

Percentage Accurate: 69.4% → 99.1%
Time: 2.6s
Alternatives: 5
Speedup: 1.1×

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));
}
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 = 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}

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: 69.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));
}
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 = 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.1% accurate, 0.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 2.5 \cdot 10^{+94}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x\_m, x\_m, y\right)}\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot 1\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y)
 :precision binary64
 (if (<= x_m 2.5e+94) (sqrt (fma x_m x_m y)) (* x_m 1.0)))
x_m = fabs(x);
double code(double x_m, double y) {
	double tmp;
	if (x_m <= 2.5e+94) {
		tmp = sqrt(fma(x_m, x_m, y));
	} else {
		tmp = x_m * 1.0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m, y)
	tmp = 0.0
	if (x_m <= 2.5e+94)
		tmp = sqrt(fma(x_m, x_m, y));
	else
		tmp = Float64(x_m * 1.0);
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := If[LessEqual[x$95$m, 2.5e+94], N[Sqrt[N[(x$95$m * x$95$m + y), $MachinePrecision]], $MachinePrecision], N[(x$95$m * 1.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.5 \cdot 10^{+94}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x\_m, x\_m, y\right)}\\

\mathbf{else}:\\
\;\;\;\;x\_m \cdot 1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.50000000000000005e94

    1. Initial program 69.4%

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

        \[\leadsto \sqrt{\color{blue}{x \cdot x + y}} \]
      2. add-flipN/A

        \[\leadsto \sqrt{\color{blue}{x \cdot x - \left(\mathsf{neg}\left(y\right)\right)}} \]
      3. sub-flipN/A

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

        \[\leadsto \sqrt{\color{blue}{x \cdot x} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)} \]
      5. remove-double-negN/A

        \[\leadsto \sqrt{x \cdot x + \color{blue}{y}} \]
      6. lower-fma.f6469.4

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

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

    if 2.50000000000000005e94 < x

    1. Initial program 69.4%

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

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

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

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

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

        \[\leadsto x \cdot \left(1 + \frac{1}{2} \cdot \frac{y}{\color{blue}{{x}^{2}}}\right) \]
      5. lower-pow.f6467.8

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

      \[\leadsto \color{blue}{x \cdot \left(1 + 0.5 \cdot \frac{y}{{x}^{2}}\right)} \]
    5. Taylor expanded in x around inf

      \[\leadsto x \cdot 1 \]
    6. Step-by-step derivation
      1. Applied rewrites67.5%

        \[\leadsto x \cdot 1 \]
    7. Recombined 2 regimes into one program.
    8. Add Preprocessing

    Alternative 2: 89.4% accurate, 1.1× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 7.1 \cdot 10^{-70}:\\ \;\;\;\;\sqrt{\left|y\right|}\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot 1\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    (FPCore (x_m y)
     :precision binary64
     (if (<= x_m 7.1e-70) (sqrt (fabs y)) (* x_m 1.0)))
    x_m = fabs(x);
    double code(double x_m, double y) {
    	double tmp;
    	if (x_m <= 7.1e-70) {
    		tmp = sqrt(fabs(y));
    	} else {
    		tmp = x_m * 1.0;
    	}
    	return tmp;
    }
    
    x_m =     private
    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_m, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x_m
        real(8), intent (in) :: y
        real(8) :: tmp
        if (x_m <= 7.1d-70) then
            tmp = sqrt(abs(y))
        else
            tmp = x_m * 1.0d0
        end if
        code = tmp
    end function
    
    x_m = Math.abs(x);
    public static double code(double x_m, double y) {
    	double tmp;
    	if (x_m <= 7.1e-70) {
    		tmp = Math.sqrt(Math.abs(y));
    	} else {
    		tmp = x_m * 1.0;
    	}
    	return tmp;
    }
    
    x_m = math.fabs(x)
    def code(x_m, y):
    	tmp = 0
    	if x_m <= 7.1e-70:
    		tmp = math.sqrt(math.fabs(y))
    	else:
    		tmp = x_m * 1.0
    	return tmp
    
    x_m = abs(x)
    function code(x_m, y)
    	tmp = 0.0
    	if (x_m <= 7.1e-70)
    		tmp = sqrt(abs(y));
    	else
    		tmp = Float64(x_m * 1.0);
    	end
    	return tmp
    end
    
    x_m = abs(x);
    function tmp_2 = code(x_m, y)
    	tmp = 0.0;
    	if (x_m <= 7.1e-70)
    		tmp = sqrt(abs(y));
    	else
    		tmp = x_m * 1.0;
    	end
    	tmp_2 = tmp;
    end
    
    x_m = N[Abs[x], $MachinePrecision]
    code[x$95$m_, y_] := If[LessEqual[x$95$m, 7.1e-70], N[Sqrt[N[Abs[y], $MachinePrecision]], $MachinePrecision], N[(x$95$m * 1.0), $MachinePrecision]]
    
    \begin{array}{l}
    x_m = \left|x\right|
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x\_m \leq 7.1 \cdot 10^{-70}:\\
    \;\;\;\;\sqrt{\left|y\right|}\\
    
    \mathbf{else}:\\
    \;\;\;\;x\_m \cdot 1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 7.10000000000000056e-70

      1. Initial program 69.4%

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

        \[\leadsto \sqrt{\color{blue}{y}} \]
      3. Step-by-step derivation
        1. Applied rewrites35.0%

          \[\leadsto \sqrt{\color{blue}{y}} \]
        2. Step-by-step derivation
          1. rem-square-sqrtN/A

            \[\leadsto \sqrt{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
          2. sqrt-unprodN/A

            \[\leadsto \sqrt{\color{blue}{\sqrt{y \cdot y}}} \]
          3. rem-sqrt-square-revN/A

            \[\leadsto \sqrt{\color{blue}{\left|y\right|}} \]
          4. lower-fabs.f6436.7

            \[\leadsto \sqrt{\color{blue}{\left|y\right|}} \]
        3. Applied rewrites36.7%

          \[\leadsto \sqrt{\color{blue}{\left|y\right|}} \]

        if 7.10000000000000056e-70 < x

        1. Initial program 69.4%

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

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

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

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

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

            \[\leadsto x \cdot \left(1 + \frac{1}{2} \cdot \frac{y}{\color{blue}{{x}^{2}}}\right) \]
          5. lower-pow.f6467.8

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

          \[\leadsto \color{blue}{x \cdot \left(1 + 0.5 \cdot \frac{y}{{x}^{2}}\right)} \]
        5. Taylor expanded in x around inf

          \[\leadsto x \cdot 1 \]
        6. Step-by-step derivation
          1. Applied rewrites67.5%

            \[\leadsto x \cdot 1 \]
        7. Recombined 2 regimes into one program.
        8. Add Preprocessing

        Alternative 3: 89.3% accurate, 1.1× speedup?

        \[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 7.1 \cdot 10^{-70}:\\ \;\;\;\;\sqrt{y}\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot 1\\ \end{array} \end{array} \]
        x_m = (fabs.f64 x)
        (FPCore (x_m y) :precision binary64 (if (<= x_m 7.1e-70) (sqrt y) (* x_m 1.0)))
        x_m = fabs(x);
        double code(double x_m, double y) {
        	double tmp;
        	if (x_m <= 7.1e-70) {
        		tmp = sqrt(y);
        	} else {
        		tmp = x_m * 1.0;
        	}
        	return tmp;
        }
        
        x_m =     private
        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_m, y)
        use fmin_fmax_functions
            real(8), intent (in) :: x_m
            real(8), intent (in) :: y
            real(8) :: tmp
            if (x_m <= 7.1d-70) then
                tmp = sqrt(y)
            else
                tmp = x_m * 1.0d0
            end if
            code = tmp
        end function
        
        x_m = Math.abs(x);
        public static double code(double x_m, double y) {
        	double tmp;
        	if (x_m <= 7.1e-70) {
        		tmp = Math.sqrt(y);
        	} else {
        		tmp = x_m * 1.0;
        	}
        	return tmp;
        }
        
        x_m = math.fabs(x)
        def code(x_m, y):
        	tmp = 0
        	if x_m <= 7.1e-70:
        		tmp = math.sqrt(y)
        	else:
        		tmp = x_m * 1.0
        	return tmp
        
        x_m = abs(x)
        function code(x_m, y)
        	tmp = 0.0
        	if (x_m <= 7.1e-70)
        		tmp = sqrt(y);
        	else
        		tmp = Float64(x_m * 1.0);
        	end
        	return tmp
        end
        
        x_m = abs(x);
        function tmp_2 = code(x_m, y)
        	tmp = 0.0;
        	if (x_m <= 7.1e-70)
        		tmp = sqrt(y);
        	else
        		tmp = x_m * 1.0;
        	end
        	tmp_2 = tmp;
        end
        
        x_m = N[Abs[x], $MachinePrecision]
        code[x$95$m_, y_] := If[LessEqual[x$95$m, 7.1e-70], N[Sqrt[y], $MachinePrecision], N[(x$95$m * 1.0), $MachinePrecision]]
        
        \begin{array}{l}
        x_m = \left|x\right|
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x\_m \leq 7.1 \cdot 10^{-70}:\\
        \;\;\;\;\sqrt{y}\\
        
        \mathbf{else}:\\
        \;\;\;\;x\_m \cdot 1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < 7.10000000000000056e-70

          1. Initial program 69.4%

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

            \[\leadsto \sqrt{\color{blue}{y}} \]
          3. Step-by-step derivation
            1. Applied rewrites35.0%

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

            if 7.10000000000000056e-70 < x

            1. Initial program 69.4%

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

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

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

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

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

                \[\leadsto x \cdot \left(1 + \frac{1}{2} \cdot \frac{y}{\color{blue}{{x}^{2}}}\right) \]
              5. lower-pow.f6467.8

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

              \[\leadsto \color{blue}{x \cdot \left(1 + 0.5 \cdot \frac{y}{{x}^{2}}\right)} \]
            5. Taylor expanded in x around inf

              \[\leadsto x \cdot 1 \]
            6. Step-by-step derivation
              1. Applied rewrites67.5%

                \[\leadsto x \cdot 1 \]
            7. Recombined 2 regimes into one program.
            8. Add Preprocessing

            Alternative 4: 35.0% accurate, 3.1× speedup?

            \[\begin{array}{l} x_m = \left|x\right| \\ \sqrt{y} \end{array} \]
            x_m = (fabs.f64 x)
            (FPCore (x_m y) :precision binary64 (sqrt y))
            x_m = fabs(x);
            double code(double x_m, double y) {
            	return sqrt(y);
            }
            
            x_m =     private
            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_m, y)
            use fmin_fmax_functions
                real(8), intent (in) :: x_m
                real(8), intent (in) :: y
                code = sqrt(y)
            end function
            
            x_m = Math.abs(x);
            public static double code(double x_m, double y) {
            	return Math.sqrt(y);
            }
            
            x_m = math.fabs(x)
            def code(x_m, y):
            	return math.sqrt(y)
            
            x_m = abs(x)
            function code(x_m, y)
            	return sqrt(y)
            end
            
            x_m = abs(x);
            function tmp = code(x_m, y)
            	tmp = sqrt(y);
            end
            
            x_m = N[Abs[x], $MachinePrecision]
            code[x$95$m_, y_] := N[Sqrt[y], $MachinePrecision]
            
            \begin{array}{l}
            x_m = \left|x\right|
            
            \\
            \sqrt{y}
            \end{array}
            
            Derivation
            1. Initial program 69.4%

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

              \[\leadsto \sqrt{\color{blue}{y}} \]
            3. Step-by-step derivation
              1. Applied rewrites35.0%

                \[\leadsto \sqrt{\color{blue}{y}} \]
              2. Add Preprocessing

              Alternative 5: 1.3% accurate, 4.3× speedup?

              \[\begin{array}{l} x_m = \left|x\right| \\ -x\_m \end{array} \]
              x_m = (fabs.f64 x)
              (FPCore (x_m y) :precision binary64 (- x_m))
              x_m = fabs(x);
              double code(double x_m, double y) {
              	return -x_m;
              }
              
              x_m =     private
              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_m, y)
              use fmin_fmax_functions
                  real(8), intent (in) :: x_m
                  real(8), intent (in) :: y
                  code = -x_m
              end function
              
              x_m = Math.abs(x);
              public static double code(double x_m, double y) {
              	return -x_m;
              }
              
              x_m = math.fabs(x)
              def code(x_m, y):
              	return -x_m
              
              x_m = abs(x)
              function code(x_m, y)
              	return Float64(-x_m)
              end
              
              x_m = abs(x);
              function tmp = code(x_m, y)
              	tmp = -x_m;
              end
              
              x_m = N[Abs[x], $MachinePrecision]
              code[x$95$m_, y_] := (-x$95$m)
              
              \begin{array}{l}
              x_m = \left|x\right|
              
              \\
              -x\_m
              \end{array}
              
              Derivation
              1. Initial program 69.4%

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

                \[\leadsto \color{blue}{-1 \cdot x} \]
              3. Step-by-step derivation
                1. lower-*.f641.3

                  \[\leadsto -1 \cdot \color{blue}{x} \]
              4. Applied rewrites1.3%

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

                  \[\leadsto -1 \cdot \color{blue}{x} \]
                2. metadata-evalN/A

                  \[\leadsto \left(\mathsf{neg}\left(1\right)\right) \cdot x \]
                3. distribute-lft-neg-outN/A

                  \[\leadsto \mathsf{neg}\left(1 \cdot x\right) \]
                4. metadata-evalN/A

                  \[\leadsto \mathsf{neg}\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right) \]
                5. distribute-lft-neg-outN/A

                  \[\leadsto \mathsf{neg}\left(\left(\mathsf{neg}\left(-1 \cdot x\right)\right)\right) \]
                6. mul-1-negN/A

                  \[\leadsto \mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)\right) \]
                7. lower-neg.f64N/A

                  \[\leadsto -\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \]
                8. mul-1-negN/A

                  \[\leadsto -\left(\mathsf{neg}\left(-1 \cdot x\right)\right) \]
                9. *-commutativeN/A

                  \[\leadsto -\left(\mathsf{neg}\left(x \cdot -1\right)\right) \]
                10. distribute-rgt-neg-outN/A

                  \[\leadsto -x \cdot \left(\mathsf{neg}\left(-1\right)\right) \]
                11. metadata-evalN/A

                  \[\leadsto -x \cdot 1 \]
                12. *-rgt-identity1.3

                  \[\leadsto -x \]
              6. Applied rewrites1.3%

                \[\leadsto \color{blue}{-x} \]
              7. Add Preprocessing

              Reproduce

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