
(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 -37000000000000.0)
(/ c (- b))
(if (<= b 3.8e+122)
(fma (/ -0.5 a) (sqrt (fma a (* c -4.0) (pow b 2.0))) (* -0.5 (/ b a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -37000000000000.0) {
tmp = c / -b;
} else if (b <= 3.8e+122) {
tmp = fma((-0.5 / a), sqrt(fma(a, (c * -4.0), pow(b, 2.0))), (-0.5 * (b / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -37000000000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e+122) tmp = fma(Float64(-0.5 / a), sqrt(fma(a, Float64(c * -4.0), (b ^ 2.0))), Float64(-0.5 * Float64(b / a))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -37000000000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e+122], N[(N[(-0.5 / a), $MachinePrecision] * N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-0.5 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -37000000000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+122}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.5}{a}, \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}, -0.5 \cdot \frac{b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.7e13Initial program 5.5%
div-sub4.7%
sub-neg4.7%
neg-mul-14.7%
*-commutative4.7%
associate-/l*4.7%
distribute-neg-frac4.7%
neg-mul-14.7%
*-commutative4.7%
associate-/l*4.8%
distribute-rgt-out5.4%
associate-/r*5.4%
metadata-eval5.4%
sub-neg5.4%
+-commutative5.4%
Simplified5.5%
Taylor expanded in b around -inf 93.1%
mul-1-neg93.1%
distribute-neg-frac293.1%
Simplified93.1%
if -3.7e13 < b < 3.7999999999999998e122Initial program 74.2%
div-sub74.2%
sub-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.1%
distribute-neg-frac74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.0%
distribute-lft-in74.0%
associate-*l/74.1%
pow274.1%
Applied egg-rr74.1%
+-commutative74.1%
fma-define74.2%
associate-*r/74.2%
*-commutative74.2%
Simplified74.2%
if 3.7999999999999998e122 < b Initial program 53.6%
div-sub53.6%
sub-neg53.6%
neg-mul-153.6%
*-commutative53.6%
associate-/l*53.6%
distribute-neg-frac53.6%
neg-mul-153.6%
*-commutative53.6%
associate-/l*53.6%
distribute-rgt-out53.6%
associate-/r*53.6%
metadata-eval53.6%
sub-neg53.6%
+-commutative53.6%
Simplified53.8%
Taylor expanded in c around 0 97.8%
+-commutative97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
Final simplification83.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.36e+14)
(/ c (- b))
(if (<= b 7.5e+123)
(/ (- (- 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 <= -1.36e+14) {
tmp = c / -b;
} else if (b <= 7.5e+123) {
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 <= (-1.36d+14)) then
tmp = c / -b
else if (b <= 7.5d+123) 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 <= -1.36e+14) {
tmp = c / -b;
} else if (b <= 7.5e+123) {
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 <= -1.36e+14: tmp = c / -b elif b <= 7.5e+123: 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 <= -1.36e+14) tmp = Float64(c / Float64(-b)); elseif (b <= 7.5e+123) 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 <= -1.36e+14) tmp = c / -b; elseif (b <= 7.5e+123) 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, -1.36e+14], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7.5e+123], 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 -1.36 \cdot 10^{+14}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{+123}:\\
\;\;\;\;\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 < -1.36e14Initial program 5.5%
div-sub4.7%
sub-neg4.7%
neg-mul-14.7%
*-commutative4.7%
associate-/l*4.7%
distribute-neg-frac4.7%
neg-mul-14.7%
*-commutative4.7%
associate-/l*4.8%
distribute-rgt-out5.4%
associate-/r*5.4%
metadata-eval5.4%
sub-neg5.4%
+-commutative5.4%
Simplified5.5%
Taylor expanded in b around -inf 93.1%
mul-1-neg93.1%
distribute-neg-frac293.1%
Simplified93.1%
if -1.36e14 < b < 7.4999999999999999e123Initial program 74.2%
if 7.4999999999999999e123 < b Initial program 53.6%
div-sub53.6%
sub-neg53.6%
neg-mul-153.6%
*-commutative53.6%
associate-/l*53.6%
distribute-neg-frac53.6%
neg-mul-153.6%
*-commutative53.6%
associate-/l*53.6%
distribute-rgt-out53.6%
associate-/r*53.6%
metadata-eval53.6%
sub-neg53.6%
+-commutative53.6%
Simplified53.8%
Taylor expanded in c around 0 97.8%
+-commutative97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
Final simplification83.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.85e-78)
(/ c (- b))
(if (<= b 3.1e-36)
(/ (- (- b) (sqrt (* -4.0 (* c a)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.85e-78) {
tmp = c / -b;
} else if (b <= 3.1e-36) {
tmp = (-b - sqrt((-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 <= (-3.85d-78)) then
tmp = c / -b
else if (b <= 3.1d-36) then
tmp = (-b - sqrt(((-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 <= -3.85e-78) {
tmp = c / -b;
} else if (b <= 3.1e-36) {
tmp = (-b - Math.sqrt((-4.0 * (c * a)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.85e-78: tmp = c / -b elif b <= 3.1e-36: tmp = (-b - math.sqrt((-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 <= -3.85e-78) tmp = Float64(c / Float64(-b)); elseif (b <= 3.1e-36) tmp = Float64(Float64(Float64(-b) - sqrt(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 <= -3.85e-78) tmp = c / -b; elseif (b <= 3.1e-36) tmp = (-b - sqrt((-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, -3.85e-78], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.1e-36], N[(N[((-b) - N[Sqrt[N[(-4.0 * N[(c * a), $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 -3.85 \cdot 10^{-78}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-36}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{-4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.85e-78Initial program 16.6%
div-sub16.1%
sub-neg16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*16.0%
distribute-neg-frac16.0%
neg-mul-116.0%
*-commutative16.0%
associate-/l*16.1%
distribute-rgt-out16.6%
associate-/r*16.6%
metadata-eval16.6%
sub-neg16.6%
+-commutative16.6%
Simplified16.6%
Taylor expanded in b around -inf 81.8%
mul-1-neg81.8%
distribute-neg-frac281.8%
Simplified81.8%
if -3.85e-78 < b < 3.0999999999999999e-36Initial program 69.4%
*-commutative69.4%
sqr-neg69.4%
*-commutative69.4%
sqr-neg69.4%
*-commutative69.4%
associate-*r*69.4%
*-commutative69.4%
Simplified69.4%
Taylor expanded in b around 0 62.2%
*-commutative62.2%
Simplified62.2%
if 3.0999999999999999e-36 < b Initial program 75.5%
div-sub75.6%
sub-neg75.6%
neg-mul-175.6%
*-commutative75.6%
associate-/l*75.5%
distribute-neg-frac75.5%
neg-mul-175.5%
*-commutative75.5%
associate-/l*75.4%
distribute-rgt-out75.4%
associate-/r*75.4%
metadata-eval75.4%
sub-neg75.4%
+-commutative75.4%
Simplified75.5%
Taylor expanded in c around 0 91.0%
+-commutative91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
Final simplification78.4%
(FPCore (a b c)
:precision binary64
(if (<= b -3.4e-52)
(/ c (- b))
(if (<= b 1.15e-41)
(/ (sqrt (* a (* c -4.0))) (- (* a 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-52) {
tmp = c / -b;
} else if (b <= 1.15e-41) {
tmp = sqrt((a * (c * -4.0))) / -(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 <= (-3.4d-52)) then
tmp = c / -b
else if (b <= 1.15d-41) then
tmp = sqrt((a * (c * (-4.0d0)))) / -(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 <= -3.4e-52) {
tmp = c / -b;
} else if (b <= 1.15e-41) {
tmp = Math.sqrt((a * (c * -4.0))) / -(a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.4e-52: tmp = c / -b elif b <= 1.15e-41: tmp = math.sqrt((a * (c * -4.0))) / -(a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.4e-52) tmp = Float64(c / Float64(-b)); elseif (b <= 1.15e-41) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(-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 <= -3.4e-52) tmp = c / -b; elseif (b <= 1.15e-41) tmp = sqrt((a * (c * -4.0))) / -(a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.4e-52], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.15e-41], N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -3.4 \cdot 10^{-52}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-41}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{-a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.40000000000000017e-52Initial program 15.0%
div-sub14.5%
sub-neg14.5%
neg-mul-114.5%
*-commutative14.5%
associate-/l*14.4%
distribute-neg-frac14.4%
neg-mul-114.4%
*-commutative14.4%
associate-/l*14.5%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.0%
Taylor expanded in b around -inf 83.1%
mul-1-neg83.1%
distribute-neg-frac283.1%
Simplified83.1%
if -3.40000000000000017e-52 < b < 1.15000000000000005e-41Initial program 68.6%
*-commutative68.6%
sqr-neg68.6%
*-commutative68.6%
sqr-neg68.6%
*-commutative68.6%
associate-*r*68.6%
*-commutative68.6%
Simplified68.6%
add-cube-cbrt68.1%
pow368.1%
*-commutative68.1%
associate-*l*67.0%
Applied egg-rr67.0%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt59.8%
mul-1-neg59.8%
rem-cube-cbrt60.4%
Simplified60.4%
if 1.15000000000000005e-41 < b Initial program 75.5%
div-sub75.6%
sub-neg75.6%
neg-mul-175.6%
*-commutative75.6%
associate-/l*75.5%
distribute-neg-frac75.5%
neg-mul-175.5%
*-commutative75.5%
associate-/l*75.4%
distribute-rgt-out75.4%
associate-/r*75.4%
metadata-eval75.4%
sub-neg75.4%
+-commutative75.4%
Simplified75.5%
Taylor expanded in c around 0 91.0%
+-commutative91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
Final simplification77.9%
(FPCore (a b c) :precision binary64 (if (<= b -5.2e-86) (/ c (- b)) (if (<= b 3.1e-111) (* (sqrt (* c (/ -4.0 a))) (- 0.5)) (/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-86) {
tmp = c / -b;
} else if (b <= 3.1e-111) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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 <= (-5.2d-86)) then
tmp = c / -b
else if (b <= 3.1d-111) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-86) {
tmp = c / -b;
} else if (b <= 3.1e-111) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-86: tmp = c / -b elif b <= 3.1e-111: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-86) tmp = Float64(c / Float64(-b)); elseif (b <= 3.1e-111) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-86) tmp = c / -b; elseif (b <= 3.1e-111) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-86], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.1e-111], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-86}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-111}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -5.2000000000000002e-86Initial program 18.2%
div-sub17.7%
sub-neg17.7%
neg-mul-117.7%
*-commutative17.7%
associate-/l*17.6%
distribute-neg-frac17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*17.8%
distribute-rgt-out18.2%
associate-/r*18.2%
metadata-eval18.2%
sub-neg18.2%
+-commutative18.2%
Simplified18.3%
Taylor expanded in b around -inf 80.4%
mul-1-neg80.4%
distribute-neg-frac280.4%
Simplified80.4%
if -5.2000000000000002e-86 < b < 3.10000000000000014e-111Initial program 64.6%
*-commutative64.6%
sqr-neg64.6%
*-commutative64.6%
sqr-neg64.6%
*-commutative64.6%
associate-*r*64.6%
*-commutative64.6%
Simplified64.6%
add-cube-cbrt64.0%
pow364.1%
*-commutative64.1%
associate-*l*64.1%
Applied egg-rr64.1%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt39.0%
neg-mul-139.0%
associate-/l*39.0%
rem-cube-cbrt39.3%
Simplified39.3%
if 3.10000000000000014e-111 < b Initial program 78.1%
div-sub78.1%
sub-neg78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*78.0%
distribute-neg-frac78.0%
neg-mul-178.0%
*-commutative78.0%
associate-/l*77.9%
distribute-rgt-out77.9%
associate-/r*77.9%
metadata-eval77.9%
sub-neg77.9%
+-commutative77.9%
Simplified78.0%
Taylor expanded in a around 0 84.5%
associate-*r/84.5%
mul-1-neg84.5%
Simplified84.5%
Final simplification71.3%
(FPCore (a b c) :precision binary64 (if (<= b -5.5e-308) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e-308) {
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 <= (-5.5d-308)) 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 <= -5.5e-308) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.5e-308: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.5e-308) 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 <= -5.5e-308) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.5e-308], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{-308}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -5.5e-308Initial program 31.8%
div-sub31.5%
sub-neg31.5%
neg-mul-131.5%
*-commutative31.5%
associate-/l*31.4%
distribute-neg-frac31.4%
neg-mul-131.4%
*-commutative31.4%
associate-/l*31.5%
distribute-rgt-out31.8%
associate-/r*31.8%
metadata-eval31.8%
sub-neg31.8%
+-commutative31.8%
Simplified31.8%
Taylor expanded in b around -inf 62.9%
mul-1-neg62.9%
distribute-neg-frac262.9%
Simplified62.9%
if -5.5e-308 < b Initial program 75.5%
div-sub75.5%
sub-neg75.5%
neg-mul-175.5%
*-commutative75.5%
associate-/l*75.4%
distribute-neg-frac75.4%
neg-mul-175.4%
*-commutative75.4%
associate-/l*75.3%
distribute-rgt-out75.3%
associate-/r*75.3%
metadata-eval75.3%
sub-neg75.3%
+-commutative75.3%
Simplified75.4%
Taylor expanded in a around 0 69.0%
associate-*r/69.0%
mul-1-neg69.0%
Simplified69.0%
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 52.6%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-neg-frac52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-rgt-out52.5%
associate-/r*52.5%
metadata-eval52.5%
sub-neg52.5%
+-commutative52.5%
Simplified52.6%
Taylor expanded in b around -inf 34.0%
mul-1-neg34.0%
distribute-neg-frac234.0%
Simplified34.0%
(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 52.6%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-neg-frac52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-rgt-out52.5%
associate-/r*52.5%
metadata-eval52.5%
sub-neg52.5%
+-commutative52.5%
Simplified52.6%
Taylor expanded in a around 0 32.8%
+-commutative32.8%
mul-1-neg32.8%
sub-neg32.8%
associate-/l*34.0%
Simplified34.0%
Taylor expanded in a around inf 10.2%
(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 52.6%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-neg-frac52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-rgt-out52.5%
associate-/r*52.5%
metadata-eval52.5%
sub-neg52.5%
+-commutative52.5%
Simplified52.6%
Taylor expanded in a around 0 34.4%
associate-*r/34.4%
mul-1-neg34.4%
Simplified34.4%
div-inv34.3%
add-sqr-sqrt1.5%
sqrt-unprod2.1%
sqr-neg2.1%
sqrt-prod0.7%
add-sqr-sqrt2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
Simplified2.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024155
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))