
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -4e+154)
(/ (+ b (fma -2.0 (* a (/ c b)) b)) (* -2.0 a))
(if (<= b 6.2e-6)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+154) {
tmp = (b + fma(-2.0, (a * (c / b)), b)) / (-2.0 * a);
} else if (b <= 6.2e-6) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+154) tmp = Float64(Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b)) / Float64(-2.0 * a)); elseif (b <= 6.2e-6) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+154], N[(N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e-6], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $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 -4 \cdot 10^{+154}:\\
\;\;\;\;\frac{b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)}{-2 \cdot a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-6}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.00000000000000015e154Initial program 29.7%
+-commutative29.7%
sqr-neg29.7%
unsub-neg29.7%
sqr-neg29.7%
sub-neg29.7%
+-commutative29.7%
*-commutative29.7%
associate-*r*29.7%
distribute-rgt-neg-in29.7%
fma-define30.0%
*-commutative30.0%
distribute-rgt-neg-in30.0%
metadata-eval30.0%
Simplified30.0%
frac-2neg30.0%
div-inv30.0%
sub-neg30.0%
distribute-neg-in30.0%
pow230.0%
add-sqr-sqrt30.0%
sqrt-unprod30.0%
sqr-neg30.0%
sqrt-prod0.0%
add-sqr-sqrt30.0%
add-sqr-sqrt30.0%
sqrt-unprod0.0%
sqr-neg0.0%
sqrt-prod0.0%
add-sqr-sqrt30.0%
distribute-rgt-neg-in30.0%
metadata-eval30.0%
Applied egg-rr30.0%
Taylor expanded in a around 0 2.1%
un-div-inv2.1%
+-commutative2.1%
add-sqr-sqrt9.4%
sqrt-unprod0.3%
sqr-neg0.3%
sqrt-unprod0.1%
add-sqr-sqrt85.9%
+-commutative85.9%
fma-define85.9%
associate-/l*95.6%
Applied egg-rr95.6%
if -4.00000000000000015e154 < b < 6.1999999999999999e-6Initial program 82.1%
*-commutative82.1%
+-commutative82.1%
sqr-neg82.1%
unsub-neg82.1%
sqr-neg82.1%
fma-neg82.2%
distribute-lft-neg-in82.2%
*-commutative82.2%
*-commutative82.2%
distribute-rgt-neg-in82.2%
metadata-eval82.2%
Simplified82.2%
if 6.1999999999999999e-6 < b Initial program 14.7%
*-commutative14.7%
Simplified14.7%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
mul-1-neg87.9%
Simplified87.9%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ b (- a))) (t_1 (* (- b (sqrt (* c (* a -4.0)))) (/ -0.5 a))))
(if (<= b -1.6e-29)
t_0
(if (<= b -2.55e-90)
t_1
(if (<= b -1.05e-129) t_0 (if (<= b 2.4e-8) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = b / -a;
double t_1 = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a);
double tmp;
if (b <= -1.6e-29) {
tmp = t_0;
} else if (b <= -2.55e-90) {
tmp = t_1;
} else if (b <= -1.05e-129) {
tmp = t_0;
} else if (b <= 2.4e-8) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = b / -a
t_1 = (b - sqrt((c * (a * (-4.0d0))))) * ((-0.5d0) / a)
if (b <= (-1.6d-29)) then
tmp = t_0
else if (b <= (-2.55d-90)) then
tmp = t_1
else if (b <= (-1.05d-129)) then
tmp = t_0
else if (b <= 2.4d-8) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = b / -a;
double t_1 = (b - Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
double tmp;
if (b <= -1.6e-29) {
tmp = t_0;
} else if (b <= -2.55e-90) {
tmp = t_1;
} else if (b <= -1.05e-129) {
tmp = t_0;
} else if (b <= 2.4e-8) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = b / -a t_1 = (b - math.sqrt((c * (a * -4.0)))) * (-0.5 / a) tmp = 0 if b <= -1.6e-29: tmp = t_0 elif b <= -2.55e-90: tmp = t_1 elif b <= -1.05e-129: tmp = t_0 elif b <= 2.4e-8: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(b / Float64(-a)) t_1 = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * Float64(-0.5 / a)) tmp = 0.0 if (b <= -1.6e-29) tmp = t_0; elseif (b <= -2.55e-90) tmp = t_1; elseif (b <= -1.05e-129) tmp = t_0; elseif (b <= 2.4e-8) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = b / -a; t_1 = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a); tmp = 0.0; if (b <= -1.6e-29) tmp = t_0; elseif (b <= -2.55e-90) tmp = t_1; elseif (b <= -1.05e-129) tmp = t_0; elseif (b <= 2.4e-8) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b / (-a)), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.6e-29], t$95$0, If[LessEqual[b, -2.55e-90], t$95$1, If[LessEqual[b, -1.05e-129], t$95$0, If[LessEqual[b, 2.4e-8], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{-a}\\
t_1 := \left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{if}\;b \leq -1.6 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -2.55 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq -1.05 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-8}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.6e-29 or -2.5499999999999998e-90 < b < -1.05e-129Initial program 63.9%
*-commutative63.9%
Simplified63.9%
Taylor expanded in b around -inf 87.6%
associate-*r/87.6%
mul-1-neg87.6%
Simplified87.6%
if -1.6e-29 < b < -2.5499999999999998e-90 or -1.05e-129 < b < 2.39999999999999998e-8Initial program 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around 0 65.8%
*-commutative65.8%
associate-*r*65.8%
Simplified65.8%
*-commutative65.8%
sqrt-prod35.9%
Applied egg-rr35.9%
frac-2neg35.9%
div-inv35.9%
distribute-neg-in35.9%
add-sqr-sqrt20.1%
sqrt-unprod35.8%
sqr-neg35.8%
sqrt-prod15.8%
add-sqr-sqrt35.2%
sub-neg35.2%
add-sqr-sqrt19.5%
*-commutative19.5%
sqrt-unprod35.3%
sqr-neg35.3%
sqrt-prod15.7%
add-sqr-sqrt35.9%
sqrt-prod65.7%
distribute-rgt-neg-in65.7%
metadata-eval65.7%
Applied egg-rr65.7%
*-commutative65.7%
associate-*l/65.7%
metadata-eval65.7%
*-commutative65.7%
associate-*r*65.7%
Simplified65.7%
if 2.39999999999999998e-8 < b Initial program 14.7%
*-commutative14.7%
Simplified14.7%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
mul-1-neg87.9%
Simplified87.9%
Final simplification80.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ b (- a))) (t_1 (/ (- b (sqrt (* c (* a -4.0)))) (* -2.0 a))))
(if (<= b -3.85e-31)
t_0
(if (<= b -2.7e-90)
t_1
(if (<= b -2e-129) t_0 (if (<= b 4.8e-8) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = b / -a;
double t_1 = (b - sqrt((c * (a * -4.0)))) / (-2.0 * a);
double tmp;
if (b <= -3.85e-31) {
tmp = t_0;
} else if (b <= -2.7e-90) {
tmp = t_1;
} else if (b <= -2e-129) {
tmp = t_0;
} else if (b <= 4.8e-8) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = b / -a
t_1 = (b - sqrt((c * (a * (-4.0d0))))) / ((-2.0d0) * a)
if (b <= (-3.85d-31)) then
tmp = t_0
else if (b <= (-2.7d-90)) then
tmp = t_1
else if (b <= (-2d-129)) then
tmp = t_0
else if (b <= 4.8d-8) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = b / -a;
double t_1 = (b - Math.sqrt((c * (a * -4.0)))) / (-2.0 * a);
double tmp;
if (b <= -3.85e-31) {
tmp = t_0;
} else if (b <= -2.7e-90) {
tmp = t_1;
} else if (b <= -2e-129) {
tmp = t_0;
} else if (b <= 4.8e-8) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = b / -a t_1 = (b - math.sqrt((c * (a * -4.0)))) / (-2.0 * a) tmp = 0 if b <= -3.85e-31: tmp = t_0 elif b <= -2.7e-90: tmp = t_1 elif b <= -2e-129: tmp = t_0 elif b <= 4.8e-8: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(b / Float64(-a)) t_1 = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) / Float64(-2.0 * a)) tmp = 0.0 if (b <= -3.85e-31) tmp = t_0; elseif (b <= -2.7e-90) tmp = t_1; elseif (b <= -2e-129) tmp = t_0; elseif (b <= 4.8e-8) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = b / -a; t_1 = (b - sqrt((c * (a * -4.0)))) / (-2.0 * a); tmp = 0.0; if (b <= -3.85e-31) tmp = t_0; elseif (b <= -2.7e-90) tmp = t_1; elseif (b <= -2e-129) tmp = t_0; elseif (b <= 4.8e-8) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b / (-a)), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3.85e-31], t$95$0, If[LessEqual[b, -2.7e-90], t$95$1, If[LessEqual[b, -2e-129], t$95$0, If[LessEqual[b, 4.8e-8], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{-a}\\
t_1 := \frac{b - \sqrt{c \cdot \left(a \cdot -4\right)}}{-2 \cdot a}\\
\mathbf{if}\;b \leq -3.85 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -2.7 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq -2 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-8}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.85000000000000006e-31 or -2.69999999999999996e-90 < b < -1.9999999999999999e-129Initial program 63.9%
*-commutative63.9%
Simplified63.9%
Taylor expanded in b around -inf 87.6%
associate-*r/87.6%
mul-1-neg87.6%
Simplified87.6%
if -3.85000000000000006e-31 < b < -2.69999999999999996e-90 or -1.9999999999999999e-129 < b < 4.79999999999999997e-8Initial program 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around 0 65.8%
*-commutative65.8%
associate-*r*65.8%
Simplified65.8%
*-un-lft-identity65.8%
times-frac65.7%
add-sqr-sqrt34.9%
sqrt-unprod65.4%
sqr-neg65.4%
sqrt-unprod30.9%
add-sqr-sqrt63.4%
Applied egg-rr63.4%
frac-2neg63.4%
metadata-eval63.4%
frac-2neg63.4%
metadata-eval63.4%
frac-times63.5%
Applied egg-rr65.8%
neg-mul-165.8%
distribute-frac-neg65.8%
distribute-neg-frac265.8%
*-commutative65.8%
associate-*r*65.8%
distribute-rgt-neg-in65.8%
metadata-eval65.8%
Simplified65.8%
if 4.79999999999999997e-8 < b Initial program 14.7%
*-commutative14.7%
Simplified14.7%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
mul-1-neg87.9%
Simplified87.9%
Final simplification80.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- b (sqrt (* c (* a -4.0)))) (* -2.0 a))))
(if (<= b -5.7e-30)
(/ (+ b (fma -2.0 (* a (/ c b)) b)) (* -2.0 a))
(if (<= b -2.3e-90)
t_0
(if (<= b -2e-129) (/ b (- a)) (if (<= b 2.4e-8) t_0 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (b - sqrt((c * (a * -4.0)))) / (-2.0 * a);
double tmp;
if (b <= -5.7e-30) {
tmp = (b + fma(-2.0, (a * (c / b)), b)) / (-2.0 * a);
} else if (b <= -2.3e-90) {
tmp = t_0;
} else if (b <= -2e-129) {
tmp = b / -a;
} else if (b <= 2.4e-8) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) / Float64(-2.0 * a)) tmp = 0.0 if (b <= -5.7e-30) tmp = Float64(Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b)) / Float64(-2.0 * a)); elseif (b <= -2.3e-90) tmp = t_0; elseif (b <= -2e-129) tmp = Float64(b / Float64(-a)); elseif (b <= 2.4e-8) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5.7e-30], N[(N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -2.3e-90], t$95$0, If[LessEqual[b, -2e-129], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.4e-8], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - \sqrt{c \cdot \left(a \cdot -4\right)}}{-2 \cdot a}\\
\mathbf{if}\;b \leq -5.7 \cdot 10^{-30}:\\
\;\;\;\;\frac{b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)}{-2 \cdot a}\\
\mathbf{elif}\;b \leq -2.3 \cdot 10^{-90}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -2 \cdot 10^{-129}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.69999999999999977e-30Initial program 61.5%
+-commutative61.5%
sqr-neg61.5%
unsub-neg61.5%
sqr-neg61.5%
sub-neg61.5%
+-commutative61.5%
*-commutative61.5%
associate-*r*61.5%
distribute-rgt-neg-in61.5%
fma-define61.7%
*-commutative61.7%
distribute-rgt-neg-in61.7%
metadata-eval61.7%
Simplified61.7%
frac-2neg61.7%
div-inv61.6%
sub-neg61.6%
distribute-neg-in61.6%
pow261.6%
add-sqr-sqrt61.5%
sqrt-unprod61.6%
sqr-neg61.6%
sqrt-prod0.0%
add-sqr-sqrt19.0%
add-sqr-sqrt21.4%
sqrt-unprod5.3%
sqr-neg5.3%
sqrt-prod0.0%
add-sqr-sqrt61.6%
distribute-rgt-neg-in61.6%
metadata-eval61.6%
Applied egg-rr61.6%
Taylor expanded in a around 0 2.3%
un-div-inv2.3%
+-commutative2.3%
add-sqr-sqrt8.0%
sqrt-unprod1.4%
sqr-neg1.4%
sqrt-unprod0.0%
add-sqr-sqrt82.4%
+-commutative82.4%
fma-define82.4%
associate-/l*86.9%
Applied egg-rr86.9%
if -5.69999999999999977e-30 < b < -2.2999999999999998e-90 or -1.9999999999999999e-129 < b < 2.39999999999999998e-8Initial program 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around 0 65.8%
*-commutative65.8%
associate-*r*65.8%
Simplified65.8%
*-un-lft-identity65.8%
times-frac65.7%
add-sqr-sqrt34.9%
sqrt-unprod65.4%
sqr-neg65.4%
sqrt-unprod30.9%
add-sqr-sqrt63.4%
Applied egg-rr63.4%
frac-2neg63.4%
metadata-eval63.4%
frac-2neg63.4%
metadata-eval63.4%
frac-times63.5%
Applied egg-rr65.8%
neg-mul-165.8%
distribute-frac-neg65.8%
distribute-neg-frac265.8%
*-commutative65.8%
associate-*r*65.8%
distribute-rgt-neg-in65.8%
metadata-eval65.8%
Simplified65.8%
if -2.2999999999999998e-90 < b < -1.9999999999999999e-129Initial program 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if 2.39999999999999998e-8 < b Initial program 14.7%
*-commutative14.7%
Simplified14.7%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
mul-1-neg87.9%
Simplified87.9%
Final simplification80.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3e+153)
(/ (+ b (fma -2.0 (* a (/ c b)) b)) (* -2.0 a))
(if (<= b 2.4e-8)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e+153) {
tmp = (b + fma(-2.0, (a * (c / b)), b)) / (-2.0 * a);
} else if (b <= 2.4e-8) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -3e+153) tmp = Float64(Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b)) / Float64(-2.0 * a)); elseif (b <= 2.4e-8) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -3e+153], N[(N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.4e-8], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $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 -3 \cdot 10^{+153}:\\
\;\;\;\;\frac{b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)}{-2 \cdot a}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-8}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.00000000000000019e153Initial program 29.7%
+-commutative29.7%
sqr-neg29.7%
unsub-neg29.7%
sqr-neg29.7%
sub-neg29.7%
+-commutative29.7%
*-commutative29.7%
associate-*r*29.7%
distribute-rgt-neg-in29.7%
fma-define30.0%
*-commutative30.0%
distribute-rgt-neg-in30.0%
metadata-eval30.0%
Simplified30.0%
frac-2neg30.0%
div-inv30.0%
sub-neg30.0%
distribute-neg-in30.0%
pow230.0%
add-sqr-sqrt30.0%
sqrt-unprod30.0%
sqr-neg30.0%
sqrt-prod0.0%
add-sqr-sqrt30.0%
add-sqr-sqrt30.0%
sqrt-unprod0.0%
sqr-neg0.0%
sqrt-prod0.0%
add-sqr-sqrt30.0%
distribute-rgt-neg-in30.0%
metadata-eval30.0%
Applied egg-rr30.0%
Taylor expanded in a around 0 2.1%
un-div-inv2.1%
+-commutative2.1%
add-sqr-sqrt9.4%
sqrt-unprod0.3%
sqr-neg0.3%
sqrt-unprod0.1%
add-sqr-sqrt85.9%
+-commutative85.9%
fma-define85.9%
associate-/l*95.6%
Applied egg-rr95.6%
if -3.00000000000000019e153 < b < 2.39999999999999998e-8Initial program 82.1%
if 2.39999999999999998e-8 < b Initial program 14.7%
*-commutative14.7%
Simplified14.7%
Taylor expanded in b around inf 87.9%
associate-*r/87.9%
mul-1-neg87.9%
Simplified87.9%
Final simplification86.1%
(FPCore (a b c) :precision binary64 (if (<= b 4.4e-254) (/ b (- a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.4e-254) {
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 <= 4.4d-254) 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 <= 4.4e-254) {
tmp = b / -a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.4e-254: tmp = b / -a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.4e-254) tmp = Float64(b / Float64(-a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.4e-254) tmp = b / -a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.4e-254], N[(b / (-a)), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.4 \cdot 10^{-254}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.4000000000000002e-254Initial program 71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in b around -inf 67.0%
associate-*r/67.0%
mul-1-neg67.0%
Simplified67.0%
if 4.4000000000000002e-254 < b Initial program 31.0%
*-commutative31.0%
Simplified31.0%
Taylor expanded in b around inf 68.7%
associate-*r/68.7%
mul-1-neg68.7%
Simplified68.7%
Final simplification67.7%
(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 / Float64(-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 53.5%
*-commutative53.5%
Simplified53.5%
Taylor expanded in b around -inf 38.8%
associate-*r/38.8%
mul-1-neg38.8%
Simplified38.8%
Final simplification38.8%
(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 53.5%
*-commutative53.5%
Simplified53.5%
clear-num53.4%
inv-pow53.4%
Applied egg-rr24.7%
unpow-124.7%
Simplified24.7%
Taylor expanded in a around 0 2.2%
Final simplification2.2%
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $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 - \left(4 \cdot a\right) \cdot c}\\
\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 2024072
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(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)))