Section 1.5 Using Sage for Interactive Computation
ΒΆThis text is advertised as having interactive computation, but so far any computation has been your own. How does digital computation (interactive or not) fit in? We'll skip ahead slightly here to see how this will work. In the interactive version of this text, the areas below are called Sage cells, or cells for short. Assuming you're connected to the internet, this very first cell will use SageMath (usually just called Sage) to check whether a given fraction remains a fraction when reduced, or whether it reduces to an integer. Click βEvaluateβ to try it out.xxxxxxxxxx
38/19
Sage note 1.5.1. About Sage notes.
Sage notes will teach you useful things about basic programming, or more general facts about Sage and Python, the computer language Sage is based on.
xxxxxxxxxx
is_prime(3169)
Sage note 1.5.2. Using commands in Sage cells.
Assuming you are using this book online, you can put any legitimate Sage command in the cells above. (Try integrate(x^3,x)
if you know some calculus.) Or you can use these commands in your own Sage worksheet at your local Sage server or with CoCalc, so that you can save your work!
If you are using an offline or hard copy version, I still highly recommend sifting through some of the code and commands; much of it will enlighten the reader. (Then try it out online or on your local computer!)
xxxxxxxxxx
def _(a=(3,[2..10]),b=(4,[2..10]),n=(20,[10..50])):
list_of_them=list(set([a*x+b*y for x in srange(n/a+1) for y in srange(n/b+1)]))
list_of_them=[item for item in list_of_them if item <= n ];list_of_them.sort()
pretty_print(html("The nonnegative integers up to $n=%s$ which can be"%(str(n))))
pretty_print(html("written as positive combinations of $a=%s$ and $b=%s$ are:"%(str(a),str(b))))
print(list_of_them)