14 Replies - 4821 Views - Last Post: 06 August 2012 - 10:41 AM Rate Topic: -----

#1 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Why can adding bracket make an arithmetic expression much faster?

Post icon  Posted 03 August 2012 - 08:27 AM

I looked at the two following expressions. And I don't understand why adding brackets make the second one 10000 times faster. Anyone an idea?

>>> import timeit
>>> expr1 = "3 ** 10 ** 5"
>>> expr2 = "(3 ** 10) ** 5"
>>> timer1 = timeit.Timer("3 ** 10 ** 5")
>>> timer2 = timeit.Timer("(3 ** 10) ** 5")
>>> time1 = timer1.timeit(1)
>>> time2 = timer2.timeit(2)
>>> print time1
0.0190041065216
>>> print time2
1.90734863281e-06
>>> print time1 / time2
9963.625


This post has been edited by atraub: 03 August 2012 - 11:16 AM


Is This A Good Question/Topic? 1
  • +

Replies To: Why can adding bracket make an arithmetic expression much faster?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 08:54 AM

Because the exponentiation operator is right-associativity. So a ** b ** c is the same as a ** (b ** c), not (a ** b) ** c.

If you actually print the results of the expressions in your sample code, you'll see that expr1 evaluates to a much larger number than expr2, so of course it takes longer to evaluate.
Was This Post Helpful? 4
  • +
  • -

#3 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 09:32 AM

Oops, thanks sepp2k. Completely forgot that ** is right associative. Now I feel really dumb.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7576
  • View blog
  • Posts: 12,729
  • Joined: 19-March 11

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 09:39 AM

View PostNallo, on 03 August 2012 - 11:32 AM, said:

Now I feel really dumb.



Which is weird, because really, you just got a bit smarter.
Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 11:10 AM

View Postsepp2k, on 03 August 2012 - 11:54 AM, said:

Because the exponentiation operator is right-associativity. So a ** b ** c is the same as a ** ( b ** c), not (a ** B) ** c.

If you actually print the results of the expressions in your sample code, you'll see that expr1 evaluates to a much larger number than expr2, so of course it takes longer to evaluate.


I have to admit, this one would have fooled me too! What a great demonstration of operator precedence working in a correct, yet counter intuitive, way!

EDIT:
I really like this post. Not only for what it shows about the operators, but also as a mini demonstration of the timeit module. FEATURED!

This post has been edited by atraub: 03 August 2012 - 11:18 AM

Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 11:14 AM

Excellent! That makes so much sense.
I guess it's like abc, where b^c is executed then before a is raised to that power.

This, on the other hand, is a much larger number:
(ab)c
Was This Post Helpful? 0
  • +
  • -

#7 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 12:01 PM

atraub, you are not trying to hook me up on writing a mini tutorial on the timeit module, do you?
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 12:57 PM

Nallo why not write that tutorial and earn yourself some kudos (50pts)
Was This Post Helpful? 0
  • +
  • -

#9 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 03 August 2012 - 01:26 PM

I'm with Speight, there are no tutorials on the timeit module. Until you mentioned it recently, I didn't even know it existed! If you don't write one soon, I'm going to snake it and keep all those delicious Kudos for myself.

This post has been edited by atraub: 03 August 2012 - 01:27 PM

Was This Post Helpful? 0
  • +
  • -

#10 ziggyfish  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 12

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 05 August 2012 - 01:18 AM

View PostNallo, on 03 August 2012 - 08:27 AM, said:

I looked at the two following expressions. And I don't understand why adding brackets make the second one 10000 times faster. Anyone an idea?

>>> import timeit
>>> expr1 = "3 ** 10 ** 5"
>>> expr2 = "(3 ** 10) ** 5"
>>> timer1 = timeit.Timer("3 ** 10 ** 5")
>>> timer2 = timeit.Timer("(3 ** 10) ** 5")
>>> time1 = timer1.timeit(1)
>>> time2 = timer2.timeit(2)
>>> print time1
0.0190041065216
>>> print time2
1.90734863281e-06
>>> print time1 / time2
9963.625



This is because ** is not constant time operator, depending on the implementation it will take O(n) to complete.

So we all know how to expand a exponent, for example 10 ** 5 = 10 * 10 * 10 * 10 * 10 = 100000. So this in this case n=5, now if we take the first part 3 ** 100000 = 3 * 3 * 3 * ... = 1.33497141410^47712. So this in this part n = 100000. So the total time taken will be 100000+5 = 100005

The second formula forces the first part first, so 3 ** 10 = 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 = 59049. So in this case n = 10. So we now take the second part 59049 ** 5 = 59049 ** 59049 ** 59049 ** 59049 ** 59049 = 7.17897987710^23.

Thanks

Brendan
Was This Post Helpful? 0
  • +
  • -

#11 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 06 August 2012 - 08:24 AM

Everyone understands why it takes longer to compute 3**(10**5) than (3**10)**5 lol. The question was more revolved around the parsing of the problem in the first place. Hell, by virtue of the fact that one problem need only allocate enough memory to store
717897987691852588770249


