
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2.3e+154)
(/ b (- a))
(if (<= b 2.35e-84)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e+154) {
tmp = b / -a;
} else if (b <= 2.35e-84) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
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 <= (-2.3d+154)) then
tmp = b / -a
else if (b <= 2.35d-84) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e+154) {
tmp = b / -a;
} else if (b <= 2.35e-84) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e+154: tmp = b / -a elif b <= 2.35e-84: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e+154) tmp = Float64(b / Float64(-a)); elseif (b <= 2.35e-84) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.3e+154) tmp = b / -a; elseif (b <= 2.35e-84) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e+154], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.35e-84], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{-84}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.3e154Initial program 54.9%
*-commutative54.9%
Simplified54.9%
Taylor expanded in b around -inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
if -2.3e154 < b < 2.35e-84Initial program 87.3%
if 2.35e-84 < b Initial program 12.2%
*-commutative12.2%
Simplified12.2%
Taylor expanded in b around inf 91.0%
associate-*r/91.0%
neg-mul-191.0%
Simplified91.0%
Final simplification90.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.2e+143)
(/ b (- a))
(if (<= b 6.6e-82)
(* (- b (sqrt (+ (* b b) (* c (* a -4.0))))) (/ -0.5 a))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e+143) {
tmp = b / -a;
} else if (b <= 6.6e-82) {
tmp = (b - sqrt(((b * b) + (c * (a * -4.0))))) * (-0.5 / a);
} else {
tmp = c / -b;
}
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 <= (-2.2d+143)) then
tmp = b / -a
else if (b <= 6.6d-82) then
tmp = (b - sqrt(((b * b) + (c * (a * (-4.0d0)))))) * ((-0.5d0) / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e+143) {
tmp = b / -a;
} else if (b <= 6.6e-82) {
tmp = (b - Math.sqrt(((b * b) + (c * (a * -4.0))))) * (-0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e+143: tmp = b / -a elif b <= 6.6e-82: tmp = (b - math.sqrt(((b * b) + (c * (a * -4.0))))) * (-0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e+143) tmp = Float64(b / Float64(-a)); elseif (b <= 6.6e-82) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0))))) * Float64(-0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.2e+143) tmp = b / -a; elseif (b <= 6.6e-82) tmp = (b - sqrt(((b * b) + (c * (a * -4.0))))) * (-0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e+143], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6.6e-82], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{+143}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-82}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.20000000000000014e143Initial program 57.0%
*-commutative57.0%
Simplified57.0%
Taylor expanded in b around -inf 95.8%
associate-*r/95.8%
mul-1-neg95.8%
Simplified95.8%
if -2.20000000000000014e143 < b < 6.60000000000000045e-82Initial program 87.1%
*-commutative87.1%
Simplified87.1%
frac-2neg87.1%
div-inv86.9%
Applied egg-rr86.9%
fma-undefine86.9%
Applied egg-rr86.9%
Taylor expanded in a around 0 86.9%
unpow286.9%
Applied egg-rr86.9%
if 6.60000000000000045e-82 < b Initial program 12.2%
*-commutative12.2%
Simplified12.2%
Taylor expanded in b around inf 91.0%
associate-*r/91.0%
neg-mul-191.0%
Simplified91.0%
Final simplification90.0%
(FPCore (a b c)
:precision binary64
(if (<= b -8e-114)
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
(if (<= b 7.5e-82)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-114) {
tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 7.5e-82) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
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 <= (-8d-114)) then
tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
else if (b <= 7.5d-82) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8e-114) {
tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 7.5e-82) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-114: tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a)) elif b <= 7.5e-82: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-114) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); elseif (b <= 7.5e-82) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8e-114) tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a)); elseif (b <= 7.5e-82) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-114], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.5e-82], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-114}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-82}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -8.0000000000000004e-114Initial program 78.9%
*-commutative78.9%
Simplified78.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
distribute-rgt-neg-in90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -8.0000000000000004e-114 < b < 7.4999999999999997e-82Initial program 78.7%
*-commutative78.7%
Simplified78.7%
Taylor expanded in b around 0 76.6%
associate-*r*76.3%
*-commutative76.3%
*-commutative76.3%
Simplified76.3%
if 7.4999999999999997e-82 < b Initial program 12.2%
*-commutative12.2%
Simplified12.2%
Taylor expanded in b around inf 91.0%
associate-*r/91.0%
neg-mul-191.0%
Simplified91.0%
Final simplification87.5%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = b / -a;
} else {
tmp = c / -b;
}
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-310)) then
tmp = b / -a
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 79.4%
*-commutative79.4%
Simplified79.4%
Taylor expanded in b around -inf 73.5%
associate-*r/73.5%
mul-1-neg73.5%
Simplified73.5%
if -3.999999999999988e-310 < b Initial program 27.2%
*-commutative27.2%
Simplified27.2%
Taylor expanded in b around inf 72.5%
associate-*r/72.5%
neg-mul-172.5%
Simplified72.5%
Final simplification73.0%
(FPCore (a b c) :precision binary64 (if (<= b 1.45e+39) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.45e+39) {
tmp = b / -a;
} else {
tmp = c / b;
}
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.45d+39) then
tmp = b / -a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.45e+39) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.45e+39: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.45e+39) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.45e+39) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.45e+39], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.45 \cdot 10^{+39}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.45000000000000015e39Initial program 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in b around -inf 52.6%
associate-*r/52.6%
mul-1-neg52.6%
Simplified52.6%
if 1.45000000000000015e39 < b Initial program 8.2%
*-commutative8.2%
Simplified8.2%
Taylor expanded in b around inf 98.6%
associate-*r/98.6%
neg-mul-198.6%
Simplified98.6%
add-sqr-sqrt49.2%
sqrt-unprod51.8%
sqr-neg51.8%
sqrt-unprod9.3%
add-sqr-sqrt25.2%
div-inv25.2%
Applied egg-rr25.2%
associate-*r/25.2%
*-rgt-identity25.2%
Simplified25.2%
Final simplification45.2%
(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 54.1%
*-commutative54.1%
Simplified54.1%
Taylor expanded in b around inf 36.4%
associate-*r/36.4%
neg-mul-136.4%
Simplified36.4%
add-sqr-sqrt18.1%
sqrt-unprod18.6%
sqr-neg18.6%
sqrt-unprod3.4%
add-sqr-sqrt8.8%
div-inv8.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
Simplified8.8%
(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 54.1%
*-commutative54.1%
Simplified54.1%
Taylor expanded in b around -inf 39.1%
associate-*r/39.1%
mul-1-neg39.1%
Simplified39.1%
neg-sub039.1%
flip--32.0%
metadata-eval32.0%
pow232.0%
add-sqr-sqrt1.2%
sqrt-prod1.1%
sqr-neg1.1%
sqrt-unprod0.6%
add-sqr-sqrt2.0%
sub-neg2.0%
neg-sub02.0%
add-sqr-sqrt0.6%
sqrt-unprod1.1%
sqr-neg1.1%
sqrt-prod1.2%
add-sqr-sqrt32.0%
Applied egg-rr32.0%
neg-sub032.0%
Simplified32.0%
div-inv31.9%
add-sqr-sqrt30.9%
add-sqr-sqrt31.9%
distribute-frac-neg31.9%
pow131.9%
pow-div39.0%
metadata-eval39.0%
pow139.0%
add-sqr-sqrt37.6%
sqrt-unprod32.1%
sqr-neg32.1%
sqrt-prod1.6%
add-sqr-sqrt2.2%
Applied egg-rr2.2%
associate-*r/2.2%
*-rgt-identity2.2%
Simplified2.2%
(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))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) 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(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024172
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))