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

Percentage Accurate: 51.7% → 80.4%
Time: 4.2s
Alternatives: 6
Speedup: 5.7×

Specification

?
\[\begin{array}{l} \\ \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} \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}

\\
\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}
\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.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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} \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}

\\
\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}
\end{array}

Alternative 1: 80.4% accurate, 0.6× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)\\ \mathbf{if}\;y\_m \leq 4.3 \cdot 10^{-64}:\\ \;\;\;\;1\\ \mathbf{elif}\;y\_m \leq 6 \cdot 10^{+149}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{t\_0}, x, \left(\frac{y\_m}{t\_0} \cdot y\_m\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m)
 :precision binary64
 (let* ((t_0 (fma (* 4.0 y_m) y_m (* x x))))
   (if (<= y_m 4.3e-64)
     1.0
     (if (<= y_m 6e+149)
       (fma (/ x t_0) x (* (* (/ y_m t_0) y_m) -4.0))
       -1.0))))
y_m = fabs(y);
double code(double x, double y_m) {
	double t_0 = fma((4.0 * y_m), y_m, (x * x));
	double tmp;
	if (y_m <= 4.3e-64) {
		tmp = 1.0;
	} else if (y_m <= 6e+149) {
		tmp = fma((x / t_0), x, (((y_m / t_0) * y_m) * -4.0));
	} else {
		tmp = -1.0;
	}
	return tmp;
}
y_m = abs(y)
function code(x, y_m)
	t_0 = fma(Float64(4.0 * y_m), y_m, Float64(x * x))
	tmp = 0.0
	if (y_m <= 4.3e-64)
		tmp = 1.0;
	elseif (y_m <= 6e+149)
		tmp = fma(Float64(x / t_0), x, Float64(Float64(Float64(y_m / t_0) * y_m) * -4.0));
	else
		tmp = -1.0;
	end
	return tmp
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_] := Block[{t$95$0 = N[(N[(4.0 * y$95$m), $MachinePrecision] * y$95$m + N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$95$m, 4.3e-64], 1.0, If[LessEqual[y$95$m, 6e+149], N[(N[(x / t$95$0), $MachinePrecision] * x + N[(N[(N[(y$95$m / t$95$0), $MachinePrecision] * y$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)\\
\mathbf{if}\;y\_m \leq 4.3 \cdot 10^{-64}:\\
\;\;\;\;1\\

\mathbf{elif}\;y\_m \leq 6 \cdot 10^{+149}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{t\_0}, x, \left(\frac{y\_m}{t\_0} \cdot y\_m\right) \cdot -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 4.29999999999999973e-64

    1. Initial program 51.7%

      \[\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.8%

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

      if 4.29999999999999973e-64 < y < 6.00000000000000007e149

      1. Initial program 51.7%

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

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

      if 6.00000000000000007e149 < y

      1. Initial program 51.7%

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

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

      Alternative 2: 80.2% accurate, 0.8× speedup?

      \[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y\_m \leq 4.5 \cdot 10^{-64}:\\ \;\;\;\;1\\ \mathbf{elif}\;y\_m \leq 1.4 \cdot 10^{+146}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y\_m \cdot y\_m, -4, x \cdot x\right)}{\mathsf{fma}\left(y\_m \cdot y\_m, 4, x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)}, x, 0.25 \cdot -4\right)\\ \end{array} \end{array} \]
      y_m = (fabs.f64 y)
      (FPCore (x y_m)
       :precision binary64
       (if (<= y_m 4.5e-64)
         1.0
         (if (<= y_m 1.4e+146)
           (/ (fma (* y_m y_m) -4.0 (* x x)) (fma (* y_m y_m) 4.0 (* x x)))
           (fma (/ x (fma (* 4.0 y_m) y_m (* x x))) x (* 0.25 -4.0)))))
      y_m = fabs(y);
      double code(double x, double y_m) {
      	double tmp;
      	if (y_m <= 4.5e-64) {
      		tmp = 1.0;
      	} else if (y_m <= 1.4e+146) {
      		tmp = fma((y_m * y_m), -4.0, (x * x)) / fma((y_m * y_m), 4.0, (x * x));
      	} else {
      		tmp = fma((x / fma((4.0 * y_m), y_m, (x * x))), x, (0.25 * -4.0));
      	}
      	return tmp;
      }
      
      y_m = abs(y)
      function code(x, y_m)
      	tmp = 0.0
      	if (y_m <= 4.5e-64)
      		tmp = 1.0;
      	elseif (y_m <= 1.4e+146)
      		tmp = Float64(fma(Float64(y_m * y_m), -4.0, Float64(x * x)) / fma(Float64(y_m * y_m), 4.0, Float64(x * x)));
      	else
      		tmp = fma(Float64(x / fma(Float64(4.0 * y_m), y_m, Float64(x * x))), x, Float64(0.25 * -4.0));
      	end
      	return tmp
      end
      
      y_m = N[Abs[y], $MachinePrecision]
      code[x_, y$95$m_] := If[LessEqual[y$95$m, 4.5e-64], 1.0, If[LessEqual[y$95$m, 1.4e+146], N[(N[(N[(y$95$m * y$95$m), $MachinePrecision] * -4.0 + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(y$95$m * y$95$m), $MachinePrecision] * 4.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(N[(4.0 * y$95$m), $MachinePrecision] * y$95$m + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + N[(0.25 * -4.0), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      y_m = \left|y\right|
      
      \\
      \begin{array}{l}
      \mathbf{if}\;y\_m \leq 4.5 \cdot 10^{-64}:\\
      \;\;\;\;1\\
      
      \mathbf{elif}\;y\_m \leq 1.4 \cdot 10^{+146}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(y\_m \cdot y\_m, -4, x \cdot x\right)}{\mathsf{fma}\left(y\_m \cdot y\_m, 4, x \cdot x\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)}, x, 0.25 \cdot -4\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if y < 4.5000000000000001e-64

        1. Initial program 51.7%

          \[\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.8%

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

          if 4.5000000000000001e-64 < y < 1.4e146

          1. Initial program 51.7%

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

            \[\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{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\color{blue}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \]
            2. lift-*.f64N/A

              \[\leadsto \frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\left(4 \cdot y\right) \cdot y + \color{blue}{x \cdot x}} \]
            3. fp-cancel-sign-sub-invN/A

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

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

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

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

              \[\leadsto \frac{\mathsf{fma}\left(y \cdot y, -4, x \cdot x\right)}{\color{blue}{\left(y \cdot y\right) \cdot 4} - \left(\mathsf{neg}\left(x\right)\right) \cdot x} \]
            8. fp-cancel-sign-sub-invN/A

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

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

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

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

          if 1.4e146 < y

          1. Initial program 51.7%

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

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

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

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

          Alternative 3: 80.2% accurate, 0.8× speedup?

          \[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)\\ \mathbf{if}\;y\_m \leq 4.5 \cdot 10^{-64}:\\ \;\;\;\;1\\ \mathbf{elif}\;y\_m \leq 1.4 \cdot 10^{+146}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y\_m \cdot y\_m\right)\right)}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{t\_0}, x, 0.25 \cdot -4\right)\\ \end{array} \end{array} \]
          y_m = (fabs.f64 y)
          (FPCore (x y_m)
           :precision binary64
           (let* ((t_0 (fma (* 4.0 y_m) y_m (* x x))))
             (if (<= y_m 4.5e-64)
               1.0
               (if (<= y_m 1.4e+146)
                 (/ (fma x x (* -4.0 (* y_m y_m))) t_0)
                 (fma (/ x t_0) x (* 0.25 -4.0))))))
          y_m = fabs(y);
          double code(double x, double y_m) {
          	double t_0 = fma((4.0 * y_m), y_m, (x * x));
          	double tmp;
          	if (y_m <= 4.5e-64) {
          		tmp = 1.0;
          	} else if (y_m <= 1.4e+146) {
          		tmp = fma(x, x, (-4.0 * (y_m * y_m))) / t_0;
          	} else {
          		tmp = fma((x / t_0), x, (0.25 * -4.0));
          	}
          	return tmp;
          }
          
          y_m = abs(y)
          function code(x, y_m)
          	t_0 = fma(Float64(4.0 * y_m), y_m, Float64(x * x))
          	tmp = 0.0
          	if (y_m <= 4.5e-64)
          		tmp = 1.0;
          	elseif (y_m <= 1.4e+146)
          		tmp = Float64(fma(x, x, Float64(-4.0 * Float64(y_m * y_m))) / t_0);
          	else
          		tmp = fma(Float64(x / t_0), x, Float64(0.25 * -4.0));
          	end
          	return tmp
          end
          
          y_m = N[Abs[y], $MachinePrecision]
          code[x_, y$95$m_] := Block[{t$95$0 = N[(N[(4.0 * y$95$m), $MachinePrecision] * y$95$m + N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$95$m, 4.5e-64], 1.0, If[LessEqual[y$95$m, 1.4e+146], N[(N[(x * x + N[(-4.0 * N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(x / t$95$0), $MachinePrecision] * x + N[(0.25 * -4.0), $MachinePrecision]), $MachinePrecision]]]]
          
          \begin{array}{l}
          y_m = \left|y\right|
          
          \\
          \begin{array}{l}
          t_0 := \mathsf{fma}\left(4 \cdot y\_m, y\_m, x \cdot x\right)\\
          \mathbf{if}\;y\_m \leq 4.5 \cdot 10^{-64}:\\
          \;\;\;\;1\\
          
          \mathbf{elif}\;y\_m \leq 1.4 \cdot 10^{+146}:\\
          \;\;\;\;\frac{\mathsf{fma}\left(x, x, -4 \cdot \left(y\_m \cdot y\_m\right)\right)}{t\_0}\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(\frac{x}{t\_0}, x, 0.25 \cdot -4\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if y < 4.5000000000000001e-64

            1. Initial program 51.7%

              \[\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.8%

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

              if 4.5000000000000001e-64 < y < 1.4e146

              1. Initial program 51.7%

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

                \[\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. lift-*.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)} \]
                3. +-commutativeN/A

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

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

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

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

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

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

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

              if 1.4e146 < y

              1. Initial program 51.7%

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

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

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

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

              Alternative 4: 72.8% accurate, 1.0× speedup?

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

                1. Initial program 51.7%

                  \[\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.8%

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

                  if 9.0000000000000007e75 < y

                  1. Initial program 51.7%

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

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

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

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

                  Alternative 5: 72.7% accurate, 5.7× speedup?

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

                    1. Initial program 51.7%

                      \[\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.8%

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

                      if 8.8000000000000002e77 < y

                      1. Initial program 51.7%

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

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

                      Alternative 6: 50.7% accurate, 27.4× speedup?

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

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

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

                        Reproduce

                        ?
                        herbie shell --seed 2025149 
                        (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))))