
(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 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(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 -5e+139)
(- (/ c b) (/ b a))
(if (<= b 8.5e-81)
(- (/ (sqrt (fma b b (* -4.0 (* c a)))) (* a 2.0)) (/ b (* a 2.0)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+139) {
tmp = (c / b) - (b / a);
} else if (b <= 8.5e-81) {
tmp = (sqrt(fma(b, b, (-4.0 * (c * a)))) / (a * 2.0)) - (b / (a * 2.0));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+139) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8.5e-81) tmp = Float64(Float64(sqrt(fma(b, b, Float64(-4.0 * Float64(c * a)))) / Float64(a * 2.0)) - Float64(b / Float64(a * 2.0))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+139], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.5e-81], N[(N[(N[Sqrt[N[(b * b + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision] - N[(b / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+139}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.0000000000000003e139Initial program 38.8%
Taylor expanded in b around -inf 95.4%
+-commutative95.4%
mul-1-neg95.4%
unsub-neg95.4%
Simplified95.4%
if -5.0000000000000003e139 < b < 8.5000000000000001e-81Initial program 79.2%
Simplified79.2%
*-commutative79.2%
metadata-eval79.2%
distribute-lft-neg-in79.2%
distribute-rgt-neg-in79.2%
*-commutative79.2%
fma-neg79.2%
associate-*l*79.2%
Applied egg-rr79.2%
div-sub79.2%
cancel-sign-sub-inv79.2%
fma-def79.2%
metadata-eval79.2%
Applied egg-rr79.2%
if 8.5000000000000001e-81 < b Initial program 18.9%
Taylor expanded in b around inf 88.7%
mul-1-neg88.7%
distribute-neg-frac88.7%
Simplified88.7%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2e+141)
(- (/ c b) (/ b a))
(if (<= b 1.7e-86)
(/ (- (sqrt (- (* b b) (* (* c a) 4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.7e-86) {
tmp = (sqrt(((b * b) - ((c * a) * 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 <= (-2d+141)) then
tmp = (c / b) - (b / a)
else if (b <= 1.7d-86) then
tmp = (sqrt(((b * b) - ((c * a) * 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 <= -2e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.7e-86) {
tmp = (Math.sqrt(((b * b) - ((c * a) * 4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+141: tmp = (c / b) - (b / a) elif b <= 1.7e-86: tmp = (math.sqrt(((b * b) - ((c * a) * 4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+141) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.7e-86) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(c * a) * 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 <= -2e+141) tmp = (c / b) - (b / a); elseif (b <= 1.7e-86) tmp = (sqrt(((b * b) - ((c * a) * 4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+141], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-86], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * 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 -2 \cdot 10^{+141}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-86}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.00000000000000003e141Initial program 38.8%
Taylor expanded in b around -inf 95.4%
+-commutative95.4%
mul-1-neg95.4%
unsub-neg95.4%
Simplified95.4%
if -2.00000000000000003e141 < b < 1.7e-86Initial program 79.2%
Simplified79.2%
*-commutative79.2%
metadata-eval79.2%
distribute-lft-neg-in79.2%
distribute-rgt-neg-in79.2%
*-commutative79.2%
fma-neg79.2%
associate-*l*79.2%
Applied egg-rr79.2%
if 1.7e-86 < b Initial program 18.9%
Taylor expanded in b around inf 88.7%
mul-1-neg88.7%
distribute-neg-frac88.7%
Simplified88.7%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e-34)
(- (/ c b) (/ b a))
(if (<= b 1.4e-82)
(* (- (sqrt (* -4.0 (* c a))) b) (/ 1.0 (* a 2.0)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-34) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-82) {
tmp = (sqrt((-4.0 * (c * a))) - b) * (1.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 <= (-3.5d-34)) then
tmp = (c / b) - (b / a)
else if (b <= 1.4d-82) then
tmp = (sqrt(((-4.0d0) * (c * a))) - b) * (1.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 <= -3.5e-34) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-82) {
tmp = (Math.sqrt((-4.0 * (c * a))) - b) * (1.0 / (a * 2.0));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e-34: tmp = (c / b) - (b / a) elif b <= 1.4e-82: tmp = (math.sqrt((-4.0 * (c * a))) - b) * (1.0 / (a * 2.0)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-34) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.4e-82) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(c * a))) - b) * Float64(1.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 <= -3.5e-34) tmp = (c / b) - (b / a); elseif (b <= 1.4e-82) tmp = (sqrt((-4.0 * (c * a))) - b) * (1.0 / (a * 2.0)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-34], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.4e-82], N[(N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-82}:\\
\;\;\;\;\left(\sqrt{-4 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.5e-34Initial program 58.4%
Taylor expanded in b around -inf 91.2%
+-commutative91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
if -3.5e-34 < b < 1.40000000000000012e-82Initial program 72.7%
Simplified72.7%
*-commutative72.7%
metadata-eval72.7%
distribute-lft-neg-in72.7%
distribute-rgt-neg-in72.7%
*-commutative72.7%
fma-neg72.7%
associate-*l*72.7%
Applied egg-rr72.7%
div-inv72.7%
cancel-sign-sub-inv72.7%
fma-def72.7%
metadata-eval72.7%
Applied egg-rr72.7%
Taylor expanded in b around 0 61.4%
*-commutative61.4%
Simplified61.4%
if 1.40000000000000012e-82 < b Initial program 18.9%
Taylor expanded in b around inf 88.7%
mul-1-neg88.7%
distribute-neg-frac88.7%
Simplified88.7%
Final simplification82.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.2e-32)
(- (/ c b) (/ b a))
(if (<= b 4.1e-86)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-32) {
tmp = (c / b) - (b / a);
} else if (b <= 4.1e-86) {
tmp = (sqrt((c * (a * -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 <= (-2.2d-32)) then
tmp = (c / b) - (b / a)
else if (b <= 4.1d-86) then
tmp = (sqrt((c * (a * (-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 <= -2.2e-32) {
tmp = (c / b) - (b / a);
} else if (b <= 4.1e-86) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e-32: tmp = (c / b) - (b / a) elif b <= 4.1e-86: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e-32) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.1e-86) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -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 <= -2.2e-32) tmp = (c / b) - (b / a); elseif (b <= 4.1e-86) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e-32], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.1e-86], N[(N[(N[Sqrt[N[(c * N[(a * -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 -2.2 \cdot 10^{-32}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.1 \cdot 10^{-86}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.2e-32Initial program 58.4%
Taylor expanded in b around -inf 91.2%
+-commutative91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
if -2.2e-32 < b < 4.09999999999999979e-86Initial program 72.7%
Simplified72.7%
*-commutative72.7%
metadata-eval72.7%
distribute-lft-neg-in72.7%
distribute-rgt-neg-in72.7%
*-commutative72.7%
fma-neg72.7%
associate-*l*72.7%
Applied egg-rr72.7%
Taylor expanded in b around 0 61.4%
associate-*r*61.4%
Simplified61.4%
if 4.09999999999999979e-86 < b Initial program 18.9%
Taylor expanded in b around inf 88.7%
mul-1-neg88.7%
distribute-neg-frac88.7%
Simplified88.7%
Final simplification82.5%
(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 62.7%
Taylor expanded in b around -inf 74.0%
+-commutative74.0%
mul-1-neg74.0%
unsub-neg74.0%
Simplified74.0%
if -4.999999999999985e-310 < b Initial program 31.0%
Taylor expanded in b around inf 72.7%
mul-1-neg72.7%
distribute-neg-frac72.7%
Simplified72.7%
Final simplification73.4%
(FPCore (a b c) :precision binary64 (if (<= b 6e+23) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6e+23) {
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 <= 6d+23) 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 <= 6e+23) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6e+23: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6e+23) 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 <= 6e+23) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6e+23], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6 \cdot 10^{+23}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 6.0000000000000002e23Initial program 61.7%
Taylor expanded in b around -inf 55.2%
associate-*r/55.2%
mul-1-neg55.2%
Simplified55.2%
if 6.0000000000000002e23 < b Initial program 14.3%
Taylor expanded in b around -inf 2.4%
+-commutative2.4%
mul-1-neg2.4%
unsub-neg2.4%
Simplified2.4%
Taylor expanded in c around inf 40.4%
Final simplification50.8%
(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 62.7%
Taylor expanded in b around -inf 73.3%
associate-*r/73.3%
mul-1-neg73.3%
Simplified73.3%
if -4.999999999999985e-310 < b Initial program 31.0%
Taylor expanded in b around inf 72.7%
mul-1-neg72.7%
distribute-neg-frac72.7%
Simplified72.7%
Final simplification73.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 47.5%
Taylor expanded in b around -inf 39.5%
+-commutative39.5%
mul-1-neg39.5%
unsub-neg39.5%
Simplified39.5%
Taylor expanded in c around inf 14.3%
Final simplification14.3%
herbie shell --seed 2023278
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))