
(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 8 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.35e+112)
(/ (- b) a)
(if (<= b 3.7e-100)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+112) {
tmp = -b / a;
} else if (b <= 3.7e-100) {
tmp = (sqrt(((b * b) - (4.0 * (a * 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 <= (-1.35d+112)) then
tmp = -b / a
else if (b <= 3.7d-100) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * 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 <= -1.35e+112) {
tmp = -b / a;
} else if (b <= 3.7e-100) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e+112: tmp = -b / a elif b <= 3.7e-100: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e+112) tmp = Float64(Float64(-b) / a); elseif (b <= 3.7e-100) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * 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 <= -1.35e+112) tmp = -b / a; elseif (b <= 3.7e-100) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e+112], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.7e-100], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $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^{+112}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{-100}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.3500000000000001e112Initial program 62.7%
neg-sub062.7%
associate-+l-62.7%
sub0-neg62.7%
neg-mul-162.7%
*-commutative62.7%
associate-*r/62.7%
Simplified62.7%
Taylor expanded in b around -inf 98.4%
associate-*r/98.4%
mul-1-neg98.4%
Simplified98.4%
if -1.3500000000000001e112 < b < 3.70000000000000018e-100Initial program 81.6%
if 3.70000000000000018e-100 < b Initial program 9.5%
neg-sub09.5%
associate-+l-9.5%
sub0-neg9.5%
neg-mul-19.5%
*-commutative9.5%
associate-*r/9.5%
Simplified9.6%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification87.7%
(FPCore (a b c)
:precision binary64
(if (<= b -64000.0)
(- (/ c b) (/ b a))
(if (<= b 8.5e-100)
(* (+ b (sqrt (* c (* a -4.0)))) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 8.5e-100) {
tmp = (b + sqrt((c * (a * -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 <= (-64000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 8.5d-100) then
tmp = (b + sqrt((c * (a * (-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 <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 8.5e-100) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -64000.0: tmp = (c / b) - (b / a) elif b <= 8.5e-100: tmp = (b + math.sqrt((c * (a * -4.0)))) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -64000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8.5e-100) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -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 <= -64000.0) tmp = (c / b) - (b / a); elseif (b <= 8.5e-100) tmp = (b + sqrt((c * (a * -4.0)))) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -64000.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.5e-100], N[(N[(b + N[Sqrt[N[(c * N[(a * -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 -64000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-100}:\\
\;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -64000Initial program 71.0%
neg-sub071.0%
associate-+l-71.0%
sub0-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-*r/71.0%
Simplified71.0%
Taylor expanded in b around -inf 93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
if -64000 < b < 8.50000000000000017e-100Initial program 78.3%
Taylor expanded in b around 0 67.8%
*-commutative67.8%
*-commutative67.8%
associate-*r*67.8%
Simplified67.8%
expm1-log1p-u50.9%
expm1-udef17.2%
add-sqr-sqrt11.1%
sqrt-unprod17.1%
sqr-neg17.1%
sqrt-prod6.2%
add-sqr-sqrt15.9%
*-commutative15.9%
Applied egg-rr15.9%
expm1-def48.8%
expm1-log1p64.9%
*-rgt-identity64.9%
associate-*r/64.8%
associate-*r*64.7%
*-commutative64.7%
rem-square-sqrt0.0%
unpow20.0%
associate-*l*0.0%
unpow20.0%
rem-square-sqrt64.8%
*-commutative64.8%
associate-/r*64.8%
metadata-eval64.8%
Simplified64.8%
if 8.50000000000000017e-100 < b Initial program 9.5%
neg-sub09.5%
associate-+l-9.5%
sub0-neg9.5%
neg-mul-19.5%
*-commutative9.5%
associate-*r/9.5%
Simplified9.6%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification81.7%
(FPCore (a b c)
:precision binary64
(if (<= b -64000.0)
(- (/ c b) (/ b a))
(if (<= b 9.5e-100)
(/ (+ b (sqrt (* (* a c) -4.0))) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-100) {
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 <= (-64000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 9.5d-100) 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 <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-100) {
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 <= -64000.0: tmp = (c / b) - (b / a) elif b <= 9.5e-100: 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 <= -64000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9.5e-100) tmp = Float64(Float64(b + sqrt(Float64(Float64(a * 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 <= -64000.0) tmp = (c / b) - (b / a); elseif (b <= 9.5e-100) 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, -64000.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.5e-100], N[(N[(b + N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -64000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-100}:\\
\;\;\;\;\frac{b + \sqrt{\left(a \cdot c\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -64000Initial program 71.0%
neg-sub071.0%
associate-+l-71.0%
sub0-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-*r/71.0%
Simplified71.0%
Taylor expanded in b around -inf 93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
if -64000 < b < 9.4999999999999992e-100Initial program 78.3%
Taylor expanded in b around 0 67.8%
*-commutative67.8%
*-commutative67.8%
associate-*r*67.8%
Simplified67.8%
expm1-log1p-u50.9%
expm1-udef17.2%
add-sqr-sqrt11.1%
sqrt-unprod17.1%
sqr-neg17.1%
sqrt-prod6.2%
add-sqr-sqrt15.9%
*-commutative15.9%
Applied egg-rr15.9%
expm1-def48.8%
expm1-log1p64.9%
associate-*r*64.9%
*-commutative64.9%
Simplified64.9%
if 9.4999999999999992e-100 < b Initial program 9.5%
neg-sub09.5%
associate-+l-9.5%
sub0-neg9.5%
neg-mul-19.5%
*-commutative9.5%
associate-*r/9.5%
Simplified9.6%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification81.7%
(FPCore (a b c)
:precision binary64
(if (<= b -64000.0)
(- (/ c b) (/ b a))
(if (<= b 1.2e-99)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 1.2e-99) {
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 <= (-64000.0d0)) then
tmp = (c / b) - (b / a)
else if (b <= 1.2d-99) 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 <= -64000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 1.2e-99) {
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 <= -64000.0: tmp = (c / b) - (b / a) elif b <= 1.2e-99: 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 <= -64000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.2e-99) 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 <= -64000.0) tmp = (c / b) - (b / a); elseif (b <= 1.2e-99) 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, -64000.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.2e-99], 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 -64000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-99}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -64000Initial program 71.0%
neg-sub071.0%
associate-+l-71.0%
sub0-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-*r/71.0%
Simplified71.0%
Taylor expanded in b around -inf 93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
if -64000 < b < 1.2e-99Initial program 78.3%
Taylor expanded in b around 0 67.8%
*-commutative67.8%
*-commutative67.8%
associate-*r*67.8%
Simplified67.8%
if 1.2e-99 < b Initial program 9.5%
neg-sub09.5%
associate-+l-9.5%
sub0-neg9.5%
neg-mul-19.5%
*-commutative9.5%
associate-*r/9.5%
Simplified9.6%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification82.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.4%
neg-sub077.4%
associate-+l-77.4%
sub0-neg77.4%
neg-mul-177.4%
*-commutative77.4%
associate-*r/77.3%
Simplified77.3%
Taylor expanded in b around -inf 64.8%
mul-1-neg64.8%
unsub-neg64.8%
Simplified64.8%
if -4.999999999999985e-310 < b Initial program 22.4%
neg-sub022.4%
associate-+l-22.4%
sub0-neg22.4%
neg-mul-122.4%
*-commutative22.4%
associate-*r/22.3%
Simplified22.4%
Taylor expanded in b around inf 71.1%
associate-*r/71.1%
neg-mul-171.1%
Simplified71.1%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (<= b 1.08e-14) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.08e-14) {
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.08d-14) 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.08e-14) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.08e-14: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.08e-14) 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 <= 1.08e-14) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.08e-14], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.08 \cdot 10^{-14}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.08000000000000004e-14Initial program 68.9%
neg-sub068.9%
associate-+l-68.9%
sub0-neg68.9%
neg-mul-168.9%
*-commutative68.9%
associate-*r/68.8%
Simplified68.8%
Taylor expanded in b around -inf 49.9%
associate-*r/49.9%
mul-1-neg49.9%
Simplified49.9%
if 1.08000000000000004e-14 < b Initial program 9.5%
neg-sub09.5%
associate-+l-9.5%
sub0-neg9.5%
neg-mul-19.5%
*-commutative9.5%
associate-*r/9.5%
Simplified9.6%
Taylor expanded in b around -inf 2.1%
mul-1-neg2.1%
unsub-neg2.1%
*-commutative2.1%
*-commutative2.1%
associate-/l*2.6%
Simplified2.6%
Taylor expanded in b around 0 31.7%
Final simplification45.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.4%
neg-sub077.4%
associate-+l-77.4%
sub0-neg77.4%
neg-mul-177.4%
*-commutative77.4%
associate-*r/77.3%
Simplified77.3%
Taylor expanded in b around -inf 64.7%
associate-*r/64.7%
mul-1-neg64.7%
Simplified64.7%
if -4.999999999999985e-310 < b Initial program 22.4%
neg-sub022.4%
associate-+l-22.4%
sub0-neg22.4%
neg-mul-122.4%
*-commutative22.4%
associate-*r/22.3%
Simplified22.4%
Taylor expanded in b around inf 71.1%
associate-*r/71.1%
neg-mul-171.1%
Simplified71.1%
Final simplification67.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 52.9%
neg-sub052.9%
associate-+l-52.9%
sub0-neg52.9%
neg-mul-152.9%
*-commutative52.9%
associate-*r/52.8%
Simplified52.8%
Taylor expanded in b around -inf 36.0%
mul-1-neg36.0%
unsub-neg36.0%
*-commutative36.0%
*-commutative36.0%
associate-/l*36.9%
Simplified36.9%
Taylor expanded in b around 0 11.0%
Final simplification11.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $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{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023178
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))