
(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 -9e+78)
(/ (- b) a)
(if (<= b 2.7e-73)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e+78) {
tmp = -b / a;
} else if (b <= 2.7e-73) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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 <= (-9d+78)) then
tmp = -b / a
else if (b <= 2.7d-73) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e+78) {
tmp = -b / a;
} else if (b <= 2.7e-73) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e+78: tmp = -b / a elif b <= 2.7e-73: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e+78) tmp = Float64(Float64(-b) / a); elseif (b <= 2.7e-73) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e+78) tmp = -b / a; elseif (b <= 2.7e-73) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e+78], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.7e-73], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{+78}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-73}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.9999999999999999e78Initial program 52.6%
Taylor expanded in b around -inf 88.5%
associate-*r/88.5%
mul-1-neg88.5%
Simplified88.5%
if -8.9999999999999999e78 < b < 2.69999999999999994e-73Initial program 85.8%
if 2.69999999999999994e-73 < b Initial program 14.6%
Taylor expanded in b around inf 88.2%
associate-*r/88.2%
neg-mul-188.2%
Simplified88.2%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-144)
(- (/ c b) (/ b a))
(if (<= b 9.5e-74)
(/ 1.0 (/ (* a 2.0) (- (sqrt (* c (* a -4.0))) b)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-74) {
tmp = 1.0 / ((a * 2.0) / (sqrt((c * (a * -4.0))) - b));
} else {
tmp = -c / b;
}
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-144)) then
tmp = (c / b) - (b / a)
else if (b <= 9.5d-74) then
tmp = 1.0d0 / ((a * 2.0d0) / (sqrt((c * (a * (-4.0d0)))) - b))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-74) {
tmp = 1.0 / ((a * 2.0) / (Math.sqrt((c * (a * -4.0))) - b));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-144: tmp = (c / b) - (b / a) elif b <= 9.5e-74: tmp = 1.0 / ((a * 2.0) / (math.sqrt((c * (a * -4.0))) - b)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-144) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9.5e-74) tmp = Float64(1.0 / Float64(Float64(a * 2.0) / Float64(sqrt(Float64(c * Float64(a * -4.0))) - b))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e-144) tmp = (c / b) - (b / a); elseif (b <= 9.5e-74) tmp = 1.0 / ((a * 2.0) / (sqrt((c * (a * -4.0))) - b)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-144], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.5e-74], N[(1.0 / N[(N[(a * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-74}:\\
\;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{c \cdot \left(a \cdot -4\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.6e-144Initial program 71.3%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
unsub-neg80.0%
Simplified80.0%
if -4.6e-144 < b < 9.5000000000000007e-74Initial program 77.6%
add-sqr-sqrt77.4%
pow277.4%
pow1/277.4%
sqrt-pow177.5%
fma-neg77.5%
distribute-lft-neg-in77.5%
associate-*r*77.5%
metadata-eval77.5%
metadata-eval77.5%
Applied egg-rr77.5%
Taylor expanded in a around inf 33.3%
Simplified76.5%
clear-num76.6%
inv-pow76.6%
*-commutative76.6%
associate-*r*76.6%
Applied egg-rr76.6%
unpow-176.6%
*-commutative76.6%
rem-square-sqrt0.0%
unpow20.0%
associate-*r*0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt76.6%
Simplified76.6%
if 9.5000000000000007e-74 < b Initial program 14.6%
Taylor expanded in b around inf 88.2%
associate-*r/88.2%
neg-mul-188.2%
Simplified88.2%
Final simplification82.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-144)
(- (/ c b) (/ b a))
(if (<= b 1.25e-71)
(/ (- (sqrt (* (* a c) -4.0)) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-71) {
tmp = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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-144)) then
tmp = (c / b) - (b / a)
else if (b <= 1.25d-71) then
tmp = (sqrt(((a * c) * (-4.0d0))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-71) {
tmp = (Math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-144: tmp = (c / b) - (b / a) elif b <= 1.25e-71: tmp = (math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-144) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.25e-71) tmp = Float64(Float64(sqrt(Float64(Float64(a * c) * -4.0)) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e-144) tmp = (c / b) - (b / a); elseif (b <= 1.25e-71) tmp = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-144], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.25e-71], N[(N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-71}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.6e-144Initial program 71.3%
Taylor expanded in b around -inf 80.0%
mul-1-neg80.0%
unsub-neg80.0%
Simplified80.0%
if -4.6e-144 < b < 1.24999999999999999e-71Initial program 77.6%
add-sqr-sqrt77.4%
pow277.4%
pow1/277.4%
sqrt-pow177.5%
fma-neg77.5%
distribute-lft-neg-in77.5%
associate-*r*77.5%
metadata-eval77.5%
metadata-eval77.5%
Applied egg-rr77.5%
Taylor expanded in a around inf 33.3%
Simplified76.5%
if 1.24999999999999999e-71 < b Initial program 14.6%
Taylor expanded in b around inf 88.2%
associate-*r/88.2%
neg-mul-188.2%
Simplified88.2%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (if (<= b -3.6e-304) (- (/ c b) (/ b a)) (/ 1.0 (- (/ a b) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-304) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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-304)) then
tmp = (c / b) - (b / a)
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-304) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-304: tmp = (c / b) - (b / a) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-304) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.6e-304) tmp = (c / b) - (b / a); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-304], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-304}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -3.6000000000000001e-304Initial program 73.2%
Taylor expanded in b around -inf 67.5%
mul-1-neg67.5%
unsub-neg67.5%
Simplified67.5%
if -3.6000000000000001e-304 < b Initial program 31.0%
add-sqr-sqrt28.4%
pow228.4%
pow1/228.4%
sqrt-pow128.5%
fma-neg28.5%
distribute-lft-neg-in28.5%
associate-*r*28.5%
metadata-eval28.5%
metadata-eval28.5%
Applied egg-rr28.5%
clear-num28.5%
inv-pow28.5%
*-commutative28.5%
neg-mul-128.5%
metadata-eval28.5%
fma-def28.5%
metadata-eval28.5%
pow-pow31.0%
metadata-eval31.0%
pow1/231.0%
fma-udef31.0%
add-sqr-sqrt29.6%
hypot-udef39.2%
associate-*l*39.2%
Applied egg-rr39.2%
unpow-139.2%
associate-/l*39.2%
*-commutative39.2%
Simplified39.2%
Taylor expanded in b around inf 0.0%
+-commutative0.0%
associate-*r/0.0%
*-commutative0.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt69.7%
metadata-eval69.7%
Simplified69.7%
Final simplification68.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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 <= (-1d-309)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 73.8%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
unsub-neg65.9%
Simplified65.9%
if -1.000000000000002e-309 < b Initial program 29.5%
Taylor expanded in b around inf 71.0%
associate-*r/71.0%
neg-mul-171.0%
Simplified71.0%
Final simplification68.6%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -b / a;
} else {
tmp = 0.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) :: tmp
if (b <= (-1d-309)) then
tmp = -b / a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -b / a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -b / a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -b / a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 73.8%
Taylor expanded in b around -inf 65.6%
associate-*r/65.6%
mul-1-neg65.6%
Simplified65.6%
if -1.000000000000002e-309 < b Initial program 29.5%
add-sqr-sqrt26.8%
pow226.8%
pow1/226.8%
sqrt-pow126.9%
fma-neg26.9%
distribute-lft-neg-in26.9%
associate-*r*26.9%
metadata-eval26.9%
metadata-eval26.9%
Applied egg-rr26.9%
clear-num26.9%
inv-pow26.9%
*-commutative26.9%
neg-mul-126.9%
metadata-eval26.9%
fma-def26.9%
metadata-eval26.9%
pow-pow29.5%
metadata-eval29.5%
pow1/229.5%
fma-udef29.5%
add-sqr-sqrt28.1%
hypot-udef37.8%
associate-*l*37.8%
Applied egg-rr37.8%
unpow-137.8%
associate-/l*37.8%
*-commutative37.8%
Simplified37.8%
Taylor expanded in a around 0 22.9%
associate-*r/22.9%
distribute-rgt1-in22.9%
metadata-eval22.9%
mul0-lft22.9%
metadata-eval22.9%
Simplified22.9%
Final simplification43.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= (-1d-309)) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 73.8%
Taylor expanded in b around -inf 65.6%
associate-*r/65.6%
mul-1-neg65.6%
Simplified65.6%
if -1.000000000000002e-309 < b Initial program 29.5%
Taylor expanded in b around inf 71.0%
associate-*r/71.0%
neg-mul-171.0%
Simplified71.0%
Final simplification68.4%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 50.6%
add-sqr-sqrt49.1%
pow249.1%
pow1/249.1%
sqrt-pow149.2%
fma-neg49.3%
distribute-lft-neg-in49.3%
associate-*r*49.3%
metadata-eval49.3%
metadata-eval49.3%
Applied egg-rr49.3%
clear-num49.2%
inv-pow49.2%
*-commutative49.2%
neg-mul-149.2%
metadata-eval49.2%
fma-def49.2%
metadata-eval49.2%
pow-pow50.7%
metadata-eval50.7%
pow1/250.6%
fma-udef50.6%
add-sqr-sqrt41.4%
hypot-udef49.0%
associate-*l*49.0%
Applied egg-rr49.0%
unpow-149.0%
associate-/l*49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 13.3%
associate-*r/13.3%
distribute-rgt1-in13.3%
metadata-eval13.3%
mul0-lft13.3%
metadata-eval13.3%
Simplified13.3%
Final simplification13.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $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{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023264
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))