
(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 -8.5e-58)
(/ c (- b))
(if (<= b 5e+136)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-58) {
tmp = c / -b;
} else if (b <= 5e+136) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * 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.5d-58)) then
tmp = c / -b
else if (b <= 5d+136) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * 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.5e-58) {
tmp = c / -b;
} else if (b <= 5e+136) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-58: tmp = c / -b elif b <= 5e+136: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-58) tmp = Float64(c / Float64(-b)); elseif (b <= 5e+136) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e-58) tmp = c / -b; elseif (b <= 5e+136) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-58], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5e+136], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $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.5 \cdot 10^{-58}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+136}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -8.5000000000000004e-58Initial program 15.2%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*12.5%
distribute-neg-frac12.5%
neg-mul-112.5%
*-commutative12.5%
associate-/l*13.7%
distribute-rgt-out15.2%
associate-/r*15.2%
metadata-eval15.2%
sub-neg15.2%
+-commutative15.2%
Simplified15.2%
Taylor expanded in b around -inf 89.2%
mul-1-neg89.2%
distribute-neg-frac289.2%
Simplified89.2%
if -8.5000000000000004e-58 < b < 5.0000000000000002e136Initial program 78.3%
*-commutative78.3%
sqr-neg78.3%
*-commutative78.3%
sqr-neg78.3%
*-commutative78.3%
associate-*r*78.4%
*-commutative78.4%
Simplified78.4%
if 5.0000000000000002e136 < b Initial program 58.2%
div-sub58.2%
sub-neg58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*58.2%
distribute-neg-frac58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*58.2%
distribute-rgt-out58.2%
associate-/r*58.2%
metadata-eval58.2%
sub-neg58.2%
+-commutative58.2%
Simplified58.2%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -6.2e-59)
(/ c (- b))
(if (<= b 3.2e+139)
(/ (- (- 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 <= -6.2e-59) {
tmp = c / -b;
} else if (b <= 3.2e+139) {
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 <= (-6.2d-59)) then
tmp = c / -b
else if (b <= 3.2d+139) 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 <= -6.2e-59) {
tmp = c / -b;
} else if (b <= 3.2e+139) {
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 <= -6.2e-59: tmp = c / -b elif b <= 3.2e+139: 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 <= -6.2e-59) tmp = Float64(c / Float64(-b)); elseif (b <= 3.2e+139) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.2e-59) tmp = c / -b; elseif (b <= 3.2e+139) 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, -6.2e-59], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.2e+139], 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 -6.2 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{+139}:\\
\;\;\;\;\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 < -6.19999999999999998e-59Initial program 15.2%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*12.5%
distribute-neg-frac12.5%
neg-mul-112.5%
*-commutative12.5%
associate-/l*13.7%
distribute-rgt-out15.2%
associate-/r*15.2%
metadata-eval15.2%
sub-neg15.2%
+-commutative15.2%
Simplified15.2%
Taylor expanded in b around -inf 89.2%
mul-1-neg89.2%
distribute-neg-frac289.2%
Simplified89.2%
if -6.19999999999999998e-59 < b < 3.2000000000000001e139Initial program 78.3%
if 3.2000000000000001e139 < b Initial program 58.2%
div-sub58.2%
sub-neg58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*58.2%
distribute-neg-frac58.2%
neg-mul-158.2%
*-commutative58.2%
associate-/l*58.2%
distribute-rgt-out58.2%
associate-/r*58.2%
metadata-eval58.2%
sub-neg58.2%
+-commutative58.2%
Simplified58.2%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-116)
(/ c (- b))
(if (<= b 2.5e-10)
(/ (+ b (sqrt (* c (* a -4.0)))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-116) {
tmp = c / -b;
} else if (b <= 2.5e-10) {
tmp = (b + sqrt((c * (a * -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 <= (-5.8d-116)) then
tmp = c / -b
else if (b <= 2.5d-10) then
tmp = (b + sqrt((c * (a * (-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 <= -5.8e-116) {
tmp = c / -b;
} else if (b <= 2.5e-10) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-116: tmp = c / -b elif b <= 2.5e-10: tmp = (b + math.sqrt((c * (a * -4.0)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-116) tmp = Float64(c / Float64(-b)); elseif (b <= 2.5e-10) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * Float64(-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 <= -5.8e-116) tmp = c / -b; elseif (b <= 2.5e-10) tmp = (b + sqrt((c * (a * -4.0)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-116], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.5e-10], N[(N[(b + N[Sqrt[N[(c * N[(a * -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 -5.8 \cdot 10^{-116}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-10}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.7999999999999996e-116Initial program 18.8%
div-sub17.4%
sub-neg17.4%
neg-mul-117.4%
*-commutative17.4%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*17.4%
distribute-rgt-out18.8%
associate-/r*18.8%
metadata-eval18.8%
sub-neg18.8%
+-commutative18.8%
Simplified18.8%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
distribute-neg-frac286.0%
Simplified86.0%
if -5.7999999999999996e-116 < b < 2.50000000000000016e-10Initial program 74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
associate-*r*74.2%
*-commutative74.2%
Simplified74.2%
Taylor expanded in b around 0 68.4%
metadata-eval68.4%
distribute-lft-neg-in68.4%
associate-*r*68.5%
*-commutative68.5%
distribute-rgt-neg-in68.5%
distribute-lft-neg-in68.5%
metadata-eval68.5%
*-commutative68.5%
Simplified68.5%
if 2.50000000000000016e-10 < b Initial program 73.4%
div-sub73.4%
sub-neg73.4%
neg-mul-173.4%
*-commutative73.4%
associate-/l*73.4%
distribute-neg-frac73.4%
neg-mul-173.4%
*-commutative73.4%
associate-/l*73.3%
distribute-rgt-out73.4%
associate-/r*73.4%
metadata-eval73.4%
sub-neg73.4%
+-commutative73.4%
Simplified73.4%
Taylor expanded in c around 0 93.0%
+-commutative93.0%
mul-1-neg93.0%
unsub-neg93.0%
Simplified93.0%
Final simplification83.6%
(FPCore (a b c)
:precision binary64
(if (<= b -4.2e-117)
(/ c (- b))
(if (<= b 5.2e-27)
(/ (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.2e-117) {
tmp = c / -b;
} else if (b <= 5.2e-27) {
tmp = 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.2d-117)) then
tmp = c / -b
else if (b <= 5.2d-27) then
tmp = 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.2e-117) {
tmp = c / -b;
} else if (b <= 5.2e-27) {
tmp = 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.2e-117: tmp = c / -b elif b <= 5.2e-27: tmp = 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.2e-117) tmp = Float64(c / Float64(-b)); elseif (b <= 5.2e-27) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-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.2e-117) tmp = c / -b; elseif (b <= 5.2e-27) tmp = 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.2e-117], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.2e-27], N[(N[Sqrt[N[(a * N[(c * -4.0), $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.2 \cdot 10^{-117}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-27}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.1999999999999998e-117Initial program 18.8%
div-sub17.4%
sub-neg17.4%
neg-mul-117.4%
*-commutative17.4%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*17.4%
distribute-rgt-out18.8%
associate-/r*18.8%
metadata-eval18.8%
sub-neg18.8%
+-commutative18.8%
Simplified18.8%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
distribute-neg-frac286.0%
Simplified86.0%
if -4.1999999999999998e-117 < b < 5.20000000000000034e-27Initial program 73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
associate-*r*73.4%
*-commutative73.4%
Simplified73.4%
add-cube-cbrt72.9%
pow372.9%
*-commutative72.9%
associate-*l*72.9%
Applied egg-rr72.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt67.8%
mul-1-neg67.8%
rem-cube-cbrt68.2%
Simplified68.2%
if 5.20000000000000034e-27 < b Initial program 74.1%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-neg-frac74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.0%
Taylor expanded in c around 0 92.0%
+-commutative92.0%
mul-1-neg92.0%
unsub-neg92.0%
Simplified92.0%
Final simplification83.3%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-118)
(/ c (- b))
(if (<= b 2.4e-33)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-118) {
tmp = c / -b;
} else if (b <= 2.4e-33) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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 <= (-3d-118)) then
tmp = c / -b
else if (b <= 2.4d-33) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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 <= -3e-118) {
tmp = c / -b;
} else if (b <= 2.4e-33) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-118: tmp = c / -b elif b <= 2.4e-33: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-118) tmp = Float64(c / Float64(-b)); elseif (b <= 2.4e-33) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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 <= -3e-118) tmp = c / -b; elseif (b <= 2.4e-33) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-118], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.4e-33], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-118}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-33}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.00000000000000018e-118Initial program 18.8%
div-sub17.4%
sub-neg17.4%
neg-mul-117.4%
*-commutative17.4%
associate-/l*16.3%
distribute-neg-frac16.3%
neg-mul-116.3%
*-commutative16.3%
associate-/l*17.4%
distribute-rgt-out18.8%
associate-/r*18.8%
metadata-eval18.8%
sub-neg18.8%
+-commutative18.8%
Simplified18.8%
Taylor expanded in b around -inf 86.0%
mul-1-neg86.0%
distribute-neg-frac286.0%
Simplified86.0%
if -3.00000000000000018e-118 < b < 2.4e-33Initial program 73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
associate-*r*73.4%
*-commutative73.4%
Simplified73.4%
add-cube-cbrt72.9%
pow372.9%
*-commutative72.9%
associate-*l*72.9%
Applied egg-rr72.9%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt35.9%
neg-mul-135.9%
rem-cube-cbrt36.3%
associate-/l*36.3%
Simplified36.3%
if 2.4e-33 < b Initial program 74.1%
div-sub74.1%
sub-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-neg-frac74.0%
neg-mul-174.0%
*-commutative74.0%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.0%
Taylor expanded in c around 0 92.0%
+-commutative92.0%
mul-1-neg92.0%
unsub-neg92.0%
Simplified92.0%
Final simplification75.4%
(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(c / Float64(-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 26.5%
div-sub25.3%
sub-neg25.3%
neg-mul-125.3%
*-commutative25.3%
associate-/l*24.4%
distribute-neg-frac24.4%
neg-mul-124.4%
*-commutative24.4%
associate-/l*25.3%
distribute-rgt-out26.4%
associate-/r*26.4%
metadata-eval26.4%
sub-neg26.4%
+-commutative26.4%
Simplified26.4%
Taylor expanded in b around -inf 76.1%
mul-1-neg76.1%
distribute-neg-frac276.1%
Simplified76.1%
if -4.999999999999985e-310 < b Initial program 74.2%
div-sub74.2%
sub-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.2%
distribute-neg-frac74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.1%
distribute-rgt-out74.1%
associate-/r*74.1%
metadata-eval74.1%
sub-neg74.1%
+-commutative74.1%
Simplified74.1%
Taylor expanded in c around 0 64.2%
+-commutative64.2%
mul-1-neg64.2%
unsub-neg64.2%
Simplified64.2%
(FPCore (a b c) :precision binary64 (if (<= b -7.5e-300) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-300) {
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 <= (-7.5d-300)) 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 <= -7.5e-300) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-300: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-300) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.5e-300) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-300], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-300}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.49999999999999961e-300Initial program 25.9%
div-sub24.8%
sub-neg24.8%
neg-mul-124.8%
*-commutative24.8%
associate-/l*23.8%
distribute-neg-frac23.8%
neg-mul-123.8%
*-commutative23.8%
associate-/l*24.7%
distribute-rgt-out25.9%
associate-/r*25.9%
metadata-eval25.9%
sub-neg25.9%
+-commutative25.9%
Simplified25.9%
Taylor expanded in b around -inf 76.6%
mul-1-neg76.6%
distribute-neg-frac276.6%
Simplified76.6%
if -7.49999999999999961e-300 < b Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.4%
distribute-neg-frac74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.3%
distribute-rgt-out74.3%
associate-/r*74.3%
metadata-eval74.3%
sub-neg74.3%
+-commutative74.3%
Simplified74.3%
Taylor expanded in a around 0 63.6%
associate-*r/63.6%
mul-1-neg63.6%
Simplified63.6%
Final simplification70.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(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 49.0%
div-sub48.4%
sub-neg48.4%
neg-mul-148.4%
*-commutative48.4%
associate-/l*47.9%
distribute-neg-frac47.9%
neg-mul-147.9%
*-commutative47.9%
associate-/l*48.3%
distribute-rgt-out48.9%
associate-/r*48.9%
metadata-eval48.9%
sub-neg48.9%
+-commutative48.9%
Simplified49.0%
Taylor expanded in b around -inf 41.1%
mul-1-neg41.1%
distribute-neg-frac241.1%
Simplified41.1%
(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 49.0%
div-sub48.4%
sub-neg48.4%
neg-mul-148.4%
*-commutative48.4%
associate-/l*47.9%
distribute-neg-frac47.9%
neg-mul-147.9%
*-commutative47.9%
associate-/l*48.3%
distribute-rgt-out48.9%
associate-/r*48.9%
metadata-eval48.9%
sub-neg48.9%
+-commutative48.9%
Simplified49.0%
Taylor expanded in a around 0 31.1%
+-commutative31.1%
mul-1-neg31.1%
sub-neg31.1%
associate-/l*31.5%
Simplified31.5%
Taylor expanded in a around inf 14.8%
(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 49.0%
*-commutative49.0%
sqr-neg49.0%
*-commutative49.0%
sqr-neg49.0%
*-commutative49.0%
associate-*r*49.1%
*-commutative49.1%
Simplified49.1%
add-cube-cbrt48.9%
pow348.9%
*-commutative48.9%
associate-*l*48.9%
Applied egg-rr48.9%
clear-num48.8%
inv-pow48.8%
Applied egg-rr48.9%
unpow-148.9%
*-commutative48.9%
*-lft-identity48.9%
times-frac48.9%
metadata-eval48.9%
unpow248.9%
fmm-def48.9%
associate-*r*48.9%
distribute-rgt-neg-in48.9%
metadata-eval48.9%
associate-*r*48.9%
Simplified48.9%
Taylor expanded in b around -inf 40.8%
Taylor expanded in b around 0 2.4%
(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 2024186
(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)))