"""The tables of the note S2 from the result files. python tables.py""" import os, re HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "..", "paper") num = lambda n: f"{n:,}".replace(",", "\\,") # the 40 000 systems rows = open(os.path.expanduser("~/pandroots-work/pandsysroots-0.21.0/bench_0.21.0.txt")).read().splitlines() names = {"one unknown, degree 2 to 30": "one unknown, degree 2 to 30", "coefficients from 1e-4 to 1e4": "coefficients from $10^{-4}$ to $10^{4}$"} body = [] for l in rows[1:28]: name, f = l[:36].strip(), l[36:].split() cert = num(int(f[3])) if int(f[3]) else "" if int(f[4]): cert = (cert + " + " if cert else "") + num(int(f[4])) + " d." ms = float(f[11]) body.append(f"{names.get(name, name)} & {num(int(f[0]))} & {num(int(f[1]))} & {num(int(f[2]))} & {cert} & {ms:.2f} \\\\") m = re.search(r"(\d+) as expected, (\d+) proved complete, (\d+) certified simple solutions, (\d+) double boxes.*?([\d.]+) s$", rows[28]) half = (len(body) + 1) // 2 with open(os.path.join(OUT, "tab_bench.tex"), "w") as f: f.write("\\begin{table}[!htbp]\\centering\\footnotesize\\setlength{\\tabcolsep}{4pt}\n\\begin{tabular}{@{}lrrrrr@{}}\\toprule\n") f.write("family & systems & as expected & proved complete & certified & ms \\\\\\midrule\n") f.write("\n".join(body)) f.write(f"\n\\midrule\\textbf{{total}} & \\textbf{{{num(40000)}}} & \\textbf{{{num(int(m[1]))}}} & \\textbf{{{num(int(m[2]))}}} & \\textbf{{{num(int(m[3]))} + {num(int(m[4]))} d.}} & \\\\\n") f.write("\\bottomrule\\end{tabular}\n\\caption{Forty thousand systems of twenty-seven families, two to five unknowns for most of them, each solved on one thread (ten at a time). ``As expected'': proved complete, except for the overdetermined systems (every solution kept, or the absence of solution proved), the underdetermined ones (complete, with the degree of the solution set) and the sparse systems of four unknowns (nothing left uncertified). ``d.'': double boxes. ms: mean time for one system.}\\label{tab:bench}\n\\end{table}\n") # the 50 000 polynomials rows = open(os.path.expanduser("~/pandroots-work/bench50k/results_0.21.0.txt")).read().splitlines() body = [] for l in rows[2:12]: name = l[:42].strip() parts = [p.split() for p in l[42:].split("|")] name = name.replace("1e-4 to 1e4", "$10^{-4}$ to $10^{4}$").replace("1e-6", "$10^{-6}$").replace("[-2, 2]", "$[-2,2]$").replace("-9 to 9", "$-9$ to $9$") body.append(f"{name} & {num(int(parts[0][0]))} & {num(int(parts[1][0]))} & {float(parts[1][1]):.3f} & {num(int(parts[2][0]))} & {float(parts[2][1]):.2f} \\\\") with open(os.path.join(OUT, "tab_50k.tex"), "w") as f: f.write("\\begin{table}[!htbp]\\centering\\footnotesize\\setlength{\\tabcolsep}{5pt}\n\\begin{tabular}{@{}lrrrrr@{}}\\toprule\n") f.write(" & & \\multicolumn{2}{c}{the solver of~\\cite{g8}} & \\multicolumn{2}{c}{this method, $n=1$} \\\\\\cmidrule(lr){3-4}\\cmidrule(l){5-6}\n") f.write("family & polynomials & complete & ms & complete & ms \\\\\\midrule\n") f.write("\n".join(body)) f.write("\n\\midrule\\textbf{total} & \\textbf{50\\,000} & \\textbf{50\\,000} & & \\textbf{49\\,995} & \\\\\n") f.write("\\bottomrule\\end{tabular}\n\\caption{Fifty thousand polynomials in one unknown (960\\,386 roots), each solved on one thread by the solver of~\\cite{g8} (\\texttt{pandroots} 0.14.0) and by the method of this note as a system of one equation. On the 49\\,995 polynomials where both are complete, every ball of one meets the discs of the other for the same number of roots.}\\label{tab:50k}\n\\end{table}\n") print("tables written")