<jupyter_start><jupyter_text>This chapter is mostly about Python commands that are not Sage-specific.<jupyter_code>import keyword
print(len(keyword.kwlist))
%display latex
for i in [1..5]:
    print(i)
for i in range(1,5):
    print(i)
#[print(7*i) for i in range(5)] # This only works in python3
#[1..5] in Sage is the same as range(1,6) in python2.
print([pi, (pi+1)..15])

'''Surprisingly, Sage prefers the use of [..] to range()'''
m, k = var('m, k')
res = sum(2*k*(2*k+1), k, 1, m)
res.show()
res.factor().show()
var('a,b')
var('k', domain = 'integer')
assume(k>0)

def u(m):
    if m==0:
        return a
    elif m>0:
        return 2*u(m-1)*v(m-1)/(u(m-1)+v(m-1))
    else:
        return None
def v(m):
    if m==0:
        return b
    elif m>0:
        return (u(m-1) + v(m-1))/2
    else:
        return None
u(2)
var('m')
def fib2 (m):
    if 0 <= m <= 1: return m
    else: return fib2(m-1) + fib2(m-2)

@cached_function
def fib2a (m):
    if 0 <= m <= 1: return m
    else: return fib2a(m-1) + fib2a(m-2)
%timeit fib2a(30)
%timeit fib2(30)<jupyter_output>1 loop, best of 3: 1.25 s per loop
{'fraction_non_alphanumeric': 0.18840579710144928, 'fraction_numerical': 0.05253623188405797, 'mean_word_length': 2.9748201438848922, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '315819', 'license': 'MIT', 'n_tokens_mistral': 496, 'n_tokens_neox': 478, 'n_words': 139, 'path': 'Chapter3.ipynb', 'repo_name': 'vaibhavkarve/Learning-SageMath', 'size': '1104'}