# SageMathメモ 資料がほぼ英語しかなくて辛いのでメモ ## SageMathインストール https://www.sagemath.org/download.html からOSとダウンロードするサーバー(日本のRikenでOk)を選ぶ なんかコンパイラを選べと言われるが適当にIntelでok(適切なものを選べばよさそう、自分はIntelだった) 圧縮ファイルをダウンロード->解凍 ターミナルにて/SageMath下で```./sage```と叩くとSageMathのインタラクティブ環境が起動する 完了 余談:オンライン環境もあるらしい https://sagecell.sagemath.org ## SageMathでQEPCADインターフェースを叩くまで [ドキュメント(SageMath 9.1)](https://doc.sagemath.org/html/en/reference/interfaces/sage/interfaces/qepcad.html)を参照 そのまま叩くとRuntimeErrorで死ぬ ← optionalのパッケージをダウンロードしないとダメっぽい? 苦労して色々エラーでググると同じ原因で死んでそうな人を発見(https://trac.sagemath.org/ticket/16642) ターミナルにて```/SageMath```下で```./sage -i qepcad```と叩くとパッケージがインストールされ始めた なんかこんなことを言われた、やっぱりbeta版なのか... ``` =========================== WARNING =========================== You are about to download and install the experimental package qepcad-B.1.72. This probably won't work at all for you! There is no guarantee that it will build correctly, or behave as expected. Use at your own risk! =============================================================== Are you sure you want to continue [Y/n]? ``` 怖いけどまぁインストールしてみないと始まらないのでYes とてつもなく時間がかかる(1h以上?) 完了したがビルドにこけた...? ```bash [sagelib-9.1] error: command 'gcc' failed with exit status 1 [sagelib-9.1] make[3]: *** [sage] Error 1 [sagelib-9.1] [sagelib-9.1] real 84m9.049s [sagelib-9.1] user 78m21.869s [sagelib-9.1] sys 4m9.310s make[2]: *** [sagelib] Error 2 make[1]: *** [all-build] Error 2 real 84m15.875s user 78m26.593s sys 4m11.100s *************************************************************** Error building Sage. The following package(s) may have failed to build (not necessarily during this run of 'make all-build'): It is safe to delete any log files and build directories, but they contain information that is helpful for debugging build problems. WARNING: If you now run 'make' again, the build directory of the same version of the package will, by default, be deleted. Set the environment variable SAGE_KEEP_BUILT_SPKGS=yes to prevent this. ``` しかしドキュメントの楕円の式のQEには成功しているように見える ```sage Kousuke-no-MacBook-Air:SageMath SHU$ ./sage ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 9.1, Release Date: 2020-05-20 │ │ Using Python 3.7.3. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: var('a, b') (a, b) sage: qepcad(a < b) b - a > 0 sage: var('a,b,c,d,x,y,z') (a, b, c, d, x, y, z) sage: ellipse = 3*x^2 + 2*x*y + y^2 - x + y - 7 sage: F = qf.exists(y, ellipse == 0); F --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-5-3dc1d08f68f4> in <module>() ----> 1 F = qf.exists(y, ellipse == Integer(0)); F NameError: name 'qf' is not defined sage: qf = qepcad_formula sage: F = qf.exists(y, ellipse == 0); F (E y)[3 x^2 + 2 x y + y^2 - x + y - 7 = 0] sage: qepcad(F) 8 x^2 - 8 x - 29 <= 0 sage: qepcad(qf.exists(x, ellipse == 0)) 8 y^2 + 16 y - 85 <= 0 sage: ``` ひとまず完了 ## Jupyter NoteBook 導入 ```./sage -n jupyter```でjupyterがブラウザに立ち上がる Newから新しいファイルを作れる ![](https://i.imgur.com/p7Hra2Q.png) 完了 ## 数独を解く \begin{equation} x_{ijk}\in\{true, false\} \forall{i, j, k} := (i, j) にある数字がk(0\leq k \leq 9)であるかどうか\\ \end{equation}