
(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 -24000000.0)
(- (/ c b) (/ b a))
(if (<= b 6.5e+86)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(* (/ 0.5 a) (* -2.0 (* c (/ a b)))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -24000000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 6.5e+86) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / 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 <= (-24000000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 6.5d+86) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = (0.5d0 / a) * ((-2.0d0) * (c * (a / b)))
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 <= 6.5e+86) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / b)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -24000000.0: tmp = (c / b) - (b / a) elif b <= 6.5e+86: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = (0.5 / a) * (-2.0 * (c * (a / b))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -24000000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6.5e+86) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(0.5 / a) * Float64(-2.0 * Float64(c * Float64(a / b)))); 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 <= 6.5e+86) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = (0.5 / a) * (-2.0 * (c * (a / b))); 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, 6.5e+86], 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[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -24000000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{+86}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(-2 \cdot \left(c \cdot \frac{a}{b}\right)\right)\\
\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 < 6.49999999999999996e86Initial program 74.6%
if 6.49999999999999996e86 < b Initial program 24.8%
*-commutative24.8%
Simplified24.8%
Taylor expanded in b around inf 67.5%
*-commutative67.5%
associate-/l*75.6%
Simplified75.6%
clear-num75.7%
inv-pow75.7%
Applied egg-rr75.7%
unpow-175.7%
Simplified75.7%
clear-num76.8%
associate-/r/75.6%
*-commutative75.6%
associate-/r*75.6%
metadata-eval75.6%
clear-num75.7%
div-inv75.7%
clear-num76.1%
Applied egg-rr76.1%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.15e-54)
(- (/ c b) (/ b a))
(if (<= b 0.78)
(* 0.5 (/ (sqrt (* a (* c -4.0))) a))
(* (/ 0.5 a) (* -2.0 (* c (/ a b)))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.15e-54) {
tmp = (c / b) - (b / a);
} else if (b <= 0.78) {
tmp = 0.5 * (sqrt((a * (c * -4.0))) / a);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / 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-54)) then
tmp = (c / b) - (b / a)
else if (b <= 0.78d0) then
tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a)
else
tmp = (0.5d0 / a) * ((-2.0d0) * (c * (a / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.15e-54) {
tmp = (c / b) - (b / a);
} else if (b <= 0.78) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / b)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.15e-54: tmp = (c / b) - (b / a) elif b <= 0.78: tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = (0.5 / a) * (-2.0 * (c * (a / b))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.15e-54) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 0.78) tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(Float64(0.5 / a) * Float64(-2.0 * Float64(c * Float64(a / b)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.15e-54) tmp = (c / b) - (b / a); elseif (b <= 0.78) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = (0.5 / a) * (-2.0 * (c * (a / b))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.15e-54], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 0.78], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.15 \cdot 10^{-54}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 0.78:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(-2 \cdot \left(c \cdot \frac{a}{b}\right)\right)\\
\end{array}
\end{array}
if b < -2.15e-54Initial 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 -2.15e-54 < b < 0.78000000000000003Initial program 71.6%
*-commutative71.6%
Simplified71.6%
prod-diff71.0%
*-commutative71.0%
fma-def71.0%
associate-+l+71.0%
pow271.0%
distribute-lft-neg-in71.0%
*-commutative71.0%
distribute-rgt-neg-in71.0%
metadata-eval71.0%
associate-*r*71.0%
*-commutative71.0%
*-commutative71.0%
fma-udef71.0%
Applied egg-rr71.0%
fma-def71.0%
fma-def71.0%
*-commutative71.0%
Simplified71.0%
Taylor expanded in b around 0 62.4%
associate-*l/62.4%
distribute-rgt-out64.1%
metadata-eval64.1%
associate-*r*64.1%
*-lft-identity64.1%
*-commutative64.1%
Simplified64.1%
if 0.78000000000000003 < b Initial program 39.1%
*-commutative39.1%
Simplified39.1%
Taylor expanded in b around inf 61.8%
*-commutative61.8%
associate-/l*67.5%
Simplified67.5%
clear-num67.5%
inv-pow67.5%
Applied egg-rr67.5%
unpow-167.5%
Simplified67.5%
clear-num68.3%
associate-/r/67.5%
*-commutative67.5%
associate-/r*67.5%
metadata-eval67.5%
clear-num67.5%
div-inv67.6%
clear-num67.9%
Applied egg-rr67.9%
Final simplification74.7%
(FPCore (a b c)
:precision binary64
(if (<= b 1.6e-308)
(/ (- b) a)
(if (<= b 1.25e+86)
(/ (- (+ b (* -2.0 (/ (* c a) b))) b) (* a 2.0))
(* (/ 0.5 a) (* -2.0 (* c (/ a b)))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.6e-308) {
tmp = -b / a;
} else if (b <= 1.25e+86) {
tmp = ((b + (-2.0 * ((c * a) / b))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / 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.6d-308) then
tmp = -b / a
else if (b <= 1.25d+86) then
tmp = ((b + ((-2.0d0) * ((c * a) / b))) - b) / (a * 2.0d0)
else
tmp = (0.5d0 / a) * ((-2.0d0) * (c * (a / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.6e-308) {
tmp = -b / a;
} else if (b <= 1.25e+86) {
tmp = ((b + (-2.0 * ((c * a) / b))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / b)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.6e-308: tmp = -b / a elif b <= 1.25e+86: tmp = ((b + (-2.0 * ((c * a) / b))) - b) / (a * 2.0) else: tmp = (0.5 / a) * (-2.0 * (c * (a / b))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.6e-308) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e+86) tmp = Float64(Float64(Float64(b + Float64(-2.0 * Float64(Float64(c * a) / b))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(0.5 / a) * Float64(-2.0 * Float64(c * Float64(a / b)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.6e-308) tmp = -b / a; elseif (b <= 1.25e+86) tmp = ((b + (-2.0 * ((c * a) / b))) - b) / (a * 2.0); else tmp = (0.5 / a) * (-2.0 * (c * (a / b))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.6e-308], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e+86], N[(N[(N[(b + N[(-2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.6 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+86}:\\
\;\;\;\;\frac{\left(b + -2 \cdot \frac{c \cdot a}{b}\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(-2 \cdot \left(c \cdot \frac{a}{b}\right)\right)\\
\end{array}
\end{array}
if b < 1.6000000000000001e-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 1.6000000000000001e-308 < b < 1.2499999999999999e86Initial program 68.4%
*-commutative68.4%
Simplified68.4%
Taylor expanded in b around inf 33.2%
if 1.2499999999999999e86 < b Initial program 24.8%
*-commutative24.8%
Simplified24.8%
Taylor expanded in b around inf 67.5%
*-commutative67.5%
associate-/l*75.6%
Simplified75.6%
clear-num75.7%
inv-pow75.7%
Applied egg-rr75.7%
unpow-175.7%
Simplified75.7%
clear-num76.8%
associate-/r/75.6%
*-commutative75.6%
associate-/r*75.6%
metadata-eval75.6%
clear-num75.7%
div-inv75.7%
clear-num76.1%
Applied egg-rr76.1%
Final simplification59.9%
(FPCore (a b c) :precision binary64 (if (<= b 3e-309) (/ (- b) a) (* (/ 0.5 a) (* -2.0 (* c (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3e-309) {
tmp = -b / a;
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / 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 <= 3d-309) then
tmp = -b / a
else
tmp = (0.5d0 / a) * ((-2.0d0) * (c * (a / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 3e-309) {
tmp = -b / a;
} else {
tmp = (0.5 / a) * (-2.0 * (c * (a / b)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3e-309: tmp = -b / a else: tmp = (0.5 / a) * (-2.0 * (c * (a / b))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3e-309) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(0.5 / a) * Float64(-2.0 * Float64(c * Float64(a / b)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3e-309) tmp = -b / a; else tmp = (0.5 / a) * (-2.0 * (c * (a / b))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3e-309], N[((-b) / a), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(-2 \cdot \left(c \cdot \frac{a}{b}\right)\right)\\
\end{array}
\end{array}
if b < 3.000000000000001e-309Initial 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.000000000000001e-309 < b Initial program 48.4%
*-commutative48.4%
Simplified48.4%
Taylor expanded in b around inf 45.5%
*-commutative45.5%
associate-/l*49.4%
Simplified49.4%
clear-num49.4%
inv-pow49.4%
Applied egg-rr49.4%
unpow-149.4%
Simplified49.4%
clear-num49.9%
associate-/r/49.4%
*-commutative49.4%
associate-/r*49.4%
metadata-eval49.4%
clear-num49.4%
div-inv49.4%
clear-num49.6%
Applied egg-rr49.6%
Final simplification58.3%
(FPCore (a b c) :precision binary64 (if (<= b 4.2e-308) (/ (- b) a) (/ (/ c (/ b a)) (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.2e-308) {
tmp = -b / a;
} else {
tmp = (c / (b / a)) / -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) :: tmp
if (b <= 4.2d-308) then
tmp = -b / a
else
tmp = (c / (b / a)) / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 4.2e-308) {
tmp = -b / a;
} else {
tmp = (c / (b / a)) / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.2e-308: tmp = -b / a else: tmp = (c / (b / a)) / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.2e-308) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(c / Float64(b / a)) / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.2e-308) tmp = -b / a; else tmp = (c / (b / a)) / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.2e-308], N[((-b) / a), $MachinePrecision], N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{-a}\\
\end{array}
\end{array}
if b < 4.2e-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 4.2e-308 < b Initial program 48.4%
*-commutative48.4%
Simplified48.4%
Taylor expanded in b around inf 45.5%
*-commutative45.5%
associate-/l*49.4%
Simplified49.4%
clear-num49.4%
inv-pow49.4%
Applied egg-rr49.4%
unpow-149.4%
Simplified49.4%
clear-num49.9%
associate-/r/49.4%
*-commutative49.4%
associate-/r*49.4%
metadata-eval49.4%
clear-num49.4%
div-inv49.4%
clear-num49.6%
Applied egg-rr49.6%
associate-*l/49.6%
frac-2neg49.6%
associate-*r*49.6%
metadata-eval49.6%
neg-mul-149.6%
distribute-lft-neg-out49.6%
add-sqr-sqrt20.6%
sqrt-unprod33.6%
sqr-neg33.6%
sqrt-unprod16.2%
add-sqr-sqrt29.9%
distribute-lft-neg-out29.9%
add-sqr-sqrt13.7%
sqrt-unprod35.5%
sqr-neg35.5%
sqrt-unprod28.9%
add-sqr-sqrt49.6%
clear-num49.4%
un-div-inv49.4%
Applied egg-rr49.4%
Final simplification58.2%
(FPCore (a b c) :precision binary64 (if (<= b -7.4e-300) (/ (- b) a) (/ (- b b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.4e-300) {
tmp = -b / a;
} else {
tmp = (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 <= (-7.4d-300)) then
tmp = -b / a
else
tmp = (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 <= -7.4e-300) {
tmp = -b / a;
} else {
tmp = (b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.4e-300: tmp = -b / a else: tmp = (b - b) / (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(Float64(b - b) / 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 = (b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.4e-300], N[((-b) / a), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / 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{b - b}{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 49.2%
*-commutative49.2%
Simplified49.2%
Taylor expanded in b around inf 46.3%
Final simplification56.9%
(FPCore (a b c) :precision binary64 (if (<= b 9e+14) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 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 <= 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 <= 9e+14) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 9e+14: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 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 <= 9e+14) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 9e+14], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{+14}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 9e14Initial program 69.6%
*-commutative69.6%
Simplified69.6%
Taylor expanded in b around -inf 49.6%
associate-*r/49.6%
mul-1-neg49.6%
Simplified49.6%
if 9e14 < b Initial program 40.9%
*-commutative40.9%
Simplified40.9%
Applied egg-rr6.5%
Taylor expanded in b around -inf 29.7%
Final simplification43.3%
(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 48.4%
*-commutative48.4%
Simplified48.4%
Taylor expanded in b around inf 39.7%
mul-1-neg39.7%
distribute-neg-frac39.7%
Simplified39.7%
Final simplification53.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 60.5%
*-commutative60.5%
Simplified60.5%
Applied egg-rr29.3%
Taylor expanded in a 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 60.5%
*-commutative60.5%
Simplified60.5%
Applied egg-rr29.3%
Taylor expanded in b around -inf 11.5%
Final simplification11.5%
herbie shell --seed 2024031
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))