
(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 -7e-70)
(/ c (- b))
(if (<= b 6.5e+52)
(/ (- (- 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 <= -7e-70) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
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 <= (-7d-70)) then
tmp = c / -b
else if (b <= 6.5d+52) 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 <= -7e-70) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
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 <= -7e-70: tmp = c / -b elif b <= 6.5e+52: 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 <= -7e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 6.5e+52) 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 <= -7e-70) tmp = c / -b; elseif (b <= 6.5e+52) 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, -7e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.5e+52], 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 -7 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{+52}:\\
\;\;\;\;\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 < -6.99999999999999949e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -6.99999999999999949e-70 < b < 6.49999999999999996e52Initial program 79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
associate-*r*79.1%
*-commutative79.1%
Simplified79.1%
if 6.49999999999999996e52 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-rgt-out72.5%
associate-/r*72.5%
metadata-eval72.5%
sub-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in c around 0 98.2%
+-commutative98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1e-69)
(/ c (- b))
(if (<= b 6.5e+52)
(/ (- (- 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 <= -1e-69) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
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 <= (-1d-69)) then
tmp = c / -b
else if (b <= 6.5d+52) 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 <= -1e-69) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
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 <= -1e-69: tmp = c / -b elif b <= 6.5e+52: 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 <= -1e-69) tmp = Float64(c / Float64(-b)); elseif (b <= 6.5e+52) 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 <= -1e-69) tmp = c / -b; elseif (b <= 6.5e+52) 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, -1e-69], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.5e+52], 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 -1 \cdot 10^{-69}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{+52}:\\
\;\;\;\;\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 < -9.9999999999999996e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -9.9999999999999996e-70 < b < 6.49999999999999996e52Initial program 79.0%
if 6.49999999999999996e52 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-rgt-out72.5%
associate-/r*72.5%
metadata-eval72.5%
sub-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in c around 0 98.2%
+-commutative98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -5.4e-70)
(/ c (- b))
(if (<= b 1.15e-122)
(* (/ -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 <= -5.4e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
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 <= (-5.4d-70)) then
tmp = c / -b
else if (b <= 1.15d-122) 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 <= -5.4e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
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 <= -5.4e-70: tmp = c / -b elif b <= 1.15e-122: 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 <= -5.4e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 1.15e-122) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * 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 <= -5.4e-70) tmp = c / -b; elseif (b <= 1.15e-122) 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, -5.4e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.15e-122], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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.4 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-122}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.4000000000000003e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -5.4000000000000003e-70 < b < 1.15000000000000003e-122Initial 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*69.0%
distribute-rgt-out69.0%
associate-/r*69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
Simplified69.0%
Taylor expanded in a around inf 65.5%
*-commutative65.5%
Simplified65.5%
if 1.15000000000000003e-122 < b Initial program 83.4%
div-sub83.4%
sub-neg83.4%
neg-mul-183.4%
*-commutative83.4%
associate-/l*83.3%
distribute-neg-frac83.3%
neg-mul-183.3%
*-commutative83.3%
associate-/l*83.2%
distribute-rgt-out83.2%
associate-/r*83.2%
metadata-eval83.2%
sub-neg83.2%
+-commutative83.2%
Simplified83.2%
Taylor expanded in c around 0 84.1%
+-commutative84.1%
mul-1-neg84.1%
unsub-neg84.1%
Simplified84.1%
Final simplification78.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 36.3%
div-sub35.3%
sub-neg35.3%
neg-mul-135.3%
*-commutative35.3%
associate-/l*34.4%
distribute-neg-frac34.4%
neg-mul-134.4%
*-commutative34.4%
associate-/l*35.1%
distribute-rgt-out36.2%
associate-/r*36.2%
metadata-eval36.2%
sub-neg36.2%
+-commutative36.2%
Simplified36.3%
Taylor expanded in b around -inf 60.8%
mul-1-neg60.8%
distribute-neg-frac260.8%
Simplified60.8%
if -3.999999999999988e-310 < b Initial program 81.1%
div-sub81.1%
sub-neg81.1%
neg-mul-181.1%
*-commutative81.1%
associate-/l*81.0%
distribute-neg-frac81.0%
neg-mul-181.0%
*-commutative81.0%
associate-/l*80.9%
distribute-rgt-out80.9%
associate-/r*80.9%
metadata-eval80.9%
sub-neg80.9%
+-commutative80.9%
Simplified80.9%
Taylor expanded in c around 0 70.0%
+-commutative70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
Final simplification64.9%
(FPCore (a b c) :precision binary64 (if (<= b -3.1e-287) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.1e-287) {
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 <= (-3.1d-287)) 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 <= -3.1e-287) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.1e-287: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.1e-287) 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 <= -3.1e-287) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.1e-287], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1 \cdot 10^{-287}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.1000000000000001e-287Initial program 36.5%
div-sub35.5%
sub-neg35.5%
neg-mul-135.5%
*-commutative35.5%
associate-/l*34.6%
distribute-neg-frac34.6%
neg-mul-134.6%
*-commutative34.6%
associate-/l*35.3%
distribute-rgt-out36.5%
associate-/r*36.5%
metadata-eval36.5%
sub-neg36.5%
+-commutative36.5%
Simplified36.5%
Taylor expanded in b around -inf 61.2%
mul-1-neg61.2%
distribute-neg-frac261.2%
Simplified61.2%
if -3.1000000000000001e-287 < b Initial program 80.4%
div-sub80.4%
sub-neg80.4%
neg-mul-180.4%
*-commutative80.4%
associate-/l*80.3%
distribute-neg-frac80.3%
neg-mul-180.3%
*-commutative80.3%
associate-/l*80.2%
distribute-rgt-out80.2%
associate-/r*80.2%
metadata-eval80.2%
sub-neg80.2%
+-commutative80.2%
Simplified80.2%
Taylor expanded in a around 0 69.2%
associate-*r/69.2%
mul-1-neg69.2%
Simplified69.2%
Final simplification64.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 / 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 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Taylor expanded in b around -inf 34.4%
mul-1-neg34.4%
distribute-neg-frac234.4%
Simplified34.4%
Final simplification34.4%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Applied egg-rr34.6%
Taylor expanded in b around -inf 2.8%
Final simplification2.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 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Applied egg-rr34.6%
Taylor expanded in a around 0 8.2%
Final simplification8.2%
(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 2024130
(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)))