
(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 -6.6e-92)
(/ (- c) b)
(if (<= b 1.9e+71)
(/ (- (- 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 <= -6.6e-92) {
tmp = -c / b;
} else if (b <= 1.9e+71) {
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 <= (-6.6d-92)) then
tmp = -c / b
else if (b <= 1.9d+71) 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 <= -6.6e-92) {
tmp = -c / b;
} else if (b <= 1.9e+71) {
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 <= -6.6e-92: tmp = -c / b elif b <= 1.9e+71: 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 <= -6.6e-92) tmp = Float64(Float64(-c) / b); elseif (b <= 1.9e+71) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.6e-92) tmp = -c / b; elseif (b <= 1.9e+71) 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, -6.6e-92], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.9e+71], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * 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.6 \cdot 10^{-92}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{+71}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.59999999999999996e-92Initial program 13.0%
sub-neg13.0%
distribute-neg-out13.0%
neg-mul-113.0%
times-frac13.0%
metadata-eval13.0%
sub-neg13.0%
+-commutative13.0%
distribute-rgt-neg-in13.0%
distribute-rgt-neg-out13.0%
*-commutative13.0%
associate-*l*13.0%
fma-def13.0%
distribute-lft-neg-in13.0%
distribute-rgt-neg-in13.0%
metadata-eval13.0%
Simplified13.0%
Taylor expanded in b around -inf 88.4%
mul-1-neg88.4%
Simplified88.4%
if -6.59999999999999996e-92 < b < 1.9e71Initial program 78.4%
*-commutative78.4%
sqr-neg78.4%
*-commutative78.4%
sqr-neg78.4%
associate-*r*78.4%
*-commutative78.4%
Simplified78.4%
if 1.9e71 < b Initial program 54.7%
sub-neg54.7%
distribute-neg-out54.7%
neg-mul-154.7%
times-frac54.7%
metadata-eval54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
distribute-rgt-neg-out54.7%
*-commutative54.7%
associate-*l*54.7%
fma-def54.7%
distribute-lft-neg-in54.7%
distribute-rgt-neg-in54.7%
metadata-eval54.7%
Simplified54.7%
Taylor expanded in b around inf 95.4%
associate-*r/95.4%
mul-1-neg95.4%
Simplified95.4%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -8.3e-103)
(/ (- c) b)
(if (<= b 2e+71)
(/ (- (- 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 <= -8.3e-103) {
tmp = -c / b;
} else if (b <= 2e+71) {
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 <= (-8.3d-103)) then
tmp = -c / b
else if (b <= 2d+71) 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 <= -8.3e-103) {
tmp = -c / b;
} else if (b <= 2e+71) {
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 <= -8.3e-103: tmp = -c / b elif b <= 2e+71: 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 <= -8.3e-103) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+71) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.3e-103) tmp = -c / b; elseif (b <= 2e+71) 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, -8.3e-103], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+71], 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 -8.3 \cdot 10^{-103}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+71}:\\
\;\;\;\;\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 < -8.30000000000000006e-103Initial program 13.0%
sub-neg13.0%
distribute-neg-out13.0%
neg-mul-113.0%
times-frac13.0%
metadata-eval13.0%
sub-neg13.0%
+-commutative13.0%
distribute-rgt-neg-in13.0%
distribute-rgt-neg-out13.0%
*-commutative13.0%
associate-*l*13.0%
fma-def13.0%
distribute-lft-neg-in13.0%
distribute-rgt-neg-in13.0%
metadata-eval13.0%
Simplified13.0%
Taylor expanded in b around -inf 88.4%
mul-1-neg88.4%
Simplified88.4%
if -8.30000000000000006e-103 < b < 2.0000000000000001e71Initial program 78.4%
if 2.0000000000000001e71 < b Initial program 54.7%
sub-neg54.7%
distribute-neg-out54.7%
neg-mul-154.7%
times-frac54.7%
metadata-eval54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
distribute-rgt-neg-out54.7%
*-commutative54.7%
associate-*l*54.7%
fma-def54.7%
distribute-lft-neg-in54.7%
distribute-rgt-neg-in54.7%
metadata-eval54.7%
Simplified54.7%
Taylor expanded in b around inf 95.4%
associate-*r/95.4%
mul-1-neg95.4%
Simplified95.4%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -6.8e-102)
(/ (- c) b)
(if (<= b 1.9e-95)
(* (/ 0.5 a) (- b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-102) {
tmp = -c / b;
} else if (b <= 1.9e-95) {
tmp = (0.5 / a) * (b - sqrt((a * (c * -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 <= (-6.8d-102)) then
tmp = -c / b
else if (b <= 1.9d-95) then
tmp = (0.5d0 / a) * (b - sqrt((a * (c * (-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 <= -6.8e-102) {
tmp = -c / b;
} else if (b <= 1.9e-95) {
tmp = (0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.8e-102: tmp = -c / b elif b <= 1.9e-95: tmp = (0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.8e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 1.9e-95) tmp = Float64(Float64(0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -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 <= -6.8e-102) tmp = -c / b; elseif (b <= 1.9e-95) tmp = (0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.8e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.9e-95], N[(N[(0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -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 -6.8 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-95}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.80000000000000026e-102Initial program 13.0%
sub-neg13.0%
distribute-neg-out13.0%
neg-mul-113.0%
times-frac13.0%
metadata-eval13.0%
sub-neg13.0%
+-commutative13.0%
distribute-rgt-neg-in13.0%
distribute-rgt-neg-out13.0%
*-commutative13.0%
associate-*l*13.0%
fma-def13.0%
distribute-lft-neg-in13.0%
distribute-rgt-neg-in13.0%
metadata-eval13.0%
Simplified13.0%
Taylor expanded in b around -inf 88.4%
mul-1-neg88.4%
Simplified88.4%
if -6.80000000000000026e-102 < b < 1.8999999999999999e-95Initial program 75.8%
*-commutative75.8%
sqr-neg75.8%
*-commutative75.8%
sqr-neg75.8%
associate-*r*75.8%
*-commutative75.8%
Simplified75.8%
Taylor expanded in b around 0 69.4%
*-commutative69.4%
associate-*r*69.5%
Simplified69.5%
div-sub69.5%
sub-neg69.5%
div-inv69.5%
add-sqr-sqrt38.3%
sqrt-unprod67.2%
sqr-neg67.2%
sqrt-prod29.0%
add-sqr-sqrt67.2%
*-commutative67.2%
associate-/r*67.2%
metadata-eval67.2%
div-inv67.2%
*-commutative67.2%
associate-/r*67.2%
metadata-eval67.2%
Applied egg-rr67.2%
sub-neg67.2%
distribute-rgt-out--67.2%
Simplified67.2%
if 1.8999999999999999e-95 < b Initial program 64.1%
sub-neg64.1%
distribute-neg-out64.1%
neg-mul-164.1%
times-frac64.1%
metadata-eval64.1%
sub-neg64.1%
+-commutative64.1%
distribute-rgt-neg-in64.1%
distribute-rgt-neg-out64.1%
*-commutative64.1%
associate-*l*64.1%
fma-def64.1%
distribute-lft-neg-in64.1%
distribute-rgt-neg-in64.1%
metadata-eval64.1%
Simplified64.1%
Taylor expanded in b around inf 86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
Final simplification81.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e-102)
(/ (- c) b)
(if (<= b 2.1e-88)
(* (/ (+ b (sqrt (* a (* c -4.0)))) a) -0.5)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.65e-102) {
tmp = -c / b;
} else if (b <= 2.1e-88) {
tmp = ((b + sqrt((a * (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.65d-102)) then
tmp = -c / b
else if (b <= 2.1d-88) then
tmp = ((b + sqrt((a * (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.65e-102) {
tmp = -c / b;
} else if (b <= 2.1e-88) {
tmp = ((b + Math.sqrt((a * (c * -4.0)))) / a) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.65e-102: tmp = -c / b elif b <= 2.1e-88: tmp = ((b + math.sqrt((a * (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.65e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 2.1e-88) tmp = Float64(Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / a) * -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.65e-102) tmp = -c / b; elseif (b <= 2.1e-88) tmp = ((b + sqrt((a * (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.65e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.1e-88], N[(N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $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.65 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.1 \cdot 10^{-88}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.65e-102Initial program 13.0%
sub-neg13.0%
distribute-neg-out13.0%
neg-mul-113.0%
times-frac13.0%
metadata-eval13.0%
sub-neg13.0%
+-commutative13.0%
distribute-rgt-neg-in13.0%
distribute-rgt-neg-out13.0%
*-commutative13.0%
associate-*l*13.0%
fma-def13.0%
distribute-lft-neg-in13.0%
distribute-rgt-neg-in13.0%
metadata-eval13.0%
Simplified13.0%
Taylor expanded in b around -inf 88.4%
mul-1-neg88.4%
Simplified88.4%
if -1.65e-102 < b < 2.1e-88Initial program 76.4%
*-commutative76.4%
sqr-neg76.4%
*-commutative76.4%
sqr-neg76.4%
associate-*r*76.5%
*-commutative76.5%
Simplified76.5%
Taylor expanded in b around 0 69.1%
*-commutative69.1%
associate-*r*69.2%
Simplified69.2%
frac-2neg69.2%
div-inv69.2%
neg-sub069.2%
add-sqr-sqrt37.3%
sqrt-unprod66.8%
sqr-neg66.8%
sqrt-prod29.6%
add-sqr-sqrt66.8%
associate-+l-66.8%
neg-sub066.8%
add-sqr-sqrt37.2%
sqrt-unprod68.7%
sqr-neg68.7%
sqrt-prod31.9%
add-sqr-sqrt69.2%
distribute-rgt-neg-in69.2%
metadata-eval69.2%
Applied egg-rr69.2%
associate-*r/69.2%
times-frac69.2%
metadata-eval69.2%
Simplified69.2%
if 2.1e-88 < b Initial program 63.3%
sub-neg63.3%
distribute-neg-out63.3%
neg-mul-163.3%
times-frac63.3%
metadata-eval63.3%
sub-neg63.3%
+-commutative63.3%
distribute-rgt-neg-in63.3%
distribute-rgt-neg-out63.3%
*-commutative63.3%
associate-*l*63.3%
fma-def63.3%
distribute-lft-neg-in63.3%
distribute-rgt-neg-in63.3%
metadata-eval63.3%
Simplified63.3%
Taylor expanded in b around inf 86.9%
+-commutative86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
Final simplification82.2%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) 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 <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 30.2%
sub-neg30.2%
distribute-neg-out30.2%
neg-mul-130.2%
times-frac30.2%
metadata-eval30.2%
sub-neg30.2%
+-commutative30.2%
distribute-rgt-neg-in30.2%
distribute-rgt-neg-out30.2%
*-commutative30.2%
associate-*l*30.3%
fma-def30.3%
distribute-lft-neg-in30.3%
distribute-rgt-neg-in30.3%
metadata-eval30.3%
Simplified30.3%
Taylor expanded in b around -inf 67.0%
mul-1-neg67.0%
Simplified67.0%
if -3.999999999999988e-310 < b Initial program 69.0%
sub-neg69.0%
distribute-neg-out69.0%
neg-mul-169.0%
times-frac69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
distribute-rgt-neg-in69.0%
distribute-rgt-neg-out69.0%
*-commutative69.0%
associate-*l*69.0%
fma-def69.0%
distribute-lft-neg-in69.0%
distribute-rgt-neg-in69.0%
metadata-eval69.0%
Simplified69.0%
Taylor expanded in b around inf 69.3%
+-commutative69.3%
mul-1-neg69.3%
unsub-neg69.3%
Simplified69.3%
Final simplification68.1%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) 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 <= -4e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 30.2%
sub-neg30.2%
distribute-neg-out30.2%
neg-mul-130.2%
times-frac30.2%
metadata-eval30.2%
sub-neg30.2%
+-commutative30.2%
distribute-rgt-neg-in30.2%
distribute-rgt-neg-out30.2%
*-commutative30.2%
associate-*l*30.3%
fma-def30.3%
distribute-lft-neg-in30.3%
distribute-rgt-neg-in30.3%
metadata-eval30.3%
Simplified30.3%
Taylor expanded in b around -inf 67.0%
mul-1-neg67.0%
Simplified67.0%
if -3.999999999999988e-310 < b Initial program 69.0%
sub-neg69.0%
distribute-neg-out69.0%
neg-mul-169.0%
times-frac69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
distribute-rgt-neg-in69.0%
distribute-rgt-neg-out69.0%
*-commutative69.0%
associate-*l*69.0%
fma-def69.0%
distribute-lft-neg-in69.0%
distribute-rgt-neg-in69.0%
metadata-eval69.0%
Simplified69.0%
Taylor expanded in b around inf 69.2%
associate-*r/69.2%
mul-1-neg69.2%
Simplified69.2%
Final simplification68.0%
(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(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 48.7%
sub-neg48.7%
distribute-neg-out48.7%
neg-mul-148.7%
times-frac48.7%
metadata-eval48.7%
sub-neg48.7%
+-commutative48.7%
distribute-rgt-neg-in48.7%
distribute-rgt-neg-out48.7%
*-commutative48.7%
associate-*l*48.7%
fma-def48.7%
distribute-lft-neg-in48.7%
distribute-rgt-neg-in48.7%
metadata-eval48.7%
Simplified48.7%
Taylor expanded in b around -inf 36.1%
mul-1-neg36.1%
Simplified36.1%
Final simplification36.1%
(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 48.7%
sub-neg48.7%
distribute-neg-out48.7%
neg-mul-148.7%
times-frac48.7%
metadata-eval48.7%
sub-neg48.7%
+-commutative48.7%
distribute-rgt-neg-in48.7%
distribute-rgt-neg-out48.7%
*-commutative48.7%
associate-*l*48.7%
fma-def48.7%
distribute-lft-neg-in48.7%
distribute-rgt-neg-in48.7%
metadata-eval48.7%
Simplified48.7%
clear-num48.7%
un-div-inv48.7%
pow248.7%
Applied egg-rr48.7%
clear-num48.7%
associate-/r/48.6%
frac-2neg48.6%
metadata-eval48.6%
distribute-neg-in48.6%
add-sqr-sqrt15.4%
sqrt-unprod26.6%
sqr-neg26.6%
sqrt-prod19.2%
add-sqr-sqrt32.0%
sub-neg32.0%
fma-udef32.0%
add-sqr-sqrt30.5%
unpow230.5%
hypot-def24.3%
Applied egg-rr24.3%
Taylor expanded in b around -inf 2.4%
Final simplification2.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 48.7%
sub-neg48.7%
distribute-neg-out48.7%
neg-mul-148.7%
times-frac48.7%
metadata-eval48.7%
sub-neg48.7%
+-commutative48.7%
distribute-rgt-neg-in48.7%
distribute-rgt-neg-out48.7%
*-commutative48.7%
associate-*l*48.7%
fma-def48.7%
distribute-lft-neg-in48.7%
distribute-rgt-neg-in48.7%
metadata-eval48.7%
Simplified48.7%
clear-num48.7%
un-div-inv48.7%
pow248.7%
Applied egg-rr48.7%
Taylor expanded in b around inf 33.3%
Taylor expanded in a around inf 12.5%
Final simplification12.5%
(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 2023334
(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)))