
(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 -5.8e-82)
(/ c (- b))
(if (<= b 5e+129)
(/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) (* a (- 2.0)))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-82) {
tmp = c / -b;
} else if (b <= 5e+129) {
tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0);
} 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 <= (-5.8d-82)) then
tmp = c / -b
else if (b <= 5d+129) then
tmp = (b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / (a * -2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-82) {
tmp = c / -b;
} else if (b <= 5e+129) {
tmp = (b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-82: tmp = c / -b elif b <= 5e+129: tmp = (b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 5e+129) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * Float64(-2.0))); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e-82) tmp = c / -b; elseif (b <= 5e+129) tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5e+129], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * (-2.0)), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+129}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -5.79999999999999954e-82Initial program 16.2%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*14.7%
distribute-neg-frac14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*15.7%
distribute-rgt-out16.2%
associate-/r*16.2%
metadata-eval16.2%
sub-neg16.2%
+-commutative16.2%
Simplified16.2%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -5.79999999999999954e-82 < b < 5.0000000000000003e129Initial program 86.3%
*-commutative86.3%
sqr-neg86.3%
*-commutative86.3%
sqr-neg86.3%
*-commutative86.3%
associate-*r*86.3%
*-commutative86.3%
Simplified86.3%
if 5.0000000000000003e129 < b Initial program 63.6%
div-sub63.6%
sub-neg63.6%
neg-mul-163.6%
*-commutative63.6%
associate-/l*63.6%
distribute-neg-frac63.6%
neg-mul-163.6%
*-commutative63.6%
associate-/l*63.6%
distribute-rgt-out63.6%
associate-/r*63.6%
metadata-eval63.6%
sub-neg63.6%
+-commutative63.6%
Simplified63.7%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(if (<= b -6.2e-82)
(/ c (- b))
(if (<= b 4.5e+129)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-82) {
tmp = c / -b;
} else if (b <= 4.5e+129) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-6.2d-82)) then
tmp = c / -b
else if (b <= 4.5d+129) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-82) {
tmp = c / -b;
} else if (b <= 4.5e+129) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e-82: tmp = c / -b elif b <= 4.5e+129: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 4.5e+129) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.2e-82) tmp = c / -b; elseif (b <= 4.5e+129) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.5e+129], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.2 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{+129}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -6.19999999999999999e-82Initial program 16.2%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*14.7%
distribute-neg-frac14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*15.7%
distribute-rgt-out16.2%
associate-/r*16.2%
metadata-eval16.2%
sub-neg16.2%
+-commutative16.2%
Simplified16.2%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -6.19999999999999999e-82 < b < 4.5000000000000001e129Initial program 86.3%
if 4.5000000000000001e129 < b Initial program 63.6%
div-sub63.6%
sub-neg63.6%
neg-mul-163.6%
*-commutative63.6%
associate-/l*63.6%
distribute-neg-frac63.6%
neg-mul-163.6%
*-commutative63.6%
associate-/l*63.6%
distribute-rgt-out63.6%
associate-/r*63.6%
metadata-eval63.6%
sub-neg63.6%
+-commutative63.6%
Simplified63.7%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(if (<= b -9.2e-83)
(/ c (- b))
(if (<= b 1.4e-26)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.2e-83) {
tmp = c / -b;
} else if (b <= 1.4e-26) {
tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.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 <= (-9.2d-83)) then
tmp = c / -b
else if (b <= 1.4d-26) then
tmp = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.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 <= -9.2e-83) {
tmp = c / -b;
} else if (b <= 1.4e-26) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.2e-83: tmp = c / -b elif b <= 1.4e-26: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.2e-83) tmp = Float64(c / Float64(-b)); elseif (b <= 1.4e-26) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.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 <= -9.2e-83) tmp = c / -b; elseif (b <= 1.4e-26) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.2e-83], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.4e-26], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.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 -9.2 \cdot 10^{-83}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-26}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.19999999999999959e-83Initial program 16.2%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*14.7%
distribute-neg-frac14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*15.7%
distribute-rgt-out16.2%
associate-/r*16.2%
metadata-eval16.2%
sub-neg16.2%
+-commutative16.2%
Simplified16.2%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -9.19999999999999959e-83 < b < 1.4000000000000001e-26Initial program 81.4%
div-sub81.3%
sub-neg81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.3%
distribute-neg-frac81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.1%
distribute-rgt-out81.2%
associate-/r*81.2%
metadata-eval81.2%
sub-neg81.2%
+-commutative81.2%
Simplified81.2%
Taylor expanded in a around inf 75.7%
metadata-eval75.7%
distribute-lft-neg-in75.7%
associate-*r*75.7%
*-commutative75.7%
distribute-rgt-neg-in75.7%
distribute-lft-neg-in75.7%
metadata-eval75.7%
*-commutative75.7%
Simplified75.7%
if 1.4000000000000001e-26 < b Initial program 76.6%
div-sub76.6%
sub-neg76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.5%
distribute-neg-frac76.5%
neg-mul-176.5%
*-commutative76.5%
associate-/l*76.4%
distribute-rgt-out76.4%
associate-/r*76.4%
metadata-eval76.4%
sub-neg76.4%
+-commutative76.4%
Simplified76.5%
Taylor expanded in c around 0 92.7%
+-commutative92.7%
mul-1-neg92.7%
unsub-neg92.7%
Simplified92.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-82)
(/ c (- b))
(if (<= b 6.4e-27)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-82) {
tmp = c / -b;
} else if (b <= 6.4e-27) {
tmp = sqrt((a * (c * -4.0))) / (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 <= (-1.45d-82)) then
tmp = c / -b
else if (b <= 6.4d-27) then
tmp = sqrt((a * (c * (-4.0d0)))) / (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 <= -1.45e-82) {
tmp = c / -b;
} else if (b <= 6.4e-27) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-82: tmp = c / -b elif b <= 6.4e-27: tmp = math.sqrt((a * (c * -4.0))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 6.4e-27) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-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 <= -1.45e-82) tmp = c / -b; elseif (b <= 6.4e-27) tmp = sqrt((a * (c * -4.0))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.4e-27], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * (-2.0)), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.4 \cdot 10^{-27}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.44999999999999989e-82Initial program 16.2%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*14.7%
distribute-neg-frac14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*15.7%
distribute-rgt-out16.2%
associate-/r*16.2%
metadata-eval16.2%
sub-neg16.2%
+-commutative16.2%
Simplified16.2%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -1.44999999999999989e-82 < b < 6.39999999999999982e-27Initial program 81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
sqr-neg81.4%
*-commutative81.4%
associate-*r*81.4%
*-commutative81.4%
Simplified81.4%
add-cube-cbrt80.8%
pow380.9%
*-commutative80.9%
associate-*l*80.9%
Applied egg-rr80.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt74.3%
mul-1-neg74.3%
rem-cube-cbrt74.9%
Simplified74.9%
if 6.39999999999999982e-27 < b Initial program 76.6%
div-sub76.6%
sub-neg76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.5%
distribute-neg-frac76.5%
neg-mul-176.5%
*-commutative76.5%
associate-/l*76.4%
distribute-rgt-out76.4%
associate-/r*76.4%
metadata-eval76.4%
sub-neg76.4%
+-commutative76.4%
Simplified76.5%
Taylor expanded in c around 0 92.7%
+-commutative92.7%
mul-1-neg92.7%
unsub-neg92.7%
Simplified92.7%
Final simplification85.7%
(FPCore (a b c)
:precision binary64
(if (<= b -4.35e-218)
(/ c (- b))
(if (<= b 1.18e-51)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.35e-218) {
tmp = c / -b;
} else if (b <= 1.18e-51) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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 <= (-4.35d-218)) then
tmp = c / -b
else if (b <= 1.18d-51) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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 <= -4.35e-218) {
tmp = c / -b;
} else if (b <= 1.18e-51) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.35e-218: tmp = c / -b elif b <= 1.18e-51: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.35e-218) tmp = Float64(c / Float64(-b)); elseif (b <= 1.18e-51) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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 <= -4.35e-218) tmp = c / -b; elseif (b <= 1.18e-51) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.35e-218], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.18e-51], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.35 \cdot 10^{-218}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.18 \cdot 10^{-51}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.34999999999999982e-218Initial program 26.1%
div-sub25.7%
sub-neg25.7%
neg-mul-125.7%
*-commutative25.7%
associate-/l*24.8%
distribute-neg-frac24.8%
neg-mul-124.8%
*-commutative24.8%
associate-/l*25.7%
distribute-rgt-out26.0%
associate-/r*26.0%
metadata-eval26.0%
sub-neg26.0%
+-commutative26.0%
Simplified26.0%
Taylor expanded in b around -inf 76.1%
mul-1-neg76.1%
distribute-neg-frac276.1%
Simplified76.1%
if -4.34999999999999982e-218 < b < 1.18000000000000004e-51Initial program 82.3%
*-commutative82.3%
sqr-neg82.3%
*-commutative82.3%
sqr-neg82.3%
*-commutative82.3%
associate-*r*82.4%
*-commutative82.4%
Simplified82.4%
add-cube-cbrt81.8%
pow381.8%
*-commutative81.8%
associate-*l*81.8%
Applied egg-rr81.8%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt44.7%
neg-mul-144.7%
rem-cube-cbrt45.0%
associate-/l*45.0%
Simplified45.0%
if 1.18000000000000004e-51 < b Initial program 77.8%
div-sub77.8%
sub-neg77.8%
neg-mul-177.8%
*-commutative77.8%
associate-/l*77.7%
distribute-neg-frac77.7%
neg-mul-177.7%
*-commutative77.7%
associate-/l*77.6%
distribute-rgt-out77.6%
associate-/r*77.6%
metadata-eval77.6%
sub-neg77.6%
+-commutative77.6%
Simplified77.7%
Taylor expanded in c around 0 90.3%
+-commutative90.3%
mul-1-neg90.3%
unsub-neg90.3%
Simplified90.3%
Final simplification76.1%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(c / Float64(-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 <= -2e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 31.3%
div-sub31.0%
sub-neg31.0%
neg-mul-131.0%
*-commutative31.0%
associate-/l*30.1%
distribute-neg-frac30.1%
neg-mul-130.1%
*-commutative30.1%
associate-/l*30.9%
distribute-rgt-out31.2%
associate-/r*31.2%
metadata-eval31.2%
sub-neg31.2%
+-commutative31.2%
Simplified31.3%
Taylor expanded in b around -inf 68.6%
mul-1-neg68.6%
distribute-neg-frac268.6%
Simplified68.6%
if -1.999999999999994e-310 < b Initial program 79.5%
div-sub79.5%
sub-neg79.5%
neg-mul-179.5%
*-commutative79.5%
associate-/l*79.4%
distribute-neg-frac79.4%
neg-mul-179.4%
*-commutative79.4%
associate-/l*79.3%
distribute-rgt-out79.3%
associate-/r*79.3%
metadata-eval79.3%
sub-neg79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in c around 0 70.9%
+-commutative70.9%
mul-1-neg70.9%
unsub-neg70.9%
Simplified70.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 31.3%
div-sub31.0%
sub-neg31.0%
neg-mul-131.0%
*-commutative31.0%
associate-/l*30.1%
distribute-neg-frac30.1%
neg-mul-130.1%
*-commutative30.1%
associate-/l*30.9%
distribute-rgt-out31.2%
associate-/r*31.2%
metadata-eval31.2%
sub-neg31.2%
+-commutative31.2%
Simplified31.3%
Taylor expanded in b around -inf 68.6%
mul-1-neg68.6%
distribute-neg-frac268.6%
Simplified68.6%
if -1.999999999999994e-310 < b Initial program 79.5%
div-sub79.5%
sub-neg79.5%
neg-mul-179.5%
*-commutative79.5%
associate-/l*79.4%
distribute-neg-frac79.4%
neg-mul-179.4%
*-commutative79.4%
associate-/l*79.3%
distribute-rgt-out79.3%
associate-/r*79.3%
metadata-eval79.3%
sub-neg79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in a around 0 70.5%
associate-*r/70.5%
mul-1-neg70.5%
Simplified70.5%
Final simplification69.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 / Float64(-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 55.9%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.6%
distribute-rgt-out55.8%
associate-/r*55.8%
metadata-eval55.8%
sub-neg55.8%
+-commutative55.8%
Simplified55.8%
Taylor expanded in b around -inf 34.7%
mul-1-neg34.7%
distribute-neg-frac234.7%
Simplified34.7%
(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 55.9%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.6%
distribute-rgt-out55.8%
associate-/r*55.8%
metadata-eval55.8%
sub-neg55.8%
+-commutative55.8%
Simplified55.8%
Taylor expanded in c around 0 37.4%
+-commutative37.4%
mul-1-neg37.4%
unsub-neg37.4%
Simplified37.4%
Taylor expanded in c around inf 9.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 55.9%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.6%
distribute-rgt-out55.8%
associate-/r*55.8%
metadata-eval55.8%
sub-neg55.8%
+-commutative55.8%
Simplified55.8%
Taylor expanded in a around 0 37.4%
associate-*r/37.4%
mul-1-neg37.4%
Simplified37.4%
add-sqr-sqrt18.4%
sqrt-unprod14.1%
distribute-frac-neg14.1%
distribute-frac-neg14.1%
sqr-neg14.1%
sqrt-unprod1.4%
add-sqr-sqrt2.3%
*-un-lft-identity2.3%
Applied egg-rr2.3%
*-lft-identity2.3%
Simplified2.3%
(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 2024180
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))