1

I'm using Sage notebook version 5.11. When I write a command, it does not change color. For example, I tried defining a function by def f(n): and pressed 'enter', it indednted, went to the next line, but I was expecting that I'd see a color change in def, which did not happen. Same thing did not happen when I typed 'return' command. Why did it not happen?

In order to see the color change, where should I write the program?

Secondly, how can I compile the program written on Sage notebook?

Any relevant tutorial link (except the one on the sage webpage) will be greatly appreciated. I'm programming after a long 6 years and totally new to Sage, the concept of notebook etc., so I might need a headstart to quickly learn things.

1 Answers1

2

I like the PREP tutorials, though I am biased.

As to your other questions, I'm not sure what you are expecting. The Sage notebook does not implement code-coloring as some IDEs might, though I don't consider that a problem. The Sage Math Cloud may do so, I'm not sure. But there is nothing wrong if it doesn't change color, this is normal.

I'm not sure what you mean by compile the program; the computations are done right there, without any further work. As an example, if in one cell you put

def f(n):
    return factorial(n)/n^n

and then evaluate it, and then in the next cell do

f(4)

you should get 3/32 back. It is possible to get Cython code in the notebook, just do (as an example from the developer guide)

%cython
def is2pow(n):
    while n != 0 and n%2 == 0:
        n = n >> 1
    return n == 1

and this will precompile to C, then compile the C for you and you can use it. But at this point you probably don't need that.

However, the functions you create this way are only available in your worksheet. If you are thinking you need things available in other contexts, creating a file with all your needed functions and other computations is a good thing - and you can use the Sage command line for that, or attach such files to a notebook worksheet.

Good luck!

kcrisman
  • 4,374
  • 20
  • 41
  • Also note William's comment on your other question http://stackoverflow.com/questions/23060775/installing-sage-6-and-opening-it-on-windows-8-pc-with-64-bit/23063502?noredirect=1#comment35492224_23063502 – kcrisman Apr 22 '14 at 14:40
  • SageMathCloud (https://cloud.sagemath.com) definitely *does* have syntax highlighting, both in Sage Worksheets and IPython notebooks. Also Sage worksheets support %cython. – William Stein Apr 23 '14 at 18:04