
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1e+153)
(/ (- b) a)
(if (<= b 2e-54)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 2e-54) {
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d+153)) then
tmp = -b / a
else if (b <= 2d-54) then
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0d0))))) * (-0.5d0)) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 2e-54) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+153: tmp = -b / a elif b <= 2e-54: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(-b) / a); elseif (b <= 2e-54) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+153) tmp = -b / a; elseif (b <= 2e-54) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2e-54], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-54}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 38.9%
neg-sub038.9%
associate-+l-38.9%
sub0-neg38.9%
neg-mul-138.9%
associate-*l/38.9%
*-commutative38.9%
associate-/r*38.9%
/-rgt-identity38.9%
metadata-eval38.9%
Simplified38.9%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1e153 < b < 2.0000000000000001e-54Initial program 84.4%
neg-sub084.4%
associate-+l-84.4%
sub0-neg84.4%
neg-mul-184.4%
associate-*l/84.3%
*-commutative84.3%
associate-/r*84.3%
/-rgt-identity84.3%
metadata-eval84.3%
Simplified84.3%
fma-udef84.3%
*-commutative84.3%
associate-*r*84.3%
metadata-eval84.3%
distribute-rgt-neg-in84.3%
*-commutative84.3%
distribute-lft-neg-in84.3%
+-commutative84.3%
sub-neg84.3%
*-commutative84.3%
associate-*l*84.3%
Applied egg-rr84.3%
*-commutative84.3%
Simplified84.3%
associate-*r/84.4%
Applied egg-rr84.4%
if 2.0000000000000001e-54 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
associate-*l/15.9%
*-commutative15.9%
associate-/r*15.9%
/-rgt-identity15.9%
metadata-eval15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
mul-1-neg93.2%
distribute-neg-frac93.2%
Simplified93.2%
Final simplification89.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- b) a)) (t_1 (* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))))
(if (<= b -1.32e-43)
t_0
(if (<= b -6.2e-106)
t_1
(if (<= b -1.32e-129) t_0 (if (<= b 3.9e-55) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = -b / a;
double t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
double tmp;
if (b <= -1.32e-43) {
tmp = t_0;
} else if (b <= -6.2e-106) {
tmp = t_1;
} else if (b <= -1.32e-129) {
tmp = t_0;
} else if (b <= 3.9e-55) {
tmp = t_1;
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = -b / a
t_1 = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
if (b <= (-1.32d-43)) then
tmp = t_0
else if (b <= (-6.2d-106)) then
tmp = t_1
else if (b <= (-1.32d-129)) then
tmp = t_0
else if (b <= 3.9d-55) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -b / a;
double t_1 = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
double tmp;
if (b <= -1.32e-43) {
tmp = t_0;
} else if (b <= -6.2e-106) {
tmp = t_1;
} else if (b <= -1.32e-129) {
tmp = t_0;
} else if (b <= 3.9e-55) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = -b / a t_1 = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) tmp = 0 if b <= -1.32e-43: tmp = t_0 elif b <= -6.2e-106: tmp = t_1 elif b <= -1.32e-129: tmp = t_0 elif b <= 3.9e-55: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(-b) / a) t_1 = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))) tmp = 0.0 if (b <= -1.32e-43) tmp = t_0; elseif (b <= -6.2e-106) tmp = t_1; elseif (b <= -1.32e-129) tmp = t_0; elseif (b <= 3.9e-55) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = -b / a; t_1 = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); tmp = 0.0; if (b <= -1.32e-43) tmp = t_0; elseif (b <= -6.2e-106) tmp = t_1; elseif (b <= -1.32e-129) tmp = t_0; elseif (b <= 3.9e-55) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) / a), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.32e-43], t$95$0, If[LessEqual[b, -6.2e-106], t$95$1, If[LessEqual[b, -1.32e-129], t$95$0, If[LessEqual[b, 3.9e-55], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-b}{a}\\
t_1 := \frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{if}\;b \leq -1.32 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -6.2 \cdot 10^{-106}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -1.32 \cdot 10^{-129}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 3.9 \cdot 10^{-55}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.32000000000000002e-43 or -6.19999999999999971e-106 < b < -1.31999999999999992e-129Initial program 66.3%
neg-sub066.3%
associate-+l-66.3%
sub0-neg66.3%
neg-mul-166.3%
associate-*l/66.1%
*-commutative66.1%
associate-/r*66.1%
/-rgt-identity66.1%
metadata-eval66.1%
Simplified66.1%
Taylor expanded in b around -inf 86.3%
associate-*r/86.3%
mul-1-neg86.3%
Simplified86.3%
if -1.32000000000000002e-43 < b < -6.19999999999999971e-106 or -1.31999999999999992e-129 < b < 3.9e-55Initial program 80.6%
neg-sub080.6%
associate-+l-80.6%
sub0-neg80.6%
neg-mul-180.6%
associate-*l/80.6%
*-commutative80.6%
associate-/r*80.6%
/-rgt-identity80.6%
metadata-eval80.6%
Simplified80.6%
Taylor expanded in a around inf 76.7%
*-commutative76.7%
*-commutative76.7%
associate-*r*76.7%
Simplified76.7%
if 3.9e-55 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
associate-*l/15.9%
*-commutative15.9%
associate-/r*15.9%
/-rgt-identity15.9%
metadata-eval15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
mul-1-neg93.2%
distribute-neg-frac93.2%
Simplified93.2%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e+126)
(/ (- b) a)
(if (<= b 1.95e-51)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e+126) {
tmp = -b / a;
} else if (b <= 1.95e-51) {
tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
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+126)) then
tmp = -b / a
else if (b <= 1.95d-51) then
tmp = (b - sqrt(((b * b) - (a * (c * 4.0d0))))) * ((-0.5d0) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e+126) {
tmp = -b / a;
} else if (b <= 1.95e-51) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.22e+126: tmp = -b / a elif b <= 1.95e-51: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.22e+126) tmp = Float64(Float64(-b) / a); elseif (b <= 1.95e-51) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.22e+126) tmp = -b / a; elseif (b <= 1.95e-51) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.22e+126], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.95e-51], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.22 \cdot 10^{+126}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-51}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.21999999999999995e126Initial program 48.1%
neg-sub048.1%
associate-+l-48.1%
sub0-neg48.1%
neg-mul-148.1%
associate-*l/48.1%
*-commutative48.1%
associate-/r*48.1%
/-rgt-identity48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.21999999999999995e126 < b < 1.9499999999999999e-51Initial program 83.4%
neg-sub083.4%
associate-+l-83.4%
sub0-neg83.4%
neg-mul-183.4%
associate-*l/83.3%
*-commutative83.3%
associate-/r*83.3%
/-rgt-identity83.3%
metadata-eval83.3%
Simplified83.3%
fma-udef83.3%
*-commutative83.3%
associate-*r*83.3%
metadata-eval83.3%
distribute-rgt-neg-in83.3%
*-commutative83.3%
distribute-lft-neg-in83.3%
+-commutative83.3%
sub-neg83.3%
*-commutative83.3%
associate-*l*83.3%
Applied egg-rr83.3%
*-commutative83.3%
Simplified83.3%
if 1.9499999999999999e-51 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
associate-*l/15.9%
*-commutative15.9%
associate-/r*15.9%
/-rgt-identity15.9%
metadata-eval15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
mul-1-neg93.2%
distribute-neg-frac93.2%
Simplified93.2%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.32e-129)
(/ (- b) a)
(if (<= b 7.4e-54)
(* -0.5 (/ (- (sqrt (* c (/ a -0.25)))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.32e-129) {
tmp = -b / a;
} else if (b <= 7.4e-54) {
tmp = -0.5 * (-sqrt((c * (a / -0.25))) / a);
} else {
tmp = -c / b;
}
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.32d-129)) then
tmp = -b / a
else if (b <= 7.4d-54) then
tmp = (-0.5d0) * (-sqrt((c * (a / (-0.25d0)))) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.32e-129) {
tmp = -b / a;
} else if (b <= 7.4e-54) {
tmp = -0.5 * (-Math.sqrt((c * (a / -0.25))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.32e-129: tmp = -b / a elif b <= 7.4e-54: tmp = -0.5 * (-math.sqrt((c * (a / -0.25))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.32e-129) tmp = Float64(Float64(-b) / a); elseif (b <= 7.4e-54) tmp = Float64(-0.5 * Float64(Float64(-sqrt(Float64(c * Float64(a / -0.25)))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.32e-129) tmp = -b / a; elseif (b <= 7.4e-54) tmp = -0.5 * (-sqrt((c * (a / -0.25))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.32e-129], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 7.4e-54], N[(-0.5 * N[((-N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.32 \cdot 10^{-129}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 7.4 \cdot 10^{-54}:\\
\;\;\;\;-0.5 \cdot \frac{-\sqrt{c \cdot \frac{a}{-0.25}}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.31999999999999992e-129Initial program 68.5%
neg-sub068.5%
associate-+l-68.5%
sub0-neg68.5%
neg-mul-168.5%
associate-*l/68.3%
*-commutative68.3%
associate-/r*68.3%
/-rgt-identity68.3%
metadata-eval68.3%
Simplified68.3%
Taylor expanded in b around -inf 79.3%
associate-*r/79.3%
mul-1-neg79.3%
Simplified79.3%
if -1.31999999999999992e-129 < b < 7.4000000000000006e-54Initial program 79.9%
neg-sub079.9%
associate-+l-79.9%
sub0-neg79.9%
neg-mul-179.9%
associate-*l/79.8%
*-commutative79.8%
associate-/r*79.8%
/-rgt-identity79.8%
metadata-eval79.8%
Simplified79.8%
fma-udef79.8%
*-commutative79.8%
associate-*r*79.8%
metadata-eval79.8%
distribute-rgt-neg-in79.8%
*-commutative79.8%
distribute-lft-neg-in79.8%
+-commutative79.8%
sub-neg79.8%
add-sqr-sqrt79.4%
pow279.4%
Applied egg-rr79.5%
Taylor expanded in c around -inf 44.6%
unpow244.6%
exp-prod43.5%
exp-prod42.7%
pow-sqr42.7%
mul-1-neg42.7%
unsub-neg42.7%
*-commutative42.7%
Simplified42.7%
Taylor expanded in b around 0 44.0%
metadata-eval44.0%
log-prod44.0%
+-commutative44.0%
log-prod44.0%
log-div73.3%
associate-*r*73.3%
exp-prod69.5%
associate-*r/69.5%
Simplified78.9%
if 7.4000000000000006e-54 < b Initial program 15.9%
neg-sub015.9%
associate-+l-15.9%
sub0-neg15.9%
neg-mul-115.9%
associate-*l/15.9%
*-commutative15.9%
associate-/r*15.9%
/-rgt-identity15.9%
metadata-eval15.9%
Simplified16.0%
Taylor expanded in b around inf 93.2%
mul-1-neg93.2%
distribute-neg-frac93.2%
Simplified93.2%
Final simplification83.5%
(FPCore (a b c) :precision binary64 (if (<= b 7.6e-300) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.6e-300) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= 7.6d-300) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 7.6e-300) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.6e-300: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.6e-300) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.6e-300) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.6e-300], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.6 \cdot 10^{-300}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 7.60000000000000026e-300Initial program 72.5%
neg-sub072.5%
associate-+l-72.5%
sub0-neg72.5%
neg-mul-172.5%
associate-*l/72.3%
*-commutative72.3%
associate-/r*72.3%
/-rgt-identity72.3%
metadata-eval72.3%
Simplified72.3%
Taylor expanded in b around -inf 65.0%
associate-*r/65.0%
mul-1-neg65.0%
Simplified65.0%
if 7.60000000000000026e-300 < b Initial program 36.1%
neg-sub036.1%
associate-+l-36.1%
sub0-neg36.1%
neg-mul-136.1%
associate-*l/36.1%
*-commutative36.1%
associate-/r*36.1%
/-rgt-identity36.1%
metadata-eval36.1%
Simplified36.1%
Taylor expanded in b around inf 68.0%
mul-1-neg68.0%
distribute-neg-frac68.0%
Simplified68.0%
Final simplification66.4%
(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(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.3%
neg-sub055.3%
associate-+l-55.3%
sub0-neg55.3%
neg-mul-155.3%
associate-*l/55.2%
*-commutative55.2%
associate-/r*55.2%
/-rgt-identity55.2%
metadata-eval55.2%
Simplified55.2%
Taylor expanded in b around -inf 35.6%
associate-*r/35.6%
mul-1-neg35.6%
Simplified35.6%
Final simplification35.6%
herbie shell --seed 2023230
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))