where as the other would need to allocate enough room for
13349714142304014694589143904897822922452485076062
77355345627993984127414621589686952230598025579823
32391498894254195905243324288735370830207822798029
84670783174192973884875772106202489810965195750670
54001772910465325312490675422508873342629571008941
29930017223303316612954445683629949845257948650401
54552147363813207209965356768946943602282911944326
15463049211300257964232304885829543477013613818075
31506158288312619405016500120857253910525756220107
55977649358077483459506643914763503008295365339548
65604481712000952705040802828803086444633043581934
92337459032491955493253782690555462562559069218062
26622155440527634094668066864913662376758390987340
20890785176472646045161605817204755472104483660819
67137447991822644265192852969988649270387807365530
82694994579374849302380335292984474443305592397659
31523784102893721522385100349875765013041292735961
76005780304161903796298302903624866963435298923914
98918169043371620434554192522038249180947265608151
00985838795186158194775604404398151067087953994291
06942565966267959292463417142028296949344653043370
15784361135937440940664714154737267519782717648220
62443772974953113631391171828465268473960111002566
41964726915840529026133350440572152877325055850265
53121689863435648710646543348275130053326487223367
98578355121274660610619989132683323691989424982157
42806094819888044689865575017784629284031528807251
03465924306130045709815180283855532895934988218337
24114527495691603695714743361010656708814466807351
53625966248616963411331288356796239510712747250341
16042262749977206507262437895238456653520219653531
97817949971262980218757257539566872973761855563572
71688531139890579653883304482771789483031388421357
48100850985659359217667819174634578587692306462315
84554088864174529684257142410973222364981754013483
98918736201279186685091348697361949589203836748126
49484543522305782210030259264680757572757819426071
71815439354828704033591807492330777161530340011793
58936192447585827246500839472937171522566623901124
41619439508345839860146997174686693257680063934668
35431110049135421963635094516184789296636019144432
10415814538534529238970509876596798896164377609768
50921718682205364271288156051226089311343949176457
28564527112075649899243588509896189777871982262490
84177337145632822807051179601259136143598716916706
03977668478901681124754489210554082390746894419702
86447135211653933201894014849557457175928887169395
02494769978142085727941658926153580258922721694799
45101558169714879671102845757093354494145314661487
82731280748249177568148307903598682116226458877966
11801058190775463766510292907711997110626974295341
78304613634429363432074053861168972297326077166299
62790290594693258720290527962515742948541908629615
92038770271328440553222191263958050579346991272357
39861503038989250127304616711372778706981341392639
65445523865220175972182387611873915865996620624135
39213518918645513578338850493396100319844660520867
07447491444300749100900595376599498429978267285770
39649773069544827611866775654363977241068139998392
92704527481693615098133911081299856727250082277653
88521363898370115108211658702915208809959767686699
91872861743665353152080221603977438626211594841556
15696101809347278413588667920484750473697357757270
18812749016750931462912955125594990141946585753506
47158102843413403033425379550112043708155448934828
12679643003407025461492617584333495534436165867788
38250466294453904884775564679059806343071479179073
24010231216353890005861558147227617286591360275732
30144546331363791069447435078497787635828875274374
49170717108602424789427423435553801671600206695745
15042804347145645311238456912009690317832988292741
31199958682432779917577129247882577737716864003470
46399412661923709542272363661203265890314172863777
68021576590840665892680664632681784251536537116755
69440306152843418579518627215615782318174869054982
17743895367054995929228193579563481630718696004411
48786972830758543218792320712760035735487848071421
87524385080127984534910573591957565407768374772440
64221930590143121983577298182656237987162764092981
52892342925338687735996256929450163104572151175543
25069427871208178917592341317790705591060341987941
87251387824661921949042262945957068396059323374312
33494629435666965049583686364606117955832693410338
09749989374922646273500531856175494725182154617056
02125114147952657770963143594638938255348900250723
48400055644199798397611636958589582563067615424314
09159383524235876210709544277931650421628937652456
50686307707212763130705657093765605944832005356656
51751436948980869921025907786078137046932846589812
70561235460448718448868526049020018210678078465447
27699328119684922325802937704865234083191521371703
74071112327031570327514487430519488899412679202273
83840857922329198517389237264600197952918957810837
85682532241066019705320752114796228872683259890669
09380667955039896842672404971999441620102587002389
05566707081031678660145858294157035937370831552578
04012414300702488730288149452569380882923587421428
25897034099721468245941508680776118231399033075823
22997578299578657363484930382373188199149084726979
93369543135217780612641552478562753911332170838692
77859968305367203603243060441431916049561622118488
06073993213150721118133086737837444524345562341372
73517093201664640449765453517042831506992310223758
25537628336479220766847067235363138006014269210138
89928581905936352641934400677579830941450125688907
13645572853021468434589615060936702976957549923043
45921355058028856519718292323761725635880694289425
07648734244569531581277528867606210391411313046048
85083421793797330361712844497185987159906901323171
69665961842234909776670587288821661651139948921457
48714083484607697380130422295046298773672287993544
40270720238103482259479407771105100014641359796408
05916403807343968321570630503925633381716828835020
37570557465637738936493706488029344926581653968857
25427464406698314172012619338661207506417484399429
62043642095844763456617323382486196973466598102625
88790693897960358429809819781958012092045569358296
81118297717184946191221187026225501547219187979612
33337027323086427168954530599802817401657993469292
25712948796990126659349306814872768421756953639644
60033258410333729517266574619913957170757527085914
21272561430474973178770766128366749967747395266483
38595429354974077264904919911066668919787202294856
95458127154083530344777215295278730236809988240050
98060529330768524842394953639010703169832569349927
56008752714396884115241531698351342064576480016019
13757246398917800483890827735063707640460177292600
91910225123911481042978949273397328995404278205395
05781861776808401446478713478160212460108460501287
12977005742014457393425711835522774914697489379199
01140789087246127442562151366389034300856887396486
24106625340069555129830501302507365972347187438333
65699691793293521833137988292192193580666325123305
05982753224920270949856479726151109895867734980085
82013998575546149996559383952278086170484598469193
82756038570105572337770195651317073145272491902295
55925995739887874368528401134288590465106556858084
43916595581932537909065570152482343211000245656758
51970507018326174256317032219384851947310298008555
74247937366330242905627862614994176164791763750804
48938817553307910642873341333841030292090426685240
32807337817242780789048445709019768238046226887354
63969881994028929873779841027214400147177492414099
04314430348731797352120846665150151223232388932169
82424280076917234107503861276205927377367185287432
85134223275701064206075887970918872031381236106465
95800981955390232335256130838081965035617068532715
15708001767769792033568587008933165886868358133266
73994567314913372820187372659749670894631256097316
03566841297285449463722946119587117507291300269587
10952174971503825742605799340399993334424731812514
48220792104523932961770764239510061661516371346206
43646000818660993441237619985435556296935180392365
63532439708170051749857738316313985893707659291972
37018727930912874143032652342249115110905011503964
43016645330052023462851860297816657081191634082984
10760212284294752072921754811984628190942420411674
42560153996413406957900827965574946523786905664663
72659603004984967803429029247173835086409123128740
44250080553012881363962657304846636279523490037712
85660691095624989718141785508633268943204764197976
00293064143524803859088097848881391911916194072909
99659029314805022322516902434539971856900875372513
97360455376765495087748952644835032484979588203952
95518260687967530964850188123796012343279515006302
38826421951838067574255256784933227171011913717913
85608432555648481983126822468787716619820803216979
60511541423869691034278411410503610049737618294303
50559862396979945988500831480681600776379028931668
73547164402114027907996485157629568445962365856761
01942227183812772209320431517182201781694787931278
86774317310503775200621822108272186978526455342606
96275069914448355726777611906452287874696914763437
06389753667674360706752082122519224236717973266469
86031722969925370203573382385394746776320665663060
99530681067987636822044778676790571526156752682098
05400806011422204864823521108867765200173340897239
04040212348587337498166956391055169726819502134965
64480918881121470308245056746614322544958130326224
78334872293769452151767150054404576681408107994962
40600641481419947177870067972042803611808078760330
49761456459736601225700682679513329369667135280396
12239147091095984899331032637022755692037255959825
40831266635392783985346691176472750780817017760107
25472872859706510326074619775290538573540867490363
04923640454229517768729779435917255217852266935754
29098973403840860041384689245507547791562513587227
15250078273456312400695475455417163793954731031875
48731671291477822677719948204266687600763155928248
35593341302634845451016684729433371079746361890726
68256721441101751960657630930579890571217013133779
25375017888623460071512668147119273219487696797470
53463999423708280575959959013839379892627579162393
01838161298743259102739530046115969689386067963504
47384182513100926357076744184454349882206101816583
62211018883043187736024423350930448253329519268636
60605860472577128040415789564658658760949664374550
50648365752007331534587205692439812080195062875994
96004520744368269199719096837231401058066430409935
41984696276659353515432883704923181750655292097082
24894258836947165570522754128555641572432606296483
77707493735080122248060497632762102969134603155697
22822241233699197676158719308644620420427399754206
83976780616585614992237025512880400802289415872396
75340114702092931873408257169855869780908034832001
78017155619123489584114366739929326163278379671370
04774524486983943361366370075681962731190459363202
86737910924697345047095776251786044900229117757956
35903527757590082803960967183621843334230396544679
82357717801452739197150774870251830535097215155101
35870878435300245758293839567356930962388667904909
28507739221629097063537066753821854932139055125113
29407589520588803558932180155393468676316236078825
03932832870443729430273059658917707459459619868891
33993939743871207337620200744875931142612339641944
34317168078911495890923645769356472743588689214025
11854463231699574988658383571635070608104610801917
19950542249186902301394200638270687404668379284242
49190794163525631820343826689143126893042250484489
75996778150946834234600868389463084091851092180995
82382778552584415280973758084138100423576874873870
06320217162286053292407736803841122641098242413707
51534015113888460163956234407037288193993516409785
16448071165407640197955386458301032352563028276255
68315391835792962951120417305722083024709343570355
81154461491651086151140937184226300231561589746607
42161614974080012659585301647749464656263935203569
31511425568895552018677725563784172909008896576539
18724913329884562249611319714977443552910777674398
04729220014482176434770117509356056419462005900009
23920913630429840782960429024265709970876392512186
22782523066257561197505367588626686289737426951474
79212115123029472181282286710958441680215133272578
87702048154609693446955416809173346004114312161790
09517843751320394194698988215500456680435725700584
93696157097990107188854285061406445356389995621965
34846056057065003033959458472309514940751272247560
84821514212545324567059213442903298263630506668137
41835759679010264383183900900426982032888709346018
67736713259402757197222116954279407434558376746304
95326176651223733715212905699693711051869648006458
14907996405338776139086310190546246384604748323569
29346080433057188601586542556368784594221134768628
73456358633074410881456819802717368523565078026605
71900537562489865889482887569802379094531316593700
61653518126550087737186575748989169216820909501335
59492911244085380067706803417650968774904663819227
66715154296827892218583851693874149152110945319202
53250192838204146630199764835454417312441427678537
96526728744089341111868608729340767691163263103057
32334678772045167997727383062882090208828400757534
38061066137777932575707828835645842869983875074377
24140902340019774813187806103053576278213443660909
49146786132210132425891844467997767873041828256234
13404370091905459680135752609306419269949441804617
12742982961954822569541146552580875167225492887170
90027359157455511851879040894028116277760672092385
18708344115391307339974482030620271340341590476754
08725517163338180491102379766610408669870047137190
42003989076669812744369018276469014791033171905093
72843205515538141743289503546288792336787860170434
38053560778383519971525458757884212551576275683952
26659972603450474196250982782741797808458813714356
94456418559900322412794909410275569713936321482685
63670433698180105533902521633656469145626273509782
69530096557709255865404190216746739329725367231970
88669725180955006907458368906996370258949215873430
75974976997072401334632355163904461297974807194299
56128048268047204543591754339902140829769117752756
75664025460386429002676646519840109070848716895734
58957157962011321024466461795243682739629955787059
52926635889671115894074874803013840940056804092814
71873481142493500128756836335279555711763432014938
58552922098930755411551858130718409977390571097530
26713343842457980886252867656475169859262711808274
71429426579616950474179677107841157110156889556601
74575916080684232708144919206935536215439474206959
82990619436159191379982387433106219432189136024006
99863467084025029023982091945881419952812626109841
78600124529872836923186879028744315252847654681276
43263104694648785136505375114357803385063650315850
60656784622318175740318479665875283188348281009906
09655811755736005954720189721388708217040121885035
89089312983577901121129384096015468665635783128187
32824754739674770325316722784887637585709899825064
45241997238441517011716925470943452607059842066236
24863025200858356498534598288885818837182768732337
66879131166803806597944219308914644869356430430498
34811635513099219654992102826758065113466835897438
75951772396657365219736195938929189194913603866951
12121147443888275395428362768524229944000261347336
42088430110654379028911571812113069000599521905797
81528346718337433070426993322556578048312559898523
00034385858328021133700101555174056426488716803301
03243734836714899688251816072343957394836354732797
14019629137437578202418402058472831775487234858953
68420998249866710074155275396032536169814448476666
40976070765517540600587741463811923048361058803218
53493984110452770827328015864518496319676496956772
99728579906704188175680926578091247595918678931095
99412890917012764818346426752892374488506393468526
18609404078337396010229041892757300921386637690046
18431362209222100457173113712171003314194995471216
35193397741238761115143934657657455106179387180617
18075427624246820706206513097174359222182497386901
69078011604345952152745129549491637115012612788513
99363440653008889826234525320259610595412825071735
48650339807646821116854039523643552224540017131300
82703844075383826049781784823268266486615010858628
99824085763461335396398662045826032959161883079568
61878979055339735816572725123077564389664492965932
29932720111874992295731151203994552122324020186161
47958657815944257642623955050154594752987821190303
07421574784849733256742420493040822099882934990213
36255902398683986125151741149309854167543869861202
65049976729100423872555370447634071426030116277016
58521544283806126507066809950962108520803801513474
50062886012948995451457354608510401969653035518389
07114959554195446063704272745558029780841708666371
29346922858611243000188133689238314755020716365649
66650801511062175957772096757818124978413403421844
81907356923890346247894726006711728965338262572110
28219493366440722205798291768435654013605110056243
05750771187312363645479286055317639809458882723079
76264436155948659592187337210257811963753103514939
17912241473013174855023562893117815539149124356605
75954984024886142938141172310546216440270354699838
83496954036968825088525940648093393834173243353899
95539584184254093812710500587943739048701034495377
34696438998582525748796419124385498059773124885720
66128710444707809268057222192966441924149945385499
31179642552745230707990175606441891527691676985823
56951747006424651558003879297715997150523954518795
02962684453476683560883581752682985421703240802582
51052505212130324032291636762881382690112676350744
02478600119364444006631288899592086143684913162894
61535989009049614732927560384422608757027008766441
62725420497761004241075375523703620055764764356475
21338493081541664178909313640747935249474151435996
51323980058100500797127692787017276899824773111392
53177662136649692334277810572805520893816077502651
14742040211813299790420858245647224288668505797435
03561105568551922262867858647511291693803894396900
87480943060525409115908004010113950206090900969378
65640554337731586664519381635710656415821046575026
18661793100440052777010671867898483153725713636855
16542670736721011537999881773042328315088634621956
57633196607034490130171658180719128631733114589576
21307443136403841696510383857035410087996779755829
20714820854722708866931850351350029851958455429625
78681899226677051560065125461160206793396957464886
35080377857706663642960970693395241501028004376048
62854592151492457145388426208639847728204236100786
24963857277408867562323951727046930923977746902480
64166583840771530196398068428176121523257921617458
72436694716543519436217788297635939709843315173670
92768137336338335390310092239657049379456240372693
03984116189346681198668053963779149962716914789095
23072315433776340422877786559932918466195686794466
25165839209787991288349451679367778468419823632254
09820110845699823380424654516598550862465324022124
64662527009941130185731810505052405688440520015630
98608203973007286622927118747380986919796713832316
32530676345007367986199600929756734391498989246584
86702001134377748096002118274868381123953640128778
05970921841390975734974828849327626774622450176609
65054110504082898666089104721375691243199923198868
61088629188556821840130556677908155742753289012689
70889830714997479232013347150287430282241090804668
51585181895152652202279007691197808161551893756374
70882563130139909992351368113701521646419453183387
42848099103104045958704655018339864218277763706225
90724066195879936046527809849706669120303032144344
44321321766239470602261647626317976250111487127612
09286773586134677395279195655882803680618661812720
67157872871982404293439265298719743159136576197690
04519811756418179900214555051535427409144731868451
93594146887167022182987042273380869404873736356791
20995743789104204426313394715312328079242497497327
20161341427597463880338080959640792534963010817410
35808442299485001506405882019948920651834746638335
94832807701050185316219218473395113831871832398892
43052196617438290925375271132119525753066641739136
40957187284186341020334949619299132467060373650097
67522432419310403135904242797300700012196491746009
42943688899079835840130919713079116806886915454525
35296366413363879792540908958883204773012407762683
81437775597198008944924289552790962866105046883282
01094657108127577172513768767077194234423509311399
19334634160726019795931688011564899685424777782863
33655377093205766814055049691763665245900072058281
96090933494864126583286143520105724897954678406661
29973936838142523911770864493113540041708548121908
90140318431594442778897465624054414822481707998730
12254790984957112690127547893716200236210767133267
55336077135086289414896296439475190910078699973404
66581176377447326327959618546909495799820287124546
63748319036815758012319412132356917867673036751004
00132607206418996381022803163764992240044291803130
29272587491517287824813014186709031909424305864211
33007679510340291841677718318755417340560247767747
25806765041863212563597999679861540340670627302197
21966808874671650835480163036759785331823763931466
54004780448610800824932670509442707049388274701594
29265078111233209443655185360241644973565825454715
00566752728348858501497849677020156071484510731593
25105059993407214344535293536092775335609544314000
09726165019914512522483155116455302861707034667235
68846911399677803170317990386851250347437190329427
93489103748528612157226093386802220110750761584119
92327201608657908841986285664020051166747957460159
95669964633079396223314170300436200552138693087860
35450540037074045654080958662819994053555689636408
97494232235178135330158861847465051682002324188482
03529774821553488845250252163991523745228030956235
75469793591669130415671350376694542232270045219873
63007495009221554859616957508976604885673449637714
34759651408943075011673797752053505792925807887533
26484995280622921632602019459094459083440394183280
37822681306600967114911947785124972343923072713080
26812825114370911904111808913798853073766397303760
05391482090130407182429137125471451801644463058380
22555469567762520528494174399365050496149006596611
37462839502234013725328303920094325881085559587426
65914124116499906385990212303436607082716886354711
29923500410513394193307865291774844519522591816924
00652456458797617775749289584292439958600428886644
84033028238787786166321636395058928056471993461723
66002995952240581433179520182815140237932135744613
50686796913506103068030086713306078817632769618578
01409774291401568837918097847790620066441037186937
34674678728908061674004214148376384258853119543434
93393588029477899079598254666087913550644500353947
75975215575425922677662314385015197797874182914928
81764515106806559289553639811216876913502415114678
59317496839680524293387682059212541787884300880619
85797992703403545298591021516024663838099027583280
84126657338106450148437291821535724021697527560955
66292191593030746894773445612153871721870405818041
15286660768140911201903303394067377273696317489248
67566857311913349772348423790550631180847783776110
40827475749463860803795257640303510482137336293432
35587473686907307904953032382441983338176649495457
91562930105719129957838112545448322300800036745578
03535508640402229875311736696395886435189855802007
13125621038174570991028610240653383936036338237437
88835820631382106358367698683990085271805299039901
75234189687394393714220787685049556320555482525724
49594083357047530585211938514897171375977194718314
65550604012123642533699766479515211710729973055775
00194482916490810743660917434209798564128912109382
08606521958820885838241030605187573672314048064857
38335979278181108613285225001631242718803298104724
36786010928604863036519198122573740269219982855526
30639026147077667928782100985230246175473606184569
47504167542927083835902309408466449298549589597175
50287275503585366168096477015553712213060082226908
49751127278960160822029647151370520784202562625621
73326442255061742708190737133011019938484123392071
62487021773781636607272188089124372145596436312923
95464424071131155221930195220976064144138679332063
15688614594724356125644839595979129460527408490510
48802108474601565053267649673879167437402989229168
48269278556691477504326328206509031560954412335434
40284791342920615192968698277433558334443793062523
13092506620252897914438096261679129030119980390748
47586995231708898245027517967907112959567211776360
59898452550116262435363265029620466417195236682887
25237193597501501422405653001597330860204515035421
99742092708278573846446982452120435490887489007601
80304574419670050243105925155203900012082675252397
03583920033130600018672207750364629492457358466741
99253315675797060894821075289755273551164126538667
82931554227883621532891372959026636033562863389855
11249135903644816016676854004208503858514382788482
07233433885394536958941375454577381188862492985489
09532888089717789643135187184757218153503609269748
67317227624435159345615459829998815995822050662206
49648580265278339118846857927906635498626353315347
78305491327968579730780852434295077012004198119888
35018631137789119072177113305451993570526119300517
93878471831545619264670171350549386495684024594398
42176490316952187412194562239857901134700624707819
98964084965561118532110146530689479042322386252987
53039930750641071406240724607241771760064391460273
90712199967302446957577108519780308855458996237155
58743677059499554439378485651212872915035782068590
02575761781901563775828878574122937961972665412924
07477893421503423653606252909252159543206567515385
04145395436993516311801266048140867596337637659973
21923287430191846341924661794561102130809264491029
37319461097670018334444215701139252670432504063955
86889939155624086852496551229386124391656309764370
32158977171594728293054145251358332396615066845743
56876362931376486887665490127219853837025952931705
79513666498710842940455560611621908674671198048922
76998565419082020378155707546213593028852589801181
00310683764679183469086609748315187191830319906166
07137007728070681356244728068835203139522267523856
31930700111180797033967249263113948752981484443868
32054612007082412567025891875222839267386503801608
92686914645529364682032196163136171148159594259437
85159500684978883247744812630737239730155692130545
94575655747049283465159965708914336440286234113774
33136130206850276644314282288935958349372339666252
76712757094813043478139048028581617702019495630995
62902724729985256874432249652254310417352821708793
12279490557943809640824589343996115753605568074600
18043150819123743454166727456379749733740448637479
19906277512099551318046701267947782257894563587217
80105186056861610342370169789800080592370346453585
77800152386110910811530732717632547615910191580503
65763211610240237178585481850393708052016210701286
45280081392152586972104948859228909431785397426500
51849713821287098339339611565505571736600918611171
84351151194122969004023691921045275957750459208284
28732133356002608109276353267869738750355280060241
99663023081042219704613767308193391136775359851325
15829879914456809265416787882951985623803367090928
47598148709953290290898729512732474428736304911269
96923627335521964719196707029894776361895377147013
46411506581105150304038995026103628657140934149865
71235130892498625308791642629154992030175843616445
83787023273781065754343230692374579850192243148117
43516459817014885719198647814722740844006050482019
64933749546198883420602840007284588975952142807964
94157390443590958185107336229691248882370977294538
06774363659904380616739858027971277462296958856002
85898971136619672258329311461188565508980999905466
06755529928428665474412472328105646449395707987071
53473000416786898307397242006839074681887377403482
50201432744093769148931903612875180990786364118535
52560068719331940454554800572732947277450968753478
97580281609773693956977895127680032175935626757900
31412138706620120942492646169847104738209185436791
44529352199086710746858924778792837126298818317325
60597684105029855355811095364148277096501938359560
58316882238797633423187679055611539290739604840109
91526208106417642295743666865824337030577671090002
19451493877833838602569802285319025968271907740184
28735964481298282704884862329795276238746141417496
02252542434703116187264096025187856919793323879263
13001532652464428195115777814000588960020507870269
69224392833436011213630045389930999311334410233928
37370986230447746569033277242600439688563632928302
91011385571962026306015554804570674105686310020478
94524415232832929622318267908241675962002481319301
17745187487349234283733660524633519681171782641851
67030883418548454623791529384131660162581580039617
78149255913226273530903998481972996073422869706418
79021637040590315675396497313783515559383963349532
50720734425131176963924338517587562899673915301763
48122888133672272472855278929745417510891766586392
38414818831789624145109824432798844343395155404964
73113297449525641518376258187519052528134286236851
33411627650805116711075071431779948197757969416689
37457374962270590619747810139300328552194494112202
57698361065557928128918410512956359343108900018560
97368500700050933546126914146739568015943265824421
02332383818710571432819666242648315975293334022495
93185218857842561911574885850483013493295437108460
03825632301600659405541058232790209161791931328889
92518444818405842454323327473748329973966835134792
12719499238766363703347104603778616998832675519697
38245038334385827874190829155539331376518236958282
54099738895084777394494420877133785307361790247896
90573259378211693406283139346717240058718451962877
14181581022488345363477828711770995104694733594517
31170928917516047897438488447545743423283225330462
95384067563514329048513176688546299274625583929607
20366102986414907653398430329220738450123869778911
32738180652847860223530979986250672542411242867895
59883721567790199601591214468958286058227192862080
88605120984669324523814347245565329786560340777258
88877184395260645138588087239796713822492310998358
44149069401836069278395641350021100364389288690137
02818029386700399804171499392402936384775821084881
30684110852267584890400146785503178555472836626984
42831117882211919639913607383725341562659040697635
57497820391795611449480379272063653403013506509462
42722393567209621932345702640244563024536109986196
36220563138139570037230159166350024419221493917560
34747185522328458509034881691193531836675375293742
11599018415058417214410645447203743123755899461209
64165873357261694775460353567169775510024180772415
54755813114967002898063009194289077562852199254602
51924651856074821852223029266095120984290010551757
51018851862694013910832600449884233185149018638089
11666279226631967556399705120000904036052346529797
19135803154992775691436502141005407057980974360716
67998771178520549219670171938022819324632379125249
24611522735972047776695395134262990614341354198767
39265674325385992675070742575652878089488609358374
59641894987637551058775962420330096497888042765303
51114851811977874135454260117234305109932831921062
91958004349321968984202383353644613030131635035811
53805385462473554890309412167515774101686460030470
83852345605934295799858361123499457359384473857579
27372469320331855304420068077267518870914214106806
28461543773015394460116050565806819852676987843838
68969931266238916660384926470653607431694016037248
86663452393555458413935288895196340480251150128316
20243318379554645755222726192984410661290170970874
80111702993760104373661029119300233671108812399100
74778462761751872287650662006006808043053289979348
77708428727544214161882595947748014060205229414995
12651463902544882551264991406539384097543864906962
67098285080156983849831840651017267744433490700933
81710163413316427533511369351966387287390853191984
38030695008776085987026627894738885503357276721983
76141149645240800296087348970258631577932596719561
60989084369649164676510438849999443761041800104300
89024697186451486197313277529504594964231733253421
55465239206088514345121481760394309393280437634112
79576203133064168268072352624433260184473349832372
34545249650988144824629188219521037490565049493172
37541234189517744818019030194459190722412618545250
78078024784348577819602978484004607461744439111681
47487730215205431805668121078148504496105184675883
78069462111046002272878199952187399640907897478698
05585796461594069182485772966792456524368978900367
79171547633000173594367606583727654080819756826978
28731500307528619098625835934576051693216977575748
98049442109922326552836694061120927558808091165910
13948740370840793626348481079570399490902560397058
59332490052656255568199480633684334640996841274635
01701633818262962585979549101294244469181521255225
17786838934819487392275854656342419382327173551741
72100101354812807654496683550151442104976046653954
49659311135966152547362542491048181955050333720491
99245727073994864310496404837974179938909503562415
38877367475058710171031520081815097027434966547220
75120348944173955716860019707852317861748178497163
78411423583961400088234903812736728113942563953993
07801030878755225463100553147543893736714545810193
56884280700019401168150204520457043701336309362914
20458681411986883600542680000470648154745569255229
53025586312256433869494451352664677788495626147527
90808180960513858328492921794720249886453429462285
64746961604932989495261824910663588832338204748128
27936059676876885888739467107928331385364082325824
00216610502357158350869156721134720555007813407932
72928829393111007039262821419403124982070210435940
38392867293015783535483255226186673845346752138714
35186951750953651427235807208739034435803224491510
97078272070870839630165065839348981914971503624447
94837279772373704299160525214383003594848532083843
87942553295027780737561278056218729318839126401665
02829481012585504485436093749555438618620804757889
35104599114848915803852783556204081055657535489710
29934664396929203414786095178629539159852894104966
44263645294510607283763948635099194901772348794302
93830873076744436728667632418135050052719395254740
98069224897974183888257058374525646219985985493642
64592426612259901047976816944358901477570663461375
96539593206017751722928090234412823349821491102434
65351027028957497358231870270960145335157546740889
58550859426134484947340432048986087151270928362799
27554549576846385390809536894706813483094675141122
87393673657047776332277358628970958857172047325524
78861701296374734192192233626540365056961294708842
44054315855950884626459674281847485176060088605533
73093092921198780101523007464414261727505172417507
81371218534776930997757223210830835358504223823268
10835868249179974292294793476154513821433866738927
92984749513665530101504486880648665677927635624274
03817450309249284367519684218602923986818178642690
55380149092636558003100655097787862166725629154897
42328429563752335224099862759621507921784765688538
03890541185792808103379016798930520599070203991533
39320431697480152621724389561681757130784439390686
95764790328100530433123356062447517261916284746650
47824692364857762137408209132674290298586329240707
44915006006616281001389298412433572624734317405722
26121506904849791577162401371736135223000091320019
59725614563166602890628898558522633513515396370719
66682236585444117250616678311486131213831940318307
40418810228849799492681751789854455284150057218693
65485890155887211857702536329354206245024013337566
29452818575354258495828620521393008253684524890279
86306405158617234312409449901980112550678488046701
30150591444452767179884899116560896206994528161684
59186066375760847837255664185719140166721036615016
96578283486632909685201798727206522041231588633546
86013079308592153513190131514128880297160251557576
45225347344968610585171993294010942696817433336516
17899031280599362597075783071485237339384087433602
62832113690680890087404611839324852782120346817023
80793139593324763521670800768113266696348723705050
06508099299354055318503279569046366402035238041387
98986137255837064521642601754199132989457568970937
44934260462769556112055492081893670072323456066761
85575272719959316415771222454761565719424557002997
13654342865306158023195861794202593925057761103400
80096723724202204114428225232981095685597200316107
35500503177257851935235903249939253341422667293294
92612140930667888242800890613594179173830575604417
12614873152504456519714725056716926175525382162572
00413173552472554209165072088046880362872381319244
83564083909078653599575966280587068087623857944660
13335921554721716372543978455948367212043267116545
72115230215285270115637905424089676793424941552833
37094431850124503126623257093552146252488711294391
16060622626324846539582713062035380310217172192127
41904348884966869087630815356720977467169339645007
32675322380982654562230964166843246982840579062494
53846808168145948549271112173145642207466751751767
09970854240717956291003091775511668506936484501117
67855521111001549221668772454480460697695509336429
73303268648715449129029753468823955004071925684683
20972598051308805749564475505140134721546539777535
44976851419300968608138482886052162032101158608184
89311883937333670714806394378732314112388707147092
83075919026348544982716560723584723505217017409291
13742247255468527175325498633588258811734010270499
35095621842982533877999701929257368725328190140044
42615019799621708065327982664151088124795299959075
71151046915919388828412093301034494655263848164478
06864585447546400788317699332783865138478383946424
27702108122641383214984697991438623286698633466048
23995471471325052081506936213094275052510536900331
31987112144879835115311296476640181881141823439296
05106788167417929618521803285375145948551017253282
32241326400506600908519464240553324856003921732094
95618738853423527859248422156116906269488873017328
64278140399838166927606732567555141384986026457965
80369270744546305079490523576670419364956471071883
02794830183096304390663270421396138584902900391547
61265836175261520102452263018162641025792869379844
26918887435908426208452846875183792892397625161029
52544665734624414903939859510068504959588779167044
19035390898498268515052942395328920386235321004421
64538843437045353733484417979364993312032011881995
50106567121151485579947124946747706294628783094768
23887047643320805007536635516930310470561337973198
53530017845831278145232540988611569462968497523673
92855750345754649212722641663466891564922953532802
95349466962461428897539141143558991851348753532816
28784447810442754222745182889025865370346393723423
52948389409692597650395384554329613075745954184303
93892028263457978547886172660314810744661362500605
43978875482273334429462425211226689448095077281920
03433286270692003311338148334150073879055865436605
46914214742473312847122240216912462604511579933073
62508573091036375629386745231836408193399377927804
07911430397892329787873818107006269550648404441764
51393175627708438624603103614227585209078537419147
15603657357274252953096681100476738582223273052001
54099355657853150292711934780443344413550082058600
67502482576551126123599920829540355669453407402124
99645736756184135630249228053032576707078561784154
71264207987466829850162764626558613187165683223158
30094965972328166743977541342663079645788997389956
71377667781022454209010612702044927770420074000979
33572244197206989643709644439613487338252572596930
25553518228200355094895550275515214857949471738261
43738629990838673709558166111285489246530959266706
08760501838215323454296376555767489075368793587690
96643518323866217381120643606707617338693364478666
38749421157023635057960115695755543410671963416718
85376663414280490731473197624473886646631575582404
01992700163325984335459855414987936033662481000379
80033720802520999722753191962739779989590625185263
43251906847486172395767509859655113042764718114515
95068913666430171099201794415749634618806162139065
73631860352397356754948082579615581970858367338792
40146212241863677642648496407658501744210994334373
49863522650896551366292048953750619745779001718489
37156853385831912398947340971138051605591350596373
04673959650078253975653370748595373716304192577669
59906910730492494684779953033653709698827217145035
93072785468888016919851296645602299527450877184724
56667953909340936895052680821691098839351620979413
04254545831105630185780439730982859429905663488249
45213968061627635788059293714491159986059107629110
96693145315957863547005224421956029903633930764875
43837409759223245293171580501391769944026291949632
25003360926503432015949807399093763295738388803748
08173476112200313646290397242499569122775273744331
64336570792392604809799580177810405825555468726652
53933278625643246625860773845399238763096178632194
47037386214760222705852010476057548834965449272992
30817231639754437310944992316352295010161812945408
24028859211179783055289888221345996874735253005497
35750352577449961251490113832712779663792855700088
51109814472550947085518645986381495469716153178526
62949543044040077902286063562880781438055628749481
10692438701403001732206653689924004368900550336196
08852697284778751220463033696427207626896198270473
74472501378117795462431450546952554644285528461098
86413308197418574242147572723276270056563336368836
97627063080146596184585780147045589754787690535562
70348086044224534513639450919428123185307850723103
48027256980327438759509028488340770682942757612613
19720745317929401031493480477548728525703811996342
76133021317357033268832546451774009686568200196578
86240085543166348197853272563672567558937650849120
55583046013238901966216964869079524289402063769755
47189439183772958764690039181299262924358683324226
63686249049788161564624567347428694305767076309128
35768442113001142246330839439650064359363044097479
21659288865067687972663900587669847233851549079484
19138375234211195309639992324703218582204764968643
63105288993232320040699949392152038609960627140525
86021061489386949676545364787829262265930613951332
88749736767311964467974030522878870656253627777474
65543093425091960328949472240596050175698255255724
81316448640452542139620741640231122195694869012782
28489919320858259088555351123289285604102894499012
81930161294260504332917323271824439473063387799459
49953695946356777976613627284998003272898219992560
41736549545061843420677839642834791765044100794412
00549623745862575643811685440606981451704889914334
29631187262561571550802205437523706800193709753300
65182015854504307335040541251478991434285156133246
11426201613905594844011760630999092473141526730464
35022051390543519714099841822785306333293019968781
02398454192604328370442395731632055248336946538340
29300345959675554670978630550980312356659841823163
46159594299821157773364980794707520832821131144556
02030181835272985047006071500782220586745149766329
87925036652037120668989270484640166354505823082519
01679062344064566355397027486712371310706715634664
53009186605056808393126256429884597752739968158576
68162414535544635996391426681605670449244278792740
66506024330229882510790820272513876487059529902526
65612466530326087121232492080700860425290277024614
51727613595845659524071411608747241971362613961555
60479565737562706713339176591591497656115289585436
88856072915756580047601570922913853459719043045866
54885406715969411225830538052250750534829668576135
69030240161725307209959350021133144691852944763198
16350292847468760497291828157940930991564323778486
19210271117531247975165805042869970550904050172205
26634074521285947651310756419850617089345476393883
30327249404435373584032210638902122514692543965307
84271315557700870519696142883366343150416607074789
77499287231780958064669155626184995044179991310898
31727095933305532540582189033579107071167241585399
83509926598871154262527772406783683391766940200057
78295017677771390967021565449662919134486029248792
08510485649033419318261091511169759360788683054347
68919477440133401044124564353001723398533017018502
79329256530481526878688547490506101281937963954906
42660955203623759477518505078463309508093904173364
63027712789170267729387329471639004698620792339357
20813966434008696514017156313662560113317300055463
62315213421083646999384997106683640088628024252964
33238263980555617162080692564983331436442634438518
87553478828356106518211305236764720890351763778794
07528271149737259084902880511794656212775192390852
91869403792839353735748618480569716360996574672192
44720823038278493805172225805535721703862184754781
24935534054107957008136748264000490308965643074450
32519316338173500879929736752693975063512752015598
51567451908787573452086972179199718232220876942374
05151945323538808625861060819726648657962336362108
19102437964371327868426798673021846653647340019434
17562257690503232974804629283493525339265280674368
39318767094970219381527787311411633657598204327492
20504095747990877631853573923036872337874748823784
68761117639873591501191769739897697908214197129916
20341274826036493802956421260537590507618309622390
24878018314692809932319763655928915042848432965749
07588878208789166920267579785136306175842498673279
81465289461053054748743951808939280902570477411564
59223779380003765987526257271623775763661331690364
51077898585977556310759478262604573636168767909091
54202413505205444685387982262066604264991949246045
33145381469144234999513935070139630276641599108792
78727981531414535969117850672389562920058269159671
77056379529885504778175533214736212068696729434612
78332822797126734717617560464983619064488390640114
64962035383283568172123137486049061130492976731703
18933022537696282034331405789143873125968977889884
24140861055072164144351816851664548176991206006442
19270612181283326087803841740271789152870938896971
35151979001590743044696647197222508441180831851697
20031404731770849434508770355267704506108167785539
88425239758401555209500151735321279914950034423151
69548249007421716242618739646913273042440941615521
00843756357975104918304985289974782554598784787625
94204492239068343164899831321526580700736939118306
69307002025480728483307291028519063061933926918033
13641615593893452388282577822536489321785155123698
63285055145245387770028038270188821136327313264254
04753127471894955871885513720028919517738166729252
33779201678185622122066144881567827571604637693388
63885334393280837481133626843938519788765709420588
21544822430824735191309611046573115836298827097601
19033083890062779452022094010310315630699777892805
59212735022736139182442800647078311617347274317080
67755189785297003716512782588528729445068602283891
08935684002812042659424544148494511697698993938261
46751474260007067380571870141422660863345614097749
82410240661502006707334615727133473136480212468899
09696342341682430560049230359185214724557432834273
50249350244735682558497079040709451687136437348098
73174447465426508242318604170472528878475158927804
01310774384494481146554976887345660918014712462453
20960542949066257413538936614378255311955503622858
27585482362899583768136115182673221275009243528255
46019417487465080387804832947695215045225703731260
56848409877616744426654063441246568708275394348789
28916322840472517031286608161870820546953457709862
52082781424131114908661633119451745792579258088750
00952510440098560857576054070444091216913278307940
65652190465147186295597827881377884787914108834268
12518949062943364997340006458557802307807174887114
76292700282248504171327244951357197451669909068476
93493364355789322141304144325835803096900860917424
94064878879556430815396977180578808413794066766174
59204313789713471206861116274613763263919047222708
29938513460159101597317711618428073158331118707404
76924889955705979155168279285359407555677422589140
43846777938110010174004073674280665238315237990518
51693152679492899893126468587595857785744663316636
61264555596477148493164260367661394801129998308046
59375262508775162501170023346105943078354390457183
12120508279820767102401203361587173276314279227046
64118759888441479936454945083627040176089350987531
74576753463616513906848613366059306510628054511240
24396480575434317119804074700058022485194771034449
95472352109286836282594723353884944978438757954462
74457331248244043647871228242748427123466037667216
39842047247593484918749812851399723456216399942245
15406931685802696388431964145655426481342973700751
49483794491050949421708887550149507393447565431412
47332191270439105999684981601058464808116335334488
62448557405499509600647528031329332773927739267195
94664028008620725930105030351123763249622018459155
97406453056897228124786693779006036487808643485666
25683699554381906041361852592048276356413564414919
20197724505981966029544163008637085587855162972393
74756516837295082184619855174316246656272782988107
12781396232150360552036336511839992313185259592787
18197537022265072538351012491467401679874305321026
84664791920676836851209912738247232900260478207772
18463159877508853399903086683229634923717274856247
59961538274459211908302166973520139812402017565942
65456402119389667636812546724474159600183045445473
10651302278135270887403087321530046460312357988524
47012260817864082180431402136059248549489112477275
66289913273441809238040802387058773562765141503378
16432268184999321673894277627015958098281315365832
92971242307846759150927159012701864028118631218801
28610103755943887061752742445724616537396077303195
93639094452907668815118912039668443580791938645373
88945457653627280378482553149854828483809325751596
07276463328760306668403558229494845328177547545133
75766541635663236893532169753493257682034426160136
76145534449112910305562227378744505167776520163901
02436811661314789440197945030580604606481813964231
72896717835446897094354737305722548000966457425066
9865522000001


