Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3

Percentage Accurate: 51.2% → 80.7%
Time: 2.9s
Alternatives: 6
Speedup: 4.8×

Specification

?
\[\begin{array}{l} t_0 := \left(y \cdot 4\right) \cdot y\\ \frac{x \cdot x - t\_0}{x \cdot x + t\_0} \end{array} \]
(FPCore (x y)
  :precision binary64
  (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
	double t_0 = (y * 4.0) * y;
	return ((x * x) - t_0) / ((x * x) + t_0);
}
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) :: t_0
    t_0 = (y * 4.0d0) * y
    code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
	double t_0 = (y * 4.0) * y;
	return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y):
	t_0 = (y * 4.0) * y
	return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y)
	t_0 = Float64(Float64(y * 4.0) * y)
	return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
end
function tmp = code(x, y)
	t_0 = (y * 4.0) * y;
	tmp = ((x * x) - t_0) / ((x * x) + t_0);
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t\_0}{x \cdot x + t\_0}
\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 6 alternatives:

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

Initial Program: 51.2% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \left(y \cdot 4\right) \cdot y\\ \frac{x \cdot x - t\_0}{x \cdot x + t\_0} \end{array} \]
(FPCore (x y)
  :precision binary64
  (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
	double t_0 = (y * 4.0) * y;
	return ((x * x) - t_0) / ((x * x) + t_0);
}
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) :: t_0
    t_0 = (y * 4.0d0) * y
    code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
	double t_0 = (y * 4.0) * y;
	return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y):
	t_0 = (y * 4.0) * y
	return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y)
	t_0 = Float64(Float64(y * 4.0) * y)
	return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
end
function tmp = code(x, y)
	t_0 = (y * 4.0) * y;
	tmp = ((x * x) - t_0) / ((x * x) + t_0);
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t\_0}{x \cdot x + t\_0}
\end{array}

Alternative 1: 80.7% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := -4 \cdot \left|y\right|\\ t_1 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\ t_2 := \frac{\left|y\right|}{t\_1}\\ \mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\ \;\;\;\;\mathsf{fma}\left(t\_2, t\_0, \frac{x}{t\_1} \cdot x\right)\\ \mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\ \;\;\;\;\mathsf{fma}\left(t\_2, t\_0, 1\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  (let* ((t_0 (* -4.0 (fabs y)))
       (t_1 (fma (* 4.0 (fabs y)) (fabs y) (* x x)))
       (t_2 (/ (fabs y) t_1)))
  (if (<= (fabs y) 5.5e-147)
    1.0
    (if (<= (fabs y) 9.5e+136)
      (fma t_2 t_0 (* (/ x t_1) x))
      (if (<= (fabs y) 7.5e+145) (fma t_2 t_0 1.0) -1.0)))))
