
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* c 4.0) a)))))
(if (<= b -2e+146)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b -1.1e-308)
(* -0.5 (/ (* c 4.0) (- b t_0)))
(if (<= b 2.6e+120) (* -0.5 (/ (+ b t_0) a)) (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((c * 4.0) * a)));
double tmp;
if (b <= -2e+146) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= -1.1e-308) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if (b <= 2.6e+120) {
tmp = -0.5 * ((b + t_0) / a);
} else {
tmp = -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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((c * 4.0d0) * a)))
if (b <= (-2d+146)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= (-1.1d-308)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b - t_0))
else if (b <= 2.6d+120) then
tmp = (-0.5d0) * ((b + t_0) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((c * 4.0) * a)));
double tmp;
if (b <= -2e+146) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= -1.1e-308) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if (b <= 2.6e+120) {
tmp = -0.5 * ((b + t_0) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((c * 4.0) * a))) tmp = 0 if b <= -2e+146: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= -1.1e-308: tmp = -0.5 * ((c * 4.0) / (b - t_0)) elif b <= 2.6e+120: tmp = -0.5 * ((b + t_0) / a) else: tmp = -b / a return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a))) tmp = 0.0 if (b <= -2e+146) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= -1.1e-308) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b - t_0))); elseif (b <= 2.6e+120) tmp = Float64(-0.5 * Float64(Float64(b + t_0) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((c * 4.0) * a))); tmp = 0.0; if (b <= -2e+146) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= -1.1e-308) tmp = -0.5 * ((c * 4.0) / (b - t_0)); elseif (b <= 2.6e+120) tmp = -0.5 * ((b + t_0) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2e+146], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.1e-308], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.6e+120], N[(-0.5 * N[(N[(b + t$95$0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+146}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq -1.1 \cdot 10^{-308}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - t_0}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+120}:\\
\;\;\;\;-0.5 \cdot \frac{b + t_0}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.99999999999999987e146Initial program 2.0%
Simplified2.0%
fma-udef2.0%
associate-*r*2.0%
metadata-eval2.0%
distribute-rgt-neg-in2.0%
*-commutative2.0%
+-commutative2.0%
sub-neg2.0%
*-commutative2.0%
associate-*l*2.0%
Applied egg-rr2.0%
flip-+0.3%
add-sqr-sqrt0.3%
Applied egg-rr0.3%
associate--r-5.2%
+-inverses44.6%
sub-neg44.6%
+-commutative44.6%
distribute-rgt-neg-in44.6%
fma-udef44.6%
distribute-rgt-neg-in44.6%
metadata-eval44.6%
Simplified44.6%
expm1-log1p-u44.6%
expm1-udef39.7%
+-lft-identity39.7%
Applied egg-rr39.7%
expm1-def44.6%
expm1-log1p44.6%
associate-/l/44.6%
times-frac44.8%
*-inverses44.8%
Simplified44.8%
Taylor expanded in b around -inf 94.9%
mul-1-neg94.9%
unsub-neg94.9%
*-commutative94.9%
associate-/l*95.1%
Simplified95.1%
if -1.99999999999999987e146 < b < -1.1000000000000001e-308Initial program 42.6%
Simplified42.6%
fma-udef42.6%
associate-*r*42.6%
metadata-eval42.6%
distribute-rgt-neg-in42.6%
*-commutative42.6%
+-commutative42.6%
sub-neg42.6%
*-commutative42.6%
associate-*l*42.6%
Applied egg-rr42.6%
flip-+42.3%
add-sqr-sqrt42.1%
Applied egg-rr42.1%
associate--r-68.4%
+-inverses68.4%
sub-neg68.4%
+-commutative68.4%
distribute-rgt-neg-in68.4%
fma-udef68.4%
distribute-rgt-neg-in68.4%
metadata-eval68.4%
Simplified68.4%
expm1-log1p-u47.8%
expm1-udef26.8%
+-lft-identity26.8%
Applied egg-rr26.8%
expm1-def47.8%
expm1-log1p68.4%
associate-/l/64.8%
times-frac81.8%
*-inverses81.8%
Simplified81.8%
fma-udef42.6%
associate-*r*42.6%
metadata-eval42.6%
distribute-rgt-neg-in42.6%
*-commutative42.6%
+-commutative42.6%
sub-neg42.6%
*-commutative42.6%
associate-*l*42.6%
Applied egg-rr81.8%
if -1.1000000000000001e-308 < b < 2.5999999999999999e120Initial program 81.5%
Simplified81.5%
fma-udef81.5%
associate-*r*81.5%
metadata-eval81.5%
distribute-rgt-neg-in81.5%
*-commutative81.5%
+-commutative81.5%
sub-neg81.5%
*-commutative81.5%
associate-*l*81.5%
Applied egg-rr81.5%
if 2.5999999999999999e120 < b Initial program 52.1%
Taylor expanded in b around inf 96.4%
associate-*r/96.4%
mul-1-neg96.4%
Simplified96.4%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (* (* c a) -4.0))))
(if (<= b -2.2e-59)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b 1.3e-121)
(* -0.5 (/ (* c 4.0) (- b t_0)))
(if (or (<= b 1.7e-17) (not (<= b 2.2)))
(- (/ c b) (/ b a))
(* -0.5 (/ (+ b t_0) a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((c * a) * -4.0));
double tmp;
if (b <= -2.2e-59) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 1.3e-121) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if ((b <= 1.7e-17) || !(b <= 2.2)) {
tmp = (c / b) - (b / a);
} else {
tmp = -0.5 * ((b + t_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(((c * a) * (-4.0d0)))
if (b <= (-2.2d-59)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= 1.3d-121) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b - t_0))
else if ((b <= 1.7d-17) .or. (.not. (b <= 2.2d0))) then
tmp = (c / b) - (b / a)
else
tmp = (-0.5d0) * ((b + t_0) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((c * a) * -4.0));
double tmp;
if (b <= -2.2e-59) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 1.3e-121) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if ((b <= 1.7e-17) || !(b <= 2.2)) {
tmp = (c / b) - (b / a);
} else {
tmp = -0.5 * ((b + t_0) / a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((c * a) * -4.0)) tmp = 0 if b <= -2.2e-59: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= 1.3e-121: tmp = -0.5 * ((c * 4.0) / (b - t_0)) elif (b <= 1.7e-17) or not (b <= 2.2): tmp = (c / b) - (b / a) else: tmp = -0.5 * ((b + t_0) / a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(c * a) * -4.0)) tmp = 0.0 if (b <= -2.2e-59) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= 1.3e-121) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b - t_0))); elseif ((b <= 1.7e-17) || !(b <= 2.2)) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(-0.5 * Float64(Float64(b + t_0) / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((c * a) * -4.0)); tmp = 0.0; if (b <= -2.2e-59) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= 1.3e-121) tmp = -0.5 * ((c * 4.0) / (b - t_0)); elseif ((b <= 1.7e-17) || ~((b <= 2.2))) tmp = (c / b) - (b / a); else tmp = -0.5 * ((b + t_0) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.2e-59], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.3e-121], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 1.7e-17], N[Not[LessEqual[b, 2.2]], $MachinePrecision]], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b + t$95$0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(c \cdot a\right) \cdot -4}\\
\mathbf{if}\;b \leq -2.2 \cdot 10^{-59}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{-121}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - t_0}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-17} \lor \neg \left(b \leq 2.2\right):\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + t_0}{a}\\
\end{array}
\end{array}
if b < -2.1999999999999999e-59Initial program 18.3%
Simplified18.3%
fma-udef18.3%
associate-*r*18.3%
metadata-eval18.3%
distribute-rgt-neg-in18.3%
*-commutative18.3%
+-commutative18.3%
sub-neg18.3%
*-commutative18.3%
associate-*l*18.3%
Applied egg-rr18.3%
flip-+17.3%
add-sqr-sqrt17.3%
Applied egg-rr17.3%
associate--r-44.2%
+-inverses61.4%
sub-neg61.4%
+-commutative61.4%
distribute-rgt-neg-in61.4%
fma-udef61.4%
distribute-rgt-neg-in61.4%
metadata-eval61.4%
Simplified61.4%
expm1-log1p-u53.0%
expm1-udef36.4%
+-lft-identity36.4%
Applied egg-rr36.4%
expm1-def53.0%
expm1-log1p61.4%
associate-/l/62.8%
times-frac69.1%
*-inverses69.1%
Simplified69.1%
Taylor expanded in b around -inf 84.0%
mul-1-neg84.0%
unsub-neg84.0%
*-commutative84.0%
associate-/l*84.2%
Simplified84.2%
if -2.1999999999999999e-59 < b < 1.29999999999999993e-121Initial program 65.5%
Simplified65.5%
fma-udef65.5%
associate-*r*65.5%
metadata-eval65.5%
distribute-rgt-neg-in65.5%
*-commutative65.5%
+-commutative65.5%
sub-neg65.5%
*-commutative65.5%
associate-*l*65.5%
Applied egg-rr65.5%
flip-+64.5%
add-sqr-sqrt64.3%
Applied egg-rr64.3%
associate--r-65.7%
+-inverses65.7%
sub-neg65.7%
+-commutative65.7%
distribute-rgt-neg-in65.7%
fma-udef65.7%
distribute-rgt-neg-in65.7%
metadata-eval65.7%
Simplified65.7%
expm1-log1p-u43.3%
expm1-udef23.4%
+-lft-identity23.4%
Applied egg-rr23.4%
expm1-def43.3%
expm1-log1p65.7%
associate-/l/56.0%
times-frac72.7%
*-inverses72.7%
Simplified72.7%
Taylor expanded in a around inf 66.8%
*-commutative65.5%
Simplified66.8%
if 1.29999999999999993e-121 < b < 1.6999999999999999e-17 or 2.2000000000000002 < b Initial program 68.3%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
unsub-neg84.6%
Simplified84.6%
if 1.6999999999999999e-17 < b < 2.2000000000000002Initial program 83.3%
Simplified83.3%
Taylor expanded in a around inf 83.3%
*-commutative83.3%
Simplified83.3%
Final simplification79.4%
(FPCore (a b c)
:precision binary64
(if (<= b -3.1e-109)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b 5e+119)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.1e-109) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 5e+119) {
tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / a);
} else {
tmp = -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 <= (-3.1d-109)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= 5d+119) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.1e-109) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 5e+119) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.1e-109: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= 5e+119: tmp = -0.5 * ((b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.1e-109) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= 5e+119) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.1e-109) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= 5e+119) tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.1e-109], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+119], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1 \cdot 10^{-109}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+119}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.1e-109Initial program 20.1%
Simplified20.1%
fma-udef20.1%
associate-*r*20.1%
metadata-eval20.1%
distribute-rgt-neg-in20.1%
*-commutative20.1%
+-commutative20.1%
sub-neg20.1%
*-commutative20.1%
associate-*l*20.1%
Applied egg-rr20.1%
flip-+19.1%
add-sqr-sqrt19.1%
Applied egg-rr19.1%
associate--r-44.5%
+-inverses60.3%
sub-neg60.3%
+-commutative60.3%
distribute-rgt-neg-in60.3%
fma-udef60.3%
distribute-rgt-neg-in60.3%
metadata-eval60.3%
Simplified60.3%
expm1-log1p-u51.5%
expm1-udef35.2%
+-lft-identity35.2%
Applied egg-rr35.2%
expm1-def51.5%
expm1-log1p60.3%
associate-/l/61.5%
times-frac69.7%
*-inverses69.7%
Simplified69.7%
Taylor expanded in b around -inf 80.3%
mul-1-neg80.3%
unsub-neg80.3%
*-commutative80.3%
associate-/l*80.5%
Simplified80.5%
if -3.1e-109 < b < 4.9999999999999999e119Initial program 76.7%
Simplified76.7%
fma-udef76.7%
associate-*r*76.7%
metadata-eval76.7%
distribute-rgt-neg-in76.7%
*-commutative76.7%
+-commutative76.7%
sub-neg76.7%
*-commutative76.7%
associate-*l*76.7%
Applied egg-rr76.7%
if 4.9999999999999999e119 < b Initial program 52.1%
Taylor expanded in b around inf 96.4%
associate-*r/96.4%
mul-1-neg96.4%
Simplified96.4%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-121)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b 2.2)
(* -0.5 (/ (+ b (sqrt (* (* c a) -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-121) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 2.2) {
tmp = -0.5 * ((b + sqrt(((c * a) * -4.0))) / a);
} else {
tmp = (c / b) - (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 <= (-7d-121)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= 2.2d0) then
tmp = (-0.5d0) * ((b + sqrt(((c * a) * (-4.0d0)))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7e-121) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 2.2) {
tmp = -0.5 * ((b + Math.sqrt(((c * a) * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-121: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= 2.2: tmp = -0.5 * ((b + math.sqrt(((c * a) * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-121) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= 2.2) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(c * a) * -4.0))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-121) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= 2.2) tmp = -0.5 * ((b + sqrt(((c * a) * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-121], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-121}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq 2.2:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.99999999999999985e-121Initial program 20.1%
Simplified20.1%
fma-udef20.1%
associate-*r*20.1%
metadata-eval20.1%
distribute-rgt-neg-in20.1%
*-commutative20.1%
+-commutative20.1%
sub-neg20.1%
*-commutative20.1%
associate-*l*20.1%
Applied egg-rr20.1%
flip-+19.1%
add-sqr-sqrt19.1%
Applied egg-rr19.1%
associate--r-44.5%
+-inverses60.3%
sub-neg60.3%
+-commutative60.3%
distribute-rgt-neg-in60.3%
fma-udef60.3%
distribute-rgt-neg-in60.3%
metadata-eval60.3%
Simplified60.3%
expm1-log1p-u51.5%
expm1-udef35.2%
+-lft-identity35.2%
Applied egg-rr35.2%
expm1-def51.5%
expm1-log1p60.3%
associate-/l/61.5%
times-frac69.7%
*-inverses69.7%
Simplified69.7%
Taylor expanded in b around -inf 80.3%
mul-1-neg80.3%
unsub-neg80.3%
*-commutative80.3%
associate-/l*80.5%
Simplified80.5%
if -6.99999999999999985e-121 < b < 2.2000000000000002Initial program 73.0%
Simplified73.0%
Taylor expanded in a around inf 64.4%
*-commutative64.4%
Simplified64.4%
if 2.2000000000000002 < b Initial program 64.6%
Taylor expanded in b around inf 89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
Final simplification77.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0))))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else {
tmp = (c / b) - (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 <= (-1d-309)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 30.2%
Simplified30.2%
fma-udef30.2%
associate-*r*30.2%
metadata-eval30.2%
distribute-rgt-neg-in30.2%
*-commutative30.2%
+-commutative30.2%
sub-neg30.2%
*-commutative30.2%
associate-*l*30.2%
Applied egg-rr30.2%
flip-+29.4%
add-sqr-sqrt29.3%
Applied egg-rr29.3%
associate--r-49.0%
+-inverses61.1%
sub-neg61.1%
+-commutative61.1%
distribute-rgt-neg-in61.1%
fma-udef61.1%
distribute-rgt-neg-in61.1%
metadata-eval61.1%
Simplified61.1%
expm1-log1p-u46.8%
expm1-udef30.8%
+-lft-identity30.8%
Applied egg-rr30.8%
expm1-def46.8%
expm1-log1p61.1%
associate-/l/58.6%
times-frac70.4%
*-inverses70.4%
Simplified70.4%
Taylor expanded in b around -inf 68.0%
mul-1-neg68.0%
unsub-neg68.0%
*-commutative68.0%
associate-/l*68.3%
Simplified68.3%
if -1.000000000000002e-309 < b Initial program 70.3%
Taylor expanded in b around inf 61.4%
mul-1-neg61.4%
unsub-neg61.4%
Simplified61.4%
Final simplification64.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} else {
tmp = (c / b) - (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 <= (-1d-309)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 30.2%
Taylor expanded in b around -inf 68.0%
associate-*r/68.0%
neg-mul-168.0%
Simplified68.0%
if -1.000000000000002e-309 < b Initial program 70.3%
Taylor expanded in b around inf 61.4%
mul-1-neg61.4%
unsub-neg61.4%
Simplified61.4%
Final simplification64.6%
(FPCore (a b c) :precision binary64 (if (<= b -75000000.0) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -75000000.0) {
tmp = c / b;
} else {
tmp = -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 <= (-75000000.0d0)) then
tmp = c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -75000000.0) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -75000000.0: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -75000000.0) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -75000000.0) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -75000000.0], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -75000000:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.5e7Initial program 17.1%
Taylor expanded in b around inf 2.1%
mul-1-neg2.1%
unsub-neg2.1%
Simplified2.1%
Taylor expanded in c around inf 29.6%
if -7.5e7 < b Initial program 64.4%
Taylor expanded in b around inf 45.0%
associate-*r/45.0%
mul-1-neg45.0%
Simplified45.0%
Final simplification40.6%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} else {
tmp = -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 <= (-1d-309)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 30.2%
Taylor expanded in b around -inf 68.0%
associate-*r/68.0%
neg-mul-168.0%
Simplified68.0%
if -1.000000000000002e-309 < b Initial program 70.3%
Taylor expanded in b around inf 61.3%
associate-*r/61.3%
mul-1-neg61.3%
Simplified61.3%
Final simplification64.5%
(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 50.9%
Taylor expanded in b around inf 32.7%
mul-1-neg32.7%
unsub-neg32.7%
Simplified32.7%
Taylor expanded in c around inf 10.8%
Final simplification10.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023224
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))