
(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 -0.0013)
(/ c (- b))
(if (<= b 2e+96)
(/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.0013) {
tmp = c / -b;
} else if (b <= 2e+96) {
tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (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 <= (-0.0013d0)) then
tmp = c / -b
else if (b <= 2d+96) then
tmp = (b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / (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 <= -0.0013) {
tmp = c / -b;
} else if (b <= 2e+96) {
tmp = (b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.0013: tmp = c / -b elif b <= 2e+96: tmp = (b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.0013) tmp = Float64(c / Float64(-b)); elseif (b <= 2e+96) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / 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 <= -0.0013) tmp = c / -b; elseif (b <= 2e+96) tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.0013], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2e+96], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0013:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+96}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -0.0012999999999999999Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.2%
distribute-neg-frac12.2%
neg-mul-112.2%
*-commutative12.2%
associate-/l*14.6%
distribute-rgt-out15.1%
associate-/r*15.1%
metadata-eval15.1%
sub-neg15.1%
+-commutative15.1%
Simplified15.1%
Taylor expanded in b around -inf 87.0%
mul-1-neg87.0%
distribute-neg-frac287.0%
Simplified87.0%
if -0.0012999999999999999 < b < 2.0000000000000001e96Initial program 76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
associate-*r*76.7%
*-commutative76.7%
Simplified76.7%
if 2.0000000000000001e96 < b Initial program 55.2%
div-sub55.2%
sub-neg55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.1%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.1%
Taylor expanded in c around 0 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Final simplification83.7%
(FPCore (a b c)
:precision binary64
(if (<= b -0.0013)
(/ c (- b))
(if (<= b 5.9e+94)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.0013) {
tmp = c / -b;
} else if (b <= 5.9e+94) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (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 <= (-0.0013d0)) then
tmp = c / -b
else if (b <= 5.9d+94) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (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 <= -0.0013) {
tmp = c / -b;
} else if (b <= 5.9e+94) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.0013: tmp = c / -b elif b <= 5.9e+94: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.0013) tmp = Float64(c / Float64(-b)); elseif (b <= 5.9e+94) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(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 <= -0.0013) tmp = c / -b; elseif (b <= 5.9e+94) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.0013], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.9e+94], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0013:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.9 \cdot 10^{+94}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -0.0012999999999999999Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.2%
distribute-neg-frac12.2%
neg-mul-112.2%
*-commutative12.2%
associate-/l*14.6%
distribute-rgt-out15.1%
associate-/r*15.1%
metadata-eval15.1%
sub-neg15.1%
+-commutative15.1%
Simplified15.1%
Taylor expanded in b around -inf 87.0%
mul-1-neg87.0%
distribute-neg-frac287.0%
Simplified87.0%
if -0.0012999999999999999 < b < 5.8999999999999999e94Initial program 76.7%
if 5.8999999999999999e94 < b Initial program 55.2%
div-sub55.2%
sub-neg55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.1%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.1%
Taylor expanded in c around 0 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Final simplification83.7%
(FPCore (a b c)
:precision binary64
(if (<= b -0.00082)
(/ c (- b))
(if (<= b 7e-24)
(/ (- (- b) (sqrt (* a (* c -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.00082) {
tmp = c / -b;
} else if (b <= 7e-24) {
tmp = (-b - 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 <= (-0.00082d0)) then
tmp = c / -b
else if (b <= 7d-24) then
tmp = (-b - 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 <= -0.00082) {
tmp = c / -b;
} else if (b <= 7e-24) {
tmp = (-b - 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 <= -0.00082: tmp = c / -b elif b <= 7e-24: tmp = (-b - 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 <= -0.00082) tmp = Float64(c / Float64(-b)); elseif (b <= 7e-24) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))) / Float64(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 <= -0.00082) tmp = c / -b; elseif (b <= 7e-24) tmp = (-b - 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, -0.00082], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7e-24], N[(N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $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 -0.00082:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-24}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.1999999999999998e-4Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.2%
distribute-neg-frac12.2%
neg-mul-112.2%
*-commutative12.2%
associate-/l*14.6%
distribute-rgt-out15.1%
associate-/r*15.1%
metadata-eval15.1%
sub-neg15.1%
+-commutative15.1%
Simplified15.1%
Taylor expanded in b around -inf 87.0%
mul-1-neg87.0%
distribute-neg-frac287.0%
Simplified87.0%
if -8.1999999999999998e-4 < b < 6.9999999999999993e-24Initial program 72.7%
*-commutative72.7%
sqr-neg72.7%
*-commutative72.7%
sqr-neg72.7%
*-commutative72.7%
associate-*r*72.7%
*-commutative72.7%
Simplified72.7%
add-cube-cbrt72.1%
pow372.2%
*-commutative72.2%
associate-*l*72.2%
Applied egg-rr72.2%
Taylor expanded in c around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt67.8%
rem-cube-cbrt68.1%
Simplified68.1%
if 6.9999999999999993e-24 < b Initial program 66.8%
div-sub66.8%
sub-neg66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.8%
distribute-neg-frac66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.7%
distribute-rgt-out66.7%
associate-/r*66.7%
metadata-eval66.7%
sub-neg66.7%
+-commutative66.7%
Simplified66.7%
Taylor expanded in c around 0 84.4%
+-commutative84.4%
mul-1-neg84.4%
unsub-neg84.4%
Simplified84.4%
Final simplification79.6%
(FPCore (a b c)
:precision binary64
(if (<= b -0.00082)
(/ c (- b))
(if (<= b 6e-28)
(* (/ -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 <= -0.00082) {
tmp = c / -b;
} else if (b <= 6e-28) {
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 <= (-0.00082d0)) then
tmp = c / -b
else if (b <= 6d-28) 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 <= -0.00082) {
tmp = c / -b;
} else if (b <= 6e-28) {
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 <= -0.00082: tmp = c / -b elif b <= 6e-28: 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 <= -0.00082) tmp = Float64(c / Float64(-b)); elseif (b <= 6e-28) 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 <= -0.00082) tmp = c / -b; elseif (b <= 6e-28) 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, -0.00082], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6e-28], 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 -0.00082:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-28}:\\
\;\;\;\;\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 < -8.1999999999999998e-4Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.2%
distribute-neg-frac12.2%
neg-mul-112.2%
*-commutative12.2%
associate-/l*14.6%
distribute-rgt-out15.1%
associate-/r*15.1%
metadata-eval15.1%
sub-neg15.1%
+-commutative15.1%
Simplified15.1%
Taylor expanded in b around -inf 87.0%
mul-1-neg87.0%
distribute-neg-frac287.0%
Simplified87.0%
if -8.1999999999999998e-4 < b < 6.00000000000000005e-28Initial program 72.7%
div-sub72.7%
sub-neg72.7%
neg-mul-172.7%
*-commutative72.7%
associate-/l*72.7%
distribute-neg-frac72.7%
neg-mul-172.7%
*-commutative72.7%
associate-/l*72.6%
distribute-rgt-out72.6%
associate-/r*72.6%
metadata-eval72.6%
sub-neg72.6%
+-commutative72.6%
Simplified72.6%
Taylor expanded in a around inf 68.0%
metadata-eval68.0%
distribute-lft-neg-in68.0%
associate-*r*68.0%
*-commutative68.0%
distribute-rgt-neg-in68.0%
distribute-lft-neg-in68.0%
metadata-eval68.0%
*-commutative68.0%
Simplified68.0%
if 6.00000000000000005e-28 < b Initial program 66.8%
div-sub66.8%
sub-neg66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.8%
distribute-neg-frac66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.7%
distribute-rgt-out66.7%
associate-/r*66.7%
metadata-eval66.7%
sub-neg66.7%
+-commutative66.7%
Simplified66.7%
Taylor expanded in c around 0 84.4%
+-commutative84.4%
mul-1-neg84.4%
unsub-neg84.4%
Simplified84.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e-104)
(/ c (- b))
(if (<= b 6.2e-45)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e-104) {
tmp = c / -b;
} else if (b <= 6.2e-45) {
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 <= (-1.22d-104)) then
tmp = c / -b
else if (b <= 6.2d-45) 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 <= -1.22e-104) {
tmp = c / -b;
} else if (b <= 6.2e-45) {
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 <= -1.22e-104: tmp = c / -b elif b <= 6.2e-45: 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 <= -1.22e-104) tmp = Float64(c / Float64(-b)); elseif (b <= 6.2e-45) 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 <= -1.22e-104) tmp = c / -b; elseif (b <= 6.2e-45) 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, -1.22e-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.2e-45], 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 -1.22 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-45}:\\
\;\;\;\;\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 < -1.21999999999999997e-104Initial program 22.8%
div-sub22.5%
sub-neg22.5%
neg-mul-122.5%
*-commutative22.5%
associate-/l*20.4%
distribute-neg-frac20.4%
neg-mul-120.4%
*-commutative20.4%
associate-/l*22.4%
distribute-rgt-out22.8%
associate-/r*22.8%
metadata-eval22.8%
sub-neg22.8%
+-commutative22.8%
Simplified22.8%
Taylor expanded in b around -inf 79.1%
mul-1-neg79.1%
distribute-neg-frac279.1%
Simplified79.1%
if -1.21999999999999997e-104 < b < 6.2000000000000002e-45Initial program 74.4%
*-commutative74.4%
sqr-neg74.4%
*-commutative74.4%
sqr-neg74.4%
*-commutative74.4%
associate-*r*74.4%
*-commutative74.4%
Simplified74.4%
add-cube-cbrt73.8%
pow373.9%
*-commutative73.9%
associate-*l*73.9%
Applied egg-rr73.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt33.3%
rem-cube-cbrt33.5%
associate-/l*33.5%
Simplified33.5%
if 6.2000000000000002e-45 < b Initial program 67.9%
div-sub68.0%
sub-neg68.0%
neg-mul-168.0%
*-commutative68.0%
associate-/l*67.9%
distribute-neg-frac67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.9%
distribute-rgt-out67.9%
associate-/r*67.9%
metadata-eval67.9%
sub-neg67.9%
+-commutative67.9%
Simplified67.9%
Taylor expanded in c around 0 82.8%
+-commutative82.8%
mul-1-neg82.8%
unsub-neg82.8%
Simplified82.8%
Final simplification68.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.8%
div-sub31.5%
sub-neg31.5%
neg-mul-131.5%
*-commutative31.5%
associate-/l*29.8%
distribute-neg-frac29.8%
neg-mul-129.8%
*-commutative29.8%
associate-/l*31.4%
distribute-rgt-out31.7%
associate-/r*31.7%
metadata-eval31.7%
sub-neg31.7%
+-commutative31.7%
Simplified31.8%
Taylor expanded in b around -inf 64.9%
mul-1-neg64.9%
distribute-neg-frac264.9%
Simplified64.9%
if -4.999999999999985e-310 < b Initial program 71.7%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.7%
distribute-neg-frac71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.6%
Taylor expanded in c around 0 60.5%
+-commutative60.5%
mul-1-neg60.5%
unsub-neg60.5%
Simplified60.5%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.8%
div-sub31.5%
sub-neg31.5%
neg-mul-131.5%
*-commutative31.5%
associate-/l*29.8%
distribute-neg-frac29.8%
neg-mul-129.8%
*-commutative29.8%
associate-/l*31.4%
distribute-rgt-out31.7%
associate-/r*31.7%
metadata-eval31.7%
sub-neg31.7%
+-commutative31.7%
Simplified31.8%
Taylor expanded in b around -inf 64.9%
mul-1-neg64.9%
distribute-neg-frac264.9%
Simplified64.9%
if -4.999999999999985e-310 < b Initial program 71.7%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.7%
distribute-neg-frac71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.6%
Taylor expanded in a around 0 60.5%
associate-*r/60.5%
mul-1-neg60.5%
Simplified60.5%
Final simplification62.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 / 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 51.9%
div-sub51.7%
sub-neg51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*50.9%
distribute-neg-frac50.9%
neg-mul-150.9%
*-commutative50.9%
associate-/l*51.7%
distribute-rgt-out51.8%
associate-/r*51.8%
metadata-eval51.8%
sub-neg51.8%
+-commutative51.8%
Simplified51.8%
Taylor expanded in b around -inf 33.2%
mul-1-neg33.2%
distribute-neg-frac233.2%
Simplified33.2%
(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 51.9%
div-sub51.7%
sub-neg51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*50.9%
distribute-neg-frac50.9%
neg-mul-150.9%
*-commutative50.9%
associate-/l*51.7%
distribute-rgt-out51.8%
associate-/r*51.8%
metadata-eval51.8%
sub-neg51.8%
+-commutative51.8%
Simplified51.8%
Applied egg-rr33.5%
Taylor expanded in a around 0 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 51.9%
div-sub51.7%
sub-neg51.7%
neg-mul-151.7%
*-commutative51.7%
associate-/l*50.9%
distribute-neg-frac50.9%
neg-mul-150.9%
*-commutative50.9%
associate-/l*51.7%
distribute-rgt-out51.8%
associate-/r*51.8%
metadata-eval51.8%
sub-neg51.8%
+-commutative51.8%
Simplified51.8%
Applied egg-rr33.5%
Taylor expanded in b around -inf 2.7%
(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 2024169
(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)))