NevilleHolmes
SchoolofComputing
UniversityofTasmaniaLaunceston7250Australia
Email:Neville.Holmes@utas.edu.au
ABSTRACT
Thisarticleisthefirstinaseriesexpoundingthejoysoffunctionalcalculation.Functionalcalculationdoeswithoperationsappliedtofunctionsandnumberswhatnumericalcalculationdoeswithfunctionsappliedtonumbers.Thefunc-tionalnotationusedasthevehicleinthisseriesisprovidedbyafreelyavailablecalculationtoolcalledJ.
ThisarticlegivesadetailedillustrationofafewnumericalusesofthenotationsupportedbytheJinterpreter.Thisexplanationispreliminarytofollowingar-ticles,whichwillreviewsomeofthattool’ssupportfornumericalcalculation.TheillustrationtakesasimplefunctionandshowshowJ,oranyothertoolforfunctionalcalculation,canbeusedtoinvestigatespecialvaluesofthefunction.
CALCULATION
Calculationisanhonourableandsatisfyingoccupationwithalonghistoryandarichtradition[1].
Relativelyrecentdevelopmentsinelectroniccomputationhaveledtotheadop-tionofthreeclassesofaidstocalculation,namelyelectronicorprogrammedcalculatorsbaseddirectlyontraditionalcalculation,spreadsheetprograms,andcomplexmathematicalsystems.Electroniccalculatorsareunreliableandverypoorlydesigned[2].Spreadsheetprogramsareverypowerfulandusefulforthekindofcalculationthatsuitsthem,butclumsyandlimitedotherwise.Thecom-plexmathematicalsystemsareextremelypowerful,butinanelephantineway.
Thekindoffunctionalcalculationdescribedinfollowingarticlesislikeanenor-mousbutsympatheticextensionoftraditionalcalculation.Theextensionispar-ticularlyeffectiveindealingwiththekindsoftablestowhichspreadsheetpro-gramsaresuitedbutallowingconvenientlyfortablesofmanydimensions.Itisalsousefulforcollectionsoftablesofdifferentkinds.Theextensionisofsurpris-ingexpressivepowersothatproblemswhichwouldotherwiserequirethemightofacomplexmathematicalsystemcanbetackledsimply.
Thisarticlewillgothroughsomesimplenumericalcalculationsstepbystep,ex-plainingthemindetail.Readerswillgetmostbenefitoutofthedescriptioniftheygettheirowninterpreterandthemselvescarryoutthecalculations(andanyotherssuggestedbytheexamples)astheyarebeingdescribed.
ThenotationusedhereiscalledsimplyJ,andprograms(formanyofthemorepopularcomputingplatforms)toevaluateexpressionsinthenotationcanbedownloadedfromInternetlocation
ftp://archive.uwaterloo.ca/languages/jandhelpwithitcanbegotfromtheUsenetgroup
news:comp.lang.apl
BecausetheprogramswhichevaluateJexpressionsastheyarekeyedinseemtointerpretthenotation,theyarecalledinterpreters.TheJinterpretersthatcanbegotforfreefromtheInternetareoldversions,butinformationaboutup-to-dateversions,andmuchmuchmore,canbefoundat
http://www.jsoftware.com/Theprimitivefunctions,thosefunctionswithsymbolsfornames,usedinthisarticlearefew,andverymanymoresuchareprovidedbytheinterpreter,andarelistedandbrieflyexplainedbytheinterpreter’shelpfacilities.
Thepurposeofthisarticleistoshowhowsimplefunctionscanbeusedsimplytogetusefulresults,thekindofresultsthatshowtheinterpreterinthelightofautilitycalculator.Toallowthistobebetterappreciated,exampleswhichinvolvetheuseoflistsofnumbershavebeenchosen.
Thecalculationsusedhereasanexamplearebasedonanexplorationofafunc-tionnamedfinthedescription.Anyreadercarryingouttheexamplecalcula-tionscandefinefbykeyingin
f=:ˆ-o.
butthisdefinitionwillnotbefurtherexplainedherebecausetheexpressionusedtodefinefisafunctionalexpressionand,assuch,willbeexplainedinlaterarti-clesofthisseries.
FINDINGZEROES
Giventhefunctionfandaneedtoexploreitsbehaviour,thefirststepistonameausefullistoftestvalues,andthentoapplythefunctiontothosevalues.Keyingintheexpression
nn=:i.11
usestheprimitivefunctioni.(pronouncedintegers)toproducethefirstelevennonnnegativeintegers,towhichthecopula=:(pronouncedgetsorbecomes)givesthenamenn.
Thecopulaisonlyusedforconferringnames,anditisnotafunctionassuch.Noresultisshownbecausetheinterpreterisjustnaming.Howeveranynamed
2
resultcanbelookedatjustbykeyinginitsname,inthiscase
nn
0123456710
showsnntobealistoftenintegers.
Somegeneralremarksareappropriateatthispoint.TheJinterpretertakesintheexpressionsitevaluatesindented,buttheresultsareshownunindented.Forthefirstexpressionshownabove,thespacesbetweenthennandthe=:,andbetweenthe=:andthei.,arenotrequiredbytheinterpreter,buthavebeenputtheretomaketheexpressionmorereadable.Morethanonespacecouldhavebeenusedwithsameresult,andspacescouldhavebeenputbetweenthei.andthe11withoutaffectingtheresult.However,puttingaspacewithinthe=:orthei.wouldhaveaffectedtheresultjustasputtingaspacewithinthe11wouldhave,becausethenotationusessuffixeddotsandcolonstoextendtheASCIIcharacterset,sothatineffect=and=.and=:arethreedifferentcharacters.
Thefunctionfcannowbeevaluatedfortheargumentnn,anditsresultdis-played,by
fnn
1_0.4233111.1058710.660842.0318132.705384.5791074.2955.838074.8121995
whichshowsaquitedistinctivebehaviourindeed.
However,theinconvenientlysmallfontforcedontheprintingaboveoftheresultsoffnnmakesitdifficultheretoappreciatefullythenatureofthatbehaviour,soitisusefultodefinewithscantcomment
show=:\".&(0.1&\":)
whichnamesafunctionthatcanbeusedasin
showfnn
1_0.41.110.742132.7384.61074.62955.88074.821995toforceeachvaluetobedisplayedwithatmostonedecimalplace.Thisisper-hapsnotsousefulhere,butwillbesolater.
Oneofthevaluesintheresultlistisnegative.Noticethatthenotationdisam-biguatesthehyphenbyrepresentingthepropertyofnegativitybythesign_sothatthehyphencanbekepttostandforthenegationandsubtractionfunctions.Toinvestigatehowfbehavesfornegativearguments,thetestvaluescanhavetensubtractedfromthembeforeapplyingfbykeyingin
showfnn-10
31.428.325.12218.915.712.69.46.43.51
wherethevaluesdisplayedhavebeenroundedtoonedecimalplacebyshow.Tomakecompletelyplainwhattheargumentvalueisforeachresultvalue,thelaminatefunction,:canbeusedin
a,:showfa=:nn-10_10_9_8_7_6_5_4_3_2_1031.428.325.12218.915.712.69.56.43.51
wherethetestvaluesaretemporarilynamedasothattheycanbestackedby,:
3
ontopoftheresults.Caremustbetakeninputtingtogetherexpressionsliketheonekeyedinabove.Forexample,thecopula=:givesthenametoitslefttoitspredicate,whichiseverythingtoitsright,justasinEnglishsentencesthepredicateofaverbiseverythingtoitsright.Providingthereisaspacebetweenthefandthea,thentherearetwonames,andthecopulaonlyusesthenamenexttoit.Ifthere’snospace,thenameisfaandthereisnofunctionfanymore.Similarly,thepredicateofthelaminatefunctioniseverythingtoitsright,whichistheresultofapplyingftothevaluesofa.
Thesametechniquecanbeusedtostackthevaluesofnnontheresultoffnnby
nn,:showfnn01234567101_0.41.110.742132.7384.61074.62955.88074.821995whichshowsquitedifferentbehaviourfromthatfornegativeargumentvalues.
Themostinterestingfeaturehereisthatthefunctionhastwozeroes,onebetweenargumentsof0and1,andonebetween1and2.Thesezeroescannowbeex-ploredoneatatime,thoughtheexplorationofthesecondzeroishereleftasanexerciseforthereader.
THEFIRSTZERO
Thesimplestzerotoexploreistheonebetween0and1,andby
a,:showfa=:nn%10
00.10.20.30.40.50.60.70.80.9110.80.60.40.20.1_0.1_0.2_0.3_0.4_0.4
theelevenvaluesbetweenandincluding0and1aredisplayed.BecausetherestrictionsoftheASCIIcharactersetrequirethe%symboltobeusedforthedividefunction,ratherthanthemoreusualsymbol,theexpressionnn%10asksfornntobedividedbyten.Thus,theexpressionnn%10givesalistofvaluesbetween0and1incrementingbytenths,andfromtheresultofapplyingftonn%10itcaneasilybeseenthatthezeroliesbetweenargumentvaluesof0.50.6,abouthalfwaybetween.
Thelimitationsofthefunctionshowareevidenthere,butitcaneasilyberede-finedas
show=:\".&(0.2&\":)
whichthenreturnsaseconddecimalplacetosightin
a,:showfa=:nn%10
00.10.20.30.40.50.60.70.80.9110.790.590.410.240.08_0.06_0.19_0.29_0.37_0.42sothatthezerocanbepredictedtobeslightlycloserto0.6thanto0.5.Notonlyarefractionalvalueslike0.5and0.6alwaysdisplayedwithaleadingzero,buttheymustalsobekeyedinwithone.Hencethenextstepinfindingthezero,goingdowntohundredths,is
a,:showfa=:0.5+nn%100
0.50.510.520.530.540.550.560.570.580.590.60.080.060.050.030.020.01_0.01_0.02_0.04_0.05_0.06
wheretheleadingzeroofthe0.5oftheexpressionbeingkeyedinisrequired,notoptional.Thenewdisplayoftheresultsshowsthatthezeroisbetweenargumentvalues0.55and0.56.
Theresultvaluesarebecomingrathertooclosetozero,andwillnowneedtobescaledup,soin
a,:show1000*fa=:0.55+nn%1000
0.550.5510.5520.5530.5540.5550.5560.5570.5580.5590.565.383.972.561.16_0.24_1._3.04_4.44_5.83_7.23_8.62
theresultsaremultipliedbyathousandbeforebeingdisplayed,the*symbolbeingusedtostandforthemultiplicationfunctionbecausethesymbolisnotprovidedintheASCIIcharacterset!Intheabsenceofparentheses,therightargu-mentofafunctionistheentireexpressiontotherightofthefunctionsymbol,sothatthe*in1000*takestheresultoftheapplicationoffasitsrightargument.
Bynow,theargumentvaluesaregettingabittoolongtoprintoutcomfortably,andthewaytheycorrespondshouldbegettingtobeclear,sotheywon’tbeshownstackedanylonger.Theargumentoffnowbeingfrom0.55to0.56,andthezerobeinglocatedbetween0.553and0.554,thenextnarrowingdowncanbedoneby
show10000*f0.553+nn%10000
11.610.28.797.395.994.583.181.780.38_1.02_2.42whichnowplacesthezerobetweenarguments0.5538and0.5539.
TheJinterpretermakesiteasyenoughtobringdownthepreviouslineandsim-plyinsertthethreeextradigitsneededateachstageofthecalculation.Butbynowthestringsofzerodigitsarebecomingabithardtokeepvisualtrackof,so,usinge-notationforthelargescalingintegerandthesmallintervalsize,thenextstepbecomes
show1e5*f0.5538+nn%1e5
3.792.390.99_0.42_1.82_3.22_4.62_6.02_7.42_8.83_10.23
Thisprocessofnarrowingdownhasnowbecomesomewhatrepetitive.Ofcourse,thewholeprocesscouldbemadeautomatic,butbydoingitstepbystepthesuccessionofnumbersgivesabetterfeelforhowthefunctionfisbehaving.Nevertheless,therepeatedpartoftheexpressionusedjustabovecouldrelativelyeasilybeencapsulated(byanexperiencedJuser)asin
g=:]*f@(+nn&%)
5
sothattheinvestigationcannowproceedasfollows.
show0.55382g1e6
9.868.467.065.6.262.851.450.05_1.35_2.75_4.15
show0.553827g1e7
0.51_0._2.29_3.69_5.09_6.49_7.9_9.3_10.7_12.1_13.5
show0.5538270g1e8
5.143.732.330.93_0.47_1.87_3.27_4.68_6.08_7.48_8.88
show0.55382703g1e9
9.317.916.515.113.712.310.9_0.5_1.9_3.3_4.7
Forsometimenowtheresultshavebeenshowingastrangeuniformity.Itmightbesuspectedeitherthatthearithmeticisbeginningtogiveout,orthatthevari-ationbetweensuccessivevalueshasbecomeuniform.Thiscanbecheckedbytakingtheresultvaluesinpairsandsubtractingthem.Thisisdone(withoutex-planationhere)by
show2-/\\0.55382703g1e9
1.41.41.41.41.41.41.41.41.41.4
whichimmediatelyshowsthepostulateduniformity.Indeed,keyingintheex-pressionwithouttheshowgivestenvalues1.40169soitisveryuniform.Thiscouldallowafairlyaccurateinterpolationbyhandofjustwherethezerois,but,forthepurposesofexploration,theestimationprocessiscontinuedhereasbe-fore,exceptthatnow
show=:\".&(0.1&\":)
becauseonlyonedecimalplaceisnowneededtobeshown.
show0.553827036g1e10
97.66.24.83.420.6_0.8_2.2_3.6_5
show0.5538270366g1e11
6.24.83.420.6_0.8_2.2_3.6_5_6.4_7.8
show0.553827036g1e12
6.34.93.52.10.7_0.7_2.1_3.5_4.9_6.3_7.7
show0.55382703g1e13
7.25.84.431.60.2_1.2_2.6_4_5.4_6.8
show0.553827035g1e14
1.90.5_0.9_2.3_3.7_5.1_6.5_7.9_9.3_10.7_12.1
show0.5538270351g1e15
4.93.320.7_0.7_2_3.3_4.7_6.2_7.5_8.9
show0.55382703513g1e16
6.74.46.72.2000_2.2_6.7_2.2_6.7
Thevalueshavebecomeerratic,somuchsothatdoubtmuchattachtoanyat-tempttoaddfurtherdigitstothevaluefoundforthefirstzero.However,check-ingwith
f0.55382703510.553827035130.5538270351354.88498e_156.66134e_160
suggeststhatatleastthefirstfifteendecimalplacesshouldbereliable,providedthecalculationbuiltintotheinterpreterisreliabletosuchprecision.
6
Itisimportanttorealisethatthebarrierthathasbeenencounteredhereisoneofprecision,notrange,since
4*4e324e_321.6e331.6e_31
showsthatamuchgreaterrangecanbesatisfactorilyused.
FINDINGTHELOWESTVALUE
Whilethevalueofthesecondzerocanbeaseasilyfoundasthefirst,betweenthetwozeroesallthevaluesoffarenegative,itmightbepresumed.Thiscanbeexploredby
show0.5g5
0.4_0.9_1.8_2.3_2.1_1.20.73.67.813.721.6
wheretheintervalbetweenargumentsis0.2andstartingfrom0.5.Thissug-gestsaminimumvalueforfofabout_2.3%5whentheargumentisabout1.1,probablyjustabitlargerthan1.1.
Beforegoingfurther,itisconvenienttoredefinefasitsnegation,thus
f=:-&(ˆ-o.)
sothatthevaluesbeinglookedatwillbefreeofthenegativesign,thoughnowwhatwaslowestvaluewillhavebecomethehighest.Consequently,
show1.1g100
45.245.345.445.445.545.545.445.445.345.145
suggeststhat,whilethenowhighestvalueoffis0.455,theargumentcorre-spondingtothisvalueisroundabout1.14.Butthisisnowestimation,andonedecimalplaceforshowistoofew.Thenextstepsincalculationaretherefore
show=:\".&(0.2&\":)show1.14g1000
454.65454.654.67454.68454.68454.68454.68454.67...
whichverifiesthehighestvaluetobeabout0.45468butit’smainlyaguessthattheargumentforthatvalueisabout1.144.Evenwhenweissue
show=:\".&(0.3&\":)
togetthreedecimalplaces,whichthenallows
show_45468+10*1.144g10000
0.1510.1720.1910.2060.2180.2260.2320.2340.2340.230.223
wherethe_45468+10*reducesthesizeofnumbersdisplayedandgetsanextradecimalplaceatthesametime.Theprocedurecanbecontinued,thus
show_4546823+100*1.1447g100000
0.4470.4550.460.4610.460.4550.4470.4360.4220.4050.384
whichaddsanextradigit(abituncertainly—isit2,or3?)tothevalueoftheargument,andtwoextradigitstothevalueofthefunction.Theproceduregoeson,heresplittingthedifferencebetweenthe2andthe3.
7
show_454682346+1000*1.144725g1000000
0.1020.1160.1260.1340.1380.1390.1370.1320.1240.1130.098
whichconfirms2,anditssuccessor9,andagainaddsacoupleofdigits,13,maybeeven138,tothevalueofthefunction.Now
show_454682346138+100000*1.144729g1e7
0.1320.3950.6260.8250.9941.1311.2361.3111.3531.31.344
showsthatthelastdigitofthepreviousfunctionvalueshouldhavebeen9ratherthan8,butstillgivesanothertwofunctionvaluedigitsforthesingleargumentdigit.Inthenextstep
show_45468234613935+1e6*1.1447298g1e8
0.2730.5470.7660.9841.1171.2971.3441.3911.431.4771.477
leadsimmediatelyto
show_45468234613937+1e7*1.144729g1e9105_4511_411_4
whereeverythingnowblowsupatapointwherethefunctionvalueisknowntoabout16digits,buttheargumentvaluetoonly9.
Thismismatchbetweentheaccuracyoftheresultandthatofitsargumentisagoodillustrationoftheinherentunreliabilityofsimplecomputerarithmetic.Moreextremeexamplesofmismatchcouldeasilybeconcocted.
CONCLUSION
Theproceduresdescribedinthisarticleshowtheway,orthestyle,inwhichcal-culationscanbecarriedoutinteractivelyusingatoollikeJ.Ifthecalculationtoolismastered,mostcalculationscanbecarriedoutinthesamestyle.Thebarrierisattainingthatmastery.
Indeedtherepeatedsearchingforananswerbyakindoftrialanderrorisnotcharacteristicoffunctionalcalculation,sincemasterywillenablefunctionstobedefinedwhichcandothesearchingautomatically.Suchvirtuositywouldnotbeappropriatelydemonstratedinanap´eritif.Theinteractivestyleofcalculationdependsontwofactorsillustratedinthisar-ticle.Thefirstissimplytheabilitytokeyinanexpressionandhaveitevaluatedonthefly.Thesecondistheabilitytogiveanametoanexpressionthenusethatnamefromthenonasthoughitwerethatexpression.
Thisarticleisonlyanap´eritiftothemainmealofgettingtogripswitharamifiedfunctionalcalculationtool.
References
1.Menninger,K.(1958)ZahlwortundZiffer,Vandenhoeck&Ruprecht,G¨ottingen,
8
2ndedition(asNumberWordsandNumberSymbolsbyMITPressin1969).
2.Thimbleby,H.W.(1995)ANewCalculatorandWhyitisNecessary,The418–433.9
˜/tex/fc/screeds/mt0/na.tex(0/3)
ComputerJournal,38(6),.
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务