(sqrt (- (* z0 z0) (* (* z1 4) z2)))

Percentage Accurate: 60.6% → 94.2%
Time: 14.1s
Alternatives: 3
Speedup: 1.0×

Specification

?
\[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (sqrt (- (* z0 z0) (* (* z1 4) z2))))
double code(double z0, double z1, double z2) {
	return sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = sqrt(((z0 * z0) - ((z1 * 4.0d0) * z2)))
end function
public static double code(double z0, double z1, double z2) {
	return Math.sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
}
def code(z0, z1, z2):
	return math.sqrt(((z0 * z0) - ((z1 * 4.0) * z2)))
function code(z0, z1, z2)
	return sqrt(Float64(Float64(z0 * z0) - Float64(Float64(z1 * 4.0) * z2)))
end
function tmp = code(z0, z1, z2)
	tmp = sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
end
code[z0_, z1_, z2_] := N[Sqrt[N[(N[(z0 * z0), $MachinePrecision] - N[(N[(z1 * 4), $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}

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 3 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: 60.6% accurate, 1.0× speedup?

\[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (sqrt (- (* z0 z0) (* (* z1 4) z2))))
double code(double z0, double z1, double z2) {
	return sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
}
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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    code = sqrt(((z0 * z0) - ((z1 * 4.0d0) * z2)))
end function
public static double code(double z0, double z1, double z2) {
	return Math.sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
}
def code(z0, z1, z2):
	return math.sqrt(((z0 * z0) - ((z1 * 4.0) * z2)))
function code(z0, z1, z2)
	return sqrt(Float64(Float64(z0 * z0) - Float64(Float64(z1 * 4.0) * z2)))
end
function tmp = code(z0, z1, z2)
	tmp = sqrt(((z0 * z0) - ((z1 * 4.0) * z2)));
end
code[z0_, z1_, z2_] := N[Sqrt[N[(N[(z0 * z0), $MachinePrecision] - N[(N[(z1 * 4), $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}

Alternative 1: 94.2% accurate, 0.0× speedup?

\[\begin{array}{l} t_0 := \left|z0\right| \cdot \left|z0\right|\\ t_1 := \sqrt{t\_0 - \left(\mathsf{min}\left(z1, z2\right) \cdot 4\right) \cdot \mathsf{max}\left(z1, z2\right)}\\ \mathbf{if}\;t\_1 \leq \frac{3019169939857233}{30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808}:\\ \;\;\;\;\sqrt{\left|z0\right| - \left(\frac{\mathsf{min}\left(z1, z2\right)}{\left|z0\right|} \cdot \mathsf{max}\left(z1, z2\right)\right) \cdot 4} \cdot \sqrt{\left|z0\right|}\\ \mathbf{elif}\;t\_1 \leq 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - 4 \cdot \left(\frac{\mathsf{min}\left(z1, z2\right)}{t\_0} \cdot \mathsf{max}\left(z1, z2\right)\right)} \cdot \left|\left|z0\right|\right|\\ \end{array} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (let* ((t_0 (* (fabs z0) (fabs z0)))
       (t_1 (sqrt (- t_0 (* (* (fmin z1 z2) 4) (fmax z1 z2))))))
  (if (<=
       t_1
       3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808)
    (*
     (sqrt
      (- (fabs z0) (* (* (/ (fmin z1 z2) (fabs z0)) (fmax z1 z2)) 4)))
     (sqrt (fabs z0)))
    (if (<=
         t_1
         20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968)
      t_1
      (*
       (sqrt (- 1 (* 4 (* (/ (fmin z1 z2) t_0) (fmax z1 z2)))))
       (fabs (fabs z0)))))))
double code(double z0, double z1, double z2) {
	double t_0 = fabs(z0) * fabs(z0);
	double t_1 = sqrt((t_0 - ((fmin(z1, z2) * 4.0) * fmax(z1, z2))));
	double tmp;
	if (t_1 <= 1e-154) {
		tmp = sqrt((fabs(z0) - (((fmin(z1, z2) / fabs(z0)) * fmax(z1, z2)) * 4.0))) * sqrt(fabs(z0));
	} else if (t_1 <= 2e+148) {
		tmp = t_1;
	} else {
		tmp = sqrt((1.0 - (4.0 * ((fmin(z1, z2) / t_0) * fmax(z1, z2))))) * fabs(fabs(z0));
	}
	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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = abs(z0) * abs(z0)
    t_1 = sqrt((t_0 - ((fmin(z1, z2) * 4.0d0) * fmax(z1, z2))))
    if (t_1 <= 1d-154) then
        tmp = sqrt((abs(z0) - (((fmin(z1, z2) / abs(z0)) * fmax(z1, z2)) * 4.0d0))) * sqrt(abs(z0))
    else if (t_1 <= 2d+148) then
        tmp = t_1
    else
        tmp = sqrt((1.0d0 - (4.0d0 * ((fmin(z1, z2) / t_0) * fmax(z1, z2))))) * abs(abs(z0))
    end if
    code = tmp
end function
public static double code(double z0, double z1, double z2) {
	double t_0 = Math.abs(z0) * Math.abs(z0);
	double t_1 = Math.sqrt((t_0 - ((fmin(z1, z2) * 4.0) * fmax(z1, z2))));
	double tmp;
	if (t_1 <= 1e-154) {
		tmp = Math.sqrt((Math.abs(z0) - (((fmin(z1, z2) / Math.abs(z0)) * fmax(z1, z2)) * 4.0))) * Math.sqrt(Math.abs(z0));
	} else if (t_1 <= 2e+148) {
		tmp = t_1;
	} else {
		tmp = Math.sqrt((1.0 - (4.0 * ((fmin(z1, z2) / t_0) * fmax(z1, z2))))) * Math.abs(Math.abs(z0));
	}
	return tmp;
}
def code(z0, z1, z2):
	t_0 = math.fabs(z0) * math.fabs(z0)
	t_1 = math.sqrt((t_0 - ((fmin(z1, z2) * 4.0) * fmax(z1, z2))))
	tmp = 0
	if t_1 <= 1e-154:
		tmp = math.sqrt((math.fabs(z0) - (((fmin(z1, z2) / math.fabs(z0)) * fmax(z1, z2)) * 4.0))) * math.sqrt(math.fabs(z0))
	elif t_1 <= 2e+148:
		tmp = t_1
	else:
		tmp = math.sqrt((1.0 - (4.0 * ((fmin(z1, z2) / t_0) * fmax(z1, z2))))) * math.fabs(math.fabs(z0))
	return tmp
function code(z0, z1, z2)
	t_0 = Float64(abs(z0) * abs(z0))
	t_1 = sqrt(Float64(t_0 - Float64(Float64(fmin(z1, z2) * 4.0) * fmax(z1, z2))))
	tmp = 0.0
	if (t_1 <= 1e-154)
		tmp = Float64(sqrt(Float64(abs(z0) - Float64(Float64(Float64(fmin(z1, z2) / abs(z0)) * fmax(z1, z2)) * 4.0))) * sqrt(abs(z0)));
	elseif (t_1 <= 2e+148)
		tmp = t_1;
	else
		tmp = Float64(sqrt(Float64(1.0 - Float64(4.0 * Float64(Float64(fmin(z1, z2) / t_0) * fmax(z1, z2))))) * abs(abs(z0)));
	end
	return tmp
end
function tmp_2 = code(z0, z1, z2)
	t_0 = abs(z0) * abs(z0);
	t_1 = sqrt((t_0 - ((min(z1, z2) * 4.0) * max(z1, z2))));
	tmp = 0.0;
	if (t_1 <= 1e-154)
		tmp = sqrt((abs(z0) - (((min(z1, z2) / abs(z0)) * max(z1, z2)) * 4.0))) * sqrt(abs(z0));
	elseif (t_1 <= 2e+148)
		tmp = t_1;
	else
		tmp = sqrt((1.0 - (4.0 * ((min(z1, z2) / t_0) * max(z1, z2))))) * abs(abs(z0));
	end
	tmp_2 = tmp;
end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(t$95$0 - N[(N[(N[Min[z1, z2], $MachinePrecision] * 4), $MachinePrecision] * N[Max[z1, z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, 3019169939857233/30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808], N[(N[Sqrt[N[(N[Abs[z0], $MachinePrecision] - N[(N[(N[(N[Min[z1, z2], $MachinePrecision] / N[Abs[z0], $MachinePrecision]), $MachinePrecision] * N[Max[z1, z2], $MachinePrecision]), $MachinePrecision] * 4), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968], t$95$1, N[(N[Sqrt[N[(1 - N[(4 * N[(N[(N[Min[z1, z2], $MachinePrecision] / t$95$0), $MachinePrecision] * N[Max[z1, z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Abs[N[Abs[z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \left|z0\right|\\
t_1 := \sqrt{t\_0 - \left(\mathsf{min}\left(z1, z2\right) \cdot 4\right) \cdot \mathsf{max}\left(z1, z2\right)}\\
\mathbf{if}\;t\_1 \leq \frac{3019169939857233}{30191699398572330817932436647906151127335369763331523427009650401964993299137190816689013801421270140331747000246110759198164677039398341060491474011461568349195162615808}:\\
\;\;\;\;\sqrt{\left|z0\right| - \left(\frac{\mathsf{min}\left(z1, z2\right)}{\left|z0\right|} \cdot \mathsf{max}\left(z1, z2\right)\right) \cdot 4} \cdot \sqrt{\left|z0\right|}\\

\mathbf{elif}\;t\_1 \leq 20000000000000000979534531503010411591444540070614877774900847491803365271867695123224630584945529275862261293630205535241068658373251704342045523968:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 - 4 \cdot \left(\frac{\mathsf{min}\left(z1, z2\right)}{t\_0} \cdot \mathsf{max}\left(z1, z2\right)\right)} \cdot \left|\left|z0\right|\right|\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 (*.f64 z1 #s(literal 4 binary64)) z2))) < 9.9999999999999997e-155

    1. Initial program 60.6%

      \[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]
    2. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \]
      2. sqrt-fabs-revN/A

        \[\leadsto \color{blue}{\left|\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right|} \]
      3. lift-sqrt.f64N/A

        \[\leadsto \left|\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right| \]
      4. rem-sqrt-square-revN/A

        \[\leadsto \color{blue}{\sqrt{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}} \]
      5. pow1/2N/A

        \[\leadsto \color{blue}{{\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}}} \]
      6. lift-sqrt.f64N/A

        \[\leadsto {\left(\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}} \]
      7. lift-sqrt.f64N/A

        \[\leadsto {\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right)}^{\frac{1}{2}} \]
      8. sqrt-unprodN/A

        \[\leadsto {\color{blue}{\left(\sqrt{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}\right)}}^{\frac{1}{2}} \]
      9. sqrt-pow2N/A

        \[\leadsto \color{blue}{{\left(\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      10. unpow-prod-downN/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      11. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
    3. Applied rewrites60.2%

      \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
    4. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      2. lift--.f64N/A

        \[\leadsto {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    5. Applied rewrites43.9%

      \[\leadsto \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    6. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
      2. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    7. Applied rewrites45.6%

      \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    8. Applied rewrites43.2%

      \[\leadsto \color{blue}{\sqrt{z0 - \left(\frac{z1}{z0} \cdot z2\right) \cdot 4} \cdot \sqrt{z0}} \]

    if 9.9999999999999997e-155 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 (*.f64 z1 #s(literal 4 binary64)) z2))) < 2.0000000000000001e148

    1. Initial program 60.6%

      \[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]

    if 2.0000000000000001e148 < (sqrt.f64 (-.f64 (*.f64 z0 z0) (*.f64 (*.f64 z1 #s(literal 4 binary64)) z2)))

    1. Initial program 60.6%

      \[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]
    2. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \]
      2. sqrt-fabs-revN/A

        \[\leadsto \color{blue}{\left|\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right|} \]
      3. lift-sqrt.f64N/A

        \[\leadsto \left|\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right| \]
      4. rem-sqrt-square-revN/A

        \[\leadsto \color{blue}{\sqrt{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}} \]
      5. pow1/2N/A

        \[\leadsto \color{blue}{{\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}}} \]
      6. lift-sqrt.f64N/A

        \[\leadsto {\left(\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}} \]
      7. lift-sqrt.f64N/A

        \[\leadsto {\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right)}^{\frac{1}{2}} \]
      8. sqrt-unprodN/A

        \[\leadsto {\color{blue}{\left(\sqrt{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}\right)}}^{\frac{1}{2}} \]
      9. sqrt-pow2N/A

        \[\leadsto \color{blue}{{\left(\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      10. unpow-prod-downN/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      11. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
    3. Applied rewrites60.2%

      \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
    4. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      2. lift--.f64N/A

        \[\leadsto {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    5. Applied rewrites43.9%

      \[\leadsto \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    6. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
      2. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    7. Applied rewrites45.6%

      \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    8. Applied rewrites76.4%

      \[\leadsto \color{blue}{\sqrt{1 - 4 \cdot \left(\frac{z1}{z0 \cdot z0} \cdot z2\right)} \cdot \left|z0\right|} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 92.2% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \left|z0\right| \cdot \left|z0\right|\\ \mathbf{if}\;\left|z0\right| \leq 68000000000000000000:\\ \;\;\;\;\sqrt{t\_0 - \left(z1 \cdot 4\right) \cdot z2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - 4 \cdot \left(\frac{z1}{t\_0} \cdot z2\right)} \cdot \left|\left|z0\right|\right|\\ \end{array} \]
(FPCore (z0 z1 z2)
  :precision binary64
  (let* ((t_0 (* (fabs z0) (fabs z0))))
  (if (<= (fabs z0) 68000000000000000000)
    (sqrt (- t_0 (* (* z1 4) z2)))
    (* (sqrt (- 1 (* 4 (* (/ z1 t_0) z2)))) (fabs (fabs z0))))))
double code(double z0, double z1, double z2) {
	double t_0 = fabs(z0) * fabs(z0);
	double tmp;
	if (fabs(z0) <= 6.8e+19) {
		tmp = sqrt((t_0 - ((z1 * 4.0) * z2)));
	} else {
		tmp = sqrt((1.0 - (4.0 * ((z1 / t_0) * z2)))) * fabs(fabs(z0));
	}
	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(z0, z1, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z2
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs(z0) * abs(z0)
    if (abs(z0) <= 6.8d+19) then
        tmp = sqrt((t_0 - ((z1 * 4.0d0) * z2)))
    else
        tmp = sqrt((1.0d0 - (4.0d0 * ((z1 / t_0) * z2)))) * abs(abs(z0))
    end if
    code = tmp
end function
public static double code(double z0, double z1, double z2) {
	double t_0 = Math.abs(z0) * Math.abs(z0);
	double tmp;
	if (Math.abs(z0) <= 6.8e+19) {
		tmp = Math.sqrt((t_0 - ((z1 * 4.0) * z2)));
	} else {
		tmp = Math.sqrt((1.0 - (4.0 * ((z1 / t_0) * z2)))) * Math.abs(Math.abs(z0));
	}
	return tmp;
}
def code(z0, z1, z2):
	t_0 = math.fabs(z0) * math.fabs(z0)
	tmp = 0
	if math.fabs(z0) <= 6.8e+19:
		tmp = math.sqrt((t_0 - ((z1 * 4.0) * z2)))
	else:
		tmp = math.sqrt((1.0 - (4.0 * ((z1 / t_0) * z2)))) * math.fabs(math.fabs(z0))
	return tmp
function code(z0, z1, z2)
	t_0 = Float64(abs(z0) * abs(z0))
	tmp = 0.0
	if (abs(z0) <= 6.8e+19)
		tmp = sqrt(Float64(t_0 - Float64(Float64(z1 * 4.0) * z2)));
	else
		tmp = Float64(sqrt(Float64(1.0 - Float64(4.0 * Float64(Float64(z1 / t_0) * z2)))) * abs(abs(z0)));
	end
	return tmp
end
function tmp_2 = code(z0, z1, z2)
	t_0 = abs(z0) * abs(z0);
	tmp = 0.0;
	if (abs(z0) <= 6.8e+19)
		tmp = sqrt((t_0 - ((z1 * 4.0) * z2)));
	else
		tmp = sqrt((1.0 - (4.0 * ((z1 / t_0) * z2)))) * abs(abs(z0));
	end
	tmp_2 = tmp;
end
code[z0_, z1_, z2_] := Block[{t$95$0 = N[(N[Abs[z0], $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[z0], $MachinePrecision], 68000000000000000000], N[Sqrt[N[(t$95$0 - N[(N[(z1 * 4), $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[Sqrt[N[(1 - N[(4 * N[(N[(z1 / t$95$0), $MachinePrecision] * z2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Abs[N[Abs[z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|z0\right| \cdot \left|z0\right|\\
\mathbf{if}\;\left|z0\right| \leq 68000000000000000000:\\
\;\;\;\;\sqrt{t\_0 - \left(z1 \cdot 4\right) \cdot z2}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 - 4 \cdot \left(\frac{z1}{t\_0} \cdot z2\right)} \cdot \left|\left|z0\right|\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z0 < 6.8e19

    1. Initial program 60.6%

      \[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]

    if 6.8e19 < z0

    1. Initial program 60.6%

      \[\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \]
    2. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \]
      2. sqrt-fabs-revN/A

        \[\leadsto \color{blue}{\left|\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right|} \]
      3. lift-sqrt.f64N/A

        \[\leadsto \left|\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right| \]
      4. rem-sqrt-square-revN/A

        \[\leadsto \color{blue}{\sqrt{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}} \]
      5. pow1/2N/A

        \[\leadsto \color{blue}{{\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}}} \]
      6. lift-sqrt.f64N/A

        \[\leadsto {\left(\color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}} \cdot \sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}\right)}^{\frac{1}{2}} \]
      7. lift-sqrt.f64N/A

        \[\leadsto {\left(\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2} \cdot \color{blue}{\sqrt{z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2}}\right)}^{\frac{1}{2}} \]
      8. sqrt-unprodN/A

        \[\leadsto {\color{blue}{\left(\sqrt{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}\right)}}^{\frac{1}{2}} \]
      9. sqrt-pow2N/A

        \[\leadsto \color{blue}{{\left(\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right) \cdot \left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      10. unpow-prod-downN/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      11. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(z0 \cdot z0 - \left(z1 \cdot 4\right) \cdot z2\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
    3. Applied rewrites60.2%

      \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
    4. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      2. lift--.f64N/A

        \[\leadsto {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    5. Applied rewrites43.9%

      \[\leadsto \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \cdot {\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}} \]
    6. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}^{\frac{1}{4}}} \]
      2. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(z0 \cdot z0 - z2 \cdot \left(4 \cdot z1\right)\right)}}^{\frac{1}{4}} \]
      3. sub-to-mult-revN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\color{blue}{\left(\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right) \cdot \left(z0 \cdot z0\right)\right)}}^{\frac{1}{4}} \]
      4. lift-/.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\left(1 - \color{blue}{\frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}}\right) \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      5. lift--.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot {\left(\color{blue}{\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)} \cdot \left(z0 \cdot z0\right)\right)}^{\frac{1}{4}} \]
      6. unpow-prod-downN/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
      7. lower-unsound-*.f64N/A

        \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(1 - \frac{z2 \cdot \left(4 \cdot z1\right)}{z0 \cdot z0}\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    7. Applied rewrites45.6%

      \[\leadsto \left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right) \cdot \color{blue}{\left({\left(\left(-4 \cdot z2\right) \cdot \frac{z1}{z0 \cdot z0} - -1\right)}^{\frac{1}{4}} \cdot {\left(z0 \cdot z0\right)}^{\frac{1}{4}}\right)} \]
    8. Applied rewrites76.4%

      \[\leadsto \color{blue}{\sqrt{1 - 4 \cdot \left(\frac{z1}{z0 \cdot z0} \cdot z2\right)} \cdot \left|z0\right|} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z2)
  :name "(sqrt (- (* z0 z0) (* (* z1 4) z2)))"
  :precision binary64
  (sqrt (- (* z0 z0) (* (* z1 4) z2))))