
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_0}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_0}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b)))
(t_1 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b -1.35e-264)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) t_1)))
(if (<= b 2e+100)
(if (>= b 0.0)
(/ (+ b t_1) (* (- 2.0) a))
(- (sqrt (* (/ c a) -1.0))))
(if (>= b 0.0) t_0 (- (- (sqrt (/ (- c) a))))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double t_1 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= -1.35e-264) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_0;
} else {
tmp_3 = (2.0 * c) / (-b + t_1);
}
tmp_1 = tmp_3;
} else if (b <= 2e+100) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (b + t_1) / (-2.0 * a);
} else {
tmp_4 = -sqrt(((c / a) * -1.0));
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -(-sqrt((-c / a)));
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) t_1 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= -1.35e-264) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_0; else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_1)); end tmp_1 = tmp_3; elseif (b <= 2e+100) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(b + t_1) / Float64(Float64(-2.0) * a)); else tmp_4 = Float64(-sqrt(Float64(Float64(c / a) * -1.0))); end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, -1.35e-264], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$1), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2e+100], If[GreaterEqual[b, 0.0], N[(N[(b + t$95$1), $MachinePrecision] / N[((-2.0) * a), $MachinePrecision]), $MachinePrecision], (-N[Sqrt[N[(N[(c / a), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision])], If[GreaterEqual[b, 0.0], t$95$0, (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
t_1 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq -1.35 \cdot 10^{-264}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_1}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+100}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b + t\_1}{\left(-2\right) \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt{\frac{c}{a} \cdot -1}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\left(-\sqrt{\frac{-c}{a}}\right)\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < -1.34999999999999997e-264Initial program 87.8%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6487.8
Applied rewrites87.8%
if -1.34999999999999997e-264 < b < 2.00000000000000003e100Initial program 85.5%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6486.9
Applied rewrites86.9%
if 2.00000000000000003e100 < b Initial program 51.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.8
Applied rewrites92.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6492.8
Applied rewrites92.8%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6492.8
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6492.8
Applied rewrites92.8%
Final simplification89.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b)))
(t_1 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b 2e+100)
(if (>= b 0.0) (/ (+ b t_1) (* (- 2.0) a)) (/ (* 2.0 c) (+ (- b) t_1)))
(if (>= b 0.0) t_0 (- (- (sqrt (/ (- c) a)))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double t_1 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= 2e+100) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (b + t_1) / (-2.0 * a);
} else {
tmp_3 = (2.0 * c) / (-b + t_1);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -(-sqrt((-c / a)));
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) t_1 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= 2e+100) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(b + t_1) / Float64(Float64(-2.0) * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_1)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2e+100], If[GreaterEqual[b, 0.0], N[(N[(b + t$95$1), $MachinePrecision] / N[((-2.0) * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$1), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
t_1 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+100}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b + t\_1}{\left(-2\right) \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_1}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\left(-\sqrt{\frac{-c}{a}}\right)\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < 2.00000000000000003e100Initial program 86.7%
if 2.00000000000000003e100 < b Initial program 51.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.8
Applied rewrites92.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6492.8
Applied rewrites92.8%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6492.8
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6492.8
Applied rewrites92.8%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (- (sqrt (/ (- c) a)))))
(t_1 (sqrt (- (* b b) (* (* 4.0 a) c))))
(t_2 (fma (/ b a) -1.0 (/ c b))))
(if (<= b -1e+118)
(if (>= b 0.0) t_2 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b 2.3e-301)
(if (>= b 0.0)
(/ (* (- (/ b c) (* (sqrt (* (/ a c) -1.0)) 2.0)) (- c)) (* 2.0 a))
(/ (* 2.0 c) (+ (- b) t_1)))
(if (<= b 2e+100)
(if (>= b 0.0) (/ (+ b t_1) (* (- 2.0) a)) t_0)
(if (>= b 0.0) t_2 t_0))))))
double code(double a, double b, double c) {
double t_0 = -(-sqrt((-c / a)));
double t_1 = sqrt(((b * b) - ((4.0 * a) * c)));
double t_2 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_2;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= 2.3e-301) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (((b / c) - (sqrt(((a / c) * -1.0)) * 2.0)) * -c) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (-b + t_1);
}
tmp_1 = tmp_3;
} else if (b <= 2e+100) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (b + t_1) / (-2.0 * a);
} else {
tmp_4 = t_0;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = t_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))) t_1 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) t_2 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_2; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= 2.3e-301) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(Float64(b / c) - Float64(sqrt(Float64(Float64(a / c) * -1.0)) * 2.0)) * Float64(-c)) / Float64(2.0 * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_1)); end tmp_1 = tmp_3; elseif (b <= 2e+100) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(b + t_1) / Float64(Float64(-2.0) * a)); else tmp_4 = t_0; end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = t_2; else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.3e-301], If[GreaterEqual[b, 0.0], N[(N[(N[(N[(b / c), $MachinePrecision] - N[(N[Sqrt[N[(N[(a / c), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * (-c)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$1), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2e+100], If[GreaterEqual[b, 0.0], N[(N[(b + t$95$1), $MachinePrecision] / N[((-2.0) * a), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], t$95$2, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\left(-\sqrt{\frac{-c}{a}}\right)\\
t_1 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
t_2 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-301}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(\frac{b}{c} - \sqrt{\frac{a}{c} \cdot -1} \cdot 2\right) \cdot \left(-c\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_1}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+100}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b + t\_1}{\left(-2\right) \cdot a}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < 2.3000000000000002e-301Initial program 87.1%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6487.1
Applied rewrites87.1%
if 2.3000000000000002e-301 < b < 2.00000000000000003e100Initial program 86.1%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6486.1
Applied rewrites86.1%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6486.1
Applied rewrites86.1%
if 2.00000000000000003e100 < b Initial program 51.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.8
Applied rewrites92.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6492.8
Applied rewrites92.8%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6492.8
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6492.8
Applied rewrites92.8%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b 4.8e-93)
(if (>= b 0.0)
(/
(*
(*
(- (/ (/ b a) c) (* (sqrt (* (pow (* c a) -1.0) -1.0)) 2.0))
(- c))
a)
(* 2.0 a))
(/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))))
(if (>= b 0.0) t_0 (- (- (sqrt (/ (- c) a)))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= 4.8e-93) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (((((b / a) / c) - (sqrt((pow((c * a), -1.0) * -1.0)) * 2.0)) * -c) * a) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -(-sqrt((-c / a)));
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= 4.8e-93) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(Float64(Float64(Float64(b / a) / c) - Float64(sqrt(Float64((Float64(c * a) ^ -1.0) * -1.0)) * 2.0)) * Float64(-c)) * a) / Float64(2.0 * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4.8e-93], If[GreaterEqual[b, 0.0], N[(N[(N[(N[(N[(N[(b / a), $MachinePrecision] / c), $MachinePrecision] - N[(N[Sqrt[N[(N[Power[N[(c * a), $MachinePrecision], -1.0], $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * (-c)), $MachinePrecision] * a), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-93}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(\left(\frac{\frac{b}{a}}{c} - \sqrt{{\left(c \cdot a\right)}^{-1} \cdot -1} \cdot 2\right) \cdot \left(-c\right)\right) \cdot a}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\left(-\sqrt{\frac{-c}{a}}\right)\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < 4.8000000000000002e-93Initial program 87.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6476.6
Applied rewrites76.6%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.2%
if 4.8000000000000002e-93 < b Initial program 63.5%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6483.8
Applied rewrites83.8%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6483.8
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6483.8
Applied rewrites83.8%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b 1.15e-140)
(if (>= b 0.0)
(/ (* (- (/ b c) (* (sqrt (* (/ a c) -1.0)) 2.0)) (- c)) (* 2.0 a))
(/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))))
(if (>= b 0.0)
t_0
(/ (* 2.0 c) (* (fma (sqrt (/ (- c) a)) 2.0 (/ b a)) (- a))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= 1.15e-140) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (((b / c) - (sqrt(((a / c) * -1.0)) * 2.0)) * -c) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (2.0 * c) / (fma(sqrt((-c / a)), 2.0, (b / a)) * -a);
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= 1.15e-140) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(Float64(b / c) - Float64(sqrt(Float64(Float64(a / c) * -1.0)) * 2.0)) * Float64(-c)) / Float64(2.0 * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(2.0 * c) / Float64(fma(sqrt(Float64(Float64(-c) / a)), 2.0, Float64(b / a)) * Float64(-a))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.15e-140], If[GreaterEqual[b, 0.0], N[(N[(N[(N[(b / c), $MachinePrecision] - N[(N[Sqrt[N[(N[(a / c), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * (-c)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[(N[(N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision] * 2.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-140}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(\frac{b}{c} - \sqrt{\frac{a}{c} \cdot -1} \cdot 2\right) \cdot \left(-c\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{\frac{-c}{a}}, 2, \frac{b}{a}\right) \cdot \left(-a\right)}\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < 1.1500000000000001e-140Initial program 88.5%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6480.0
Applied rewrites80.0%
if 1.1500000000000001e-140 < b Initial program 64.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f64N/A
lift-/.f6480.6
Applied rewrites80.6%
Final simplification82.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (<= b 4.5e-205)
(if (>= b 0.0)
(/ (* (- (/ b a) (* (sqrt (* (/ c a) -1.0)) 2.0)) (- a)) (* 2.0 a))
(/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))))
(if (>= b 0.0) t_0 (- (- (sqrt (/ (- c) a)))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b <= 4.5e-205) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (((b / a) - (sqrt(((c / a) * -1.0)) * 2.0)) * -a) / (2.0 * a);
} else {
tmp_3 = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -(-sqrt((-c / a)));
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b <= 4.5e-205) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(Float64(b / a) - Float64(sqrt(Float64(Float64(c / a) * -1.0)) * 2.0)) * Float64(-a)) / Float64(2.0 * a)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4.5e-205], If[GreaterEqual[b, 0.0], N[(N[(N[(N[(b / a), $MachinePrecision] - N[(N[Sqrt[N[(N[(c / a), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-205}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(\frac{b}{a} - \sqrt{\frac{c}{a} \cdot -1} \cdot 2\right) \cdot \left(-a\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-\left(-\sqrt{\frac{-c}{a}}\right)\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b < 4.49999999999999956e-205Initial program 88.6%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if 4.49999999999999956e-205 < b Initial program 65.6%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6475.6
Applied rewrites75.6%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6475.6
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6475.6
Applied rewrites75.6%
Final simplification80.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b))))
(if (<= b -1e+118)
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b))))
(if (>= b 0.0)
t_0
(/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (b <= -1e+118) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (-b + -b);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (b <= -1e+118) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+118], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -1 \cdot 10^{+118}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\end{array}
if b < -9.99999999999999967e117Initial program 40.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6440.4
Applied rewrites40.4%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6490.9
Applied rewrites90.9%
if -9.99999999999999967e117 < b Initial program 75.0%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (/ b a) -1.0 (/ c b))))
(if (<= a -1.8e+129)
(if (>= b 0.0)
t_0
(/ (* 2.0 c) (* (fma (sqrt (/ (- c) a)) 2.0 (/ b a)) (- a))))
(if (>= b 0.0) t_0 (/ (* 2.0 c) (+ (- b) (- b)))))))
double code(double a, double b, double c) {
double t_0 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (a <= -1.8e+129) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (2.0 * c) / (fma(sqrt((-c / a)), 2.0, (b / a)) * -a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (2.0 * c) / (-b + -b);
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (a <= -1.8e+129) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(2.0 * c) / Float64(fma(sqrt(Float64(Float64(-c) / a)), 2.0, Float64(b / a)) * Float64(-a))); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) + Float64(-b))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -1.8e+129], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[(N[(N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision] * 2.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + (-b)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;a \leq -1.8 \cdot 10^{+129}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(\sqrt{\frac{-c}{a}}, 2, \frac{b}{a}\right) \cdot \left(-a\right)}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \left(-b\right)}\\
\end{array}
\end{array}
if a < -1.8000000000000001e129Initial program 54.6%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6461.6
Applied rewrites61.6%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f64N/A
lift-/.f6472.3
Applied rewrites72.3%
if -1.8000000000000001e129 < a Initial program 69.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6469.7
Applied rewrites69.7%
Taylor expanded in b around -inf
mul-1-negN/A
lift-neg.f6471.9
Applied rewrites71.9%
Final simplification71.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (/ (- c) a))) (t_1 (fma (/ b a) -1.0 (/ c b))))
(if (<= c -4.1e-172)
(if (>= b 0.0) t_1 (- t_0))
(if (>= b 0.0) t_1 (/ (* 2.0 c) (* (fma t_0 2.0 (/ b a)) (- a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt((-c / a));
double t_1 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (c <= -4.1e-172) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = -t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = (2.0 * c) / (fma(t_0, 2.0, (b / a)) * -a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(-c) / a)) t_1 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (c <= -4.1e-172) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(-t_0); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_1; else tmp_1 = Float64(Float64(2.0 * c) / Float64(fma(t_0, 2.0, Float64(b / a)) * Float64(-a))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.1e-172], If[GreaterEqual[b, 0.0], t$95$1, (-t$95$0)], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(2.0 * c), $MachinePrecision] / N[(N[(t$95$0 * 2.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{-c}{a}}\\
t_1 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;c \leq -4.1 \cdot 10^{-172}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;-t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(t\_0, 2, \frac{b}{a}\right) \cdot \left(-a\right)}\\
\end{array}
\end{array}
if c < -4.1e-172Initial program 64.5%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6460.6
Applied rewrites60.6%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6448.9
Applied rewrites48.9%
if -4.1e-172 < c Initial program 70.8%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6474.8
Applied rewrites74.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f64N/A
lift-/.f6459.0
Applied rewrites59.0%
Final simplification54.7%
(FPCore (a b c) :precision binary64 (let* ((t_0 (- (sqrt (/ (- c) a)))) (t_1 (fma (/ b a) -1.0 (/ c b)))) (if (<= c -1e-303) (if (>= b 0.0) t_1 t_0) (if (>= b 0.0) t_1 (- t_0)))))
double code(double a, double b, double c) {
double t_0 = -sqrt((-c / a));
double t_1 = fma((b / a), -1.0, (c / b));
double tmp_1;
if (c <= -1e-303) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = -t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-sqrt(Float64(Float64(-c) / a))) t_1 = fma(Float64(b / a), -1.0, Float64(c / b)) tmp_1 = 0.0 if (c <= -1e-303) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_1; else tmp_1 = Float64(-t_0); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1e-303], If[GreaterEqual[b, 0.0], t$95$1, t$95$0], If[GreaterEqual[b, 0.0], t$95$1, (-t$95$0)]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sqrt{\frac{-c}{a}}\\
t_1 := \mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{if}\;c \leq -1 \cdot 10^{-303}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;-t\_0\\
\end{array}
\end{array}
if c < -9.99999999999999931e-304Initial program 70.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6467.9
Applied rewrites67.9%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6450.0
Applied rewrites50.0%
if -9.99999999999999931e-304 < c Initial program 65.5%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6469.7
Applied rewrites69.7%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6440.5
Applied rewrites40.5%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6453.6
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6453.6
Applied rewrites53.6%
Final simplification51.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (fma (/ b a) -1.0 (/ c b)) (- (- (sqrt (/ (- c) a))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = fma((b / a), -1.0, (c / b));
} else {
tmp = -(-sqrt((-c / a)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); else tmp = Float64(-Float64(-sqrt(Float64(Float64(-c) / a)))); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], (-(-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]))]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;-\left(-\sqrt{\frac{-c}{a}}\right)\\
\end{array}
\end{array}
Initial program 68.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6468.8
Applied rewrites68.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6445.6
Applied rewrites45.6%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6444.9
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6444.9
Applied rewrites44.9%
herbie shell --seed 2025057
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))