Cubic critical

Percentage Accurate: 52.1% → 85.7%
Time: 4.1s
Alternatives: 15
Speedup: 2.2×

Specification

?
\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\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 15 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: 52.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}

Alternative 1: 85.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -5.1e+147)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 2.3e-91)
     (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a))
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.1e+147) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-5.1d+147)) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else if (b <= 2.3d-91) then
        tmp = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.1e+147) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -5.1e+147:
		tmp = ((-2.0 * b) / 3.0) / a
	elif b <= 2.3e-91:
		tmp = (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -5.1e+147)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 2.3e-91)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -5.1e+147)
		tmp = ((-2.0 * b) / 3.0) / a;
	elseif (b <= 2.3e-91)
		tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -5.1e+147], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -5.09999999999999999e147

    1. Initial program 49.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites97.7%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -5.09999999999999999e147 < b < 2.29999999999999996e-91

    1. Initial program 88.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 85.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -5.1e+147)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 2.3e-91)
     (/ (+ (- b) (sqrt (fma (* c a) -3.0 (* b b)))) (* 3.0 a))
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.1e+147) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = (-b + sqrt(fma((c * a), -3.0, (b * b)))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -5.1e+147)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 2.3e-91)
		tmp = Float64(Float64(Float64(-b) + sqrt(fma(Float64(c * a), -3.0, Float64(b * b)))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -5.1e+147], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[((-b) + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -3.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -5.09999999999999999e147

    1. Initial program 49.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites97.7%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -5.09999999999999999e147 < b < 2.29999999999999996e-91

    1. Initial program 88.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites88.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\mathsf{fma}\left(c \cdot a, -3, b \cdot b\right)}}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 85.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -5.1e+147)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 2.3e-91)
     (/ (- (sqrt (fma (* -3.0 a) c (* b b))) b) (* 3.0 a))
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.1e+147) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = (sqrt(fma((-3.0 * a), c, (b * b))) - b) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -5.1e+147)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 2.3e-91)
		tmp = Float64(Float64(sqrt(fma(Float64(-3.0 * a), c, Float64(b * b))) - b) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -5.1e+147], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[(N[Sqrt[N[(N[(-3.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} - b}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -5.09999999999999999e147

    1. Initial program 49.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites97.7%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -5.09999999999999999e147 < b < 2.29999999999999996e-91

    1. Initial program 88.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites88.3%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.1 \cdot 10^{+147}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 80.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\sqrt{\left(c \cdot a\right) \cdot -3}, 0.3333333333333333, -0.3333333333333333 \cdot b\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -8.8e-116)
   (* (- b) (fma (/ c (* b b)) -0.5 (/ 0.6666666666666666 a)))
   (if (<= b 2.3e-91)
     (/
      (fma
       (sqrt (* (* c a) -3.0))
       0.3333333333333333
       (* -0.3333333333333333 b))
      a)
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = -b * fma((c / (b * b)), -0.5, (0.6666666666666666 / a));
	} else if (b <= 2.3e-91) {
		tmp = fma(sqrt(((c * a) * -3.0)), 0.3333333333333333, (-0.3333333333333333 * b)) / a;
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -8.8e-116)
		tmp = Float64(Float64(-b) * fma(Float64(c / Float64(b * b)), -0.5, Float64(0.6666666666666666 / a)));
	elseif (b <= 2.3e-91)
		tmp = Float64(fma(sqrt(Float64(Float64(c * a) * -3.0)), 0.3333333333333333, Float64(-0.3333333333333333 * b)) / a);
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-116], N[((-b) * N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -0.5 + N[(0.6666666666666666 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -3.0), $MachinePrecision]], $MachinePrecision] * 0.3333333333333333 + N[(-0.3333333333333333 * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\
\;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt{\left(c \cdot a\right) \cdot -3}, 0.3333333333333333, -0.3333333333333333 \cdot b\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.8000000000000004e-116

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(b \cdot \left(\frac{-1}{2} \cdot \frac{c}{{b}^{2}} + \frac{2}{3} \cdot \frac{1}{a}\right)\right)} \]
    4. Applied rewrites81.3%

      \[\leadsto \color{blue}{\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)} \]

    if -8.8000000000000004e-116 < b < 2.29999999999999996e-91

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites86.9%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around 0

      \[\leadsto \frac{\color{blue}{\frac{-1}{3} \cdot b + \frac{1}{3} \cdot \left(\sqrt{a \cdot c} \cdot \sqrt{-3}\right)}}{a} \]
    5. Applied rewrites86.3%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt{\left(c \cdot a\right) \cdot -3}, 0.3333333333333333, -0.3333333333333333 \cdot b\right)}}{a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 80.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -8.8e-116)
   (* (- b) (fma (/ c (* b b)) -0.5 (/ 0.6666666666666666 a)))
   (if (<= b 2.3e-91)
     (/ (+ (- b) (sqrt (* -3.0 (* c a)))) (* 3.0 a))
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = -b * fma((c / (b * b)), -0.5, (0.6666666666666666 / a));
	} else if (b <= 2.3e-91) {
		tmp = (-b + sqrt((-3.0 * (c * a)))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -8.8e-116)
		tmp = Float64(Float64(-b) * fma(Float64(c / Float64(b * b)), -0.5, Float64(0.6666666666666666 / a)));
	elseif (b <= 2.3e-91)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(-3.0 * Float64(c * a)))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-116], N[((-b) * N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -0.5 + N[(0.6666666666666666 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[((-b) + N[Sqrt[N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\
\;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.8000000000000004e-116

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(b \cdot \left(\frac{-1}{2} \cdot \frac{c}{{b}^{2}} + \frac{2}{3} \cdot \frac{1}{a}\right)\right)} \]
    4. Applied rewrites81.3%

      \[\leadsto \color{blue}{\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)} \]

    if -8.8000000000000004e-116 < b < 2.29999999999999996e-91

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{-3 \cdot \left(a \cdot c\right)}}}{3 \cdot a} \]
    4. Applied rewrites86.2%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{-3 \cdot \left(c \cdot a\right)}}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 80.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -8.8e-116)
   (* (- b) (fma (/ c (* b b)) -0.5 (/ 0.6666666666666666 a)))
   (if (<= b 2.3e-91) (/ (sqrt (* c (* a -3.0))) (* 3.0 a)) (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = -b * fma((c / (b * b)), -0.5, (0.6666666666666666 / a));
	} else if (b <= 2.3e-91) {
		tmp = sqrt((c * (a * -3.0))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -8.8e-116)
		tmp = Float64(Float64(-b) * fma(Float64(c / Float64(b * b)), -0.5, Float64(0.6666666666666666 / a)));
	elseif (b <= 2.3e-91)
		tmp = Float64(sqrt(Float64(c * Float64(a * -3.0))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-116], N[((-b) * N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -0.5 + N[(0.6666666666666666 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\
\;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.8000000000000004e-116

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(b \cdot \left(\frac{-1}{2} \cdot \frac{c}{{b}^{2}} + \frac{2}{3} \cdot \frac{1}{a}\right)\right)} \]
    4. Applied rewrites81.3%

      \[\leadsto \color{blue}{\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)} \]

    if -8.8000000000000004e-116 < b < 2.29999999999999996e-91

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites87.1%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites86.1%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\left(-b\right) \cdot \mathsf{fma}\left(\frac{c}{b \cdot b}, -0.5, \frac{0.6666666666666666}{a}\right)\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 80.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -8.8e-116)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 2.3e-91) (/ (sqrt (* c (* a -3.0))) (* 3.0 a)) (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = sqrt((c * (a * -3.0))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-8.8d-116)) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else if (b <= 2.3d-91) then
        tmp = sqrt((c * (a * (-3.0d0)))) / (3.0d0 * a)
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = Math.sqrt((c * (a * -3.0))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -8.8e-116:
		tmp = ((-2.0 * b) / 3.0) / a
	elif b <= 2.3e-91:
		tmp = math.sqrt((c * (a * -3.0))) / (3.0 * a)
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -8.8e-116)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 2.3e-91)
		tmp = Float64(sqrt(Float64(c * Float64(a * -3.0))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -8.8e-116)
		tmp = ((-2.0 * b) / 3.0) / a;
	elseif (b <= 2.3e-91)
		tmp = sqrt((c * (a * -3.0))) / (3.0 * a);
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-116], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.8000000000000004e-116

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites72.0%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites81.2%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -8.8000000000000004e-116 < b < 2.29999999999999996e-91

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites87.1%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites86.1%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 80.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -8.8e-116)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 2.3e-91) (/ (sqrt (* -3.0 (* c a))) (* 3.0 a)) (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = sqrt((-3.0 * (c * a))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-8.8d-116)) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else if (b <= 2.3d-91) then
        tmp = sqrt(((-3.0d0) * (c * a))) / (3.0d0 * a)
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -8.8e-116) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 2.3e-91) {
		tmp = Math.sqrt((-3.0 * (c * a))) / (3.0 * a);
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -8.8e-116:
		tmp = ((-2.0 * b) / 3.0) / a
	elif b <= 2.3e-91:
		tmp = math.sqrt((-3.0 * (c * a))) / (3.0 * a)
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -8.8e-116)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 2.3e-91)
		tmp = Float64(sqrt(Float64(-3.0 * Float64(c * a))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -8.8e-116)
		tmp = ((-2.0 * b) / 3.0) / a;
	elseif (b <= 2.3e-91)
		tmp = sqrt((-3.0 * (c * a))) / (3.0 * a);
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-116], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.3e-91], N[(N[Sqrt[N[(-3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.8 \cdot 10^{-116}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.8000000000000004e-116

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites72.0%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites81.2%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -8.8000000000000004e-116 < b < 2.29999999999999996e-91

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    4. Applied rewrites86.0%

      \[\leadsto \frac{\color{blue}{\sqrt{-3 \cdot \left(c \cdot a\right)}}}{3 \cdot a} \]

    if 2.29999999999999996e-91 < b

    1. Initial program 17.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites17.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites19.7%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites88.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites88.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 72.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -4 \cdot 10^{-117}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 3.9 \cdot 10^{-147}:\\ \;\;\;\;\sqrt{\frac{c \cdot -3}{a}} \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -4e-117)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 3.9e-147)
     (* (sqrt (/ (* c -3.0) a)) -0.3333333333333333)
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -4e-117) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 3.9e-147) {
		tmp = sqrt(((c * -3.0) / a)) * -0.3333333333333333;
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-4d-117)) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else if (b <= 3.9d-147) then
        tmp = sqrt(((c * (-3.0d0)) / a)) * (-0.3333333333333333d0)
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -4e-117) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 3.9e-147) {
		tmp = Math.sqrt(((c * -3.0) / a)) * -0.3333333333333333;
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -4e-117:
		tmp = ((-2.0 * b) / 3.0) / a
	elif b <= 3.9e-147:
		tmp = math.sqrt(((c * -3.0) / a)) * -0.3333333333333333
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -4e-117)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 3.9e-147)
		tmp = Float64(sqrt(Float64(Float64(c * -3.0) / a)) * -0.3333333333333333);
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -4e-117)
		tmp = ((-2.0 * b) / 3.0) / a;
	elseif (b <= 3.9e-147)
		tmp = sqrt(((c * -3.0) / a)) * -0.3333333333333333;
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -4e-117], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 3.9e-147], N[(N[Sqrt[N[(N[(c * -3.0), $MachinePrecision] / a), $MachinePrecision]], $MachinePrecision] * -0.3333333333333333), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-117}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 3.9 \cdot 10^{-147}:\\
\;\;\;\;\sqrt{\frac{c \cdot -3}{a}} \cdot -0.3333333333333333\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -4.00000000000000012e-117

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites72.0%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites81.2%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -4.00000000000000012e-117 < b < 3.8999999999999998e-147

    1. Initial program 88.7%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around -inf

      \[\leadsto \color{blue}{\frac{-1}{3} \cdot \left(\sqrt{\frac{c}{a}} \cdot \left(\sqrt{-1} \cdot \sqrt{3}\right)\right)} \]
    4. Applied rewrites40.6%

      \[\leadsto \color{blue}{\sqrt{\frac{c}{a} \cdot -3} \cdot -0.3333333333333333} \]
    5. Applied rewrites40.6%

      \[\leadsto \sqrt{\frac{c \cdot -3}{a}} \cdot -0.3333333333333333 \]

    if 3.8999999999999998e-147 < b

    1. Initial program 20.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites20.9%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites22.6%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites85.1%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites85.1%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 10: 72.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -4 \cdot 10^{-117}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{elif}\;b \leq 3.9 \cdot 10^{-147}:\\ \;\;\;\;\sqrt{\frac{c}{a} \cdot -3} \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -4e-117)
   (/ (/ (* -2.0 b) 3.0) a)
   (if (<= b 3.9e-147)
     (* (sqrt (* (/ c a) -3.0)) -0.3333333333333333)
     (/ (* -0.5 c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -4e-117) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 3.9e-147) {
		tmp = sqrt(((c / a) * -3.0)) * -0.3333333333333333;
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-4d-117)) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else if (b <= 3.9d-147) then
        tmp = sqrt(((c / a) * (-3.0d0))) * (-0.3333333333333333d0)
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -4e-117) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else if (b <= 3.9e-147) {
		tmp = Math.sqrt(((c / a) * -3.0)) * -0.3333333333333333;
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -4e-117:
		tmp = ((-2.0 * b) / 3.0) / a
	elif b <= 3.9e-147:
		tmp = math.sqrt(((c / a) * -3.0)) * -0.3333333333333333
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -4e-117)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	elseif (b <= 3.9e-147)
		tmp = Float64(sqrt(Float64(Float64(c / a) * -3.0)) * -0.3333333333333333);
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -4e-117)
		tmp = ((-2.0 * b) / 3.0) / a;
	elseif (b <= 3.9e-147)
		tmp = sqrt(((c / a) * -3.0)) * -0.3333333333333333;
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -4e-117], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 3.9e-147], N[(N[Sqrt[N[(N[(c / a), $MachinePrecision] * -3.0), $MachinePrecision]], $MachinePrecision] * -0.3333333333333333), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-117}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{elif}\;b \leq 3.9 \cdot 10^{-147}:\\
\;\;\;\;\sqrt{\frac{c}{a} \cdot -3} \cdot -0.3333333333333333\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -4.00000000000000012e-117

    1. Initial program 71.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites72.0%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites81.2%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if -4.00000000000000012e-117 < b < 3.8999999999999998e-147

    1. Initial program 88.7%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around -inf

      \[\leadsto \color{blue}{\frac{-1}{3} \cdot \left(\sqrt{\frac{c}{a}} \cdot \left(\sqrt{-1} \cdot \sqrt{3}\right)\right)} \]
    4. Applied rewrites40.6%

      \[\leadsto \color{blue}{\sqrt{\frac{c}{a} \cdot -3} \cdot -0.3333333333333333} \]

    if 3.8999999999999998e-147 < b

    1. Initial program 20.9%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites20.9%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites22.6%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites85.1%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites85.1%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 11: 68.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 10^{-308}:\\ \;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b 1e-308) (/ (/ (* -2.0 b) 3.0) a) (/ (* -0.5 c) b)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= 1d-308) then
        tmp = (((-2.0d0) * b) / 3.0d0) / a
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = ((-2.0 * b) / 3.0) / a;
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 1e-308:
		tmp = ((-2.0 * b) / 3.0) / a
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 1e-308)
		tmp = Float64(Float64(Float64(-2.0 * b) / 3.0) / a);
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 1e-308)
		tmp = ((-2.0 * b) / 3.0) / a;
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 1e-308], N[(N[(N[(-2.0 * b), $MachinePrecision] / 3.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-308}:\\
\;\;\;\;\frac{\frac{-2 \cdot b}{3}}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


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

    1. Initial program 77.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites77.3%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(-1, b, \sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)}\right)}{3}}{a}} \]
    4. Taylor expanded in b around -inf

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]
    5. Applied rewrites63.3%

      \[\leadsto \frac{\frac{\color{blue}{-2 \cdot b}}{3}}{a} \]

    if 9.9999999999999991e-309 < b

    1. Initial program 29.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites29.6%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites30.9%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites73.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites73.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 68.0% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 10^{-308}:\\ \;\;\;\;\frac{-0.6666666666666666 \cdot b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b 1e-308) (/ (* -0.6666666666666666 b) a) (/ (* -0.5 c) b)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = (-0.6666666666666666 * b) / a;
	} else {
		tmp = (-0.5 * c) / b;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= 1d-308) then
        tmp = ((-0.6666666666666666d0) * b) / a
    else
        tmp = ((-0.5d0) * c) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = (-0.6666666666666666 * b) / a;
	} else {
		tmp = (-0.5 * c) / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 1e-308:
		tmp = (-0.6666666666666666 * b) / a
	else:
		tmp = (-0.5 * c) / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 1e-308)
		tmp = Float64(Float64(-0.6666666666666666 * b) / a);
	else
		tmp = Float64(Float64(-0.5 * c) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 1e-308)
		tmp = (-0.6666666666666666 * b) / a;
	else
		tmp = (-0.5 * c) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 1e-308], N[(N[(-0.6666666666666666 * b), $MachinePrecision] / a), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-308}:\\
