### COMP 150 Exploration: Experimentation in the Sage Cell, including show, N, arithmetic, and assignment of values to variables

Treat this exploration as a "power session": Work intensively for a distraction-free period during which you can focus closely---about 30 minutes:

1. Jot down any Sage exploration goals you may have, perhaps based on questions that are on your mind. Preview this exploration for five minutes by looking at section headings and other key features of the file.
2. Read the material more closely for about 20 minutes. Take only very brief notes. Ask me why! Whenever you encounter computer code, anticipate or guess what it will do by jotting down a prediction in your notebook. Test yourself. Were you correct?
3. Turn away from your computer and jot down the key concepts as best you can recall them. Orally explain these concepts as best you can. Talk to the mirror or a colleague or friend! Spend about five minutes on this recall step / quiz yourself. Do you need to turn back to your computer to glance for any key concepts you might have forgotten about?

As you work on COMP 150 this week,

• Identify areas of overlap between the textbook, this exploration, and the mini-lecture.
• Identify topics and activities that need additional attention, and plan additional power sessions accordingly.

#### Chapter 1: Using Sage as a calculator

Let's get warmed up to the course content by launching into Chapter 1 of our Sage text. The point is to get a feel for what the the computer-algebra system (CAS) Sage can do without getting too bogged down in every little detail.

If you go to the section of our Blackboard page on "Getting Started: COMP 150," you'll see

```Sage: Let's Dive In! Right Now! (Sage for Undergraduates, P. xvii)
As Gregory Bard says:
--
Without any hesitation whatsoever, open up a web browser at this very moment. Type in the following URL:

https://sagecell.sagemath.org/ .

You have now connected to "The Sage Cell Server." Now you shall see a large window (called a cell) and a big button marked "Evaluate."

In that cell, type the following solve( x^2 - 16 == 0, x ),

and then click "Evaluate."  You should receive back the answer [x == -4, x == 4],

which is clearly the correct set of two solutions to the equation x^2 - 16 = 0.

You have now solved your first math problem with Sage. Congratulations.  Welcome to Sage!
```

#### Experimentation in the Sage Cell

What do the 23 instructions below do? Try to guess! Then copy and paste (or type) the instructions below into the Sage Cell (without the 23 numbers), and either hit the evaluate button, or (equivalently) type shift-enter. Think very carefully: Why do you think these instructions do what they do?

1. (-2)^4
2. -2^4
3. -2**4
4. 1/(2*x^2)
5. show(1/(2*x^2))
6. 1/2*x^2
7. 1/2x^2
8. show(1/2*x^2)
9. 1/[2*x^2]
10. sqrt(144)
11. sqrt(8)
12. show(sqrt(8))
13. n(sqrt(8))
14. N(sqrt(8))
15. N(sqrt(144))
16. N(sqrt(144), digits = 2)
17. N(sqrt(144), digits = 5)
18. 8^(1/3)
19. 9/3
20. 7/3
21. n(7/3)
22. # I am writing a comment to myself.
23. x
24. X
25. y
26. x = 4
27. y = 4

You have given Sage a variety of instructions. You typed them into the Sage Cell and something happened.

There's a lot going on in the many experiments you've run already today. Do you have a very general feel for the commands and keystrokes? Discuss your conjectures with colleagues throughout your explorations in this course.

Can some of these calculations be done in Scratch? If so, which ones? And how?

#### Two instructions in the Sage Cell

What happens if you include multiple instructions in the cell and then hit evaluate? For example:

```-2**4
1/(2*x^2)
```

#### Variables x and y in the Sage Cell

How do these entries in the Sage Cell compare? First try

```x
```
Then try
```x = 4
x
```
Now delete the x = 4 in the Sage Cell and go back to evaluating just this:
```x
```
. Does Sage remember a value for x?

We got an error when we tried

```y
```
. But what about if the Sage Cell contains these two instructions:
```y = 4
y
```
?

Where are single equals sign (=) and double equals sign (==) used in this exploration? Which syntax (arrangement of typographic elements) corresponds to assignment of a value to a variable?

Can you explain the behavior of these instructions when evaluated together in the Sage Cell?

```x = 4
2*x == 8
```
```x = 4
2*x == 9
```
?

#### Grouping symbols (parentheses)

Have you noticed that when you type

show(1/(2*x^2))

Sage is using different colors for the parentheses as you type out the command left to right? Sage is HELPING you to balance the parentheses.

Where are square brackets used erroneously and apparently correctly in this exploration?

#### Understanding commands

You can find out what a Sage command like show means by typing

help(show)

in the Sage Cell and hitting the evaluate button or typing shift-enter.

In general, type help, then the command name in parentheses to get help on any Sage command. Note that the descriptions of the commands are pretty technical. You may prefer to get a simpler and shorter definition in your textbook Appendix F (Index of Commands by Name and Section). However, note that the definition of show on P. 329 does not appear to be relevant to the examples here!

Unfortunately, the Sage Cell doesn't keep track of the commands you've given. Jot down a couple of key insights in your class notebook about commands you've tried. You'll be able to keep track of commands you've given in a Sage session when we move into the SageMathCloud.