
(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 7 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.8e-49)
(/ (- c) b)
(if (<= b 1.15e+86)
(* -0.5 (/ (+ b (sqrt (fma b b (* a (* c -4.0))))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-49) {
tmp = -c / b;
} else if (b <= 1.15e+86) {
tmp = -0.5 * ((b + sqrt(fma(b, b, (a * (c * -4.0))))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-49) tmp = Float64(Float64(-c) / b); elseif (b <= 1.15e+86) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(b, b, Float64(a * Float64(c * -4.0))))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-49], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.15e+86], N[(-0.5 * N[(N[(b + N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-49}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{+86}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.79999999999999985e-49Initial program 16.1%
Taylor expanded in b around -inf 88.9%
associate-*r/88.9%
neg-mul-188.9%
Simplified88.9%
if -1.79999999999999985e-49 < b < 1.14999999999999995e86Initial program 83.0%
/-rgt-identity83.0%
metadata-eval83.0%
associate-/l*82.9%
associate-/r/82.9%
*-commutative82.9%
metadata-eval82.9%
metadata-eval82.9%
associate-*l/82.9%
associate-/r/82.9%
times-frac83.0%
*-commutative83.0%
times-frac83.0%
metadata-eval83.0%
associate-/r/83.0%
*-commutative83.0%
div-sub83.0%
Simplified83.0%
if 1.14999999999999995e86 < b Initial program 55.2%
Taylor expanded in b around inf 97.0%
mul-1-neg97.0%
unsub-neg97.0%
Simplified97.0%
Final simplification88.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))))
(if (<= b -4.5e-103)
(/ (- c) b)
(if (<= b 3.8e-63)
t_0
(if (<= b 5.6e-34)
(/ (+ (* 2.0 (/ (* c a) b)) (* b -2.0)) (* a 2.0))
(if (<= b 1.8e+33) t_0 (/ (- b) a)))))))
double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a);
double tmp;
if (b <= -4.5e-103) {
tmp = -c / b;
} else if (b <= 3.8e-63) {
tmp = t_0;
} else if (b <= 5.6e-34) {
tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0);
} else if (b <= 1.8e+33) {
tmp = t_0;
} else {
tmp = -b / 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 = (-0.5d0) * ((b + sqrt((c * (a * (-4.0d0))))) / a)
if (b <= (-4.5d-103)) then
tmp = -c / b
else if (b <= 3.8d-63) then
tmp = t_0
else if (b <= 5.6d-34) then
tmp = ((2.0d0 * ((c * a) / b)) + (b * (-2.0d0))) / (a * 2.0d0)
else if (b <= 1.8d+33) then
tmp = t_0
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
double tmp;
if (b <= -4.5e-103) {
tmp = -c / b;
} else if (b <= 3.8e-63) {
tmp = t_0;
} else if (b <= 5.6e-34) {
tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0);
} else if (b <= 1.8e+33) {
tmp = t_0;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = -0.5 * ((b + math.sqrt((c * (a * -4.0)))) / a) tmp = 0 if b <= -4.5e-103: tmp = -c / b elif b <= 3.8e-63: tmp = t_0 elif b <= 5.6e-34: tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0) elif b <= 1.8e+33: tmp = t_0 else: tmp = -b / a return tmp
function code(a, b, c) t_0 = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / a)) tmp = 0.0 if (b <= -4.5e-103) tmp = Float64(Float64(-c) / b); elseif (b <= 3.8e-63) tmp = t_0; elseif (b <= 5.6e-34) tmp = Float64(Float64(Float64(2.0 * Float64(Float64(c * a) / b)) + Float64(b * -2.0)) / Float64(a * 2.0)); elseif (b <= 1.8e+33) tmp = t_0; else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a); tmp = 0.0; if (b <= -4.5e-103) tmp = -c / b; elseif (b <= 3.8e-63) tmp = t_0; elseif (b <= 5.6e-34) tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0); elseif (b <= 1.8e+33) tmp = t_0; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4.5e-103], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.8e-63], t$95$0, If[LessEqual[b, 5.6e-34], N[(N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+33], t$95$0, N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{if}\;b \leq -4.5 \cdot 10^{-103}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{-34}:\\
\;\;\;\;\frac{2 \cdot \frac{c \cdot a}{b} + b \cdot -2}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+33}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.5e-103Initial program 19.3%
Taylor expanded in b around -inf 86.0%
associate-*r/86.0%
neg-mul-186.0%
Simplified86.0%
if -4.5e-103 < b < 3.80000000000000017e-63 or 5.59999999999999994e-34 < b < 1.8000000000000001e33Initial program 81.9%
Simplified81.9%
Taylor expanded in a around inf 73.6%
*-commutative73.6%
*-commutative73.6%
*-commutative73.6%
associate-*l*73.6%
Simplified73.6%
if 3.80000000000000017e-63 < b < 5.59999999999999994e-34Initial program 100.0%
Taylor expanded in b around inf 93.5%
if 1.8000000000000001e33 < b Initial program 63.8%
Taylor expanded in b around inf 94.1%
associate-*r/94.1%
mul-1-neg94.1%
Simplified94.1%
Final simplification84.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))))
(if (<= b -8e-103)
(* -0.5 (/ 1.0 (fma -0.5 (/ a b) (/ 0.5 (/ c b)))))
(if (<= b 7e-63)
t_0
(if (<= b 1.8e-33)
(/ (+ (* 2.0 (/ (* c a) b)) (* b -2.0)) (* a 2.0))
(if (<= b 1.8e+33) t_0 (/ (- b) a)))))))
double code(double a, double b, double c) {
double t_0 = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a);
double tmp;
if (b <= -8e-103) {
tmp = -0.5 * (1.0 / fma(-0.5, (a / b), (0.5 / (c / b))));
} else if (b <= 7e-63) {
tmp = t_0;
} else if (b <= 1.8e-33) {
tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0);
} else if (b <= 1.8e+33) {
tmp = t_0;
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / a)) tmp = 0.0 if (b <= -8e-103) tmp = Float64(-0.5 * Float64(1.0 / fma(-0.5, Float64(a / b), Float64(0.5 / Float64(c / b))))); elseif (b <= 7e-63) tmp = t_0; elseif (b <= 1.8e-33) tmp = Float64(Float64(Float64(2.0 * Float64(Float64(c * a) / b)) + Float64(b * -2.0)) / Float64(a * 2.0)); elseif (b <= 1.8e+33) tmp = t_0; else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8e-103], N[(-0.5 * N[(1.0 / N[(-0.5 * N[(a / b), $MachinePrecision] + N[(0.5 / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7e-63], t$95$0, If[LessEqual[b, 1.8e-33], N[(N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+33], t$95$0, N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{if}\;b \leq -8 \cdot 10^{-103}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\mathsf{fma}\left(-0.5, \frac{a}{b}, \frac{0.5}{\frac{c}{b}}\right)}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{-33}:\\
\;\;\;\;\frac{2 \cdot \frac{c \cdot a}{b} + b \cdot -2}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+33}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.99999999999999966e-103Initial program 19.3%
/-rgt-identity19.3%
metadata-eval19.3%
associate-/l*19.3%
associate-/r/19.3%
*-commutative19.3%
metadata-eval19.3%
metadata-eval19.3%
associate-*l/19.3%
associate-/r/19.3%
times-frac19.3%
*-commutative19.3%
times-frac19.3%
metadata-eval19.3%
associate-/r/19.3%
*-commutative19.3%
div-sub18.6%
Simplified19.3%
fma-udef19.3%
Applied egg-rr19.3%
clear-num19.3%
inv-pow19.3%
Applied egg-rr25.1%
unpow-125.1%
Simplified25.1%
Taylor expanded in b around -inf 0.0%
+-commutative0.0%
fma-def0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt85.9%
metadata-eval85.9%
Simplified85.9%
expm1-log1p-u81.7%
expm1-udef31.2%
associate-*r/31.2%
Applied egg-rr31.2%
expm1-def81.7%
expm1-log1p85.9%
associate-/l*86.1%
Simplified86.1%
if -7.99999999999999966e-103 < b < 7.00000000000000006e-63 or 1.80000000000000017e-33 < b < 1.8000000000000001e33Initial program 81.9%
Simplified81.9%
Taylor expanded in a around inf 73.6%
*-commutative73.6%
*-commutative73.6%
*-commutative73.6%
associate-*l*73.6%
Simplified73.6%
if 7.00000000000000006e-63 < b < 1.80000000000000017e-33Initial program 100.0%
Taylor expanded in b around inf 93.5%
if 1.8000000000000001e33 < b Initial program 63.8%
Taylor expanded in b around inf 94.1%
associate-*r/94.1%
mul-1-neg94.1%
Simplified94.1%
Final simplification84.5%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-51)
(/ (- c) b)
(if (<= b 5e+85)
(* -0.5 (/ (+ b (sqrt (+ (* a (* c -4.0)) (* b b)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-51) {
tmp = -c / b;
} else if (b <= 5e+85) {
tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-7d-51)) then
tmp = -c / b
else if (b <= 5d+85) then
tmp = (-0.5d0) * ((b + sqrt(((a * (c * (-4.0d0))) + (b * b)))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7e-51) {
tmp = -c / b;
} else if (b <= 5e+85) {
tmp = -0.5 * ((b + Math.sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-51: tmp = -c / b elif b <= 5e+85: tmp = -0.5 * ((b + math.sqrt(((a * (c * -4.0)) + (b * b)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-51) tmp = Float64(Float64(-c) / b); elseif (b <= 5e+85) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-51) tmp = -c / b; elseif (b <= 5e+85) tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-51], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5e+85], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-51}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+85}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.9999999999999995e-51Initial program 16.1%
Taylor expanded in b around -inf 88.9%
associate-*r/88.9%
neg-mul-188.9%
Simplified88.9%
if -6.9999999999999995e-51 < b < 5.0000000000000001e85Initial program 83.0%
/-rgt-identity83.0%
metadata-eval83.0%
associate-/l*82.9%
associate-/r/82.9%
*-commutative82.9%
metadata-eval82.9%
metadata-eval82.9%
associate-*l/82.9%
associate-/r/82.9%
times-frac83.0%
*-commutative83.0%
times-frac83.0%
metadata-eval83.0%
associate-/r/83.0%
*-commutative83.0%
div-sub83.0%
Simplified83.0%
fma-udef83.0%
Applied egg-rr83.0%
if 5.0000000000000001e85 < b Initial program 55.2%
Taylor expanded in b around inf 97.0%
mul-1-neg97.0%
unsub-neg97.0%
Simplified97.0%
Final simplification88.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-2d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 33.6%
Taylor expanded in b around -inf 66.7%
associate-*r/66.7%
neg-mul-166.7%
Simplified66.7%
if -1.999999999999994e-310 < b Initial program 74.0%
Taylor expanded in b around inf 66.4%
mul-1-neg66.4%
unsub-neg66.4%
Simplified66.4%
Final simplification66.5%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -c / b;
} else {
tmp = -b / 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) :: tmp
if (b <= (-2d-310)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 33.6%
Taylor expanded in b around -inf 66.7%
associate-*r/66.7%
neg-mul-166.7%
Simplified66.7%
if -1.999999999999994e-310 < b Initial program 74.0%
Taylor expanded in b around inf 66.2%
associate-*r/66.2%
mul-1-neg66.2%
Simplified66.2%
Final simplification66.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(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 55.1%
Taylor expanded in b around inf 36.5%
associate-*r/36.5%
mul-1-neg36.5%
Simplified36.5%
Final simplification36.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-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(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $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{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023258
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))