
(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 -4.5e+115)
(/ b (- a))
(if (<= b 1.16e-82)
(/ (- (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 <= -4.5e+115) {
tmp = b / -a;
} else if (b <= 1.16e-82) {
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 <= (-4.5d+115)) then
tmp = b / -a
else if (b <= 1.16d-82) 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 <= -4.5e+115) {
tmp = b / -a;
} else if (b <= 1.16e-82) {
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 <= -4.5e+115: tmp = b / -a elif b <= 1.16e-82: 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 <= -4.5e+115) tmp = Float64(b / Float64(-a)); elseif (b <= 1.16e-82) 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 <= -4.5e+115) tmp = b / -a; elseif (b <= 1.16e-82) 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, -4.5e+115], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.16e-82], 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 -4.5 \cdot 10^{+115}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.16 \cdot 10^{-82}:\\
\;\;\;\;\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 < -4.49999999999999963e115Initial program 53.3%
*-commutative53.3%
Simplified53.3%
Taylor expanded in b around -inf 94.8%
associate-*r/94.8%
mul-1-neg94.8%
Simplified94.8%
if -4.49999999999999963e115 < b < 1.16e-82Initial program 82.8%
if 1.16e-82 < b Initial program 17.4%
*-commutative17.4%
Simplified17.5%
Taylor expanded in a around 0 85.3%
associate-*r/85.3%
mul-1-neg85.3%
Simplified85.3%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -4.8e-46)
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
(if (<= b 1.55e-82)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-46) {
tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 1.55e-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 <= (-4.8d-46)) then
tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
else if (b <= 1.55d-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 <= -4.8e-46) {
tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 1.55e-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 <= -4.8e-46: tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a)) elif b <= 1.55e-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 <= -4.8e-46) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); elseif (b <= 1.55e-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 <= -4.8e-46) tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a)); elseif (b <= 1.55e-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, -4.8e-46], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.55e-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 -4.8 \cdot 10^{-46}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\mathbf{elif}\;b \leq 1.55 \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 < -4.80000000000000027e-46Initial program 71.8%
*-commutative71.8%
Simplified71.8%
Taylor expanded in b around -inf 92.3%
mul-1-neg92.3%
distribute-rgt-neg-in92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
if -4.80000000000000027e-46 < b < 1.55e-82Initial program 75.8%
*-commutative75.8%
Simplified75.8%
Taylor expanded in a around inf 69.6%
associate-*r*69.7%
*-commutative69.7%
Simplified69.7%
if 1.55e-82 < b Initial program 17.4%
*-commutative17.4%
Simplified17.5%
Taylor expanded in a around 0 85.3%
associate-*r/85.3%
mul-1-neg85.3%
Simplified85.3%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (if (<= b -2e-238) (/ b (- a)) (if (<= b 2e-205) (* (sqrt (/ (* c -4.0) a)) (- -0.5)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-238) {
tmp = b / -a;
} else if (b <= 2e-205) {
tmp = sqrt(((c * -4.0) / a)) * -(-0.5);
} 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 <= (-2d-238)) then
tmp = b / -a
else if (b <= 2d-205) then
tmp = sqrt(((c * (-4.0d0)) / a)) * -(-0.5d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-238) {
tmp = b / -a;
} else if (b <= 2e-205) {
tmp = Math.sqrt(((c * -4.0) / a)) * -(-0.5);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-238: tmp = b / -a elif b <= 2e-205: tmp = math.sqrt(((c * -4.0) / a)) * -(-0.5) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-238) tmp = Float64(b / Float64(-a)); elseif (b <= 2e-205) tmp = Float64(sqrt(Float64(Float64(c * -4.0) / a)) * Float64(-(-0.5))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-238) tmp = b / -a; elseif (b <= 2e-205) tmp = sqrt(((c * -4.0) / a)) * -(-0.5); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-238], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2e-205], N[(N[Sqrt[N[(N[(c * -4.0), $MachinePrecision] / a), $MachinePrecision]], $MachinePrecision] * (--0.5)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-238}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-205}:\\
\;\;\;\;\sqrt{\frac{c \cdot -4}{a}} \cdot \left(--0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2e-238Initial program 73.5%
*-commutative73.5%
Simplified73.5%
Taylor expanded in b around -inf 77.0%
associate-*r/77.0%
mul-1-neg77.0%
Simplified77.0%
if -2e-238 < b < 2e-205Initial program 80.9%
*-commutative80.9%
Simplified80.9%
add-cube-cbrt80.1%
pow379.9%
Applied egg-rr79.9%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt49.6%
rem-cube-cbrt49.7%
Simplified49.7%
if 2e-205 < b Initial program 27.3%
*-commutative27.3%
Simplified27.3%
Taylor expanded in a around 0 73.3%
associate-*r/73.3%
mul-1-neg73.3%
Simplified73.3%
Final simplification71.9%
(FPCore (a b c) :precision binary64 (if (<= b 3.05e-289) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.05e-289) {
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 <= 3.05d-289) 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 <= 3.05e-289) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.05e-289: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.05e-289) 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 <= 3.05e-289) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.05e-289], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.05 \cdot 10^{-289}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 3.0499999999999999e-289Initial program 73.5%
*-commutative73.5%
Simplified73.5%
Taylor expanded in b around -inf 67.3%
associate-*r/67.3%
mul-1-neg67.3%
Simplified67.3%
if 3.0499999999999999e-289 < b Initial program 35.1%
*-commutative35.1%
Simplified35.1%
Taylor expanded in a around 0 65.4%
associate-*r/65.4%
mul-1-neg65.4%
Simplified65.4%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b 6.2e-51) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.2e-51) {
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 <= 6.2d-51) 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 <= 6.2e-51) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.2e-51: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.2e-51) 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 <= 6.2e-51) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.2e-51], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.2 \cdot 10^{-51}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 6.1999999999999995e-51Initial program 72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in b around -inf 51.9%
associate-*r/51.9%
mul-1-neg51.9%
Simplified51.9%
if 6.1999999999999995e-51 < b Initial program 16.0%
*-commutative16.0%
Simplified16.0%
add-exp-log7.2%
Applied egg-rr7.2%
rem-exp-log16.0%
clear-num16.0%
inv-pow16.0%
add-sqr-sqrt0.0%
sqrt-unprod8.0%
sqr-neg8.0%
sqrt-prod8.0%
add-sqr-sqrt8.0%
pow28.0%
*-commutative8.0%
*-commutative8.0%
Applied egg-rr8.0%
unpow-18.0%
unpow28.0%
fma-neg8.0%
associate-*r*8.0%
*-commutative8.0%
distribute-rgt-neg-in8.0%
*-commutative8.0%
metadata-eval8.0%
Simplified8.0%
Taylor expanded in b around -inf 21.0%
Final simplification42.6%
(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 55.5%
*-commutative55.5%
Simplified55.5%
add-exp-log27.4%
Applied egg-rr27.4%
rem-exp-log55.5%
clear-num55.4%
inv-pow55.4%
add-sqr-sqrt37.8%
sqrt-unprod52.7%
sqr-neg52.7%
sqrt-prod15.2%
add-sqr-sqrt33.2%
pow233.2%
*-commutative33.2%
*-commutative33.2%
Applied egg-rr33.2%
unpow-133.2%
unpow233.2%
fma-neg33.2%
associate-*r*33.2%
*-commutative33.2%
distribute-rgt-neg-in33.2%
*-commutative33.2%
metadata-eval33.2%
Simplified33.2%
Taylor expanded in b around -inf 8.4%
(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 55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in b around -inf 37.1%
associate-*r/37.1%
mul-1-neg37.1%
Simplified37.1%
div-inv37.0%
add-sqr-sqrt35.5%
sqrt-unprod27.5%
sqr-neg27.5%
sqrt-prod1.9%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
associate-*r/2.7%
*-rgt-identity2.7%
Simplified2.7%
(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 2024125
(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)))