\;\;\;\;\frac{-0.6666666666666666 \cdot b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\


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

    1. Initial program 77.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{\frac{-2}{3} \cdot \frac{b}{a}} \]
    4. Applied rewrites63.1%

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
    5. Applied rewrites63.2%

      \[\leadsto \frac{-0.6666666666666666 \cdot b}{\color{blue}{a}} \]

    if 9.9999999999999991e-309 < b

    1. Initial program 29.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Applied rewrites29.6%

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(-3 \cdot a, c, b \cdot b\right)} + \left(-b\right)}}{3 \cdot a} \]
    4. Taylor expanded in a around inf

      \[\leadsto \frac{\color{blue}{\sqrt{a \cdot c} \cdot \sqrt{-3}}}{3 \cdot a} \]
    5. Applied rewrites30.9%

      \[\leadsto \frac{\color{blue}{\sqrt{c \cdot \left(a \cdot -3\right)}}}{3 \cdot a} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    7. Applied rewrites73.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    8. Applied rewrites73.3%

      \[\leadsto \frac{-0.5 \cdot c}{\color{blue}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 68.0% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 10^{-308}:\\ \;\;\;\;\frac{-0.6666666666666666 \cdot b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b 1e-308) (/ (* -0.6666666666666666 b) a) (* (/ c b) -0.5)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = (-0.6666666666666666 * b) / a;
	} else {
		tmp = (c / b) * -0.5;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= 1d-308) then
        tmp = ((-0.6666666666666666d0) * b) / a
    else
        tmp = (c / b) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = (-0.6666666666666666 * b) / a;
	} else {
		tmp = (c / b) * -0.5;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 1e-308:
		tmp = (-0.6666666666666666 * b) / a
	else:
		tmp = (c / b) * -0.5
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 1e-308)
		tmp = Float64(Float64(-0.6666666666666666 * b) / a);
	else
		tmp = Float64(Float64(c / b) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 1e-308)
		tmp = (-0.6666666666666666 * b) / a;
	else
		tmp = (c / b) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 1e-308], N[(N[(-0.6666666666666666 * b), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-308}:\\
\;\;\;\;\frac{-0.6666666666666666 \cdot b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\


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

    1. Initial program 77.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{\frac{-2}{3} \cdot \frac{b}{a}} \]
    4. Applied rewrites63.1%

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
    5. Applied rewrites63.2%

      \[\leadsto \frac{-0.6666666666666666 \cdot b}{\color{blue}{a}} \]

    if 9.9999999999999991e-309 < b

    1. Initial program 29.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    4. Applied rewrites73.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 68.0% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 10^{-308}:\\ \;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b 1e-308) (* -0.6666666666666666 (/ b a)) (* (/ c b) -0.5)))
