
(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 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(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 -24000000.0)
(- (/ c b) (/ b a))
(if (<= b 5e+148)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -24000000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 5e+148) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.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 <= (-24000000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 5d+148) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -24000000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 5e+148) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -24000000.0: tmp = (c / b) - (b / a) elif b <= 5e+148: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -24000000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5e+148) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -24000000.0) tmp = (c / b) - (b / a); elseif (b <= 5e+148) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -24000000.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+148], 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[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -24000000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+148}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.4e7Initial program 64.8%
*-commutative64.8%
Simplified64.8%
Taylor expanded in b around -inf 94.5%
+-commutative94.5%
mul-1-neg94.5%
unsub-neg94.5%
Simplified94.5%
if -2.4e7 < b < 5.00000000000000024e148Initial program 76.8%
if 5.00000000000000024e148 < b Initial program 6.8%
*-commutative6.8%
Simplified6.8%
add-sqr-sqrt4.1%
pow24.1%
pow1/24.1%
sqrt-pow14.1%
fma-neg4.2%
distribute-lft-neg-in4.2%
*-commutative4.2%
associate-*r*4.2%
metadata-eval4.2%
metadata-eval4.2%
Applied egg-rr4.2%
Taylor expanded in b around inf 100.0%
distribute-rgt1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
Simplified100.0%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e-56)
(- (/ c b) (/ b a))
(if (<= b 1.05e-60)
(* (/ -0.5 a) (- b (sqrt (* c (* a -4.0)))))
(/ (- (+ b (* a (/ (* c -2.0) b))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-60) {
tmp = (-0.5 / a) * (b - sqrt((c * (a * -4.0))));
} else {
tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.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 <= (-1.9d-56)) then
tmp = (c / b) - (b / a)
else if (b <= 1.05d-60) then
tmp = ((-0.5d0) / a) * (b - sqrt((c * (a * (-4.0d0)))))
else
tmp = ((b + (a * ((c * (-2.0d0)) / b))) - b) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-60) {
tmp = (-0.5 / a) * (b - Math.sqrt((c * (a * -4.0))));
} else {
tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.9e-56: tmp = (c / b) - (b / a) elif b <= 1.05e-60: tmp = (-0.5 / a) * (b - math.sqrt((c * (a * -4.0)))) else: tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-56) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.05e-60) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(Float64(Float64(b + Float64(a * Float64(Float64(c * -2.0) / b))) - b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.9e-56) tmp = (c / b) - (b / a); elseif (b <= 1.05e-60) tmp = (-0.5 / a) * (b - sqrt((c * (a * -4.0)))); else tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-56], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e-60], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b + N[(a * N[(N[(c * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-60}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + a \cdot \frac{c \cdot -2}{b}\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.9000000000000001e-56Initial program 70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in b around -inf 92.2%
+-commutative92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
if -1.9000000000000001e-56 < b < 1.04999999999999996e-60Initial program 71.9%
*-commutative71.9%
Simplified71.9%
add-sqr-sqrt70.2%
pow270.2%
pow1/270.2%
sqrt-pow170.3%
fma-neg70.3%
distribute-lft-neg-in70.3%
*-commutative70.3%
associate-*r*70.3%
metadata-eval70.3%
metadata-eval70.3%
Applied egg-rr70.3%
Taylor expanded in b around 0 63.7%
*-commutative63.7%
associate-*r*63.7%
Simplified63.7%
frac-2neg63.7%
div-inv63.6%
Applied egg-rr63.9%
*-commutative63.9%
associate-*l/63.9%
metadata-eval63.9%
*-commutative63.9%
*-commutative63.9%
Simplified63.9%
if 1.04999999999999996e-60 < b Initial program 49.5%
*-commutative49.5%
Simplified49.5%
add-sqr-sqrt28.1%
pow228.1%
pow1/228.1%
sqrt-pow128.2%
fma-neg28.2%
distribute-lft-neg-in28.2%
*-commutative28.2%
associate-*r*28.2%
metadata-eval28.2%
metadata-eval28.2%
Applied egg-rr28.2%
Taylor expanded in b around inf 77.0%
mul-1-neg77.0%
associate-+r+77.0%
unsub-neg77.0%
associate-*r/80.3%
*-commutative80.3%
associate-*r*80.3%
associate-*l/80.3%
Simplified80.3%
Final simplification79.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e-57)
(- (/ c b) (/ b a))
(if (<= b 8.6e-61)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- (+ b (* a (/ (* c -2.0) b))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e-57) {
tmp = (c / b) - (b / a);
} else if (b <= 8.6e-61) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.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 <= (-1.22d-57)) then
tmp = (c / b) - (b / a)
else if (b <= 8.6d-61) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = ((b + (a * ((c * (-2.0d0)) / b))) - b) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e-57) {
tmp = (c / b) - (b / a);
} else if (b <= 8.6e-61) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.22e-57: tmp = (c / b) - (b / a) elif b <= 8.6e-61: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.22e-57) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8.6e-61) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(b + Float64(a * Float64(Float64(c * -2.0) / b))) - b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.22e-57) tmp = (c / b) - (b / a); elseif (b <= 8.6e-61) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.22e-57], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.6e-61], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b + N[(a * N[(N[(c * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.22 \cdot 10^{-57}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8.6 \cdot 10^{-61}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + a \cdot \frac{c \cdot -2}{b}\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.2200000000000001e-57Initial program 70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in b around -inf 92.2%
+-commutative92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
if -1.2200000000000001e-57 < b < 8.6000000000000007e-61Initial program 71.9%
*-commutative71.9%
Simplified71.9%
add-sqr-sqrt70.2%
pow270.2%
pow1/270.2%
sqrt-pow170.3%
fma-neg70.3%
distribute-lft-neg-in70.3%
*-commutative70.3%
associate-*r*70.3%
metadata-eval70.3%
metadata-eval70.3%
Applied egg-rr70.3%
Taylor expanded in c around inf 34.4%
unpow234.4%
fma-neg34.4%
Simplified63.9%
if 8.6000000000000007e-61 < b Initial program 49.5%
*-commutative49.5%
Simplified49.5%
add-sqr-sqrt28.1%
pow228.1%
pow1/228.1%
sqrt-pow128.2%
fma-neg28.2%
distribute-lft-neg-in28.2%
*-commutative28.2%
associate-*r*28.2%
metadata-eval28.2%
metadata-eval28.2%
Applied egg-rr28.2%
Taylor expanded in b around inf 77.0%
mul-1-neg77.0%
associate-+r+77.0%
unsub-neg77.0%
associate-*r/80.3%
*-commutative80.3%
associate-*r*80.3%
associate-*l/80.3%
Simplified80.3%
Final simplification79.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- (+ b (* a (/ (* c -2.0) b))) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.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 = ((b + (a * ((c * (-2.0d0)) / b))) - b) / (a * 2.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 = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(Float64(b + Float64(a * Float64(Float64(c * -2.0) / b))) - b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -b / a; else tmp = ((b + (a * ((c * -2.0) / b))) - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[(N[(N[(b + N[(a * N[(N[(c * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + a \cdot \frac{c \cdot -2}{b}\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 72.8%
*-commutative72.8%
Simplified72.8%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
if -4.999999999999985e-310 < b Initial program 54.4%
*-commutative54.4%
Simplified54.4%
add-sqr-sqrt38.4%
pow238.4%
pow1/238.4%
sqrt-pow138.5%
fma-neg38.5%
distribute-lft-neg-in38.5%
*-commutative38.5%
associate-*r*38.5%
metadata-eval38.5%
metadata-eval38.5%
Applied egg-rr38.5%
Taylor expanded in b around inf 58.9%
mul-1-neg58.9%
associate-+r+58.9%
unsub-neg58.9%
associate-*r/61.4%
*-commutative61.4%
associate-*r*61.4%
associate-*l/61.4%
Simplified61.4%
Final simplification64.2%
(FPCore (a b c) :precision binary64 (if (<= b 3e-308) (/ (- b) a) (/ -1.0 (/ b c))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3e-308) {
tmp = -b / a;
} else {
tmp = -1.0 / (b / c);
}
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 <= 3d-308) then
tmp = -b / a
else
tmp = (-1.0d0) / (b / c)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 3e-308) {
tmp = -b / a;
} else {
tmp = -1.0 / (b / c);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3e-308: tmp = -b / a else: tmp = -1.0 / (b / c) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3e-308) tmp = Float64(Float64(-b) / a); else tmp = Float64(-1.0 / Float64(b / c)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3e-308) tmp = -b / a; else tmp = -1.0 / (b / c); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3e-308], N[((-b) / a), $MachinePrecision], N[(-1.0 / N[(b / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c}}\\
\end{array}
\end{array}
if b < 3.00000000000000022e-308Initial program 72.8%
*-commutative72.8%
Simplified72.8%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
if 3.00000000000000022e-308 < b Initial program 54.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in b around inf 35.1%
associate-/l*35.9%
Simplified35.9%
add-exp-log31.7%
*-commutative31.7%
times-frac31.7%
metadata-eval31.7%
div-inv31.7%
clear-num31.2%
Applied egg-rr31.2%
Taylor expanded in a around 0 22.3%
associate-*r/22.3%
mul-1-neg22.3%
Simplified22.3%
rem-exp-log27.1%
clear-num28.0%
frac-2neg28.0%
metadata-eval28.0%
add-sqr-sqrt13.1%
sqrt-unprod28.8%
sqr-neg28.8%
sqrt-unprod11.9%
add-sqr-sqrt20.4%
distribute-frac-neg20.4%
add-sqr-sqrt0.0%
sqrt-unprod43.7%
sqr-neg43.7%
sqrt-unprod27.9%
add-sqr-sqrt28.0%
Applied egg-rr28.0%
Final simplification47.4%
(FPCore (a b c) :precision binary64 (if (<= b -7.4e-300) (/ (- b) a) (/ 0.0 (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.4e-300) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.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 <= (-7.4d-300)) then
tmp = -b / a
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.4e-300) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.4e-300: tmp = -b / a else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.4e-300) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.4e-300) tmp = -b / a; else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.4e-300], N[((-b) / a), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.4 \cdot 10^{-300}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -7.4000000000000003e-300Initial program 72.4%
*-commutative72.4%
Simplified72.4%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
if -7.4000000000000003e-300 < b Initial program 55.1%
*-commutative55.1%
Simplified55.1%
add-sqr-sqrt39.3%
pow239.3%
pow1/239.3%
sqrt-pow139.4%
fma-neg39.4%
distribute-lft-neg-in39.4%
*-commutative39.4%
associate-*r*39.4%
metadata-eval39.4%
metadata-eval39.4%
Applied egg-rr39.4%
Taylor expanded in b around inf 58.8%
distribute-rgt1-in58.8%
metadata-eval58.8%
mul0-lft58.8%
Simplified58.8%
Final simplification63.3%
(FPCore (a b c) :precision binary64 (if (<= b 3.9e+14) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.9e+14) {
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 <= 3.9d+14) 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 <= 3.9e+14) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.9e+14: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.9e+14) 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 <= 3.9e+14) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.9e+14], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.9 \cdot 10^{+14}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.9e14Initial program 71.1%
*-commutative71.1%
Simplified71.1%
Taylor expanded in b around -inf 49.8%
associate-*r/49.8%
mul-1-neg49.8%
Simplified49.8%
if 3.9e14 < b Initial program 47.5%
*-commutative47.5%
Simplified47.5%
Taylor expanded in b around inf 46.4%
associate-/l*47.4%
Simplified47.4%
frac-2neg47.4%
div-inv47.4%
*-commutative47.4%
distribute-lft-neg-in47.4%
add-sqr-sqrt47.4%
sqrt-unprod67.0%
sqr-neg67.0%
sqrt-unprod0.0%
add-sqr-sqrt40.3%
distribute-neg-frac40.3%
distribute-frac-neg40.3%
frac-2neg40.3%
div-inv40.3%
clear-num39.4%
associate-*l*39.4%
distribute-rgt-neg-in39.4%
metadata-eval39.4%
Applied egg-rr39.4%
Taylor expanded in a around 0 29.7%
Final simplification43.4%
(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 72.8%
*-commutative72.8%
Simplified72.8%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
mul-1-neg67.1%
Simplified67.1%
if -4.999999999999985e-310 < b Initial program 54.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in b around inf 27.1%
associate-*r/27.1%
neg-mul-127.1%
Simplified27.1%
Final simplification46.9%
(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 63.5%
*-commutative63.5%
Simplified63.5%
add-sqr-sqrt55.4%
pow255.4%
pow1/255.4%
sqrt-pow155.4%
fma-neg55.4%
distribute-lft-neg-in55.4%
*-commutative55.4%
associate-*r*55.4%
metadata-eval55.4%
metadata-eval55.4%
Applied egg-rr55.4%
Applied egg-rr59.3%
unpow-159.3%
*-commutative59.3%
Simplified59.3%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt15.8%
metadata-eval15.8%
neg-mul-115.8%
distribute-neg-frac15.8%
Simplified15.8%
Taylor expanded in b around 0 2.6%
Final simplification2.6%
(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 63.5%
*-commutative63.5%
Simplified63.5%
Taylor expanded in b around inf 18.8%
associate-/l*19.2%
Simplified19.2%
frac-2neg19.2%
div-inv19.2%
*-commutative19.2%
distribute-lft-neg-in19.2%
add-sqr-sqrt18.1%
sqrt-unprod25.8%
sqr-neg25.8%
sqrt-unprod1.7%
add-sqr-sqrt16.0%
distribute-neg-frac16.0%
distribute-frac-neg16.0%
frac-2neg16.0%
div-inv16.0%
clear-num15.8%
associate-*l*15.8%
distribute-rgt-neg-in15.8%
metadata-eval15.8%
Applied egg-rr15.8%
Taylor expanded in a around 0 11.6%
Final simplification11.6%
(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 2024031
(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)))