
(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 -9e+61)
(- (/ c b) (/ b a))
(if (<= b 1.7e-120)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e+61) {
tmp = (c / b) - (b / a);
} else if (b <= 1.7e-120) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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 <= (-9d+61)) then
tmp = (c / b) - (b / a)
else if (b <= 1.7d-120) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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 <= -9e+61) {
tmp = (c / b) - (b / a);
} else if (b <= 1.7e-120) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e+61: tmp = (c / b) - (b / a) elif b <= 1.7e-120: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e+61) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.7e-120) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - 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 <= -9e+61) tmp = (c / b) - (b / a); elseif (b <= 1.7e-120) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e+61], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-120], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $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 -9 \cdot 10^{+61}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-120}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9e61Initial program 65.1%
neg-sub065.1%
associate-+l-65.1%
sub0-neg65.1%
neg-mul-165.1%
*-commutative65.1%
associate-*r/64.9%
Simplified65.2%
Taylor expanded in b around -inf 95.5%
mul-1-neg95.5%
unsub-neg95.5%
Simplified95.5%
if -9e61 < b < 1.70000000000000005e-120Initial program 86.7%
if 1.70000000000000005e-120 < b Initial program 13.2%
neg-sub013.2%
associate-+l-13.2%
sub0-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-*r/13.2%
Simplified13.2%
Taylor expanded in b around inf 92.0%
associate-*r/92.0%
neg-mul-192.0%
Simplified92.0%
Final simplification91.2%
(FPCore (a b c)
:precision binary64
(if (<= b -7.5e-64)
(- (/ c b) (/ b a))
(if (<= b 3.4e-119)
(* (- b (sqrt (* (* c a) -4.0))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-64) {
tmp = (c / b) - (b / a);
} else if (b <= 3.4e-119) {
tmp = (b - sqrt(((c * a) * -4.0))) * (-0.5 / 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 <= (-7.5d-64)) then
tmp = (c / b) - (b / a)
else if (b <= 3.4d-119) then
tmp = (b - sqrt(((c * a) * (-4.0d0)))) * ((-0.5d0) / 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 <= -7.5e-64) {
tmp = (c / b) - (b / a);
} else if (b <= 3.4e-119) {
tmp = (b - Math.sqrt(((c * a) * -4.0))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-64: tmp = (c / b) - (b / a) elif b <= 3.4e-119: tmp = (b - math.sqrt(((c * a) * -4.0))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-64) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.4e-119) tmp = Float64(Float64(b - sqrt(Float64(Float64(c * a) * -4.0))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.5e-64) tmp = (c / b) - (b / a); elseif (b <= 3.4e-119) tmp = (b - sqrt(((c * a) * -4.0))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-64], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.4e-119], N[(N[(b - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-119}:\\
\;\;\;\;\left(b - \sqrt{\left(c \cdot a\right) \cdot -4}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.49999999999999949e-64Initial program 74.2%
neg-sub074.2%
associate-+l-74.2%
sub0-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-*r/74.0%
Simplified74.1%
Taylor expanded in b around -inf 85.4%
mul-1-neg85.4%
unsub-neg85.4%
Simplified85.4%
if -7.49999999999999949e-64 < b < 3.40000000000000024e-119Initial program 82.5%
neg-sub082.5%
associate-+l-82.5%
sub0-neg82.5%
neg-mul-182.5%
*-commutative82.5%
associate-*r/82.4%
Simplified82.4%
fma-udef82.4%
associate-*r*82.4%
metadata-eval82.4%
distribute-rgt-neg-in82.4%
*-commutative82.4%
+-commutative82.4%
sub-neg82.4%
add-sqr-sqrt81.8%
pow281.8%
Applied egg-rr81.9%
Taylor expanded in a around inf 42.0%
unpow242.0%
*-commutative42.0%
exp-prod33.8%
mul-1-neg33.8%
log-rec33.8%
remove-double-neg33.8%
*-commutative33.8%
log-prod34.3%
rem-exp-log34.3%
metadata-eval34.3%
*-commutative34.3%
exp-prod34.3%
Simplified76.8%
if 3.40000000000000024e-119 < b Initial program 13.2%
neg-sub013.2%
associate-+l-13.2%
sub0-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-*r/13.2%
Simplified13.2%
Taylor expanded in b around inf 92.0%
associate-*r/92.0%
neg-mul-192.0%
Simplified92.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -6.2e-66)
(- (/ c b) (/ b a))
(if (<= b 1.02e-119)
(/ -0.5 (/ a (- b (sqrt (* c (* a -4.0))))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-66) {
tmp = (c / b) - (b / a);
} else if (b <= 1.02e-119) {
tmp = -0.5 / (a / (b - sqrt((c * (a * -4.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 <= (-6.2d-66)) then
tmp = (c / b) - (b / a)
else if (b <= 1.02d-119) then
tmp = (-0.5d0) / (a / (b - sqrt((c * (a * (-4.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 <= -6.2e-66) {
tmp = (c / b) - (b / a);
} else if (b <= 1.02e-119) {
tmp = -0.5 / (a / (b - Math.sqrt((c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e-66: tmp = (c / b) - (b / a) elif b <= 1.02e-119: tmp = -0.5 / (a / (b - math.sqrt((c * (a * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e-66) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.02e-119) tmp = Float64(-0.5 / Float64(a / Float64(b - sqrt(Float64(c * Float64(a * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.2e-66) tmp = (c / b) - (b / a); elseif (b <= 1.02e-119) tmp = -0.5 / (a / (b - sqrt((c * (a * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e-66], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.02e-119], N[(-0.5 / N[(a / N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.2 \cdot 10^{-66}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-119}:\\
\;\;\;\;\frac{-0.5}{\frac{a}{b - \sqrt{c \cdot \left(a \cdot -4\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.1999999999999995e-66Initial program 74.2%
neg-sub074.2%
associate-+l-74.2%
sub0-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-*r/74.0%
Simplified74.1%
Taylor expanded in b around -inf 85.4%
mul-1-neg85.4%
unsub-neg85.4%
Simplified85.4%
if -6.1999999999999995e-66 < b < 1.02e-119Initial program 82.5%
neg-sub082.5%
associate-+l-82.5%
sub0-neg82.5%
neg-mul-182.5%
*-commutative82.5%
associate-*r/82.4%
Simplified82.4%
fma-udef82.4%
associate-*r*82.4%
metadata-eval82.4%
distribute-rgt-neg-in82.4%
*-commutative82.4%
+-commutative82.4%
sub-neg82.4%
add-sqr-sqrt81.8%
pow281.8%
Applied egg-rr81.9%
Taylor expanded in a around inf 42.0%
associate-*r/42.0%
Simplified76.9%
expm1-log1p-u52.5%
expm1-udef22.6%
*-commutative22.6%
*-commutative22.6%
Applied egg-rr22.6%
expm1-def52.5%
expm1-log1p76.9%
associate-/l*76.8%
*-commutative76.8%
*-commutative76.8%
associate-*r*76.8%
Simplified76.8%
if 1.02e-119 < b Initial program 13.2%
neg-sub013.2%
associate-+l-13.2%
sub0-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-*r/13.2%
Simplified13.2%
Taylor expanded in b around inf 92.0%
associate-*r/92.0%
neg-mul-192.0%
Simplified92.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9.2e-64)
(- (/ c b) (/ b a))
(if (<= b 1.3e-119)
(/ (* -0.5 (- b (sqrt (* (* c a) -4.0)))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.2e-64) {
tmp = (c / b) - (b / a);
} else if (b <= 1.3e-119) {
tmp = (-0.5 * (b - sqrt(((c * a) * -4.0)))) / 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 <= (-9.2d-64)) then
tmp = (c / b) - (b / a)
else if (b <= 1.3d-119) then
tmp = ((-0.5d0) * (b - sqrt(((c * a) * (-4.0d0))))) / 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 <= -9.2e-64) {
tmp = (c / b) - (b / a);
} else if (b <= 1.3e-119) {
tmp = (-0.5 * (b - Math.sqrt(((c * a) * -4.0)))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.2e-64: tmp = (c / b) - (b / a) elif b <= 1.3e-119: tmp = (-0.5 * (b - math.sqrt(((c * a) * -4.0)))) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.2e-64) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.3e-119) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(Float64(Float64(c * a) * -4.0)))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.2e-64) tmp = (c / b) - (b / a); elseif (b <= 1.3e-119) tmp = (-0.5 * (b - sqrt(((c * a) * -4.0)))) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.2e-64], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.3e-119], N[(N[(-0.5 * N[(b - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.2 \cdot 10^{-64}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{-119}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{\left(c \cdot a\right) \cdot -4}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.2000000000000006e-64Initial program 74.2%
neg-sub074.2%
associate-+l-74.2%
sub0-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-*r/74.0%
Simplified74.1%
Taylor expanded in b around -inf 85.4%
mul-1-neg85.4%
unsub-neg85.4%
Simplified85.4%
if -9.2000000000000006e-64 < b < 1.30000000000000006e-119Initial program 82.5%
neg-sub082.5%
associate-+l-82.5%
sub0-neg82.5%
neg-mul-182.5%
*-commutative82.5%
associate-*r/82.4%
Simplified82.4%
fma-udef82.4%
associate-*r*82.4%
metadata-eval82.4%
distribute-rgt-neg-in82.4%
*-commutative82.4%
+-commutative82.4%
sub-neg82.4%
add-sqr-sqrt81.8%
pow281.8%
Applied egg-rr81.9%
Taylor expanded in a around inf 42.0%
associate-*r/42.0%
Simplified76.9%
if 1.30000000000000006e-119 < b Initial program 13.2%
neg-sub013.2%
associate-+l-13.2%
sub0-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-*r/13.2%
Simplified13.2%
Taylor expanded in b around inf 92.0%
associate-*r/92.0%
neg-mul-192.0%
Simplified92.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-65)
(- (/ c b) (/ b a))
(if (<= b 3.8e-121)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-65) {
tmp = (c / b) - (b / a);
} else if (b <= 3.8e-121) {
tmp = (sqrt((a * (c * -4.0))) - 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 <= (-9.5d-65)) then
tmp = (c / b) - (b / a)
else if (b <= 3.8d-121) then
tmp = (sqrt((a * (c * (-4.0d0)))) - 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 <= -9.5e-65) {
tmp = (c / b) - (b / a);
} else if (b <= 3.8e-121) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-65: tmp = (c / b) - (b / a) elif b <= 3.8e-121: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-65) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.8e-121) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - 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 <= -9.5e-65) tmp = (c / b) - (b / a); elseif (b <= 3.8e-121) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-65], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-121], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -9.5 \cdot 10^{-65}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-121}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.5000000000000004e-65Initial program 74.2%
neg-sub074.2%
associate-+l-74.2%
sub0-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-*r/74.0%
Simplified74.1%
Taylor expanded in b around -inf 85.4%
mul-1-neg85.4%
unsub-neg85.4%
Simplified85.4%
if -9.5000000000000004e-65 < b < 3.8000000000000001e-121Initial program 82.5%
Taylor expanded in b around 0 76.9%
*-commutative76.9%
*-commutative76.9%
associate-*r*77.0%
Simplified77.0%
if 3.8000000000000001e-121 < b Initial program 13.2%
neg-sub013.2%
associate-+l-13.2%
sub0-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-*r/13.2%
Simplified13.2%
Taylor expanded in b around inf 92.0%
associate-*r/92.0%
neg-mul-192.0%
Simplified92.0%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b -1e-311) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-311) {
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 <= (-1d-311)) 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 <= -1e-311) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-311: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-311) 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 <= -1e-311) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-311], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.99999999999948e-312Initial program 77.9%
neg-sub077.9%
associate-+l-77.9%
sub0-neg77.9%
neg-mul-177.9%
*-commutative77.9%
associate-*r/77.7%
Simplified77.8%
Taylor expanded in b around -inf 70.2%
mul-1-neg70.2%
unsub-neg70.2%
Simplified70.2%
if -9.99999999999948e-312 < b Initial program 22.7%
neg-sub022.7%
associate-+l-22.7%
sub0-neg22.7%
neg-mul-122.7%
*-commutative22.7%
associate-*r/22.7%
Simplified22.8%
Taylor expanded in b around inf 77.7%
associate-*r/77.7%
neg-mul-177.7%
Simplified77.7%
Final simplification74.0%
(FPCore (a b c) :precision binary64 (if (<= b 5.8e+44) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.8e+44) {
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 <= 5.8d+44) 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 <= 5.8e+44) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.8e+44: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.8e+44) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 5.8e+44) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.8e+44], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.8 \cdot 10^{+44}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 5.8000000000000004e44Initial program 68.9%
neg-sub068.9%
associate-+l-68.9%
sub0-neg68.9%
neg-mul-168.9%
*-commutative68.9%
associate-*r/68.7%
Simplified68.8%
Taylor expanded in b around -inf 51.8%
associate-*r/51.8%
mul-1-neg51.8%
Simplified51.8%
if 5.8000000000000004e44 < b Initial program 10.3%
neg-sub010.3%
associate-+l-10.3%
sub0-neg10.3%
neg-mul-110.3%
*-commutative10.3%
associate-*r/10.3%
Simplified10.3%
Taylor expanded in b around -inf 2.6%
mul-1-neg2.6%
unsub-neg2.6%
Simplified2.6%
Taylor expanded in c around inf 26.1%
Final simplification43.6%
(FPCore (a b c) :precision binary64 (if (<= b 2.6e-304) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.6e-304) {
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 <= 2.6d-304) 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 <= 2.6e-304) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.6e-304: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.6e-304) 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 <= 2.6e-304) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.6e-304], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.6 \cdot 10^{-304}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.59999999999999997e-304Initial program 78.2%
neg-sub078.2%
associate-+l-78.2%
sub0-neg78.2%
neg-mul-178.2%
*-commutative78.2%
associate-*r/78.0%
Simplified78.2%
Taylor expanded in b around -inf 68.9%
associate-*r/68.9%
mul-1-neg68.9%
Simplified68.9%
if 2.59999999999999997e-304 < b Initial program 21.5%
neg-sub021.5%
associate-+l-21.5%
sub0-neg21.5%
neg-mul-121.5%
*-commutative21.5%
associate-*r/21.5%
Simplified21.6%
Taylor expanded in b around inf 78.9%
associate-*r/78.9%
neg-mul-178.9%
Simplified78.9%
Final simplification73.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 50.1%
neg-sub050.1%
associate-+l-50.1%
sub0-neg50.1%
neg-mul-150.1%
*-commutative50.1%
associate-*r/50.0%
Simplified50.1%
Taylor expanded in b around -inf 36.0%
mul-1-neg36.0%
unsub-neg36.0%
Simplified36.0%
Taylor expanded in c around inf 10.5%
Final simplification10.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $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{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023218
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))