
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-82)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 26500.0)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-82) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 26500.0) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4.6d-82)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 26500.0d0) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-82) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 26500.0) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-82: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 26500.0: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-82) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 26500.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e-82) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 26500.0) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-82], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 26500.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -4.6 \cdot 10^{-82}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 26500:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.59999999999999994e-82Initial program 14.2%
div-sub12.7%
sub-neg12.7%
neg-mul-112.7%
*-commutative12.7%
associate-/l*10.6%
distribute-neg-frac10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*12.6%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
associate-*l/14.2%
clear-num14.2%
*-commutative14.2%
pow214.2%
Applied egg-rr14.2%
Taylor expanded in b around -inf 89.1%
associate-*r*89.1%
mul-1-neg89.1%
+-commutative89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
Taylor expanded in c around inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -4.59999999999999994e-82 < b < 26500Initial program 74.7%
if 26500 < b Initial program 54.9%
div-sub55.0%
sub-neg55.0%
neg-mul-155.0%
*-commutative55.0%
associate-/l*54.9%
distribute-neg-frac54.9%
neg-mul-154.9%
*-commutative54.9%
associate-/l*54.9%
distribute-rgt-out54.9%
associate-/r*54.9%
metadata-eval54.9%
sub-neg54.9%
+-commutative54.9%
Simplified55.0%
Taylor expanded in c around 0 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.1e-82)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 4.2e-25)
(* (/ -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 <= -4.1e-82) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.2e-25) {
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 <= (-4.1d-82)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 4.2d-25) 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 <= -4.1e-82) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 4.2e-25) {
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 <= -4.1e-82: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 4.2e-25: 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 <= -4.1e-82) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 4.2e-25) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(a * 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 <= -4.1e-82) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 4.2e-25) 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, -4.1e-82], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e-25], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(a * c), $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 -4.1 \cdot 10^{-82}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-25}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(a \cdot c\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.09999999999999996e-82Initial program 14.2%
div-sub12.7%
sub-neg12.7%
neg-mul-112.7%
*-commutative12.7%
associate-/l*10.6%
distribute-neg-frac10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*12.6%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
associate-*l/14.2%
clear-num14.2%
*-commutative14.2%
pow214.2%
Applied egg-rr14.2%
Taylor expanded in b around -inf 89.1%
associate-*r*89.1%
mul-1-neg89.1%
+-commutative89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
Taylor expanded in c around inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -4.09999999999999996e-82 < b < 4.20000000000000005e-25Initial program 73.0%
div-sub73.0%
sub-neg73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*73.0%
distribute-neg-frac73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*72.8%
distribute-rgt-out72.7%
associate-/r*72.7%
metadata-eval72.7%
sub-neg72.7%
+-commutative72.7%
Simplified72.7%
Taylor expanded in a around inf 66.4%
*-commutative66.4%
Simplified66.4%
if 4.20000000000000005e-25 < b Initial program 58.6%
div-sub58.7%
sub-neg58.7%
neg-mul-158.7%
*-commutative58.7%
associate-/l*58.6%
distribute-neg-frac58.6%
neg-mul-158.6%
*-commutative58.6%
associate-/l*58.5%
distribute-rgt-out58.5%
associate-/r*58.5%
metadata-eval58.5%
sub-neg58.5%
+-commutative58.5%
Simplified58.7%
Taylor expanded in c around 0 94.4%
+-commutative94.4%
mul-1-neg94.4%
unsub-neg94.4%
Simplified94.4%
Final simplification84.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ 1.0 (- (/ a b) (/ b c))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = 1.0 / ((a / b) - (b / c));
} 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 = 1.0d0 / ((a / b) - (b / c))
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 = 1.0 / ((a / b) - (b / c));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = 1.0 / ((a / b) - (b / c)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); 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 = 1.0 / ((a / b) - (b / c)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $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{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 28.5%
div-sub27.5%
sub-neg27.5%
neg-mul-127.5%
*-commutative27.5%
associate-/l*26.0%
distribute-neg-frac26.0%
neg-mul-126.0%
*-commutative26.0%
associate-/l*27.4%
distribute-rgt-out28.5%
associate-/r*28.5%
metadata-eval28.5%
sub-neg28.5%
+-commutative28.5%
Simplified28.5%
associate-*l/28.5%
clear-num28.6%
*-commutative28.6%
pow228.6%
Applied egg-rr28.6%
Taylor expanded in b around -inf 67.9%
associate-*r*67.9%
mul-1-neg67.9%
+-commutative67.9%
mul-1-neg67.9%
unsub-neg67.9%
Simplified67.9%
Taylor expanded in c around inf 69.3%
+-commutative69.3%
mul-1-neg69.3%
unsub-neg69.3%
Simplified69.3%
if -4.999999999999985e-310 < b Initial program 66.7%
div-sub66.8%
sub-neg66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.7%
distribute-neg-frac66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.6%
distribute-rgt-out66.6%
associate-/r*66.6%
metadata-eval66.6%
sub-neg66.6%
+-commutative66.6%
Simplified66.7%
Taylor expanded in c around 0 74.4%
+-commutative74.4%
mul-1-neg74.4%
unsub-neg74.4%
Simplified74.4%
Final simplification71.7%
(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 28.5%
div-sub27.5%
sub-neg27.5%
neg-mul-127.5%
*-commutative27.5%
associate-/l*26.0%
distribute-neg-frac26.0%
neg-mul-126.0%
*-commutative26.0%
associate-/l*27.4%
distribute-rgt-out28.5%
associate-/r*28.5%
metadata-eval28.5%
sub-neg28.5%
+-commutative28.5%
Simplified28.5%
Taylor expanded in b around -inf 69.1%
mul-1-neg69.1%
distribute-neg-frac269.1%
Simplified69.1%
if -4.999999999999985e-310 < b Initial program 66.7%
div-sub66.8%
sub-neg66.8%
neg-mul-166.8%
*-commutative66.8%
associate-/l*66.7%
distribute-neg-frac66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.6%
distribute-rgt-out66.6%
associate-/r*66.6%
metadata-eval66.6%
sub-neg66.6%
+-commutative66.6%
Simplified66.7%
Taylor expanded in c around 0 74.4%
+-commutative74.4%
mul-1-neg74.4%
unsub-neg74.4%
Simplified74.4%
Final simplification71.6%
(FPCore (a b c) :precision binary64 (if (<= b -3.6e-302) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-302) {
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.6d-302)) 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.6e-302) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-302: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-302) 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 <= -3.6e-302) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-302], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-302}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.6000000000000001e-302Initial program 28.2%
div-sub27.1%
sub-neg27.1%
neg-mul-127.1%
*-commutative27.1%
associate-/l*25.6%
distribute-neg-frac25.6%
neg-mul-125.6%
*-commutative25.6%
associate-/l*27.0%
distribute-rgt-out28.1%
associate-/r*28.1%
metadata-eval28.1%
sub-neg28.1%
+-commutative28.1%
Simplified28.2%
Taylor expanded in b around -inf 70.1%
mul-1-neg70.1%
distribute-neg-frac270.1%
Simplified70.1%
if -3.6000000000000001e-302 < b Initial program 66.5%
div-sub66.5%
sub-neg66.5%
neg-mul-166.5%
*-commutative66.5%
associate-/l*66.4%
distribute-neg-frac66.4%
neg-mul-166.4%
*-commutative66.4%
associate-/l*66.3%
distribute-rgt-out66.3%
associate-/r*66.3%
metadata-eval66.3%
sub-neg66.3%
+-commutative66.3%
Simplified66.4%
Taylor expanded in a around 0 72.6%
associate-*r/72.6%
mul-1-neg72.6%
Simplified72.6%
Final simplification71.3%
(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 46.3%
div-sub45.7%
sub-neg45.7%
neg-mul-145.7%
*-commutative45.7%
associate-/l*44.9%
distribute-neg-frac44.9%
neg-mul-144.9%
*-commutative44.9%
associate-/l*45.6%
distribute-rgt-out46.2%
associate-/r*46.2%
metadata-eval46.2%
sub-neg46.2%
+-commutative46.2%
Simplified46.2%
Taylor expanded in b around -inf 38.1%
mul-1-neg38.1%
distribute-neg-frac238.1%
Simplified38.1%
Final simplification38.1%
(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 46.3%
div-sub45.7%
sub-neg45.7%
neg-mul-145.7%
*-commutative45.7%
associate-/l*44.9%
distribute-neg-frac44.9%
neg-mul-144.9%
*-commutative44.9%
associate-/l*45.6%
distribute-rgt-out46.2%
associate-/r*46.2%
metadata-eval46.2%
sub-neg46.2%
+-commutative46.2%
Simplified46.2%
associate-*l/46.3%
clear-num46.3%
*-commutative46.3%
pow246.3%
Applied egg-rr46.3%
Taylor expanded in b around -inf 37.6%
associate-*r*37.6%
mul-1-neg37.6%
+-commutative37.6%
mul-1-neg37.6%
unsub-neg37.6%
Simplified37.6%
Taylor expanded in b around 0 2.6%
Final simplification2.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 / 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 46.3%
div-sub45.7%
sub-neg45.7%
neg-mul-145.7%
*-commutative45.7%
associate-/l*44.9%
distribute-neg-frac44.9%
neg-mul-144.9%
*-commutative44.9%
associate-/l*45.6%
distribute-rgt-out46.2%
associate-/r*46.2%
metadata-eval46.2%
sub-neg46.2%
+-commutative46.2%
Simplified46.2%
Taylor expanded in b around inf 34.1%
Taylor expanded in b around 0 8.6%
Final simplification8.6%
(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 2024080
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(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)))