
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -6.6e-87)
(/ c (- b))
(if (<= b 2.35e+60)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.6e-87) {
tmp = c / -b;
} else if (b <= 2.35e+60) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-6.6d-87)) then
tmp = c / -b
else if (b <= 2.35d+60) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.6e-87) {
tmp = c / -b;
} else if (b <= 2.35e+60) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.6e-87: tmp = c / -b elif b <= 2.35e+60: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.6e-87) tmp = Float64(c / Float64(-b)); elseif (b <= 2.35e+60) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.6e-87) tmp = c / -b; elseif (b <= 2.35e+60) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.6e-87], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.35e+60], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.6 \cdot 10^{-87}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{+60}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.6000000000000001e-87Initial program 18.0%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.5%
distribute-neg-frac14.5%
neg-mul-114.5%
*-commutative14.5%
associate-/l*16.9%
distribute-rgt-out18.0%
associate-/r*18.0%
metadata-eval18.0%
sub-neg18.0%
+-commutative18.0%
Simplified18.0%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
distribute-neg-frac284.9%
Simplified84.9%
if -6.6000000000000001e-87 < b < 2.3499999999999999e60Initial program 82.3%
if 2.3499999999999999e60 < b Initial program 61.5%
div-sub61.5%
sub-neg61.5%
neg-mul-161.5%
*-commutative61.5%
associate-/l*61.5%
distribute-neg-frac61.5%
neg-mul-161.5%
*-commutative61.5%
associate-/l*61.4%
distribute-rgt-out61.4%
associate-/r*61.4%
metadata-eval61.4%
sub-neg61.4%
+-commutative61.4%
Simplified61.5%
Taylor expanded in c around 0 93.3%
+-commutative93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-90)
(/ c (- b))
(if (<= b 3.8e-87)
(/ (- (- b) (sqrt (* (* c a) -4.0))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-90) {
tmp = c / -b;
} else if (b <= 3.8e-87) {
tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.05d-90)) then
tmp = c / -b
else if (b <= 3.8d-87) then
tmp = (-b - sqrt(((c * a) * (-4.0d0)))) / (a * 2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-90) {
tmp = c / -b;
} else if (b <= 3.8e-87) {
tmp = (-b - Math.sqrt(((c * a) * -4.0))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e-90: tmp = c / -b elif b <= 3.8e-87: tmp = (-b - math.sqrt(((c * a) * -4.0))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e-90) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e-87) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(c * a) * -4.0))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.05e-90) tmp = c / -b; elseif (b <= 3.8e-87) tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e-90], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e-87], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{-90}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-87}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.05e-90Initial program 18.0%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.5%
distribute-neg-frac14.5%
neg-mul-114.5%
*-commutative14.5%
associate-/l*16.9%
distribute-rgt-out18.0%
associate-/r*18.0%
metadata-eval18.0%
sub-neg18.0%
+-commutative18.0%
Simplified18.0%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
distribute-neg-frac284.9%
Simplified84.9%
if -1.05e-90 < b < 3.8e-87Initial program 79.1%
*-commutative79.1%
sqr-neg79.1%
*-commutative79.1%
sqr-neg79.1%
*-commutative79.1%
associate-*r*79.1%
*-commutative79.1%
Simplified79.1%
Taylor expanded in b around 0 72.0%
*-commutative72.0%
Simplified72.0%
if 3.8e-87 < b Initial program 70.6%
div-sub70.6%
sub-neg70.6%
neg-mul-170.6%
*-commutative70.6%
associate-/l*70.5%
distribute-neg-frac70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.4%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified70.5%
Taylor expanded in a around 0 83.9%
associate-*r/83.9%
mul-1-neg83.9%
Simplified83.9%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -8.6e-85) (/ c (- b)) (if (<= b 2.3e-89) (/ (sqrt (* (* c a) -4.0)) (* a -2.0)) (/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-85) {
tmp = c / -b;
} else if (b <= 2.3e-89) {
tmp = sqrt(((c * a) * -4.0)) / (a * -2.0);
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-8.6d-85)) then
tmp = c / -b
else if (b <= 2.3d-89) then
tmp = sqrt(((c * a) * (-4.0d0))) / (a * (-2.0d0))
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-85) {
tmp = c / -b;
} else if (b <= 2.3e-89) {
tmp = Math.sqrt(((c * a) * -4.0)) / (a * -2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.6e-85: tmp = c / -b elif b <= 2.3e-89: tmp = math.sqrt(((c * a) * -4.0)) / (a * -2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.6e-85) tmp = Float64(c / Float64(-b)); elseif (b <= 2.3e-89) tmp = Float64(sqrt(Float64(Float64(c * a) * -4.0)) / Float64(a * -2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.6e-85) tmp = c / -b; elseif (b <= 2.3e-89) tmp = sqrt(((c * a) * -4.0)) / (a * -2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.6e-85], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.3e-89], N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.6 \cdot 10^{-85}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-89}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -8.59999999999999998e-85Initial program 18.0%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.5%
distribute-neg-frac14.5%
neg-mul-114.5%
*-commutative14.5%
associate-/l*16.9%
distribute-rgt-out18.0%
associate-/r*18.0%
metadata-eval18.0%
sub-neg18.0%
+-commutative18.0%
Simplified18.0%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
distribute-neg-frac284.9%
Simplified84.9%
if -8.59999999999999998e-85 < b < 2.3e-89Initial program 79.1%
*-commutative79.1%
sqr-neg79.1%
*-commutative79.1%
sqr-neg79.1%
*-commutative79.1%
associate-*r*79.1%
*-commutative79.1%
Simplified79.1%
add-cube-cbrt78.5%
pow378.5%
*-commutative78.5%
associate-*l*78.5%
Applied egg-rr78.5%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt69.7%
rem-cube-cbrt70.2%
neg-mul-170.2%
Simplified70.2%
neg-mul-170.2%
*-commutative70.2%
times-frac70.2%
metadata-eval70.2%
Applied egg-rr70.2%
*-commutative70.2%
metadata-eval70.2%
times-frac70.2%
*-rgt-identity70.2%
associate-*r*70.2%
*-commutative70.2%
Simplified70.2%
if 2.3e-89 < b Initial program 70.6%
div-sub70.6%
sub-neg70.6%
neg-mul-170.6%
*-commutative70.6%
associate-/l*70.5%
distribute-neg-frac70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.4%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified70.5%
Taylor expanded in a around 0 83.9%
associate-*r/83.9%
mul-1-neg83.9%
Simplified83.9%
Final simplification80.5%
(FPCore (a b c) :precision binary64 (if (<= b -3.4e-107) (/ c (- b)) (if (<= b 8.6e-170) (- (sqrt (/ (- c) a))) (/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-107) {
tmp = c / -b;
} else if (b <= 8.6e-170) {
tmp = -sqrt((-c / a));
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.4d-107)) then
tmp = c / -b
else if (b <= 8.6d-170) then
tmp = -sqrt((-c / a))
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-107) {
tmp = c / -b;
} else if (b <= 8.6e-170) {
tmp = -Math.sqrt((-c / a));
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.4e-107: tmp = c / -b elif b <= 8.6e-170: tmp = -math.sqrt((-c / a)) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.4e-107) tmp = Float64(c / Float64(-b)); elseif (b <= 8.6e-170) tmp = Float64(-sqrt(Float64(Float64(-c) / a))); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.4e-107) tmp = c / -b; elseif (b <= 8.6e-170) tmp = -sqrt((-c / a)); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.4e-107], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8.6e-170], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.4 \cdot 10^{-107}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8.6 \cdot 10^{-170}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.39999999999999994e-107Initial program 19.7%
div-sub18.6%
sub-neg18.6%
neg-mul-118.6%
*-commutative18.6%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*18.7%
distribute-rgt-out19.8%
associate-/r*19.8%
metadata-eval19.8%
sub-neg19.8%
+-commutative19.8%
Simplified19.8%
Taylor expanded in b around -inf 82.1%
mul-1-neg82.1%
distribute-neg-frac282.1%
Simplified82.1%
if -3.39999999999999994e-107 < b < 8.5999999999999997e-170Initial program 74.3%
*-commutative74.3%
sqr-neg74.3%
*-commutative74.3%
sqr-neg74.3%
*-commutative74.3%
associate-*r*74.3%
*-commutative74.3%
Simplified74.3%
add-cube-cbrt73.7%
pow373.7%
*-commutative73.7%
associate-*l*73.7%
Applied egg-rr73.7%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt35.6%
neg-mul-135.6%
rem-cube-cbrt35.9%
Simplified35.9%
distribute-rgt-neg-out35.9%
neg-sub035.9%
add-sqr-sqrt35.9%
sqr-neg35.9%
sqrt-unprod1.1%
add-sqr-sqrt30.8%
add-sqr-sqrt1.1%
sqrt-unprod35.9%
*-commutative35.9%
*-commutative35.9%
swap-sqr35.9%
Applied egg-rr35.9%
neg-sub035.9%
*-commutative35.9%
neg-mul-135.9%
Simplified35.9%
if 8.5999999999999997e-170 < b Initial program 74.1%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*73.9%
distribute-neg-frac73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.8%
distribute-rgt-out73.8%
associate-/r*73.8%
metadata-eval73.8%
sub-neg73.8%
+-commutative73.8%
Simplified73.9%
Taylor expanded in a around 0 77.8%
associate-*r/77.8%
mul-1-neg77.8%
Simplified77.8%
Final simplification70.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.4e-91) (/ c (- b)) (if (<= b 4.2e-207) (sqrt (/ (- c) a)) (/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-91) {
tmp = c / -b;
} else if (b <= 4.2e-207) {
tmp = sqrt((-c / a));
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.4d-91)) then
tmp = c / -b
else if (b <= 4.2d-207) then
tmp = sqrt((-c / a))
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-91) {
tmp = c / -b;
} else if (b <= 4.2e-207) {
tmp = Math.sqrt((-c / a));
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-91: tmp = c / -b elif b <= 4.2e-207: tmp = math.sqrt((-c / a)) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-91) tmp = Float64(c / Float64(-b)); elseif (b <= 4.2e-207) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.4e-91) tmp = c / -b; elseif (b <= 4.2e-207) tmp = sqrt((-c / a)); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-91], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.2e-207], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-91}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-207}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.4e-91Initial program 18.0%
div-sub16.9%
sub-neg16.9%
neg-mul-116.9%
*-commutative16.9%
associate-/l*14.5%
distribute-neg-frac14.5%
neg-mul-114.5%
*-commutative14.5%
associate-/l*16.9%
distribute-rgt-out18.0%
associate-/r*18.0%
metadata-eval18.0%
sub-neg18.0%
+-commutative18.0%
Simplified18.0%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
distribute-neg-frac284.9%
Simplified84.9%
if -1.4e-91 < b < 4.20000000000000007e-207Initial program 73.9%
*-commutative73.9%
sqr-neg73.9%
*-commutative73.9%
sqr-neg73.9%
*-commutative73.9%
associate-*r*73.9%
*-commutative73.9%
Simplified73.9%
add-cube-cbrt73.2%
pow373.2%
*-commutative73.2%
associate-*l*73.2%
Applied egg-rr73.2%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt69.0%
rem-cube-cbrt69.4%
neg-mul-169.4%
Simplified69.4%
add-sqr-sqrt36.6%
sqrt-unprod24.0%
frac-times17.5%
sqr-neg17.5%
add-sqr-sqrt17.5%
swap-sqr17.5%
pow217.5%
metadata-eval17.5%
Applied egg-rr17.5%
times-frac22.1%
Simplified22.1%
Taylor expanded in a around 0 36.1%
mul-1-neg36.1%
distribute-frac-neg36.1%
Simplified36.1%
if 4.20000000000000007e-207 < b Initial program 74.1%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-neg-frac74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*73.8%
distribute-rgt-out73.8%
associate-/r*73.8%
metadata-eval73.8%
sub-neg73.8%
+-commutative73.8%
Simplified73.9%
Taylor expanded in a around 0 74.6%
associate-*r/74.6%
mul-1-neg74.6%
Simplified74.6%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.75e-263) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-263) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.75d-263)) then
tmp = c / -b
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-263) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-263: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-263) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-263) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-263], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-263}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.74999999999999985e-263Initial program 34.5%
div-sub33.7%
sub-neg33.7%
neg-mul-133.7%
*-commutative33.7%
associate-/l*31.9%
distribute-neg-frac31.9%
neg-mul-131.9%
*-commutative31.9%
associate-/l*33.6%
distribute-rgt-out34.5%
associate-/r*34.5%
metadata-eval34.5%
sub-neg34.5%
+-commutative34.5%
Simplified34.5%
Taylor expanded in b around -inf 65.5%
mul-1-neg65.5%
distribute-neg-frac265.5%
Simplified65.5%
if -1.74999999999999985e-263 < b Initial program 73.0%
div-sub73.0%
sub-neg73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*72.9%
distribute-neg-frac72.9%
neg-mul-172.9%
*-commutative72.9%
associate-/l*72.7%
distribute-rgt-out72.7%
associate-/r*72.7%
metadata-eval72.7%
sub-neg72.7%
+-commutative72.7%
Simplified72.8%
Taylor expanded in a around 0 66.1%
associate-*r/66.1%
mul-1-neg66.1%
Simplified66.1%
Final simplification65.8%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 56.3%
div-sub55.9%
sub-neg55.9%
neg-mul-155.9%
*-commutative55.9%
associate-/l*55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
*-commutative55.1%
associate-/l*55.8%
distribute-rgt-out56.2%
associate-/r*56.2%
metadata-eval56.2%
sub-neg56.2%
+-commutative56.2%
Simplified56.2%
Taylor expanded in b around -inf 29.8%
mul-1-neg29.8%
distribute-neg-frac229.8%
Simplified29.8%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 56.3%
div-sub55.9%
sub-neg55.9%
neg-mul-155.9%
*-commutative55.9%
associate-/l*55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
*-commutative55.1%
associate-/l*55.8%
distribute-rgt-out56.2%
associate-/r*56.2%
metadata-eval56.2%
sub-neg56.2%
+-commutative56.2%
Simplified56.2%
Taylor expanded in b around -inf 29.8%
mul-1-neg29.8%
distribute-neg-frac229.8%
Simplified29.8%
add-sqr-sqrt19.9%
sqrt-unprod18.2%
distribute-frac-neg218.2%
distribute-frac-neg218.2%
sqr-neg18.2%
sqrt-unprod7.4%
add-sqr-sqrt9.1%
div-inv9.1%
Applied egg-rr9.1%
associate-*r/9.1%
*-rgt-identity9.1%
Simplified9.1%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 56.3%
div-sub55.9%
sub-neg55.9%
neg-mul-155.9%
*-commutative55.9%
associate-/l*55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
*-commutative55.1%
associate-/l*55.8%
distribute-rgt-out56.2%
associate-/r*56.2%
metadata-eval56.2%
sub-neg56.2%
+-commutative56.2%
Simplified56.2%
Taylor expanded in a around 0 38.6%
associate-*r/38.6%
mul-1-neg38.6%
Simplified38.6%
add-sqr-sqrt22.0%
sqrt-unprod17.0%
distribute-frac-neg17.0%
distribute-frac-neg17.0%
sqr-neg17.0%
sqrt-unprod1.5%
add-sqr-sqrt2.5%
div-inv2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
Simplified2.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024184
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))