double code(double x, double y) {
	double t_0 = -4.0 * fabs(y);
	double t_1 = fma((4.0 * fabs(y)), fabs(y), (x * x));
	double t_2 = fabs(y) / t_1;
	double tmp;
	if (fabs(y) <= 5.5e-147) {
		tmp = 1.0;
	} else if (fabs(y) <= 9.5e+136) {
		tmp = fma(t_2, t_0, ((x / t_1) * x));
	} else if (fabs(y) <= 7.5e+145) {
		tmp = fma(t_2, t_0, 1.0);
	} else {
		tmp = -1.0;
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(-4.0 * abs(y))
	t_1 = fma(Float64(4.0 * abs(y)), abs(y), Float64(x * x))
	t_2 = Float64(abs(y) / t_1)
	tmp = 0.0
	if (abs(y) <= 5.5e-147)
		tmp = 1.0;
	elseif (abs(y) <= 9.5e+136)
		tmp = fma(t_2, t_0, Float64(Float64(x / t_1) * x));
	elseif (abs(y) <= 7.5e+145)
		tmp = fma(t_2, t_0, 1.0);
	else
		tmp = -1.0;
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(-4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[Abs[y], $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[y], $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[N[Abs[y], $MachinePrecision], 5.5e-147], 1.0, If[LessEqual[N[Abs[y], $MachinePrecision], 9.5e+136], N[(t$95$2 * t$95$0 + N[(N[(x / t$95$1), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[y], $MachinePrecision], 7.5e+145], N[(t$95$2 * t$95$0 + 1.0), $MachinePrecision], -1.0]]]]]]
\begin{array}{l}
t_0 := -4 \cdot \left|y\right|\\
t_1 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\
t_2 := \frac{\left|y\right|}{t\_1}\\
\mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\
\;\;\;\;\mathsf{fma}\left(t\_2, t\_0, \frac{x}{t\_1} \cdot x\right)\\

\mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\
\;\;\;\;\mathsf{fma}\left(t\_2, t\_0, 1\right)\\

\mathbf{else}:\\
\;\;\;\;-1\\


\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 5.5e-147

    1. Initial program 51.2%

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

      \[\leadsto \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites49.5%

        \[\leadsto \color{blue}{1} \]

      if 5.5e-147 < y < 9.4999999999999991e136

      1. Initial program 51.2%

        \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. Applied rewrites52.1%

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

      if 9.4999999999999991e136 < y < 7.5000000000000001e145

      1. Initial program 51.2%

        \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      2. Applied rewrites52.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \frac{x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \cdot x\right)} \]
      3. Taylor expanded in x around inf

        \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]
      4. Step-by-step derivation
        1. Applied rewrites48.0%

          \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]

        if 7.5000000000000001e145 < y

        1. Initial program 51.2%

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

          \[\leadsto \color{blue}{-1} \]
        3. Step-by-step derivation
          1. Applied rewrites50.8%

            \[\leadsto \color{blue}{-1} \]
        4. Recombined 4 regimes into one program.
        5. Add Preprocessing

        Alternative 2: 80.5% accurate, 0.6× speedup?

        \[\begin{array}{l} t_0 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\ \mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\ \;\;\;\;\frac{1}{\frac{t\_0}{\mathsf{fma}\left(\left|y\right| \cdot -4, \left|y\right|, x \cdot x\right)}}\\ \mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left|y\right|}{t\_0}, -4 \cdot \left|y\right|, 1\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
        (FPCore (x y)
          :precision binary64
          (let* ((t_0 (fma (* 4.0 (fabs y)) (fabs y) (* x x))))
          (if (<= (fabs y) 5.5e-147)
            1.0
            (if (<= (fabs y) 9.5e+136)
              (/ 1.0 (/ t_0 (fma (* (fabs y) -4.0) (fabs y) (* x x))))
              (if (<= (fabs y) 7.5e+145)
                (fma (/ (fabs y) t_0) (* -4.0 (fabs y)) 1.0)
                -1.0)))))
        double code(double x, double y) {
        	double t_0 = fma((4.0 * fabs(y)), fabs(y), (x * x));
        	double tmp;
        	if (fabs(y) <= 5.5e-147) {
        		tmp = 1.0;
        	} else if (fabs(y) <= 9.5e+136) {
        		tmp = 1.0 / (t_0 / fma((fabs(y) * -4.0), fabs(y), (x * x)));
        	} else if (fabs(y) <= 7.5e+145) {
        		tmp = fma((fabs(y) / t_0), (-4.0 * fabs(y)), 1.0);
        	} else {
        		tmp = -1.0;
        	}
        	return tmp;
        }
        
        function code(x, y)
        	t_0 = fma(Float64(4.0 * abs(y)), abs(y), Float64(x * x))
        	tmp = 0.0
        	if (abs(y) <= 5.5e-147)
        		tmp = 1.0;
        	elseif (abs(y) <= 9.5e+136)
        		tmp = Float64(1.0 / Float64(t_0 / fma(Float64(abs(y) * -4.0), abs(y), Float64(x * x))));
        	elseif (abs(y) <= 7.5e+145)
        		tmp = fma(Float64(abs(y) / t_0), Float64(-4.0 * abs(y)), 1.0);
        	else
        		tmp = -1.0;
        	end
        	return tmp
        end
        
        code[x_, y_] := Block[{t$95$0 = N[(N[(4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[Abs[y], $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[y], $MachinePrecision], 5.5e-147], 1.0, If[LessEqual[N[Abs[y], $MachinePrecision], 9.5e+136], N[(1.0 / N[(t$95$0 / N[(N[(N[Abs[y], $MachinePrecision] * -4.0), $MachinePrecision] * N[Abs[y], $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[y], $MachinePrecision], 7.5e+145], N[(N[(N[Abs[y], $MachinePrecision] / t$95$0), $MachinePrecision] * N[(-4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], -1.0]]]]
        
        \begin{array}{l}
        t_0 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\
        \mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\
        \;\;\;\;1\\
        
        \mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\
        \;\;\;\;\frac{1}{\frac{t\_0}{\mathsf{fma}\left(\left|y\right| \cdot -4, \left|y\right|, x \cdot x\right)}}\\
        
        \mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\
        \;\;\;\;\mathsf{fma}\left(\frac{\left|y\right|}{t\_0}, -4 \cdot \left|y\right|, 1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;-1\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if y < 5.5e-147

          1. Initial program 51.2%

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

            \[\leadsto \color{blue}{1} \]
          3. Step-by-step derivation
            1. Applied rewrites49.5%

              \[\leadsto \color{blue}{1} \]

            if 5.5e-147 < y < 9.4999999999999991e136

            1. Initial program 51.2%

              \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
            2. Applied rewrites51.1%

              \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}} \]
            3. Step-by-step derivation
              1. lift-fma.f64N/A

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

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

                \[\leadsto \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)} + x \cdot x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
              4. associate-*l*N/A

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

                \[\leadsto \frac{\color{blue}{\left(-4 \cdot y\right)} \cdot y + x \cdot x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
              6. lift-fma.f6451.2%

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-4 \cdot y, y, x \cdot x\right)}}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
            4. Applied rewrites51.2%

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

                \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}} \]
              2. div-flipN/A

                \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(-4 \cdot y, y, x \cdot x\right)}}} \]
              3. lower-unsound-/.f64N/A

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

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

                \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(\color{blue}{-4 \cdot y}, y, x \cdot x\right)}} \]
              6. *-commutativeN/A

                \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(\color{blue}{y \cdot -4}, y, x \cdot x\right)}} \]
              7. lower-*.f6451.2%

                \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(\color{blue}{y \cdot -4}, y, x \cdot x\right)}} \]
            6. Applied rewrites51.2%

              \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}{\mathsf{fma}\left(y \cdot -4, y, x \cdot x\right)}}} \]

            if 9.4999999999999991e136 < y < 7.5000000000000001e145

            1. Initial program 51.2%

              \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
            2. Applied rewrites52.1%

              \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \frac{x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \cdot x\right)} \]
            3. Taylor expanded in x around inf

              \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]
            4. Step-by-step derivation
              1. Applied rewrites48.0%

                \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]

              if 7.5000000000000001e145 < y

              1. Initial program 51.2%

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

                \[\leadsto \color{blue}{-1} \]
              3. Step-by-step derivation
                1. Applied rewrites50.8%

                  \[\leadsto \color{blue}{-1} \]
              4. Recombined 4 regimes into one program.
              5. Add Preprocessing

              Alternative 3: 80.5% accurate, 0.7× speedup?

              \[\begin{array}{l} t_0 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\ t_1 := -4 \cdot \left|y\right|\\ \mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t\_1, \left|y\right|, x \cdot x\right)}{t\_0}\\ \mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left|y\right|}{t\_0}, t\_1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
              (FPCore (x y)
                :precision binary64
                (let* ((t_0 (fma (* 4.0 (fabs y)) (fabs y) (* x x)))
                     (t_1 (* -4.0 (fabs y))))
                (if (<= (fabs y) 5.5e-147)
                  1.0
                  (if (<= (fabs y) 9.5e+136)
                    (/ (fma t_1 (fabs y) (* x x)) t_0)
                    (if (<= (fabs y) 7.5e+145)
                      (fma (/ (fabs y) t_0) t_1 1.0)
                      -1.0)))))
              double code(double x, double y) {
              	double t_0 = fma((4.0 * fabs(y)), fabs(y), (x * x));
              	double t_1 = -4.0 * fabs(y);
              	double tmp;
              	if (fabs(y) <= 5.5e-147) {
              		tmp = 1.0;
              	} else if (fabs(y) <= 9.5e+136) {
              		tmp = fma(t_1, fabs(y), (x * x)) / t_0;
              	} else if (fabs(y) <= 7.5e+145) {
              		tmp = fma((fabs(y) / t_0), t_1, 1.0);
              	} else {
              		tmp = -1.0;
              	}
              	return tmp;
              }
              
              function code(x, y)
              	t_0 = fma(Float64(4.0 * abs(y)), abs(y), Float64(x * x))
              	t_1 = Float64(-4.0 * abs(y))
              	tmp = 0.0
              	if (abs(y) <= 5.5e-147)
              		tmp = 1.0;
              	elseif (abs(y) <= 9.5e+136)
              		tmp = Float64(fma(t_1, abs(y), Float64(x * x)) / t_0);
              	elseif (abs(y) <= 7.5e+145)
              		tmp = fma(Float64(abs(y) / t_0), t_1, 1.0);
              	else
              		tmp = -1.0;
              	end
              	return tmp
              end
              
              code[x_, y_] := Block[{t$95$0 = N[(N[(4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[Abs[y], $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[Abs[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[y], $MachinePrecision], 5.5e-147], 1.0, If[LessEqual[N[Abs[y], $MachinePrecision], 9.5e+136], N[(N[(t$95$1 * N[Abs[y], $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[N[Abs[y], $MachinePrecision], 7.5e+145], N[(N[(N[Abs[y], $MachinePrecision] / t$95$0), $MachinePrecision] * t$95$1 + 1.0), $MachinePrecision], -1.0]]]]]
              
              \begin{array}{l}
              t_0 := \mathsf{fma}\left(4 \cdot \left|y\right|, \left|y\right|, x \cdot x\right)\\
              t_1 := -4 \cdot \left|y\right|\\
              \mathbf{if}\;\left|y\right| \leq 5.5 \cdot 10^{-147}:\\
              \;\;\;\;1\\
              
              \mathbf{elif}\;\left|y\right| \leq 9.5 \cdot 10^{+136}:\\
              \;\;\;\;\frac{\mathsf{fma}\left(t\_1, \left|y\right|, x \cdot x\right)}{t\_0}\\
              
              \mathbf{elif}\;\left|y\right| \leq 7.5 \cdot 10^{+145}:\\
              \;\;\;\;\mathsf{fma}\left(\frac{\left|y\right|}{t\_0}, t\_1, 1\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;-1\\
              
              
              \end{array}
              
              Derivation
              1. Split input into 4 regimes
              2. if y < 5.5e-147

                1. Initial program 51.2%

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

                  \[\leadsto \color{blue}{1} \]
                3. Step-by-step derivation
                  1. Applied rewrites49.5%

                    \[\leadsto \color{blue}{1} \]

                  if 5.5e-147 < y < 9.4999999999999991e136

                  1. Initial program 51.2%

                    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
                  2. Applied rewrites51.1%

                    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}} \]
                  3. Step-by-step derivation
                    1. lift-fma.f64N/A

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

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

                      \[\leadsto \frac{-4 \cdot \color{blue}{\left(y \cdot y\right)} + x \cdot x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
                    4. associate-*l*N/A

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

                      \[\leadsto \frac{\color{blue}{\left(-4 \cdot y\right)} \cdot y + x \cdot x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
                    6. lift-fma.f6451.2%

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-4 \cdot y, y, x \cdot x\right)}}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \]
                  4. Applied rewrites51.2%

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

                  if 9.4999999999999991e136 < y < 7.5000000000000001e145

                  1. Initial program 51.2%

                    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
                  2. Applied rewrites52.1%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \frac{x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \cdot x\right)} \]
                  3. Taylor expanded in x around inf

                    \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]
                  4. Step-by-step derivation
                    1. Applied rewrites48.0%

                      \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]

                    if 7.5000000000000001e145 < y

                    1. Initial program 51.2%

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

                      \[\leadsto \color{blue}{-1} \]
                    3. Step-by-step derivation
                      1. Applied rewrites50.8%

                        \[\leadsto \color{blue}{-1} \]
                    4. Recombined 4 regimes into one program.
                    5. Add Preprocessing

                    Alternative 4: 74.6% accurate, 0.9× speedup?

                    \[\begin{array}{l} \mathbf{if}\;\left|x\right| \leq 2.9 \cdot 10^{+41}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, \left|x\right| \cdot \left|x\right|\right)}, -4 \cdot y, 1\right)\\ \end{array} \]
                    (FPCore (x y)
                      :precision binary64
                      (if (<= (fabs x) 2.9e+41)
                      -1.0
                      (fma (/ y (fma (* 4.0 y) y (* (fabs x) (fabs x)))) (* -4.0 y) 1.0)))
                    double code(double x, double y) {
                    	double tmp;
                    	if (fabs(x) <= 2.9e+41) {
                    		tmp = -1.0;
                    	} else {
                    		tmp = fma((y / fma((4.0 * y), y, (fabs(x) * fabs(x)))), (-4.0 * y), 1.0);
                    	}
                    	return tmp;
                    }
                    
                    function code(x, y)
                    	tmp = 0.0
                    	if (abs(x) <= 2.9e+41)
                    		tmp = -1.0;
                    	else
                    		tmp = fma(Float64(y / fma(Float64(4.0 * y), y, Float64(abs(x) * abs(x)))), Float64(-4.0 * y), 1.0);
                    	end
                    	return tmp
                    end
                    
                    code[x_, y_] := If[LessEqual[N[Abs[x], $MachinePrecision], 2.9e+41], -1.0, N[(N[(y / N[(N[(4.0 * y), $MachinePrecision] * y + N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-4.0 * y), $MachinePrecision] + 1.0), $MachinePrecision]]
                    
                    \begin{array}{l}
                    \mathbf{if}\;\left|x\right| \leq 2.9 \cdot 10^{+41}:\\
                    \;\;\;\;-1\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, \left|x\right| \cdot \left|x\right|\right)}, -4 \cdot y, 1\right)\\
                    
                    
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if x < 2.8999999999999999e41

                      1. Initial program 51.2%

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

                        \[\leadsto \color{blue}{-1} \]
                      3. Step-by-step derivation
                        1. Applied rewrites50.8%

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

                        if 2.8999999999999999e41 < x

                        1. Initial program 51.2%

                          \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
                        2. Applied rewrites52.1%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \frac{x}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)} \cdot x\right)} \]
                        3. Taylor expanded in x around inf

                          \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(4 \cdot y, y, x \cdot x\right)}, -4 \cdot y, \color{blue}{1}\right) \]
                        4. Step-by-step derivation
                          1. Applied rewrites48.0%

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

                        Alternative 5: 74.5% accurate, 4.8× speedup?

                        \[\begin{array}{l} \mathbf{if}\;\left|x\right| \leq 2 \cdot 10^{+41}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
                        (FPCore (x y)
                          :precision binary64
                          (if (<= (fabs x) 2e+41) -1.0 1.0))
                        double code(double x, double y) {
                        	double tmp;
                        	if (fabs(x) <= 2e+41) {
                        		tmp = -1.0;
                        	} else {
                        		tmp = 1.0;
                        	}
                        	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 (abs(x) <= 2d+41) then
                                tmp = -1.0d0
                            else
                                tmp = 1.0d0
                            end if
                            code = tmp
                        end function
                        
                        public static double code(double x, double y) {
                        	double tmp;
                        	if (Math.abs(x) <= 2e+41) {
                        		tmp = -1.0;
                        	} else {
                        		tmp = 1.0;
                        	}
                        	return tmp;
                        }
                        
                        def code(x, y):
                        	tmp = 0
                        	if math.fabs(x) <= 2e+41:
                        		tmp = -1.0
                        	else:
                        		tmp = 1.0
                        	return tmp
                        
                        function code(x, y)
                        	tmp = 0.0
                        	if (abs(x) <= 2e+41)
                        		tmp = -1.0;
                        	else
                        		tmp = 1.0;
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(x, y)
                        	tmp = 0.0;
                        	if (abs(x) <= 2e+41)
                        		tmp = -1.0;
                        	else
                        		tmp = 1.0;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[x_, y_] := If[LessEqual[N[Abs[x], $MachinePrecision], 2e+41], -1.0, 1.0]
                        
                        \begin{array}{l}
                        \mathbf{if}\;\left|x\right| \leq 2 \cdot 10^{+41}:\\
                        \;\;\;\;-1\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;1\\
                        
                        
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if x < 2e41

                          1. Initial program 51.2%

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

                            \[\leadsto \color{blue}{-1} \]
                          3. Step-by-step derivation
                            1. Applied rewrites50.8%

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

                            if 2e41 < x

                            1. Initial program 51.2%

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

                              \[\leadsto \color{blue}{1} \]
                            3. Step-by-step derivation
                              1. Applied rewrites49.5%

                                \[\leadsto \color{blue}{1} \]
                            4. Recombined 2 regimes into one program.
                            5. Add Preprocessing

                            Alternative 6: 50.8% accurate, 28.0× speedup?

                            \[-1 \]
                            (FPCore (x y)
                              :precision binary64
                              -1.0)
                            double code(double x, double y) {
                            	return -1.0;
                            }
                            
                            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 = -1.0d0
                            end function
                            
                            public static double code(double x, double y) {
                            	return -1.0;
                            }
                            
                            def code(x, y):
                            	return -1.0
                            
                            function code(x, y)
                            	return -1.0
                            end
                            
                            function tmp = code(x, y)
                            	tmp = -1.0;
                            end
                            
                            code[x_, y_] := -1.0
                            
                            -1
                            
                            Derivation
                            1. Initial program 51.2%

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

                              \[\leadsto \color{blue}{-1} \]
                            3. Step-by-step derivation
                              1. Applied rewrites50.8%

                                \[\leadsto \color{blue}{-1} \]
                              2. Add Preprocessing

                              Reproduce

                              ?
                              herbie shell --seed 2025212 
                              (FPCore (x y)
                                :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
                                :precision binary64
                                (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))