Sage Math on the Raspberry Pi


36 posts   Page 1 of 2   1, 2
by ArchimedesPi » Mon Jun 10, 2013 4:12 pm
I realized that the Raspberry Pi could be an inexpensive tool for teaching mathematics in schools in developing countries, or in schools that have low technology budgets.
There are a lot of open source math programs, but only a few have a Computer Algebra System.
An interesting program is Sage Mathematics, which is actually glue code between other math software.
Sage has many good features:
  • Interactive learning
  • Web interface/server
  • Graphing (2D and 3D)
  • Algebra, Calculus, and up...
  • Web interface has multiple accounts, and is easy to administrate.
When I went to the Sage Math website, they distributed Sage as prebuilt binaries, and there was no armv6l hardfp binary.
They have instructions on the Sage Math website for building from source, so I tried it with the current release, Sage 5.8.
It was not easy to compile, and took a lot of time, so I am distributing a binary tarball so people do not have to build it themselves.
I have not run the doctests yet, but plan to, and will post the results when done.
Chromium is the best browser for using the web interface, because it is fast and supports Javascript.
There are links to the binaries at http://github.com/ArchimedesPi/SageMathematics-raspi/

I *just* finished building/packaging/uploading Sage 6.0, it's great, I have it on the previously mentioned page.
So I've build Sage [5.8, 6.0] currently,
*IF YOU WANT TO BUILD SAGE, CHECK THE WIKI!*
Last edited by ArchimedesPi on Mon Jan 20, 2014 1:45 am, edited 5 times in total.
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by Jezmo » Mon Jun 10, 2013 4:45 pm
A much nicer package which is very powerful, but free and open source is geogebra, is comes as either a stand alone application or as a HTML5 app
http://www.geogebra.org/cms/en/ I use it for work as a replacement for mathcad.
Posts: 34
Joined: Tue Jun 04, 2013 1:08 pm
by alecthegeek » Thu Nov 21, 2013 8:20 pm
ArchimedesPi wrote:It was not easy to compile, and took a lot of time, so I am distributing a binary tarball so people do not have to build it themselves.

I have not run the doctests yet, but plan to, and will post the results when done.


Do you have any updates on your progress please?
--
Alec Clews <alec.clews@gmail.com>
http://about.me/alecthegeek
Posts: 38
Joined: Mon Aug 08, 2011 3:11 am
Location: Melbourne, Australia
by ArchimedesPi » Fri Nov 22, 2013 11:45 pm
alecthegeek wrote:
ArchimedesPi wrote:It was not easy to compile, and took a lot of time, so I am distributing a binary tarball so people do not have to build it themselves.

I have not run the doctests yet, but plan to, and will post the results when done.


Do you have any updates on your progress please?


Yep, I do.
I'm still working on the project, but haven't compiled an updated, patched version *yet*.
But I do still have the sources, so I'll work on that.
And I've moved my hosting to Dropbox, but the Github repo is still used for issues and instructions.
I'm glad that people are still interested! :D

~ArchimedesPi
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by DougieLawson » Fri Nov 22, 2013 11:51 pm
Why not use Mathematica? It arrived this week as a free download and can be used for educational purposes.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
RPi owner since '12.
Twitter: @DougieLawson

2B, B+, A+, 5Bs, zero, 3B

Please post ALL technical questions on the forum.Do not send private messages.
User avatar
Posts: 22271
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by ArchimedesPi » Sat Nov 23, 2013 12:11 am
DougieLawson wrote:Why not use Mathematica?


The comments on the post about Mathematica are full of requests for FOSS math software.
It might not be faster, but tons of people want FOSS.
Sage Math can interface with Mathematica so you might be able to use a bit of both - it can use it as a computational engine. :lol:

~ArchimedesPi
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by ArchimedesPi » Wed Nov 27, 2013 3:00 am
I'm wondering if anyone wants a recompile with an updated version?
The current version I compiled is Sage 5.8, Sage's up to 5.12 now.
And they redid their build system.
So, just wondering. :)

~ArchimedesPi
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by DomasoFan » Tue Dec 10, 2013 6:28 am
ArchimedesPi wrote:I'm wondering if anyone wants a recompile with an updated version?
The current version I compiled is Sage 5.8, Sage's up to 5.12 now.
And they redid their build system.
So, just wondering. :)

