
(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 -1.2e-101)
(/ (- c) b)
(if (<= b 2e+146)
(/ (- (- 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 <= -1.2e-101) {
tmp = -c / b;
} else if (b <= 2e+146) {
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 <= (-1.2d-101)) then
tmp = -c / b
else if (b <= 2d+146) 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 <= -1.2e-101) {
tmp = -c / b;
} else if (b <= 2e+146) {
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 <= -1.2e-101: tmp = -c / b elif b <= 2e+146: 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 <= -1.2e-101) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+146) 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 <= -1.2e-101) tmp = -c / b; elseif (b <= 2e+146) 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, -1.2e-101], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+146], 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.2 \cdot 10^{-101}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+146}:\\
\;\;\;\;\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 < -1.2e-101Initial program 20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
associate-*r*20.4%
*-commutative20.4%
Simplified20.4%
Taylor expanded in b around -inf 83.3%
mul-1-neg83.3%
Simplified83.3%
if -1.2e-101 < b < 1.99999999999999987e146Initial program 86.7%
if 1.99999999999999987e146 < b Initial program 43.4%
*-commutative43.4%
sqr-neg43.4%
*-commutative43.4%
sqr-neg43.4%
*-commutative43.4%
associate-*r*43.4%
*-commutative43.4%
Simplified43.4%
Taylor expanded in b around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification87.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-102)
(/ (- c) b)
(if (<= b 5.5e-70)
(* -0.5 (/ 1.0 (/ a (+ b (sqrt (* c (* a -4.0)))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-102) {
tmp = -c / b;
} else if (b <= 5.5e-70) {
tmp = -0.5 * (1.0 / (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 <= (-1.45d-102)) then
tmp = -c / b
else if (b <= 5.5d-70) then
tmp = (-0.5d0) * (1.0d0 / (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 <= -1.45e-102) {
tmp = -c / b;
} else if (b <= 5.5e-70) {
tmp = -0.5 * (1.0 / (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 <= -1.45e-102: tmp = -c / b elif b <= 5.5e-70: tmp = -0.5 * (1.0 / (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 <= -1.45e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 5.5e-70) tmp = Float64(-0.5 * Float64(1.0 / Float64(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 <= -1.45e-102) tmp = -c / b; elseif (b <= 5.5e-70) tmp = -0.5 * (1.0 / (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, -1.45e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.5e-70], N[(-0.5 * N[(1.0 / N[(a / N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $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 -1.45 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-70}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{c \cdot \left(a \cdot -4\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.44999999999999993e-102Initial program 20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
associate-*r*20.4%
*-commutative20.4%
Simplified20.4%
Taylor expanded in b around -inf 83.3%
mul-1-neg83.3%
Simplified83.3%
if -1.44999999999999993e-102 < b < 5.5000000000000001e-70Initial program 79.7%
sub-neg79.7%
distribute-neg-out79.7%
neg-mul-179.7%
times-frac79.7%
metadata-eval79.7%
remove-double-neg79.7%
neg-sub079.7%
associate-+l-79.7%
Simplified79.7%
pow1/279.7%
pow-to-exp74.7%
Applied egg-rr74.7%
Taylor expanded in c around -inf 34.9%
mul-1-neg34.9%
unsub-neg34.9%
*-commutative34.9%
Simplified34.9%
clear-num34.9%
inv-pow34.9%
exp-prod27.7%
unpow1/227.7%
diff-log67.9%
add-exp-log72.3%
*-commutative72.3%
div-inv72.3%
times-frac72.3%
metadata-eval72.3%
Applied egg-rr72.3%
unpow-172.3%
*-commutative72.3%
associate-/r/72.3%
/-rgt-identity72.3%
*-commutative72.3%
associate-*r*72.3%
Simplified72.3%
if 5.5000000000000001e-70 < b Initial program 71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
associate-*r*71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around inf 89.3%
+-commutative89.3%
mul-1-neg89.3%
unsub-neg89.3%
Simplified89.3%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-102)
(/ (- c) b)
(if (<= b 2.7e-70)
(* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-102) {
tmp = -c / b;
} else if (b <= 2.7e-70) {
tmp = -0.5 * ((b + sqrt((c * (a * -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 <= (-1.8d-102)) then
tmp = -c / b
else if (b <= 2.7d-70) then
tmp = (-0.5d0) * ((b + sqrt((c * (a * (-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 <= -1.8e-102) {
tmp = -c / b;
} else if (b <= 2.7e-70) {
tmp = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-102: tmp = -c / b elif b <= 2.7e-70: tmp = -0.5 * ((b + math.sqrt((c * (a * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 2.7e-70) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -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 <= -1.8e-102) tmp = -c / b; elseif (b <= 2.7e-70) tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.7e-70], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-70}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.8e-102Initial program 20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
associate-*r*20.4%
*-commutative20.4%
Simplified20.4%
Taylor expanded in b around -inf 83.3%
mul-1-neg83.3%
Simplified83.3%
if -1.8e-102 < b < 2.7000000000000001e-70Initial program 79.7%
sub-neg79.7%
distribute-neg-out79.7%
neg-mul-179.7%
times-frac79.7%
metadata-eval79.7%
remove-double-neg79.7%
neg-sub079.7%
associate-+l-79.7%
Simplified79.7%
Taylor expanded in b around 0 72.3%
*-commutative72.3%
*-commutative72.3%
associate-*r*72.3%
Simplified72.3%
if 2.7000000000000001e-70 < b Initial program 71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
associate-*r*71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around inf 89.3%
+-commutative89.3%
mul-1-neg89.3%
unsub-neg89.3%
Simplified89.3%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-102)
(/ (- c) b)
(if (<= b 1.35e-69)
(* -0.5 (/ (sqrt (* c (* a -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-102) {
tmp = -c / b;
} else if (b <= 1.35e-69) {
tmp = -0.5 * (sqrt((c * (a * -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 <= (-4.6d-102)) then
tmp = -c / b
else if (b <= 1.35d-69) then
tmp = (-0.5d0) * (sqrt((c * (a * (-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 <= -4.6e-102) {
tmp = -c / b;
} else if (b <= 1.35e-69) {
tmp = -0.5 * (Math.sqrt((c * (a * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-102: tmp = -c / b elif b <= 1.35e-69: tmp = -0.5 * (math.sqrt((c * (a * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 1.35e-69) tmp = Float64(-0.5 * Float64(sqrt(Float64(c * Float64(a * -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 <= -4.6e-102) tmp = -c / b; elseif (b <= 1.35e-69) tmp = -0.5 * (sqrt((c * (a * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.35e-69], N[(-0.5 * N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-69}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.59999999999999973e-102Initial program 20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
sqr-neg20.4%
*-commutative20.4%
associate-*r*20.4%
*-commutative20.4%
Simplified20.4%
Taylor expanded in b around -inf 83.3%
mul-1-neg83.3%
Simplified83.3%
if -4.59999999999999973e-102 < b < 1.3499999999999999e-69Initial program 79.7%
sub-neg79.7%
distribute-neg-out79.7%
neg-mul-179.7%
times-frac79.7%
metadata-eval79.7%
remove-double-neg79.7%
neg-sub079.7%
associate-+l-79.7%
Simplified79.7%
pow1/279.7%
pow-to-exp74.7%
Applied egg-rr74.7%
Taylor expanded in c around -inf 34.9%
mul-1-neg34.9%
unsub-neg34.9%
*-commutative34.9%
Simplified34.9%
Taylor expanded in b around 0 34.7%
expm1-log1p-u34.7%
expm1-udef18.6%
*-commutative18.6%
diff-log38.9%
exp-to-pow38.9%
div-inv38.9%
times-frac38.9%
metadata-eval38.9%
Applied egg-rr38.9%
expm1-def69.2%
expm1-log1p71.4%
unpow1/271.4%
associate-/r/71.4%
/-rgt-identity71.4%
*-commutative71.4%
*-commutative71.4%
associate-*r*71.4%
Simplified71.4%
if 1.3499999999999999e-69 < b Initial program 71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
sqr-neg71.5%
*-commutative71.5%
associate-*r*71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around inf 89.3%
+-commutative89.3%
mul-1-neg89.3%
unsub-neg89.3%
Simplified89.3%
Final simplification82.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (* -0.5 (/ (+ b (+ b (* -2.0 (/ a (/ b c))))) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / 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 = (-0.5d0) * ((b + (b + ((-2.0d0) * (a / (b / c))))) / 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 = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(-0.5 * Float64(Float64(b + Float64(b + Float64(-2.0 * Float64(a / Float64(b / c))))) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(-0.5 * N[(N[(b + N[(b + N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b + -2 \cdot \frac{a}{\frac{b}{c}}\right)}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
associate-*r*34.2%
*-commutative34.2%
Simplified34.2%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
Simplified65.9%
if -4.999999999999985e-310 < b Initial program 74.5%
sub-neg74.5%
distribute-neg-out74.5%
neg-mul-174.5%
times-frac74.5%
metadata-eval74.5%
remove-double-neg74.5%
neg-sub074.5%
associate-+l-74.5%
Simplified74.5%
Taylor expanded in b around inf 62.2%
associate-/l*67.5%
Simplified67.5%
Final simplification66.7%
(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 34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
associate-*r*34.2%
*-commutative34.2%
Simplified34.2%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
Simplified65.9%
if -4.999999999999985e-310 < b Initial program 74.5%
*-commutative74.5%
sqr-neg74.5%
*-commutative74.5%
sqr-neg74.5%
*-commutative74.5%
associate-*r*74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around inf 67.5%
+-commutative67.5%
mul-1-neg67.5%
unsub-neg67.5%
Simplified67.5%
Final simplification66.7%
(FPCore (a b c) :precision binary64 (if (<= b -1.2e-303) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-303) {
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 <= (-1.2d-303)) 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 <= -1.2e-303) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-303: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-303) 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 <= -1.2e-303) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-303], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-303}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.2e-303Initial program 32.9%
*-commutative32.9%
sqr-neg32.9%
*-commutative32.9%
sqr-neg32.9%
*-commutative32.9%
associate-*r*32.9%
*-commutative32.9%
Simplified32.9%
Taylor expanded in b around -inf 67.9%
mul-1-neg67.9%
Simplified67.9%
if -1.2e-303 < b Initial program 74.5%
*-commutative74.5%
sqr-neg74.5%
*-commutative74.5%
sqr-neg74.5%
*-commutative74.5%
associate-*r*74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around inf 65.1%
associate-*r/65.1%
mul-1-neg65.1%
Simplified65.1%
Final simplification66.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(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 54.2%
*-commutative54.2%
sqr-neg54.2%
*-commutative54.2%
sqr-neg54.2%
*-commutative54.2%
associate-*r*54.2%
*-commutative54.2%
Simplified54.2%
Taylor expanded in b around -inf 34.4%
mul-1-neg34.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 54.2%
*-commutative54.2%
sqr-neg54.2%
*-commutative54.2%
sqr-neg54.2%
*-commutative54.2%
associate-*r*54.2%
*-commutative54.2%
Simplified54.2%
Applied egg-rr28.7%
Taylor expanded in b around -inf 2.7%
Final simplification2.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 2023314
(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)))