
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -6.5e-67)
(/ c (- b))
(if (<= b 1e+127)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-67) {
tmp = c / -b;
} else if (b <= 1e+127) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * 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 <= (-6.5d-67)) then
tmp = c / -b
else if (b <= 1d+127) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * 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 <= -6.5e-67) {
tmp = c / -b;
} else if (b <= 1e+127) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.5e-67: tmp = c / -b elif b <= 1e+127: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.5e-67) tmp = Float64(c / Float64(-b)); elseif (b <= 1e+127) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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 <= -6.5e-67) tmp = c / -b; elseif (b <= 1e+127) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.5e-67], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1e+127], 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[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.5 \cdot 10^{-67}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 10^{+127}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.4999999999999997e-67Initial program 17.8%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*15.9%
distribute-neg-frac15.9%
neg-mul-115.9%
*-commutative15.9%
associate-/l*17.6%
distribute-rgt-out17.8%
associate-/r*17.8%
metadata-eval17.8%
sub-neg17.8%
+-commutative17.8%
Simplified17.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -6.4999999999999997e-67 < b < 9.99999999999999955e126Initial program 81.4%
*-commutative81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
associate-*r*81.4%
Simplified81.4%
if 9.99999999999999955e126 < b Initial program 53.4%
div-sub53.4%
sub-neg53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.4%
distribute-neg-frac53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.4%
distribute-rgt-out53.4%
associate-/r*53.4%
metadata-eval53.4%
sub-neg53.4%
+-commutative53.4%
Simplified53.5%
Taylor expanded in a around 0 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-67)
(/ c (- b))
(if (<= b 4e+124)
(/ (- (- 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 <= -9e-67) {
tmp = c / -b;
} else if (b <= 4e+124) {
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 <= (-9d-67)) then
tmp = c / -b
else if (b <= 4d+124) 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 <= -9e-67) {
tmp = c / -b;
} else if (b <= 4e+124) {
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 <= -9e-67: tmp = c / -b elif b <= 4e+124: 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 <= -9e-67) tmp = Float64(c / Float64(-b)); elseif (b <= 4e+124) 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 <= -9e-67) tmp = c / -b; elseif (b <= 4e+124) 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, -9e-67], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4e+124], 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 -9 \cdot 10^{-67}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+124}:\\
\;\;\;\;\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 < -9.00000000000000031e-67Initial program 17.8%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*15.9%
distribute-neg-frac15.9%
neg-mul-115.9%
*-commutative15.9%
associate-/l*17.6%
distribute-rgt-out17.8%
associate-/r*17.8%
metadata-eval17.8%
sub-neg17.8%
+-commutative17.8%
Simplified17.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -9.00000000000000031e-67 < b < 3.99999999999999979e124Initial program 81.4%
if 3.99999999999999979e124 < b Initial program 53.4%
div-sub53.4%
sub-neg53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.4%
distribute-neg-frac53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.4%
distribute-rgt-out53.4%
associate-/r*53.4%
metadata-eval53.4%
sub-neg53.4%
+-commutative53.4%
Simplified53.5%
Taylor expanded in a around 0 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-67)
(/ c (- b))
(if (<= b 1.6e-100)
(* (/ -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 <= -9e-67) {
tmp = c / -b;
} else if (b <= 1.6e-100) {
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 <= (-9d-67)) then
tmp = c / -b
else if (b <= 1.6d-100) 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 <= -9e-67) {
tmp = c / -b;
} else if (b <= 1.6e-100) {
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 <= -9e-67: tmp = c / -b elif b <= 1.6e-100: 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 <= -9e-67) tmp = Float64(c / Float64(-b)); elseif (b <= 1.6e-100) 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 <= -9e-67) tmp = c / -b; elseif (b <= 1.6e-100) 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, -9e-67], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.6e-100], 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 -9 \cdot 10^{-67}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-100}:\\
\;\;\;\;\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 < -9.00000000000000031e-67Initial program 17.8%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*15.9%
distribute-neg-frac15.9%
neg-mul-115.9%
*-commutative15.9%
associate-/l*17.6%
distribute-rgt-out17.8%
associate-/r*17.8%
metadata-eval17.8%
sub-neg17.8%
+-commutative17.8%
Simplified17.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -9.00000000000000031e-67 < b < 1.60000000000000008e-100Initial program 76.6%
div-sub76.6%
sub-neg76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.6%
distribute-neg-frac76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.4%
distribute-rgt-out76.4%
associate-/r*76.4%
metadata-eval76.4%
sub-neg76.4%
+-commutative76.4%
Simplified76.4%
Taylor expanded in a around inf 73.8%
*-commutative73.8%
Simplified73.8%
if 1.60000000000000008e-100 < b Initial program 72.7%
div-sub72.7%
sub-neg72.7%
neg-mul-172.7%
*-commutative72.7%
associate-/l*72.6%
distribute-neg-frac72.6%
neg-mul-172.6%
*-commutative72.6%
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 80.7%
+-commutative80.7%
mul-1-neg80.7%
unsub-neg80.7%
Simplified80.7%
Final simplification80.8%
(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.4%
div-sub36.2%
sub-neg36.2%
neg-mul-136.2%
*-commutative36.2%
associate-/l*35.0%
distribute-neg-frac35.0%
neg-mul-135.0%
*-commutative35.0%
associate-/l*36.1%
distribute-rgt-out36.3%
associate-/r*36.3%
metadata-eval36.3%
sub-neg36.3%
+-commutative36.3%
Simplified36.3%
Taylor expanded in b around -inf 63.1%
mul-1-neg63.1%
distribute-neg-frac263.1%
Simplified63.1%
if -9.999999999999969e-311 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.4%
distribute-neg-frac72.4%
neg-mul-172.4%
*-commutative72.4%
associate-/l*72.3%
distribute-rgt-out72.3%
associate-/r*72.3%
metadata-eval72.3%
sub-neg72.3%
+-commutative72.3%
Simplified72.4%
Taylor expanded in c around 0 66.2%
+-commutative66.2%
mul-1-neg66.2%
unsub-neg66.2%
Simplified66.2%
Final simplification64.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-266) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-266) {
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 <= (-5d-266)) 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 <= -5e-266) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-266: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-266) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-266) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-266], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-266}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.99999999999999992e-266Initial program 34.5%
div-sub34.3%
sub-neg34.3%
neg-mul-134.3%
*-commutative34.3%
associate-/l*33.1%
distribute-neg-frac33.1%
neg-mul-133.1%
*-commutative33.1%
associate-/l*34.3%
distribute-rgt-out34.5%
associate-/r*34.5%
metadata-eval34.5%
sub-neg34.5%
+-commutative34.5%
Simplified34.5%
Taylor expanded in b around -inf 65.6%
mul-1-neg65.6%
distribute-neg-frac265.6%
Simplified65.6%
if -4.99999999999999992e-266 < b Initial program 72.8%
div-sub72.8%
sub-neg72.8%
neg-mul-172.8%
*-commutative72.8%
associate-/l*72.7%
distribute-neg-frac72.7%
neg-mul-172.7%
*-commutative72.7%
associate-/l*72.6%
distribute-rgt-out72.6%
associate-/r*72.6%
metadata-eval72.6%
sub-neg72.6%
+-commutative72.6%
Simplified72.6%
Taylor expanded in a around 0 63.8%
associate-*r/63.8%
mul-1-neg63.8%
Simplified63.8%
Final simplification64.6%
(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.3%
div-sub55.2%
sub-neg55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*54.6%
distribute-neg-frac54.6%
neg-mul-154.6%
*-commutative54.6%
associate-/l*55.1%
distribute-rgt-out55.2%
associate-/r*55.2%
metadata-eval55.2%
sub-neg55.2%
+-commutative55.2%
Simplified55.2%
Taylor expanded in b around -inf 31.3%
mul-1-neg31.3%
distribute-neg-frac231.3%
Simplified31.3%
Final simplification31.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.3%
div-sub55.2%
sub-neg55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*54.6%
distribute-neg-frac54.6%
neg-mul-154.6%
*-commutative54.6%
associate-/l*55.1%
distribute-rgt-out55.2%
associate-/r*55.2%
metadata-eval55.2%
sub-neg55.2%
+-commutative55.2%
Simplified55.2%
associate-*l/55.3%
clear-num55.3%
*-commutative55.3%
pow255.3%
Applied egg-rr55.3%
Taylor expanded in a around 0 34.6%
Taylor expanded in a around inf 11.7%
Final simplification11.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 2024077
(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)))