would be a source of slowdown on its own.

EDIT:
That's 47,713 digits :)

This post has been edited by atraub: 06 August 2012 - 09:26 AM
Reason for edit:: WHEW, FINALLY GOT THE NUMBER DISPLAYING NICELY!!

Was This Post Helpful? 1
  • +
  • -

#12 ziggyfish  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 12

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 06 August 2012 - 09:29 AM

View Postatraub, on 06 August 2012 - 08:24 AM, said:

Everyone understands why it takes longer to compute 3**(10**5) than (3**10)**5 lol. The question was more revolved around the parsing of the problem in the first place. Hell, by virtue of the fact that one problem need only allocate enough memory to store


Often there are a lot of contributing factors to performance issues. So rather than be rude and suggest that was the only problem, I wanted to give an alternative answer.

Anyway doing this on a core i7.

I get different results to the OP:
import timeit
def preventOptimizations( x, y, z ):
   return x ** y ** z;
def preventOptimizationsWithBracket( x, y, z ):
   return (x ** y) ** z;
timer1 = timeit.Timer("preventOptimizations(0.8, 100, 100)", "from __main__ import preventOptimizations")
timer1 = timeit.Timer("preventOptimizationsWithBracket(0.8, 100, 100)", "from __main__ import preventOptimizationsWithBracket")
timer2 = timeit.Timer("1 ** (3 ** 10) ** 5")
time1 = timer1.timeit(1)
time2 = timer2.timeit(2)
print "preventOptimizations(0.8, 100, 100) = ", preventOptimizations(0.8, 100, 100)
print "time preventOptimizations(0.8, 100, 100)", time1
print "time preventOptimizationsWithBracket(0.8, 100, 100)", time2
print time1 / time2
print "============================================================="
timer1 = timeit.Timer("preventOptimizations(3, 10, 5)", "from __main__ import preventOptimizations")
timer1 = timeit.Timer("preventOptimizationsWithBracket(3, 10, 5)", "from __main__ import preventOptimizationsWithBracket")
time1 = timer1.timeit(1)
time2 = timer2.timeit(2)

