
(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 -4.5e-71)
(/ c (- b))
(if (<= b 3e+84)
(/ (- (- 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 <= -4.5e-71) {
tmp = c / -b;
} else if (b <= 3e+84) {
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 <= (-4.5d-71)) then
tmp = c / -b
else if (b <= 3d+84) 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 <= -4.5e-71) {
tmp = c / -b;
} else if (b <= 3e+84) {
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 <= -4.5e-71: tmp = c / -b elif b <= 3e+84: 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 <= -4.5e-71) tmp = Float64(c / Float64(-b)); elseif (b <= 3e+84) 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 <= -4.5e-71) tmp = c / -b; elseif (b <= 3e+84) 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, -4.5e-71], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3e+84], 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 -4.5 \cdot 10^{-71}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{+84}:\\
\;\;\;\;\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 < -4.5000000000000002e-71Initial program 14.1%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*12.3%
distribute-neg-frac12.3%
neg-mul-112.3%
*-commutative12.3%
associate-/l*13.7%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified14.1%
Taylor expanded in b around -inf 83.4%
mul-1-neg83.4%
distribute-neg-frac283.4%
Simplified83.4%
if -4.5000000000000002e-71 < b < 2.99999999999999996e84Initial program 84.6%
if 2.99999999999999996e84 < b Initial program 61.6%
div-sub61.6%
sub-neg61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.6%
distribute-neg-frac61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.6%
distribute-rgt-out61.6%
associate-/r*61.6%
metadata-eval61.6%
sub-neg61.6%
+-commutative61.6%
Simplified61.6%
Taylor expanded in a around 0 92.2%
associate-*r/92.2%
mul-1-neg92.2%
Simplified92.2%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-65)
(/ c (- b))
(if (<= b 2.2e-13)
(/ (- (- b) (sqrt (* (* c a) -4.0))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-65) {
tmp = c / -b;
} else if (b <= 2.2e-13) {
tmp = (-b - sqrt(((c * a) * -4.0))) / (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 <= (-1.15d-65)) then
tmp = c / -b
else if (b <= 2.2d-13) then
tmp = (-b - sqrt(((c * a) * (-4.0d0)))) / (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 <= -1.15e-65) {
tmp = c / -b;
} else if (b <= 2.2e-13) {
tmp = (-b - Math.sqrt(((c * a) * -4.0))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.15e-65: tmp = c / -b elif b <= 2.2e-13: tmp = (-b - math.sqrt(((c * a) * -4.0))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-65) tmp = Float64(c / Float64(-b)); elseif (b <= 2.2e-13) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(c * a) * -4.0))) / 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 <= -1.15e-65) tmp = c / -b; elseif (b <= 2.2e-13) tmp = (-b - sqrt(((c * a) * -4.0))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-65], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.2e-13], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-65}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-13}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.15e-65Initial program 14.1%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*12.3%
distribute-neg-frac12.3%
neg-mul-112.3%
*-commutative12.3%
associate-/l*13.7%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified14.1%
Taylor expanded in b around -inf 83.4%
mul-1-neg83.4%
distribute-neg-frac283.4%
Simplified83.4%
if -1.15e-65 < b < 2.19999999999999997e-13Initial program 81.2%
*-commutative81.2%
sqr-neg81.2%
*-commutative81.2%
sqr-neg81.2%
*-commutative81.2%
associate-*r*81.2%
*-commutative81.2%
Simplified81.2%
Taylor expanded in b around 0 74.3%
*-commutative74.3%
Simplified74.3%
if 2.19999999999999997e-13 < b Initial program 69.0%
div-sub69.0%
sub-neg69.0%
neg-mul-169.0%
*-commutative69.0%
associate-/l*68.9%
distribute-neg-frac68.9%
neg-mul-168.9%
*-commutative68.9%
associate-/l*68.8%
distribute-rgt-out68.8%
associate-/r*68.8%
metadata-eval68.8%
sub-neg68.8%
+-commutative68.8%
Simplified68.8%
Taylor expanded in a around 0 90.6%
associate-*r/90.6%
mul-1-neg90.6%
Simplified90.6%
Final simplification83.1%
(FPCore (a b c) :precision binary64 (if (<= b -1.75e-68) (/ c (- b)) (if (<= b 3.4e-55) (/ (sqrt (* a (* c -4.0))) (* a (- 2.0))) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-68) {
tmp = c / -b;
} else if (b <= 3.4e-55) {
tmp = sqrt((a * (c * -4.0))) / (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 <= (-1.75d-68)) then
tmp = c / -b
else if (b <= 3.4d-55) then
tmp = sqrt((a * (c * (-4.0d0)))) / (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 <= -1.75e-68) {
tmp = c / -b;
} else if (b <= 3.4e-55) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * -2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-68: tmp = c / -b elif b <= 3.4e-55: tmp = math.sqrt((a * (c * -4.0))) / (a * -2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-68) tmp = Float64(c / Float64(-b)); elseif (b <= 3.4e-55) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-2.0))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-68) tmp = c / -b; elseif (b <= 3.4e-55) tmp = sqrt((a * (c * -4.0))) / (a * -2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-68], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.4e-55], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * (-2.0)), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-68}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-55}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.75000000000000006e-68Initial program 14.1%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*12.3%
distribute-neg-frac12.3%
neg-mul-112.3%
*-commutative12.3%
associate-/l*13.7%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified14.1%
Taylor expanded in b around -inf 83.4%
mul-1-neg83.4%
distribute-neg-frac283.4%
Simplified83.4%
if -1.75000000000000006e-68 < b < 3.39999999999999973e-55Initial program 81.3%
*-commutative81.3%
sqr-neg81.3%
*-commutative81.3%
sqr-neg81.3%
*-commutative81.3%
associate-*r*81.3%
*-commutative81.3%
Simplified81.3%
add-cube-cbrt80.5%
pow380.6%
*-commutative80.6%
associate-*l*80.6%
Applied egg-rr80.6%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt74.6%
mul-1-neg74.6%
rem-cube-cbrt74.8%
Simplified74.8%
if 3.39999999999999973e-55 < b Initial program 69.6%
div-sub69.6%
sub-neg69.6%
neg-mul-169.6%
*-commutative69.6%
associate-/l*69.6%
distribute-neg-frac69.6%
neg-mul-169.6%
*-commutative69.6%
associate-/l*69.4%
distribute-rgt-out69.4%
associate-/r*69.4%
metadata-eval69.4%
sub-neg69.4%
+-commutative69.4%
Simplified69.4%
Taylor expanded in a around 0 88.1%
associate-*r/88.1%
mul-1-neg88.1%
Simplified88.1%
Final simplification82.7%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e-82)
(/ c (- b))
(if (<= b 2.4e-102)
(* 0.5 (- (sqrt (* c (/ -4.0 a)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-82) {
tmp = c / -b;
} else if (b <= 2.4e-102) {
tmp = 0.5 * -sqrt((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 <= (-2.8d-82)) then
tmp = c / -b
else if (b <= 2.4d-102) then
tmp = 0.5d0 * -sqrt((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 <= -2.8e-82) {
tmp = c / -b;
} else if (b <= 2.4e-102) {
tmp = 0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e-82: tmp = c / -b elif b <= 2.4e-102: tmp = 0.5 * -math.sqrt((c * (-4.0 / a))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 2.4e-102) tmp = Float64(0.5 * Float64(-sqrt(Float64(c * Float64(-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 <= -2.8e-82) tmp = c / -b; elseif (b <= 2.4e-102) tmp = 0.5 * -sqrt((c * (-4.0 / a))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.4e-102], N[(0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $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.8 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-102}:\\
\;\;\;\;0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.80000000000000024e-82Initial program 15.0%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*13.3%
distribute-neg-frac13.3%
neg-mul-113.3%
*-commutative13.3%
associate-/l*14.6%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.1%
Taylor expanded in b around -inf 82.6%
mul-1-neg82.6%
distribute-neg-frac282.6%
Simplified82.6%
if -2.80000000000000024e-82 < b < 2.4e-102Initial program 82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
sqr-neg82.0%
*-commutative82.0%
associate-*r*82.0%
*-commutative82.0%
Simplified82.0%
add-cube-cbrt81.2%
pow381.3%
*-commutative81.3%
associate-*l*81.3%
Applied egg-rr81.3%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt35.4%
neg-mul-135.4%
associate-/l*35.3%
rem-cube-cbrt35.6%
Simplified35.6%
if 2.4e-102 < b Initial program 69.7%
div-sub69.7%
sub-neg69.7%
neg-mul-169.7%
*-commutative69.7%
associate-/l*69.7%
distribute-neg-frac69.7%
neg-mul-169.7%
*-commutative69.7%
associate-/l*69.6%
distribute-rgt-out69.6%
associate-/r*69.6%
metadata-eval69.6%
sub-neg69.6%
+-commutative69.6%
Simplified69.6%
Taylor expanded in c around 0 83.3%
+-commutative83.3%
mul-1-neg83.3%
unsub-neg83.3%
Simplified83.3%
(FPCore (a b c) :precision binary64 (if (<= b -3.4e-249) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-249) {
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 <= (-3.4d-249)) 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 <= -3.4e-249) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.4e-249: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.4e-249) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.4e-249) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.4e-249], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.4 \cdot 10^{-249}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.3999999999999998e-249Initial program 26.3%
div-sub26.0%
sub-neg26.0%
neg-mul-126.0%
*-commutative26.0%
associate-/l*24.9%
distribute-neg-frac24.9%
neg-mul-124.9%
*-commutative24.9%
associate-/l*25.9%
distribute-rgt-out26.3%
associate-/r*26.3%
metadata-eval26.3%
sub-neg26.3%
+-commutative26.3%
Simplified26.3%
Taylor expanded in b around -inf 68.6%
mul-1-neg68.6%
distribute-neg-frac268.6%
Simplified68.6%
if -3.3999999999999998e-249 < b Initial program 75.2%
div-sub75.2%
sub-neg75.2%
neg-mul-175.2%
*-commutative75.2%
associate-/l*75.2%
distribute-neg-frac75.2%
neg-mul-175.2%
*-commutative75.2%
associate-/l*75.1%
distribute-rgt-out75.1%
associate-/r*75.1%
metadata-eval75.1%
sub-neg75.1%
+-commutative75.1%
Simplified75.1%
Taylor expanded in a around 0 62.9%
associate-*r/62.9%
mul-1-neg62.9%
Simplified62.9%
(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 / Float64(-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 53.6%
div-sub53.5%
sub-neg53.5%
neg-mul-153.5%
*-commutative53.5%
associate-/l*53.0%
distribute-neg-frac53.0%
neg-mul-153.0%
*-commutative53.0%
associate-/l*53.4%
distribute-rgt-out53.5%
associate-/r*53.5%
metadata-eval53.5%
sub-neg53.5%
+-commutative53.5%
Simplified53.5%
Taylor expanded in b around -inf 31.4%
mul-1-neg31.4%
distribute-neg-frac231.4%
Simplified31.4%
(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 53.6%
div-sub53.5%
sub-neg53.5%
neg-mul-153.5%
*-commutative53.5%
associate-/l*53.0%
distribute-neg-frac53.0%
neg-mul-153.0%
*-commutative53.0%
associate-/l*53.4%
distribute-rgt-out53.5%
associate-/r*53.5%
metadata-eval53.5%
sub-neg53.5%
+-commutative53.5%
Simplified53.5%
Taylor expanded in b around -inf 10.2%
mul-1-neg10.2%
Simplified10.2%
Taylor expanded in a around 0 10.2%
(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 2024163
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))