
(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 10 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 -4e+154)
(- (/ b a))
(if (<= b 8.5e-119)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (or (<= b 6.5e-61) (not (<= b 2.9e-34)))
(/ (- c) b)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+154) {
tmp = -(b / a);
} else if (b <= 8.5e-119) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if ((b <= 6.5e-61) || !(b <= 2.9e-34)) {
tmp = -c / b;
} else {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+154) tmp = Float64(-Float64(b / a)); elseif (b <= 8.5e-119) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif ((b <= 6.5e-61) || !(b <= 2.9e-34)) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+154], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 8.5e-119], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 6.5e-61], N[Not[LessEqual[b, 2.9e-34]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], 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]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+154}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-119}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-61} \lor \neg \left(b \leq 2.9 \cdot 10^{-34}\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.00000000000000015e154Initial program 41.2%
*-commutative41.2%
Simplified41.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.00000000000000015e154 < b < 8.49999999999999977e-119Initial program 82.0%
+-commutative82.0%
unsub-neg82.0%
fma-neg82.0%
distribute-lft-neg-in82.0%
*-commutative82.0%
*-commutative82.0%
associate-*l*82.0%
metadata-eval82.0%
*-commutative82.0%
Simplified82.0%
if 8.49999999999999977e-119 < b < 6.4999999999999994e-61 or 2.9000000000000002e-34 < b Initial program 17.4%
*-commutative17.4%
Simplified17.4%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
if 6.4999999999999994e-61 < b < 2.9000000000000002e-34Initial program 86.2%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+152)
(- (/ b a))
(if (or (<= b 8.5e-119) (and (not (<= b 5.5e-61)) (<= b 3.1e-34)))
(/ (- (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 <= -4e+152) {
tmp = -(b / a);
} else if ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) {
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 <= (-4d+152)) then
tmp = -(b / a)
else if ((b <= 8.5d-119) .or. (.not. (b <= 5.5d-61)) .and. (b <= 3.1d-34)) 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 <= -4e+152) {
tmp = -(b / a);
} else if ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) {
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 <= -4e+152: tmp = -(b / a) elif (b <= 8.5e-119) or (not (b <= 5.5e-61) and (b <= 3.1e-34)): 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 <= -4e+152) tmp = Float64(-Float64(b / a)); elseif ((b <= 8.5e-119) || (!(b <= 5.5e-61) && (b <= 3.1e-34))) 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 <= -4e+152) tmp = -(b / a); elseif ((b <= 8.5e-119) || (~((b <= 5.5e-61)) && (b <= 3.1e-34))) 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, -4e+152], (-N[(b / a), $MachinePrecision]), If[Or[LessEqual[b, 8.5e-119], And[N[Not[LessEqual[b, 5.5e-61]], $MachinePrecision], LessEqual[b, 3.1e-34]]], 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 -4 \cdot 10^{+152}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-119} \lor \neg \left(b \leq 5.5 \cdot 10^{-61}\right) \land b \leq 3.1 \cdot 10^{-34}:\\
\;\;\;\;\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 < -4.0000000000000002e152Initial program 41.2%
*-commutative41.2%
Simplified41.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.0000000000000002e152 < b < 8.49999999999999977e-119 or 5.4999999999999997e-61 < b < 3.0999999999999998e-34Initial program 82.2%
if 8.49999999999999977e-119 < b < 5.4999999999999997e-61 or 3.0999999999999998e-34 < b Initial program 17.4%
*-commutative17.4%
Simplified17.4%
Taylor expanded in b around inf 86.6%
associate-*r/86.6%
neg-mul-186.6%
Simplified86.6%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-81)
(- (/ b a))
(if (<= b 3.6e-119)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-81) {
tmp = -(b / a);
} else if (b <= 3.6e-119) {
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.15d-81)) then
tmp = -(b / a)
else if (b <= 3.6d-119) 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.15e-81) {
tmp = -(b / a);
} else if (b <= 3.6e-119) {
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.15e-81: tmp = -(b / a) elif b <= 3.6e-119: 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.15e-81) tmp = Float64(-Float64(b / a)); elseif (b <= 3.6e-119) 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.15e-81) tmp = -(b / a); elseif (b <= 3.6e-119) 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.15e-81], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 3.6e-119], 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.15 \cdot 10^{-81}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-119}:\\
\;\;\;\;\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.14999999999999996e-81Initial program 67.6%
*-commutative67.6%
Simplified67.6%
Taylor expanded in b around -inf 87.4%
associate-*r/87.4%
mul-1-neg87.4%
Simplified87.4%
if -1.14999999999999996e-81 < b < 3.6e-119Initial program 73.8%
*-commutative73.8%
Simplified73.8%
Applied egg-rr72.9%
+-commutative72.9%
fma-udef72.9%
associate-+l+72.9%
*-commutative72.9%
*-commutative72.9%
+-commutative72.9%
fma-udef72.9%
unpow272.9%
associate-+l+72.9%
distribute-lft-out72.9%
Simplified72.9%
Taylor expanded in b around 0 70.6%
neg-mul-170.6%
unsub-neg70.6%
distribute-rgt-out71.0%
metadata-eval71.0%
associate-*r*71.0%
Simplified71.0%
if 3.6e-119 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in b around inf 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.2e-81) (- (/ b a)) (if (<= b 8e-121) (/ (- (sqrt (* -4.0 (* a c))) b) (* a 2.0)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-81) {
tmp = -(b / a);
} else if (b <= 8e-121) {
tmp = (sqrt((-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.2d-81)) then
tmp = -(b / a)
else if (b <= 8d-121) then
tmp = (sqrt(((-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.2e-81) {
tmp = -(b / a);
} else if (b <= 8e-121) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-81: tmp = -(b / a) elif b <= 8e-121: tmp = (math.sqrt((-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.2e-81) tmp = Float64(-Float64(b / a)); elseif (b <= 8e-121) tmp = Float64(Float64(sqrt(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.2e-81) tmp = -(b / a); elseif (b <= 8e-121) tmp = (sqrt((-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.2e-81], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 8e-121], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $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.2 \cdot 10^{-81}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-121}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.2e-81Initial program 67.6%
*-commutative67.6%
Simplified67.6%
Taylor expanded in b around -inf 87.4%
associate-*r/87.4%
mul-1-neg87.4%
Simplified87.4%
if -1.2e-81 < b < 7.9999999999999998e-121Initial program 73.8%
*-commutative73.8%
Simplified73.8%
Taylor expanded in b around 0 71.0%
*-commutative71.0%
Simplified71.0%
if 7.9999999999999998e-121 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in b around inf 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
Final simplification81.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-95) (- (/ b a)) (if (<= b 8.5e-119) (* 0.5 (/ (sqrt (* a (* c -4.0))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-95) {
tmp = -(b / a);
} else if (b <= 8.5e-119) {
tmp = 0.5 * (sqrt((a * (c * -4.0))) / 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 <= (-2.4d-95)) then
tmp = -(b / a)
else if (b <= 8.5d-119) then
tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / 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 <= -2.4e-95) {
tmp = -(b / a);
} else if (b <= 8.5e-119) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-95: tmp = -(b / a) elif b <= 8.5e-119: tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-95) tmp = Float64(-Float64(b / a)); elseif (b <= 8.5e-119) tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-95) tmp = -(b / a); elseif (b <= 8.5e-119) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-95], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 8.5e-119], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-95}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-119}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4e-95Initial program 68.4%
*-commutative68.4%
Simplified68.4%
Taylor expanded in b around -inf 86.7%
associate-*r/86.7%
mul-1-neg86.7%
Simplified86.7%
if -2.4e-95 < b < 8.49999999999999977e-119Initial program 73.0%
*-commutative73.0%
Simplified73.0%
Applied egg-rr72.0%
+-commutative72.0%
fma-udef72.0%
associate-+l+72.0%
*-commutative72.0%
*-commutative72.0%
+-commutative72.0%
fma-udef72.0%
unpow272.0%
associate-+l+72.0%
distribute-lft-out72.0%
Simplified72.0%
Taylor expanded in b around 0 70.3%
associate-*l/70.4%
*-lft-identity70.4%
distribute-rgt-out70.8%
metadata-eval70.8%
associate-*r*70.8%
Simplified70.8%
if 8.49999999999999977e-119 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in b around inf 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
Final simplification81.0%
(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 71.2%
*-commutative71.2%
Simplified71.2%
Taylor expanded in b around -inf 65.6%
+-commutative65.6%
mul-1-neg65.6%
unsub-neg65.6%
Simplified65.6%
if -4.999999999999985e-310 < b Initial program 31.8%
*-commutative31.8%
Simplified31.8%
Taylor expanded in b around inf 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b 4.8e+44) (- (/ b a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.8e+44) {
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 <= 4.8d+44) 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 <= 4.8e+44) {
tmp = -(b / a);
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.8e+44: tmp = -(b / a) else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.8e+44) 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 <= 4.8e+44) tmp = -(b / a); else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.8e+44], (-N[(b / a), $MachinePrecision]), N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8 \cdot 10^{+44}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 4.80000000000000026e44Initial program 63.2%
*-commutative63.2%
Simplified63.2%
Taylor expanded in b around -inf 43.9%
associate-*r/43.9%
mul-1-neg43.9%
Simplified43.9%
if 4.80000000000000026e44 < b Initial program 15.9%
+-commutative15.9%
unsub-neg15.9%
fma-neg15.9%
distribute-lft-neg-in15.9%
*-commutative15.9%
*-commutative15.9%
associate-*l*15.9%
metadata-eval15.9%
*-commutative15.9%
Simplified15.9%
sub-neg15.9%
Applied egg-rr0.8%
Taylor expanded in b around inf 2.3%
Taylor expanded in b around 0 32.3%
Final simplification40.9%
(FPCore (a b c) :precision binary64 (if (<= b 6.5e-299) (- (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.5e-299) {
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 <= 6.5d-299) 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 <= 6.5e-299) {
tmp = -(b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.5e-299: tmp = -(b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.5e-299) 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 <= 6.5e-299) tmp = -(b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.5e-299], (-N[(b / a), $MachinePrecision]), N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{-299}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 6.4999999999999997e-299Initial program 70.1%
*-commutative70.1%
Simplified70.1%
Taylor expanded in b around -inf 64.5%
associate-*r/64.5%
mul-1-neg64.5%
Simplified64.5%
if 6.4999999999999997e-299 < b Initial program 32.2%
*-commutative32.2%
Simplified32.2%
Taylor expanded in b around inf 68.1%
associate-*r/68.1%
neg-mul-168.1%
Simplified68.1%
Final simplification66.3%
(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.8%
+-commutative50.8%
unsub-neg50.8%
fma-neg50.8%
distribute-lft-neg-in50.8%
*-commutative50.8%
*-commutative50.8%
associate-*l*50.9%
metadata-eval50.9%
*-commutative50.9%
Simplified50.9%
sub-neg50.9%
Applied egg-rr1.1%
Taylor expanded in b around inf 2.7%
Final simplification2.7%
(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.8%
+-commutative50.8%
unsub-neg50.8%
fma-neg50.8%
distribute-lft-neg-in50.8%
*-commutative50.8%
*-commutative50.8%
associate-*l*50.9%
metadata-eval50.9%
*-commutative50.9%
Simplified50.9%
sub-neg50.9%
Applied egg-rr1.1%
Taylor expanded in b around inf 2.3%
Taylor expanded in b around 0 10.6%
Final simplification10.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t_0 - t_1} \cdot \sqrt{t_0 + t_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t_2}\\
\end{array}
\end{array}
herbie shell --seed 2023332
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))