
(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 -7.2e+107)
(/ (- b) a)
(if (<= b 6e-144)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e+107) {
tmp = -b / a;
} else if (b <= 6e-144) {
tmp = (sqrt(((b * b) - (4.0 * (a * 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 <= (-7.2d+107)) then
tmp = -b / a
else if (b <= 6d-144) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * 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 <= -7.2e+107) {
tmp = -b / a;
} else if (b <= 6e-144) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e+107: tmp = -b / a elif b <= 6e-144: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e+107) tmp = Float64(Float64(-b) / a); elseif (b <= 6e-144) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e+107) tmp = -b / a; elseif (b <= 6e-144) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e+107], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 6e-144], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $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 -7.2 \cdot 10^{+107}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-144}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.1999999999999995e107Initial program 44.2%
neg-sub044.2%
associate-+l-44.2%
sub0-neg44.2%
neg-mul-144.2%
*-commutative44.2%
associate-*r/44.1%
Simplified44.1%
Taylor expanded in b around -inf 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
if -7.1999999999999995e107 < b < 5.9999999999999997e-144Initial program 87.1%
if 5.9999999999999997e-144 < b Initial program 16.4%
neg-sub016.4%
associate-+l-16.4%
sub0-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-*r/16.4%
Simplified16.4%
Taylor expanded in b around inf 80.6%
associate-*r/80.6%
neg-mul-180.6%
Simplified80.6%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e+106)
(/ (- b) a)
(if (<= b 7.3e-144)
(* (- b (sqrt (- (* b b) (* a (* 4.0 c))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e+106) {
tmp = -b / a;
} else if (b <= 7.3e-144) {
tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-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 <= (-5.8d+106)) then
tmp = -b / a
else if (b <= 7.3d-144) then
tmp = (b - sqrt(((b * b) - (a * (4.0d0 * c))))) * ((-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 <= -5.8e+106) {
tmp = -b / a;
} else if (b <= 7.3e-144) {
tmp = (b - Math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e+106: tmp = -b / a elif b <= 7.3e-144: tmp = (b - math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e+106) tmp = Float64(Float64(-b) / a); elseif (b <= 7.3e-144) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(4.0 * c))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e+106) tmp = -b / a; elseif (b <= 7.3e-144) tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e+106], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 7.3e-144], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(4.0 * c), $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 -5.8 \cdot 10^{+106}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 7.3 \cdot 10^{-144}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.8000000000000004e106Initial program 45.4%
neg-sub045.4%
associate-+l-45.4%
sub0-neg45.4%
neg-mul-145.4%
*-commutative45.4%
associate-*r/45.4%
Simplified45.4%
Taylor expanded in b around -inf 97.9%
associate-*r/97.9%
mul-1-neg97.9%
Simplified97.9%
if -5.8000000000000004e106 < b < 7.3000000000000003e-144Initial program 86.9%
neg-sub086.9%
associate-+l-86.9%
sub0-neg86.9%
neg-mul-186.9%
*-commutative86.9%
associate-*r/86.9%
Simplified86.9%
fma-udef86.9%
associate-*r*86.9%
metadata-eval86.9%
distribute-rgt-neg-in86.9%
*-commutative86.9%
+-commutative86.9%
sub-neg86.9%
*-commutative86.9%
associate-*l*86.9%
Applied egg-rr86.9%
if 7.3000000000000003e-144 < b Initial program 16.4%
neg-sub016.4%
associate-+l-16.4%
sub0-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-*r/16.4%
Simplified16.4%
Taylor expanded in b around inf 80.6%
associate-*r/80.6%
neg-mul-180.6%
Simplified80.6%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-155)
(- (/ c b) (/ b a))
(if (<= b 7.3e-144)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-155) {
tmp = (c / b) - (b / a);
} else if (b <= 7.3e-144) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.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.7d-155)) then
tmp = (c / b) - (b / a)
else if (b <= 7.3d-144) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.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.7e-155) {
tmp = (c / b) - (b / a);
} else if (b <= 7.3e-144) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-155: tmp = (c / b) - (b / a) elif b <= 7.3e-144: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-155) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7.3e-144) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.7e-155) tmp = (c / b) - (b / a); elseif (b <= 7.3e-144) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-155], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.3e-144], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-155}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7.3 \cdot 10^{-144}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.69999999999999981e-155Initial program 70.8%
neg-sub070.8%
associate-+l-70.8%
sub0-neg70.8%
neg-mul-170.8%
*-commutative70.8%
associate-*r/70.7%
Simplified70.7%
Taylor expanded in b around -inf 85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -2.69999999999999981e-155 < b < 7.3000000000000003e-144Initial program 79.6%
neg-sub079.6%
associate-+l-79.6%
sub0-neg79.6%
neg-mul-179.6%
*-commutative79.6%
associate-*r/79.6%
Simplified79.6%
Taylor expanded in a around inf 79.6%
*-commutative79.6%
*-commutative79.6%
associate-*r*79.6%
Simplified79.6%
if 7.3000000000000003e-144 < b Initial program 16.4%
neg-sub016.4%
associate-+l-16.4%
sub0-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-*r/16.4%
Simplified16.4%
Taylor expanded in b around inf 80.6%
associate-*r/80.6%
neg-mul-180.6%
Simplified80.6%
Final simplification82.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = (c / b) - (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 <= (-5d-311)) then
tmp = (c / b) - (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 <= -5e-311) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-311) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 70.5%
neg-sub070.5%
associate-+l-70.5%
sub0-neg70.5%
neg-mul-170.5%
*-commutative70.5%
associate-*r/70.4%
Simplified70.4%
Taylor expanded in b around -inf 66.6%
mul-1-neg66.6%
unsub-neg66.6%
Simplified66.6%
if -5.00000000000023e-311 < b Initial program 29.8%
neg-sub029.8%
associate-+l-29.8%
sub0-neg29.8%
neg-mul-129.8%
*-commutative29.8%
associate-*r/29.8%
Simplified29.8%
Taylor expanded in b around inf 67.6%
associate-*r/67.6%
neg-mul-167.6%
Simplified67.6%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (<= b 3.5e-22) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.5e-22) {
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.5d-22) 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.5e-22) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.5e-22: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.5e-22) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3.5e-22) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.5e-22], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-22}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.50000000000000005e-22Initial program 68.0%
neg-sub068.0%
associate-+l-68.0%
sub0-neg68.0%
neg-mul-168.0%
*-commutative68.0%
associate-*r/67.9%
Simplified67.9%
Taylor expanded in b around -inf 46.6%
associate-*r/46.6%
mul-1-neg46.6%
Simplified46.6%
if 3.50000000000000005e-22 < b Initial program 10.4%
neg-sub010.4%
associate-+l-10.4%
sub0-neg10.4%
neg-mul-110.4%
*-commutative10.4%
associate-*r/10.4%
Simplified10.4%
Taylor expanded in b around -inf 2.5%
mul-1-neg2.5%
unsub-neg2.5%
Simplified2.5%
Taylor expanded in c around inf 24.9%
Final simplification39.2%
(FPCore (a b c) :precision binary64 (if (<= b 1.9e-307) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.9e-307) {
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.9d-307) 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.9e-307) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.9e-307: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.9e-307) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.9e-307) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.9e-307], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{-307}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.89999999999999993e-307Initial program 70.9%
neg-sub070.9%
associate-+l-70.9%
sub0-neg70.9%
neg-mul-170.9%
*-commutative70.9%
associate-*r/70.9%
Simplified70.9%
Taylor expanded in b around -inf 64.9%
associate-*r/64.9%
mul-1-neg64.9%
Simplified64.9%
if 1.89999999999999993e-307 < b Initial program 28.8%
neg-sub028.8%
associate-+l-28.8%
sub0-neg28.8%
neg-mul-128.8%
*-commutative28.8%
associate-*r/28.8%
Simplified28.8%
Taylor expanded in b around inf 68.5%
associate-*r/68.5%
neg-mul-168.5%
Simplified68.5%
Final simplification66.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 48.4%
neg-sub048.4%
associate-+l-48.4%
sub0-neg48.4%
neg-mul-148.4%
*-commutative48.4%
associate-*r/48.4%
Simplified48.4%
Taylor expanded in b around -inf 31.6%
mul-1-neg31.6%
unsub-neg31.6%
Simplified31.6%
Taylor expanded in c around inf 10.5%
Final simplification10.5%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023201
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))