
(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
(if (<= b -1.15e-77)
(/ c (- b))
(if (<= b 1.35e+100)
(/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) (* a -2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-77) {
tmp = c / -b;
} else if (b <= 1.35e+100) {
tmp = (b + sqrt(fma(a, (c * -4.0), (b * b)))) / (a * -2.0);
} else {
tmp = b / -a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-77) tmp = Float64(c / Float64(-b)); elseif (b <= 1.35e+100) tmp = Float64(Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / Float64(a * -2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-77], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.35e+100], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-77}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+100}:\\
\;\;\;\;\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.14999999999999999e-77Initial program 14.1%
div-sub13.6%
sub-neg13.6%
neg-mul-113.6%
*-commutative13.6%
associate-/l*12.5%
distribute-neg-frac12.5%
neg-mul-112.5%
*-commutative12.5%
associate-/l*13.6%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified14.1%
Taylor expanded in b around -inf 85.3%
mul-1-neg85.3%
distribute-neg-frac285.3%
Simplified85.3%
if -1.14999999999999999e-77 < b < 1.34999999999999999e100Initial program 77.6%
remove-double-neg77.6%
distribute-rgt-neg-out77.6%
neg-mul-177.6%
associate-/r*77.6%
Simplified77.6%
if 1.34999999999999999e100 < b Initial program 56.2%
div-sub56.2%
sub-neg56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.1%
distribute-neg-frac56.1%
neg-mul-156.1%
*-commutative56.1%
associate-/l*56.1%
distribute-rgt-out56.1%
associate-/r*56.1%
metadata-eval56.1%
sub-neg56.1%
+-commutative56.1%
Simplified56.2%
Taylor expanded in a around 0 98.3%
associate-*r/98.3%
mul-1-neg98.3%
Simplified98.3%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -6.8e-81)
(/ c (- b))
(if (<= b 4e+100)
(/ (- (- 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.8e-81) {
tmp = c / -b;
} else if (b <= 4e+100) {
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.8d-81)) then
tmp = c / -b
else if (b <= 4d+100) 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.8e-81) {
tmp = c / -b;
} else if (b <= 4e+100) {
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.8e-81: tmp = c / -b elif b <= 4e+100: 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.8e-81) tmp = Float64(c / Float64(-b)); elseif (b <= 4e+100) 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.8e-81) tmp = c / -b; elseif (b <= 4e+100) 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.8e-81], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4e+100], 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.8 \cdot 10^{-81}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+100}:\\
\;\;\;\;\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.7999999999999997e-81Initial program 14.1%
div-sub13.6%
sub-neg13.6%
neg-mul-113.6%
*-commutative13.6%
associate-/l*12.5%
distribute-neg-frac12.5%
neg-mul-112.5%
*-commutative12.5%
associate-/l*13.6%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified14.1%
Taylor expanded in b around -inf 85.3%
mul-1-neg85.3%
distribute-neg-frac285.3%
Simplified85.3%
if -6.7999999999999997e-81 < b < 4.00000000000000006e100Initial program 77.6%
if 4.00000000000000006e100 < b Initial program 56.2%
div-sub56.2%
sub-neg56.2%
neg-mul-156.2%
*-commutative56.2%
associate-/l*56.1%
distribute-neg-frac56.1%
neg-mul-156.1%
*-commutative56.1%
associate-/l*56.1%
distribute-rgt-out56.1%
associate-/r*56.1%
metadata-eval56.1%
sub-neg56.1%
+-commutative56.1%
Simplified56.2%
Taylor expanded in a around 0 98.3%
associate-*r/98.3%
mul-1-neg98.3%
Simplified98.3%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-150)
(/ c (- b))
(if (<= b 1.6e-101)
(/ (+ 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 <= -1.05e-150) {
tmp = c / -b;
} else if (b <= 1.6e-101) {
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 <= (-1.05d-150)) then
tmp = c / -b
else if (b <= 1.6d-101) 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 <= -1.05e-150) {
tmp = c / -b;
} else if (b <= 1.6e-101) {
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 <= -1.05e-150: tmp = c / -b elif b <= 1.6e-101: 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 <= -1.05e-150) tmp = Float64(c / Float64(-b)); elseif (b <= 1.6e-101) tmp = 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 <= -1.05e-150) tmp = c / -b; elseif (b <= 1.6e-101) 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, -1.05e-150], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.6e-101], 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 -1.05 \cdot 10^{-150}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-101}:\\
\;\;\;\;\frac{b + \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 < -1.0500000000000001e-150Initial program 18.5%
div-sub18.1%
sub-neg18.1%
neg-mul-118.1%
*-commutative18.1%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*18.1%
distribute-rgt-out18.5%
associate-/r*18.5%
metadata-eval18.5%
sub-neg18.5%
+-commutative18.5%
Simplified18.5%
Taylor expanded in b around -inf 80.9%
mul-1-neg80.9%
distribute-neg-frac280.9%
Simplified80.9%
if -1.0500000000000001e-150 < b < 1.59999999999999989e-101Initial program 69.8%
remove-double-neg69.8%
distribute-rgt-neg-out69.8%
neg-mul-169.8%
associate-/r*69.8%
Simplified69.8%
Taylor expanded in a around inf 65.8%
*-commutative65.8%
associate-*r*65.8%
Simplified65.8%
if 1.59999999999999989e-101 < b Initial program 73.9%
div-sub73.9%
sub-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-150)
(/ c (- b))
(if (<= b 8e-102)
(* (+ b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-150) {
tmp = c / -b;
} else if (b <= 8e-102) {
tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / 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 <= (-2.9d-150)) then
tmp = c / -b
else if (b <= 8d-102) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / 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 <= -2.9e-150) {
tmp = c / -b;
} else if (b <= 8e-102) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-150: tmp = c / -b elif b <= 8e-102: tmp = (b + math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-150) tmp = Float64(c / Float64(-b)); elseif (b <= 8e-102) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / 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 <= -2.9e-150) tmp = c / -b; elseif (b <= 8e-102) tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-150], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8e-102], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-150}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-102}:\\
\;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.8999999999999998e-150Initial program 18.5%
div-sub18.1%
sub-neg18.1%
neg-mul-118.1%
*-commutative18.1%
associate-/l*17.1%
distribute-neg-frac17.1%
neg-mul-117.1%
*-commutative17.1%
associate-/l*18.1%
distribute-rgt-out18.5%
associate-/r*18.5%
metadata-eval18.5%
sub-neg18.5%
+-commutative18.5%
Simplified18.5%
Taylor expanded in b around -inf 80.9%
mul-1-neg80.9%
distribute-neg-frac280.9%
Simplified80.9%
if -2.8999999999999998e-150 < b < 7.99999999999999946e-102Initial program 69.8%
div-sub69.8%
sub-neg69.8%
neg-mul-169.8%
*-commutative69.8%
associate-/l*69.8%
distribute-neg-frac69.8%
neg-mul-169.8%
*-commutative69.8%
associate-/l*69.8%
distribute-rgt-out69.7%
associate-/r*69.7%
metadata-eval69.7%
sub-neg69.7%
+-commutative69.7%
Simplified69.7%
Taylor expanded in a around inf 65.8%
*-commutative65.8%
associate-*r*65.8%
Simplified65.8%
if 7.99999999999999946e-102 < b Initial program 73.9%
div-sub73.9%
sub-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
Final simplification82.0%
(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 25.8%
div-sub25.4%
sub-neg25.4%
neg-mul-125.4%
*-commutative25.4%
associate-/l*24.6%
distribute-neg-frac24.6%
neg-mul-124.6%
*-commutative24.6%
associate-/l*25.4%
distribute-rgt-out25.7%
associate-/r*25.7%
metadata-eval25.7%
sub-neg25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
distribute-neg-frac270.0%
Simplified70.0%
if -1.999999999999994e-310 < b Initial program 74.0%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-neg-frac74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*73.9%
distribute-rgt-out73.9%
associate-/r*73.9%
metadata-eval73.9%
sub-neg73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in c around 0 73.8%
+-commutative73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
(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 25.8%
div-sub25.4%
sub-neg25.4%
neg-mul-125.4%
*-commutative25.4%
associate-/l*24.6%
distribute-neg-frac24.6%
neg-mul-124.6%
*-commutative24.6%
associate-/l*25.4%
distribute-rgt-out25.7%
associate-/r*25.7%
metadata-eval25.7%
sub-neg25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
distribute-neg-frac270.0%
Simplified70.0%
if -1.999999999999994e-310 < b Initial program 74.0%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-neg-frac74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*73.9%
distribute-rgt-out73.9%
associate-/r*73.9%
metadata-eval73.9%
sub-neg73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in a around 0 73.2%
associate-*r/73.2%
mul-1-neg73.2%
Simplified73.2%
Final simplification71.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 49.7%
div-sub49.5%
sub-neg49.5%
neg-mul-149.5%
*-commutative49.5%
associate-/l*49.1%
distribute-neg-frac49.1%
neg-mul-149.1%
*-commutative49.1%
associate-/l*49.4%
distribute-rgt-out49.6%
associate-/r*49.6%
metadata-eval49.6%
sub-neg49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in b around -inf 36.4%
mul-1-neg36.4%
distribute-neg-frac236.4%
Simplified36.4%
(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 49.7%
div-sub49.5%
sub-neg49.5%
neg-mul-149.5%
*-commutative49.5%
associate-/l*49.1%
distribute-neg-frac49.1%
neg-mul-149.1%
*-commutative49.1%
associate-/l*49.4%
distribute-rgt-out49.6%
associate-/r*49.6%
metadata-eval49.6%
sub-neg49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in a around 0 35.8%
+-commutative35.8%
mul-1-neg35.8%
sub-neg35.8%
associate-/l*37.8%
Simplified37.8%
Taylor expanded in a around inf 11.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 49.7%
div-sub49.5%
sub-neg49.5%
neg-mul-149.5%
*-commutative49.5%
associate-/l*49.1%
distribute-neg-frac49.1%
neg-mul-149.1%
*-commutative49.1%
associate-/l*49.4%
distribute-rgt-out49.6%
associate-/r*49.6%
metadata-eval49.6%
sub-neg49.6%
+-commutative49.6%
Simplified49.6%
metadata-eval49.6%
associate-/r*49.6%
*-commutative49.6%
associate-/r/49.6%
associate-/l*49.6%
pow249.6%
Applied egg-rr49.6%
Taylor expanded in b around -inf 35.3%
associate-*r*35.3%
neg-mul-135.3%
+-commutative35.3%
mul-1-neg35.3%
unsub-neg35.3%
Simplified35.3%
Taylor expanded in b around 0 2.4%
(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 2024185
(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)))