| Alternative 1 | |
|---|---|
| Error | 11.0 |
| Cost | 7888 |
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b)))
(t_1 (/ (+ b (sqrt (+ (* b b) (* (* a c) -4.0)))) (* a -2.0))))
(if (<= b -0.0125)
t_0
(if (<= b -6.4e-37)
t_1
(if (<= b -4e-101)
(+ t_0 (- (/ (* a (pow c 2.0)) (pow b 3.0))))
(if (<= b 4.9e+82) t_1 (- (/ c b) (/ b a))))))))double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
double code(double a, double b, double c) {
double t_0 = -(c / b);
double t_1 = (b + sqrt(((b * b) + ((a * c) * -4.0)))) / (a * -2.0);
double tmp;
if (b <= -0.0125) {
tmp = t_0;
} else if (b <= -6.4e-37) {
tmp = t_1;
} else if (b <= -4e-101) {
tmp = t_0 + -((a * pow(c, 2.0)) / pow(b, 3.0));
} else if (b <= 4.9e+82) {
tmp = t_1;
} 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
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
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 = -(c / b)
t_1 = (b + sqrt(((b * b) + ((a * c) * (-4.0d0))))) / (a * (-2.0d0))
if (b <= (-0.0125d0)) then
tmp = t_0
else if (b <= (-6.4d-37)) then
tmp = t_1
else if (b <= (-4d-101)) then
tmp = t_0 + -((a * (c ** 2.0d0)) / (b ** 3.0d0))
else if (b <= 4.9d+82) then
tmp = t_1
else
tmp = (c / b) - (b / a)
end if
code = tmp
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);
}
public static double code(double a, double b, double c) {
double t_0 = -(c / b);
double t_1 = (b + Math.sqrt(((b * b) + ((a * c) * -4.0)))) / (a * -2.0);
double tmp;
if (b <= -0.0125) {
tmp = t_0;
} else if (b <= -6.4e-37) {
tmp = t_1;
} else if (b <= -4e-101) {
tmp = t_0 + -((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0));
} else if (b <= 4.9e+82) {
tmp = t_1;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c): t_0 = -(c / b) t_1 = (b + math.sqrt(((b * b) + ((a * c) * -4.0)))) / (a * -2.0) tmp = 0 if b <= -0.0125: tmp = t_0 elif b <= -6.4e-37: tmp = t_1 elif b <= -4e-101: tmp = t_0 + -((a * math.pow(c, 2.0)) / math.pow(b, 3.0)) elif b <= 4.9e+82: tmp = t_1 else: tmp = (c / b) - (b / a) return tmp
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 code(a, b, c) t_0 = Float64(-Float64(c / b)) t_1 = Float64(Float64(b + sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) * -4.0)))) / Float64(a * -2.0)) tmp = 0.0 if (b <= -0.0125) tmp = t_0; elseif (b <= -6.4e-37) tmp = t_1; elseif (b <= -4e-101) tmp = Float64(t_0 + Float64(-Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))); elseif (b <= 4.9e+82) tmp = t_1; else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
function tmp_2 = code(a, b, c) t_0 = -(c / b); t_1 = (b + sqrt(((b * b) + ((a * c) * -4.0)))) / (a * -2.0); tmp = 0.0; if (b <= -0.0125) tmp = t_0; elseif (b <= -6.4e-37) tmp = t_1; elseif (b <= -4e-101) tmp = t_0 + -((a * (c ^ 2.0)) / (b ^ 3.0)); elseif (b <= 4.9e+82) tmp = t_1; else tmp = (c / b) - (b / a); end tmp_2 = tmp; 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]
code[a_, b_, c_] := Block[{t$95$0 = (-N[(c / b), $MachinePrecision])}, Block[{t$95$1 = N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -0.0125], t$95$0, If[LessEqual[b, -6.4e-37], t$95$1, If[LessEqual[b, -4e-101], N[(t$95$0 + (-N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision])), $MachinePrecision], If[LessEqual[b, 4.9e+82], t$95$1, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
t_0 := -\frac{c}{b}\\
t_1 := \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{a \cdot -2}\\
\mathbf{if}\;b \leq -0.0125:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -6.4 \cdot 10^{-37}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -4 \cdot 10^{-101}:\\
\;\;\;\;t_0 + \left(-\frac{a \cdot {c}^{2}}{{b}^{3}}\right)\\
\mathbf{elif}\;b \leq 4.9 \cdot 10^{+82}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
Results
| Original | 34.7 |
|---|---|
| Target | 21.3 |
| Herbie | 10.8 |
if b < -0.012500000000000001Initial program 56.3
Simplified56.3
[Start]56.3 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-65 [=>]56.3 | \[ \frac{\color{blue}{-\left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)\right)}}{2 \cdot a}
\] |
rational_best-simplify-54 [=>]56.3 | \[ \color{blue}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)}{-2 \cdot a}}
\] |
rational_best-simplify-63 [=>]56.3 | \[ \frac{\color{blue}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-61 [=>]56.3 | \[ \frac{b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]56.3 | \[ \frac{b + \sqrt{b \cdot b + \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}}}{-2 \cdot a}
\] |
metadata-eval [=>]56.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot \color{blue}{-4}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]56.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{\color{blue}{a \cdot \left(-2\right)}}
\] |
metadata-eval [=>]56.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{a \cdot \color{blue}{-2}}
\] |
Taylor expanded in b around -inf 5.7
Simplified5.7
[Start]5.7 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
rational_best-simplify-3 [=>]5.7 | \[ \color{blue}{\frac{c}{b} \cdot -1}
\] |
rational_best-simplify-17 [=>]5.7 | \[ \color{blue}{-\frac{c}{b}}
\] |
if -0.012500000000000001 < b < -6.3999999999999998e-37 or -4.00000000000000021e-101 < b < 4.9000000000000001e82Initial program 14.4
Simplified14.4
[Start]14.4 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-65 [=>]14.4 | \[ \frac{\color{blue}{-\left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)\right)}}{2 \cdot a}
\] |
rational_best-simplify-54 [=>]14.4 | \[ \color{blue}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)}{-2 \cdot a}}
\] |
rational_best-simplify-63 [=>]14.4 | \[ \frac{\color{blue}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-61 [=>]14.4 | \[ \frac{b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]14.4 | \[ \frac{b + \sqrt{b \cdot b + \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}}}{-2 \cdot a}
\] |
metadata-eval [=>]14.4 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot \color{blue}{-4}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]14.4 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{\color{blue}{a \cdot \left(-2\right)}}
\] |
metadata-eval [=>]14.4 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{a \cdot \color{blue}{-2}}
\] |
if -6.3999999999999998e-37 < b < -4.00000000000000021e-101Initial program 35.8
Simplified35.8
[Start]35.8 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-65 [=>]35.8 | \[ \frac{\color{blue}{-\left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)\right)}}{2 \cdot a}
\] |
rational_best-simplify-54 [=>]35.8 | \[ \color{blue}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)}{-2 \cdot a}}
\] |
rational_best-simplify-63 [=>]35.8 | \[ \frac{\color{blue}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-61 [=>]35.8 | \[ \frac{b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]35.8 | \[ \frac{b + \sqrt{b \cdot b + \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}}}{-2 \cdot a}
\] |
metadata-eval [=>]35.8 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot \color{blue}{-4}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]35.8 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{\color{blue}{a \cdot \left(-2\right)}}
\] |
metadata-eval [=>]35.8 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{a \cdot \color{blue}{-2}}
\] |
Taylor expanded in b around -inf 32.8
Simplified32.8
[Start]32.8 | \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -1 \cdot \frac{c}{b}
\] |
|---|---|
rational_best-simplify-1 [=>]32.8 | \[ \color{blue}{-1 \cdot \frac{c}{b} + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}}
\] |
rational_best-simplify-3 [=>]32.8 | \[ \color{blue}{\frac{c}{b} \cdot -1} + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
rational_best-simplify-17 [=>]32.8 | \[ \color{blue}{\left(-\frac{c}{b}\right)} + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\] |
rational_best-simplify-3 [=>]32.8 | \[ \left(-\frac{c}{b}\right) + \color{blue}{\frac{{c}^{2} \cdot a}{{b}^{3}} \cdot -1}
\] |
rational_best-simplify-17 [=>]32.8 | \[ \left(-\frac{c}{b}\right) + \color{blue}{\left(-\frac{{c}^{2} \cdot a}{{b}^{3}}\right)}
\] |
rational_best-simplify-3 [=>]32.8 | \[ \left(-\frac{c}{b}\right) + \left(-\frac{\color{blue}{a \cdot {c}^{2}}}{{b}^{3}}\right)
\] |
if 4.9000000000000001e82 < b Initial program 44.3
Simplified44.3
[Start]44.3 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-65 [=>]44.3 | \[ \frac{\color{blue}{-\left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)\right)}}{2 \cdot a}
\] |
rational_best-simplify-54 [=>]44.3 | \[ \color{blue}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \left(-b\right)}{-2 \cdot a}}
\] |
rational_best-simplify-63 [=>]44.3 | \[ \frac{\color{blue}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-61 [=>]44.3 | \[ \frac{b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]44.3 | \[ \frac{b + \sqrt{b \cdot b + \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}}}{-2 \cdot a}
\] |
metadata-eval [=>]44.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot \color{blue}{-4}}}{-2 \cdot a}
\] |
rational_best-simplify-52 [=>]44.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{\color{blue}{a \cdot \left(-2\right)}}
\] |
metadata-eval [=>]44.3 | \[ \frac{b + \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{a \cdot \color{blue}{-2}}
\] |
Taylor expanded in b around inf 5.0
Simplified5.0
[Start]5.0 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
rational_best-simplify-1 [=>]5.0 | \[ \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}}
\] |
rational_best-simplify-3 [=>]5.0 | \[ \color{blue}{\frac{b}{a} \cdot -1} + \frac{c}{b}
\] |
rational_best-simplify-17 [=>]5.0 | \[ \color{blue}{\left(-\frac{b}{a}\right)} + \frac{c}{b}
\] |
Taylor expanded in b around 0 5.0
Simplified5.0
[Start]5.0 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
rational_best-simplify-3 [=>]5.0 | \[ \frac{c}{b} + \color{blue}{\frac{b}{a} \cdot -1}
\] |
rational_best-simplify-18 [<=]5.0 | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
rational_best-simplify-61 [<=]5.0 | \[ \color{blue}{\frac{c}{b} - \frac{b}{a}}
\] |
Final simplification10.8
| Alternative 1 | |
|---|---|
| Error | 11.0 |
| Cost | 7888 |
| Alternative 2 | |
|---|---|
| Error | 13.7 |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 13.9 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 20.0 |
| Cost | 7112 |
| Alternative 5 | |
|---|---|
| Error | 40.1 |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Error | 23.0 |
| Cost | 388 |
| Alternative 7 | |
|---|---|
| Error | 56.5 |
| Cost | 192 |
herbie shell --seed 2023104
(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)))