
(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
(let* ((t_0 (sqrt (- (* b b) (* (* c 4.0) a)))))
(if (<= b -1.1e+130)
(/ (- c) b)
(if (<= b -2.5e-297)
(* -0.5 (/ (* c 4.0) (- b t_0)))
(if (<= b 4e+65) (* -0.5 (/ (+ b t_0) a)) (- (/ c b) (/ b a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((c * 4.0) * a)));
double tmp;
if (b <= -1.1e+130) {
tmp = -c / b;
} else if (b <= -2.5e-297) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if (b <= 4e+65) {
tmp = -0.5 * ((b + t_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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((c * 4.0d0) * a)))
if (b <= (-1.1d+130)) then
tmp = -c / b
else if (b <= (-2.5d-297)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b - t_0))
else if (b <= 4d+65) then
tmp = (-0.5d0) * ((b + t_0) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((c * 4.0) * a)));
double tmp;
if (b <= -1.1e+130) {
tmp = -c / b;
} else if (b <= -2.5e-297) {
tmp = -0.5 * ((c * 4.0) / (b - t_0));
} else if (b <= 4e+65) {
tmp = -0.5 * ((b + t_0) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((c * 4.0) * a))) tmp = 0 if b <= -1.1e+130: tmp = -c / b elif b <= -2.5e-297: tmp = -0.5 * ((c * 4.0) / (b - t_0)) elif b <= 4e+65: tmp = -0.5 * ((b + t_0) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a))) tmp = 0.0 if (b <= -1.1e+130) tmp = Float64(Float64(-c) / b); elseif (b <= -2.5e-297) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b - t_0))); elseif (b <= 4e+65) tmp = Float64(-0.5 * Float64(Float64(b + t_0) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((c * 4.0) * a))); tmp = 0.0; if (b <= -1.1e+130) tmp = -c / b; elseif (b <= -2.5e-297) tmp = -0.5 * ((c * 4.0) / (b - t_0)); elseif (b <= 4e+65) tmp = -0.5 * ((b + t_0) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1.1e+130], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -2.5e-297], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e+65], N[(-0.5 * N[(N[(b + t$95$0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{+130}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -2.5 \cdot 10^{-297}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - t_0}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+65}:\\
\;\;\;\;-0.5 \cdot \frac{b + t_0}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.09999999999999997e130Initial program 4.3%
Taylor expanded in b around -inf 95.9%
associate-*r/95.9%
neg-mul-195.9%
Simplified95.9%
if -1.09999999999999997e130 < b < -2.5e-297Initial program 44.5%
Simplified44.5%
fma-udef44.5%
associate-*r*44.5%
metadata-eval44.5%
distribute-rgt-neg-in44.5%
*-commutative44.5%
+-commutative44.5%
sub-neg44.5%
*-commutative44.5%
associate-*l*44.5%
Applied egg-rr44.5%
flip-+44.4%
add-sqr-sqrt44.5%
Applied egg-rr44.5%
associate--r-78.7%
+-inverses78.7%
*-commutative78.7%
associate-*l*78.7%
sub-neg78.7%
+-commutative78.7%
distribute-rgt-neg-in78.7%
distribute-rgt-neg-in78.7%
metadata-eval78.7%
fma-udef78.7%
Simplified78.7%
expm1-log1p-u60.0%
expm1-udef16.7%
associate-/l/15.4%
+-lft-identity15.4%
Applied egg-rr15.4%
expm1-def51.4%
expm1-log1p67.7%
associate-*r*67.7%
*-commutative67.7%
times-frac91.1%
*-inverses91.1%
Simplified91.1%
fma-udef44.5%
associate-*r*44.5%
metadata-eval44.5%
distribute-rgt-neg-in44.5%
*-commutative44.5%
+-commutative44.5%
sub-neg44.5%
*-commutative44.5%
associate-*l*44.5%
Applied egg-rr91.1%
if -2.5e-297 < b < 4e65Initial program 87.9%
Simplified87.9%
fma-udef87.9%
associate-*r*87.9%
metadata-eval87.9%
distribute-rgt-neg-in87.9%
*-commutative87.9%
+-commutative87.9%
sub-neg87.9%
*-commutative87.9%
associate-*l*87.9%
Applied egg-rr87.9%
if 4e65 < b Initial program 54.8%
Taylor expanded in b around inf 98.3%
mul-1-neg98.3%
unsub-neg98.3%
Simplified98.3%
Final simplification92.6%
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e-95)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b 7.4e+68)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-95) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 7.4e+68) {
tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / 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 <= (-3.5d-95)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= 7.4d+68) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / 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 <= -3.5e-95) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 7.4e+68) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e-95: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= 7.4e+68: tmp = -0.5 * ((b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-95) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= 7.4e+68) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / 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 <= -3.5e-95) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= 7.4e+68) tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-95], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.4e+68], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{-95}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq 7.4 \cdot 10^{+68}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.4999999999999997e-95Initial program 18.5%
Simplified18.5%
fma-udef18.5%
associate-*r*18.5%
metadata-eval18.5%
distribute-rgt-neg-in18.5%
*-commutative18.5%
+-commutative18.5%
sub-neg18.5%
*-commutative18.5%
associate-*l*18.5%
Applied egg-rr18.5%
flip-+17.8%
add-sqr-sqrt17.8%
Applied egg-rr17.8%
associate--r-49.3%
+-inverses65.6%
*-commutative65.6%
associate-*l*65.6%
sub-neg65.6%
+-commutative65.6%
distribute-rgt-neg-in65.6%
distribute-rgt-neg-in65.6%
metadata-eval65.6%
fma-udef65.6%
Simplified65.6%
expm1-log1p-u57.6%
expm1-udef27.0%
associate-/l/27.0%
+-lft-identity27.0%
Applied egg-rr27.0%
expm1-def53.6%
expm1-log1p60.8%
associate-*r*60.8%
*-commutative60.8%
times-frac74.4%
*-inverses74.4%
Simplified74.4%
Taylor expanded in b around -inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
*-commutative84.3%
associate-/l*85.3%
Simplified85.3%
if -3.4999999999999997e-95 < b < 7.39999999999999996e68Initial program 85.0%
Simplified85.0%
fma-udef85.0%
associate-*r*85.0%
metadata-eval85.0%
distribute-rgt-neg-in85.0%
*-commutative85.0%
+-commutative85.0%
sub-neg85.0%
*-commutative85.0%
associate-*l*85.0%
Applied egg-rr85.0%
if 7.39999999999999996e68 < b Initial program 54.8%
Taylor expanded in b around inf 98.3%
mul-1-neg98.3%
unsub-neg98.3%
Simplified98.3%
Final simplification88.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.4e-94)
(* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0)))))
(if (<= b 2.05e+20)
(* -0.5 (/ (+ b (sqrt (* (* c a) -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-94) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 2.05e+20) {
tmp = -0.5 * ((b + sqrt(((c * a) * -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 <= (-3.4d-94)) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / a)) * 2.0d0))))
else if (b <= 2.05d+20) then
tmp = (-0.5d0) * ((b + sqrt(((c * a) * (-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 <= -3.4e-94) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else if (b <= 2.05e+20) {
tmp = -0.5 * ((b + Math.sqrt(((c * a) * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.4e-94: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) elif b <= 2.05e+20: tmp = -0.5 * ((b + math.sqrt(((c * a) * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.4e-94) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / a)) * 2.0))))); elseif (b <= 2.05e+20) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(c * a) * -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 <= -3.4e-94) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); elseif (b <= 2.05e+20) tmp = -0.5 * ((b + sqrt(((c * a) * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.4e-94], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.05e+20], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.4 \cdot 10^{-94}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{+20}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.3999999999999998e-94Initial program 18.5%
Simplified18.5%
fma-udef18.5%
associate-*r*18.5%
metadata-eval18.5%
distribute-rgt-neg-in18.5%
*-commutative18.5%
+-commutative18.5%
sub-neg18.5%
*-commutative18.5%
associate-*l*18.5%
Applied egg-rr18.5%
flip-+17.8%
add-sqr-sqrt17.8%
Applied egg-rr17.8%
associate--r-49.3%
+-inverses65.6%
*-commutative65.6%
associate-*l*65.6%
sub-neg65.6%
+-commutative65.6%
distribute-rgt-neg-in65.6%
distribute-rgt-neg-in65.6%
metadata-eval65.6%
fma-udef65.6%
Simplified65.6%
expm1-log1p-u57.6%
expm1-udef27.0%
associate-/l/27.0%
+-lft-identity27.0%
Applied egg-rr27.0%
expm1-def53.6%
expm1-log1p60.8%
associate-*r*60.8%
*-commutative60.8%
times-frac74.4%
*-inverses74.4%
Simplified74.4%
Taylor expanded in b around -inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
*-commutative84.3%
associate-/l*85.3%
Simplified85.3%
if -3.3999999999999998e-94 < b < 2.05e20Initial program 83.0%
Simplified83.0%
Taylor expanded in a around inf 67.5%
*-commutative67.5%
Simplified67.5%
if 2.05e20 < b Initial program 62.8%
Taylor expanded in b around inf 93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
Final simplification81.3%
(FPCore (a b c) :precision binary64 (if (<= b 2.16e-296) (* -0.5 (/ (* c 4.0) (+ b (- b (* (/ c (/ b a)) 2.0))))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.16e-296) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / 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.16d-296) then
tmp = (-0.5d0) * ((c * 4.0d0) / (b + (b - ((c / (b / 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.16e-296) {
tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.16e-296: tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.16e-296) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b + Float64(b - Float64(Float64(c / Float64(b / 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 <= 2.16e-296) tmp = -0.5 * ((c * 4.0) / (b + (b - ((c / (b / a)) * 2.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.16e-296], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[(b - N[(N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.16 \cdot 10^{-296}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b + \left(b - \frac{c}{\frac{b}{a}} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < 2.1600000000000001e-296Initial program 31.0%
Simplified31.0%
fma-udef31.0%
associate-*r*31.0%
metadata-eval31.0%
distribute-rgt-neg-in31.0%
*-commutative31.0%
+-commutative31.0%
sub-neg31.0%
*-commutative31.0%
associate-*l*31.0%
Applied egg-rr31.0%
flip-+30.4%
add-sqr-sqrt30.5%
Applied egg-rr30.5%
associate--r-54.8%
+-inverses67.5%
*-commutative67.5%
associate-*l*67.5%
sub-neg67.5%
+-commutative67.5%
distribute-rgt-neg-in67.5%
distribute-rgt-neg-in67.5%
metadata-eval67.5%
fma-udef67.5%
Simplified67.5%
expm1-log1p-u55.7%
expm1-udef24.2%
associate-/l/23.4%
+-lft-identity23.4%
Applied egg-rr23.4%
expm1-def50.5%
expm1-log1p60.7%
associate-*r*60.7%
*-commutative60.7%
times-frac76.1%
*-inverses76.1%
Simplified76.1%
Taylor expanded in b around -inf 69.8%
mul-1-neg69.8%
unsub-neg69.8%
*-commutative69.8%
associate-/l*70.5%
Simplified70.5%
if 2.1600000000000001e-296 < b Initial program 74.4%
Taylor expanded in b around inf 67.0%
mul-1-neg67.0%
unsub-neg67.0%
Simplified67.0%
Final simplification68.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 30.5%
Taylor expanded in b around -inf 70.8%
associate-*r/70.8%
neg-mul-170.8%
Simplified70.8%
if -4.999999999999985e-310 < b Initial program 74.6%
Taylor expanded in b around inf 66.4%
mul-1-neg66.4%
unsub-neg66.4%
Simplified66.4%
Final simplification68.7%
(FPCore (a b c) :precision binary64 (if (<= b -5.5e+90) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e+90) {
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 <= (-5.5d+90)) 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 <= -5.5e+90) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.5e+90: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.5e+90) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.5e+90) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.5e+90], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{+90}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.49999999999999999e90Initial program 12.0%
clear-num12.0%
associate-/r/12.0%
associate-/r*12.0%
metadata-eval12.0%
add-sqr-sqrt5.4%
cancel-sign-sub-inv5.4%
add-sqr-sqrt12.0%
sqrt-unprod4.4%
sqr-neg4.4%
sqrt-prod0.0%
add-sqr-sqrt2.2%
Applied egg-rr2.2%
Taylor expanded in a around 0 35.1%
if -5.49999999999999999e90 < b Initial program 65.1%
Taylor expanded in b around inf 44.1%
associate-*r/44.1%
mul-1-neg44.1%
Simplified44.1%
Final simplification41.9%
(FPCore (a b c) :precision binary64 (if (<= b -1.04e-303) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.04e-303) {
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 <= (-1.04d-303)) 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 <= -1.04e-303) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.04e-303: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.04e-303) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.04e-303) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.04e-303], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.04 \cdot 10^{-303}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.03999999999999999e-303Initial program 29.9%
Taylor expanded in b around -inf 71.3%
associate-*r/71.3%
neg-mul-171.3%
Simplified71.3%
if -1.03999999999999999e-303 < b Initial program 74.8%
Taylor expanded in b around inf 65.9%
associate-*r/65.9%
mul-1-neg65.9%
Simplified65.9%
Final simplification68.6%
(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 52.0%
clear-num51.9%
associate-/r/51.9%
associate-/r*51.9%
metadata-eval51.9%
add-sqr-sqrt50.1%
cancel-sign-sub-inv50.1%
add-sqr-sqrt15.5%
sqrt-unprod29.4%
sqr-neg29.4%
sqrt-prod17.9%
add-sqr-sqrt31.2%
Applied egg-rr30.4%
Taylor expanded in b around -inf 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 52.0%
clear-num51.9%
associate-/r/51.9%
associate-/r*51.9%
metadata-eval51.9%
add-sqr-sqrt50.1%
cancel-sign-sub-inv50.1%
add-sqr-sqrt15.5%
sqrt-unprod29.4%
sqr-neg29.4%
sqrt-prod17.9%
add-sqr-sqrt31.2%
Applied egg-rr30.4%
Taylor expanded in a around 0 11.1%
Final simplification11.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023222
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))