
(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 -2.3e-74)
(/ (- c) b)
(if (<= b 105.0)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-74) {
tmp = -c / b;
} else if (b <= 105.0) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} 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 <= (-2.3d-74)) then
tmp = -c / b
else if (b <= 105.0d0) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * a)))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-74) {
tmp = -c / b;
} else if (b <= 105.0) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e-74: tmp = -c / b elif b <= 105.0: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e-74) tmp = Float64(Float64(-c) / b); elseif (b <= 105.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.3e-74) tmp = -c / b; elseif (b <= 105.0) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e-74], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 105.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{-74}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 105:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.2999999999999998e-74Initial program 14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
associate-*r*14.8%
*-commutative14.8%
Simplified14.8%
Taylor expanded in b around -inf 84.4%
mul-1-neg84.4%
distribute-neg-frac84.4%
Simplified84.4%
if -2.2999999999999998e-74 < b < 105Initial program 73.0%
*-commutative73.0%
sqr-neg73.0%
*-commutative73.0%
sqr-neg73.0%
*-commutative73.0%
associate-*r*73.0%
*-commutative73.0%
Simplified73.0%
if 105 < b Initial program 63.1%
*-commutative63.1%
sqr-neg63.1%
*-commutative63.1%
sqr-neg63.1%
*-commutative63.1%
associate-*r*63.1%
*-commutative63.1%
Simplified63.1%
Taylor expanded in b around inf 94.5%
associate-*r/94.5%
mul-1-neg94.5%
Simplified94.5%
Final simplification84.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.72e-73)
(/ (- c) b)
(if (<= b 105.0)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.72e-73) {
tmp = -c / b;
} else if (b <= 105.0) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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.72d-73)) then
tmp = -c / b
else if (b <= 105.0d0) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
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.72e-73) {
tmp = -c / b;
} else if (b <= 105.0) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.72e-73: tmp = -c / b elif b <= 105.0: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.72e-73) tmp = Float64(Float64(-c) / b); elseif (b <= 105.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.72e-73) tmp = -c / b; elseif (b <= 105.0) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.72e-73], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 105.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.72 \cdot 10^{-73}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 105:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.71999999999999989e-73Initial program 14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
associate-*r*14.8%
*-commutative14.8%
Simplified14.8%
Taylor expanded in b around -inf 84.4%
mul-1-neg84.4%
distribute-neg-frac84.4%
Simplified84.4%
if -1.71999999999999989e-73 < b < 105Initial program 73.0%
if 105 < b Initial program 63.1%
*-commutative63.1%
sqr-neg63.1%
*-commutative63.1%
sqr-neg63.1%
*-commutative63.1%
associate-*r*63.1%
*-commutative63.1%
Simplified63.1%
Taylor expanded in b around inf 94.5%
associate-*r/94.5%
mul-1-neg94.5%
Simplified94.5%
Final simplification84.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.65e-73)
(/ (- c) b)
(if (<= b 7.8e-59)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.65e-73) {
tmp = -c / b;
} else if (b <= 7.8e-59) {
tmp = (-b - sqrt((c * (a * -4.0)))) / (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.65d-73)) then
tmp = -c / b
else if (b <= 7.8d-59) then
tmp = (-b - sqrt((c * (a * (-4.0d0))))) / (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.65e-73) {
tmp = -c / b;
} else if (b <= 7.8e-59) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.65e-73: tmp = -c / b elif b <= 7.8e-59: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.65e-73) tmp = Float64(Float64(-c) / b); elseif (b <= 7.8e-59) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0)))) / 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 <= -2.65e-73) tmp = -c / b; elseif (b <= 7.8e-59) tmp = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.65e-73], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 7.8e-59], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $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 -2.65 \cdot 10^{-73}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{-59}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.64999999999999986e-73Initial program 14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
associate-*r*14.8%
*-commutative14.8%
Simplified14.8%
Taylor expanded in b around -inf 84.4%
mul-1-neg84.4%
distribute-neg-frac84.4%
Simplified84.4%
if -2.64999999999999986e-73 < b < 7.80000000000000038e-59Initial program 70.1%
*-commutative70.1%
sqr-neg70.1%
*-commutative70.1%
sqr-neg70.1%
*-commutative70.1%
associate-*r*70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in b around 0 61.8%
*-commutative61.8%
*-commutative61.8%
associate-*l*61.9%
Simplified61.9%
if 7.80000000000000038e-59 < b Initial program 66.3%
*-commutative66.3%
sqr-neg66.3%
*-commutative66.3%
sqr-neg66.3%
*-commutative66.3%
associate-*r*66.3%
*-commutative66.3%
Simplified66.3%
Taylor expanded in b around inf 94.0%
+-commutative94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
Final simplification81.3%
(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 26.1%
*-commutative26.1%
sqr-neg26.1%
*-commutative26.1%
sqr-neg26.1%
*-commutative26.1%
associate-*r*26.1%
*-commutative26.1%
Simplified26.1%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
distribute-neg-frac70.0%
Simplified70.0%
if -4.999999999999985e-310 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
associate-*r*70.6%
*-commutative70.6%
Simplified70.6%
Taylor expanded in b around inf 70.9%
+-commutative70.9%
mul-1-neg70.9%
unsub-neg70.9%
Simplified70.9%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (if (<= b -6.2) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2) {
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 <= (-6.2d0)) 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 <= -6.2) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2) 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 <= -6.2) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.2:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.20000000000000018Initial program 12.9%
*-commutative12.9%
sqr-neg12.9%
*-commutative12.9%
sqr-neg12.9%
*-commutative12.9%
associate-*r*12.9%
*-commutative12.9%
Simplified12.9%
Taylor expanded in b around -inf 75.6%
associate-*r/75.6%
associate-*r*75.6%
*-commutative75.6%
Simplified75.6%
expm1-log1p-u70.8%
expm1-udef43.3%
Applied egg-rr33.5%
expm1-def33.0%
expm1-log1p33.1%
metadata-eval33.1%
times-frac33.1%
*-commutative33.1%
*-lft-identity33.1%
associate-/r/33.2%
*-commutative33.2%
associate-*r/33.0%
*-commutative33.0%
associate-*r/33.0%
associate-*l/32.9%
*-inverses32.9%
*-lft-identity32.9%
Simplified32.9%
if -6.20000000000000018 < b Initial program 64.9%
*-commutative64.9%
sqr-neg64.9%
*-commutative64.9%
sqr-neg64.9%
*-commutative64.9%
associate-*r*65.0%
*-commutative65.0%
Simplified65.0%
Taylor expanded in b around inf 53.9%
associate-*r/53.9%
mul-1-neg53.9%
Simplified53.9%
Final simplification47.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = -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(-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 = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 26.1%
*-commutative26.1%
sqr-neg26.1%
*-commutative26.1%
sqr-neg26.1%
*-commutative26.1%
associate-*r*26.1%
*-commutative26.1%
Simplified26.1%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
distribute-neg-frac70.0%
Simplified70.0%
if -4.999999999999985e-310 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
associate-*r*70.6%
*-commutative70.6%
Simplified70.6%
Taylor expanded in b around inf 70.8%
associate-*r/70.8%
mul-1-neg70.8%
Simplified70.8%
Final simplification70.4%
(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 49.7%
*-commutative49.7%
sqr-neg49.7%
*-commutative49.7%
sqr-neg49.7%
*-commutative49.7%
associate-*r*49.7%
*-commutative49.7%
Simplified49.7%
Taylor expanded in b around -inf 26.7%
associate-*r/26.7%
associate-*r*26.7%
*-commutative26.7%
Simplified26.7%
expm1-log1p-u24.0%
expm1-udef15.2%
Applied egg-rr11.4%
expm1-def11.3%
expm1-log1p11.8%
metadata-eval11.8%
times-frac11.8%
*-commutative11.8%
*-lft-identity11.8%
associate-/r/11.8%
*-commutative11.8%
associate-*r/11.7%
*-commutative11.7%
associate-*r/11.7%
associate-*l/11.7%
*-inverses11.7%
*-lft-identity11.7%
Simplified11.7%
Final simplification11.7%
(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 2023301
(FPCore (a b c)
:name "The quadratic formula (r2)"
: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)))