{"id":90,"date":"2008-08-11T18:57:52","date_gmt":"2008-08-11T17:57:52","guid":{"rendered":"https:\/\/wpethzprd.ethz.ch\/kowalski\/2008\/08\/11\/enfin-sage\/"},"modified":"2024-02-20T13:40:58","modified_gmt":"2024-02-20T11:40:58","slug":"enfin-sage","status":"publish","type":"post","link":"https:\/\/blogs.ethz.ch\/kowalski\/2008\/08\/11\/enfin-sage\/","title":{"rendered":"Enfin Sage!"},"content":{"rendered":"<p>In previous posts (such as this <a href=\"https:\/\/blogs.ethz.ch\/kowalski\/2008\/02\/05\/can-computers-give-you-a-mathematical-object-part-ii\/\">old one<\/a>), I&#8217;ve mentioned a few computer programs that I use fairly frequently, but one particularly interesting one was missing: <a href=\"http:\/\/sagemath.org\">SAGE<\/a>, which packages together many different scientific software and libraries with a convenient interface around the <a href=\"http:\/\/www.python.org\">Python<\/a> language. The reason was that SAGE may be quite a bit more difficult to install than, for instance, GAP or Pari\/GP (which it actually includes). Or at least, it was for me: my current laptop is quite nice but also quite recent, and so is <a href=\"http:\/\/fedoraproject.org\">Fedora 9<\/a>, which is my Linux distribution. Some SAGE binary packages exist for Fedora 8, but not for Fedora 9 at the moment, and unfortunately there is a subtle packaging issue of some kind with some cryptographic routines that prevent the Fedora 8 package from working. So the current solution is to download and compile SAGE from source. But here another problem arises: the Core 2 CPU is misdetected by one of the packages involved in today&#8217;s version of SAGE (the <a href=\"http:\/\/math-atlas.sourceforge.net\/\">ATLAS linear algebra package<\/a>, version 3.8.1), which sees it as some kind of freaky Pentium III, and then takes forever to build.<\/p>\n<p>As often where open source software is involved, the solution is not very far after a bit of search. In this case, the <a href=\"http:\/\/sagetrac.org\/sage_trac\/ticket\/3787\">issue is known<\/a>, as well as the workaround: commenting out two lines in one of the Atlas source files, and modifiying a third one. Once this is done, the rest of the build process worked perfectly. However, one must notice (or not forget), contrary to what I first did, that the build process of Atlas used by SAGE starts by installing and working from a pristine copy of the source code, contained in a compressed file, which will therefore erase the patched version of the delinquent code if one is not careful&#8230;<\/p>\n<p>What must really be done is to create a new archive with the modified file. And in case anyone else has the same problem and finds this post, here is a copy of such an archive: it is the file <a href=\"http:\/\/www.math.ethz.ch\/~kowalski\/atlas-3.8.1.p3.spkg\"><code>$SAGE_DIR\/spkg\/standard\/atlas-3.8.1.p3.spkg<\/code><\/a>, valid for release 3.0.6 of SAGE (where <code>$SAGE_DIR<\/code> is the base directory where the SAGE files are found), and should be copied (with that name) in that location; this is a 2.8MB file.<\/p>\n<p>(All this will soon be obsolete of course; within a month at most, the necessary patch will have found a permanent place on all the required software).<\/p>\n<p>Now, this being done, I have started reading the documentation to actually use SAGE. Learning it is easier because of the concrete project of adapting the GAP script I have been using to compute <a href=\"https:\/\/blogs.ethz.ch\/kowalski\/2008\/07\/24\/the-chebotarev-invariant-or-wait-and-see\/\">Chebotarev invariants<\/a> (at least, I find this type of manageable project is a good way to adapt to a new programming environment).<\/p>\n<p>For illustration, here is the resulting SAGE program:<\/p>\n<pre>\r\ndef chebotarev(G):\r\n    G1=gap(G)\r\n    g=G1.Order()._sage_()\r\n    M=G1.ConjugacyClassesMaximalSubgroups()\r\n    M1=[i.Representative() for i in M] # Python list\r\n    nbM=len(M1)\r\n    C=G1.ConjugacyClasses() # Gap list\r\n    O=[c.Size()._sage_() for c in C] # Python list\r\n    print O\r\n    print \"Done precomputing\"\r\n\r\n    cheb=0.0\r\n    scheb=0.0\r\n    ar=matrix(len(C),len(M1))\r\n    # C is a GAP lists hence starts at 1.\r\n    for i in range(1,len(C)+1):\r\n        for j in range(0,len(M1)):\r\n            #print i,j\r\n            if C[i].Intersection(M1[j]) != gap([]):\r\n                ar[i-1,j]=1\r\n\r\n    for i in subsets(range(0,len(M1))):\r\n        if len(i) != 0:\r\n            density=0.0\r\n            for j in range(1,len(C)+1):\r\n                isin=True\r\n                for x in i:\r\n                    if ar[j-1,x]==0:\r\n                         isin=False\r\n                if isin==True:\r\n                    density=density+O[j-1]\r\n                    #if len(i)==1: print \"---\", i, C[j], density\r\n            #if len(i)==1: print i, density\r\n            cheb=cheb+(-1)^(len(i)+1)\/(1-density\/g)\r\n            scheb=scheb+(-1)^(len(i))\/(1-density\/g)*(1-2\/(1-density\/g))\r\n    return cheb, scheb<\/pre>\n<p>(Since this is actually Python code, remember that the indentation is significant if copying the script).<\/p>\n<p>Compared with the earlier script, notice that while the &#8220;mathematical heart&#8221; of the computations are still done in GAP (the maximal subgroups and the conjugacy classes are computed in GAP from SAGE), the logic is written in the Python language. This has a number of advantages in this case: (1) it is easy to loop over all subsets of the maximal subgroups (GAP doesn&#8217;t have a command to get all subsets of a finite set; I had to implement it by interpreting subsets as bit patterns of integers, and the annoyance of this was compounded by the absence of a bitwise &#8220;and&#8221; operator in GAP&#8230;); (2) it is easy to get a real approximation instead of a rational number with enormous denominator (the Chebotarev invariants are rational numbers of this type as soon as the group is not ridiculously small); GAP doesn&#8217;t implement any floating point operations, and earlier I transferred the rationals to Pari\/GP to get such real approximations&#8230; (Note that Magma does not have the two defects mentioned here, and as I said before, it is currently more efficient for some of these computations).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous posts (such as this old one), I&#8217;ve mentioned a few computer programs that I use fairly frequently, but one particularly interesting one was missing: SAGE, which packages together many different scientific software and libraries with a convenient interface around the Python language. The reason was that SAGE may be quite a bit more &hellip; <a href=\"https:\/\/blogs.ethz.ch\/kowalski\/2008\/08\/11\/enfin-sage\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Enfin Sage!<\/span><\/a><\/p>\n","protected":false},"author":625,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[904,2],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-computers","category-blogroll"],"_links":{"self":[{"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/users\/625"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":0,"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ethz.ch\/kowalski\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}