
(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 5e+148)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- b b) (* 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) - (c * (a * 4.0)))) - b) / (a * 2.0);
} 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 <= (-24000000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 5d+148) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
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 <= -24000000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 5e+148) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (b - b) / (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) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = (b - b) / (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(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); 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 <= -24000000.0) tmp = (c / b) - (b / a); elseif (b <= 5e+148) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = (b - b) / (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[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / 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 - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{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%
Taylor expanded in b around inf 100.0%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-56)
(- (/ c b) (/ b a))
(if (<= b 1.05e-60)
(* (/ 0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(/ (- b b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-60) {
tmp = (0.5 / a) * (b + sqrt((a * (c * -4.0))));
} 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 <= (-1.85d-56)) then
tmp = (c / b) - (b / a)
else if (b <= 1.05d-60) then
tmp = (0.5d0 / a) * (b + sqrt((a * (c * (-4.0d0)))))
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 <= -1.85e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-60) {
tmp = (0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-56: tmp = (c / b) - (b / a) elif b <= 1.05e-60: tmp = (0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (b - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-56) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.05e-60) tmp = Float64(Float64(0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))); 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 <= -1.85e-56) tmp = (c / b) - (b / a); elseif (b <= 1.05e-60) tmp = (0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-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[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \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{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.8500000000000001e-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.8500000000000001e-56 < b < 1.04999999999999996e-60Initial program 71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in b around 0 63.9%
*-commutative63.9%
Simplified63.9%
expm1-log1p-u50.0%
expm1-udef17.5%
add-sqr-sqrt10.8%
sqrt-unprod17.7%
sqr-neg17.7%
sqrt-prod7.0%
add-sqr-sqrt17.1%
associate-*l*17.1%
*-commutative17.1%
Applied egg-rr17.1%
expm1-def49.6%
expm1-log1p62.7%
*-rgt-identity62.7%
associate-*r/62.7%
*-commutative62.7%
associate-/r*62.7%
metadata-eval62.7%
Simplified62.7%
if 1.04999999999999996e-60 < b Initial program 49.5%
*-commutative49.5%
Simplified49.5%
Taylor expanded in b around inf 78.8%
Final simplification78.3%
(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 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 - 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 - 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 - 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 - 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(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 - 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[(b - 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{b - 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%
prod-diff71.3%
*-commutative71.3%
fma-def71.3%
associate-+l+71.3%
pow271.3%
distribute-lft-neg-in71.3%
*-commutative71.3%
distribute-rgt-neg-in71.3%
metadata-eval71.3%
associate-*r*71.3%
*-commutative71.3%
*-commutative71.3%
fma-udef71.3%
Applied egg-rr71.3%
fma-def71.3%
fma-def71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in b around 0 62.1%
distribute-rgt-out63.9%
metadata-eval63.9%
associate-*r*63.9%
mul-1-neg63.9%
unsub-neg63.9%
Simplified63.9%
if 8.6000000000000007e-61 < b Initial program 49.5%
*-commutative49.5%
Simplified49.5%
Taylor expanded in b around inf 78.8%
Final simplification78.6%
(FPCore (a b c)
:precision binary64
(if (<= b 4e-308)
(/ (- b) a)
(if (or (<= b 6.2e+250) (not (<= b 5.2e+284)))
(/ (* c (/ a b)) (- a))
(* a (/ c (* b a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 4e-308) {
tmp = -b / a;
} else if ((b <= 6.2e+250) || !(b <= 5.2e+284)) {
tmp = (c * (a / b)) / -a;
} else {
tmp = a * (c / (b * 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 <= 4d-308) then
tmp = -b / a
else if ((b <= 6.2d+250) .or. (.not. (b <= 5.2d+284))) then
tmp = (c * (a / b)) / -a
else
tmp = a * (c / (b * a))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 4e-308) {
tmp = -b / a;
} else if ((b <= 6.2e+250) || !(b <= 5.2e+284)) {
tmp = (c * (a / b)) / -a;
} else {
tmp = a * (c / (b * a));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4e-308: tmp = -b / a elif (b <= 6.2e+250) or not (b <= 5.2e+284): tmp = (c * (a / b)) / -a else: tmp = a * (c / (b * a)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4e-308) tmp = Float64(Float64(-b) / a); elseif ((b <= 6.2e+250) || !(b <= 5.2e+284)) tmp = Float64(Float64(c * Float64(a / b)) / Float64(-a)); else tmp = Float64(a * Float64(c / Float64(b * a))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4e-308) tmp = -b / a; elseif ((b <= 6.2e+250) || ~((b <= 5.2e+284))) tmp = (c * (a / b)) / -a; else tmp = a * (c / (b * a)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4e-308], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 6.2e+250], N[Not[LessEqual[b, 5.2e+284]], $MachinePrecision]], N[(N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] / (-a)), $MachinePrecision], N[(a * N[(c / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{+250} \lor \neg \left(b \leq 5.2 \cdot 10^{+284}\right):\\
\;\;\;\;\frac{c \cdot \frac{a}{b}}{-a}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \frac{c}{b \cdot a}\\
\end{array}
\end{array}
if b < 4.00000000000000013e-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.00000000000000013e-308 < b < 6.2000000000000001e250 or 5.1999999999999997e284 < b Initial program 59.3%
*-commutative59.3%
Simplified59.3%
Taylor expanded in b around inf 33.9%
*-commutative33.9%
associate-/l*37.4%
Simplified37.4%
*-commutative37.4%
*-commutative37.4%
times-frac37.4%
Applied egg-rr37.4%
expm1-log1p-u35.6%
expm1-udef48.4%
associate-*r/48.4%
div-inv48.4%
associate-*l*48.4%
div-inv48.4%
clear-num47.6%
metadata-eval47.6%
metadata-eval47.6%
Applied egg-rr47.6%
expm1-def34.7%
expm1-log1p36.6%
/-rgt-identity36.6%
associate-/l*36.6%
metadata-eval36.6%
associate-/r*36.6%
neg-mul-136.6%
Simplified36.6%
if 6.2000000000000001e250 < b < 5.1999999999999997e284Initial program 1.4%
*-commutative1.4%
Simplified1.4%
Taylor expanded in b around inf 48.1%
*-commutative48.1%
associate-/l*48.4%
Simplified48.4%
*-commutative48.4%
*-commutative48.4%
times-frac48.4%
Applied egg-rr48.4%
frac-2neg48.4%
metadata-eval48.4%
clear-num48.4%
frac-times48.4%
distribute-neg-frac48.4%
add-sqr-sqrt10.6%
sqrt-unprod47.9%
sqr-neg47.9%
sqrt-prod37.8%
add-sqr-sqrt48.4%
*-commutative48.4%
*-un-lft-identity48.4%
div-inv48.4%
clear-num48.4%
div-inv48.4%
metadata-eval48.4%
Applied egg-rr48.4%
*-commutative48.4%
associate-*l*48.4%
metadata-eval48.4%
*-rgt-identity48.4%
*-rgt-identity48.4%
*-commutative48.4%
metadata-eval48.4%
times-frac48.4%
neg-mul-148.4%
associate-*r/48.1%
distribute-neg-frac48.1%
distribute-rgt-neg-out48.1%
neg-mul-148.1%
associate-/r*73.3%
distribute-rgt-neg-in73.3%
neg-mul-173.3%
*-commutative73.3%
times-frac91.5%
Simplified91.5%
Final simplification54.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.1e-308) (/ (- b) a) (if (<= b 4.8e+134) (/ (- c) b) (* a (/ c (* b a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1e-308) {
tmp = -b / a;
} else if (b <= 4.8e+134) {
tmp = -c / b;
} else {
tmp = a * (c / (b * 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 <= 1.1d-308) then
tmp = -b / a
else if (b <= 4.8d+134) then
tmp = -c / b
else
tmp = a * (c / (b * a))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.1e-308) {
tmp = -b / a;
} else if (b <= 4.8e+134) {
tmp = -c / b;
} else {
tmp = a * (c / (b * a));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.1e-308: tmp = -b / a elif b <= 4.8e+134: tmp = -c / b else: tmp = a * (c / (b * a)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.1e-308) tmp = Float64(Float64(-b) / a); elseif (b <= 4.8e+134) tmp = Float64(Float64(-c) / b); else tmp = Float64(a * Float64(c / Float64(b * a))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.1e-308) tmp = -b / a; elseif (b <= 4.8e+134) tmp = -c / b; else tmp = a * (c / (b * a)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.1e-308], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.8e+134], N[((-c) / b), $MachinePrecision], N[(a * N[(c / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{+134}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \frac{c}{b \cdot a}\\
\end{array}
\end{array}
if b < 1.1000000000000001e-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.1000000000000001e-308 < b < 4.80000000000000011e134Initial program 73.1%
*-commutative73.1%
Simplified73.1%
Taylor expanded in b around inf 18.3%
mul-1-neg18.3%
distribute-neg-frac18.3%
Simplified18.3%
if 4.80000000000000011e134 < b Initial program 16.9%
*-commutative16.9%
Simplified16.9%
Taylor expanded in b around inf 55.4%
*-commutative55.4%
associate-/l*62.3%
Simplified62.3%
*-commutative62.3%
*-commutative62.3%
times-frac62.3%
Applied egg-rr62.3%
frac-2neg62.3%
metadata-eval62.3%
clear-num62.3%
frac-times62.3%
distribute-neg-frac62.3%
add-sqr-sqrt26.6%
sqrt-unprod56.6%
sqr-neg56.6%
sqrt-prod35.7%
add-sqr-sqrt60.9%
*-commutative60.9%
*-un-lft-identity60.9%
div-inv60.9%
clear-num60.9%
div-inv60.9%
metadata-eval60.9%
Applied egg-rr60.9%
*-commutative60.9%
associate-*l*60.9%
metadata-eval60.9%
*-rgt-identity60.9%
*-rgt-identity60.9%
*-commutative60.9%
metadata-eval60.9%
times-frac60.9%
neg-mul-160.9%
associate-*r/54.1%
distribute-neg-frac54.1%
distribute-rgt-neg-out54.1%
neg-mul-154.1%
associate-/r*54.0%
distribute-rgt-neg-in54.0%
neg-mul-154.0%
*-commutative54.0%
times-frac62.2%
Simplified62.2%
Final simplification49.9%
(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 55.1%
*-commutative55.1%
Simplified55.1%
Taylor expanded in b around inf 58.8%
Final simplification63.3%
(FPCore (a b c) :precision binary64 (if (<= b 4.1e+14) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.1e+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 <= 4.1d+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 <= 4.1e+14) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.1e+14: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.1e+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 <= 4.1e+14) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.1e+14], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.1 \cdot 10^{+14}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 4.1e14Initial 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 4.1e14 < b Initial program 47.5%
*-commutative47.5%
Simplified47.5%
Applied egg-rr6.5%
Taylor expanded in b around -inf 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%
mul-1-neg27.1%
distribute-neg-frac27.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%
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 63.5%
*-commutative63.5%
Simplified63.5%
Applied egg-rr29.3%
Taylor expanded in b around -inf 11.6%
Final simplification11.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024031
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))