SageMath – Open-Source Mathematical Software System
sagemath.org
sagemath.org
1. Grobner basis: http://bollu.github.io/#computing-equivalent-gate-sets-using...
2. Commutators of subgroups: http://bollu.github.io/#5age-code-to-play-around-with-commut...
3. Graph/group theory: https://github.com/bollu/bollu.github.io/blob/2f88c28efc54fb...
One application of Gröbner bases is to solve systems of polynomial equations [0], and characterize their solutions. In many circumstances it is not however the best method, for example if you are content with a numerical solution you can use other techniques.
Notice that this concerns equations, not inequalities. After a cursory search, I cannot find any "big" reference for solving polynomial inequalities using Gröbner bases. There is this [1], still, not sure how serious it is.
[0] https://en.wikipedia.org/wiki/Gr%C3%B6bner_basis#Solutions_o...
So suddenly I was in the situation of dealing with maths that was harder than anything I'd done at school years and years ago.
In the end I transliterated the equations into sage, checked the results carefully and then wrote the PHP to do the same calculations using a large set of tests against the official stuff, stressful two weeks but sage was useful as hell.
My other gripe, more objective than the above, with Sage is the lack of good documentation. The documentation is certainly complete, but it is painful to read. Mathematica documentation is a treat to read. Every function has its own page with plenty of examples to show capabilities, and show relations to other functions.
With Sage I constantly have to search the web to how to do things, while in Mathematica, I rarely had to leave the inbuilt help.
Regarding examples, currently there are 50,283 functions defined in the Sage library, and 96.8% of these functions have documentation that is illustrated with working tested examples. Also, you can read the source code of 100% of these functions (unlike with Mathematica) in case something isn't clear. Much of the Sage reference manual (find it here: https://doc.sagemath.org/) is autogenerated from the sagemath library source code; that's why there are 1,287,666 source lines of comments in sage, versus 636,899 lines of non-comment code.
First of all I wanna say that Mathematica/Wolfram Language is not just functional and certainly not purely functional.
Thus said, I feel trying to be purely functional has its drawbacks whenever you have to keep track of a lot of stuff that requires state: for example if you have to declare that some of your constants are real you end up having to use Assuming or Assumptions a lot and that can get verbose quickly. Setting the $Assumptions global makes for terser code.
If you wanna dig more into the differences of the two approaches in the same language you can look at the xAct package vs. the built-in symbolic tensors: xAct has many more features but feels less idiomatic, because you have to set they type of your symbols beforehand and expressions are not really self-contained.
One of the best features of Mathematica documentation (https://reference.wolfram.com/) is that every function has its own page, and there are helpful links to related functions. I have found so many functions via these links. I really wish Sage had something like this.
This is an important observation. The source is the ultimate documentation, and, in many cases (in my experience) the only correct documentation for a software system. If you can’t see the source, you don’t know what the program does, you only know what someone says it does (aside from exhaustive experimentation).
Simple arithmetic, or even computer-algebra simplifications are too simplistic. They help with high-school stuff but are useless for higher math where the bread and butter are theorem-proof-theorem-proof based learning/understanding/research.
Geometric plotting/vis, again, good for high-school and freshman stuff mainly. (Plotting is useful for research, data science, numerics, what not, but that's a whole other story. And computer graphics is a rabbit hole).
Same with Analysis. Good to have an automatic integrator for Calculus, useless for Real Analysis.
Numerical calculations are too laborious and you have to have a good understanding of a wide body of numerical literature, plus have experience. (again a rabbit hole)
That leaves us with proof-assistants, model-checkers, and small-scale automatic theorem-provers. And experience research mathematicians are still learning those.
Am I missing something?
But I think one example would be: you're investigating something and get a large linear system, a polynomial, etc. Sage can solve equations with symbols. It saves a lot of manual labor. Various expressions can be manipulated, simplified, etc. It can readily verify equality of huge expressions (which can be error prone by hand), and so on. More specific fields have more specific tools that could be used to assist, so it would depend on the field I guess.
See here:
https://ask.sagemath.org/question/24866/how-to-simplify-with...
Edit: I also think it should be fairly common to need to perform an actual numerical calculation in mathematical work? I think it's quite better than a simple calculator for that too, since it gives exact e.g. rational results, and approximations would be unfit for a proof (unless extensive precautions are made).
I remember I got an expression for an eigenvalue of a matrix (as a function of some parameters) that would be very laborious to get by hand.
I asked a coworker about it, someone who had previously worked on Sage. It sounds like some parts of the community are now favoring using lighter-weight libraries directly (like SymPy for symbolic math).
I discovered that Sage is not pure Python: Sage is translated to Python before running, which is how it can support syntax like "f(x) = x + 1" to define a function (whereas in pure Python you would need to use "def".
The reason Sage is currently distributed this way is similar to the reason Anaconda exists, which is that Python's package manager isn't (or wasn't in 2005 when I started this!) meant to build something as complicated as Sage, which has about 100 complicated dependencies. I really hope this eventually changes someday and people can type "pip install sagemath" and get something useful.
Oh, I think for several Linux distributions there are SageMath packages that just build Sage into the standard system-wide Python. So if you're using Linux, the problem may already be solved for you.
(I realize that this response is probably useless for the Sage author, but hopefully will benefit others who struggle with installation)
[1] https://doc.sagemath.org/html/en/installation/conda.html#sec... [2] https://hub.docker.com/r/sagemath/sagemath/ [3] https://github.com/NixOS/nixpkgs/blob/master/pkgs/applicatio...
I've never met anyone who uses Sage and work at large research center. If your college background is math, you used Matlab in school. If your background is in computer science, you go with Python or another programming language. Sage seems like the middle ground between those two, but who is that?
The cases posted here seem to be like yours where there is occasional need for workers or students whose employer or school doesn't or won't supply a Matlab license. Matlab is in most college math departments and offers keys directly to students for like $50-100, so there are few of those cases. An employer with math researchers isn't going blink at the $2k for a perpetual license, so anyone doing the work regularly gets Matlab who wants it.
I do think Sage is good software and it is important to have a free alternative to Matlab. The audience is pretty limited, though.
- Research mathematicians often use Sage not just because they are "freedom-loving folks", but because their research fundamentally demands that they can see, modify and extend the source code of the software they are using to do computations, and in many cases this simply isn't possible with commercial options.
First of all IANAL not an expert on free software nor is any of this legal advice. Also this post is a bit tangential to the OP topic as it talks mostly about free software. Seeing modifying and extending the source code is exactly what free software is about. If you need or want that then you would often appreciate the free software movement. Free software can be commercial it just usually comes with some form of support or more looser licensing options that you would pay for in order to use it in a closed source product. Really I mainly say this to mention that free software is not free as in price but free as in freedom to see, change, and modify as you see fit. (I assume the parent poster already knew most of this and what I’m about to say by his use of ‘just, but I wanted to make this point more clear to anyone else who may not understand the purpose of free software.) It has taken me a while to understand the ethos, pathos, and logos of the whole free software movement and I’m sure there’s a whole lot more I could learn about it, but I am convinced it is a very necessary and good thing. It has troubled me that I can’t just throw in a GPL licensed software into a commercial product willy-nilly, but I appreciate what free software has accomplished due to it’s principles towards that freedom mentioned above and that is why I think it has accomplished them. I couldn’t imagine a world without Linux and other nice free softwares. I think without the principle of freedom that free software sticks to and has mandated in its licensing has freed a lot of developers that buy into that message a lot less fear that their work will be taken over by some who don’t value that freedom to see, change, and modify the software. I think in that sense those scientists who want the ability for those and themselves in the future to see modify and extend software are very much “freedom-loving folks”.
Sage can deal with these tasks as well as Matlab, simply by virtue of having interfaces to NumPy/SciPy/Octave/others, but this is not where Sage shines. Sage is indispensable for research math (some examples I understand: group theory, cryptography, abstract algebras; but there are many others that are far beyond my level of math education).
In short, I think you are misrepresenting or missing who Sage is really useful for. Matlab simply does not have these features. The competitors would be Mathematica/Maple/Magma.
Not all employers can splash for matlab. You might be right about a simple license, but in my experience most matlab developers rely on toolkits which ratchet that price up through the roof.
For one example, somebody I worked with rewrote the parfor functionality as a c extension, because we couldn't justify the expense of that addon for every seat. Not a great use of that math researcher's time, but it got the job done, I guess.
I and a couple others at my company showed that Python / Cython could be meet and beat matlab's performance, and we built up an open source stack that our customers love and contribute to -- good luck doing that with matlab.
Our physicists found that the only feature they needed of matlab was its plotting functionality -- so they rewrote that in their native lisp and moved on with their lives.
Today, we only need a few seats for some researchers with seniority. I can't say how much we're saving, obviously, but we eliminated a significant cost in two departments' budgets and our finance folks are quite pleased.
My regret in this is that I used to be a Sage developer, but I've only got so much sway at the company and GPL'd code is a no-go.
This is as misinformed as you can get. Matlab is not meant for math - it's meant for computation and the target is science/engineering. Sage likely does a lot that Matlab doesn't do well.
> I've never met anyone who uses Sage and work at large research center.
My company has licenses for MATLAB and Maple. Still, quite a few employees prefer to use Sage over those two.
sage: p = 19; p.is_prime()
True
sage: K = GF(p); K
Finite Field of size 19
sage: E = EllipticCurve(K, [5, 9]); E
Elliptic Curve defined by y^2 = x^3 + 5*x + 9 over Finite Field of size 19
sage: E.count_points(), E.order(), E.gens()
(19, 19, [(4 : 6 : 1)])
There are far too many things to name that sage can do, but the CLI has a great autocomplete. Here's an example: let's say you have ECDH with point compression, and you specify only an x coordinate. Point compression limits the effectiveness of invalid curve attacks, where an attacker gives you a maliciously picked Diffie-Hellman value that isn't actually on the curve you're supposed to be on. However, if the x coordinate doesn't map to a point on the curve, it's necessarily on its "nontrivial quadratic twist". Sage makes this easy to play with because sage makes pretty much everything easy to play with: sage: E.lift_x(6, all=True)
[]
sage: E.quadratic_twist()
Elliptic Curve defined by y^2 = x^3 + 6*x + 13 over Finite Field of size 19
sage: E.quadratic_twist().lift_x(6, all=True)
[(6 : 6 : 1), (6 : 13 : 1)]
If you want to do a full-on invalid curve attack, the easiest way to do that is with Sage. You look up how the explicit formulas work in the EFD[efd], you write a ladder, you figure out how to create other elliptic curves for which the short Weierstrass doubling formulas still work (which parameter doesn't appear in the formula?), and then just let sage generate every possible curve and see which ones have the poor cryptographic properties you're after.There's a reason the introduction to Cryptopals Set 8[set8] sends with the words:
> By the time you're done, you will have written an ad hoc, informally-specified, bug-ridden, slow implementation of one percent of SageMath.
As much as I'm a Clojure fanboy none of the Java libraries come even close. Unfortunately, sage is mildly annoying to use/install as a Python library (that would help interop significantly).
[efd]: https://www.hyperelliptic.org/EFD/g1p/auto-shortw.html
[set8]: https://cryptopals.com/sets/8
https://doc.sagemath.org/html/en/prep/quickstart.html
These contain have examples for linear algebra, calculus, diff equations, statistics, etc.
I use sagemath with Jupyter lab and it works pretty well. You can evaluate an expression and ask sage to output the LaTeX code for it, so you can have everything nicely formatted.
It's an amazing bit of kit. But I'm not without criticisms. I feel it could do with the kind of fresh-start overhaul that really isn't practical for an open-source code base of this nature. E.g. move python 2.6 to python3. Also, you have excellent multi-precision support, but many of the algorithms from other modules don't support precision beyond machine lengths.
But really really good. Love it.
Since version 9.0 released in January 2020, SageMath is using Python 3.
I once used Sympy to parse formulas written in infix notation and convert them to S-expressions. But that's just less than 1% of what Sympy can do. I'd like to find more uses for it.
I'm a weensy bit biased; I probably took part in conversations around the plotting interface as it was taking shape, and got familiar with that before learning matplotlib in earnest.
What happened is that in 2006 I hired Alex Clemesha to implement a "Mathematica-like API on top of matplotlib for Sage", and he spent a year doing so. Then Robert Bradshaw (lead dev of Cython) and Carl Witty wrote some really sophisticated just in time compiler code to make it more efficient to evaluate symbolic expression at many floating point values, which helps in plotting (especially for 3d plots). Over many years after that other people filled in little missing pieces of functionality and exposed more of Matplotlib's functionality, and also just added a bunch of new functionality (e.g., for drawing gridlines, 3d implicit plots, etc.) that wasn't available in the Python ecosystem.
And that's Sage's plotting functionality...
https://news.ycombinator.com/item?id=19682126 - "Should I Resign from My Full Professor Job to Work Fulltime on Cocalc?" - 2019
https://news.ycombinator.com/item?id=19485166 - "Computational Mathematics with SageMath" - 2019
https://news.ycombinator.com/item?id=11883987 - "The Origins of SageMath" - 2016
https://news.ycombinator.com/item?id=11078220 - "Open source is now ready to compete with Mathematica for use in the classroom" - 2016
https://news.ycombinator.com/item?id=10175563 - "The Simons Foundation and Open Source Software" - 2015
https://news.ycombinator.com/item?id=10147401 - "React, Flux, RethinkDB and SageMathCloud – Summer 2015 Update" - 2015
https://news.ycombinator.com/item?id=2088871 - "SageMath: Python-based Mathematics. Rock it." - 2011 - a little bit of editorializing there...
https://news.ycombinator.com/item?id=983423 - "Conception, birth and developement of a Free math software (Sage)" - ditto...
https://news.ycombinator.com/item?id=179416 - "Sage: Can There be a Viable Free Open Source Alternative to Magma, Maple, Mathematica, and Matlab?" - 2008
Any others?
Yes, better tooling would be nice. But I think better math support would be better. I encourage everyone to read William Stein's posts on the challenges they face on that front (incredibly hard to get funding, etc). Their resources are very limited, and they have to prioritize heavily.
I'm a physicist, and the most I'd need a CAS for is essentially mathematica's "Simplify". DESolve is great too but back then (2010 or so) Sage's diffeq solvers felt limited.
A bit surprised to hear that, though. Do you mean Sage is better in algebraic number theory as a whole, or is it more of some aspects are better with Sage and others with Mathematica?
Any one done a writeup comparing the strengths of Sage w.r.t Mathematica/Maple/etc? (In detail, not just big picture).
EDIT: got some names wrong, here's a possible starting point for this rabbit hole https://def.fe.up.pt/pipermail/maxima-discuss/2009/029211.ht...
Ideas from STEM (Science Technology Engineering and Mathematics) are pretty large and pervasive throughout the tech industry. I think there are also a large area of tech startups that could come from any area of STEM. Also one of the goals of info on hacker news is to be intriguing to hackers themselves and to fulfill some sense of intellectual curiosity. For me personally SAGEMath opens doors for me as a programmer to better understand abstract math concepts that might or might not have relevance to my daily work as a programmer and as a cofounder. In that sense I think SAGEMath helps fulfill that intellectual curiosity. Heck it may even help me complete that next projecteuler problem. (Which also is only done for the fun and experience of it.)
Also people who come up with really creative company ideas or that build free software that really do something quite amazing are often at the intersection of tech and some other field. This is not to say that tech solves all other fields’ problems. It’s that tech can benefit other fields when it takes the approach of how can I make this field’s work easier which often comes from a good amount of knowledge of how that field actually works otherwise it’s just too superficial. SAGEMath is a great example of tech actually helping research mathematicians and most of it is made by mathematicians themselves (who clearly have some programming prowess.)
By the way I’m sorry you were downvoted. Looking at your profile I see you’ve only been on here for 82 days. I see your comment as very genuine but I also understand a little of why you might have been downvoted but for that I’ll just point you to the sites guidelines:
https://news.ycombinator.com/newsguidelines.html
The original post very clearly meets the guidelines though it is not your typical news, it is news to hackers. Happy Hacking. :)