Announcements:
Today: Functions and Classes
|
|
Use def
|
|
Traceback (click to the left of this block for traceback) ... TypeError Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_56.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZigxMCwgMTEsIDEyKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpOKfMK9/___code___.py", line 3, in <module>
exec compile(u'f(_sage_const_10 , _sage_const_11 , _sage_const_12 )
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpMSsiWK/___code___.py", line 5, in f
raise TypeError
TypeError
|
a= 10 b= 11 c= 12 33 a= 10 b= 11 c= 12 33 |
|
|
|
|
a= 1 b= 2 c= 5 8 a= 1 b= 2 c= 5 8 |
a= 1 b= 2 c= 10 13 a= 1 b= 2 c= 10 13 |
a= nikhil b= william c= jon 'nikhilwilliamjon' a= nikhil b= william c= jon 'nikhilwilliamjon' |
a= [1, 2] b= [3, 4] c= [5, 6] [1, 2, 3, 4, 5, 6] a= [1, 2] b= [3, 4] c= [5, 6] [1, 2, 3, 4, 5, 6] |
a= True b= False c= True 2 a= True b= False c= True 2 |
'chrischrischrischrischrischrischris' 'chrischrischrischrischrischrischris' |
'chrischrischrischrischrischrischris' 'chrischrischrischrischrischrischris' |
a= chris b= chris c= 2008 Traceback (click to the left of this block for traceback) ... TypeError: cannot concatenate 'str' and 'int' objects a= chris b= chris c= 2008
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_51.py", line 10, in <module>
exec compile(u'print _support_.syseval(python, u"f(\'chris\', \'chris\', 2008)", __SAGE_TMP_DIR__)
File "", line 1, in <module>
File "/Users/wstein/sage/install/sage-5.0.beta1/devel/sagenb/sagenb/misc/support.py", line 481, in syseval
return system.eval(cmd, sage_globals, locals = sage_globals)
File "/Users/wstein/sage/install/sage-5.0.beta1/local/lib/python2.7/site-packages/sage/misc/python.py", line 56, in eval
eval(z, globals)
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpPplOUx/___code___.py", line 5, in f
return a+b+c
TypeError: cannot concatenate 'str' and 'int' objects
|
a= 1 b= 2 c= 3 6 a= 1 b= 2 c= 3 6 |
Variable Scope
|
|
5 10 fun stuff 5 10 5 10 fun stuff 5 10 |
(1, 10) (1, 10) |
Python "functions" are not functions in the sense of mathematics. They depend on more than their input, and can have side effects.
|
|
|
|
1327355654.310404 1327355654.310404 |
4 4 |
8 8 |
8 8 |
|
|
|
|
|
|
Arguments of functions are just new references to an object (just like assignments):
|
|
4484384888 v --> 4484384888 [10, 2, 7] 4484384888 v --> 4484384888 [10, 2, 7] |
[10, 2, 7] [10, 2, 7] |
108833536 v --> 90694144 [10, 2, 7] 108833536 v --> 90694144 [10, 2, 7] |
Standard mistake that you may never make: a default list as input
|
|
L --> 4485333720 [1] L --> 4485333720 [1] |
L --> 4485333720 [1, 2] L --> 4485333720 [1, 2] |
L --> 4485333720 [1, 2, 3] L --> 4485333720 [1, 2, 3] |
Traceback (click to the left of this block for traceback) ... NameError: name 'L' is not defined Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_96.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("TA=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmptu5Cnp/___code___.py", line 2, in <module>
exec compile(u'L
File "", line 1, in <module>
NameError: name 'L' is not defined
|
|
|
389 L --> 4459132896 1 389 L --> 4459132896 1 |
389 L --> 4459132896 2 389 L --> 4459132896 2 |
|
|
|
|
<class '__main__.DumbClass'> <class '__main__.DumbClass'> |
140512116046256 140512116046256 |
|
|
no, i don't want to! no, i don't want to! |
|
|
L --> 4467228176 no, i don't want to! <__main__.DumbClass object at 0x10a447e10> L --> 4467228176 no, i don't want to! <__main__.DumbClass object at 0x10a447e10> |
hi False hi False |
L --> 4485232616 [1] L --> 4485232616 [1] |
L --> 4481575680 [2] L --> 4481575680 [2] |
L --> 4481753528 [3] L --> 4481753528 [3] |
L --> 4484369296 [1, 2, 3, 5] L --> 4484369296 [1, 2, 3, 5] |
It works, but by default it is limited.
|
|
120 120 |
WARNING: Output truncated! full_output.txt Traceback (click to the left of this block for traceback) ... RuntimeError: maximum recursion depth exceeded in cmp WARNING: Output truncated! full_output.txt Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_133.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmFjKDExMDAp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpOVkxqM/___code___.py", line 3, in <module> exec compile(u'fac(_sage_const_1100 ) File "", line 1, in <module> File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac ... return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpCi60wv/___code___.py", line 4, in fac return n if n==_sage_const_1 else n*fac(n-_sage_const_1 ) RuntimeError: maximum recursion depth exceeded in cmp |
1000 1000 |
|
|
534370848809263770342421558229505611830801307688668954088274588180366180\ 507230142593359743515667883274154675144889870336145824766456944642617389\ 104733808858036231887137145451981246007462271428980768726544820445627938\ 521384696779273305727495769481668074212168774982084587690054053663052207\ 974765307461854174761407828535465327192407514146840446037688836558176964\ 615337214194379121252115480979065230041337053263382381903878504838477803\ 724588229236052052802737146250787678631254934255034752507195831922837186\ 030239875807777800355948130376137959023725202218865036777462816124054696\ 067849623033545571878068013262711078162177228752949470718358225524298555\ 062659304726235529400439683750995457229825772063311815720595326782817708\ 920420936288168056236465773117812572473654112151753182299528872746983872\ 340629193606959156392223691790438526372745935906675613488166812498098047\ 697386214801382532597457501623884675983655617265690103925964794592333024\ 323536810983017987978944342677864199822342261966341544427566312125083062\ 324656190016824389531140071376929493673248560712179251586301228003899683\ 281401139943312168491213607465195878608574071289179201422918723640246484\ 582489779977603613604718849834315506364003926574273569421105427234464838\ 229595036372921748183592701478838442454491279935703996801454263268591217\ 411293039868708405683574547193689070618929850174592801197517541507435597\ 289982955567323602505100388178442747542851341998969076383964477727378271\ 071547961192019215362150550579304549119593219720589371606769113577207430\ 589945046720705494848261132473585053881617998656177083673499543703808532\ 192432883186291945808989805781924389370357686568396818659379312091885082\ 282670831506561018936080655136970279976803222392921356379936817819124988\ 714512823673236915860472014331087898518943799844045922160923039163416282\ 747378951005309376545654483238563097799645410120160626688816981494456970\ 335134673327992503771447719262504033078194051236272349251363303333031943\ 725505672666478934559485065930513420665737267456485791075859859536589310\ 456140360381555965691258129225797502605868499261246665965245515699452002\ 476606332869836526626211811389591512469040731053588029798552054188230707\ 892213626619862738697277632967887268727487919402518596797342957419685013\ 036891174178271574199813848317234052091159529637811519976390901131118896\ 757105267934486097267301995911743575358800329297051491721051468122364760\ 559105886494816369278793601900859787526572270771248827682569134013497568\ 169550577062064755085844944156336082567893030480431935935274066793521165\ 881294443099150565491295279276352340940609556759543421730501252476349532\ 078080000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000 53437084880926377034242155822950561183080130768866895408827458818036618050723014259335974351566788327415467514488987033614582476645694464261738910473380885803623188713714545198124600746227142898076872654482044562793852138469677927330572749576948166807421216877498208458769005405366305220797476530746185417476140782853546532719240751414684044603768883655817696461533721419437912125211548097906523004133705326338238190387850483847780372458822923605205280273714625078767863125493425503475250719583192283718603023987580777780035594813037613795902372520221886503677746281612405469606784962303354557187806801326271107816217722875294947071835822552429855506265930472623552940043968375099545722982577206331181572059532678281770892042093628816805623646577311781257247365411215175318229952887274698387234062919360695915639222369179043852637274593590667561348816681249809804769738621480138253259745750162388467598365561726569010392596479459233302432353681098301798797894434267786419982234226196634154442756631212508306232465619001682438953114007137692949367324856071217925158630122800389968328140113994331216849121360746519587860857407128917920142291872364024648458248977997760361360471884983431550636400392657427356942110542723446483822959503637292174818359270147883844245449127993570399680145426326859121741129303986870840568357454719368907061892985017459280119751754150743559728998295556732360250510038817844274754285134199896907638396447772737827107154796119201921536215055057930454911959321972058937160676911357720743058994504672070549484826113247358505388161799865617708367349954370380853219243288318629194580898980578192438937035768656839681865937931209188508228267083150656101893608065513697027997680322239292135637993681781912498871451282367323691586047201433108789851894379984404592216092303916341628274737895100530937654565448323856309779964541012016062668881698149445697033513467332799250377144771926250403307819405123627234925136330333303194372550567266647893455948506593051342066573726745648579107585985953658931045614036038155596569125812922579750260586849926124666596524551569945200247660633286983652662621181138959151246904073105358802979855205418823070789221362661986273869727763296788726872748791940251859679734295741968501303689117417827157419981384831723405209115952963781151997639090113111889675710526793448609726730199591174357535880032929705149172105146812236476055910588649481636927879360190085978752657227077124882768256913401349756816955057706206475508584494415633608256789303048043193593527406679352116588129444309915056549129527927635234094060955675954342173050125247634953207808000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
By the way, Sage's builtin factorial function (which is part of the MPIR library) is pretty damn fast (far faster to compute the answer than convert it to decimal):
Time: CPU 0.94 s, Wall: 0.94 s Time: CPU 0.94 s, Wall: 0.94 s |
5565709 Time: CPU 5.50 s, Wall: 5.47 s 5565709 Time: CPU 5.50 s, Wall: 5.47 s |
|
|
These are used for Calculus. They are also called "functions" but have little to do with Python functions.
x |--> log(x)*sin(x) x |--> log(x)*sin(x) |
<type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
log(1/2*pi) log(1/2*pi) |
x |--> -log(x)*cos(x) + 1/2*Ei(-I*x) + 1/2*Ei(I*x) x |--> -log(x)*cos(x) + 1/2*Ei(-I*x) + 1/2*Ei(I*x) |
|
|
|
|
Classes allow you to make new types of objects.
|
|
<__main__.CoolThing object at 0x10a447b50> abc <__main__.CoolThing object at 0x10a447b50> abc |
<class '__main__.CoolThing'> <class '__main__.CoolThing'> |
|
|
2/6 2/3 2/6 2/3 |
1/3 1/3 |
18/18 18/18 |
1/1 1/1 |
How do you think we should get the following to work?
Traceback (click to the left of this block for traceback) ... TypeError: unsupported operand type(s) for -: 'MyRational' and 'MyRational' Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_142.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YSAtIGI="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmpUBX_CC/___code___.py", line 2, in <module>
exec compile(u'a - b
File "", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'MyRational' and 'MyRational'
|
|
|
Traceback (click to the left of this block for traceback) ... TypeError: unsupported operand type(s) for -: 'MyRational' and 'MyRational' Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_29.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("TXlSYXRpb25hbCgyLDYpIC0gTXlSYXRpb25hbCgyLCAzKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/4z/h5m3q9b94zs641jlbxj79sv00000gn/T/tmp5EJwuz/___code___.py", line 3, in <module>
exec compile(u'MyRational(_sage_const_2 ,_sage_const_6 ) - MyRational(_sage_const_2 , _sage_const_3 )
File "", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'MyRational' and 'MyRational'
|
2/6 2/3 2/6 2/3 |
18/18 18/18 |
-6/18 -6/18 |
<class '__main__.MyRational2'> <class '__main__.MyRational2'> |
|
|
<class '__main__.MyRational'> <class '__main__.MyRational'> |
(<class '__main__.MyRational4'>, <class '__main__.MyRational4'>) (<class '__main__.MyRational4'>, <class '__main__.MyRational4'>) |
|
|
|
|
|
|
|
|
This week:
Next week: Cython
Week after: Sage development
Then: 2d and 3d Graphics
Rest of course: Applications of Sage in Calculus, Linear Algebra, etc.