
(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 11 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.5e-90)
(/ c (- b))
(if (<= b 1.85e+24)
(/ (- (- b) (pow (- (pow b 2.0) (* a (* c 4.0))) 0.5)) (* 2.0 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-90) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - pow((pow(b, 2.0) - (a * (c * 4.0))), 0.5)) / (2.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 <= (-7.5d-90)) then
tmp = c / -b
else if (b <= 1.85d+24) then
tmp = (-b - (((b ** 2.0d0) - (a * (c * 4.0d0))) ** 0.5d0)) / (2.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 <= -7.5e-90) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - Math.pow((Math.pow(b, 2.0) - (a * (c * 4.0))), 0.5)) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-90: tmp = c / -b elif b <= 1.85e+24: tmp = (-b - math.pow((math.pow(b, 2.0) - (a * (c * 4.0))), 0.5)) / (2.0 * a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-90) tmp = Float64(c / Float64(-b)); elseif (b <= 1.85e+24) tmp = Float64(Float64(Float64(-b) - (Float64((b ^ 2.0) - Float64(a * Float64(c * 4.0))) ^ 0.5)) / Float64(2.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 <= -7.5e-90) tmp = c / -b; elseif (b <= 1.85e+24) tmp = (-b - (((b ^ 2.0) - (a * (c * 4.0))) ^ 0.5)) / (2.0 * a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-90], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.85e+24], N[(N[((-b) - N[Power[N[(N[Power[b, 2.0], $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-90}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{+24}:\\
\;\;\;\;\frac{\left(-b\right) - {\left({b}^{2} - a \cdot \left(c \cdot 4\right)\right)}^{0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.4999999999999999e-90Initial program 18.1%
div-sub16.5%
sub-neg16.5%
neg-mul-116.5%
*-commutative16.5%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*16.5%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
if -7.4999999999999999e-90 < b < 1.85e24Initial program 83.5%
*-commutative83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
associate-*r*83.8%
Simplified83.8%
add-sqr-sqrt45.2%
pow245.2%
sqrt-prod45.2%
metadata-eval45.2%
Applied egg-rr45.2%
pow1/245.2%
pow245.2%
*-commutative45.2%
*-commutative45.2%
unpow-prod-down45.2%
pow245.2%
add-sqr-sqrt83.8%
metadata-eval83.8%
Applied egg-rr83.8%
if 1.85e24 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-89)
(/ c (- b))
(if (<= b 1.85e+24)
(/ (- (- b) (sqrt (- (* b b) (* a (* c 4.0))))) (* 2.0 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (2.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 <= (-2.35d-89)) then
tmp = c / -b
else if (b <= 1.85d+24) then
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0d0))))) / (2.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 <= -2.35e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - Math.sqrt(((b * b) - (a * (c * 4.0))))) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-89: tmp = c / -b elif b <= 1.85e+24: tmp = (-b - math.sqrt(((b * b) - (a * (c * 4.0))))) / (2.0 * a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-89) tmp = Float64(c / Float64(-b)); elseif (b <= 1.85e+24) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / Float64(2.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 <= -2.35e-89) tmp = c / -b; elseif (b <= 1.85e+24) tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (2.0 * a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-89], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.85e+24], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-89}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{+24}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.34999999999999998e-89Initial program 18.1%
div-sub16.5%
sub-neg16.5%
neg-mul-116.5%
*-commutative16.5%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*16.5%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
if -2.34999999999999998e-89 < b < 1.85e24Initial program 83.5%
*-commutative83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
sqr-neg83.5%
*-commutative83.5%
associate-*r*83.8%
Simplified83.8%
if 1.85e24 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -7.5e-89)
(/ c (- b))
(if (<= b 1.85e+24)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (2.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 <= (-7.5d-89)) then
tmp = c / -b
else if (b <= 1.85d+24) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (2.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 <= -7.5e-89) {
tmp = c / -b;
} else if (b <= 1.85e+24) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-89: tmp = c / -b elif b <= 1.85e+24: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-89) tmp = Float64(c / Float64(-b)); elseif (b <= 1.85e+24) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(2.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 <= -7.5e-89) tmp = c / -b; elseif (b <= 1.85e+24) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-89], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.85e+24], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-89}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{+24}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.4999999999999999e-89Initial program 18.1%
div-sub16.5%
sub-neg16.5%
neg-mul-116.5%
*-commutative16.5%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*16.5%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
if -7.4999999999999999e-89 < b < 1.85e24Initial program 83.5%
if 1.85e24 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.3%
distribute-rgt-out69.3%
associate-/r*69.3%
metadata-eval69.3%
sub-neg69.3%
+-commutative69.3%
Simplified69.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-104)
(/ c (- b))
(if (<= b 2.5e-81)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* 2.0 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-104) {
tmp = c / -b;
} else if (b <= 2.5e-81) {
tmp = (-b - sqrt((c * (a * -4.0)))) / (2.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 <= (-9d-104)) then
tmp = c / -b
else if (b <= 2.5d-81) then
tmp = (-b - sqrt((c * (a * (-4.0d0))))) / (2.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 <= -9e-104) {
tmp = c / -b;
} else if (b <= 2.5e-81) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (2.0 * a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-104: tmp = c / -b elif b <= 2.5e-81: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (2.0 * a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-104) tmp = Float64(c / Float64(-b)); elseif (b <= 2.5e-81) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0)))) / Float64(2.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 <= -9e-104) tmp = c / -b; elseif (b <= 2.5e-81) tmp = (-b - sqrt((c * (a * -4.0)))) / (2.0 * a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.5e-81], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.9999999999999995e-104Initial program 18.9%
div-sub17.3%
sub-neg17.3%
neg-mul-117.3%
*-commutative17.3%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*17.3%
distribute-rgt-out18.9%
associate-/r*18.9%
metadata-eval18.9%
sub-neg18.9%
+-commutative18.9%
Simplified18.9%
Taylor expanded in b around -inf 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
Simplified86.4%
if -8.9999999999999995e-104 < b < 2.4999999999999999e-81Initial program 76.8%
*-commutative76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
associate-*r*77.1%
Simplified77.1%
Taylor expanded in b around 0 71.1%
associate-*r*71.4%
*-commutative71.4%
Simplified71.4%
if 2.4999999999999999e-81 < b Initial program 76.8%
div-sub76.8%
sub-neg76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
sub-neg76.5%
+-commutative76.5%
Simplified76.7%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.55e-105)
(/ c (- b))
(if (<= b 2e-82)
(/ (sqrt (* (* c a) -4.0)) (* 2.0 (- a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-105) {
tmp = c / -b;
} else if (b <= 2e-82) {
tmp = sqrt(((c * a) * -4.0)) / (2.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.55d-105)) then
tmp = c / -b
else if (b <= 2d-82) then
tmp = sqrt(((c * a) * (-4.0d0))) / (2.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.55e-105) {
tmp = c / -b;
} else if (b <= 2e-82) {
tmp = Math.sqrt(((c * a) * -4.0)) / (2.0 * -a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.55e-105: tmp = c / -b elif b <= 2e-82: tmp = math.sqrt(((c * a) * -4.0)) / (2.0 * -a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.55e-105) tmp = Float64(c / Float64(-b)); elseif (b <= 2e-82) tmp = Float64(sqrt(Float64(Float64(c * a) * -4.0)) / Float64(2.0 * Float64(-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.55e-105) tmp = c / -b; elseif (b <= 2e-82) tmp = sqrt(((c * a) * -4.0)) / (2.0 * -a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.55e-105], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2e-82], N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] / N[(2.0 * (-a)), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-105}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-82}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4}}{2 \cdot \left(-a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.55000000000000007e-105Initial program 18.9%
div-sub17.3%
sub-neg17.3%
neg-mul-117.3%
*-commutative17.3%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*17.3%
distribute-rgt-out18.9%
associate-/r*18.9%
metadata-eval18.9%
sub-neg18.9%
+-commutative18.9%
Simplified18.9%
Taylor expanded in b around -inf 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
Simplified86.4%
if -1.55000000000000007e-105 < b < 2e-82Initial program 76.8%
*-commutative76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
sqr-neg76.8%
*-commutative76.8%
associate-*r*77.1%
Simplified77.1%
add-sqr-sqrt39.0%
pow239.0%
sqrt-prod39.0%
metadata-eval39.0%
Applied egg-rr39.0%
add-cube-cbrt38.6%
pow338.6%
*-commutative38.6%
*-commutative38.6%
unpow-prod-down38.6%
pow238.6%
add-sqr-sqrt76.5%
metadata-eval76.5%
Applied egg-rr76.5%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt69.9%
mul-1-neg69.9%
rem-cube-cbrt70.3%
associate-*r*69.9%
Simplified69.9%
if 2e-82 < b Initial program 76.8%
div-sub76.8%
sub-neg76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
sub-neg76.5%
+-commutative76.5%
Simplified76.7%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.95e-111)
(/ c (- b))
(if (<= b 5.8e-185)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-111) {
tmp = c / -b;
} else if (b <= 5.8e-185) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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.95d-111)) then
tmp = c / -b
else if (b <= 5.8d-185) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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.95e-111) {
tmp = c / -b;
} else if (b <= 5.8e-185) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-111: tmp = c / -b elif b <= 5.8e-185: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-111) tmp = Float64(c / Float64(-b)); elseif (b <= 5.8e-185) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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.95e-111) tmp = c / -b; elseif (b <= 5.8e-185) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-111], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.8e-185], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-111}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-185}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.9500000000000001e-111Initial program 18.9%
div-sub17.3%
sub-neg17.3%
neg-mul-117.3%
*-commutative17.3%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*17.3%
distribute-rgt-out18.9%
associate-/r*18.9%
metadata-eval18.9%
sub-neg18.9%
+-commutative18.9%
Simplified18.9%
Taylor expanded in b around -inf 86.4%
mul-1-neg86.4%
distribute-neg-frac286.4%
Simplified86.4%
if -1.9500000000000001e-111 < b < 5.79999999999999989e-185Initial program 72.9%
*-commutative72.9%
*-commutative72.9%
sqr-neg72.9%
*-commutative72.9%
sqr-neg72.9%
*-commutative72.9%
associate-*r*73.4%
Simplified73.4%
add-sqr-sqrt32.3%
pow232.3%
sqrt-prod32.3%
metadata-eval32.3%
Applied egg-rr32.3%
add-cube-cbrt32.0%
pow332.0%
*-commutative32.0%
*-commutative32.0%
unpow-prod-down32.0%
pow232.0%
add-sqr-sqrt72.8%
metadata-eval72.8%
Applied egg-rr72.8%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt40.3%
neg-mul-140.3%
rem-cube-cbrt40.5%
associate-/l*40.4%
Simplified40.4%
if 5.79999999999999989e-185 < b Initial program 78.1%
div-sub78.1%
sub-neg78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*78.0%
distribute-neg-frac78.0%
neg-mul-178.0%
*-commutative78.0%
associate-/l*77.9%
distribute-rgt-out77.9%
associate-/r*77.9%
metadata-eval77.9%
sub-neg77.9%
+-commutative77.9%
Simplified78.0%
Taylor expanded in c around 0 78.6%
+-commutative78.6%
mul-1-neg78.6%
unsub-neg78.6%
Simplified78.6%
Final simplification75.4%
(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 27.4%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*25.9%
distribute-neg-frac25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*26.1%
distribute-rgt-out27.4%
associate-/r*27.4%
metadata-eval27.4%
sub-neg27.4%
+-commutative27.4%
Simplified27.4%
Taylor expanded in b around -inf 74.4%
mul-1-neg74.4%
distribute-neg-frac274.4%
Simplified74.4%
if -9.999999999999969e-311 < b Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.1%
distribute-rgt-out77.1%
associate-/r*77.1%
metadata-eval77.1%
sub-neg77.1%
+-commutative77.1%
Simplified77.4%
Taylor expanded in c around 0 66.8%
+-commutative66.8%
mul-1-neg66.8%
unsub-neg66.8%
Simplified66.8%
(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(b / Float64(-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 27.4%
div-sub26.1%
sub-neg26.1%
neg-mul-126.1%
*-commutative26.1%
associate-/l*25.9%
distribute-neg-frac25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*26.1%
distribute-rgt-out27.4%
associate-/r*27.4%
metadata-eval27.4%
sub-neg27.4%
+-commutative27.4%
Simplified27.4%
Taylor expanded in b around -inf 74.4%
mul-1-neg74.4%
distribute-neg-frac274.4%
Simplified74.4%
if -9.999999999999969e-311 < b Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.1%
distribute-rgt-out77.1%
associate-/r*77.1%
metadata-eval77.1%
sub-neg77.1%
+-commutative77.1%
Simplified77.4%
Taylor expanded in a around 0 66.5%
associate-*r/66.5%
mul-1-neg66.5%
Simplified66.5%
Final simplification70.0%
(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 55.1%
div-sub54.5%
sub-neg54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.4%
distribute-neg-frac54.4%
neg-mul-154.4%
*-commutative54.4%
associate-/l*54.4%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.1%
Taylor expanded in b around -inf 34.3%
mul-1-neg34.3%
distribute-neg-frac234.3%
Simplified34.3%
(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.1%
div-sub54.5%
sub-neg54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.4%
distribute-neg-frac54.4%
neg-mul-154.4%
*-commutative54.4%
associate-/l*54.4%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.1%
Taylor expanded in b around -inf 34.3%
mul-1-neg34.3%
distribute-neg-frac234.3%
Simplified34.3%
add-sqr-sqrt33.0%
sqrt-unprod26.7%
sqr-neg26.7%
sqrt-prod2.1%
add-sqr-sqrt12.3%
div-inv12.3%
Applied egg-rr12.3%
associate-*r/12.3%
*-rgt-identity12.3%
Simplified12.3%
(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.1%
div-sub54.5%
sub-neg54.5%
neg-mul-154.5%
*-commutative54.5%
associate-/l*54.4%
distribute-neg-frac54.4%
neg-mul-154.4%
*-commutative54.4%
associate-/l*54.4%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.1%
Taylor expanded in a around 0 38.1%
associate-*r/38.1%
mul-1-neg38.1%
Simplified38.1%
div-inv38.0%
add-sqr-sqrt1.2%
sqrt-unprod1.9%
sqr-neg1.9%
sqrt-prod0.7%
add-sqr-sqrt2.4%
Applied egg-rr2.4%
associate-*r/2.4%
*-rgt-identity2.4%
Simplified2.4%
(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 2024110
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(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)))