
(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 -1.8e-91)
(/ (- c) b)
(if (<= b 3.5e+97)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-91) {
tmp = -c / b;
} else if (b <= 3.5e+97) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-1.8d-91)) then
tmp = -c / b
else if (b <= 3.5d+97) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
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 <= -1.8e-91) {
tmp = -c / b;
} else if (b <= 3.5e+97) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-91: tmp = -c / b elif b <= 3.5e+97: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-91) tmp = Float64(Float64(-c) / b); elseif (b <= 3.5e+97) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); 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 <= -1.8e-91) tmp = -c / b; elseif (b <= 3.5e+97) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-91], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.5e+97], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $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^{-91}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{+97}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.8e-91Initial program 12.0%
sub-neg12.0%
distribute-neg-out12.0%
neg-mul-112.0%
times-frac12.0%
metadata-eval12.0%
sub-neg12.0%
+-commutative12.0%
distribute-rgt-neg-in12.0%
distribute-rgt-neg-out12.0%
*-commutative12.0%
associate-*l*12.0%
fma-def12.0%
distribute-lft-neg-in12.0%
distribute-rgt-neg-in12.0%
metadata-eval12.0%
Simplified12.0%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
Simplified90.2%
if -1.8e-91 < b < 3.5000000000000001e97Initial program 84.7%
if 3.5000000000000001e97 < b Initial program 52.4%
sub-neg52.4%
distribute-neg-out52.4%
neg-mul-152.4%
times-frac52.4%
metadata-eval52.4%
sub-neg52.4%
+-commutative52.4%
distribute-rgt-neg-in52.4%
distribute-rgt-neg-out52.4%
*-commutative52.4%
associate-*l*52.4%
fma-def52.4%
distribute-lft-neg-in52.4%
distribute-rgt-neg-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in b around inf 91.7%
+-commutative91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
Final simplification88.2%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-92)
(/ (- c) b)
(if (<= b 2.7e-7)
(/ (- (- b) (sqrt (* a (* c -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-92) {
tmp = -c / b;
} else if (b <= 2.7e-7) {
tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0);
} 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 <= (-4.6d-92)) then
tmp = -c / b
else if (b <= 2.7d-7) then
tmp = (-b - sqrt((a * (c * (-4.0d0))))) / (a * 2.0d0)
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 <= -4.6e-92) {
tmp = -c / b;
} else if (b <= 2.7e-7) {
tmp = (-b - Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-92: tmp = -c / b elif b <= 2.7e-7: tmp = (-b - math.sqrt((a * (c * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-92) tmp = Float64(Float64(-c) / b); elseif (b <= 2.7e-7) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))) / Float64(a * 2.0)); 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 <= -4.6e-92) tmp = -c / b; elseif (b <= 2.7e-7) tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-92], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.7e-7], N[(N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-92}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-7}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.60000000000000032e-92Initial program 12.0%
sub-neg12.0%
distribute-neg-out12.0%
neg-mul-112.0%
times-frac12.0%
metadata-eval12.0%
sub-neg12.0%
+-commutative12.0%
distribute-rgt-neg-in12.0%
distribute-rgt-neg-out12.0%
*-commutative12.0%
associate-*l*12.0%
fma-def12.0%
distribute-lft-neg-in12.0%
distribute-rgt-neg-in12.0%
metadata-eval12.0%
Simplified12.0%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
Simplified90.2%
if -4.60000000000000032e-92 < b < 2.70000000000000009e-7Initial program 84.2%
*-commutative84.2%
sqr-neg84.2%
*-commutative84.2%
sqr-neg84.2%
associate-*r*84.2%
*-commutative84.2%
Simplified84.2%
Taylor expanded in b around 0 72.9%
*-commutative72.9%
associate-*r*72.9%
Simplified72.9%
if 2.70000000000000009e-7 < b Initial program 63.9%
sub-neg63.9%
distribute-neg-out63.9%
neg-mul-163.9%
times-frac63.9%
metadata-eval63.9%
sub-neg63.9%
+-commutative63.9%
distribute-rgt-neg-in63.9%
distribute-rgt-neg-out63.9%
*-commutative63.9%
associate-*l*63.9%
fma-def63.9%
distribute-lft-neg-in63.9%
distribute-rgt-neg-in63.9%
metadata-eval63.9%
Simplified63.9%
Taylor expanded in b around inf 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-97)
(/ (- c) b)
(if (<= b 3.2e-8)
(* (/ 0.5 a) (- b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-97) {
tmp = -c / b;
} else if (b <= 3.2e-8) {
tmp = (0.5 / a) * (b - sqrt((a * (c * -4.0))));
} 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 <= (-1.05d-97)) then
tmp = -c / b
else if (b <= 3.2d-8) then
tmp = (0.5d0 / a) * (b - sqrt((a * (c * (-4.0d0)))))
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 <= -1.05e-97) {
tmp = -c / b;
} else if (b <= 3.2e-8) {
tmp = (0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e-97: tmp = -c / b elif b <= 3.2e-8: tmp = (0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e-97) tmp = Float64(Float64(-c) / b); elseif (b <= 3.2e-8) tmp = Float64(Float64(0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); 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 <= -1.05e-97) tmp = -c / b; elseif (b <= 3.2e-8) tmp = (0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e-97], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.2e-8], N[(N[(0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{-97}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.0500000000000001e-97Initial program 12.0%
sub-neg12.0%
distribute-neg-out12.0%
neg-mul-112.0%
times-frac12.0%
metadata-eval12.0%
sub-neg12.0%
+-commutative12.0%
distribute-rgt-neg-in12.0%
distribute-rgt-neg-out12.0%
*-commutative12.0%
associate-*l*12.0%
fma-def12.0%
distribute-lft-neg-in12.0%
distribute-rgt-neg-in12.0%
metadata-eval12.0%
Simplified12.0%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
Simplified90.2%
if -1.0500000000000001e-97 < b < 3.2000000000000002e-8Initial program 84.2%
*-commutative84.2%
sqr-neg84.2%
*-commutative84.2%
sqr-neg84.2%
associate-*r*84.2%
*-commutative84.2%
Simplified84.2%
Applied egg-rr70.5%
Taylor expanded in a around inf 70.1%
*-commutative70.1%
associate-*r*70.1%
Simplified70.1%
if 3.2000000000000002e-8 < b Initial program 63.9%
sub-neg63.9%
distribute-neg-out63.9%
neg-mul-163.9%
times-frac63.9%
metadata-eval63.9%
sub-neg63.9%
+-commutative63.9%
distribute-rgt-neg-in63.9%
distribute-rgt-neg-out63.9%
*-commutative63.9%
associate-*l*63.9%
fma-def63.9%
distribute-lft-neg-in63.9%
distribute-rgt-neg-in63.9%
metadata-eval63.9%
Simplified63.9%
Taylor expanded in b around inf 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.3e-91)
(/ (- c) b)
(if (<= b 3e-8)
(/ -0.5 (/ a (+ b (sqrt (* a (* c -4.0))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-91) {
tmp = -c / b;
} else if (b <= 3e-8) {
tmp = -0.5 / (a / (b + sqrt((a * (c * -4.0)))));
} 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 <= (-1.3d-91)) then
tmp = -c / b
else if (b <= 3d-8) then
tmp = (-0.5d0) / (a / (b + sqrt((a * (c * (-4.0d0))))))
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 <= -1.3e-91) {
tmp = -c / b;
} else if (b <= 3e-8) {
tmp = -0.5 / (a / (b + Math.sqrt((a * (c * -4.0)))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.3e-91: tmp = -c / b elif b <= 3e-8: tmp = -0.5 / (a / (b + math.sqrt((a * (c * -4.0))))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.3e-91) tmp = Float64(Float64(-c) / b); elseif (b <= 3e-8) tmp = Float64(-0.5 / Float64(a / Float64(b + sqrt(Float64(a * Float64(c * -4.0)))))); 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 <= -1.3e-91) tmp = -c / b; elseif (b <= 3e-8) tmp = -0.5 / (a / (b + sqrt((a * (c * -4.0))))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.3e-91], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3e-8], N[(-0.5 / N[(a / N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-8}:\\
\;\;\;\;\frac{-0.5}{\frac{a}{b + \sqrt{a \cdot \left(c \cdot -4\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.30000000000000007e-91Initial program 12.0%
sub-neg12.0%
distribute-neg-out12.0%
neg-mul-112.0%
times-frac12.0%
metadata-eval12.0%
sub-neg12.0%
+-commutative12.0%
distribute-rgt-neg-in12.0%
distribute-rgt-neg-out12.0%
*-commutative12.0%
associate-*l*12.0%
fma-def12.0%
distribute-lft-neg-in12.0%
distribute-rgt-neg-in12.0%
metadata-eval12.0%
Simplified12.0%
Taylor expanded in b around -inf 90.2%
mul-1-neg90.2%
Simplified90.2%
if -1.30000000000000007e-91 < b < 2.99999999999999973e-8Initial program 84.2%
sub-neg84.2%
distribute-neg-out84.2%
neg-mul-184.2%
times-frac84.2%
metadata-eval84.2%
sub-neg84.2%
+-commutative84.2%
distribute-rgt-neg-in84.2%
distribute-rgt-neg-out84.2%
*-commutative84.2%
associate-*l*84.2%
fma-def84.2%
distribute-lft-neg-in84.2%
distribute-rgt-neg-in84.2%
metadata-eval84.2%
Simplified84.2%
clear-num84.1%
un-div-inv84.1%
pow284.1%
Applied egg-rr84.1%
Taylor expanded in a around inf 72.9%
*-commutative70.1%
associate-*r*70.1%
Simplified72.9%
if 2.99999999999999973e-8 < b Initial program 63.9%
sub-neg63.9%
distribute-neg-out63.9%
neg-mul-163.9%
times-frac63.9%
metadata-eval63.9%
sub-neg63.9%
+-commutative63.9%
distribute-rgt-neg-in63.9%
distribute-rgt-neg-out63.9%
*-commutative63.9%
associate-*l*63.9%
fma-def63.9%
distribute-lft-neg-in63.9%
distribute-rgt-neg-in63.9%
metadata-eval63.9%
Simplified63.9%
Taylor expanded in b around inf 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification83.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 28.2%
sub-neg28.2%
distribute-neg-out28.2%
neg-mul-128.2%
times-frac28.2%
metadata-eval28.2%
sub-neg28.2%
+-commutative28.2%
distribute-rgt-neg-in28.2%
distribute-rgt-neg-out28.2%
*-commutative28.2%
associate-*l*28.2%
fma-def28.2%
distribute-lft-neg-in28.2%
distribute-rgt-neg-in28.2%
metadata-eval28.2%
Simplified28.2%
Taylor expanded in b around -inf 72.2%
mul-1-neg72.2%
Simplified72.2%
if -3.999999999999988e-310 < b Initial program 73.0%
sub-neg73.0%
distribute-neg-out73.0%
neg-mul-173.0%
times-frac73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
distribute-rgt-neg-in73.0%
distribute-rgt-neg-out73.0%
*-commutative73.0%
associate-*l*73.0%
fma-def73.0%
distribute-lft-neg-in73.0%
distribute-rgt-neg-in73.0%
metadata-eval73.0%
Simplified73.0%
Taylor expanded in b around inf 60.5%
+-commutative60.5%
mul-1-neg60.5%
unsub-neg60.5%
Simplified60.5%
Final simplification66.8%
(FPCore (a b c) :precision binary64 (if (<= b -1.3e-277) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-277) {
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 <= (-1.3d-277)) 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 <= -1.3e-277) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.3e-277: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.3e-277) 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 <= -1.3e-277) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.3e-277], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.3 \cdot 10^{-277}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.3e-277Initial program 24.0%
sub-neg24.0%
distribute-neg-out24.0%
neg-mul-124.0%
times-frac24.0%
metadata-eval24.0%
sub-neg24.0%
+-commutative24.0%
distribute-rgt-neg-in24.0%
distribute-rgt-neg-out24.0%
*-commutative24.0%
associate-*l*24.0%
fma-def24.0%
distribute-lft-neg-in24.0%
distribute-rgt-neg-in24.0%
metadata-eval24.0%
Simplified24.0%
Taylor expanded in b around -inf 77.0%
mul-1-neg77.0%
Simplified77.0%
if -1.3e-277 < b Initial program 74.1%
sub-neg74.1%
distribute-neg-out74.1%
neg-mul-174.1%
times-frac74.1%
metadata-eval74.1%
sub-neg74.1%
+-commutative74.1%
distribute-rgt-neg-in74.1%
distribute-rgt-neg-out74.1%
*-commutative74.1%
associate-*l*74.1%
fma-def74.1%
distribute-lft-neg-in74.1%
distribute-rgt-neg-in74.1%
metadata-eval74.1%
Simplified74.1%
Taylor expanded in b around inf 56.1%
associate-*r/56.1%
mul-1-neg56.1%
Simplified56.1%
Final simplification66.6%
(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(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 49.0%
sub-neg49.0%
distribute-neg-out49.0%
neg-mul-149.0%
times-frac49.0%
metadata-eval49.0%
sub-neg49.0%
+-commutative49.0%
distribute-rgt-neg-in49.0%
distribute-rgt-neg-out49.0%
*-commutative49.0%
associate-*l*49.0%
fma-def49.0%
distribute-lft-neg-in49.0%
distribute-rgt-neg-in49.0%
metadata-eval49.0%
Simplified49.0%
Taylor expanded in b around -inf 39.6%
mul-1-neg39.6%
Simplified39.6%
Final simplification39.6%
(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 49.0%
sub-neg49.0%
distribute-neg-out49.0%
neg-mul-149.0%
times-frac49.0%
metadata-eval49.0%
sub-neg49.0%
+-commutative49.0%
distribute-rgt-neg-in49.0%
distribute-rgt-neg-out49.0%
*-commutative49.0%
associate-*l*49.0%
fma-def49.0%
distribute-lft-neg-in49.0%
distribute-rgt-neg-in49.0%
metadata-eval49.0%
Simplified49.0%
clear-num49.0%
un-div-inv49.0%
pow249.0%
Applied egg-rr49.0%
Taylor expanded in a around 0 29.2%
associate-/r/29.2%
add-log-exp9.5%
exp-prod11.3%
add-sqr-sqrt10.8%
sqrt-prod13.4%
sqr-neg13.4%
sqrt-unprod9.2%
add-sqr-sqrt12.1%
sub-neg12.1%
+-inverses12.1%
metadata-eval12.1%
metadata-eval12.1%
Applied egg-rr12.1%
Final simplification12.1%
(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) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a 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(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); 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 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; 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[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $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{c}{t_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2023331
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ c (- (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))) (/ (+ (/ 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)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))