4 ms·
SymPy is great! On one hand it's great that it was written in Python and fairly extensible thanks to that, but on the other it's a shame, since it probably wil
by tikej 6y ago
SymPy is great!
On one hand it's great that it was written in Python and fairly extensible thanks to that, but on the other it's a shame, since it probably will never be fast enough for high performance symbolic computing.
That said I think CASes (Computer Algebra Systems) are heavily under-utilised nowadays. Schools and universities should use is as widely as possible i.e. it should be even more widely used than calculator is/once was. I believe that for every two hours of regular pen-and-paper exercises there should be at least one hour of CAS assisted computer exercises. It's pretty radical and sadly there aren't enough teachers (even in good universities/colleges), that know CASes enough to teach that, so it isn't gonna happen any time soon. Maybe I'm biassed here (I hated doing repeated exercises, such as algebraic simplifications, fraction simplifications etc. in high school), because I use CASes as crutches for doing tough math, but I believe sciences would benefit if more papers in math and physics was written as a code (less mistakes, plus it's not a mistake – it's a bug!). Hopefully it will happen someday and we will have "open source derivations" of formulas, theories, theorems etc. :)
That said, the thing about CASes I'm missing most is more hand guided, step-by-step and mathematical transformations assistant approach. Recently they added a bit of this kind of functionality to Mathematica 12 (sadly I use it most of the time, despite it being closed source) – functions like AddSides, MutiplySides, ApplySides – but I think it's still too automatic for what I have in mind. Hopefully when I finish my PhD I will have some time to work on the kind of "assistant CAS" I have in mind using projects like SymPy, Maxima and Reduce for some parts. What I have in mind is to make hand-like derivations using CAS and let it do small things, like I want to substitute log(a) as x in integral, so find dx for this substitution (actually SymPy has this functionality, even though slightly limited at the moment! [https://github.com/sympy/sympy/blob/58e1e9abade7c38c66871fd06bf76ebac8c1df78/sympy/integrals/integrals.py#L153-L370] https://github.com/sympy/sympy/blob/58e1e9abade7c38c66871fd0...) and do more things this way (series, equations, inequalities, derivatives, limits, operators etc).
Yeah, it's probably more suited for series of blog posts than HN comment but if someone knows FOSS software that is focused on this kind of approach I'll be thankful for links to articles code etc.
- smt1 6y agoI agree, although anecdotally, there seems to be an increasing amount of courses teaching Sage. Sometimes free books/lecture notes are published here: https://www.sagemath.org/library-publications.html#books https://www.sagemath.org/library-publications.html#books Sage is a lot larger than Sympy (it's more than 1 million LOC AFAIK), but it still delegates to other libraries to do most types of underlying symbolic and numerical computations. I usually use sympy (or rather some wrapper of symengine these days) when I'm writing a pure python script, sage otherwise. For a lot of math and CS courses, I think having some knowledge of some sort of computer-assisted theorem proving. I think the most promising is maybe Lean these days (Coq still might take too long to learn): https://github.com/leanprover-community/mathlib https://github.com/leanprover-community/mathlib
- bocklund 6y agoEven though SymPy is written in Python, there are several options to go much faster. The simplest is when actually using the symbolic expression to do some calculation. For that SymPy has a `lambdify`, which can make a callable using NumPy as the backend. They also have a variety of code printers to write your expression in C/Fortran/Julia/<many others> that you can compile to be very fast. There’s also the SymEngine project, which is a rewrite of SymPy in C++ with bindings to other languages (like Python where it is a drop-in API replacement for SymPy). It’s not finished yet, but the CAS is a lot faster and it’s lambdify can give you an internal representation or an LLVM-compiled version, both of which are much faster than SymPy in compile-time and run-time for our expressions (which are often quite large, but simple in terms of the mathematical functions used).
- tikej 6y agoSure, but that's numerics. What I meant by high performance symbolic computing was things integrating hundred term expression or expanding, manipulating and simplifying expressions of similar lengths or solving (diagonalising) 9x9 matrix with symbolic expressions. Unfortunately in these applications SymPy is (painfully) slow, although I haven't tried using PyPy backend for this. Yeah, SymEngine is a great idea and it is a lot faster, but its functionality is very limited compared to SymPy. The development is slower than SymPy and I suppose its due to the fact that its in C++, which is more difficult to write after all. Therefore I don't believe it will ever catch up with SymPy features and it boils down to the two-language problem. I think Julia (with multiple dispatch, parametric type system and JIT) is a great candidate for CAS, but it's still very far behind SymPy (although the nice thing is that functionalities can be "borrowed" via PyCall until they are rewritten).
- ChrisRackauckas 6y agoJulia's ModelingToolkit.jl is already pretty far along and has a lot of SymPy, plus extra features like parallel simplification and generation of parallel sparse functions via its form of lambify. See the first tutorial on that: https://mtk.sciml.ai/dev/tutorials/symbolic_functions/ https://mtk.sciml.ai/dev/tutorials/symbolic_functions/ . The equation solver is in progress right now and is moving along quite fast. The nice thing is that this will all use Julia's multithreading, since separate tree cases are mostly independent so there's a lot of parallelism that the symbolic pieces can use here.
- ABeeSea 6y agoWhen I was getting my math degree at a large public state university, a lab class in Mathematica was a requirement for freshmen/sophomore math majors. I had a free student license for my laptop and it was available on every lab computer. I used it extensively during every math class I took during my degree even though I never had another “coding exercise” in any those classes. I’m damn sure not calculating permutation groups by hand.