
(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 8 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 -1.15e-57)
(/ (- c) b)
(if (<= b 1e+147)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-57) {
tmp = -c / b;
} else if (b <= 1e+147) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-1.15d-57)) then
tmp = -c / b
else if (b <= 1d+147) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-57) {
tmp = -c / b;
} else if (b <= 1e+147) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.15e-57: tmp = -c / b elif b <= 1e+147: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-57) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+147) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.15e-57) tmp = -c / b; elseif (b <= 1e+147) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-57], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+147], 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[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-57}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+147}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.15e-57Initial program 15.8%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
neg-mul-191.1%
Simplified91.1%
if -1.15e-57 < b < 9.9999999999999998e146Initial program 88.4%
if 9.9999999999999998e146 < b Initial program 37.7%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification91.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.45e-54)
(/ (- c) b)
(if (<= b 2e+143)
(* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.0))))) a))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e-54) {
tmp = -c / b;
} else if (b <= 2e+143) {
tmp = -0.5 * ((b + sqrt(((b * b) + (a * (c * -4.0))))) / a);
} 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 <= (-2.45d-54)) then
tmp = -c / b
else if (b <= 2d+143) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) + (a * (c * (-4.0d0)))))) / a)
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e-54) {
tmp = -c / b;
} else if (b <= 2e+143) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) + (a * (c * -4.0))))) / a);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.45e-54: tmp = -c / b elif b <= 2e+143: tmp = -0.5 * ((b + math.sqrt(((b * b) + (a * (c * -4.0))))) / a) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.45e-54) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+143) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0))))) / a)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.45e-54) tmp = -c / b; elseif (b <= 2e+143) tmp = -0.5 * ((b + sqrt(((b * b) + (a * (c * -4.0))))) / a); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.45e-54], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+143], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.45 \cdot 10^{-54}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+143}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.4500000000000001e-54Initial program 15.8%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
neg-mul-191.1%
Simplified91.1%
if -2.4500000000000001e-54 < b < 2e143Initial program 88.4%
/-rgt-identity88.4%
metadata-eval88.4%
associate-/l*88.3%
associate-/r/88.3%
*-commutative88.3%
metadata-eval88.3%
metadata-eval88.3%
associate-*l/88.3%
associate-/r/88.3%
times-frac88.4%
*-commutative88.4%
times-frac88.4%
metadata-eval88.4%
associate-/r/88.4%
*-commutative88.4%
div-sub88.5%
Simplified87.7%
fma-udef87.7%
Applied egg-rr87.7%
if 2e143 < b Initial program 37.7%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification90.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.1e-57)
(/ (- c) b)
(if (<= b 2.7e-65)
(* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-57) {
tmp = -c / b;
} else if (b <= 2.7e-65) {
tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a);
} 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.1d-57)) then
tmp = -c / b
else if (b <= 2.7d-65) then
tmp = (-0.5d0) * ((b + sqrt((c * (a * (-4.0d0))))) / a)
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.1e-57) {
tmp = -c / b;
} else if (b <= 2.7e-65) {
tmp = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-57: tmp = -c / b elif b <= 2.7e-65: tmp = -0.5 * ((b + math.sqrt((c * (a * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-57) tmp = Float64(Float64(-c) / b); elseif (b <= 2.7e-65) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / a)); 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.1e-57) tmp = -c / b; elseif (b <= 2.7e-65) tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-57], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.7e-65], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-57}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-65}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.09999999999999999e-57Initial program 15.8%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
neg-mul-191.1%
Simplified91.1%
if -1.09999999999999999e-57 < b < 2.6999999999999999e-65Initial program 82.1%
Simplified80.9%
Taylor expanded in a around inf 73.6%
*-commutative73.6%
*-commutative73.6%
*-commutative73.6%
associate-*l*73.6%
Simplified73.6%
if 2.6999999999999999e-65 < b Initial program 70.4%
Taylor expanded in b around inf 93.7%
mul-1-neg93.7%
unsub-neg93.7%
Simplified93.7%
Final simplification86.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-c) / 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 <= -2e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 34.9%
Taylor expanded in b around -inf 64.9%
associate-*r/64.9%
neg-mul-164.9%
Simplified64.9%
if -1.999999999999994e-310 < b Initial program 75.7%
Taylor expanded in b around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
Final simplification69.4%
(FPCore (a b c) :precision binary64 (if (<= b -920000.0) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -920000.0) {
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 <= (-920000.0d0)) 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 <= -920000.0) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -920000.0: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -920000.0) tmp = Float64(c / b); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -920000.0) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -920000.0], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -920000:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -9.2e5Initial program 16.3%
clear-num16.3%
inv-pow16.3%
Applied egg-rr7.6%
unpow-17.6%
unpow1/27.7%
metadata-eval7.7%
pow-sqr7.7%
pow-sqr7.7%
metadata-eval7.7%
unpow1/27.6%
*-commutative7.6%
associate-*r*7.6%
remove-double-neg7.6%
fma-neg7.6%
*-commutative7.6%
distribute-lft-neg-in7.6%
distribute-rgt-neg-in7.6%
metadata-eval7.6%
associate-*r*7.6%
unsub-neg7.6%
fma-udef7.6%
distribute-rgt-neg-in7.6%
Simplified7.6%
Taylor expanded in a around 0 30.2%
if -9.2e5 < b Initial program 70.7%
Taylor expanded in b around inf 52.3%
associate-*r/52.3%
mul-1-neg52.3%
Simplified52.3%
Final simplification46.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 34.9%
Taylor expanded in b around -inf 64.9%
associate-*r/64.9%
neg-mul-164.9%
Simplified64.9%
if -1.999999999999994e-310 < b Initial program 75.7%
Taylor expanded in b around inf 73.0%
associate-*r/73.0%
mul-1-neg73.0%
Simplified73.0%
Final simplification69.0%
(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.8%
clear-num55.7%
inv-pow55.7%
Applied egg-rr31.7%
unpow-131.7%
unpow1/231.8%
metadata-eval31.8%
pow-sqr32.0%
pow-sqr31.8%
metadata-eval31.8%
unpow1/231.7%
*-commutative31.7%
associate-*r*31.4%
remove-double-neg31.4%
fma-neg31.4%
*-commutative31.4%
distribute-lft-neg-in31.4%
distribute-rgt-neg-in31.4%
metadata-eval31.4%
associate-*r*31.7%
unsub-neg31.7%
fma-udef31.7%
distribute-rgt-neg-in31.7%
Simplified31.7%
Taylor expanded in b around -inf 2.4%
Taylor expanded in a around 0 2.4%
Final simplification2.4%
(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.8%
clear-num55.7%
inv-pow55.7%
Applied egg-rr31.7%
unpow-131.7%
unpow1/231.8%
metadata-eval31.8%
pow-sqr32.0%
pow-sqr31.8%
metadata-eval31.8%
unpow1/231.7%
*-commutative31.7%
associate-*r*31.4%
remove-double-neg31.4%
fma-neg31.4%
*-commutative31.4%
distribute-lft-neg-in31.4%
distribute-rgt-neg-in31.4%
metadata-eval31.4%
associate-*r*31.7%
unsub-neg31.7%
fma-udef31.7%
distribute-rgt-neg-in31.7%
Simplified31.7%
Taylor expanded in a around 0 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)
(/ 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 2023229
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))