
(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 -1.8e-80)
(/ c (- b))
(if (<= b 2.75e+47)
(/ (+ 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-80) {
tmp = c / -b;
} else if (b <= 2.75e+47) {
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-80)) then
tmp = c / -b
else if (b <= 2.75d+47) 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-80) {
tmp = c / -b;
} else if (b <= 2.75e+47) {
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-80: tmp = c / -b elif b <= 2.75e+47: 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-80) tmp = Float64(c / Float64(-b)); elseif (b <= 2.75e+47) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / 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 <= -1.8e-80) tmp = c / -b; elseif (b <= 2.75e+47) 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-80], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.75e+47], 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^{-80}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.75 \cdot 10^{+47}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.8e-80Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.6%
distribute-neg-frac12.6%
neg-mul-112.6%
*-commutative12.6%
associate-/l*14.7%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.0%
Taylor expanded in b around -inf 89.6%
mul-1-neg89.6%
distribute-neg-frac289.6%
Simplified89.6%
if -1.8e-80 < b < 2.7499999999999999e47Initial program 83.3%
if 2.7499999999999999e47 < b Initial program 59.3%
div-sub59.3%
sub-neg59.3%
neg-mul-159.3%
*-commutative59.3%
associate-/l*59.3%
distribute-neg-frac59.3%
neg-mul-159.3%
*-commutative59.3%
associate-/l*59.1%
distribute-rgt-out59.1%
associate-/r*59.1%
metadata-eval59.1%
sub-neg59.1%
+-commutative59.1%
Simplified59.1%
Taylor expanded in c around 0 96.6%
+-commutative96.6%
mul-1-neg96.6%
unsub-neg96.6%
Simplified96.6%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.62e-80)
(/ c (- b))
(if (<= b 2.7e-90)
(/ (- (- 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.62e-80) {
tmp = c / -b;
} else if (b <= 2.7e-90) {
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.62d-80)) then
tmp = c / -b
else if (b <= 2.7d-90) 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.62e-80) {
tmp = c / -b;
} else if (b <= 2.7e-90) {
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.62e-80: tmp = c / -b elif b <= 2.7e-90: 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.62e-80) tmp = Float64(c / Float64(-b)); elseif (b <= 2.7e-90) 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.62e-80) tmp = c / -b; elseif (b <= 2.7e-90) 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.62e-80], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.7e-90], 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.62 \cdot 10^{-80}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-90}:\\
\;\;\;\;\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.62e-80Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.6%
distribute-neg-frac12.6%
neg-mul-112.6%
*-commutative12.6%
associate-/l*14.7%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.0%
Taylor expanded in b around -inf 89.6%
mul-1-neg89.6%
distribute-neg-frac289.6%
Simplified89.6%
if -1.62e-80 < b < 2.69999999999999996e-90Initial program 78.1%
*-commutative78.1%
*-commutative78.1%
sqr-neg78.1%
*-commutative78.1%
sqr-neg78.1%
*-commutative78.1%
associate-*r*78.1%
Simplified78.1%
add-cube-cbrt77.3%
pow377.2%
*-commutative77.2%
associate-*l*77.2%
Applied egg-rr77.2%
Taylor expanded in c around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt74.7%
mul-1-neg74.7%
rem-cube-cbrt75.3%
Simplified75.3%
remove-double-neg75.3%
*-un-lft-identity75.3%
Applied egg-rr75.3%
*-lft-identity75.3%
Simplified75.3%
if 2.69999999999999996e-90 < b Initial program 71.6%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.5%
distribute-neg-frac71.5%
neg-mul-171.5%
*-commutative71.5%
associate-/l*71.4%
distribute-rgt-out71.4%
associate-/r*71.4%
metadata-eval71.4%
sub-neg71.4%
+-commutative71.4%
Simplified71.4%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -8.6e-82)
(/ c (- b))
(if (<= b 1.4e-93)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-82) {
tmp = c / -b;
} else if (b <= 1.4e-93) {
tmp = (-0.5 / a) * (b + sqrt(((c * a) * -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 <= (-8.6d-82)) then
tmp = c / -b
else if (b <= 1.4d-93) then
tmp = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-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 <= -8.6e-82) {
tmp = c / -b;
} else if (b <= 1.4e-93) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.6e-82: tmp = c / -b elif b <= 1.4e-93: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.6e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 1.4e-93) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -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 <= -8.6e-82) tmp = c / -b; elseif (b <= 1.4e-93) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.6e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.4e-93], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.6 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-93}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.60000000000000037e-82Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.6%
distribute-neg-frac12.6%
neg-mul-112.6%
*-commutative12.6%
associate-/l*14.7%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.0%
Taylor expanded in b around -inf 89.6%
mul-1-neg89.6%
distribute-neg-frac289.6%
Simplified89.6%
if -8.60000000000000037e-82 < b < 1.39999999999999999e-93Initial program 78.1%
div-sub78.0%
sub-neg78.0%
neg-mul-178.0%
*-commutative78.0%
associate-/l*78.1%
distribute-neg-frac78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*78.0%
distribute-rgt-out78.0%
associate-/r*78.0%
metadata-eval78.0%
sub-neg78.0%
+-commutative78.0%
Simplified78.0%
Taylor expanded in a around inf 75.2%
*-commutative75.2%
Simplified75.2%
if 1.39999999999999999e-93 < b Initial program 71.6%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.5%
distribute-neg-frac71.5%
neg-mul-171.5%
*-commutative71.5%
associate-/l*71.4%
distribute-rgt-out71.4%
associate-/r*71.4%
metadata-eval71.4%
sub-neg71.4%
+-commutative71.4%
Simplified71.4%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification85.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-82)
(/ c (- b))
(if (<= b 1.02e-92)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-82) {
tmp = c / -b;
} else if (b <= 1.02e-92) {
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 <= (-2.1d-82)) then
tmp = c / -b
else if (b <= 1.02d-92) 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 <= -2.1e-82) {
tmp = c / -b;
} else if (b <= 1.02e-92) {
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 <= -2.1e-82: tmp = c / -b elif b <= 1.02e-92: 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 <= -2.1e-82) tmp = Float64(c / Float64(-b)); elseif (b <= 1.02e-92) 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 <= -2.1e-82) tmp = c / -b; elseif (b <= 1.02e-92) 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, -2.1e-82], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.02e-92], 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 -2.1 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-92}:\\
\;\;\;\;\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 < -2.1e-82Initial program 15.1%
div-sub14.7%
sub-neg14.7%
neg-mul-114.7%
*-commutative14.7%
associate-/l*12.6%
distribute-neg-frac12.6%
neg-mul-112.6%
*-commutative12.6%
associate-/l*14.7%
distribute-rgt-out15.0%
associate-/r*15.0%
metadata-eval15.0%
sub-neg15.0%
+-commutative15.0%
Simplified15.0%
Taylor expanded in b around -inf 89.6%
mul-1-neg89.6%
distribute-neg-frac289.6%
Simplified89.6%
if -2.1e-82 < b < 1.02000000000000005e-92Initial program 78.1%
*-commutative78.1%
*-commutative78.1%
sqr-neg78.1%
*-commutative78.1%
sqr-neg78.1%
*-commutative78.1%
associate-*r*78.1%
Simplified78.1%
add-cube-cbrt77.3%
pow377.2%
*-commutative77.2%
associate-*l*77.2%
Applied egg-rr77.2%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt73.3%
mul-1-neg73.3%
rem-cube-cbrt73.8%
Simplified73.8%
if 1.02000000000000005e-92 < b Initial program 71.6%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.5%
distribute-neg-frac71.5%
neg-mul-171.5%
*-commutative71.5%
associate-/l*71.4%
distribute-rgt-out71.4%
associate-/r*71.4%
metadata-eval71.4%
sub-neg71.4%
+-commutative71.4%
Simplified71.4%
Taylor expanded in c around 0 87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -8.6e-153)
(/ c (- b))
(if (<= b 4.8e-108)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.6e-153) {
tmp = c / -b;
} else if (b <= 4.8e-108) {
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 <= (-8.6d-153)) then
tmp = c / -b
else if (b <= 4.8d-108) 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 <= -8.6e-153) {
tmp = c / -b;
} else if (b <= 4.8e-108) {
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 <= -8.6e-153: tmp = c / -b elif b <= 4.8e-108: 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 <= -8.6e-153) tmp = Float64(c / Float64(-b)); elseif (b <= 4.8e-108) 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 <= -8.6e-153) tmp = c / -b; elseif (b <= 4.8e-108) 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, -8.6e-153], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.8e-108], 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 -8.6 \cdot 10^{-153}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-108}:\\
\;\;\;\;\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 < -8.6000000000000001e-153Initial program 22.7%
div-sub22.3%
sub-neg22.3%
neg-mul-122.3%
*-commutative22.3%
associate-/l*20.5%
distribute-neg-frac20.5%
neg-mul-120.5%
*-commutative20.5%
associate-/l*22.3%
distribute-rgt-out22.7%
associate-/r*22.7%
metadata-eval22.7%
sub-neg22.7%
+-commutative22.7%
Simplified22.7%
Taylor expanded in b around -inf 81.1%
mul-1-neg81.1%
distribute-neg-frac281.1%
Simplified81.1%
if -8.6000000000000001e-153 < b < 4.80000000000000034e-108Initial program 80.2%
*-commutative80.2%
*-commutative80.2%
sqr-neg80.2%
*-commutative80.2%
sqr-neg80.2%
*-commutative80.2%
associate-*r*80.2%
Simplified80.2%
add-cube-cbrt79.3%
pow379.4%
*-commutative79.4%
associate-*l*79.4%
Applied egg-rr79.4%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt29.4%
neg-mul-129.4%
rem-cube-cbrt29.7%
associate-/l*29.6%
Simplified29.6%
if 4.80000000000000034e-108 < b Initial program 71.2%
div-sub71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.1%
distribute-neg-frac71.1%
neg-mul-171.1%
*-commutative71.1%
associate-/l*70.9%
distribute-rgt-out70.9%
associate-/r*70.9%
metadata-eval70.9%
sub-neg70.9%
+-commutative70.9%
Simplified70.9%
Taylor expanded in c around 0 85.9%
+-commutative85.9%
mul-1-neg85.9%
unsub-neg85.9%
Simplified85.9%
Final simplification71.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-311) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-311) {
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 <= (-2d-311)) 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 <= -2e-311) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-311: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-311) 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 <= -2e-311) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-311], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.9999999999999e-311Initial program 30.6%
div-sub30.3%
sub-neg30.3%
neg-mul-130.3%
*-commutative30.3%
associate-/l*28.8%
distribute-neg-frac28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*30.3%
distribute-rgt-out30.6%
associate-/r*30.6%
metadata-eval30.6%
sub-neg30.6%
+-commutative30.6%
Simplified30.6%
Taylor expanded in b around -inf 68.9%
mul-1-neg68.9%
distribute-neg-frac268.9%
Simplified68.9%
if -1.9999999999999e-311 < b Initial program 75.5%
div-sub75.5%
sub-neg75.5%
neg-mul-175.5%
*-commutative75.5%
associate-/l*75.4%
distribute-neg-frac75.4%
neg-mul-175.4%
*-commutative75.4%
associate-/l*75.2%
distribute-rgt-out75.2%
associate-/r*75.2%
metadata-eval75.2%
sub-neg75.2%
+-commutative75.2%
Simplified75.2%
Taylor expanded in c around 0 66.0%
+-commutative66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
(FPCore (a b c) :precision binary64 (if (<= b -2.1e-270) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-270) {
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 <= (-2.1d-270)) 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 <= -2.1e-270) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-270: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-270) 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 <= -2.1e-270) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-270], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-270}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -2.09999999999999996e-270Initial program 30.0%
div-sub29.7%
sub-neg29.7%
neg-mul-129.7%
*-commutative29.7%
associate-/l*28.1%
distribute-neg-frac28.1%
neg-mul-128.1%
*-commutative28.1%
associate-/l*29.7%
distribute-rgt-out29.9%
associate-/r*29.9%
metadata-eval29.9%
sub-neg29.9%
+-commutative29.9%
Simplified29.9%
Taylor expanded in b around -inf 70.8%
mul-1-neg70.8%
distribute-neg-frac270.8%
Simplified70.8%
if -2.09999999999999996e-270 < b Initial program 74.7%
div-sub74.7%
sub-neg74.7%
neg-mul-174.7%
*-commutative74.7%
associate-/l*74.6%
distribute-neg-frac74.6%
neg-mul-174.6%
*-commutative74.6%
associate-/l*74.4%
distribute-rgt-out74.4%
associate-/r*74.4%
metadata-eval74.4%
sub-neg74.4%
+-commutative74.4%
Simplified74.4%
Taylor expanded in a around 0 63.9%
associate-*r/63.9%
mul-1-neg63.9%
Simplified63.9%
Final simplification67.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(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 51.1%
div-sub51.0%
sub-neg51.0%
neg-mul-151.0%
*-commutative51.0%
associate-/l*50.1%
distribute-neg-frac50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*50.8%
distribute-rgt-out51.0%
associate-/r*51.0%
metadata-eval51.0%
sub-neg51.0%
+-commutative51.0%
Simplified51.0%
Taylor expanded in b around -inf 38.3%
mul-1-neg38.3%
distribute-neg-frac238.3%
Simplified38.3%
(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 51.1%
div-sub51.0%
sub-neg51.0%
neg-mul-151.0%
*-commutative51.0%
associate-/l*50.1%
distribute-neg-frac50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*50.8%
distribute-rgt-out51.0%
associate-/r*51.0%
metadata-eval51.0%
sub-neg51.0%
+-commutative51.0%
Simplified51.0%
Taylor expanded in b around -inf 11.7%
mul-1-neg11.7%
Simplified11.7%
Taylor expanded in a around 0 11.7%
(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 2024132
(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)))