
(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 -1e+150)
(- (/ c b) (/ b a))
(if (<= b 5.5e-78)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+150) {
tmp = (c / b) - (b / a);
} else if (b <= 5.5e-78) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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 <= (-1d+150)) then
tmp = (c / b) - (b / a)
else if (b <= 5.5d-78) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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 <= -1e+150) {
tmp = (c / b) - (b / a);
} else if (b <= 5.5e-78) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+150: tmp = (c / b) - (b / a) elif b <= 5.5e-78: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+150) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.5e-78) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - 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 <= -1e+150) tmp = (c / b) - (b / a); elseif (b <= 5.5e-78) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+150], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e-78], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $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 \cdot 10^{+150}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.99999999999999981e149Initial program 34.1%
neg-sub034.1%
associate-+l-34.1%
sub0-neg34.1%
neg-mul-134.1%
*-commutative34.1%
associate-*r/34.1%
Simplified34.4%
Taylor expanded in b around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -9.99999999999999981e149 < b < 5.50000000000000017e-78Initial program 82.9%
if 5.50000000000000017e-78 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
*-commutative17.5%
associate-*r/17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
associate-*r/87.3%
neg-mul-187.3%
Simplified87.3%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(- (/ c b) (/ b a))
(if (<= b 1.45e-77)
(* (- (sqrt (* c (* a -4.0))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 1.45e-77) {
tmp = (sqrt((c * (a * -4.0))) - b) * (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.66d-195)) then
tmp = (c / b) - (b / a)
else if (b <= 1.45d-77) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) * (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.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 1.45e-77) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.66e-195: tmp = (c / b) - (b / a) elif b <= 1.45e-77: tmp = (math.sqrt((c * (a * -4.0))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.45e-77) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) * 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.66e-195) tmp = (c / b) - (b / a); elseif (b <= 1.45e-77) tmp = (sqrt((c * (a * -4.0))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.45e-77], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.45 \cdot 10^{-77}:\\
\;\;\;\;\left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 71.7%
neg-sub071.7%
associate-+l-71.7%
sub0-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-*r/71.5%
Simplified71.7%
Taylor expanded in b around -inf 85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -1.66e-195 < b < 1.4499999999999999e-77Initial program 71.0%
Taylor expanded in b around 0 69.3%
*-commutative69.3%
*-commutative69.3%
associate-*r*69.4%
Simplified69.4%
expm1-log1p-u44.1%
expm1-udef20.2%
+-commutative20.2%
*-commutative20.2%
Applied egg-rr20.2%
expm1-def44.1%
expm1-log1p69.4%
*-rgt-identity69.4%
associate-*r/69.4%
unsub-neg69.4%
associate-*r*69.3%
*-commutative69.3%
associate-*l*69.4%
*-commutative69.4%
associate-/r*69.4%
metadata-eval69.4%
Simplified69.4%
if 1.4499999999999999e-77 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
*-commutative17.5%
associate-*r/17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
associate-*r/87.3%
neg-mul-187.3%
Simplified87.3%
Final simplification82.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(- (/ c b) (/ b a))
(if (<= b 1.65e-77)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 1.65e-77) {
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.66d-195)) then
tmp = (c / b) - (b / a)
else if (b <= 1.65d-77) 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.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 1.65e-77) {
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.66e-195: tmp = (c / b) - (b / a) elif b <= 1.65e-77: 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.66e-195) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.65e-77) 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.66e-195) tmp = (c / b) - (b / a); elseif (b <= 1.65e-77) 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.66e-195], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.65e-77], 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.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-77}:\\
\;\;\;\;\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.66e-195Initial program 71.7%
neg-sub071.7%
associate-+l-71.7%
sub0-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-*r/71.5%
Simplified71.7%
Taylor expanded in b around -inf 85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -1.66e-195 < b < 1.64999999999999996e-77Initial program 71.0%
Taylor expanded in b around 0 69.3%
*-commutative69.3%
*-commutative69.3%
associate-*r*69.4%
Simplified69.4%
expm1-log1p-u44.1%
expm1-udef20.2%
+-commutative20.2%
*-commutative20.2%
Applied egg-rr20.2%
expm1-def44.1%
expm1-log1p69.4%
unsub-neg69.4%
Simplified69.4%
if 1.64999999999999996e-77 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
*-commutative17.5%
associate-*r/17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
associate-*r/87.3%
neg-mul-187.3%
Simplified87.3%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 72.1%
neg-sub072.1%
associate-+l-72.1%
sub0-neg72.1%
neg-mul-172.1%
*-commutative72.1%
associate-*r/72.0%
Simplified72.1%
Taylor expanded in b around -inf 71.0%
mul-1-neg71.0%
unsub-neg71.0%
Simplified71.0%
if -3.999999999999988e-310 < b Initial program 30.5%
neg-sub030.5%
associate-+l-30.5%
sub0-neg30.5%
neg-mul-130.5%
*-commutative30.5%
associate-*r/30.5%
Simplified30.5%
Taylor expanded in b around inf 71.6%
associate-*r/71.6%
neg-mul-171.6%
Simplified71.6%
Final simplification71.3%
(FPCore (a b c) :precision binary64 (if (<= b 7.2e-84) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e-84) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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-84) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e-84) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.2e-84: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.2e-84) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.2e-84) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.2e-84], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{-84}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 7.20000000000000007e-84Initial program 71.0%
neg-sub071.0%
associate-+l-71.0%
sub0-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-*r/70.9%
Simplified71.0%
Taylor expanded in b around -inf 60.9%
associate-*r/60.9%
mul-1-neg60.9%
Simplified60.9%
if 7.20000000000000007e-84 < b Initial program 20.5%
neg-sub020.5%
associate-+l-20.5%
sub0-neg20.5%
neg-mul-120.5%
*-commutative20.5%
associate-*r/20.5%
Simplified20.5%
*-commutative20.5%
sub-neg20.5%
distribute-lft-in17.5%
Applied egg-rr17.5%
Taylor expanded in a around 0 26.4%
distribute-rgt-out26.4%
metadata-eval26.4%
metadata-eval26.4%
associate-*l/18.3%
metadata-eval18.3%
mul0-rgt26.4%
Simplified26.4%
Final simplification49.6%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 72.1%
neg-sub072.1%
associate-+l-72.1%
sub0-neg72.1%
neg-mul-172.1%
*-commutative72.1%
associate-*r/72.0%
Simplified72.1%
Taylor expanded in b around -inf 70.6%
associate-*r/70.6%
mul-1-neg70.6%
Simplified70.6%
if -3.999999999999988e-310 < b Initial program 30.5%
neg-sub030.5%
associate-+l-30.5%
sub0-neg30.5%
neg-mul-130.5%
*-commutative30.5%
associate-*r/30.5%
Simplified30.5%
Taylor expanded in b around inf 71.6%
associate-*r/71.6%
neg-mul-171.6%
Simplified71.6%
Final simplification71.1%
(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 54.4%
neg-sub054.4%
associate-+l-54.4%
sub0-neg54.4%
neg-mul-154.4%
*-commutative54.4%
associate-*r/54.3%
Simplified54.4%
Taylor expanded in b around -inf 41.7%
mul-1-neg41.7%
unsub-neg41.7%
Simplified41.7%
Taylor expanded in c around inf 10.7%
Final simplification10.7%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 54.4%
neg-sub054.4%
associate-+l-54.4%
sub0-neg54.4%
neg-mul-154.4%
*-commutative54.4%
associate-*r/54.3%
Simplified54.4%
*-commutative54.4%
sub-neg54.4%
distribute-lft-in53.5%
Applied egg-rr53.5%
Taylor expanded in a around 0 10.6%
distribute-rgt-out10.6%
metadata-eval10.6%
metadata-eval10.6%
associate-*l/7.8%
metadata-eval7.8%
mul0-rgt10.6%
Simplified10.6%
Final simplification10.6%
(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 2023213
(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)))