
(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 10 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 -5e+125)
(- (/ b a))
(if (<= b 5e-73)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+125) {
tmp = -(b / a);
} else if (b <= 5e-73) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+125) tmp = Float64(-Float64(b / a)); elseif (b <= 5e-73) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+125], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5e-73], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $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 -5 \cdot 10^{+125}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-73}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.99999999999999962e125Initial program 39.6%
*-commutative39.6%
Simplified39.7%
Taylor expanded in b around -inf 95.8%
associate-*r/95.8%
mul-1-neg95.8%
Simplified95.8%
if -4.99999999999999962e125 < b < 4.9999999999999998e-73Initial program 84.6%
*-commutative84.6%
Simplified84.6%
if 4.9999999999999998e-73 < b Initial program 15.5%
*-commutative15.5%
Simplified15.6%
Taylor expanded in a around 0 85.9%
associate-*r/85.9%
mul-1-neg85.9%
Simplified85.9%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.15e+126)
(- (/ b a))
(if (<= b 9.5e-73)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.15e+126) {
tmp = -(b / a);
} else if (b <= 9.5e-73) {
tmp = (sqrt(((b * b) - (c * (a * 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 <= (-2.15d+126)) then
tmp = -(b / a)
else if (b <= 9.5d-73) then
tmp = (sqrt(((b * b) - (c * (a * 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 <= -2.15e+126) {
tmp = -(b / a);
} else if (b <= 9.5e-73) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.15e+126: tmp = -(b / a) elif b <= 9.5e-73: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.15e+126) tmp = Float64(-Float64(b / a)); elseif (b <= 9.5e-73) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.15e+126) tmp = -(b / a); elseif (b <= 9.5e-73) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.15e+126], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 9.5e-73], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $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 -2.15 \cdot 10^{+126}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-73}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.1500000000000001e126Initial program 39.6%
*-commutative39.6%
Simplified39.7%
Taylor expanded in b around -inf 95.8%
associate-*r/95.8%
mul-1-neg95.8%
Simplified95.8%
if -2.1500000000000001e126 < b < 9.50000000000000005e-73Initial program 84.6%
if 9.50000000000000005e-73 < b Initial program 15.5%
*-commutative15.5%
Simplified15.6%
Taylor expanded in a around 0 85.9%
associate-*r/85.9%
mul-1-neg85.9%
Simplified85.9%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.65e-39)
(- (/ b a))
(if (<= b 5.6e-73)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.65e-39) {
tmp = -(b / a);
} else if (b <= 5.6e-73) {
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 <= (-2.65d-39)) then
tmp = -(b / a)
else if (b <= 5.6d-73) 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 <= -2.65e-39) {
tmp = -(b / a);
} else if (b <= 5.6e-73) {
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 <= -2.65e-39: tmp = -(b / a) elif b <= 5.6e-73: 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 <= -2.65e-39) tmp = Float64(-Float64(b / a)); elseif (b <= 5.6e-73) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.65e-39) tmp = -(b / a); elseif (b <= 5.6e-73) 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, -2.65e-39], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5.6e-73], 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 -2.65 \cdot 10^{-39}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{-73}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.65000000000000002e-39Initial program 63.0%
*-commutative63.0%
Simplified63.1%
Taylor expanded in b around -inf 86.6%
associate-*r/86.6%
mul-1-neg86.6%
Simplified86.6%
if -2.65000000000000002e-39 < b < 5.60000000000000023e-73Initial program 80.3%
*-commutative80.3%
Simplified80.4%
Taylor expanded in a around inf 70.3%
*-commutative70.3%
associate-*r*70.3%
Simplified70.3%
if 5.60000000000000023e-73 < b Initial program 15.5%
*-commutative15.5%
Simplified15.6%
Taylor expanded in a around 0 85.9%
associate-*r/85.9%
mul-1-neg85.9%
Simplified85.9%
Final simplification81.4%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-42) (- (/ b a)) (if (<= b 8e-73) (/ 0.5 (/ a (- (sqrt (* -4.0 (* a c))) b))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-42) {
tmp = -(b / a);
} else if (b <= 8e-73) {
tmp = 0.5 / (a / (sqrt((-4.0 * (a * c))) - b));
} 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 <= (-4.5d-42)) then
tmp = -(b / a)
else if (b <= 8d-73) then
tmp = 0.5d0 / (a / (sqrt(((-4.0d0) * (a * c))) - b))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-42) {
tmp = -(b / a);
} else if (b <= 8e-73) {
tmp = 0.5 / (a / (Math.sqrt((-4.0 * (a * c))) - b));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-42: tmp = -(b / a) elif b <= 8e-73: tmp = 0.5 / (a / (math.sqrt((-4.0 * (a * c))) - b)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-42) tmp = Float64(-Float64(b / a)); elseif (b <= 8e-73) tmp = Float64(0.5 / Float64(a / Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e-42) tmp = -(b / a); elseif (b <= 8e-73) tmp = 0.5 / (a / (sqrt((-4.0 * (a * c))) - b)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-42], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 8e-73], N[(0.5 / N[(a / N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-42}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-73}:\\
\;\;\;\;\frac{0.5}{\frac{a}{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.5e-42Initial program 63.0%
*-commutative63.0%
Simplified63.1%
Taylor expanded in b around -inf 86.6%
associate-*r/86.6%
mul-1-neg86.6%
Simplified86.6%
if -4.5e-42 < b < 7.99999999999999998e-73Initial program 80.3%
*-commutative80.3%
Simplified80.4%
Taylor expanded in a around inf 70.3%
*-commutative70.3%
associate-*r*70.3%
Simplified70.3%
div-sub70.3%
*-un-lft-identity70.3%
*-commutative70.3%
times-frac70.3%
metadata-eval70.3%
*-un-lft-identity70.3%
*-commutative70.3%
times-frac70.3%
metadata-eval70.3%
Applied egg-rr70.3%
distribute-lft-out--70.3%
associate-*r*70.3%
Simplified70.3%
*-commutative70.3%
sub-div70.3%
pow1/270.3%
metadata-eval70.3%
pow-pow55.3%
pow1/359.1%
metadata-eval59.1%
div-inv59.1%
associate-/r*59.1%
clear-num59.1%
*-commutative59.1%
*-un-lft-identity59.1%
times-frac59.1%
metadata-eval59.1%
Applied egg-rr70.2%
associate-/r*70.2%
metadata-eval70.2%
associate-*r*70.2%
*-commutative70.2%
*-commutative70.2%
Simplified70.2%
if 7.99999999999999998e-73 < b Initial program 15.5%
*-commutative15.5%
Simplified15.6%
Taylor expanded in a around 0 85.9%
associate-*r/85.9%
mul-1-neg85.9%
Simplified85.9%
Final simplification81.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-39)
(- (/ b a))
(if (<= b 4.2e-73)
(* (- (sqrt (* -4.0 (* a c))) b) (/ 0.5 a))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-39) {
tmp = -(b / a);
} else if (b <= 4.2e-73) {
tmp = (sqrt((-4.0 * (a * c))) - b) * (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 <= (-5.8d-39)) then
tmp = -(b / a)
else if (b <= 4.2d-73) then
tmp = (sqrt(((-4.0d0) * (a * c))) - b) * (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 <= -5.8e-39) {
tmp = -(b / a);
} else if (b <= 4.2e-73) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-39: tmp = -(b / a) elif b <= 4.2e-73: tmp = (math.sqrt((-4.0 * (a * c))) - b) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-39) tmp = Float64(-Float64(b / a)); elseif (b <= 4.2e-73) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) * Float64(0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e-39) tmp = -(b / a); elseif (b <= 4.2e-73) tmp = (sqrt((-4.0 * (a * c))) - b) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-39], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 4.2e-73], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-39}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-73}:\\
\;\;\;\;\left(\sqrt{-4 \cdot \left(a \cdot c\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.79999999999999975e-39Initial program 63.0%
*-commutative63.0%
Simplified63.1%
Taylor expanded in b around -inf 86.6%
associate-*r/86.6%
mul-1-neg86.6%
Simplified86.6%
if -5.79999999999999975e-39 < b < 4.1999999999999997e-73Initial program 80.3%
*-commutative80.3%
Simplified80.4%
Taylor expanded in a around inf 70.3%
*-commutative70.3%
associate-*r*70.3%
Simplified70.3%
div-sub70.3%
*-un-lft-identity70.3%
*-commutative70.3%
times-frac70.3%
metadata-eval70.3%
*-un-lft-identity70.3%
*-commutative70.3%
times-frac70.3%
metadata-eval70.3%
Applied egg-rr70.3%
distribute-lft-out--70.3%
associate-*r*70.3%
Simplified70.3%
*-commutative70.3%
sub-div70.3%
pow1/270.3%
metadata-eval70.3%
pow-pow55.3%
pow1/359.1%
metadata-eval59.1%
div-inv59.1%
associate-/r*59.1%
div-sub59.1%
sub-neg59.1%
Applied egg-rr70.3%
sub-neg70.3%
distribute-lft-out--70.3%
div-sub70.3%
*-commutative70.3%
associate-*l/70.3%
associate-*r/70.1%
*-commutative70.1%
associate-*r*70.1%
*-commutative70.1%
*-commutative70.1%
Simplified70.1%
if 4.1999999999999997e-73 < b Initial program 15.5%
*-commutative15.5%
Simplified15.6%
Taylor expanded in a around 0 85.9%
associate-*r/85.9%
mul-1-neg85.9%
Simplified85.9%
Final simplification81.3%
(FPCore (a b c) :precision binary64 (if (<= b -1.38e-177) (- (/ b a)) (if (<= b 1.35e-152) (* -0.5 (sqrt (* -4.0 (/ c a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.38e-177) {
tmp = -(b / a);
} else if (b <= 1.35e-152) {
tmp = -0.5 * sqrt((-4.0 * (c / 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 <= (-1.38d-177)) then
tmp = -(b / a)
else if (b <= 1.35d-152) then
tmp = (-0.5d0) * sqrt(((-4.0d0) * (c / 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 <= -1.38e-177) {
tmp = -(b / a);
} else if (b <= 1.35e-152) {
tmp = -0.5 * Math.sqrt((-4.0 * (c / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.38e-177: tmp = -(b / a) elif b <= 1.35e-152: tmp = -0.5 * math.sqrt((-4.0 * (c / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.38e-177) tmp = Float64(-Float64(b / a)); elseif (b <= 1.35e-152) tmp = Float64(-0.5 * sqrt(Float64(-4.0 * Float64(c / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.38e-177) tmp = -(b / a); elseif (b <= 1.35e-152) tmp = -0.5 * sqrt((-4.0 * (c / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.38e-177], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 1.35e-152], N[(-0.5 * N[Sqrt[N[(-4.0 * N[(c / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.38 \cdot 10^{-177}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-152}:\\
\;\;\;\;-0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.37999999999999991e-177Initial program 65.9%
*-commutative65.9%
Simplified66.0%
Taylor expanded in b around -inf 76.6%
associate-*r/76.6%
mul-1-neg76.6%
Simplified76.6%
if -1.37999999999999991e-177 < b < 1.34999999999999999e-152Initial program 83.4%
*-commutative83.4%
Simplified83.4%
add-cube-cbrt82.5%
pow382.4%
Applied egg-rr82.4%
Taylor expanded in a around -inf 0.0%
rem-cube-cbrt0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt26.5%
Simplified26.5%
add-sqr-sqrt1.4%
sqrt-unprod36.5%
pow236.5%
Applied egg-rr36.5%
unpow236.5%
*-commutative36.5%
*-commutative36.5%
swap-sqr36.5%
metadata-eval36.5%
metadata-eval36.5%
swap-sqr36.5%
*-lft-identity36.5%
*-lft-identity36.5%
rem-square-sqrt36.5%
associate-*r/36.5%
*-commutative36.5%
associate-*r/36.5%
Simplified36.5%
if 1.34999999999999999e-152 < b Initial program 23.9%
*-commutative23.9%
Simplified23.9%
Taylor expanded in a around 0 78.4%
associate-*r/78.4%
mul-1-neg78.4%
Simplified78.4%
Final simplification70.9%
(FPCore (a b c) :precision binary64 (if (<= b 1.85e-255) (- (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.85e-255) {
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 <= 1.85d-255) 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 <= 1.85e-255) {
tmp = -(b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.85e-255: tmp = -(b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.85e-255) tmp = Float64(-Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.85e-255) tmp = -(b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.85e-255], (-N[(b / a), $MachinePrecision]), N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.85 \cdot 10^{-255}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.8500000000000001e-255Initial program 69.1%
*-commutative69.1%
Simplified69.2%
Taylor expanded in b around -inf 64.0%
associate-*r/64.0%
mul-1-neg64.0%
Simplified64.0%
if 1.8500000000000001e-255 < b Initial program 32.1%
*-commutative32.1%
Simplified32.1%
Taylor expanded in a around 0 69.7%
associate-*r/69.7%
mul-1-neg69.7%
Simplified69.7%
Final simplification66.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.24e+33) (- (/ b a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.24e+33) {
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 <= 1.24d+33) 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 <= 1.24e+33) {
tmp = -(b / a);
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.24e+33: tmp = -(b / a) else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.24e+33) 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 <= 1.24e+33) tmp = -(b / a); else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.24e+33], (-N[(b / a), $MachinePrecision]), N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.24 \cdot 10^{+33}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.23999999999999997e33Initial program 67.5%
*-commutative67.5%
Simplified67.5%
Taylor expanded in b around -inf 48.3%
associate-*r/48.3%
mul-1-neg48.3%
Simplified48.3%
if 1.23999999999999997e33 < b Initial program 8.7%
*-commutative8.7%
Simplified8.7%
Taylor expanded in a around 0 92.8%
associate-*r/92.8%
mul-1-neg92.8%
Simplified92.8%
add-sqr-sqrt37.7%
sqrt-unprod39.5%
sqr-neg39.5%
sqrt-unprod10.9%
add-sqr-sqrt19.7%
*-un-lft-identity19.7%
Applied egg-rr19.7%
*-lft-identity19.7%
Simplified19.7%
Final simplification41.2%
(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 52.8%
*-commutative52.8%
Simplified52.8%
Taylor expanded in a around 0 32.1%
associate-*r/32.1%
mul-1-neg32.1%
Simplified32.1%
add-sqr-sqrt12.5%
sqrt-unprod13.6%
sqr-neg13.6%
sqrt-unprod3.8%
add-sqr-sqrt7.3%
*-un-lft-identity7.3%
Applied egg-rr7.3%
*-lft-identity7.3%
Simplified7.3%
(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 52.8%
*-commutative52.8%
Simplified52.8%
Taylor expanded in b around -inf 36.9%
associate-*r/36.9%
mul-1-neg36.9%
Simplified36.9%
neg-mul-136.9%
add-sqr-sqrt20.6%
times-frac20.5%
Applied egg-rr20.5%
frac-times20.6%
neg-mul-120.6%
add-sqr-sqrt36.9%
add-sqr-sqrt35.4%
sqrt-unprod25.0%
sqr-neg25.0%
sqrt-prod1.8%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
herbie shell --seed 2024181
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))