double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = -0.6666666666666666 * (b / a);
	} else {
		tmp = (c / b) * -0.5;
	}
	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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= 1d-308) then
        tmp = (-0.6666666666666666d0) * (b / a)
    else
        tmp = (c / b) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= 1e-308) {
		tmp = -0.6666666666666666 * (b / a);
	} else {
		tmp = (c / b) * -0.5;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= 1e-308:
		tmp = -0.6666666666666666 * (b / a)
	else:
		tmp = (c / b) * -0.5
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= 1e-308)
		tmp = Float64(-0.6666666666666666 * Float64(b / a));
	else
		tmp = Float64(Float64(c / b) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= 1e-308)
		tmp = -0.6666666666666666 * (b / a);
	else
		tmp = (c / b) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, 1e-308], N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-308}:\\
\;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\


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

    1. Initial program 77.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in b around -inf

      \[\leadsto \color{blue}{\frac{-2}{3} \cdot \frac{b}{a}} \]
    4. Applied rewrites63.1%

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]

    if 9.9999999999999991e-309 < b

    1. Initial program 29.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}} \]
    4. Applied rewrites73.3%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 35.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ -0.6666666666666666 \cdot \frac{b}{a} \end{array} \]
(FPCore (a b c) :precision binary64 (* -0.6666666666666666 (/ b a)))
double code(double a, double b, double c) {
	return -0.6666666666666666 * (b / a);
}
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(a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-0.6666666666666666d0) * (b / a)
end function
public static double code(double a, double b, double c) {
	return -0.6666666666666666 * (b / a);
}
def code(a, b, c):
	return -0.6666666666666666 * (b / a)
function code(a, b, c)
	return Float64(-0.6666666666666666 * Float64(b / a))
end
function tmp = code(a, b, c)
	tmp = -0.6666666666666666 * (b / a);
end
code[a_, b_, c_] := N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-0.6666666666666666 \cdot \frac{b}{a}
\end{array}
Derivation
  1. Initial program 54.9%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Add Preprocessing
  3. Taylor expanded in b around -inf

    \[\leadsto \color{blue}{\frac{-2}{3} \cdot \frac{b}{a}} \]
  4. Applied rewrites34.9%

    \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025042 -o generate:proofs
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))