x = 2
print(x)

print(x * 4)

x = x + 2
print(x)

import math
x = math.cos(43)
print(x)

a = 2
a = a * b
b = 4

"""
Explanation: Python Basics
Unit 3, Lecture 1
Numerical Methods and Statistics

Prof. Andrew White, Jan 30 2020

Suggested Reading

https://docs.python.org/3.6/tutorial/
https://en.wikipedia.org/wiki/Binary_number

Variables
A way of storing a number. You create a variable by assigning (=) an expression (right-hand-side) to a name (left-hand-side).
End of explanation
"""


x = 2
x * 2
print(x)

"""
Explanation: Be careful
Just like you remember to save you documents, be sure to store what you want in your variables.
End of explanation
"""


x = 4
print('This is the simple way of printing x', x)

y = 2.3
print('This is how we print x', x, 'and y', y, '. Notice spaces are inserted for us')

print('What if I want to print y ({}) without spaces?'.format(y))

z = 0.489349842432423829328933 * 10**32
print('{}'.format(z))

"""
Explanation: Python String Formatting
What's the point of having variables if we can't tell anyone about them?!?!
End of explanation
"""


print('What if I want to print x twice, like this {0:} {0:}, and y once, {1:}?'.format(x,y))

print('With a fixed precision (number of digits): {:.4}'.format(z))

print('Make it take up exactly 10 spaces: {:10.4}'.format(z))
print('Make it take up exactly 10 spaces: {:10.4}'.format(math.pi))
print('Make it take up exactly 10 spaces: {:10.4}'.format(z*math.pi))

print('You can demand to show without scientific notation too: {:f}'.format(z))

print('or demand to use scientific notation: {:e}'.format(math.pi))

print('There are many more formatting tags, such as binary: {:b} and percentage: {:%}'.format(43, 0.23))

"""
Explanation: The 'Formatted' in String Formatting
By using special character inside the {} expression, we can modify how variables are output.
End of explanation
"""


%%bash
pip install fixedint

from fixedint import *

def bprint(x):
    print('{0:08b} ({0:})'.format(x))

i = UInt8(8)
bprint(i)

i = UInt8(24)
bprint(i)

i = UInt8(2**8 - 1)
bprint(i)

i = UInt8(2**8)
bprint(i)

"""
Explanation: Representing Data
Consider a model where the computer uses 8 bit numbers (1 byte). You could represent $[0,2^8-1]$.
End of explanation
"""


i = Int8(2**7 - 1)
bprint(i)
bprint(i + 1)

"""
Explanation: This effect, where if we add 1 too many to a number and "roll-over" to the beginnig is called integer overflow. This is a common bug in programming, where a number becomes too large and then rolls-back. 
Ineger overflow can result in negative numbers, if we have signed numbers.
End of explanation
"""


