
(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 -5.6e+159)
(/ (- b) a)
(if (<= b 2.3e-60)
(/ (* -0.5 (- b (sqrt (fma (* -4.0 c) a (* b b))))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.6e+159) {
tmp = -b / a;
} else if (b <= 2.3e-60) {
tmp = (-0.5 * (b - sqrt(fma((-4.0 * c), a, (b * b))))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5.6e+159) tmp = Float64(Float64(-b) / a); elseif (b <= 2.3e-60) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5.6e+159], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.3e-60], N[(N[(-0.5 * N[(b - N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.6 \cdot 10^{+159}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.6000000000000002e159Initial program 40.5%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6497.8
Applied rewrites97.8%
if -5.6000000000000002e159 < b < 2.3000000000000001e-60Initial program 84.0%
Applied rewrites84.8%
if 2.3000000000000001e-60 < b Initial program 14.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.6
Applied rewrites91.6%
Final simplification89.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e+129)
(/ (- b) a)
(if (<= b 2.3e-60)
(* (- (sqrt (fma (* -4.0 c) a (* b b))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e+129) {
tmp = -b / a;
} else if (b <= 2.3e-60) {
tmp = (sqrt(fma((-4.0 * c), a, (b * b))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.8e+129) tmp = Float64(Float64(-b) / a); elseif (b <= 2.3e-60) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.8e+129], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.3e-60], N[(N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $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.8 \cdot 10^{+129}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.8000000000000001e129Initial program 45.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6498.0
Applied rewrites98.0%
if -1.8000000000000001e129 < b < 2.3000000000000001e-60Initial program 83.4%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6483.2
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6483.2
Applied rewrites84.1%
if 2.3000000000000001e-60 < b Initial program 14.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.6
Applied rewrites91.6%
Final simplification89.4%
(FPCore (a b c)
:precision binary64
(if (<= b -8.2e-17)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 2.3e-60)
(/ (* (- (sqrt (* (* c a) -4.0)) b) 0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-17) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 2.3e-60) {
tmp = ((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 <= -8.2e-17) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 2.3e-60) tmp = Float64(Float64(Float64(sqrt(Float64(Float64(c * a) * -4.0)) - b) * 0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8.2e-17], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-60], N[(N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * 0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\frac{\left(\sqrt{\left(c \cdot a\right) \cdot -4} - b\right) \cdot 0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.2000000000000001e-17Initial program 66.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6491.6
Applied rewrites91.6%
if -8.2000000000000001e-17 < b < 2.3000000000000001e-60Initial program 78.4%
Taylor expanded in c around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6474.4
Applied rewrites74.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites75.5%
if 2.3000000000000001e-60 < b Initial program 14.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.6
Applied rewrites91.6%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -8.2e-17)
(* (- (/ c (* b b)) (/ 1.0 a)) b)
(if (<= b 2.3e-60)
(/ (* (- (sqrt (* (* c a) -4.0)) b) 0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-17) {
tmp = ((c / (b * b)) - (1.0 / a)) * b;
} else if (b <= 2.3e-60) {
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 <= (-8.2d-17)) then
tmp = ((c / (b * b)) - (1.0d0 / a)) * b
else if (b <= 2.3d-60) 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 <= -8.2e-17) {
tmp = ((c / (b * b)) - (1.0 / a)) * b;
} else if (b <= 2.3e-60) {
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 <= -8.2e-17: tmp = ((c / (b * b)) - (1.0 / a)) * b elif b <= 2.3e-60: 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 <= -8.2e-17) tmp = Float64(Float64(Float64(c / Float64(b * b)) - Float64(1.0 / a)) * b); elseif (b <= 2.3e-60) tmp = Float64(Float64(Float64(sqrt(Float64(Float64(c * a) * -4.0)) - b) * 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 <= -8.2e-17) tmp = ((c / (b * b)) - (1.0 / a)) * b; elseif (b <= 2.3e-60) 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, -8.2e-17], N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[b, 2.3e-60], N[(N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * 0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-17}:\\
\;\;\;\;\left(\frac{c}{b \cdot b} - \frac{1}{a}\right) \cdot b\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\frac{\left(\sqrt{\left(c \cdot a\right) \cdot -4} - b\right) \cdot 0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.2000000000000001e-17Initial program 66.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6491.1
Applied rewrites91.1%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6491.4
Applied rewrites91.4%
if -8.2000000000000001e-17 < b < 2.3000000000000001e-60Initial program 78.4%
Taylor expanded in c around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6474.4
Applied rewrites74.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites75.5%
if 2.3000000000000001e-60 < b Initial program 14.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.6
Applied rewrites91.6%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -8.2e-17)
(* (- (/ c (* b b)) (/ 1.0 a)) b)
(if (<= b 2.3e-60)
(* (- (sqrt (* (* c a) -4.0)) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-17) {
tmp = ((c / (b * b)) - (1.0 / a)) * b;
} else if (b <= 2.3e-60) {
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 <= (-8.2d-17)) then
tmp = ((c / (b * b)) - (1.0d0 / a)) * b
else if (b <= 2.3d-60) 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 <= -8.2e-17) {
tmp = ((c / (b * b)) - (1.0 / a)) * b;
} else if (b <= 2.3e-60) {
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 <= -8.2e-17: tmp = ((c / (b * b)) - (1.0 / a)) * b elif b <= 2.3e-60: 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 <= -8.2e-17) tmp = Float64(Float64(Float64(c / Float64(b * b)) - Float64(1.0 / a)) * b); elseif (b <= 2.3e-60) tmp = Float64(Float64(sqrt(Float64(Float64(c * 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 <= -8.2e-17) tmp = ((c / (b * b)) - (1.0 / a)) * b; elseif (b <= 2.3e-60) 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, -8.2e-17], N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[b, 2.3e-60], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-17}:\\
\;\;\;\;\left(\frac{c}{b \cdot b} - \frac{1}{a}\right) \cdot b\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\left(\sqrt{\left(c \cdot a\right) \cdot -4} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.2000000000000001e-17Initial program 66.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6491.1
Applied rewrites91.1%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6491.4
Applied rewrites91.4%
if -8.2000000000000001e-17 < b < 2.3000000000000001e-60Initial program 78.4%
Taylor expanded in c around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6474.4
Applied rewrites74.4%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lift-/.f64N/A
lower-*.f6475.3
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6475.3
Applied rewrites75.3%
if 2.3000000000000001e-60 < b Initial program 14.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.6
Applied rewrites91.6%
Final simplification86.3%
(FPCore (a b c) :precision binary64 (if (<= b 3.5e-308) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.5e-308) {
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 <= 3.5d-308) 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 <= 3.5e-308) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.5e-308: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.5e-308) 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 <= 3.5e-308) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.5e-308], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 3.5e-308Initial program 72.5%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6464.1
Applied rewrites64.1%
if 3.5e-308 < b Initial program 31.9%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6468.8
Applied rewrites68.8%
(FPCore (a b c) :precision binary64 (if (<= b 3.1e+28) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.1e+28) {
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 <= 3.1d+28) 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 <= 3.1e+28) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.1e+28: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.1e+28) 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 <= 3.1e+28) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.1e+28], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.1 \cdot 10^{+28}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.1000000000000001e28Initial program 69.5%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6445.3
Applied rewrites45.3%
if 3.1000000000000001e28 < b Initial program 13.6%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.6
Applied rewrites92.6%
Applied rewrites32.8%
(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 50.3%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6438.6
Applied rewrites38.6%
Applied rewrites13.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 50.3%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6430.5
Applied rewrites30.5%
Applied rewrites21.0%
Applied rewrites2.6%
herbie shell --seed 2024270
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))