3 ms·
Usually I would agree, but it is written in the context of SymPy, as symbolic math library. There I would expect 1/2 is the solution to 2*x=1 .
by yk 10y ago
Usually I would agree, but it is written in the context of SymPy, as symbolic math library. There I would expect 1/2 is the solution to 2*x=1 .
- gshulegaard 10y agoWhether or not SymPy gives int(1)/int(2) as a float or Python gives int(1)/int(2) as an integer are wholly different things. In the context of a programming language, I have to agree with wyldfire that int-on-int operations should yield integers. Now if SymPy wanted to override the base behavior, I think they absolutely should! I could even understand that the context of symbolic math makes this the least surprising outcome. But Python is a programming language, not a Domain Specific Language.
- fdej 10y agoOn the other hand, 1/3 is still not the (exact) solution to 3*x=1...
- lrem 10y agoBut it can be done, even in systems implemented in Python 2. Try the following in http://sagecell.sagemath.org/ http://sagecell.sagemath.org/ x = 1/3 3 * x == 1
- williamstein 10y ago1. I introduced the "Sage preparser", which does things like replacing "1/3" by "Integer(1)/Integer(3)" in Sage, before feeding that input to Python to be evaluated; Robert Bradshaw also did a lot of work on the preparer. The preparser uses a hook into the IPython evaluation system. I decided I really needed Sage to use a preparser like this during a talk I gave at Pycon 2005, based on audience feedback, which is why it exists. 2. I would really like somebody to remove the preparse code from Sage and make it a standalone library available on pypi. Here's the code (happy to relicense it under BSD): https://github.com/sagemath/sage/blob/master/src/sage/repl/preparse.py https://github.com/sagemath/sage/blob/master/src/sage/repl/p... 3. Permalink to your example -- http://sagecell.sagemath.org/?q=nwzdzn http://sagecell.sagemath.org/?q=nwzdzn