
(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 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(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 -2e+148)
(/ (- b) a)
(if (<= b 3.9e-118)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+148) {
tmp = -b / a;
} else if (b <= 3.9e-118) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} 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 <= (-2d+148)) then
tmp = -b / a
else if (b <= 3.9d-118) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e+148) {
tmp = -b / a;
} else if (b <= 3.9e-118) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+148: tmp = -b / a elif b <= 3.9e-118: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+148) tmp = Float64(Float64(-b) / a); elseif (b <= 3.9e-118) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e+148) tmp = -b / a; elseif (b <= 3.9e-118) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+148], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.9e-118], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+148}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.9 \cdot 10^{-118}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.0000000000000001e148Initial program 42.2%
neg-sub042.2%
associate-+l-42.2%
sub0-neg42.2%
neg-mul-142.2%
associate-*l/42.2%
*-commutative42.2%
associate-/r*42.2%
/-rgt-identity42.2%
metadata-eval42.2%
Simplified42.2%
Taylor expanded in b around -inf 97.8%
associate-*r/97.8%
mul-1-neg97.8%
Simplified97.8%
if -2.0000000000000001e148 < b < 3.90000000000000001e-118Initial program 82.9%
if 3.90000000000000001e-118 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
associate-*l/17.8%
*-commutative17.8%
associate-/r*17.8%
/-rgt-identity17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.7e-59)
(- (/ c b) (/ b a))
(if (<= b 1.5e-117)
(* (+ b (sqrt (* a (* c -4.0)))) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.7e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (b + sqrt((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.7d-59)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-117) then
tmp = (b + sqrt((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.7e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.7e-59: tmp = (c / b) - (b / a) elif b <= 1.5e-117: tmp = (b + math.sqrt((a * (c * -4.0)))) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.7e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-117) tmp = Float64(Float64(b + sqrt(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.7e-59) tmp = (c / b) - (b / a); elseif (b <= 1.5e-117) tmp = (b + sqrt((a * (c * -4.0)))) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.7e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-117], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $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.7 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;\left(b + \sqrt{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.70000000000000009e-59Initial program 73.1%
neg-sub073.1%
associate-+l-73.1%
sub0-neg73.1%
neg-mul-173.1%
associate-*l/72.9%
*-commutative72.9%
associate-/r*72.9%
/-rgt-identity72.9%
metadata-eval72.9%
Simplified72.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -1.70000000000000009e-59 < b < 1.49999999999999996e-117Initial program 70.7%
Taylor expanded in b around 0 66.4%
*-commutative66.4%
*-commutative66.4%
associate-*r*66.4%
Simplified66.4%
expm1-log1p-u43.6%
expm1-udef15.9%
*-un-lft-identity15.9%
times-frac15.9%
metadata-eval15.9%
+-commutative15.9%
add-sqr-sqrt4.1%
sqrt-unprod15.7%
sqr-neg15.7%
sqrt-unprod11.8%
add-sqr-sqrt15.3%
Applied egg-rr15.3%
expm1-def41.7%
expm1-log1p64.3%
*-commutative64.3%
metadata-eval64.3%
times-frac64.3%
associate-*r/64.2%
+-commutative64.2%
*-commutative64.2%
associate-/r*64.2%
metadata-eval64.2%
Simplified64.2%
if 1.49999999999999996e-117 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
associate-*l/17.8%
*-commutative17.8%
associate-/r*17.8%
/-rgt-identity17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-59)
(- (/ c b) (/ b a))
(if (<= b 1.5e-117)
(/ (+ b (sqrt (* a (* c -4.0)))) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (b + sqrt((a * (c * -4.0)))) / (a * 2.0);
} 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.2d-59)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-117) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) / (a * 2.0d0)
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.2e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-59: tmp = (c / b) - (b / a) elif b <= 1.5e-117: tmp = (b + math.sqrt((a * (c * -4.0)))) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-117) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-59) tmp = (c / b) - (b / a); elseif (b <= 1.5e-117) tmp = (b + sqrt((a * (c * -4.0)))) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-117], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.20000000000000001e-59Initial program 73.1%
neg-sub073.1%
associate-+l-73.1%
sub0-neg73.1%
neg-mul-173.1%
associate-*l/72.9%
*-commutative72.9%
associate-/r*72.9%
/-rgt-identity72.9%
metadata-eval72.9%
Simplified72.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -7.20000000000000001e-59 < b < 1.49999999999999996e-117Initial program 70.7%
Taylor expanded in b around 0 66.4%
*-commutative66.4%
*-commutative66.4%
associate-*r*66.4%
Simplified66.4%
expm1-log1p-u64.8%
expm1-udef31.9%
+-commutative31.9%
add-sqr-sqrt16.6%
sqrt-unprod31.9%
sqr-neg31.9%
sqrt-unprod15.4%
add-sqr-sqrt31.9%
Applied egg-rr31.9%
expm1-def62.7%
expm1-log1p64.3%
+-commutative64.3%
Simplified64.3%
if 1.49999999999999996e-117 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
associate-*l/17.8%
*-commutative17.8%
associate-/r*17.8%
/-rgt-identity17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.35e-58)
(- (/ c b) (/ b a))
(if (<= b 1.5e-117)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} 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.35d-58)) then
tmp = (c / b) - (b / a)
else if (b <= 1.5d-117) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
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.35e-58) {
tmp = (c / b) - (b / a);
} else if (b <= 1.5e-117) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-58: tmp = (c / b) - (b / a) elif b <= 1.5e-117: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-58) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.5e-117) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e-58) tmp = (c / b) - (b / a); elseif (b <= 1.5e-117) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-58], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-117], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-58}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.3499999999999999e-58Initial program 73.1%
neg-sub073.1%
associate-+l-73.1%
sub0-neg73.1%
neg-mul-173.1%
associate-*l/72.9%
*-commutative72.9%
associate-/r*72.9%
/-rgt-identity72.9%
metadata-eval72.9%
Simplified72.9%
Taylor expanded in b around -inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
if -1.3499999999999999e-58 < b < 1.49999999999999996e-117Initial program 70.7%
Taylor expanded in b around 0 66.4%
*-commutative66.4%
*-commutative66.4%
associate-*r*66.4%
Simplified66.4%
if 1.49999999999999996e-117 < b Initial program 17.8%
neg-sub017.8%
associate-+l-17.8%
sub0-neg17.8%
neg-mul-117.8%
associate-*l/17.8%
*-commutative17.8%
associate-/r*17.8%
/-rgt-identity17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
distribute-neg-frac86.6%
Simplified86.6%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = (c / b) - (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 <= (-1d-310)) then
tmp = (c / b) - (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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(c / b) - 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 <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 70.7%
neg-sub070.7%
associate-+l-70.7%
sub0-neg70.7%
neg-mul-170.7%
associate-*l/70.5%
*-commutative70.5%
associate-/r*70.5%
/-rgt-identity70.5%
metadata-eval70.5%
Simplified70.5%
Taylor expanded in b around -inf 70.1%
mul-1-neg70.1%
unsub-neg70.1%
Simplified70.1%
if -9.999999999999969e-311 < b Initial program 31.5%
neg-sub031.5%
associate-+l-31.5%
sub0-neg31.5%
neg-mul-131.5%
associate-*l/31.4%
*-commutative31.4%
associate-/r*31.4%
/-rgt-identity31.4%
metadata-eval31.4%
Simplified31.4%
Taylor expanded in b around inf 69.0%
mul-1-neg69.0%
distribute-neg-frac69.0%
Simplified69.0%
Final simplification69.6%
(FPCore (a b c) :precision binary64 (if (<= b 7.4e+47) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.4e+47) {
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.4d+47) 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.4e+47) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.4e+47: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.4e+47) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.4e+47) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.4e+47], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.4 \cdot 10^{+47}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.40000000000000081e47Initial program 65.8%
neg-sub065.8%
associate-+l-65.8%
sub0-neg65.8%
neg-mul-165.8%
associate-*l/65.6%
*-commutative65.6%
associate-/r*65.6%
/-rgt-identity65.6%
metadata-eval65.6%
Simplified65.6%
Taylor expanded in b around -inf 49.6%
associate-*r/49.6%
mul-1-neg49.6%
Simplified49.6%
if 7.40000000000000081e47 < b Initial program 12.2%
neg-sub012.2%
associate-+l-12.2%
sub0-neg12.2%
neg-mul-112.2%
associate-*l/12.2%
*-commutative12.2%
associate-/r*12.2%
/-rgt-identity12.2%
metadata-eval12.2%
Simplified12.2%
Taylor expanded in b around -inf 2.6%
mul-1-neg2.6%
unsub-neg2.6%
Simplified2.6%
Taylor expanded in c around inf 33.5%
Final simplification45.3%
(FPCore (a b c) :precision binary64 (if (<= b 1.1e-301) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1e-301) {
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 <= 1.1d-301) 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 <= 1.1e-301) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.1e-301: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.1e-301) 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 <= 1.1e-301) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.1e-301], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.1e-301Initial program 70.9%
neg-sub070.9%
associate-+l-70.9%
sub0-neg70.9%
neg-mul-170.9%
associate-*l/70.8%
*-commutative70.8%
associate-/r*70.8%
/-rgt-identity70.8%
metadata-eval70.8%
Simplified70.8%
Taylor expanded in b around -inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
if 1.1e-301 < b Initial program 30.9%
neg-sub030.9%
associate-+l-30.9%
sub0-neg30.9%
neg-mul-130.9%
associate-*l/30.9%
*-commutative30.9%
associate-/r*30.9%
/-rgt-identity30.9%
metadata-eval30.9%
Simplified30.9%
Taylor expanded in b around inf 69.5%
mul-1-neg69.5%
distribute-neg-frac69.5%
Simplified69.5%
Final simplification69.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(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.5%
neg-sub051.5%
associate-+l-51.5%
sub0-neg51.5%
neg-mul-151.5%
associate-*l/51.4%
*-commutative51.4%
associate-/r*51.4%
/-rgt-identity51.4%
metadata-eval51.4%
Simplified51.4%
associate-*r/51.5%
clear-num51.5%
Applied egg-rr51.5%
Taylor expanded in b around -inf 37.0%
mul-1-neg37.0%
distribute-neg-frac37.0%
Simplified37.0%
add-sqr-sqrt20.0%
sqrt-unprod15.1%
frac-times14.9%
distribute-frac-neg14.9%
distribute-frac-neg14.9%
sqr-neg14.9%
frac-times15.1%
clear-num15.1%
clear-num15.2%
sqrt-unprod1.4%
add-sqr-sqrt2.5%
expm1-log1p-u2.1%
expm1-udef3.2%
Applied egg-rr3.2%
expm1-def2.1%
expm1-log1p2.5%
Simplified2.5%
Final simplification2.5%
(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.5%
neg-sub051.5%
associate-+l-51.5%
sub0-neg51.5%
neg-mul-151.5%
associate-*l/51.4%
*-commutative51.4%
associate-/r*51.4%
/-rgt-identity51.4%
metadata-eval51.4%
Simplified51.4%
Taylor expanded in b around -inf 37.0%
mul-1-neg37.0%
unsub-neg37.0%
Simplified37.0%
Taylor expanded in c around inf 11.1%
Final simplification11.1%
herbie shell --seed 2023181
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))