High-Powered Mathematical Software in your Browser

in #mathematics6 years ago (edited)

SageMath (or just "Sage") is open-source mathematics software, written in Python. The project's self-proclaimed mission is "a viable free open source alternative to Magma, Maple, Mathematica, and Matlab."

An easy way to try it out is SageMathCell, a web front end which can be embedded in your own web pages. (Not, alas, in Steem markdown.)

Unfortunately, as far as user friendliness goes, it lacks the natural-language capabilities of Wolfram Alpha and the accessible documentation of Mathematica. The code above factors a polynomial. But if you want the symbolic representation instead... well, I couldn't make head or tails of the answers here: https://ask.sagemath.org/question/39772/factoring-polynomials-with-symbolic-expressions/

Sage is very comprehensive in the algebraic structures it provides: rings, fields, p-adic numbers, etc. Unfortunately, that often means that a Google search for help will turn up something incomprehensible to mere mortals, rather than a straightforward example. People who need Sage really need Sage... those with lesser requirements probably use a different tool. I mean, even the quickstart guide goes from 1+1 to the very next line V=QQ^3 which defines a vector space over the rationals.

Here's an example of something you can do easily in Sage that is hard in Wolfram Alpha.

A Real Quadratic Field

x^2 - 17 doesn't factor over the rational numbers, but it does factor over the reals as (x + sqrt(17))*(x - sqrt(17)). Instead of using the real numbers, we can create the smallest possible extension of the rational numbers where it does factor, a Quadratic Field. This is just a fancy name for number of the form a + b*sqrt(17), where a and b are rational numbers. To add two of them you just add the corresponding a and b parts. To multiply, treat the two numbers are binomials, use FOIL, and simplify sqrt(17)*sqrt(17) to 17 like usual.

Like the field of rational numbers, a quadratic field has a subring of "integers", called the Quadratic integers.

Naturally, Sage lets you create these:

>>> K.<y> = NumberField(x^2-17)
>>> K
Number Field in y with defining polynomial x^2 - 17
>>> (3+4*y)*(-3+y)
-9*y + 59

We told Sage to create a number field, call it K, and call its generator y. In this case the generator just means "a root of the defining polynomial", i.e., a square root of 17. (Which square root you use doesn't matter.)

The generator y can be used to create other expressions to operate on. 3+4*y means 3+4*sqrt(17) and we can multiply or add it. Sage doesn't permit multiplication by concatenation; you have to type in the * symbol.

The documentation for NumberField has a few examples for using it, then launches into the Python documentation for every class and method. This is comprehensive but shows one of the weaknesses of automatically-generated documentation: the most relevant material is not always first. Because right after the examples is:

class sage.rings.number_field.number_field.CyclotomicFieldFactory
Bases: sage.structure.factory.UniqueFactory

Return the n-th cyclotomic field, where n is a positive integer, or the universal cyclotomic field if n==0.

The class you're actually trying to use is further down the page, with lots more examples. Don't be discouraged, keep looking--- what you want do to is probably there! It just can be hard to find.

Now we can ask questions both about the real quadratic field we've created, or about individual elements in it. For example, does Q[sqrt(17)] still have unique factorization for its integers?

>>> K.class_number()
1

That means "yes"! See Class Number, although the bit you really want is:

When the class number of a ring of integers in a number field is 1, the ring corresponding to a given ideal has unique factorization and, in a sense, the class number is a measure of the failure of unique factorization in that ring.

So let's start factoring:

>>> factor( 7+0*y )
7
>>> factor( 2 + 0*y )
(-1/2*y - 3/2) * (-1/2*y + 3/2)
>>> factor( 6-6*y )
(-y + 4) * (-1/2*y - 3/2)^4 * (-1/2*y + 3/2)^2 * 3

7 is still a prime. But 2 isn't a prime in this ring! Instead it factors into the product of two other integers (and to make things even more complex, this ring has some integers with half-integer coefficients.) We had to specify 2+0*y rather than just 2 because that's how Sage can tell we're talking about an element of the field K that we defined. There are other ways to do it, like specifying K(2) instead, but I find always including the generator to be the most convenient.

This is where Sage really shines. You can't ask Wolfram Alpha to do this. You might be able to get Mathematica to do it, but it's hard.

The benefit of creating a number field like this is that it lets you turn equations that have an addition like

2^n = x^2 - 153

into something that is entirely made of multiplications

>>> K.<y> = NumberField(x^2-17)
>>> R.<z> = PolynomialRing(K)
>>> factor( z^2 - 153 )
(z - 3*y) * (z + 3*y)

which is what I did in this recent Quora answer, although it turns out there's an easier way to solve the equation above. (You can show that n has to be even, and then factor x^2 - 2^n instead.) Or, see Alon Amit's wonderful introduction to Algebraic Number Theory.

Sort:  



This post has been voted on by the steemstem curation team and voting trail.

There is more to SteemSTEM than just writing posts, check here for some more tips on being a community member. You can also join our discord here to get to know the rest of the community!

I didn't know about the existence of Sagemathcell. Thanks :)

Coin Marketplace

STEEM 0.35
TRX 0.12
JST 0.040
BTC 70557.88
ETH 3560.83
USDT 1.00
SBD 4.75