
(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 -1e+141)
(/ (- b) a)
(if (<= b 3e-79)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+141) {
tmp = -b / a;
} else if (b <= 3e-79) {
tmp = (sqrt(((b * b) - (4.0 * (a * 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 <= (-1d+141)) then
tmp = -b / a
else if (b <= 3d-79) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * 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 <= -1e+141) {
tmp = -b / a;
} else if (b <= 3e-79) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+141: tmp = -b / a elif b <= 3e-79: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+141) tmp = Float64(Float64(-b) / a); elseif (b <= 3e-79) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * 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 <= -1e+141) tmp = -b / a; elseif (b <= 3e-79) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+141], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3e-79], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -1 \cdot 10^{+141}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-79}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000002e141Initial program 41.4%
*-commutative41.4%
Simplified41.4%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
mul-1-neg91.1%
Simplified91.1%
if -1.00000000000000002e141 < b < 3e-79Initial program 80.6%
if 3e-79 < b Initial program 12.9%
*-commutative12.9%
Simplified12.9%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* 0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))))
(if (<= b -4e-59)
(- (/ c b) (/ b a))
(if (<= b -5.6e-76)
t_0
(if (<= b -6.5e-97)
(/ (- b) a)
(if (<= b 1.28e-76) t_0 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = 0.5 * ((b + sqrt((c * (a * -4.0)))) / a);
double tmp;
if (b <= -4e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -5.6e-76) {
tmp = t_0;
} else if (b <= -6.5e-97) {
tmp = -b / a;
} else if (b <= 1.28e-76) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * ((b + sqrt((c * (a * (-4.0d0))))) / a)
if (b <= (-4d-59)) then
tmp = (c / b) - (b / a)
else if (b <= (-5.6d-76)) then
tmp = t_0
else if (b <= (-6.5d-97)) then
tmp = -b / a
else if (b <= 1.28d-76) then
tmp = t_0
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = 0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
double tmp;
if (b <= -4e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -5.6e-76) {
tmp = t_0;
} else if (b <= -6.5e-97) {
tmp = -b / a;
} else if (b <= 1.28e-76) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = 0.5 * ((b + math.sqrt((c * (a * -4.0)))) / a) tmp = 0 if b <= -4e-59: tmp = (c / b) - (b / a) elif b <= -5.6e-76: tmp = t_0 elif b <= -6.5e-97: tmp = -b / a elif b <= 1.28e-76: tmp = t_0 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / a)) tmp = 0.0 if (b <= -4e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -5.6e-76) tmp = t_0; elseif (b <= -6.5e-97) tmp = Float64(Float64(-b) / a); elseif (b <= 1.28e-76) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = 0.5 * ((b + sqrt((c * (a * -4.0)))) / a); tmp = 0.0; if (b <= -4e-59) tmp = (c / b) - (b / a); elseif (b <= -5.6e-76) tmp = t_0; elseif (b <= -6.5e-97) tmp = -b / a; elseif (b <= 1.28e-76) tmp = t_0; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -5.6e-76], t$95$0, If[LessEqual[b, -6.5e-97], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.28e-76], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{if}\;b \leq -4 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -5.6 \cdot 10^{-76}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -6.5 \cdot 10^{-97}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.28 \cdot 10^{-76}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.0000000000000001e-59Initial program 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in b around -inf 86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -4.0000000000000001e-59 < b < -5.6000000000000002e-76 or -6.5000000000000004e-97 < b < 1.28e-76Initial program 72.1%
*-commutative72.1%
Simplified72.1%
clear-num72.0%
inv-pow72.0%
add-sqr-sqrt37.3%
sqrt-unprod71.9%
sqr-neg71.9%
sqrt-prod34.9%
add-sqr-sqrt69.7%
fma-neg69.7%
distribute-lft-neg-in69.7%
*-commutative69.7%
associate-*r*69.7%
metadata-eval69.7%
Applied egg-rr69.7%
Taylor expanded in b around 0 69.7%
associate-*r*69.7%
Simplified69.7%
expm1-log1p-u45.4%
expm1-udef26.6%
unpow-126.6%
clear-num26.6%
*-un-lft-identity26.6%
*-commutative26.6%
times-frac26.6%
metadata-eval26.6%
associate-*l*26.6%
Applied egg-rr26.6%
expm1-def45.4%
expm1-log1p69.7%
*-commutative69.7%
*-commutative69.7%
associate-*l*69.7%
Simplified69.7%
if -5.6000000000000002e-76 < b < -6.5000000000000004e-97Initial program 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if 1.28e-76 < b Initial program 12.9%
*-commutative12.9%
Simplified12.9%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification82.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (+ b (sqrt (* c (* a -4.0))))))
(if (<= b -2e-59)
(- (/ c b) (/ b a))
(if (<= b -9.5e-76)
(/ 0.5 (/ a t_0))
(if (<= b -4.6e-97)
(/ (- b) a)
(if (<= b 3.2e-80) (* 0.5 (/ t_0 a)) (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = b + sqrt((c * (a * -4.0)));
double tmp;
if (b <= -2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -9.5e-76) {
tmp = 0.5 / (a / t_0);
} else if (b <= -4.6e-97) {
tmp = -b / a;
} else if (b <= 3.2e-80) {
tmp = 0.5 * (t_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) :: t_0
real(8) :: tmp
t_0 = b + sqrt((c * (a * (-4.0d0))))
if (b <= (-2d-59)) then
tmp = (c / b) - (b / a)
else if (b <= (-9.5d-76)) then
tmp = 0.5d0 / (a / t_0)
else if (b <= (-4.6d-97)) then
tmp = -b / a
else if (b <= 3.2d-80) then
tmp = 0.5d0 * (t_0 / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = b + Math.sqrt((c * (a * -4.0)));
double tmp;
if (b <= -2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -9.5e-76) {
tmp = 0.5 / (a / t_0);
} else if (b <= -4.6e-97) {
tmp = -b / a;
} else if (b <= 3.2e-80) {
tmp = 0.5 * (t_0 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = b + math.sqrt((c * (a * -4.0))) tmp = 0 if b <= -2e-59: tmp = (c / b) - (b / a) elif b <= -9.5e-76: tmp = 0.5 / (a / t_0) elif b <= -4.6e-97: tmp = -b / a elif b <= 3.2e-80: tmp = 0.5 * (t_0 / a) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) tmp = 0.0 if (b <= -2e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -9.5e-76) tmp = Float64(0.5 / Float64(a / t_0)); elseif (b <= -4.6e-97) tmp = Float64(Float64(-b) / a); elseif (b <= 3.2e-80) tmp = Float64(0.5 * Float64(t_0 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = b + sqrt((c * (a * -4.0))); tmp = 0.0; if (b <= -2e-59) tmp = (c / b) - (b / a); elseif (b <= -9.5e-76) tmp = 0.5 / (a / t_0); elseif (b <= -4.6e-97) tmp = -b / a; elseif (b <= 3.2e-80) tmp = 0.5 * (t_0 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -9.5e-76], N[(0.5 / N[(a / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -4.6e-97], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.2e-80], N[(0.5 * N[(t$95$0 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b + \sqrt{c \cdot \left(a \cdot -4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -9.5 \cdot 10^{-76}:\\
\;\;\;\;\frac{0.5}{\frac{a}{t_0}}\\
\mathbf{elif}\;b \leq -4.6 \cdot 10^{-97}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{-80}:\\
\;\;\;\;0.5 \cdot \frac{t_0}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.0000000000000001e-59Initial program 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in b around -inf 86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -2.0000000000000001e-59 < b < -9.49999999999999984e-76Initial program 99.2%
*-commutative99.2%
Simplified99.2%
clear-num99.2%
inv-pow99.2%
add-sqr-sqrt99.2%
sqrt-unprod99.2%
sqr-neg99.2%
sqrt-prod0.0%
add-sqr-sqrt88.3%
fma-neg88.3%
distribute-lft-neg-in88.3%
*-commutative88.3%
associate-*r*88.3%
metadata-eval88.3%
Applied egg-rr88.3%
Taylor expanded in b around 0 88.3%
associate-*r*88.3%
Simplified88.3%
unpow-188.3%
*-commutative88.3%
*-un-lft-identity88.3%
times-frac88.3%
metadata-eval88.3%
associate-*l*88.3%
Applied egg-rr88.3%
associate-/r*88.3%
metadata-eval88.3%
*-commutative88.3%
*-commutative88.3%
associate-*l*88.3%
Simplified88.3%
if -9.49999999999999984e-76 < b < -4.59999999999999988e-97Initial program 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.59999999999999988e-97 < b < 3.1999999999999999e-80Initial program 69.7%
*-commutative69.7%
Simplified69.7%
clear-num69.6%
inv-pow69.6%
add-sqr-sqrt31.7%
sqrt-unprod69.4%
sqr-neg69.4%
sqrt-prod38.0%
add-sqr-sqrt68.0%
fma-neg68.0%
distribute-lft-neg-in68.0%
*-commutative68.0%
associate-*r*68.0%
metadata-eval68.0%
Applied egg-rr68.0%
Taylor expanded in b around 0 68.0%
associate-*r*68.0%
Simplified68.0%
expm1-log1p-u44.7%
expm1-udef27.5%
unpow-127.5%
clear-num27.5%
*-un-lft-identity27.5%
*-commutative27.5%
times-frac27.5%
metadata-eval27.5%
associate-*l*27.5%
Applied egg-rr27.5%
expm1-def44.7%
expm1-log1p68.1%
*-commutative68.1%
*-commutative68.1%
associate-*l*68.1%
Simplified68.1%
if 3.1999999999999999e-80 < b Initial program 12.9%
*-commutative12.9%
Simplified12.9%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification82.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))))
(if (<= b -1.52e-59)
(- (/ c b) (/ b a))
(if (<= b -3.8e-76)
t_0
(if (<= b -6.5e-97) (/ (- b) a) (if (<= b 3.6e-75) t_0 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.52e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -3.8e-76) {
tmp = t_0;
} else if (b <= -6.5e-97) {
tmp = -b / a;
} else if (b <= 3.6e-75) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-1.52d-59)) then
tmp = (c / b) - (b / a)
else if (b <= (-3.8d-76)) then
tmp = t_0
else if (b <= (-6.5d-97)) then
tmp = -b / a
else if (b <= 3.6d-75) then
tmp = t_0
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((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.52e-59) {
tmp = (c / b) - (b / a);
} else if (b <= -3.8e-76) {
tmp = t_0;
} else if (b <= -6.5e-97) {
tmp = -b / a;
} else if (b <= 3.6e-75) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -1.52e-59: tmp = (c / b) - (b / a) elif b <= -3.8e-76: tmp = t_0 elif b <= -6.5e-97: tmp = -b / a elif b <= 3.6e-75: tmp = t_0 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1.52e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -3.8e-76) tmp = t_0; elseif (b <= -6.5e-97) tmp = Float64(Float64(-b) / a); elseif (b <= 3.6e-75) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -1.52e-59) tmp = (c / b) - (b / a); elseif (b <= -3.8e-76) tmp = t_0; elseif (b <= -6.5e-97) tmp = -b / a; elseif (b <= 3.6e-75) tmp = t_0; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.52e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -3.8e-76], t$95$0, If[LessEqual[b, -6.5e-97], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.6e-75], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.52 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -3.8 \cdot 10^{-76}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -6.5 \cdot 10^{-97}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-75}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.51999999999999998e-59Initial program 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in b around -inf 86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -1.51999999999999998e-59 < b < -3.8000000000000002e-76 or -6.5000000000000004e-97 < b < 3.6e-75Initial program 72.1%
*-commutative72.1%
Simplified72.1%
Taylor expanded in b around 0 70.4%
associate-*r*70.4%
Simplified70.4%
if -3.8000000000000002e-76 < b < -6.5000000000000004e-97Initial program 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if 3.6e-75 < b Initial program 12.9%
*-commutative12.9%
Simplified12.9%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification82.6%
(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 75.8%
*-commutative75.8%
Simplified75.8%
Taylor expanded in b around -inf 64.3%
+-commutative64.3%
mul-1-neg64.3%
unsub-neg64.3%
Simplified64.3%
if -4.999999999999985e-310 < b Initial program 26.9%
*-commutative26.9%
Simplified26.9%
Taylor expanded in b around inf 68.9%
associate-*r/68.9%
neg-mul-168.9%
Simplified68.9%
Final simplification66.9%
(FPCore (a b c) :precision binary64 (if (<= b 7.2e+38) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e+38) {
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 <= 7.2d+38) 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 <= 7.2e+38) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.2e+38: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.2e+38) 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 <= 7.2e+38) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.2e+38], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{+38}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.19999999999999938e38Initial program 66.2%
*-commutative66.2%
Simplified66.2%
Taylor expanded in b around -inf 41.2%
associate-*r/41.2%
mul-1-neg41.2%
Simplified41.2%
if 7.19999999999999938e38 < b Initial program 7.6%
*-commutative7.6%
Simplified7.6%
Taylor expanded in b around -inf 2.2%
+-commutative2.2%
mul-1-neg2.2%
unsub-neg2.2%
associate-/l*2.3%
associate-*r/2.3%
*-commutative2.3%
Simplified2.3%
Taylor expanded in b around 0 31.2%
Final simplification38.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 75.8%
*-commutative75.8%
Simplified75.8%
Taylor expanded in b around -inf 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
if -4.999999999999985e-310 < b Initial program 26.9%
*-commutative26.9%
Simplified26.9%
Taylor expanded in b around inf 68.9%
associate-*r/68.9%
neg-mul-168.9%
Simplified68.9%
Final simplification66.8%
(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 48.1%
*-commutative48.1%
Simplified48.1%
add-sqr-sqrt47.1%
pow247.1%
pow1/247.1%
sqrt-pow147.1%
fma-neg47.1%
distribute-lft-neg-in47.1%
*-commutative47.1%
associate-*r*47.1%
metadata-eval47.1%
metadata-eval47.1%
Applied egg-rr47.1%
Taylor expanded in b around -inf 29.2%
associate-*r*29.2%
metadata-eval29.2%
mul-1-neg29.2%
add-sqr-sqrt14.2%
sqrt-unprod14.8%
sqr-neg14.8%
sqrt-unprod1.3%
add-sqr-sqrt2.8%
distribute-frac-neg2.8%
expm1-log1p-u2.1%
frac-2neg2.1%
expm1-udef2.4%
Applied egg-rr2.4%
expm1-def2.1%
expm1-log1p2.8%
Simplified2.8%
Final simplification2.8%
(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 48.1%
*-commutative48.1%
Simplified48.1%
Taylor expanded in b around -inf 27.3%
+-commutative27.3%
mul-1-neg27.3%
unsub-neg27.3%
associate-/l*29.0%
associate-*r/29.0%
*-commutative29.0%
Simplified29.0%
Taylor expanded in b around 0 11.7%
Final simplification11.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t_0 - t_1} \cdot \sqrt{t_0 + t_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t_2}\\
\end{array}
\end{array}
herbie shell --seed 2024013
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))