Lynn Bradshaw via plug on 6 Jan 2022 19:07:25 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Topics for PLUG in January


Of course it does but it doesn't look like regular math on paper.
That's why SageMath replaced **. It looks a lot nicer in my opinion.
Another good example of the SageMath difference: consider Euler's
identity. With regular Python:

from math import e, pi

print(e**(1j*pi) + 1)

Output:

1.2246467991473532e-16j

Very, very close. But not right. With SageMath:

print(e^(i*pi) + 1)

Output: 0

Perfect. No imports even needed and it looks better too.

On Thu, Jan 6, 2022 at 9:03 PM Walt Mankowski via plug
<plug@lists.phillylinux.org> wrote:
>
> By "have ^ like SageMath does", do you mean exponentiation? In that
> case, yes, since Python does exponentiation with the ** operator.
>
> On Thu, Jan 06, 2022 at 08:34:03PM -0500, Lynn Bradshaw via plug wrote:
> > I'm using Gmail (web client) here which means I won't (AFAIK) be able
> > to continue the thread as in your reply. Or possibly I can but I'll be
> > uncertain about the outcome. Top posting it is then. Sorry about that.
> >
> > Anyway, I do have some vague memory of having to implement some kind
> > of dynamic programming thing where NetworkX wasn't quite going to cut
> > it so that's true. And rolling your own vs. using SageMath etc. are
> > both legitimate in their own ways, yes.
> >
> > Regarding Python, I was pleased to see that underscores in number
> > literals are in fact supported but that was only in PEP 515
> > (https://www.python.org/dev/peps/pep-0515/), making it pretty recent.
> > That will come in handy. And does Python have ^ like SageMath does?
> > Yes and no. Yes, in the sense that you can override __xor__ in your
> > own classes that you write. SageMath however extends the intended
> > outcome typically expected in such a package to builtin number types.
> >
> > On Thu, Jan 6, 2022 at 8:17 PM Walt Mankowski via plug
> > <plug@lists.phillylinux.org> wrote:
> > >
> > > On Thu, Jan 06, 2022 at 07:23:11PM -0500, Lynn Bradshaw via plug wrote:
> > > > The scare quotes are there because it was a tongue-in-cheek remark.
> > > > True cheating would be stealing others' code or looking up the answers
> > > > and just plugging them in. (They're all some easily verified
> > > > non-negative integer as opposed to the approach many other sites use
> > > > with an automated code judge.)
> > > >
> > > > Having said that, for some it might subvert what they deem the true
> > > > purpose of Project Euler, which would be to develop a full grasp of
> > > > the mathematical principles underlying the puzzles and implement all
> > > > one's own algorithms to get the answer.
> > >
> > > I don't know how far you've gotten through Project Euler. I've done
> > > the first 100 problems, plus 16 more in the next set of 50. The first
> > > set of 50 can generally be solved with a brute force approach. After
> > > that they increasingly require some mathematical insight that
> > > something like a graph library isn't necessarily going to help you
> > > with.
> > >
> > > I'm not saying to NOT roll your own. In fact, problem sets like these
> > > are a great thing to practice on. I'm just saying that it's also a
> > > good way to learn what sorts of tools are available so that you DON'T
> > > have to write your own.
> > >
> > > > For a little bit, I was using
> > > > SageMath to do them. Here's a description of SageMath from the
> > > > website:
> > > >
> > > > "SageMath is a free open-source mathematics software system licensed
> > > > under the GPL. It builds on top of many existing open-source packages:
> > > > NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more.
> > > > Access their combined power through a common, Python-based language or
> > > > directly via interfaces or wrappers.
> > > > Mission: Creating a viable free open source alternative to Magma,
> > > > Maple, Mathematica and Matlab."
> > > >
> > > > (Yes, it's very close to Python except with embellishments like ^ for
> > > > exponentiation and underscores in numbers to make them easier to read,
> > > > which Python badly needs. In fact you can see how it transpiles to
> > > > Python.)
> > >
> > > I'm confused by this statement. Python already lets you put
> > > underscores in numbers. It also has an exponentiation operator, but it
> > > uses ** since ^ is already used for bitwise-or (presumably copied from
> > > C).
> > >
> > > Walt
> > > ___________________________________________________________________________
> > > Philadelphia Linux Users Group         --        http://www.phillylinux.org
> > > Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> > > General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug
> > ___________________________________________________________________________
> > Philadelphia Linux Users Group         --        http://www.phillylinux.org
> > Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> > General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug
> ___________________________________________________________________________
> Philadelphia Linux Users Group         --        http://www.phillylinux.org
> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug