| Alternative 1 | |
|---|---|
| Error | 9.8 |
| Cost | 7496 |
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (sqrt (- (* b_2 b_2) (* a c)))))
(if (<= b_2 -1.3e+154)
(/ (* b_2 -2.0) a)
(if (<= b_2 -9.2e-284)
(- (/ t_0 a) (/ b_2 a))
(if (<= b_2 1.8e+94)
(/ 1.0 (/ (- (- b_2) t_0) c))
(* -0.5 (/ c b_2)))))))double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
double code(double a, double b_2, double c) {
double t_0 = sqrt(((b_2 * b_2) - (a * c)));
double tmp;
if (b_2 <= -1.3e+154) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= -9.2e-284) {
tmp = (t_0 / a) - (b_2 / a);
} else if (b_2 <= 1.8e+94) {
tmp = 1.0 / ((-b_2 - t_0) / c);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b_2 * b_2) - (a * c)))
if (b_2 <= (-1.3d+154)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= (-9.2d-284)) then
tmp = (t_0 / a) - (b_2 / a)
else if (b_2 <= 1.8d+94) then
tmp = 1.0d0 / ((-b_2 - t_0) / c)
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt(((b_2 * b_2) - (a * c)));
double tmp;
if (b_2 <= -1.3e+154) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= -9.2e-284) {
tmp = (t_0 / a) - (b_2 / a);
} else if (b_2 <= 1.8e+94) {
tmp = 1.0 / ((-b_2 - t_0) / c);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
def code(a, b_2, c): t_0 = math.sqrt(((b_2 * b_2) - (a * c))) tmp = 0 if b_2 <= -1.3e+154: tmp = (b_2 * -2.0) / a elif b_2 <= -9.2e-284: tmp = (t_0 / a) - (b_2 / a) elif b_2 <= 1.8e+94: tmp = 1.0 / ((-b_2 - t_0) / c) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function code(a, b_2, c) t_0 = sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) tmp = 0.0 if (b_2 <= -1.3e+154) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= -9.2e-284) tmp = Float64(Float64(t_0 / a) - Float64(b_2 / a)); elseif (b_2 <= 1.8e+94) tmp = Float64(1.0 / Float64(Float64(Float64(-b_2) - t_0) / c)); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
function tmp_2 = code(a, b_2, c) t_0 = sqrt(((b_2 * b_2) - (a * c))); tmp = 0.0; if (b_2 <= -1.3e+154) tmp = (b_2 * -2.0) / a; elseif (b_2 <= -9.2e-284) tmp = (t_0 / a) - (b_2 / a); elseif (b_2 <= 1.8e+94) tmp = 1.0 / ((-b_2 - t_0) / c); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b$95$2, -1.3e+154], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, -9.2e-284], N[(N[(t$95$0 / a), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.8e+94], N[(1.0 / N[(N[((-b$95$2) - t$95$0), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
t_0 := \sqrt{b_2 \cdot b_2 - a \cdot c}\\
\mathbf{if}\;b_2 \leq -1.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq -9.2 \cdot 10^{-284}:\\
\;\;\;\;\frac{t_0}{a} - \frac{b_2}{a}\\
\mathbf{elif}\;b_2 \leq 1.8 \cdot 10^{+94}:\\
\;\;\;\;\frac{1}{\frac{\left(-b_2\right) - t_0}{c}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\end{array}
Results
if b_2 < -1.29999999999999994e154Initial program 64.0
Simplified64.0
[Start]64.0 | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]64.0 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]64.0 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Taylor expanded in b_2 around -inf 2.5
Simplified2.5
[Start]2.5 | \[ \frac{-2 \cdot b_2}{a}
\] |
|---|---|
*-commutative [=>]2.5 | \[ \frac{\color{blue}{b_2 \cdot -2}}{a}
\] |
if -1.29999999999999994e154 < b_2 < -9.2e-284Initial program 8.0
Simplified8.0
[Start]8.0 | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]8.0 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]8.0 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Applied egg-rr8.0
if -9.2e-284 < b_2 < 1.79999999999999996e94Initial program 32.1
Simplified32.1
[Start]32.1 | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]32.1 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]32.1 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Applied egg-rr32.2
Simplified32.2
[Start]32.2 | \[ \frac{\frac{\left(b_2 \cdot b_2 - a \cdot c\right) - \left(-b_2\right) \cdot \left(-b_2\right)}{\sqrt{b_2 \cdot b_2 - a \cdot c} - \left(-b_2\right)}}{a}
\] |
|---|---|
associate--l- [=>]32.2 | \[ \frac{\frac{\color{blue}{b_2 \cdot b_2 - \left(a \cdot c + \left(-b_2\right) \cdot \left(-b_2\right)\right)}}{\sqrt{b_2 \cdot b_2 - a \cdot c} - \left(-b_2\right)}}{a}
\] |
sqr-neg [=>]32.2 | \[ \frac{\frac{b_2 \cdot b_2 - \left(a \cdot c + \color{blue}{b_2 \cdot b_2}\right)}{\sqrt{b_2 \cdot b_2 - a \cdot c} - \left(-b_2\right)}}{a}
\] |
*-commutative [=>]32.2 | \[ \frac{\frac{b_2 \cdot b_2 - \left(\color{blue}{c \cdot a} + b_2 \cdot b_2\right)}{\sqrt{b_2 \cdot b_2 - a \cdot c} - \left(-b_2\right)}}{a}
\] |
*-commutative [=>]32.2 | \[ \frac{\frac{b_2 \cdot b_2 - \left(c \cdot a + b_2 \cdot b_2\right)}{\sqrt{b_2 \cdot b_2 - \color{blue}{c \cdot a}} - \left(-b_2\right)}}{a}
\] |
Applied egg-rr32.2
Simplified16.1
[Start]32.2 | \[ \frac{\left(b_2 \cdot b_2 - \left(c \cdot a + b_2 \cdot b_2\right)\right) \cdot \frac{1}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}{a}
\] |
|---|---|
associate-*r/ [=>]32.2 | \[ \frac{\color{blue}{\frac{\left(b_2 \cdot b_2 - \left(c \cdot a + b_2 \cdot b_2\right)\right) \cdot 1}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}}{a}
\] |
*-rgt-identity [=>]32.2 | \[ \frac{\frac{\color{blue}{b_2 \cdot b_2 - \left(c \cdot a + b_2 \cdot b_2\right)}}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}{a}
\] |
+-commutative [=>]32.2 | \[ \frac{\frac{b_2 \cdot b_2 - \color{blue}{\left(b_2 \cdot b_2 + c \cdot a\right)}}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}{a}
\] |
associate--r+ [=>]16.1 | \[ \frac{\frac{\color{blue}{\left(b_2 \cdot b_2 - b_2 \cdot b_2\right) - c \cdot a}}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}{a}
\] |
+-inverses [=>]16.1 | \[ \frac{\frac{\color{blue}{0} - c \cdot a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \left(-b_2\right)}}{a}
\] |
neg-sub0 [=>]16.1 | \[ \frac{\frac{0 - c \cdot a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - \color{blue}{\left(0 - b_2\right)}}}{a}
\] |
associate-+l- [<=]16.1 | \[ \frac{\frac{0 - c \cdot a}{\color{blue}{\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - 0\right) + b_2}}}{a}
\] |
+-commutative [<=]16.1 | \[ \frac{\frac{0 - c \cdot a}{\color{blue}{b_2 + \left(\sqrt{b_2 \cdot b_2 - c \cdot a} - 0\right)}}}{a}
\] |
--rgt-identity [=>]16.1 | \[ \frac{\frac{0 - c \cdot a}{b_2 + \color{blue}{\sqrt{b_2 \cdot b_2 - c \cdot a}}}}{a}
\] |
Applied egg-rr16.3
Simplified16.3
[Start]16.3 | \[ {\left(a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{0 - c \cdot a}\right)}^{-1}
\] |
|---|---|
unpow-1 [=>]16.3 | \[ \color{blue}{\frac{1}{a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{0 - c \cdot a}}}
\] |
sub0-neg [=>]16.3 | \[ \frac{1}{a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{\color{blue}{-c \cdot a}}}
\] |
mul-1-neg [<=]16.3 | \[ \frac{1}{a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{\color{blue}{-1 \cdot \left(c \cdot a\right)}}}
\] |
associate-*r* [=>]16.3 | \[ \frac{1}{a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{\color{blue}{\left(-1 \cdot c\right) \cdot a}}}
\] |
neg-mul-1 [<=]16.3 | \[ \frac{1}{a \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{\color{blue}{\left(-c\right)} \cdot a}}
\] |
Applied egg-rr20.6
Simplified9.5
[Start]20.6 | \[ \frac{1}{\frac{a \cdot \left(-\left(b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}\right)\right)}{c \cdot a}}
\] |
|---|---|
*-commutative [=>]20.6 | \[ \frac{1}{\frac{a \cdot \left(-\left(b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}\right)\right)}{\color{blue}{a \cdot c}}}
\] |
times-frac [=>]9.5 | \[ \frac{1}{\color{blue}{\frac{a}{a} \cdot \frac{-\left(b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{c}}}
\] |
*-inverses [=>]9.5 | \[ \frac{1}{\color{blue}{1} \cdot \frac{-\left(b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{c}}
\] |
distribute-frac-neg [=>]9.5 | \[ \frac{1}{1 \cdot \color{blue}{\left(-\frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{c}\right)}}
\] |
distribute-rgt-neg-in [<=]9.5 | \[ \frac{1}{\color{blue}{-1 \cdot \frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{c}}}
\] |
*-lft-identity [=>]9.5 | \[ \frac{1}{-\color{blue}{\frac{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}{c}}}
\] |
distribute-frac-neg [<=]9.5 | \[ \frac{1}{\color{blue}{\frac{-\left(b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}\right)}{c}}}
\] |
distribute-neg-in [=>]9.5 | \[ \frac{1}{\frac{\color{blue}{\left(-b_2\right) + \left(-\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}}{c}}
\] |
unsub-neg [=>]9.5 | \[ \frac{1}{\frac{\color{blue}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}}{c}}
\] |
if 1.79999999999999996e94 < b_2 Initial program 59.2
Simplified59.2
[Start]59.2 | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]59.2 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]59.2 | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Taylor expanded in b_2 around inf 2.6
Final simplification6.6
| Alternative 1 | |
|---|---|
| Error | 9.8 |
| Cost | 7496 |
| Alternative 2 | |
|---|---|
| Error | 9.8 |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 13.8 |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Error | 13.7 |
| Cost | 7176 |
| Alternative 5 | |
|---|---|
| Error | 14.1 |
| Cost | 7048 |
| Alternative 6 | |
|---|---|
| Error | 22.1 |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 39.9 |
| Cost | 320 |
herbie shell --seed 2023187
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))