
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+139)
(/ (- b) a)
(if (<= b 1.2e-50)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+139) {
tmp = -b / a;
} else if (b <= 1.2e-50) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.8d+139)) then
tmp = -b / a
else if (b <= 1.2d-50) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+139) {
tmp = -b / a;
} else if (b <= 1.2e-50) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e+139: tmp = -b / a elif b <= 1.2e-50: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+139) tmp = Float64(Float64(-b) / a); elseif (b <= 1.2e-50) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.8e+139) tmp = -b / a; elseif (b <= 1.2e-50) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+139], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.2e-50], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+139}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-50}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.7999999999999998e139Initial program 41.9%
*-commutative41.9%
Simplified41.9%
Taylor expanded in b around -inf 94.9%
associate-*r/94.9%
mul-1-neg94.9%
Simplified94.9%
if -2.7999999999999998e139 < b < 1.20000000000000001e-50Initial program 81.0%
if 1.20000000000000001e-50 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around inf 82.5%
mul-1-neg82.5%
distribute-neg-frac82.5%
Simplified82.5%
Final simplification83.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (* a (* c -4.0)))) (t_1 (- (/ c b) (/ b a))))
(if (<= b -1.18e+80)
t_1
(if (<= b -7.2e+14)
(/ (- t_0 b) (* a 2.0))
(if (<= b -2.1e-8)
t_1
(if (<= b 2.8e-53) (* 0.5 (- (/ t_0 a) (/ b a))) (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = sqrt((a * (c * -4.0)));
double t_1 = (c / b) - (b / a);
double tmp;
if (b <= -1.18e+80) {
tmp = t_1;
} else if (b <= -7.2e+14) {
tmp = (t_0 - b) / (a * 2.0);
} else if (b <= -2.1e-8) {
tmp = t_1;
} else if (b <= 2.8e-53) {
tmp = 0.5 * ((t_0 / a) - (b / a));
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = sqrt((a * (c * (-4.0d0))))
t_1 = (c / b) - (b / a)
if (b <= (-1.18d+80)) then
tmp = t_1
else if (b <= (-7.2d+14)) then
tmp = (t_0 - b) / (a * 2.0d0)
else if (b <= (-2.1d-8)) then
tmp = t_1
else if (b <= 2.8d-53) then
tmp = 0.5d0 * ((t_0 / a) - (b / a))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt((a * (c * -4.0)));
double t_1 = (c / b) - (b / a);
double tmp;
if (b <= -1.18e+80) {
tmp = t_1;
} else if (b <= -7.2e+14) {
tmp = (t_0 - b) / (a * 2.0);
} else if (b <= -2.1e-8) {
tmp = t_1;
} else if (b <= 2.8e-53) {
tmp = 0.5 * ((t_0 / a) - (b / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt((a * (c * -4.0))) t_1 = (c / b) - (b / a) tmp = 0 if b <= -1.18e+80: tmp = t_1 elif b <= -7.2e+14: tmp = (t_0 - b) / (a * 2.0) elif b <= -2.1e-8: tmp = t_1 elif b <= 2.8e-53: tmp = 0.5 * ((t_0 / a) - (b / a)) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = sqrt(Float64(a * Float64(c * -4.0))) t_1 = Float64(Float64(c / b) - Float64(b / a)) tmp = 0.0 if (b <= -1.18e+80) tmp = t_1; elseif (b <= -7.2e+14) tmp = Float64(Float64(t_0 - b) / Float64(a * 2.0)); elseif (b <= -2.1e-8) tmp = t_1; elseif (b <= 2.8e-53) tmp = Float64(0.5 * Float64(Float64(t_0 / a) - Float64(b / a))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt((a * (c * -4.0))); t_1 = (c / b) - (b / a); tmp = 0.0; if (b <= -1.18e+80) tmp = t_1; elseif (b <= -7.2e+14) tmp = (t_0 - b) / (a * 2.0); elseif (b <= -2.1e-8) tmp = t_1; elseif (b <= 2.8e-53) tmp = 0.5 * ((t_0 / a) - (b / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.18e+80], t$95$1, If[LessEqual[b, -7.2e+14], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -2.1e-8], t$95$1, If[LessEqual[b, 2.8e-53], N[(0.5 * N[(N[(t$95$0 / a), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{a \cdot \left(c \cdot -4\right)}\\
t_1 := \frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \leq -1.18 \cdot 10^{+80}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -7.2 \cdot 10^{+14}:\\
\;\;\;\;\frac{t_0 - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq -2.1 \cdot 10^{-8}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \left(\frac{t_0}{a} - \frac{b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.18e80 or -7.2e14 < b < -2.09999999999999994e-8Initial program 60.9%
*-commutative60.9%
Simplified60.9%
Taylor expanded in b around -inf 94.8%
+-commutative94.8%
mul-1-neg94.8%
unsub-neg94.8%
Simplified94.8%
if -1.18e80 < b < -7.2e14Initial program 99.8%
*-commutative99.8%
Simplified99.8%
prod-diff99.8%
*-commutative99.8%
fma-def99.8%
associate-+l+99.8%
pow299.8%
distribute-lft-neg-in99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
associate-*r*99.8%
*-commutative99.8%
*-commutative99.8%
fma-udef99.8%
Applied egg-rr99.8%
+-commutative99.8%
associate-+r+99.8%
associate-+l+99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-lft-out99.8%
metadata-eval99.8%
+-commutative99.8%
unpow299.8%
fma-udef99.8%
associate-*l*99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in b around 0 81.0%
mul-1-neg81.0%
unsub-neg81.0%
distribute-rgt-out81.0%
metadata-eval81.0%
associate-*r*81.0%
Simplified81.0%
if -2.09999999999999994e-8 < b < 2.79999999999999985e-53Initial program 74.9%
*-commutative74.9%
Simplified74.9%
prod-diff74.6%
*-commutative74.6%
fma-def74.6%
associate-+l+74.6%
pow274.6%
distribute-lft-neg-in74.6%
*-commutative74.6%
distribute-rgt-neg-in74.6%
metadata-eval74.6%
associate-*r*74.6%
*-commutative74.6%
*-commutative74.6%
fma-udef74.6%
Applied egg-rr74.6%
+-commutative74.6%
associate-+r+74.6%
associate-+l+74.6%
associate-*r*74.6%
associate-*r*74.6%
distribute-lft-out74.6%
metadata-eval74.6%
+-commutative74.6%
unpow274.6%
fma-udef74.6%
associate-*l*74.6%
*-commutative74.6%
Simplified74.6%
associate-*l*74.6%
fma-def74.6%
Applied egg-rr74.6%
Taylor expanded in b around 0 68.1%
+-commutative68.1%
*-commutative68.1%
associate-*r/68.3%
*-rgt-identity68.3%
distribute-rgt-out68.6%
metadata-eval68.6%
metadata-eval68.6%
cancel-sign-sub-inv68.6%
distribute-lft-out--68.6%
associate-*l*68.6%
Simplified68.6%
if 2.79999999999999985e-53 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around inf 82.5%
mul-1-neg82.5%
distribute-neg-frac82.5%
Simplified82.5%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a)))
(t_1 (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))))
(if (<= b -1.18e+80)
t_0
(if (<= b -7.2e+14)
t_1
(if (<= b -2.1e-8) t_0 (if (<= b 1.9e-50) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.18e+80) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -2.1e-8) {
tmp = t_0;
} else if (b <= 1.9e-50) {
tmp = t_1;
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-1.18d+80)) then
tmp = t_0
else if (b <= (-7.2d+14)) then
tmp = t_1
else if (b <= (-2.1d-8)) then
tmp = t_0
else if (b <= 1.9d-50) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.18e+80) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -2.1e-8) {
tmp = t_0;
} else if (b <= 1.9e-50) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -1.18e+80: tmp = t_0 elif b <= -7.2e+14: tmp = t_1 elif b <= -2.1e-8: tmp = t_0 elif b <= 1.9e-50: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1.18e+80) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -2.1e-8) tmp = t_0; elseif (b <= 1.9e-50) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -1.18e+80) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -2.1e-8) tmp = t_0; elseif (b <= 1.9e-50) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.18e+80], t$95$0, If[LessEqual[b, -7.2e+14], t$95$1, If[LessEqual[b, -2.1e-8], t$95$0, If[LessEqual[b, 1.9e-50], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.18 \cdot 10^{+80}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -7.2 \cdot 10^{+14}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -2.1 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-50}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.18e80 or -7.2e14 < b < -2.09999999999999994e-8Initial program 60.9%
*-commutative60.9%
Simplified60.9%
Taylor expanded in b around -inf 94.8%
+-commutative94.8%
mul-1-neg94.8%
unsub-neg94.8%
Simplified94.8%
if -1.18e80 < b < -7.2e14 or -2.09999999999999994e-8 < b < 1.9e-50Initial program 78.2%
*-commutative78.2%
Simplified78.2%
prod-diff78.0%
*-commutative78.0%
fma-def78.0%
associate-+l+78.0%
pow278.0%
distribute-lft-neg-in78.0%
*-commutative78.0%
distribute-rgt-neg-in78.0%
metadata-eval78.0%
associate-*r*78.0%
*-commutative78.0%
*-commutative78.0%
fma-udef78.0%
Applied egg-rr78.0%
+-commutative78.0%
associate-+r+78.0%
associate-+l+78.0%
associate-*r*78.0%
associate-*r*78.0%
distribute-lft-out78.0%
metadata-eval78.0%
+-commutative78.0%
unpow278.0%
fma-udef78.0%
associate-*l*78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around 0 70.0%
mul-1-neg70.0%
unsub-neg70.0%
distribute-rgt-out70.2%
metadata-eval70.2%
associate-*r*70.2%
Simplified70.2%
if 1.9e-50 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around inf 82.5%
mul-1-neg82.5%
distribute-neg-frac82.5%
Simplified82.5%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a))) (t_1 (* 0.5 (/ (sqrt (* a (* c -4.0))) a))))
(if (<= b -8.6e+38)
t_0
(if (<= b -7.2e+14)
t_1
(if (<= b -5.5e-7) t_0 (if (<= b 8.4e-53) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = 0.5 * (sqrt((a * (c * -4.0))) / a);
double tmp;
if (b <= -8.6e+38) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -5.5e-7) {
tmp = t_0;
} else if (b <= 8.4e-53) {
tmp = t_1;
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a)
if (b <= (-8.6d+38)) then
tmp = t_0
else if (b <= (-7.2d+14)) then
tmp = t_1
else if (b <= (-5.5d-7)) then
tmp = t_0
else if (b <= 8.4d-53) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
double tmp;
if (b <= -8.6e+38) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -5.5e-7) {
tmp = t_0;
} else if (b <= 8.4e-53) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = 0.5 * (math.sqrt((a * (c * -4.0))) / a) tmp = 0 if b <= -8.6e+38: tmp = t_0 elif b <= -7.2e+14: tmp = t_1 elif b <= -5.5e-7: tmp = t_0 elif b <= 8.4e-53: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)) tmp = 0.0 if (b <= -8.6e+38) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -5.5e-7) tmp = t_0; elseif (b <= 8.4e-53) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = 0.5 * (sqrt((a * (c * -4.0))) / a); tmp = 0.0; if (b <= -8.6e+38) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -5.5e-7) tmp = t_0; elseif (b <= 8.4e-53) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8.6e+38], t$95$0, If[LessEqual[b, -7.2e+14], t$95$1, If[LessEqual[b, -5.5e-7], t$95$0, If[LessEqual[b, 8.4e-53], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := 0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{if}\;b \leq -8.6 \cdot 10^{+38}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -7.2 \cdot 10^{+14}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -5.5 \cdot 10^{-7}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{-53}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5999999999999994e38 or -7.2e14 < b < -5.5000000000000003e-7Initial program 64.1%
*-commutative64.1%
Simplified64.1%
Taylor expanded in b around -inf 92.2%
+-commutative92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
if -8.5999999999999994e38 < b < -7.2e14 or -5.5000000000000003e-7 < b < 8.3999999999999991e-53Initial program 77.2%
*-commutative77.2%
Simplified77.2%
prod-diff76.9%
*-commutative76.9%
fma-def76.9%
associate-+l+76.9%
pow276.9%
distribute-lft-neg-in76.9%
*-commutative76.9%
distribute-rgt-neg-in76.9%
metadata-eval76.9%
associate-*r*76.9%
*-commutative76.9%
*-commutative76.9%
fma-udef76.9%
Applied egg-rr76.9%
+-commutative76.9%
associate-+r+76.9%
associate-+l+76.9%
associate-*r*76.9%
associate-*r*76.9%
distribute-lft-out76.9%
metadata-eval76.9%
+-commutative76.9%
unpow276.9%
fma-udef76.9%
associate-*l*76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in b around 0 68.1%
associate-*l/68.3%
*-lft-identity68.3%
distribute-rgt-out68.6%
metadata-eval68.6%
associate-*r*68.6%
Simplified68.6%
if 8.3999999999999991e-53 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around inf 82.5%
mul-1-neg82.5%
distribute-neg-frac82.5%
Simplified82.5%
Final simplification79.4%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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) - (b / a)
else
tmp = -c / b
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) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 62.3%
+-commutative62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
if -4.999999999999985e-310 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
Taylor expanded in b around inf 63.2%
mul-1-neg63.2%
distribute-neg-frac63.2%
Simplified63.2%
Final simplification62.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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 = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 62.0%
associate-*r/62.0%
mul-1-neg62.0%
Simplified62.0%
if -4.999999999999985e-310 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
Applied egg-rr31.8%
fma-def30.2%
distribute-neg-frac30.2%
Simplified30.2%
Taylor expanded in a around 0 16.1%
distribute-rgt-out16.1%
metadata-eval16.1%
associate-*l/14.3%
mul0-rgt16.1%
Simplified16.1%
Final simplification35.8%
(FPCore (a b c) :precision binary64 (if (<= b 7e-290) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7e-290) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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-290) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 7e-290) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7e-290: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7e-290) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7e-290) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7e-290], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{-290}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 6.99999999999999963e-290Initial program 74.3%
*-commutative74.3%
Simplified74.3%
Taylor expanded in b around -inf 60.5%
associate-*r/60.5%
mul-1-neg60.5%
Simplified60.5%
if 6.99999999999999963e-290 < b Initial program 32.9%
*-commutative32.9%
Simplified32.9%
Taylor expanded in b around inf 64.5%
mul-1-neg64.5%
distribute-neg-frac64.5%
Simplified64.5%
Final simplification62.7%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 51.2%
*-commutative51.2%
Simplified51.2%
Applied egg-rr50.1%
fma-def49.2%
distribute-neg-frac49.2%
Simplified49.2%
Taylor expanded in a around 0 10.3%
distribute-rgt-out10.3%
metadata-eval10.3%
associate-*l/9.2%
mul0-rgt10.3%
Simplified10.3%
Final simplification10.3%
herbie shell --seed 2024019
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))