
(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 7 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.1e-90)
(/ (- c) b)
(if (<= b 9.5e+143)
(* -0.5 (/ (+ b (sqrt (fma b b (* a (* c -4.0))))) a))
(* -0.5 (/ (+ b (+ b (* -2.0 (* c (/ a b))))) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-90) {
tmp = -c / b;
} else if (b <= 9.5e+143) {
tmp = -0.5 * ((b + sqrt(fma(b, b, (a * (c * -4.0))))) / a);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (c * (a / b))))) / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.1e-90) tmp = Float64(Float64(-c) / b); elseif (b <= 9.5e+143) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(b, b, Float64(a * Float64(c * -4.0))))) / a)); else tmp = Float64(-0.5 * Float64(Float64(b + Float64(b + Float64(-2.0 * Float64(c * Float64(a / b))))) / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.1e-90], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 9.5e+143], N[(-0.5 * N[(N[(b + N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b + N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.1 \cdot 10^{-90}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{+143}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b + -2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}{a}\\
\end{array}
\end{array}
if b < -4.10000000000000035e-90Initial program 17.1%
Taylor expanded in b around -inf 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
if -4.10000000000000035e-90 < b < 9.50000000000000066e143Initial program 77.9%
/-rgt-identity77.9%
metadata-eval77.9%
associate-/l*77.7%
associate-/r/77.7%
*-commutative77.7%
metadata-eval77.7%
metadata-eval77.7%
associate-*l/77.7%
associate-/r/77.7%
times-frac77.9%
*-commutative77.9%
times-frac77.9%
metadata-eval77.9%
associate-/r/77.9%
*-commutative77.9%
div-sub77.9%
Simplified77.9%
if 9.50000000000000066e143 < b Initial program 49.0%
/-rgt-identity49.0%
metadata-eval49.0%
associate-/l*49.0%
associate-/r/49.0%
*-commutative49.0%
metadata-eval49.0%
metadata-eval49.0%
associate-*l/49.0%
associate-/r/49.0%
times-frac49.0%
*-commutative49.0%
times-frac49.0%
metadata-eval49.0%
associate-/r/49.0%
*-commutative49.0%
div-sub49.0%
Simplified49.0%
fma-udef49.0%
Applied egg-rr49.0%
Taylor expanded in b around inf 87.0%
associate-*r/100.0%
Simplified100.0%
Final simplification83.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.6e-90)
(/ (- c) b)
(if (<= b 1.5e+142)
(* -0.5 (/ (+ b (sqrt (+ (* a (* c -4.0)) (* b b)))) a))
(* -0.5 (/ (+ b (+ b (* -2.0 (* c (/ a b))))) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-90) {
tmp = -c / b;
} else if (b <= 1.5e+142) {
tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (c * (a / 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.6d-90)) then
tmp = -c / b
else if (b <= 1.5d+142) then
tmp = (-0.5d0) * ((b + sqrt(((a * (c * (-4.0d0))) + (b * b)))) / a)
else
tmp = (-0.5d0) * ((b + (b + ((-2.0d0) * (c * (a / b))))) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-90) {
tmp = -c / b;
} else if (b <= 1.5e+142) {
tmp = -0.5 * ((b + Math.sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (c * (a / b))))) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-90: tmp = -c / b elif b <= 1.5e+142: tmp = -0.5 * ((b + math.sqrt(((a * (c * -4.0)) + (b * b)))) / a) else: tmp = -0.5 * ((b + (b + (-2.0 * (c * (a / b))))) / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-90) tmp = Float64(Float64(-c) / b); elseif (b <= 1.5e+142) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b)))) / a)); else tmp = Float64(-0.5 * Float64(Float64(b + Float64(b + Float64(-2.0 * Float64(c * Float64(a / b))))) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-90) tmp = -c / b; elseif (b <= 1.5e+142) tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a); else tmp = -0.5 * ((b + (b + (-2.0 * (c * (a / b))))) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-90], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.5e+142], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b + N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-90}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+142}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b + -2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}{a}\\
\end{array}
\end{array}
if b < -1.60000000000000004e-90Initial program 17.1%
Taylor expanded in b around -inf 82.3%
associate-*r/82.3%
neg-mul-182.3%
Simplified82.3%
if -1.60000000000000004e-90 < b < 1.49999999999999987e142Initial program 77.9%
/-rgt-identity77.9%
metadata-eval77.9%
associate-/l*77.7%
associate-/r/77.7%
*-commutative77.7%
metadata-eval77.7%
metadata-eval77.7%
associate-*l/77.7%
associate-/r/77.7%
times-frac77.9%
*-commutative77.9%
times-frac77.9%
metadata-eval77.9%
associate-/r/77.9%
*-commutative77.9%
div-sub77.9%
Simplified77.9%
fma-udef77.9%
Applied egg-rr77.9%
if 1.49999999999999987e142 < b Initial program 49.0%
/-rgt-identity49.0%
metadata-eval49.0%
associate-/l*49.0%
associate-/r/49.0%
*-commutative49.0%
metadata-eval49.0%
metadata-eval49.0%
associate-*l/49.0%
associate-/r/49.0%
times-frac49.0%
*-commutative49.0%
times-frac49.0%
metadata-eval49.0%
associate-/r/49.0%
*-commutative49.0%
div-sub49.0%
Simplified49.0%
fma-udef49.0%
Applied egg-rr49.0%
Taylor expanded in b around inf 87.0%
associate-*r/100.0%
Simplified100.0%
Final simplification83.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-125)
(/ (- c) b)
(if (<= b 1.12e-104)
(* -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.8e-125) {
tmp = -c / b;
} else if (b <= 1.12e-104) {
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.8d-125)) then
tmp = -c / b
else if (b <= 1.12d-104) 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.8e-125) {
tmp = -c / b;
} else if (b <= 1.12e-104) {
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.8e-125: tmp = -c / b elif b <= 1.12e-104: 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.8e-125) tmp = Float64(Float64(-c) / b); elseif (b <= 1.12e-104) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(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.8e-125) tmp = -c / b; elseif (b <= 1.12e-104) 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.8e-125], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.12e-104], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $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.8 \cdot 10^{-125}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.12 \cdot 10^{-104}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.8000000000000001e-125Initial program 20.0%
Taylor expanded in b around -inf 80.2%
associate-*r/80.2%
neg-mul-180.2%
Simplified80.2%
if -3.8000000000000001e-125 < b < 1.12e-104Initial program 70.2%
Simplified70.2%
Taylor expanded in a around inf 66.4%
*-commutative66.4%
*-commutative66.4%
*-commutative66.4%
associate-*l*66.4%
Simplified66.4%
if 1.12e-104 < b Initial program 71.0%
Taylor expanded in b around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
Final simplification79.8%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 29.9%
Taylor expanded in b around -inf 66.1%
associate-*r/66.1%
neg-mul-166.1%
Simplified66.1%
if -9.999999999999969e-311 < b Initial program 71.2%
Taylor expanded in b around inf 66.9%
mul-1-neg66.9%
unsub-neg66.9%
Simplified66.9%
Final simplification66.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.02e+34) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e+34) {
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.02d+34)) 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.02e+34) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.02e+34: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.02e+34) 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 <= -1.02e+34) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.02e+34], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.02 \cdot 10^{+34}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.02e34Initial program 15.8%
Taylor expanded in b around -inf 67.6%
associate-/l*66.6%
Simplified66.6%
add-cbrt-cube50.1%
pow350.0%
times-frac50.0%
metadata-eval50.0%
mul-1-neg50.0%
div-inv50.1%
associate-/l*50.1%
clear-num50.1%
Applied egg-rr50.1%
pow1/341.5%
distribute-neg-frac41.5%
associate-/r/44.2%
pow144.2%
pow144.2%
pow-div44.2%
metadata-eval44.2%
metadata-eval44.2%
*-un-lft-identity44.2%
Applied egg-rr44.2%
unpow1/356.3%
rem-cbrt-cube91.1%
add-sqr-sqrt40.4%
sqrt-unprod45.9%
sqr-neg45.9%
sqrt-unprod19.3%
add-sqr-sqrt33.1%
expm1-log1p-u33.0%
expm1-udef33.7%
Applied egg-rr33.7%
expm1-def33.0%
expm1-log1p33.1%
Simplified33.1%
if -1.02e34 < b Initial program 64.4%
Taylor expanded in b around inf 49.0%
associate-*r/49.0%
mul-1-neg49.0%
Simplified49.0%
Final simplification45.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 29.9%
Taylor expanded in b around -inf 66.1%
associate-*r/66.1%
neg-mul-166.1%
Simplified66.1%
if -9.999999999999969e-311 < b Initial program 71.2%
Taylor expanded in b around inf 66.2%
associate-*r/66.2%
mul-1-neg66.2%
Simplified66.2%
Final simplification66.1%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 52.6%
Taylor expanded in b around -inf 21.7%
associate-/l*23.7%
Simplified23.7%
add-cbrt-cube16.9%
pow316.9%
times-frac16.9%
metadata-eval16.9%
mul-1-neg16.9%
div-inv16.9%
associate-/l*16.9%
clear-num16.9%
Applied egg-rr16.9%
pow1/313.4%
distribute-neg-frac13.4%
associate-/r/14.1%
pow114.1%
pow114.1%
pow-div14.1%
metadata-eval14.1%
metadata-eval14.1%
*-un-lft-identity14.1%
Applied egg-rr14.1%
unpow1/318.5%
rem-cbrt-cube30.8%
add-sqr-sqrt13.6%
sqrt-unprod15.1%
sqr-neg15.1%
sqrt-unprod5.8%
add-sqr-sqrt10.3%
expm1-log1p-u9.7%
expm1-udef9.9%
Applied egg-rr9.9%
expm1-def9.7%
expm1-log1p10.3%
Simplified10.3%
Final simplification10.3%
(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 2023240
(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)))