
(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 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(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 -8.2e-82)
(/ (- c) b)
(if (<= b 3.2e+114)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-82) {
tmp = -c / b;
} else if (b <= 3.2e+114) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.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) :: tmp
if (b <= (-8.2d-82)) then
tmp = -c / b
else if (b <= 3.2d+114) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.2e-82) {
tmp = -c / b;
} else if (b <= 3.2e+114) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.2e-82: tmp = -c / b elif b <= 3.2e+114: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.2e-82) tmp = Float64(Float64(-c) / b); elseif (b <= 3.2e+114) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.2e-82) tmp = -c / b; elseif (b <= 3.2e+114) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.2e-82], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.2e+114], 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[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-82}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{+114}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.19999999999999992e-82Initial program 13.9%
sub-neg13.9%
distribute-neg-out13.9%
neg-mul-113.9%
times-frac13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
distribute-rgt-neg-in13.9%
distribute-rgt-neg-out13.9%
*-commutative13.9%
associate-*l*13.9%
fma-def13.9%
distribute-lft-neg-in13.9%
distribute-rgt-neg-in13.9%
metadata-eval13.9%
Simplified13.9%
Taylor expanded in b around -inf 90.3%
mul-1-neg90.3%
Simplified90.3%
if -8.19999999999999992e-82 < b < 3.2e114Initial program 81.3%
if 3.2e114 < b Initial program 35.1%
sub-neg35.1%
distribute-neg-out35.1%
neg-mul-135.1%
times-frac35.1%
metadata-eval35.1%
sub-neg35.1%
+-commutative35.1%
distribute-rgt-neg-in35.1%
distribute-rgt-neg-out35.1%
*-commutative35.1%
associate-*l*35.1%
fma-def35.1%
distribute-lft-neg-in35.1%
distribute-rgt-neg-in35.1%
metadata-eval35.1%
Simplified35.1%
Taylor expanded in b around inf 98.0%
associate-*r/98.0%
mul-1-neg98.0%
Simplified98.0%
Final simplification87.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.3e-82)
(/ (- c) b)
(if (<= b 4.2e-82)
(/ (- (- 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 <= -1.3e-82) {
tmp = -c / b;
} else if (b <= 4.2e-82) {
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 <= (-1.3d-82)) then
tmp = -c / b
else if (b <= 4.2d-82) 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 <= -1.3e-82) {
tmp = -c / b;
} else if (b <= 4.2e-82) {
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 <= -1.3e-82: tmp = -c / b elif b <= 4.2e-82: 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 <= -1.3e-82) tmp = Float64(Float64(-c) / b); elseif (b <= 4.2e-82) 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 <= -1.3e-82) tmp = -c / b; elseif (b <= 4.2e-82) 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, -1.3e-82], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.2e-82], 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 -1.3 \cdot 10^{-82}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-82}:\\
\;\;\;\;\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 < -1.3e-82Initial program 13.9%
sub-neg13.9%
distribute-neg-out13.9%
neg-mul-113.9%
times-frac13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
distribute-rgt-neg-in13.9%
distribute-rgt-neg-out13.9%
*-commutative13.9%
associate-*l*13.9%
fma-def13.9%
distribute-lft-neg-in13.9%
distribute-rgt-neg-in13.9%
metadata-eval13.9%
Simplified13.9%
Taylor expanded in b around -inf 90.3%
mul-1-neg90.3%
Simplified90.3%
if -1.3e-82 < b < 4.2000000000000001e-82Initial program 74.5%
*-commutative74.5%
sqr-neg74.5%
*-commutative74.5%
sqr-neg74.5%
associate-*r*74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around 0 68.0%
*-commutative68.0%
associate-*r*68.0%
Simplified68.0%
if 4.2000000000000001e-82 < b Initial program 62.3%
sub-neg62.3%
distribute-neg-out62.3%
neg-mul-162.3%
times-frac61.3%
metadata-eval61.3%
sub-neg61.3%
+-commutative61.3%
distribute-rgt-neg-in61.3%
distribute-rgt-neg-out61.3%
*-commutative61.3%
associate-*l*61.3%
fma-def61.3%
distribute-lft-neg-in61.3%
distribute-rgt-neg-in61.3%
metadata-eval61.3%
Simplified61.3%
Taylor expanded in b around inf 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
Final simplification83.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.4e-82)
(/ (- c) b)
(if (<= b 8.8e-83)
(* (/ -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 <= -2.4e-82) {
tmp = -c / b;
} else if (b <= 8.8e-83) {
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 <= (-2.4d-82)) then
tmp = -c / b
else if (b <= 8.8d-83) 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 <= -2.4e-82) {
tmp = -c / b;
} else if (b <= 8.8e-83) {
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 <= -2.4e-82: tmp = -c / b elif b <= 8.8e-83: 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 <= -2.4e-82) tmp = Float64(Float64(-c) / b); elseif (b <= 8.8e-83) 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 <= -2.4e-82) tmp = -c / b; elseif (b <= 8.8e-83) 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, -2.4e-82], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8.8e-83], 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 -2.4 \cdot 10^{-82}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8.8 \cdot 10^{-83}:\\
\;\;\;\;\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 < -2.40000000000000008e-82Initial program 13.9%
sub-neg13.9%
distribute-neg-out13.9%
neg-mul-113.9%
times-frac13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
distribute-rgt-neg-in13.9%
distribute-rgt-neg-out13.9%
*-commutative13.9%
associate-*l*13.9%
fma-def13.9%
distribute-lft-neg-in13.9%
distribute-rgt-neg-in13.9%
metadata-eval13.9%
Simplified13.9%
Taylor expanded in b around -inf 90.3%
mul-1-neg90.3%
Simplified90.3%
if -2.40000000000000008e-82 < b < 8.8000000000000003e-83Initial program 74.5%
sub-neg74.5%
distribute-neg-out74.5%
neg-mul-174.5%
times-frac74.5%
metadata-eval74.5%
sub-neg74.5%
+-commutative74.5%
distribute-rgt-neg-in74.5%
distribute-rgt-neg-out74.5%
*-commutative74.5%
associate-*l*74.5%
fma-def74.5%
distribute-lft-neg-in74.5%
distribute-rgt-neg-in74.5%
metadata-eval74.5%
Simplified74.5%
clear-num74.4%
un-div-inv74.4%
pow274.4%
Applied egg-rr74.4%
add-sqr-sqrt74.0%
pow274.0%
pow1/274.0%
sqrt-pow174.0%
metadata-eval74.0%
Applied egg-rr74.0%
Taylor expanded in c around -inf 40.8%
Taylor expanded in a around 0 40.8%
Simplified67.9%
if 8.8000000000000003e-83 < b Initial program 62.3%
sub-neg62.3%
distribute-neg-out62.3%
neg-mul-162.3%
times-frac61.3%
metadata-eval61.3%
sub-neg61.3%
+-commutative61.3%
distribute-rgt-neg-in61.3%
distribute-rgt-neg-out61.3%
*-commutative61.3%
associate-*l*61.3%
fma-def61.3%
distribute-lft-neg-in61.3%
distribute-rgt-neg-in61.3%
metadata-eval61.3%
Simplified61.3%
Taylor expanded in b around inf 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
Final simplification83.2%
(FPCore (a b c)
:precision binary64
(if (<= b -6.2e-82)
(/ (- c) b)
(if (<= b 5.2e-118)
(* -0.5 (/ (sqrt (* a (* c -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-82) {
tmp = -c / b;
} else if (b <= 5.2e-118) {
tmp = -0.5 * (sqrt((a * (c * -4.0))) / 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 <= (-6.2d-82)) then
tmp = -c / b
else if (b <= 5.2d-118) then
tmp = (-0.5d0) * (sqrt((a * (c * (-4.0d0)))) / 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 <= -6.2e-82) {
tmp = -c / b;
} else if (b <= 5.2e-118) {
tmp = -0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e-82: tmp = -c / b elif b <= 5.2e-118: tmp = -0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e-82) tmp = Float64(Float64(-c) / b); elseif (b <= 5.2e-118) tmp = Float64(-0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / 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 <= -6.2e-82) tmp = -c / b; elseif (b <= 5.2e-118) tmp = -0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e-82], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.2e-118], N[(-0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -6.2 \cdot 10^{-82}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-118}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.19999999999999999e-82Initial program 13.9%
sub-neg13.9%
distribute-neg-out13.9%
neg-mul-113.9%
times-frac13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
distribute-rgt-neg-in13.9%
distribute-rgt-neg-out13.9%
*-commutative13.9%
associate-*l*13.9%
fma-def13.9%
distribute-lft-neg-in13.9%
distribute-rgt-neg-in13.9%
metadata-eval13.9%
Simplified13.9%
Taylor expanded in b around -inf 90.3%
mul-1-neg90.3%
Simplified90.3%
if -6.19999999999999999e-82 < b < 5.2e-118Initial program 73.4%
sub-neg73.4%
distribute-neg-out73.4%
neg-mul-173.4%
times-frac73.4%
metadata-eval73.4%
sub-neg73.4%
+-commutative73.4%
distribute-rgt-neg-in73.4%
distribute-rgt-neg-out73.4%
*-commutative73.4%
associate-*l*73.4%
fma-def73.4%
distribute-lft-neg-in73.4%
distribute-rgt-neg-in73.4%
metadata-eval73.4%
Simplified73.4%
clear-num73.2%
un-div-inv73.2%
pow273.2%
Applied egg-rr73.2%
add-sqr-sqrt72.9%
pow272.9%
pow1/272.9%
sqrt-pow172.9%
metadata-eval72.9%
Applied egg-rr72.9%
Taylor expanded in c around -inf 42.2%
Taylor expanded in b around 0 42.0%
Simplified68.6%
if 5.2e-118 < b Initial program 64.0%
sub-neg64.0%
distribute-neg-out64.0%
neg-mul-164.0%
times-frac63.2%
metadata-eval63.2%
sub-neg63.2%
+-commutative63.2%
distribute-rgt-neg-in63.2%
distribute-rgt-neg-out63.2%
*-commutative63.2%
associate-*l*63.2%
fma-def63.2%
distribute-lft-neg-in63.2%
distribute-rgt-neg-in63.2%
metadata-eval63.2%
Simplified63.2%
Taylor expanded in b around inf 86.7%
+-commutative86.7%
mul-1-neg86.7%
unsub-neg86.7%
Simplified86.7%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.5%
sub-neg31.5%
distribute-neg-out31.5%
neg-mul-131.5%
times-frac31.5%
metadata-eval31.5%
sub-neg31.5%
+-commutative31.5%
distribute-rgt-neg-in31.5%
distribute-rgt-neg-out31.5%
*-commutative31.5%
associate-*l*31.5%
fma-def31.6%
distribute-lft-neg-in31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in b around -inf 67.5%
mul-1-neg67.5%
Simplified67.5%
if -4.999999999999985e-310 < b Initial program 67.6%
sub-neg67.6%
distribute-neg-out67.6%
neg-mul-167.6%
times-frac66.9%
metadata-eval66.9%
sub-neg66.9%
+-commutative66.9%
distribute-rgt-neg-in66.9%
distribute-rgt-neg-out66.9%
*-commutative66.9%
associate-*l*66.9%
fma-def66.9%
distribute-lft-neg-in66.9%
distribute-rgt-neg-in66.9%
metadata-eval66.9%
Simplified66.9%
Taylor expanded in b around inf 69.9%
+-commutative69.9%
mul-1-neg69.9%
unsub-neg69.9%
Simplified69.9%
Final simplification68.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.5%
sub-neg31.5%
distribute-neg-out31.5%
neg-mul-131.5%
times-frac31.5%
metadata-eval31.5%
sub-neg31.5%
+-commutative31.5%
distribute-rgt-neg-in31.5%
distribute-rgt-neg-out31.5%
*-commutative31.5%
associate-*l*31.5%
fma-def31.6%
distribute-lft-neg-in31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in b around -inf 67.5%
mul-1-neg67.5%
Simplified67.5%
if -4.999999999999985e-310 < b Initial program 67.6%
sub-neg67.6%
distribute-neg-out67.6%
neg-mul-167.6%
times-frac66.9%
metadata-eval66.9%
sub-neg66.9%
+-commutative66.9%
distribute-rgt-neg-in66.9%
distribute-rgt-neg-out66.9%
*-commutative66.9%
associate-*l*66.9%
fma-def66.9%
distribute-lft-neg-in66.9%
distribute-rgt-neg-in66.9%
metadata-eval66.9%
Simplified66.9%
Taylor expanded in b around inf 69.3%
associate-*r/69.3%
mul-1-neg69.3%
Simplified69.3%
Final simplification68.4%
(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 48.8%
sub-neg48.8%
distribute-neg-out48.8%
neg-mul-148.8%
times-frac48.5%
metadata-eval48.5%
sub-neg48.5%
+-commutative48.5%
distribute-rgt-neg-in48.5%
distribute-rgt-neg-out48.5%
*-commutative48.5%
associate-*l*48.5%
fma-def48.5%
distribute-lft-neg-in48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
Simplified48.5%
Taylor expanded in b around -inf 36.4%
mul-1-neg36.4%
Simplified36.4%
Final simplification36.4%
(FPCore (a b c) :precision binary64 -0.5)
double code(double a, double b, double c) {
return -0.5;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -0.5d0
end function
public static double code(double a, double b, double c) {
return -0.5;
}
def code(a, b, c): return -0.5
function code(a, b, c) return -0.5 end
function tmp = code(a, b, c) tmp = -0.5; end
code[a_, b_, c_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 48.8%
sub-neg48.8%
distribute-neg-out48.8%
neg-mul-148.8%
times-frac48.5%
metadata-eval48.5%
sub-neg48.5%
+-commutative48.5%
distribute-rgt-neg-in48.5%
distribute-rgt-neg-out48.5%
*-commutative48.5%
associate-*l*48.5%
fma-def48.5%
distribute-lft-neg-in48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
Simplified48.5%
clear-num48.4%
un-div-inv48.7%
pow248.7%
Applied egg-rr48.7%
Taylor expanded in a around 0 34.6%
div-inv34.2%
clear-num34.4%
Applied egg-rr0.0%
Simplified3.6%
Final simplification3.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 48.8%
sub-neg48.8%
distribute-neg-out48.8%
neg-mul-148.8%
times-frac48.5%
metadata-eval48.5%
sub-neg48.5%
+-commutative48.5%
distribute-rgt-neg-in48.5%
distribute-rgt-neg-out48.5%
*-commutative48.5%
associate-*l*48.5%
fma-def48.5%
distribute-lft-neg-in48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
Simplified48.5%
clear-num48.4%
un-div-inv48.7%
pow248.7%
Applied egg-rr48.7%
Taylor expanded in a around 0 34.6%
expm1-log1p-u19.8%
expm1-udef16.4%
associate-/r/16.4%
flip-+0.0%
frac-times0.0%
unpow20.0%
unpow20.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified11.8%
Final simplification11.8%
(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 2023326
(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)))