News for hackers. Stuff that matters.
Re: by westurner on Saturday February 25, 2023 @06:41PM (#34941611)
> They have other things to smooth out the parts of python which are annoying in math, like exponentiation works with ^, and dividing integers returns a rational number instead of floating point or an integer.

SageMath also has a multivariate inequality solver IIRC. `*` is repeated multiplication (exponentiation) in Python. If you require preprocessing to translate ^ to *, you don't have valid Python code that'll run with any other interpreter.

Is it easier to import SageMath from a plain Python script now; with conda repackaging?

Type promotion in Python:

   from rational import Rational
   assert Rational(1, 4) / 2 == Rational(1, 8)
Python 2 had a __future__ import to do floatdiv instead of floordiv:

  from __future__ import division
  assert 3 / 2 == 1.5
  assert 3 // 2 == 1
  assert 4 / 2 == 2.0
Python 3 returns floats from ints or decimals IIRC:

   assert 3 / 2 == 1.5
   assert 3.0 / 2 == 1.5
   assert 3 // 2 == 1
   assert 4 / 2 == 2.0
Re: by williamstein on Saturday February 25, 2023 @06:53PM (#34941677)
> Is it easier to import SageMath from a plain Python script now; with conda repackaging?

Yes, it's easy. It was always possible, since fortunately none of the Sage library implementation uses the Sage preprocessor. You could always do "sage -python" and you get the Python interpreter that Sage uses, and can import Sage via "import sage.all". Somebody asked me exactly this question at a colloquium talk I gave on Sage yesterday, and here's my answer/demo:

https://youtu.be/dy792FEh1ns?t=1140

In the demo, I use a Jupyter kernel that runs the Python included in Sage-9.8.

Disclaimer: I created the Sage preparser long ago, in order to make Sage more palatable to mathematicians. In particular, it was inspired by audience feedback during a live demo I did at PyCon 2005.

Re: by williamstein on Saturday February 25, 2023 @07:05PM (#34941762)
> They have other things to smooth out the parts of python

I should add that this is an interesting chunk of Python code, and we've always planned to separate it out from Sage as a separate library than could be used with Sympy, etc.

https://github.com/sagemath/sage/blob/52a81cbd161ef4d5895325...

It does a surprising number of little clever things we realized would be a good idea over years, and it has some neat ideas from various Python PEP's like [1..10] that were rejected from Python, but are very useful when expressing mathematics. It's also annoying when you just want to format your code using prettier (say), and you can't because Sage isn't Python. :-(

Re: by westurner on Monday February 27, 2023 @02:41PM (#34960930)
Recently I've been working with the %%ipytest magic command for running pytest in notebooks.

Is there a %%sage IPython magic method that passes code through the preparse.py input transform?