print "preventOptimizations(3, 10, 5) = ", preventOptimizations(3, 10, 5)
print "time preventOptimizations(3, 10, 5)", time1
print "time preventOptimizationsWithBracket(3, 10, 5)", time2
print time1 / time2



Outputs:

preventOptimizations(0.8, 100, 100) =  0.0
time preventOptimizations(0.8, 100, 100) 2.19345092773e-05
time preventOptimizationsWithBracket(0.8, 100, 100) 1.19209289551e-05
1.84
=============================================================
preventOptimizations(3, 10, 5) =  1334971414230401469458914390489782292245248507606277355345627993984127414621589686952230598025579823323914988942541959052433242887353708302078227980298467078317419297388487577210620248981096519575067054001772910465325312490675422508873342629571008941299300172233033166129544456836299498452579486504015455214736381320720996535676894694360228291194432615463049211300257964232304885829543477013613818075315061582883126194050165001208572539105257562201075597764935807748345950664391476350300829536533954865604481712000952705040802828803086444633043581934923374590324919554932537826905554625625590692180622662215544052763409466806686491366237675839098734020890785176472646045161605817204755472104483660819671374479918226442651928529699886492703878073655308269499457937484930238033529298447444330559239765931523784102893721522385100349875765013041292735961760057803041619037962983029036248669634352989239149891816904337162043455419252203824918094726560815100985838795186158194775604404398151067087953994291069425659662679592924634171420282969493446530433701578436113593744094066471415473726751978271764822062443772974953113631391171828465268473960111002566419647269158405290261333504405721528773250558502655312168986343564871064654334827513005332648722336798578355121274660610619989132683323691989424982157428060948198880446898655750177846292840315288072510346592430613004570981518028385553289593498821833724114527495691603695714743361010656708814466807351536259662486169634113312883567962395107127472503411604226274997720650726243789523845665352021965353197817949971262980218757257539566872973761855563572716885311398905796538833044827717894830313884213574810085098565935921766781917463457858769230646231584554088864174529684257142410973222364981754013483989187362012791866850913486973619495892038367481264948454352230578221003025926468075757275781942607171815439354828704033591807492330777161530340011793589361924475858272465008394729371715225666239011244161943950834583986014699717468669325768006393466835431110049135421963635094516184789296636019144432104158145385345292389705098765967988961643776097685092171868220536427128815605122608931134394917645728564527112075649899243588509896189777871982262490841773371456328228070511796012591361435987169167060397766847890168112475448921055408239074689441970286447135211653933201894014849557457175928887169395024947699781420857279416589261535802589227216947994510155816971487967110284575709335449414531466148782731280748249177568148307903598682116226458877966118010581907754637665102929077119971106269742953417830461363442936343207405386116897229732607716629962790290594693258720290527962515742948541908629615920387702713284405532221912639580505793469912723573986150303898925012730461671137277870698134139263965445523865220175972182387611873915865996620624135392135189186455135783388504933961003198446605208670744749144430074910090059537659949842997826728577039649773069544827611866775654363977241068139998392927045274816936150981339110812998567272500822776538852136389837011510821165870291520880995976768669991872861743665353152080221603977438626211594841556156961018093472784135886679204847504736973577572701881274901675093146291295512559499014194658575350647158102843413403033425379550112043708155448934828126796430034070254614926175843334955344361658677883825046629445390488477556467905980634307147917907324010231216353890005861558147227617286591360275732301445463313637910694474350784977876358288752743744917071710860242478942742343555380167160020669574515042804347145645311238456912009690317832988292741311999586824327799175771292478825777377168640034704639941266192370954227236366120326589031417286377768021576590840665892680664632681784251536537116755694403061528434185795186272156157823181748690549821774389536705499592922819357956348163071869600441148786972830758543218792320712760035735487848071421875243850801279845349105735919575654077683747724406422193059014312198357729818265623798716276409298152892342925338687735996256929450163104572151175543250694278712081789175923413177907055910603419879418725138782466192194904226294595706839605932337431233494629435666965049583686364606117955832693410338097499893749226462735005318561754947251821546170560212511414795265777096314359463893825534890025072348400055644199798397611636958589582563067615424314091593835242358762107095442779316504216289376524565068630770721276313070565709376560594483200535665651751436948980869921025907786078137046932846589812705612354604487184488685260490200182106780784654472769932811968492232580293770486523408319152137170374071112327031570327514487430519488899412679202273838408579223291985173892372646001979529189578108378568253224106601970532075211479622887268325989066909380667955039896842672404971999441620102587002389055667070810316786601458582941570359373708315525780401241430070248873028814945256938088292358742142825897034099721468245941508680776118231399033075823229975782995786573634849303823731881991490847269799336954313521778061264155247856275391133217083869277859968305367203603243060441431916049561622118488060739932131507211181330867378374445243455623413727351709320166464044976545351704283150699231022375825537628336479220766847067235363138006014269210138899285819059363526419344006775798309414501256889071364557285302146843458961506093670297695754992304345921355058028856519718292323761725635880694289425076487342445695315812775288676062103914113130460488508342179379733036171284449718598715990690132317169665961842234909776670587288821661651139948921457487140834846076973801304222950462987736722879935444027072023810348225947940777110510001464135979640805916403807343968321570630503925633381716828835020375705574656377389364937064880293449265816539688572542746440669831417201261933866120750641748439942962043642095844763456617323382486196973466598102625887906938979603584298098197819580120920455693582968111829771718494619122118702622550154721918797961233337027323086427168954530599802817401657993469292257129487969901266593493068148727684217569536396446003325841033372951726657461991395717075752708591421272561430474973178770766128366749967747395266483385954293549740772649049199110666689197872022948569545812715408353034477721529527873023680998824005098060529330768524842394953639010703169832569349927560087527143968841152415316983513420645764800160191375724639891780048389082773506370764046017729260091910225123911481042978949273397328995404278205395057818617768084014464787134781602124601084605012871297700574201445739342571183552277491469748937919901140789087246127442562151366389034300856887396486241066253400695551298305013025073659723471874383336569969179329352183313798829219219358066632512330505982753224920270949856479726151109895867734980085820139985755461499965593839522780861704845984691938275603857010557233777019565131707314527249190229555925995739887874368528401134288590465106556858084439165955819325379090655701524823432110002456567585197050701832617425631703221938485194731029800855574247937366330242905627862614994176164791763750804489388175533079106428733413338410302920904266852403280733781724278078904844570901976823804622688735463969881994028929873779841027214400147177492414099043144303487317973521208466651501512232323889321698242428007691723410750386127620592737736718528743285134223275701064206075887970918872031381236106465958009819553902323352561308380819650356170685327151570800176776979203356858700893316588686835813326673994567314913372820187372659749670894631256097316035668412972854494637229461195871175072913002695871095217497150382574260579934039999333442473181251448220792104523932961770764239510061661516371346206436460008186609934412376199854355562969351803923656353243970817005174985773831631398589370765929197237018727930912874143032652342249115110905011503964430166453300520234628518602978166570811916340829841076021228429475207292175481198462819094242041167442560153996413406957900827965574946523786905664663726596030049849678034290292471738350864091231287404425008055301288136396265730484663627952349003771285660691095624989718141785508633268943204764197976002930641435248038590880978488813919119161940729099965902931480502232251690243453997185690087537251397360455376765495087748952644835032484979588203952955182606879675309648501881237960123432795150063023882642195183806757425525678493322717101191371791385608432555648481983126822468787716619820803216979605115414238696910342784114105036100497376182943035055986239697994598850083148068160077637902893166873547164402114027907996485157629568445962365856761019422271838127722093204315171822017816947879312788677431731050377520062182210827218697852645534260696275069914448355726777611906452287874696914763437063897536676743607067520821225192242367179732664698603172296992537020357338238539474677632066566306099530681067987636822044778676790571526156752682098054008060114222048648235211088677652001733408972390404021234858733749816695639105516972681950213496564480918881121470308245056746614322544958130326224783348722937694521517671500544045766814081079949624060064148141994717787006797204280361180807876033049761456459736601225700682679513329369667135280396122391470910959848993310326370227556920372559598254083126663539278398534669117647275078081701776010725472872859706510326074619775290538573540867490363049236404542295177687297794359172552178522669357542909897340384086004138468924550754779156251358722715250078273456312400695475455417163793954731031875487316712914778226777199482042666876007631559282483559334130263484545101668472943337107974636189072668256721441101751960657630930579890571217013133779253750178886234600715126681471192732194876967974705346399942370828057595995901383937989262757916239301838161298743259102739530046115969689386067963504473841825131009263570767441844543498822061018165836221101888304318773602442335093044825332951926863660605860472577128040415789564658658760949664374550506483657520073315345872056924398120801950628759949600452074436826919971909683723140105806643040993541984696276659353515432883704923181750655292097082248942588369471655705227541285556415724326062964837770749373508012224806049763276210296913460315569722822241233699197676158719308644620420427399754206839767806165856149922370255128804008022894158723967534011470209293187340825716985586978090803483200178017155619123489584114366739929326163278379671370047745244869839433613663700756819627311904593632028673791092469734504709577625178604490022911775795635903527757590082803960967183621843334230396544679823577178014527391971507748702518305350972151551013587087843530024575829383956735693096238866790490928507739221629097063537066753821854932139055125113294075895205888035589321801553934686763162360788250393283287044372943027305965891770745945961986889133993939743871207337620200744875931142612339641944343171680789114958909236457693564727435886892140251185446323169957498865838357163507060810461080191719950542249186902301394200638270687404668379284242491907941635256318203438266891431268930422504844897599677815094683423460086838946308409185109218099582382778552584415280973758084138100423576874873870063202171622860532924077368038411226410982424137075153401511388846016395623440703728819399351640978516448071165407640197955386458301032352563028276255683153918357929629511204173057220830247093435703558115446149165108615114093718422630023156158974660742161614974080012659585301647749464656263935203569315114255688955520186777255637841729090088965765391872491332988456224961131971497744355291077767439804729220014482176434770117509356056419462005900009239209136304298407829604290242657099708763925121862278252306625756119750536758862668628973742695147479212115123029472181282286710958441680215133272578877020481546096934469554168091733460041143121617900951784375132039419469898821550045668043572570058493696157097990107188854285061406445356389995621965348460560570650030339594584723095149407512722475608482151421254532456705921344290329826363050666813741835759679010264383183900900426982032888709346018677367132594027571972221169542794074345583767463049532617665122373371521290569969371105186964800645814907996405338776139086310190546246384604748323569293460804330571886015865425563687845942211347686287345635863307441088145681980271736852356507802660571900537562489865889482887569802379094531316593700616535181265500877371865757489891692168209095013355949291124408538006770680341765096877490466381922766715154296827892218583851693874149152110945319202532501928382041466301997648354544173124414276785379652672874408934111186860872934076769116326310305732334678772045167997727383062882090208828400757534380610661377779325757078288356458428699838750743772414090234001977481318780610305357627821344366090949146786132210132425891844467997767873041828256234134043700919054596801357526093064192699494418046171274298296195482256954114655258087516722549288717090027359157455511851879040894028116277760672092385187083441153913073399744820306202713403415904767540872551716333818049110237976661040866987004713719042003989076669812744369018276469014791033171905093728432055155381417432895035462887923367878601704343805356077838351997152545875788421255157627568395226659972603450474196250982782741797808458813714356944564185599003224127949094102755697139363214826856367043369818010553390252163365646914562627350978269530096557709255865404190216746739329725367231970886697251809550069074583689069963702589492158734307597497699707240133463235516390446129797480719429956128048268047204543591754339902140829769117752756756640254603864290026766465198401090708487168957345895715796201132102446646179524368273962995578705952926635889671115894074874803013840940056804092814718734811424935001287568363352795557117634320149385855292209893075541155185813071840997739057109753026713343842457980886252867656475169859262711808274714294265796169504741796771078411571101568895566017457591608068423270814491920693553621543947420695982990619436159191379982387433106219432189136024006998634670840250290239820919458814199528126261098417860012452987283692318687902874431525284765468127643263104694648785136505375114357803385063650315850606567846223181757403184796658752831883482810099060965581175573600595472018972138870821704012188503589089312983577901121129384096015468665635783128187328247547396747703253167227848876375857098998250644524199723844151701171692547094345260705984206623624863025200858356498534598288885818837182768732337668791311668038065979442193089146448693564304304983481163551309921965499210282675806511346683589743875951772396657365219736195938929189194913603866951121211474438882753954283627685242299440002613473364208843011065437902891157181211306900059952190579781528346718337433070426993322556578048312559898523000343858583280211337001015551740564264887168033010324373483671489968825181607234395739483635473279714019629137437578202418402058472831775487234858953684209982498667100741552753960325361698144484766664097607076551754060058774146381192304836105880321853493984110452770827328015864518496319676496956772997285799067041881756809265780912475959186789310959941289091701276481834642675289237448850639346852618609404078337396010229041892757300921386637690046184313622092221004571731137121710033141949954712163519339774123876111514393465765745510617938718061718075427624246820706206513097174359222182497386901690780116043459521527451295494916371150126127885139936344065300888982623452532025961059541282507173548650339807646821116854039523643552224540017131300827038440753838260497817848232682664866150108586289982408576346133539639866204582603295916188307956861878979055339735816572725123077564389664492965932299327201118749922957311512039945521223240201861614795865781594425764262395505015459475298782119030307421574784849733256742420493040822099882934990213362559023986839861251517411493098541675438698612026504997672910042387255537044763407142603011627701658521544283806126507066809950962108520803801513474500628860129489954514573546085104019696530355183890711495955419544606370427274555802978084170866637129346922858611243000188133689238314755020716365649666508015110621759577720967578181249784134034218448190735692389034624789472600671172896533826257211028219493366440722205798291768435654013605110056243057507711873123636454792860553176398094588827230797626443615594865959218733721025781196375310351493917912241473013174855023562893117815539149124356605759549840248861429381411723105462164402703546998388349695403696882508852594064809339383417324335389995539584184254093812710500587943739048701034495377346964389985825257487964191243854980597731248857206612871044470780926805722219296644192414994538549931179642552745230707990175606441891527691676985823569517470064246515580038792977159971505239545187950296268445347668356088358175268298542170324080258251052505212130324032291636762881382690112676350744024786001193644440066312888995920861436849131628946153598900904961473292756038442260875702700876644162725420497761004241075375523703620055764764356475213384930815416641789093136407479352494741514359965132398005810050079712769278701727689982477311139253177662136649692334277810572805520893816077502651147420402118132997904208582456472242886685057974350356110556855192226286785864751129169380389439690087480943060525409115908004010113950206090900969378656405543377315866645193816357106564158210465750261866179310044005277701067186789848315372571363685516542670736721011537999881773042328315088634621956576331966070344901301716581807191286317331145895762130744313640384169651038385703541008799677975582920714820854722708866931850351350029851958455429625786818992266770515600651254611602067933969574648863508037785770666364296097069339524150102800437604862854592151492457145388426208639847728204236100786249638572774088675623239517270469309239777469024806416658384077153019639806842817612152325792161745872436694716543519436217788297635939709843315173670927681373363383353903100922396570493794562403726930398411618934668119866805396377914996271691478909523072315433776340422877786559932918466195686794466251658392097879912883494516793677784684198236322540982011084569982338042465451659855086246532402212464662527009941130185731810505052405688440520015630986082039730072866229271187473809869197967138323163253067634500736798619960092975673439149898924658486702001134377748096002118274868381123953640128778059709218413909757349748288493276267746224501766096505411050408289866608910472137569124319992319886861088629188556821840130556677908155742753289012689708898307149974792320133471502874302822410908046685158518189515265220227900769119780816155189375637470882563130139909992351368113701521646419453183387428480991031040459587046550183398642182777637062259072406619587993604652780984970666912030303214434444321321766239470602261647626317976250111487127612092867735861346773952791956558828036806186618127206715787287198240429343926529871974315913657619769004519811756418179900214555051535427409144731868451935941468871670221829870422733808694048737363567912099574378910420442631339471531232807924249749732720161341427597463880338080959640792534963010817410358084422994850015064058820199489206518347466383359483280770105018531621921847339511383187183239889243052196617438290925375271132119525753066641739136409571872841863410203349496192991324670603736500976752243241931040313590424279730070001219649174600942943688899079835840130919713079116806886915454525352963664133638797925409089588832047730124077626838143777559719800894492428955279096286610504688328201094657108127577172513768767077194234423509311399193346341607260197959316880115648996854247777828633365537709320576681405504969176366524590007205828196090933494864126583286143520105724897954678406661299739368381425239117708644931135400417085481219089014031843159444277889746562405441482248170799873012254790984957112690127547893716200236210767133267553360771350862894148962964394751909100786999734046658117637744732632795961854690949579982028712454663748319036815758012319412132356917867673036751004001326072064189963810228031637649922400442918031302927258749151728782481301418670903190942430586421133007679510340291841677718318755417340560247767747258067650418632125635979996798615403406706273021972196680887467165083548016303675978533182376393146654004780448610800824932670509442707049388274701594292650781112332094436551853602416449735658254547150056675272834885850149784967702015607148451073159325105059993407214344535293536092775335609544314000097261650199145125224831551164553028617070346672356884691139967780317031799038685125034743719032942793489103748528612157226093386802220110750761584119923272016086579088419862856640200511667479574601599566996463307939622331417030043620055213869308786035450540037074045654080958662819994053555689636408974942322351781353301588618474650516820023241884820352977482155348884525025216399152374522803095623575469793591669130415671350376694542232270045219873630074950092215548596169575089766048856734496377143475965140894307501167379775205350579292580788753326484995280622921632602019459094459083440394183280378226813066009671149119477851249723439230727130802681282511437091190411180891379885307376639730376005391482090130407182429137125471451801644463058380225554695677625205284941743993650504961490065966113746283950223401372532830392009432588108555958742665914124116499906385990212303436607082716886354711299235004105133941933078652917748445195225918169240065245645879761777574928958429243995860042888664484033028238787786166321636395058928056471993461723660029959522405814331795201828151402379321357446135068679691350610306803008671330607881763276961857801409774291401568837918097847790620066441037186937346746787289080616740042141483763842588531195434349339358802947789907959825466608791355064450035394775975215575425922677662314385015197797874182914928817645151068065592895536398112168769135024151146785931749683968052429338768205921254178788430088061985797992703403545298591021516024663838099027583280841266573381064501484372918215357240216975275609556629219159303074689477344561215387172187040581804115286660768140911201903303394067377273696317489248675668573119133497723484237905506311808477837761104082747574946386080379525764030351048213733629343235587473686907307904953032382441983338176649495457915629301057191299578381125454483223008000367455780353550864040222987531173669639588643518985580200713125621038174570991028610240653383936036338237437888358206313821063583676986839900852718052990399017523418968739439371422078768504955632055548252572449594083357047530585211938514897171375977194718314655506040121236425336997664795152117107299730557750019448291649081074366091743420979856412891210938208606521958820885838241030605187573672314048064857383359792781811086132852250016312427188032981047243678601092860486303651919812257374026921998285552630639026147077667928782100985230246175473606184569475041675429270838359023094084664492985495895971755028727550358536616809647701555371221306008222690849751127278960160822029647151370520784202562625621733264422550617427081907371330110199384841233920716248702177378163660727218808912437214559643631292395464424071131155221930195220976064144138679332063156886145947243561256448395959791294605274084905104880210847460156505326764967387916743740298922916848269278556691477504326328206509031560954412335434402847913429206151929686982774335583344437930625231309250662025289791443809626167912903011998039074847586995231708898245027517967907112959567211776360598984525501162624353632650296204664171952366828872523719359750150142240565300159733086020451503542199742092708278573846446982452120435490887489007601803045744196700502431059251552039000120826752523970358392003313060001867220775036462949245735846674199253315675797060894821075289755273551164126538667829315542278836215328913729590266360335628633898551124913590364481601667685400420850385851438278848207233433885394536958941375454577381188862492985489095328880897177896431351871847572181535036092697486731722762443515934561545982999881599582205066220649648580265278339118846857927906635498626353315347783054913279685797307808524342950770120041981198883501863113778911907217711330545199357052611930051793878471831545619264670171350549386495684024594398421764903169521874121945622398579011347006247078199896408496556111853211014653068947904232238625298753039930750641071406240724607241771760064391460273907121999673024469575771085197803088554589962371555874367705949955443937848565121287291503578206859002575761781901563775828878574122937961972665412924074778934215034236536062529092521595432065675153850414539543699351631180126604814086759633763765997321923287430191846341924661794561102130809264491029373194610976700183344442157011392526704325040639558688993915562408685249655122938612439165630976437032158977171594728293054145251358332396615066845743568763629313764868876654901272198538370259529317057951366649871084294045556061162190867467119804892276998565419082020378155707546213593028852589801181003106837646791834690866097483151871918303199061660713700772807068135624472806883520313952226752385631930700111180797033967249263113948752981484443868320546120070824125670258918752228392673865038016089268691464552936468203219616313617114815959425943785159500684978883247744812630737239730155692130545945756557470492834651599657089143364402862341137743313613020685027664431428228893595834937233966625276712757094813043478139048028581617702019495630995629027247299852568744322496522543104173528217087931227949055794380964082458934399611575360556807460018043150819123743454166727456379749733740448637479199062775120995513180467012679477822578945635872178010518605686161034237016978980008059237034645358577800152386110910811530732717632547615910191580503657632116102402371785854818503937080520162107012864528008139215258697210494885922890943178539742650051849713821287098339339611565505571736600918611171843511511941229690040236919210452759577504592082842873213335600260810927635326786973875035528006024199663023081042219704613767308193391136775359851325158298799144568092654167878829519856238033670909284759814870995329029089872951273247442873630491126996923627335521964719196707029894776361895377147013464115065811051503040389950261036286571409341498657123513089249862530879164262915499203017584361644583787023273781065754343230692374579850192243148117435164598170148857191986478147227408440060504820196493374954619888342060284000728458897595214280796494157390443590958185107336229691248882370977294538067743636599043806167398580279712774622969588560028589897113661967225832931146118856550898099990546606755529928428665474412472328105646449395707987071534730004167868983073972420068390746818873774034825020143274409376914893190361287518099078636411853552560068719331940454554800572732947277450968753478975802816097736939569778951276800321759356267579003141213870662012094249264616984710473820918543679144529352199086710746858924778792837126298818317325605976841050298553558110953641482770965019383595605831688223879763342318767905561153929073960484010991526208106417642295743666865824337030577671090002194514938778338386025698022853190259682719077401842873596448129828270488486232979527623874614141749602252542434703116187264096025187856919793323879263130015326524644281951157778140005889600205078702696922439283343601121363004538993099931133441023392837370986230447746569033277242600439688563632928302910113855719620263060155548045706741056863100204789452441523283292962231826790824167596200248131930117745187487349234283733660524633519681171782641851670308834185484546237915293841316601625815800396177814925591322627353090399848197299607342286970641879021637040590315675396497313783515559383963349532507207344251311769639243385175875628996739153017634812288813367227247285527892974541751089176658639238414818831789624145109824432798844343395155404964731132974495256415183762581875190525281342862368513341162765080511671107507143177994819775796941668937457374962270590619747810139300328552194494112202576983610655579281289184105129563593431089000185609736850070005093354612691414673956801594326582442102332383818710571432819666242648315975293334022495931852188578425619115748858504830134932954371084600382563230160065940554105823279020916179193132888992518444818405842454323327473748329973966835134792127194992387663637033471046037786169988326755196973824503833438582787419082915553933137651823695828254099738895084777394494420877133785307361790247896905732593782116934062831393467172400587184519628771418158102248834536347782871177099510469473359451731170928917516047897438488447545743423283225330462953840675635143290485131766885462992746255839296072036610298641490765339843032922073845012386977891132738180652847860223530979986250672542411242867895598837215677901996015912144689582860582271928620808860512098466932452381434724556532978656034077725888877184395260645138588087239796713822492310998358441490694018360692783956413500211003643892886901370281802938670039980417149939240293638477582108488130684110852267584890400146785503178555472836626984428311178822119196399136073837253415626590406976355749782039179561144948037927206365340301350650946242722393567209621932345702640244563024536109986196362205631381395700372301591663500244192214939175603474718552232845850903488169119353183667537529374211599018415058417214410645447203743123755899461209641658733572616947754603535671697755100241807724155475581311496700289806300919428907756285219925460251924651856074821852223029266095120984290010551757510188518626940139108326004498842331851490186380891166627922663196755639970512000090403605234652979719135803154992775691436502141005407057980974360716679987711785205492196701719380228193246323791252492461152273597204777669539513426299061434135419876739265674325385992675070742575652878089488609358374596418949876375510587759624203300964978880427653035111485181197787413545426011723430510993283192106291958004349321968984202383353644613030131635035811538053854624735548903094121675157741016864600304708385234560593429579985836112349945735938447385757927372469320331855304420068077267518870914214106806284615437730153944601160505658068198526769878438386896993126623891666038492647065360743169401603724886663452393555458413935288895196340480251150128316202433183795546457552227261929844106612901709708748011170299376010437366102911930023367110881239910074778462761751872287650662006006808043053289979348777084287275442141618825959477480140602052294149951265146390254488255126499140653938409754386490696267098285080156983849831840651017267744433490700933817101634133164275335113693519663872873908531919843803069500877608598702662789473888550335727672198376141149645240800296087348970258631577932596719561609890843696491646765104388499994437610418001043008902469718645148619731327752950459496423173325342155465239206088514345121481760394309393280437634112795762031330641682680723526244332601844733498323723454524965098814482462918821952103749056504949317237541234189517744818019030194459190722412618545250780780247843485778196029784840046074617444391116814748773021520543180566812107814850449610518467588378069462111046002272878199952187399640907897478698055857964615940691824857729667924565243689789003677917154763300017359436760658372765408081975682697828731500307528619098625835934576051693216977575748980494421099223265528366940611209275588080911659101394874037084079362634848107957039949090256039705859332490052656255568199480633684334640996841274635017016338182629625859795491012942444691815212552251778683893481948739227585465634241938232717355174172100101354812807654496683550151442104976046653954496593111359661525473625424910481819550503337204919924572707399486431049640483797417993890950356241538877367475058710171031520081815097027434966547220751203489441739557168600197078523178617481784971637841142358396140008823490381273672811394256395399307801030878755225463100553147543893736714545810193568842807000194011681502045204570437013363093629142045868141198688360054268000047064815474556925522953025586312256433869494451352664677788495626147527908081809605138583284929217947202498864534294622856474696160493298949526182491066358883233820474812827936059676876885888739467107928331385364082325824002166105023571583508691567211347205550078134079327292882939311100703926282141940312498207021043594038392867293015783535483255226186673845346752138714351869517509536514272358072087390344358032244915109707827207087083963016506583934898191497150362444794837279772373704299160525214383003594848532083843879425532950277807375612780562187293188391264016650282948101258550448543609374955543861862080475788935104599114848915803852783556204081055657535489710299346643969292034147860951786295391598528941049664426364529451060728376394863509919490177234879430293830873076744436728667632418135050052719395254740980692248979741838882570583745256462199859854936426459242661225990104797681694435890147757066346137596539593206017751722928090234412823349821491102434653510270289574973582318702709601453351575467408895855085942613448494734043204898608715127092836279927554549576846385390809536894706813483094675141122873936736570477763322773586289709588571720473255247886170129637473419219223362654036505696129470884244054315855950884626459674281847485176060088605533730930929211987801015230074644142617275051724175078137121853477693099775722321083083535850422382326810835868249179974292294793476154513821433866738927929847495136655301015044868806486656779276356242740381745030924928436751968421860292398681817864269055380149092636558003100655097787862166725629154897423284295637523352240998627596215079217847656885380389054118579280810337901679893052059907020399153339320431697480152621724389561681757130784439390686957647903281005304331233560624475172619162847466504782469236485776213740820913267429029858632924070744915006006616281001389298412433572624734317405722261215069048497915771624013717361352230000913200195972561456316660289062889855852263351351539637071966682236585444117250616678311486131213831940318307404188102288497994926817517898544552841500572186936548589015588721185770253632935420624502401333756629452818575354258495828620521393008253684524890279863064051586172343124094499019801125506784880467013015059144445276717988489911656089620699452816168459186066375760847837255664185719140166721036615016965782834866329096852017987272065220412315886335468601307930859215351319013151412888029716025155757645225347344968610585171993294010942696817433336516178990312805993625970757830714852373393840874336026283211369068089008740461183932485278212034681702380793139593324763521670800768113266696348723705050065080992993540553185032795690463664020352380413879898613725583706452164260175419913298945756897093744934260462769556112055492081893670072323456066761855752727199593164157712224547615657194245570029971365434286530615802319586179420259392505776110340080096723724202204114428225232981095685597200316107355005031772578519352359032499392533414226672932949261214093066788824280089061359417917383057560441712614873152504456519714725056716926175525382162572004131735524725542091650720880468803628723813192448356408390907865359957596628058706808762385794466013335921554721716372543978455948367212043267116545721152302152852701156379054240896767934249415528333709443185012450312662325709355214625248871129439116060622626324846539582713062035380310217172192127419043488849668690876308153567209774671693396450073267532238098265456223096416684324698284057906249453846808168145948549271112173145642207466751751767099708542407179562910030917755116685069364845011176785552111100154922166877245448046069769550933642973303268648715449129029753468823955004071925684683209725980513088057495644755051401347215465397775354497685141930096860813848288605216203210115860818489311883937333670714806394378732314112388707147092830759190263485449827165607235847235052170174092911374224725546852717532549863358825881173401027049935095621842982533877999701929257368725328190140044426150197996217080653279826641510881247952999590757115104691591938882841209330103449465526384816447806864585447546400788317699332783865138478383946424277021081226413832149846979914386232866986334660482399547147132505208150693621309427505251053690033131987112144879835115311296476640181881141823439296051067881674179296185218032853751459485510172532823224132640050660090851946424055332485600392173209495618738853423527859248422156116906269488873017328642781403998381669276067325675551413849860264579658036927074454630507949052357667041936495647107188302794830183096304390663270421396138584902900391547612658361752615201024522630181626410257928693798442691888743590842620845284687518379289239762516102952544665734624414903939859510068504959588779167044190353908984982685150529423953289203862353210044216453884343704535373348441797936499331203201188199550106567121151485579947124946747706294628783094768238870476433208050075366355169303104705613379731985353001784583127814523254098861156946296849752367392855750345754649212722641663466891564922953532802953494669624614288975391411435589918513487535328162878444781044275422274518288902586537034639372342352948389409692597650395384554329613075745954184303938920282634579785478861726603148107446613625006054397887548227333442946242521122668944809507728192003433286270692003311338148334150073879055865436605469142147424733128471222402169124626045115799330736250857309103637562938674523183640819339937792780407911430397892329787873818107006269550648404441764513931756277084386246031036142275852090785374191471560365735727425295309668110047673858222327305200154099355657853150292711934780443344413550082058600675024825765511261235999208295403556694534074021249964573675618413563024922805303257670707856178415471264207987466829850162764626558613187165683223158300949659723281667439775413426630796457889973899567137766778102245420901061270204492777042007400097933572244197206989643709644439613487338252572596930255535182282003550948955502755152148579494717382614373862999083867370955816611128548924653095926670608760501838215323454296376555767489075368793587690966435183238662173811206436067076173386933644786663874942115702363505796011569575554341067196341671885376663414280490731473197624473886646631575582404019927001633259843354598554149879360336624810003798003372080252099972275319196273977998959062518526343251906847486172395767509859655113042764718114515950689136664301710992017944157496346188061621390657363186035239735675494808257961558197085836733879240146212241863677642648496407658501744210994334373498635226508965513662920489537506197457790017184893715685338583191239894734097113805160559135059637304673959650078253975653370748595373716304192577669599069107304924946847799530336537096988272171450359307278546888801691985129664560229952745087718472456667953909340936895052680821691098839351620979413042545458311056301857804397309828594299056634882494521396806162763578805929371449115998605910762911096693145315957863547005224421956029903633930764875438374097592232452931715805013917699440262919496322500336092650343201594980739909376329573838880374808173476112200313646290397242499569122775273744331643365707923926048097995801778104058255554687266525393327862564324662586077384539923876309617863219447037386214760222705852010476057548834965449272992308172316397544373109449923163522950101618129454082402885921117978305528988822134599687473525300549735750352577449961251490113832712779663792855700088511098144725509470855186459863814954697161531785266294954304404007790228606356288078143805562874948110692438701403001732206653689924004368900550336196088526972847787512204630336964272076268961982704737447250137811779546243145054695255464428552846109886413308197418574242147572723276270056563336368836976270630801465961845857801470455897547876905355627034808604422453451363945091942812318530785072310348027256980327438759509028488340770682942757612613197207453179294010314934804775487285257038119963427613302131735703326883254645177400968656820019657886240085543166348197853272563672567558937650849120555830460132389019662169648690795242894020637697554718943918377295876469003918129926292435868332422663686249049788161564624567347428694305767076309128357684421130011422463308394396500643593630440974792165928886506768797266390058766984723385154907948419138375234211195309639992324703218582204764968643631052889932323200406999493921520386099606271405258602106148938694967654536478782926226593061395133288749736767311964467974030522878870656253627777474655430934250919603289494722405960501756982552557248131644864045254213962074164023112219569486901278228489919320858259088555351123289285604102894499012819301612942605043329173232718244394730633877994594995369594635677797661362728499800327289821999256041736549545061843420677839642834791765044100794412005496237458625756438116854406069814517048899143342963118726256157155080220543752370680019370975330065182015854504307335040541251478991434285156133246114262016139055948440117606309990924731415267304643502205139054351971409984182278530633329301996878102398454192604328370442395731632055248336946538340293003459596755546709786305509803123566598418231634615959429982115777336498079470752083282113114455602030181835272985047006071500782220586745149766329879250366520371206689892704846401663545058230825190167906234406456635539702748671237131070671563466453009186605056808393126256429884597752739968158576681624145355446359963914266816056704492442787927406650602433022988251079082027251387648705952990252665612466530326087121232492080700860425290277024614517276135958456595240714116087472419713626139615556047956573756270671333917659159149765611528958543688856072915756580047601570922913853459719043045866548854067159694112258305380522507505348296685761356903024016172530720995935002113314469185294476319816350292847468760497291828157940930991564323778486192102711175312479751658050428699705509040501722052663407452128594765131075641985061708934547639388330327249404435373584032210638902122514692543965307842713155577008705196961428833663431504166070747897749928723178095806466915562618499504417999131089831727095933305532540582189033579107071167241585399835099265988711542625277724067836833917669402000577829501767777139096702156544966291913448602924879208510485649033419318261091511169759360788683054347689194774401334010441245643530017233985330170185027932925653048152687868854749050610128193796395490642660955203623759477518505078463309508093904173364630277127891702677293873294716390046986207923393572081396643400869651401715631366256011331730005546362315213421083646999384997106683640088628024252964332382639805556171620806925649833314364426344385188755347882835610651821130523676472089035176377879407528271149737259084902880511794656212775192390852918694037928393537357486184805697163609965746721924472082303827849380517222580553572170386218475478124935534054107957008136748264000490308965643074450325193163381735008799297367526939750635127520155985156745190878757345208697217919971823222087694237405151945323538808625861060819726648657962336362108191024379643713278684267986730218466536473400194341756225769050323297480462928349352533926528067436839318767094970219381527787311411633657598204327492205040957479908776318535739230368723378747488237846876111763987359150119176973989769790821419712991620341274826036493802956421260537590507618309622390248780183146928099323197636559289150428484329657490758887820878916692026757978513630617584249867327981465289461053054748743951808939280902570477411564592237793800037659875262572716237757636613316903645107789858597755631075947826260457363616876790909154202413505205444685387982262066604264991949246045331453814691442349995139350701396302766415991087927872798153141453596911785067238956292005826915967177056379529885504778175533214736212068696729434612783328227971267347176175604649836190644883906401146496203538328356817212313748604906113049297673170318933022537696282034331405789143873125968977889884241408610550721641443518168516645481769912060064421927061218128332608780384174027178915287093889697135151979001590743044696647197222508441180831851697200314047317708494345087703552677045061081677855398842523975840155520950015173532127991495003442315169548249007421716242618739646913273042440941615521008437563579751049183049852899747825545987847876259420449223906834316489983132152658070073693911830669307002025480728483307291028519063061933926918033136416155938934523882825778225364893217851551236986328505514524538777002803827018882113632731326425404753127471894955871885513720028919517738166729252337792016781856221220661448815678275716046376933886388533439328083748113362684393851978876570942058821544822430824735191309611046573115836298827097601190330838900627794520220940103103156306997778928055921273502273613918244280064707831161734727431708067755189785297003716512782588528729445068602283891089356840028120426594245441484945116976989939382614675147426000706738057187014142266086334561409774982410240661502006707334615727133473136480212468899096963423416824305600492303591852147245574328342735024935024473568255849707904070945168713643734809873174447465426508242318604170472528878475158927804013107743844944811465549768873456609180147124624532096054294906625741353893661437825531195550362285827585482362899583768136115182673221275009243528255460194174874650803878048329476952150452257037312605684840987761674442665406344124656870827539434878928916322840472517031286608161870820546953457709862520827814241311149086616331194517457925792580887500095251044009856085757605407044409121691327830794065652190465147186295597827881377884787914108834268125189490629433649973400064585578023078071748871147629270028224850417132724495135719745166990906847693493364355789322141304144325835803096900860917424940648788795564308153969771805788084137940667661745920431378971347120686111627461376326391904722270829938513460159101597317711618428073158331118707404769248899557059791551682792853594075556774225891404384677793811001017400407367428066523831523799051851693152679492899893126468587595857785744663316636612645555964771484931642603676613948011299983080465937526250877516250117002334610594307835439045718312120508279820767102401203361587173276314279227046641187598884414799364549450836270401760893509875317457675346361651390684861336605930651062805451124024396480575434317119804074700058022485194771034449954723521092868362825947233538849449784387579544627445733124824404364787122824274842712346603766721639842047247593484918749812851399723456216399942245154069316858026963884319641456554264813429737007514948379449105094942170888755014950739344756543141247332191270439105999684981601058464808116335334488624485574054995096006475280313293327739277392671959466402800862072593010503035112376324962201845915597406453056897228124786693779006036487808643485666256836995543819060413618525920482763564135644149192019772450598196602954416300863708558785516297239374756516837295082184619855174316246656272782988107127813962321503605520363365118399923131852595927871819753702226507253835101249146740167987430532102684664791920676836851209912738247232900260478207772184631598775088533999030866832296349237172748562475996153827445921190830216697352013981240201756594265456402119389667636812546724474159600183045445473106513022781352708874030873215300464603123579885244701226081786408218043140213605924854948911247727566289913273441809238040802387058773562765141503378164322681849993216738942776270159580982813153658329297124230784675915092715901270186402811863121880128610103755943887061752742445724616537396077303195936390944529076688151189120396684435807919386453738894545765362728037848255314985482848380932575159607276463328760306668403558229494845328177547545133757665416356632368935321697534932576820344261601367614553444911291030556222737874450516777652016390102436811661314789440197945030580604606481813964231728967178354468970943547373057225480009664574250669865522000001
time preventOptimizations(3, 10, 5) 3.09944152832e-06
time preventOptimizationsWithBracket(3, 10, 5) 1.09672546387e-05
0.282608695652


