
(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 9 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 -8.2e-57)
(/ c (- b))
(if (<= b 1.55e+21)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-57) {
tmp = c / -b;
} else if (b <= 1.55e+21) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} 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 <= (-8.2d-57)) then
tmp = c / -b
else if (b <= 1.55d+21) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * a)))) / (a * 2.0d0)
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 <= -8.2e-57) {
tmp = c / -b;
} else if (b <= 1.55e+21) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.2e-57: tmp = c / -b elif b <= 1.55e+21: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.2e-57) tmp = Float64(c / Float64(-b)); elseif (b <= 1.55e+21) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); 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 <= -8.2e-57) tmp = c / -b; elseif (b <= 1.55e+21) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.2e-57], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.55e+21], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-57}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{+21}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.2000000000000003e-57Initial program 20.4%
div-sub20.1%
sub-neg20.1%
neg-mul-120.1%
*-commutative20.1%
associate-/l*17.6%
distribute-neg-frac17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*20.1%
distribute-rgt-out20.4%
associate-/r*20.4%
metadata-eval20.4%
sub-neg20.4%
+-commutative20.4%
Simplified20.5%
Taylor expanded in b around -inf 81.1%
mul-1-neg81.1%
distribute-neg-frac281.1%
Simplified81.1%
if -8.2000000000000003e-57 < b < 1.55e21Initial program 74.1%
*-commutative74.1%
sqr-neg74.1%
*-commutative74.1%
sqr-neg74.1%
*-commutative74.1%
associate-*r*74.1%
*-commutative74.1%
Simplified74.1%
if 1.55e21 < b Initial program 65.7%
div-sub65.7%
sub-neg65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.6%
distribute-neg-frac65.6%
neg-mul-165.6%
*-commutative65.6%
associate-/l*65.6%
distribute-rgt-out65.6%
associate-/r*65.6%
metadata-eval65.6%
sub-neg65.6%
+-commutative65.6%
Simplified65.6%
Taylor expanded in c around 0 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.2e-56)
(/ c (- b))
(if (<= b 7e+21)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-56) {
tmp = c / -b;
} else if (b <= 7e+21) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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.2d-56)) then
tmp = c / -b
else if (b <= 7d+21) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
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.2e-56) {
tmp = c / -b;
} else if (b <= 7e+21) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e-56: tmp = c / -b elif b <= 7e+21: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e-56) tmp = Float64(c / Float64(-b)); elseif (b <= 7e+21) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); 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.2e-56) tmp = c / -b; elseif (b <= 7e+21) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e-56], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7e+21], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{+21}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.20000000000000004e-56Initial program 20.4%
div-sub20.1%
sub-neg20.1%
neg-mul-120.1%
*-commutative20.1%
associate-/l*17.6%
distribute-neg-frac17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*20.1%
distribute-rgt-out20.4%
associate-/r*20.4%
metadata-eval20.4%
sub-neg20.4%
+-commutative20.4%
Simplified20.5%
Taylor expanded in b around -inf 81.1%
mul-1-neg81.1%
distribute-neg-frac281.1%
Simplified81.1%
if -2.20000000000000004e-56 < b < 7e21Initial program 74.1%
if 7e21 < b Initial program 65.7%
div-sub65.7%
sub-neg65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.6%
distribute-neg-frac65.6%
neg-mul-165.6%
*-commutative65.6%
associate-/l*65.6%
distribute-rgt-out65.6%
associate-/r*65.6%
metadata-eval65.6%
sub-neg65.6%
+-commutative65.6%
Simplified65.6%
Taylor expanded in c around 0 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-54)
(/ c (- b))
(if (<= b 7e-101)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-54) {
tmp = c / -b;
} else if (b <= 7e-101) {
tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0))));
} 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.1d-54)) then
tmp = c / -b
else if (b <= 7d-101) then
tmp = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.0d0)))))
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.1e-54) {
tmp = c / -b;
} else if (b <= 7e-101) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-54: tmp = c / -b elif b <= 7e-101: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-54) tmp = Float64(c / Float64(-b)); elseif (b <= 7e-101) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); 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.1e-54) tmp = c / -b; elseif (b <= 7e-101) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-54], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7e-101], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-54}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-101}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.1e-54Initial program 20.4%
div-sub20.1%
sub-neg20.1%
neg-mul-120.1%
*-commutative20.1%
associate-/l*17.6%
distribute-neg-frac17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*20.1%
distribute-rgt-out20.4%
associate-/r*20.4%
metadata-eval20.4%
sub-neg20.4%
+-commutative20.4%
Simplified20.5%
Taylor expanded in b around -inf 81.1%
mul-1-neg81.1%
distribute-neg-frac281.1%
Simplified81.1%
if -2.1e-54 < b < 6.99999999999999989e-101Initial program 69.1%
div-sub69.1%
sub-neg69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.1%
distribute-neg-frac69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*68.9%
distribute-rgt-out69.0%
associate-/r*69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
Simplified69.0%
Taylor expanded in a around inf 64.3%
metadata-eval64.3%
distribute-lft-neg-in64.3%
associate-*r*64.4%
*-commutative64.4%
distribute-rgt-neg-in64.4%
distribute-lft-neg-in64.4%
metadata-eval64.4%
*-commutative64.4%
Simplified64.4%
if 6.99999999999999989e-101 < b Initial program 71.6%
div-sub71.6%
sub-neg71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.6%
distribute-neg-frac71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.4%
distribute-rgt-out71.5%
associate-/r*71.5%
metadata-eval71.5%
sub-neg71.5%
+-commutative71.5%
Simplified71.5%
Taylor expanded in c around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
Simplified91.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-122)
(/ c (- b))
(if (<= b 1.92e-140)
(* 0.5 (- (sqrt (* c (/ -4.0 a)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-122) {
tmp = c / -b;
} else if (b <= 1.92e-140) {
tmp = 0.5 * -sqrt((c * (-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 <= (-5.8d-122)) then
tmp = c / -b
else if (b <= 1.92d-140) then
tmp = 0.5d0 * -sqrt((c * ((-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 <= -5.8e-122) {
tmp = c / -b;
} else if (b <= 1.92e-140) {
tmp = 0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-122: tmp = c / -b elif b <= 1.92e-140: tmp = 0.5 * -math.sqrt((c * (-4.0 / a))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-122) tmp = Float64(c / Float64(-b)); elseif (b <= 1.92e-140) tmp = Float64(0.5 * Float64(-sqrt(Float64(c * Float64(-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 <= -5.8e-122) tmp = c / -b; elseif (b <= 1.92e-140) tmp = 0.5 * -sqrt((c * (-4.0 / a))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-122], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.92e-140], N[(0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-122}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.92 \cdot 10^{-140}:\\
\;\;\;\;0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.8000000000000005e-122Initial program 23.1%
div-sub22.8%
sub-neg22.8%
neg-mul-122.8%
*-commutative22.8%
associate-/l*20.6%
distribute-neg-frac20.6%
neg-mul-120.6%
*-commutative20.6%
associate-/l*22.8%
distribute-rgt-out23.1%
associate-/r*23.1%
metadata-eval23.1%
sub-neg23.1%
+-commutative23.1%
Simplified23.1%
Taylor expanded in b around -inf 76.6%
mul-1-neg76.6%
distribute-neg-frac276.6%
Simplified76.6%
if -5.8000000000000005e-122 < b < 1.9200000000000001e-140Initial program 67.3%
*-commutative67.3%
sqr-neg67.3%
*-commutative67.3%
sqr-neg67.3%
*-commutative67.3%
associate-*r*67.4%
*-commutative67.4%
Simplified67.4%
add-cube-cbrt66.9%
pow366.8%
*-commutative66.8%
associate-*l*66.8%
Applied egg-rr66.8%
Taylor expanded in c around -inf 0.0%
rem-cube-cbrt0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt40.5%
Simplified40.5%
if 1.9200000000000001e-140 < b Initial program 74.1%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.1%
distribute-neg-frac74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.0%
Taylor expanded in c around 0 86.1%
+-commutative86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
Final simplification72.7%
(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 36.7%
div-sub36.5%
sub-neg36.5%
neg-mul-136.5%
*-commutative36.5%
associate-/l*34.8%
distribute-neg-frac34.8%
neg-mul-134.8%
*-commutative34.8%
associate-/l*36.4%
distribute-rgt-out36.7%
associate-/r*36.7%
metadata-eval36.7%
sub-neg36.7%
+-commutative36.7%
Simplified36.7%
Taylor expanded in b around -inf 61.4%
mul-1-neg61.4%
distribute-neg-frac261.4%
Simplified61.4%
if -9.999999999999969e-311 < b Initial program 70.5%
div-sub70.5%
sub-neg70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.5%
distribute-neg-frac70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.4%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified70.4%
Taylor expanded in c around 0 73.1%
+-commutative73.1%
mul-1-neg73.1%
unsub-neg73.1%
Simplified73.1%
(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 36.7%
div-sub36.5%
sub-neg36.5%
neg-mul-136.5%
*-commutative36.5%
associate-/l*34.8%
distribute-neg-frac34.8%
neg-mul-134.8%
*-commutative34.8%
associate-/l*36.4%
distribute-rgt-out36.7%
associate-/r*36.7%
metadata-eval36.7%
sub-neg36.7%
+-commutative36.7%
Simplified36.7%
Taylor expanded in b around -inf 61.4%
mul-1-neg61.4%
distribute-neg-frac261.4%
Simplified61.4%
if -9.999999999999969e-311 < b Initial program 70.5%
div-sub70.5%
sub-neg70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.5%
distribute-neg-frac70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.4%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified70.4%
Taylor expanded in a around 0 72.7%
associate-*r/72.7%
mul-1-neg72.7%
Simplified72.7%
Final simplification67.5%
(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-sub55.0%
sub-neg55.0%
neg-mul-155.0%
*-commutative55.0%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.9%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.0%
Taylor expanded in b around -inf 29.4%
mul-1-neg29.4%
distribute-neg-frac229.4%
Simplified29.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.1%
div-sub55.0%
sub-neg55.0%
neg-mul-155.0%
*-commutative55.0%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.9%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.0%
Applied egg-rr30.3%
Taylor expanded in a around 0 8.8%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 55.1%
div-sub55.0%
sub-neg55.0%
neg-mul-155.0%
*-commutative55.0%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.9%
distribute-rgt-out55.0%
associate-/r*55.0%
metadata-eval55.0%
sub-neg55.0%
+-commutative55.0%
Simplified55.0%
Applied egg-rr30.3%
Taylor expanded in b around -inf 2.7%
(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 2024188
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))