~ArchimedesPi


Sure. Updated versions are always good to have :).
By the way maybe its easier now to compile?
Can you maybe post instructions?

It also might be interesting for the Sage devs to know that their software runs on raspberry pis as well so that they might offer precompiled binaries themselves.

greetings,
Simon
Posts: 3
Joined: Wed Oct 10, 2012 7:38 pm
by sdenton4 » Wed Dec 11, 2013 7:00 am
Hey, I built Sage on the Pi about a year ago! I posted a description of the process here:
http://inventingsituations.net/2013/01/17/pisage/

Why do this?

As mentioned above, Sage is FOSS. Except for in graphics, it's actually better than Mathematica at many, many things. It's a bit less user-friendly than Mathematica, but it's all coded in Python, which is cool and goes well with learning Python on the Pi more generally....

It would be cool to go back and build the new version. The big problem when I was compiling was an extremely resource-hungry package which has since reformed itself, and should be able to build easily in 256mb of memory. There was also a small fix to make for Tachyon; this was the only thing keeping it from being able to compile out of the box. I should try this again some time and post a patch as needed. (BTW: Compiling on the Pi took about seven days when I did this last year, and it might be down to four or so now? So it's definitely cool to have binaries...)
Posts: 7
Joined: Wed Dec 11, 2013 6:53 am
by kdilks » Wed Jan 08, 2014 5:41 am
Sage download site now offers binaries for armv6l and armv7l (though for 5.13, not 6.0). I've been chugging along trying to compile 6.0 on my Pi, but if something goes wrong (again), I'll give the binary a shot.
Posts: 1
Joined: Mon Dec 16, 2013 8:23 am
by ArchimedesPi » Wed Jan 08, 2014 5:04 pm
kdilks wrote:Sage download site now offers binaries for armv6l and armv7l (though for 5.13, not 6.0).


Yes, the Washington University mirror does have binaries for armv6l - but it doesn't say that they're hard-float. Sage would be *excruciatingly* slow in soft-float - It *really* needs an FPU.

kdilks wrote:I've been chugging along trying to compile 6.0 on my Pi, but if something goes wrong (again), I'll give the binary a shot.


I'm about to release a fully hard-float Sage 6.0 for the Raspberry Pi - Compiled using the newest Raspbian.
What I was thinking might help Sage (at least on the Pi) is using Collabora/the Foundation's new Web web browser.
That would render pages on the GPU, leaving the CPU (mostly) to Sage.
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by ArchimedesPi » Thu Jan 09, 2014 3:04 am
Progress report:

Since I'm currently compiling Sage 6.0, I just wanted to let the community know that:
libm4ri(e) has finished! It took only a few hours - the libraries linked into everything *flawlessly*.
Does anyone know why libm4rie compiled so fast?
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by ArchimedesPi » Mon Jan 20, 2014 1:49 am
Finished building Sage 6.0, check the first post for link!
I'm pretty excited about what we can do with the new Web Web browser,
I've tried it, but it still seems pretty *buggy*... :roll:

> ArchimedesPi
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by punkbass » Wed May 11, 2016 4:07 pm
I am a bit curious about using SageMath because it is based on Python and you can program Minecraft Pi in Python. However, I am a beginner on this topic and I am curious if it would be possible to integrate SageMath with the Minecraft Pi programming.

Would Sage Math be able to integrate with the Minecraft Pi like IDLE 3? Could you import the math functions into IDLE 3 somehow to use it with Minecraft Pi?
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by ArchimedesPi » Thu May 12, 2016 3:05 pm
Yeah, Sage is based on python: it's essentially a customized python prompt.
You can import the python minecraft packages from the Sage prompt or notebook and use them just like you can in IDLE.

Unfortunately, it's very hard to use Sage from IDLE since it customizes python so much. You can still write python scripts and run them with Sage though; they have documentation on that, you basically put your code in a .sage file and use the "load()" function in the Sage prompt.

If you've never used Sage before, you might want to check out the tutorial and the documentation I wrote about installing my builds of Sage.
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by punkbass » Thu May 12, 2016 10:35 pm
Thank you. I'll try it out then. I found your repository on GitHub. I'm downloading the tarball now.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by punkbass » Fri May 13, 2016 3:09 am
I got Sage to work, but the Import isn't working. And Minecraft freeze. I am guessing that Sage and Minecraft might be too resource heavy to run together on a Pi 2. I'm using Ubuntu MATE so I have Firefox. Maybe I need to try Midori instead. That might use less resources. Not sure if Sage will run on Midori though.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by punkbass » Fri May 13, 2016 4:06 am
Sage runs on Midori fine. I think what was making Minecraft crash was a corrupted world. I deleted the world and it loads fine now. I still cannot get the import to work.

Here's my code
Code: Select all
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
mc.postToChat("Hello world")
pi = [3, 1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3, 3,8,3,2,7,9,5,0,2,8, 8,4,1,9,7,1,6, 9, 3, 9, 9,3,7,5,1,0,5,8,2,0,9,7,4,9,4,4,5,9,2,3,0,7,8,1,6,4, 0,6,2,8,6,2,0,8,9,9, 8,6,2,8,0,3,4, 8, 2,5,3,4,2, 1,1,7,0, 6, 7,9,8,2,1,4,8,0,8,6,5,1,3,2,8,2,3,0,6, 6,4,7,0,9,3,8,4,4,6,0,9, 5,5,0,5, 8, 2,2, 3, 1,7, 2,5, 3,5,9,4,0,8,1,2,8,4,8,1,1,1,7,4,5,0,2,8,4,1,0,2,7,0,1,9,3,8, 5,2,1,1,0,5,5, 5, 9, 6,4,4,6,2,2,9,4,8,9,5,4,9,3,0,3,8,1,9,6,4,4,2,8,8,1,0,9,7,5,6,6,5,9,3,3,4,4,6,1,2,8,4,7,5,6, 4, 8,2,3,3, 7, 8, 6, 7, 8, 3, 1, 6, 5, 2, 7, 1, 2, 0, 1, 9, 0, 9, 1, 4, 5, 6, 4, 8, 5, 6, 6, 9, 2, 3, 4, 6, 0, 3, 4, 8, 6, 1, 0, 4, 5, 4, 3, 2, 6, 6, 4, 8, 2, 1, 3, 3, 9, 3, 6, 0, 7, 2, 6, 0, 2, 4, 9, 1, 4, 1, 2, 7, 3, 7, 2, 4, 5, 8, 7, 0, 0, 6]

test = [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,8,4,1,9,7,1,6,9,3]

def tunnel(w,x,y,z, colors):
    mc.postToChat("Building tunnel")
    air = 0
    wool = 35
    ##hole down
    ##mc.setBlock(x,10,z, x,y-4,z, air)
    for i in colors:
        ##ceiling
        mc.setBlocks(x, y+w+2, z-w, x, y+w+2, z+w, wool, i)
        ##floor
        mc.setBlocks(x, y-1, z-w, x, y-1, z+w, wool, i)
        ##minus wall
        mc.setBlocks(x,  y-1, z-w-1, x, y+w+2, z-w-1, wool, i)
        ##plus wall
        mc.setBlocks(x, y-1, z+w+1, x, y+w+2, z+w+1, wool, i)
        ##air
        mc.setBlocks(x, y, z-w, x, y+w+1, z+w, air)

        x = x + 1
    mc.postToChat("Tunnel Built")

x,y,z = mc.player.getPos()
tunnel(5,-122,y,z,pi)
import mcpi.minecraft as minecraft
import mcpi.block as block
import random
import time

mc = minecraft.Minecraft.create()


def castle(x,y,z,w,l,h):
  mc.postToChat("Castle")
##floor
  mc.setBlocks(x, y, z,
             x + w, y, z+ l,
             block.ICE.id)
##wall xw
  mc.setBlocks(x, y+1, z,
             x + w, y + h, z,
             block.ICE.id)
 ##wall lz
  mc.setBlocks(x + w, y+1, z,
             x + w, y + h, z  + l,
             block.ICE.id)
   ##wall xw
  mc.setBlocks(x + w, y+1, z + l,
             x, y + h, z + l,
             block.ICE.id)
  ##wall lz
  mc.setBlocks(x, y+1, z,
             x, y + h, z + l,
             block.ICE.id)


  ##castleWithTowers
def castleTowers(x,y,z,w,l,h,th,tw):
    mc.postToChat("Eureka!")
    ##castle
    castle(x,y,z,w,l,h)
    ##towers
    castle(x-tw, y, z-tw, tw,tw,th)
    castle(x+w, y, z+l, tw,tw,th)
    castle(x-tw, y, z+l, tw,tw,th)
    castle(x+w, y, z-tw, tw,tw,th)


pos = mc.player.getTilePos()
castleTowers(pos.x+3,pos.y,pos.z+3,20,20,7,10,5)


Here's the Error:
Code: Select all
Traceback (click to the left of this block for traceback)
...
ImportError: No module named mcpi.minecraft
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by punkbass » Fri May 13, 2016 3:30 pm
It may be a better idea to install Sage on a PiNet server than to install it on the Raspberry Pi itself.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by ArchimedesPi » Fri May 13, 2016 3:37 pm
Hmm, it looks like the mcpi module isn't on the module loading path for sage.

Can you run a python repl in a terminal (just type python in a terminal) and try running
Code: Select all
from mcpi.minecraft import Minecraft


It seems like Raspbian is bundled with the mcpi library in a place that python and sage can find it, but since you're using Ubuntu Mate it might not be and you might have to install those libraries. Did you ever download the python- and python3-minecraftpi dpkgs and install them, like in this comment?
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by punkbass » Fri May 13, 2016 4:32 pm
I ran it. It did not give an error or do anything. I wouldn't necessarily expect it to do anything though.

I tried some other code from my programs and got a Connection error
Code: Select all
>>> import mcpi.minecraft as minecraft
>>> mc = minecraft.Minecraft.create()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/mcpi/minecraft.py", line 171, in create
    return Minecraft(Connection(address, port))
  File "/usr/lib/python2.7/dist-packages/mcpi/connection.py", line 17, in __init__
    self.socket.connect((address, port))
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused


I will try switching to my Raspbian card and installing Sage to see if it works on Raspbian. Thank you.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by punkbass » Fri May 13, 2016 6:39 pm
On Raspian, the mcpi.minecraft code works in the terminal on Python.

Code: Select all
>>> from mcpi.minecraft import Minecraft
>>> mc = Minecraft.create()
>>> mc.player.getTilePos()
Vec3(0,23,0)


However, it does not work in Sage. I get the same error as I did on Ubuntu MATE
Code: Select all
ImportError: No module named mcpi.minecraft


I did not install Minecraft on Ubuntu MATE like the post you shared. Minecraft was included in the 16.04 version I installed.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by ArchimedesPi » Fri May 13, 2016 9:22 pm
OK, I see what's going on. I think if you run
Code: Select all
export SAGE_PATH=/usr/lib/python2.7/dist-packages/mcpi/
before you run Sage, you should be good to go.

The reason it's been working with Python is that Sage uses a different PYTHONPATH than the system python install, so it can't find packages installed system-wide like the mcpi package.

Thank you for your patience; I actually don't have a working Raspberry Pi to test this on anymore (and I haven't touched this project or the RPi ecosystem for over a year) so I've been debugging blind.
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)
by punkbass » Fri May 13, 2016 11:48 pm
Am I supposed to run that from the terminal. It does seem to do anything. It doesn't give an error though. I also tried the python3 path and that didn't work either. The path looks correct though.
Posts: 15
Joined: Wed May 11, 2016 4:02 pm
by ArchimedesPi » Sat May 14, 2016 3:28 am
punkbass wrote:Am I supposed to run that from the terminal.

Yep, right before you run the command to launch the Sage notebook

punkbass wrote:It does seem to do anything. It doesn't give an error though.

It shouldn't print anything out. It's just a command that sets a variable in your terminal. Sage reads this variable to find places to look for libraries.

punkbass wrote:I also tried the python3 path and that didn't work either.

Sage only uses Python 2, you don't need to worry about 3.

If doing what I suggested didn't work, I'm really not sure what to say. I'm curious though - why do you want to use the mcpi module from within Sage?
Posts: 14
Joined: Fri Jun 07, 2013 1:14 am
Location: Somewhere (over the rainbow)