This post has been edited by atraub: 06 August 2012 - 09:31 AM
Reason for edit:: fixed code tag

Was This Post Helpful? 0
  • +
  • -

#13 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 06 August 2012 - 09:35 AM

You'll have to help me out here... what exactly are you trying to prove?

This post has been edited by atraub: 06 August 2012 - 09:44 AM

Was This Post Helpful? 0
  • +
  • -

#14 ziggyfish  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 12

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 06 August 2012 - 09:54 AM

View Postatraub, on 06 August 2012 - 09:35 AM, said:

You'll have to help me out here... what exactly are you trying to prove?


Not trying to prove anything just suggesting a different answer, and I don't think "Everyone understands why it takes longer ". When you reply to my post can you actually read it?

If "Everyone understands why it takes longer ", then the original poster wouldn't have actually posted the question, right? I am sure there are others on this site that don't really understand how x ** y is actually evaluated by python.

Why does it matter that I posted a different answer to what had already been given, is this really how this community normally behaves to new members???????????????????????????????
Was This Post Helpful? 0
  • +
  • -

#15 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Why can adding bracket make an arithmetic expression much faster?

Posted 06 August 2012 - 10:41 AM

Quote

Why does it matter that I posted a different answer to what had already been given, is this really how this community normally behaves to new members???????????????????????????????
:plain: Don't be one of those members. No one is being rude; I was being blunt. No one has insulted you; you've taken offense to what I've said. So, yeah, this is no different than I'd treat any member regardless of level of experience.

Quote

If "Everyone understands why it takes longer ", then the original poster wouldn't have actually posted the question, right?
You clearly don't know Nallo. He's a far better programmer than most. I'm a professional in my field and assisted teaching Python at the collegiate level for 2 years, but even I have the humility to admit that I'm years behind him.

Quote

I am sure there are others on this site that don't really understand how x ** y is actually evaluated by python.
This is the advanced discussion forum. A general understanding of all of python's operators is taken for granted here.

I think you misunderstand why the question was asked, so let me explain. Nallo had noticed that the parenthesis appeared to make the expression compute faster. He had a (rare) D'oh! moment and didn't realize that Python's interpreter was parsing the exponents in a correct but counter-intuitive way. He mentioned it on here and sepp2k alerted him to his goof up.


EDIT:
let me also take this moment to point out that no one on this forum has any sort of "beef" with you. I believe I can safely say that no one here thinks lowly of you or thinks you're not smart. I chalked it up to you misunderstanding the initial problem and excitedly responding without reading the rest of the thread... it's understandable; we've all done it. I sincerely hope that you do contribute to DIC because it's always nice to have new faces in the Python forum. Try not to let this rocky start sour your opinion of DIC.

This post has been edited by atraub: 06 August 2012 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1