
(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 7 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 -4e-37)
(/ c (- b))
(if (<= b 1e+127)
(/ (- (- 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 <= -4e-37) {
tmp = c / -b;
} else if (b <= 1e+127) {
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 <= (-4d-37)) then
tmp = c / -b
else if (b <= 1d+127) 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 <= -4e-37) {
tmp = c / -b;
} else if (b <= 1e+127) {
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 <= -4e-37: tmp = c / -b elif b <= 1e+127: 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 <= -4e-37) tmp = Float64(c / Float64(-b)); elseif (b <= 1e+127) 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 <= -4e-37) tmp = c / -b; elseif (b <= 1e+127) 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, -4e-37], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1e+127], 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 -4 \cdot 10^{-37}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 10^{+127}:\\
\;\;\;\;\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 < -4.00000000000000027e-37Initial program 12.9%
div-sub12.4%
sub-neg12.4%
neg-mul-112.4%
*-commutative12.4%
associate-/l*11.9%
distribute-neg-frac11.9%
neg-mul-111.9%
*-commutative11.9%
associate-/l*12.5%
distribute-rgt-out12.9%
associate-/r*12.9%
metadata-eval12.9%
sub-neg12.9%
+-commutative12.9%
Simplified12.9%
Taylor expanded in b around -inf 91.3%
mul-1-neg91.3%
distribute-neg-frac291.3%
Simplified91.3%
if -4.00000000000000027e-37 < b < 9.99999999999999955e126Initial program 78.5%
if 9.99999999999999955e126 < b Initial program 35.2%
div-sub35.2%
sub-neg35.2%
neg-mul-135.2%
*-commutative35.2%
associate-/l*35.2%
distribute-neg-frac35.2%
neg-mul-135.2%
*-commutative35.2%
associate-/l*35.2%
distribute-rgt-out35.2%
associate-/r*35.2%
metadata-eval35.2%
sub-neg35.2%
+-commutative35.2%
Simplified35.3%
Taylor expanded in c around 0 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-37)
(/ c (- b))
(if (<= b 2.25e-64)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(/ (- (* a (/ c b)) b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-37) {
tmp = c / -b;
} else if (b <= 2.25e-64) {
tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0)));
} else {
tmp = ((a * (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 <= (-3d-37)) then
tmp = c / -b
else if (b <= 2.25d-64) then
tmp = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-4.0d0))))
else
tmp = ((a * (c / b)) - b) / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3e-37) {
tmp = c / -b;
} else if (b <= 2.25e-64) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = ((a * (c / b)) - b) / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-37: tmp = c / -b elif b <= 2.25e-64: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = ((a * (c / b)) - b) / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-37) tmp = Float64(c / Float64(-b)); elseif (b <= 2.25e-64) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -4.0)))); else tmp = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-37) tmp = c / -b; elseif (b <= 2.25e-64) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = ((a * (c / b)) - b) / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-37], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.25e-64], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-37}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-64}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\end{array}
\end{array}
if b < -3e-37Initial program 12.9%
div-sub12.4%
sub-neg12.4%
neg-mul-112.4%
*-commutative12.4%
associate-/l*11.9%
distribute-neg-frac11.9%
neg-mul-111.9%
*-commutative11.9%
associate-/l*12.5%
distribute-rgt-out12.9%
associate-/r*12.9%
metadata-eval12.9%
sub-neg12.9%
+-commutative12.9%
Simplified12.9%
Taylor expanded in b around -inf 91.3%
mul-1-neg91.3%
distribute-neg-frac291.3%
Simplified91.3%
if -3e-37 < b < 2.25000000000000005e-64Initial program 69.6%
div-sub69.6%
sub-neg69.6%
neg-mul-169.6%
*-commutative69.6%
associate-/l*69.6%
distribute-neg-frac69.6%
neg-mul-169.6%
*-commutative69.6%
associate-/l*69.4%
distribute-rgt-out69.5%
associate-/r*69.5%
metadata-eval69.5%
sub-neg69.5%
+-commutative69.5%
Simplified69.5%
Taylor expanded in a around inf 66.3%
*-commutative66.3%
Simplified66.3%
if 2.25000000000000005e-64 < b Initial program 62.3%
div-sub62.3%
sub-neg62.3%
neg-mul-162.3%
*-commutative62.3%
associate-/l*62.3%
distribute-neg-frac62.3%
neg-mul-162.3%
*-commutative62.3%
associate-/l*62.2%
distribute-rgt-out62.2%
associate-/r*62.2%
metadata-eval62.2%
sub-neg62.2%
+-commutative62.2%
Simplified62.2%
Taylor expanded in a around 0 89.4%
mul-1-neg89.4%
+-commutative89.4%
sub-neg89.4%
associate-/l*93.1%
Simplified93.1%
Final simplification83.9%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = c / -b;
} 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 <= (-1d-310)) then
tmp = c / -b
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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(c / Float64(-b)); 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 <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 29.1%
div-sub28.8%
sub-neg28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*28.4%
distribute-neg-frac28.4%
neg-mul-128.4%
*-commutative28.4%
associate-/l*28.7%
distribute-rgt-out29.0%
associate-/r*29.0%
metadata-eval29.0%
sub-neg29.0%
+-commutative29.0%
Simplified29.0%
Taylor expanded in b around -inf 69.7%
mul-1-neg69.7%
distribute-neg-frac269.7%
Simplified69.7%
if -9.999999999999969e-311 < b Initial program 67.6%
div-sub67.7%
sub-neg67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-neg-frac67.6%
neg-mul-167.6%
*-commutative67.6%
associate-/l*67.5%
distribute-rgt-out67.5%
associate-/r*67.5%
metadata-eval67.5%
sub-neg67.5%
+-commutative67.5%
Simplified67.5%
Taylor expanded in c around 0 69.4%
+-commutative69.4%
mul-1-neg69.4%
unsub-neg69.4%
Simplified69.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 29.1%
div-sub28.8%
sub-neg28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*28.4%
distribute-neg-frac28.4%
neg-mul-128.4%
*-commutative28.4%
associate-/l*28.7%
distribute-rgt-out29.0%
associate-/r*29.0%
metadata-eval29.0%
sub-neg29.0%
+-commutative29.0%
Simplified29.0%
Taylor expanded in b around -inf 69.7%
mul-1-neg69.7%
distribute-neg-frac269.7%
Simplified69.7%
if -9.999999999999969e-311 < b Initial program 67.6%
div-sub67.7%
sub-neg67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-neg-frac67.6%
neg-mul-167.6%
*-commutative67.6%
associate-/l*67.5%
distribute-rgt-out67.5%
associate-/r*67.5%
metadata-eval67.5%
sub-neg67.5%
+-commutative67.5%
Simplified67.5%
Taylor expanded in a around 0 68.8%
associate-*r/68.8%
mul-1-neg68.8%
Simplified68.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 46.7%
div-sub46.5%
sub-neg46.5%
neg-mul-146.5%
*-commutative46.5%
associate-/l*46.3%
distribute-neg-frac46.3%
neg-mul-146.3%
*-commutative46.3%
associate-/l*46.5%
distribute-rgt-out46.6%
associate-/r*46.6%
metadata-eval46.6%
sub-neg46.6%
+-commutative46.6%
Simplified46.6%
Taylor expanded in b around -inf 38.8%
mul-1-neg38.8%
distribute-neg-frac238.8%
Simplified38.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 46.7%
div-sub46.5%
sub-neg46.5%
neg-mul-146.5%
*-commutative46.5%
associate-/l*46.3%
distribute-neg-frac46.3%
neg-mul-146.3%
*-commutative46.3%
associate-/l*46.5%
distribute-rgt-out46.6%
associate-/r*46.6%
metadata-eval46.6%
sub-neg46.6%
+-commutative46.6%
Simplified46.6%
Taylor expanded in a around 0 31.8%
mul-1-neg31.8%
+-commutative31.8%
sub-neg31.8%
associate-/l*33.0%
Simplified33.0%
Taylor expanded in a around inf 14.5%
(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 46.7%
div-sub46.5%
sub-neg46.5%
neg-mul-146.5%
*-commutative46.5%
associate-/l*46.3%
distribute-neg-frac46.3%
neg-mul-146.3%
*-commutative46.3%
associate-/l*46.5%
distribute-rgt-out46.6%
associate-/r*46.6%
metadata-eval46.6%
sub-neg46.6%
+-commutative46.6%
Simplified46.6%
Applied egg-rr29.4%
Taylor expanded in b around -inf 2.5%
(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 2024143
(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)))