
(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 -8.6e-103)
(/ (- c) b)
(if (<= b 1.55e+128)
(/ (- (- 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 <= -8.6e-103) {
tmp = -c / b;
} else if (b <= 1.55e+128) {
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 <= (-8.6d-103)) then
tmp = -c / b
else if (b <= 1.55d+128) 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 <= -8.6e-103) {
tmp = -c / b;
} else if (b <= 1.55e+128) {
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 <= -8.6e-103: tmp = -c / b elif b <= 1.55e+128: 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 <= -8.6e-103) tmp = Float64(Float64(-c) / b); elseif (b <= 1.55e+128) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(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 <= -8.6e-103) tmp = -c / b; elseif (b <= 1.55e+128) 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, -8.6e-103], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.55e+128], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * 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 -8.6 \cdot 10^{-103}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{+128}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.60000000000000045e-103Initial program 14.5%
*-commutative14.5%
sqr-neg14.5%
*-commutative14.5%
sqr-neg14.5%
associate-*r*14.5%
*-commutative14.5%
Simplified14.5%
Taylor expanded in b around -inf 86.7%
mul-1-neg86.7%
Simplified86.7%
if -8.60000000000000045e-103 < b < 1.55000000000000002e128Initial program 83.8%
*-commutative83.8%
sqr-neg83.8%
*-commutative83.8%
sqr-neg83.8%
associate-*r*83.8%
*-commutative83.8%
Simplified83.8%
if 1.55000000000000002e128 < b Initial program 45.9%
*-commutative45.9%
sqr-neg45.9%
*-commutative45.9%
sqr-neg45.9%
associate-*r*45.9%
*-commutative45.9%
Simplified45.9%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -5.5e-96)
(/ (- c) b)
(if (<= b 5e+127)
(/ (- (- 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 <= -5.5e-96) {
tmp = -c / b;
} else if (b <= 5e+127) {
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 <= (-5.5d-96)) then
tmp = -c / b
else if (b <= 5d+127) 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 <= -5.5e-96) {
tmp = -c / b;
} else if (b <= 5e+127) {
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 <= -5.5e-96: tmp = -c / b elif b <= 5e+127: 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 <= -5.5e-96) tmp = Float64(Float64(-c) / b); elseif (b <= 5e+127) 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 <= -5.5e-96) tmp = -c / b; elseif (b <= 5e+127) 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, -5.5e-96], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5e+127], 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 -5.5 \cdot 10^{-96}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+127}:\\
\;\;\;\;\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 < -5.4999999999999997e-96Initial program 14.5%
*-commutative14.5%
sqr-neg14.5%
*-commutative14.5%
sqr-neg14.5%
associate-*r*14.5%
*-commutative14.5%
Simplified14.5%
Taylor expanded in b around -inf 86.7%
mul-1-neg86.7%
Simplified86.7%
if -5.4999999999999997e-96 < b < 5.0000000000000004e127Initial program 83.8%
if 5.0000000000000004e127 < b Initial program 45.9%
*-commutative45.9%
sqr-neg45.9%
*-commutative45.9%
sqr-neg45.9%
associate-*r*45.9%
*-commutative45.9%
Simplified45.9%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.5e-103)
(/ (- c) b)
(if (<= b 2.4e-77)
(/ (- (- b) (sqrt (* (* c a) -4.0))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-103) {
tmp = -c / b;
} else if (b <= 2.4e-77) {
tmp = (-b - sqrt(((c * a) * -4.0))) / (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.5d-103)) then
tmp = -c / b
else if (b <= 2.4d-77) then
tmp = (-b - sqrt(((c * a) * (-4.0d0)))) / (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.5e-103) {
tmp = -c / b;
} else if (b <= 2.4e-77) {
tmp = (-b - Math.sqrt(((c * a) * -4.0))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-103: tmp = -c / b elif b <= 2.4e-77: tmp = (-b - math.sqrt(((c * a) * -4.0))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-103) tmp = Float64(Float64(-c) / b); elseif (b <= 2.4e-77) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(c * a) * -4.0))) / 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.5e-103) tmp = -c / b; elseif (b <= 2.4e-77) tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-103], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.4e-77], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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.5 \cdot 10^{-103}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-77}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.50000000000000032e-103Initial program 14.5%
*-commutative14.5%
sqr-neg14.5%
*-commutative14.5%
sqr-neg14.5%
associate-*r*14.5%
*-commutative14.5%
Simplified14.5%
Taylor expanded in b around -inf 86.7%
mul-1-neg86.7%
Simplified86.7%
if -8.50000000000000032e-103 < b < 2.3999999999999999e-77Initial program 75.4%
*-commutative75.4%
sqr-neg75.4%
*-commutative75.4%
sqr-neg75.4%
associate-*r*75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in b around 0 69.9%
if 2.3999999999999999e-77 < b Initial program 73.3%
*-commutative73.3%
sqr-neg73.3%
*-commutative73.3%
sqr-neg73.3%
associate-*r*73.3%
*-commutative73.3%
Simplified73.3%
Taylor expanded in b around inf 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
Final simplification81.5%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-101)
(/ (- c) b)
(if (<= b 5.4e-77)
(* (/ -0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-101) {
tmp = -c / b;
} else if (b <= 5.4e-77) {
tmp = (-0.5 / a) * (b + sqrt((a * (c * -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.2d-101)) then
tmp = -c / b
else if (b <= 5.4d-77) then
tmp = ((-0.5d0) / a) * (b + sqrt((a * (c * (-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.2e-101) {
tmp = -c / b;
} else if (b <= 5.4e-77) {
tmp = (-0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-101: tmp = -c / b elif b <= 5.4e-77: tmp = (-0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-101) tmp = Float64(Float64(-c) / b); elseif (b <= 5.4e-77) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -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.2e-101) tmp = -c / b; elseif (b <= 5.4e-77) tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-101], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.4e-77], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -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 -5.2 \cdot 10^{-101}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{-77}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.2000000000000002e-101Initial program 14.5%
*-commutative14.5%
sqr-neg14.5%
*-commutative14.5%
sqr-neg14.5%
associate-*r*14.5%
*-commutative14.5%
Simplified14.5%
Taylor expanded in b around -inf 86.7%
mul-1-neg86.7%
Simplified86.7%
if -5.2000000000000002e-101 < b < 5.4000000000000001e-77Initial program 75.4%
*-commutative75.4%
sqr-neg75.4%
*-commutative75.4%
sqr-neg75.4%
associate-*r*75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in b around 0 69.9%
frac-2neg69.9%
div-inv69.8%
neg-sub069.8%
add-sqr-sqrt36.1%
sqrt-unprod67.9%
sqr-neg67.9%
sqrt-prod32.1%
add-sqr-sqrt67.9%
associate-+l-67.9%
neg-sub067.9%
add-sqr-sqrt35.8%
sqrt-unprod68.6%
sqr-neg68.6%
sqrt-prod33.6%
add-sqr-sqrt69.8%
*-commutative69.8%
associate-*r*69.7%
distribute-rgt-neg-in69.7%
metadata-eval69.7%
metadata-eval69.7%
div-inv69.7%
Applied egg-rr69.7%
*-commutative69.7%
Simplified69.7%
if 5.4000000000000001e-77 < b Initial program 73.3%
*-commutative73.3%
sqr-neg73.3%
*-commutative73.3%
sqr-neg73.3%
associate-*r*73.3%
*-commutative73.3%
Simplified73.3%
Taylor expanded in b around inf 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
Final simplification81.5%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.1%
*-commutative31.1%
sqr-neg31.1%
*-commutative31.1%
sqr-neg31.1%
associate-*r*31.2%
*-commutative31.2%
Simplified31.2%
Taylor expanded in b around -inf 65.4%
mul-1-neg65.4%
Simplified65.4%
if -4.999999999999985e-310 < b Initial program 73.4%
*-commutative73.4%
sqr-neg73.4%
*-commutative73.4%
sqr-neg73.4%
associate-*r*73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in b around inf 67.5%
+-commutative67.5%
mul-1-neg67.5%
unsub-neg67.5%
Simplified67.5%
Final simplification66.5%
(FPCore (a b c) :precision binary64 (if (<= b -4e-304) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-304) {
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 <= (-4d-304)) 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 <= -4e-304) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-304: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-304) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-304) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-304], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-304}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.99999999999999988e-304Initial program 30.6%
*-commutative30.6%
sqr-neg30.6%
*-commutative30.6%
sqr-neg30.6%
associate-*r*30.6%
*-commutative30.6%
Simplified30.6%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
Simplified65.9%
if -3.99999999999999988e-304 < b Initial program 73.6%
*-commutative73.6%
sqr-neg73.6%
*-commutative73.6%
sqr-neg73.6%
associate-*r*73.6%
*-commutative73.6%
Simplified73.6%
Taylor expanded in b around inf 66.6%
associate-*r/66.6%
mul-1-neg66.6%
Simplified66.6%
Final simplification66.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(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 53.0%
*-commutative53.0%
sqr-neg53.0%
*-commutative53.0%
sqr-neg53.0%
associate-*r*53.0%
*-commutative53.0%
Simplified53.0%
Taylor expanded in b around -inf 32.9%
mul-1-neg32.9%
Simplified32.9%
Final simplification32.9%
(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 53.0%
*-commutative53.0%
sqr-neg53.0%
*-commutative53.0%
sqr-neg53.0%
associate-*r*53.0%
*-commutative53.0%
Simplified53.0%
Applied egg-rr19.0%
expm1-def33.5%
expm1-log1p53.0%
*-rgt-identity53.0%
associate-*r/52.9%
*-commutative52.9%
associate-/r*52.9%
metadata-eval52.9%
Simplified52.9%
Taylor expanded in b around -inf 25.5%
associate-*r/25.5%
clear-num25.4%
associate-*r/25.4%
Applied egg-rr25.4%
associate-/r/25.5%
associate-*l/25.5%
*-commutative25.5%
associate-*r*25.5%
metadata-eval25.5%
neg-mul-125.5%
distribute-neg-frac25.5%
associate-*r/27.8%
distribute-rgt-neg-in27.8%
distribute-frac-neg27.8%
Simplified27.8%
expm1-log1p-u24.8%
expm1-udef13.7%
associate-*r*13.8%
lft-mult-inverse13.8%
*-un-lft-identity13.8%
add-sqr-sqrt6.0%
sqrt-unprod12.3%
sqr-neg12.3%
sqrt-unprod5.9%
add-sqr-sqrt11.6%
Applied egg-rr11.6%
expm1-def11.4%
expm1-log1p11.9%
Simplified11.9%
Final simplification11.9%
(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 2023332
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))