
(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 -1.25e+50)
(- (/ c b) (/ b a))
(if (<= b 2.2e-105)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e+50) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-105) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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 <= (-1.25d+50)) then
tmp = (c / b) - (b / a)
else if (b <= 2.2d-105) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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 <= -1.25e+50) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-105) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e+50: tmp = (c / b) - (b / a) elif b <= 2.2e-105: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e+50) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.2e-105) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - 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 <= -1.25e+50) tmp = (c / b) - (b / a); elseif (b <= 2.2e-105) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e+50], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-105], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $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 -1.25 \cdot 10^{+50}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-105}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.25e50Initial program 57.2%
neg-sub057.2%
associate-+l-57.2%
sub0-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-*r/57.0%
Simplified57.1%
Taylor expanded in b around -inf 90.1%
mul-1-neg90.1%
unsub-neg90.1%
Simplified90.1%
if -1.25e50 < b < 2.20000000000000004e-105Initial program 71.8%
if 2.20000000000000004e-105 < b Initial program 14.4%
neg-sub014.4%
associate-+l-14.4%
sub0-neg14.4%
neg-mul-114.4%
*-commutative14.4%
associate-*r/14.4%
Simplified14.4%
Taylor expanded in b around inf 88.4%
associate-*r/88.4%
neg-mul-188.4%
Simplified88.4%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e+33)
(- (/ c b) (/ b a))
(if (<= b 8.2e-107)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e+33) {
tmp = (c / b) - (b / a);
} else if (b <= 8.2e-107) {
tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / 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 <= (-1.8d+33)) then
tmp = (c / b) - (b / a)
else if (b <= 8.2d-107) then
tmp = (b - sqrt(((b * b) - (a * (c * 4.0d0))))) * ((-0.5d0) / 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 <= -1.8e+33) {
tmp = (c / b) - (b / a);
} else if (b <= 8.2e-107) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e+33: tmp = (c / b) - (b / a) elif b <= 8.2e-107: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e+33) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8.2e-107) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.8e+33) tmp = (c / b) - (b / a); elseif (b <= 8.2e-107) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e+33], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.2e-107], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{+33}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8.2 \cdot 10^{-107}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.8000000000000001e33Initial program 61.9%
neg-sub061.9%
associate-+l-61.9%
sub0-neg61.9%
neg-mul-161.9%
*-commutative61.9%
associate-*r/61.7%
Simplified61.9%
Taylor expanded in b around -inf 91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
if -1.8000000000000001e33 < b < 8.1999999999999998e-107Initial program 69.8%
neg-sub069.8%
associate-+l-69.8%
sub0-neg69.8%
neg-mul-169.8%
*-commutative69.8%
associate-*r/69.6%
Simplified69.6%
fma-udef69.6%
associate-*r*69.6%
metadata-eval69.6%
distribute-rgt-neg-in69.6%
*-commutative69.6%
+-commutative69.6%
sub-neg69.6%
*-commutative69.6%
associate-*l*69.6%
Applied egg-rr69.6%
if 8.1999999999999998e-107 < b Initial program 14.4%
neg-sub014.4%
associate-+l-14.4%
sub0-neg14.4%
neg-mul-114.4%
*-commutative14.4%
associate-*r/14.4%
Simplified14.4%
Taylor expanded in b around inf 88.4%
associate-*r/88.4%
neg-mul-188.4%
Simplified88.4%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.3e-99)
(- (/ c b) (/ b a))
(if (<= b 9e-108)
(* -0.5 (/ (- b (sqrt (* c (* a -4.0)))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-99) {
tmp = (c / b) - (b / a);
} else if (b <= 9e-108) {
tmp = -0.5 * ((b - sqrt((c * (a * -4.0)))) / 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 <= (-2.3d-99)) then
tmp = (c / b) - (b / a)
else if (b <= 9d-108) then
tmp = (-0.5d0) * ((b - sqrt((c * (a * (-4.0d0))))) / 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 <= -2.3e-99) {
tmp = (c / b) - (b / a);
} else if (b <= 9e-108) {
tmp = -0.5 * ((b - Math.sqrt((c * (a * -4.0)))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e-99: tmp = (c / b) - (b / a) elif b <= 9e-108: tmp = -0.5 * ((b - math.sqrt((c * (a * -4.0)))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e-99) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9e-108) tmp = Float64(-0.5 * Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.3e-99) tmp = (c / b) - (b / a); elseif (b <= 9e-108) tmp = -0.5 * ((b - sqrt((c * (a * -4.0)))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e-99], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9e-108], N[(-0.5 * N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{-99}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{-108}:\\
\;\;\;\;-0.5 \cdot \frac{b - \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.2999999999999998e-99Initial program 66.4%
neg-sub066.4%
associate-+l-66.4%
sub0-neg66.4%
neg-mul-166.4%
*-commutative66.4%
associate-*r/66.2%
Simplified66.3%
Taylor expanded in b around -inf 81.3%
mul-1-neg81.3%
unsub-neg81.3%
Simplified81.3%
if -2.2999999999999998e-99 < b < 8.99999999999999941e-108Initial program 67.0%
neg-sub067.0%
associate-+l-67.0%
sub0-neg67.0%
neg-mul-167.0%
*-commutative67.0%
associate-*r/66.9%
Simplified66.9%
fma-udef66.9%
associate-*r*66.9%
metadata-eval66.9%
distribute-rgt-neg-in66.9%
*-commutative66.9%
+-commutative66.9%
sub-neg66.9%
add-sqr-sqrt66.4%
pow266.4%
Applied egg-rr66.4%
Taylor expanded in a around inf 40.7%
Simplified65.0%
if 8.99999999999999941e-108 < b Initial program 14.4%
neg-sub014.4%
associate-+l-14.4%
sub0-neg14.4%
neg-mul-114.4%
*-commutative14.4%
associate-*r/14.4%
Simplified14.4%
Taylor expanded in b around inf 88.4%
associate-*r/88.4%
neg-mul-188.4%
Simplified88.4%
Final simplification79.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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-310)) 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-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], 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^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 68.0%
neg-sub068.0%
associate-+l-68.0%
sub0-neg68.0%
neg-mul-168.0%
*-commutative68.0%
associate-*r/67.8%
Simplified67.9%
Taylor expanded in b around -inf 66.5%
mul-1-neg66.5%
unsub-neg66.5%
Simplified66.5%
if -9.999999999999969e-311 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
*-commutative30.0%
associate-*r/29.9%
Simplified30.0%
Taylor expanded in b around inf 66.2%
associate-*r/66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification66.3%
(FPCore (a b c) :precision binary64 (if (<= b -3.5e-302) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-302) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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-302)) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-302) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e-302: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-302) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.5e-302) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-302], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{-302}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -3.5000000000000001e-302Initial program 68.6%
neg-sub068.6%
associate-+l-68.6%
sub0-neg68.6%
neg-mul-168.6%
*-commutative68.6%
associate-*r/68.4%
Simplified68.5%
Taylor expanded in b around -inf 66.6%
associate-*r/66.6%
mul-1-neg66.6%
Simplified66.6%
if -3.5000000000000001e-302 < b Initial program 29.8%
neg-sub029.8%
associate-+l-29.8%
sub0-neg29.8%
neg-mul-129.8%
*-commutative29.8%
associate-*r/29.8%
Simplified29.8%
Taylor expanded in a around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in b around 0 21.9%
Final simplification41.8%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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-310)) 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-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 68.0%
neg-sub068.0%
associate-+l-68.0%
sub0-neg68.0%
neg-mul-168.0%
*-commutative68.0%
associate-*r/67.8%
Simplified67.9%
Taylor expanded in b around -inf 66.0%
associate-*r/66.0%
mul-1-neg66.0%
Simplified66.0%
if -9.999999999999969e-311 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
*-commutative30.0%
associate-*r/29.9%
Simplified30.0%
Taylor expanded in b around inf 66.2%
associate-*r/66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification66.1%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 47.1%
neg-sub047.1%
associate-+l-47.1%
sub0-neg47.1%
neg-mul-147.1%
*-commutative47.1%
associate-*r/47.0%
Simplified47.0%
Taylor expanded in a around 0 25.4%
unpow225.4%
Simplified25.4%
Taylor expanded in b around 0 13.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 2023240
(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)))