A quarter-circle in the lower-left quadrant

Percentage Accurate: 100.0% → 100.0%
Time: 4.3s
Alternatives: 7
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \end{array} \]
(FPCore (x y)
 :precision binary64
 (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
	return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(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 = fmax((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
	return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y):
	return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y)
	return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y))
end
function tmp = code(x, y)
	tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y));
end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
\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 7 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \end{array} \]
(FPCore (x y)
 :precision binary64
 (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
	return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(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 = fmax((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
	return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y):
	return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y)
	return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y))
end
function tmp = code(x, y)
	tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y));
end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
\end{array}

Alternative 1: 100.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \mathsf{max}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right), \mathsf{max}\left(x, y\right)\right) \end{array} \]
(FPCore (x y) :precision binary64 (fmax (fma x x (fma y y -0.5)) (fmax x y)))
double code(double x, double y) {
	return fmax(fma(x, x, fma(y, y, -0.5)), fmax(x, y));
}
function code(x, y)
	return fmax(fma(x, x, fma(y, y, -0.5)), fmax(x, y))
end
code[x_, y_] := N[Max[N[(x * x + N[(y * y + -0.5), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{max}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right), \mathsf{max}\left(x, y\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \mathsf{max}\left(\color{blue}{\left({x}^{2} + {y}^{2}\right) - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
  4. Applied rewrites100.0%

    \[\leadsto \mathsf{max}\left(\color{blue}{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right)}, \mathsf{max}\left(x, y\right)\right) \]
  5. Add Preprocessing

Alternative 2: 99.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \leq 500000000:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, y \cdot y\right), \mathsf{max}\left(x, y\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)) 500000000.0)
   (fmax (fma x x -0.5) (fmax x y))
   (fmax (fma x x (* y y)) (fmax x y))))
double code(double x, double y) {
	double tmp;
	if (fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(x, y)) <= 500000000.0) {
		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
	} else {
		tmp = fmax(fma(x, x, (y * y)), fmax(x, y));
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) <= 500000000.0)
		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
	else
		tmp = fmax(fma(x, x, Float64(y * y)), fmax(x, y));
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], 500000000.0], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(x * x + N[(y * y), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \leq 500000000:\\
\;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y)) < 5e8

    1. Initial program 100.0%

      \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \mathsf{max}\left(\color{blue}{{x}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
    4. Step-by-step derivation
      1. Applied rewrites98.6%

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

      if 5e8 < (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y))

      1. Initial program 100.0%

        \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \mathsf{max}\left(\color{blue}{\left({x}^{2} + {y}^{2}\right) - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
      4. Applied rewrites100.0%

        \[\leadsto \mathsf{max}\left(\color{blue}{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right)}, \mathsf{max}\left(x, y\right)\right) \]
      5. Taylor expanded in y around inf

        \[\leadsto \mathsf{max}\left(\mathsf{fma}\left(x, x, {y}^{2}\right), \mathsf{max}\left(x, y\right)\right) \]
      6. Step-by-step derivation
        1. Applied rewrites99.9%

          \[\leadsto \mathsf{max}\left(\mathsf{fma}\left(x, x, y \cdot y\right), \mathsf{max}\left(x, y\right)\right) \]
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 3: 67.7% accurate, 0.7× speedup?

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

        1. Initial program 100.0%

          \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
        4. Step-by-step derivation
          1. Applied rewrites98.8%

            \[\leadsto \mathsf{max}\left(\color{blue}{\mathsf{fma}\left(y, y, -0.5\right)}, \mathsf{max}\left(x, y\right)\right) \]
          2. Taylor expanded in y around 0

            \[\leadsto \mathsf{max}\left(\frac{-1}{2}, \mathsf{max}\left(x, y\right)\right) \]
          3. Step-by-step derivation
            1. Applied rewrites98.8%

              \[\leadsto \mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right) \]

            if 2 < (fmax.f64 (-.f64 (+.f64 (pow.f64 y #s(literal 2 binary64)) (pow.f64 x #s(literal 2 binary64))) #s(literal 1/2 binary64)) (fmax.f64 x y))

            1. Initial program 100.0%

              \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
            2. Add Preprocessing
            3. Taylor expanded in x around inf

              \[\leadsto \mathsf{max}\left(\color{blue}{{x}^{2}}, \mathsf{max}\left(x, y\right)\right) \]
            4. Step-by-step derivation
              1. Applied rewrites51.8%

                \[\leadsto \mathsf{max}\left(\color{blue}{x \cdot x}, \mathsf{max}\left(x, y\right)\right) \]
            5. Recombined 2 regimes into one program.
            6. Add Preprocessing

            Alternative 4: 90.7% accurate, 1.9× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -22500000 \lor \neg \left(y \leq 1.85 \cdot 10^{+85}\right):\\ \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\ \end{array} \end{array} \]
            (FPCore (x y)
             :precision binary64
             (if (or (<= y -22500000.0) (not (<= y 1.85e+85)))
               (fmax (* y y) (fmax x y))
               (fmax (fma x x -0.5) (fmax x y))))
            double code(double x, double y) {
            	double tmp;
            	if ((y <= -22500000.0) || !(y <= 1.85e+85)) {
            		tmp = fmax((y * y), fmax(x, y));
            	} else {
            		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
            	}
            	return tmp;
            }
            
            function code(x, y)
            	tmp = 0.0
            	if ((y <= -22500000.0) || !(y <= 1.85e+85))
            		tmp = fmax(Float64(y * y), fmax(x, y));
            	else
            		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
            	end
            	return tmp
            end
            
            code[x_, y_] := If[Or[LessEqual[y, -22500000.0], N[Not[LessEqual[y, 1.85e+85]], $MachinePrecision]], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -22500000 \lor \neg \left(y \leq 1.85 \cdot 10^{+85}\right):\\
            \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -2.25e7 or 1.8500000000000001e85 < y

              1. Initial program 100.0%

                \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
              2. Add Preprocessing
              3. Taylor expanded in y around inf

                \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2}}, \mathsf{max}\left(x, y\right)\right) \]
              4. Step-by-step derivation
                1. Applied rewrites88.9%

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

                if -2.25e7 < y < 1.8500000000000001e85

                1. Initial program 100.0%

                  \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                2. Add Preprocessing
                3. Taylor expanded in y around 0

                  \[\leadsto \mathsf{max}\left(\color{blue}{{x}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
                4. Step-by-step derivation
                  1. Applied rewrites94.3%

                    \[\leadsto \mathsf{max}\left(\color{blue}{\mathsf{fma}\left(x, x, -0.5\right)}, \mathsf{max}\left(x, y\right)\right) \]
                5. Recombined 2 regimes into one program.
                6. Final simplification91.9%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -22500000 \lor \neg \left(y \leq 1.85 \cdot 10^{+85}\right):\\ \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\ \end{array} \]
                7. Add Preprocessing

                Alternative 5: 90.7% accurate, 1.9× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.5:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+85}:\\ \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\ \end{array} \end{array} \]
                (FPCore (x y)
                 :precision binary64
                 (if (<= y -1.5)
                   (fmax (fma y y -0.5) (fmax x y))
                   (if (<= y 1.85e+85)
                     (fmax (fma x x -0.5) (fmax x y))
                     (fmax (* y y) (fmax x y)))))
                double code(double x, double y) {
                	double tmp;
                	if (y <= -1.5) {
                		tmp = fmax(fma(y, y, -0.5), fmax(x, y));
                	} else if (y <= 1.85e+85) {
                		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
                	} else {
                		tmp = fmax((y * y), fmax(x, y));
                	}
                	return tmp;
                }
                
                function code(x, y)
                	tmp = 0.0
                	if (y <= -1.5)
                		tmp = fmax(fma(y, y, -0.5), fmax(x, y));
                	elseif (y <= 1.85e+85)
                		tmp = fmax(fma(x, x, -0.5), fmax(x, y));
                	else
                		tmp = fmax(Float64(y * y), fmax(x, y));
                	end
                	return tmp
                end
                
                code[x_, y_] := If[LessEqual[y, -1.5], N[Max[N[(y * y + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], If[LessEqual[y, 1.85e+85], N[Max[N[(x * x + -0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;y \leq -1.5:\\
                \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(y, y, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
                
                \mathbf{elif}\;y \leq 1.85 \cdot 10^{+85}:\\
                \;\;\;\;\mathsf{max}\left(\mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if y < -1.5

                  1. Initial program 100.0%

                    \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                  2. Add Preprocessing
                  3. Taylor expanded in x around 0

                    \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
                  4. Step-by-step derivation
                    1. Applied rewrites84.8%

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

                    if -1.5 < y < 1.8500000000000001e85

                    1. Initial program 100.0%

                      \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in y around 0

                      \[\leadsto \mathsf{max}\left(\color{blue}{{x}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
                    4. Step-by-step derivation
                      1. Applied rewrites94.9%

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

                      if 1.8500000000000001e85 < y

                      1. Initial program 100.0%

                        \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                      2. Add Preprocessing
                      3. Taylor expanded in y around inf

                        \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2}}, \mathsf{max}\left(x, y\right)\right) \]
                      4. Step-by-step derivation
                        1. Applied rewrites93.8%

                          \[\leadsto \mathsf{max}\left(\color{blue}{y \cdot y}, \mathsf{max}\left(x, y\right)\right) \]
                      5. Recombined 3 regimes into one program.
                      6. Add Preprocessing

                      Alternative 6: 81.1% accurate, 1.9× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{+125} \lor \neg \left(x \leq 1.4 \cdot 10^{+45}\right):\\ \;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\ \end{array} \end{array} \]
                      (FPCore (x y)
                       :precision binary64
                       (if (or (<= x -7.5e+125) (not (<= x 1.4e+45)))
                         (fmax (* x x) (fmax x y))
                         (fmax (* y y) (fmax x y))))
                      double code(double x, double y) {
                      	double tmp;
                      	if ((x <= -7.5e+125) || !(x <= 1.4e+45)) {
                      		tmp = fmax((x * x), fmax(x, y));
                      	} else {
                      		tmp = fmax((y * y), fmax(x, y));
                      	}
                      	return tmp;
                      }
                      
                      module fmin_fmax_functions
                          implicit none
                          private
                          public fmax
                          public fmin
                      
                          interface fmax
                              module procedure fmax88
                              module procedure fmax44
                              module procedure fmax84
                              module procedure fmax48
                          end interface
                          interface fmin
                              module procedure fmin88
                              module procedure fmin44
                              module procedure fmin84
                              module procedure fmin48
                          end interface
                      contains
                          real(8) function fmax88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmax44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmax84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmax48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                          end function
                          real(8) function fmin88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmin44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmin84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmin48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                          end function
                      end module
                      
                      real(8) function code(x, y)
                      use fmin_fmax_functions
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          real(8) :: tmp
                          if ((x <= (-7.5d+125)) .or. (.not. (x <= 1.4d+45))) then
                              tmp = fmax((x * x), fmax(x, y))
                          else
                              tmp = fmax((y * y), fmax(x, y))
                          end if
                          code = tmp
                      end function
                      
                      public static double code(double x, double y) {
                      	double tmp;
                      	if ((x <= -7.5e+125) || !(x <= 1.4e+45)) {
                      		tmp = fmax((x * x), fmax(x, y));
                      	} else {
                      		tmp = fmax((y * y), fmax(x, y));
                      	}
                      	return tmp;
                      }
                      
                      def code(x, y):
                      	tmp = 0
                      	if (x <= -7.5e+125) or not (x <= 1.4e+45):
                      		tmp = fmax((x * x), fmax(x, y))
                      	else:
                      		tmp = fmax((y * y), fmax(x, y))
                      	return tmp
                      
                      function code(x, y)
                      	tmp = 0.0
                      	if ((x <= -7.5e+125) || !(x <= 1.4e+45))
                      		tmp = fmax(Float64(x * x), fmax(x, y));
                      	else
                      		tmp = fmax(Float64(y * y), fmax(x, y));
                      	end
                      	return tmp
                      end
                      
                      function tmp_2 = code(x, y)
                      	tmp = 0.0;
                      	if ((x <= -7.5e+125) || ~((x <= 1.4e+45)))
                      		tmp = max((x * x), max(x, y));
                      	else
                      		tmp = max((y * y), max(x, y));
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      code[x_, y_] := If[Or[LessEqual[x, -7.5e+125], N[Not[LessEqual[x, 1.4e+45]], $MachinePrecision]], N[Max[N[(x * x), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision], N[Max[N[(y * y), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;x \leq -7.5 \cdot 10^{+125} \lor \neg \left(x \leq 1.4 \cdot 10^{+45}\right):\\
                      \;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if x < -7.5000000000000006e125 or 1.4e45 < x

                        1. Initial program 100.0%

                          \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                        2. Add Preprocessing
                        3. Taylor expanded in x around inf

                          \[\leadsto \mathsf{max}\left(\color{blue}{{x}^{2}}, \mathsf{max}\left(x, y\right)\right) \]
                        4. Step-by-step derivation
                          1. Applied rewrites90.8%

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

                          if -7.5000000000000006e125 < x < 1.4e45

                          1. Initial program 100.0%

                            \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                          2. Add Preprocessing
                          3. Taylor expanded in y around inf

                            \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2}}, \mathsf{max}\left(x, y\right)\right) \]
                          4. Step-by-step derivation
                            1. Applied rewrites83.1%

                              \[\leadsto \mathsf{max}\left(\color{blue}{y \cdot y}, \mathsf{max}\left(x, y\right)\right) \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification85.8%

                            \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{+125} \lor \neg \left(x \leq 1.4 \cdot 10^{+45}\right):\\ \;\;\;\;\mathsf{max}\left(x \cdot x, \mathsf{max}\left(x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{max}\left(y \cdot y, \mathsf{max}\left(x, y\right)\right)\\ \end{array} \]
                          7. Add Preprocessing

                          Alternative 7: 27.8% accurate, 2.0× speedup?

                          \[\begin{array}{l} \\ \mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right) \end{array} \]
                          (FPCore (x y) :precision binary64 (fmax -0.5 (fmax x y)))
                          double code(double x, double y) {
                          	return fmax(-0.5, fmax(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 = fmax((-0.5d0), fmax(x, y))
                          end function
                          
                          public static double code(double x, double y) {
                          	return fmax(-0.5, fmax(x, y));
                          }
                          
                          def code(x, y):
                          	return fmax(-0.5, fmax(x, y))
                          
                          function code(x, y)
                          	return fmax(-0.5, fmax(x, y))
                          end
                          
                          function tmp = code(x, y)
                          	tmp = max(-0.5, max(x, y));
                          end
                          
                          code[x_, y_] := N[Max[-0.5, N[Max[x, y], $MachinePrecision]], $MachinePrecision]
                          
                          \begin{array}{l}
                          
                          \\
                          \mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right)
                          \end{array}
                          
                          Derivation
                          1. Initial program 100.0%

                            \[\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right) \]
                          2. Add Preprocessing
                          3. Taylor expanded in x around 0

                            \[\leadsto \mathsf{max}\left(\color{blue}{{y}^{2} - \frac{1}{2}}, \mathsf{max}\left(x, y\right)\right) \]
                          4. Step-by-step derivation
                            1. Applied rewrites69.1%

                              \[\leadsto \mathsf{max}\left(\color{blue}{\mathsf{fma}\left(y, y, -0.5\right)}, \mathsf{max}\left(x, y\right)\right) \]
                            2. Taylor expanded in y around 0

                              \[\leadsto \mathsf{max}\left(\frac{-1}{2}, \mathsf{max}\left(x, y\right)\right) \]
                            3. Step-by-step derivation
                              1. Applied rewrites29.2%

                                \[\leadsto \mathsf{max}\left(-0.5, \mathsf{max}\left(x, y\right)\right) \]
                              2. Add Preprocessing

                              Reproduce

                              ?
                              herbie shell --seed 2025020 
                              (FPCore (x y)
                                :name "A quarter-circle in the lower-left quadrant"
                                :precision binary64
                                (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))