CM 1.5 functions MrG 2011.0926

3718 days ago by calcpage123

#1) def mod3(n): return n%3 mod3(31) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}1
def div3(n): return n//3 div3(31) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}10
\newcommand{\Bold}[1]{\mathbf{#1}}10
(31/3).n(digits=100) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}10.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}10.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
#2) def incrementByOne(x): return x+1 incrementByOne(-5) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-4
\newcommand{\Bold}[1]{\mathbf{#1}}-4
#3) absolute value abs(5) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}5
\newcommand{\Bold}[1]{\mathbf{#1}}5
abs(-9) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}9
\newcommand{\Bold}[1]{\mathbf{#1}}9
#4) def sum1ToN(n): return n*(n+1)/2 sum1ToN(6) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}21
\newcommand{\Bold}[1]{\mathbf{#1}}21
#5) def reciprocal(x): return 1/x reciprocal(.33333333) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}3.00000003000000
\newcommand{\Bold}[1]{\mathbf{#1}}3.00000003000000
a=plot(reciprocal(x),xmin=-5,xmax=-0.1) b=plot(reciprocal(x),xmin=0.1,xmax=5) a+b 
       
#6) def double(n): return 2*n show(double(incrementByOne(5))) show(incrementByOne(double(5))) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}12
\newcommand{\Bold}[1]{\mathbf{#1}}11
\newcommand{\Bold}[1]{\mathbf{#1}}12
\newcommand{\Bold}[1]{\mathbf{#1}}11
#7) incrementByOne('123') 
       
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for '+': '<type 'str'>'
and 'Integer Ring'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_14.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("IzcpCmluY3JlbWVudEJ5T25lKCcxMjMnKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpQTJwmd/___code___.py", line 3, in <module>
    exec compile(u"incrementByOne('123')" + '\n', '', 'single')
  File "", line 1, in <module>
    
  File "/tmp/tmpQATOB3/___code___.py", line 4, in incrementByOne
    return x+_sage_const_1 
  File "element.pyx", line 1302, in sage.structure.element.RingElement.__add__ (sage/structure/element.c:11504)
  File "coerce.pyx", line 766, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7337)
TypeError: unsupported operand parent(s) for '+': '<type 'str'>' and 'Integer Ring'
#8) double('123') 
       
\newcommand{\Bold}[1]{\mathbf{#1}}123123
\newcommand{\Bold}[1]{\mathbf{#1}}123123
#9) def firstChar(w): return w[0] firstChar('goodbye cruel world') 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{g}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{g}
#10) firstChar(['al','betty','charles']) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{al}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{al}
firstChar(range(1,5)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}1
min(range(2,8)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2
\newcommand{\Bold}[1]{\mathbf{#1}}2
max(range(2,8)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}7
\newcommand{\Bold}[1]{\mathbf{#1}}7
sum(range(2,8)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}27
\newcommand{\Bold}[1]{\mathbf{#1}}27
range(2,8) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 3, 4, 5, 6, 7\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 3, 4, 5, 6, 7\right]