资源描述:
《变换规则和定义》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第十讲变换规则和定义1.应用变换规则2.对规则的操作3.定义4.赋值的一些特殊形式5.索引的定义6.函数的定义7.定义的次序8.即时和延时的定义9.记住已知值的函数10.定义联系不同的符号11.定义数值值12.修改内置函数13.使用赋值列表1.应用变换规则expr/.rules在表达式上应用一次规则expr//.rules在表达式上重复应用规则直道结果不再改变应用变换规则expr/.lhs->rhs在表达式上应用某个变换规则expr/.{lhs1->rhs1,lhs2->rhs,...}在表达式上依次应用一系
2、列规则应用一组变换规则expr/.{rules1,rules2,...}应用一组规则得到一个数组一次或重复应用规则November11,20052StartLearningStepbyStep1.应用变换规则(续)Applyingrulestowholeexpressionsexpr/.rulesapplyrulestoallsubpartsofexprReplace[expr,rules]applyrulestothewholeofexpronlyReplace[expr,rules,levspec]applyrulestopart
3、sofexpronlevelsspecifiedbylevspecApplyingrulesinonewayorallpossiblewaysReplace[expr,rules]applyrulesinonewayonlyReplaceList[expr,rules]applyrulesinallpossiblewaysNovember11,20053StartLearningStepbyStep2.对规则的操作CreatingandusingdispatchtablesDispatch[rules]createarepresent
4、ationofalistofrulesthatincludesdispatchtablesexpr/.drulesapplyrulesthatincludedispatchtablesNovember11,20054StartLearningStepbyStep3.定义Manualandautomaticapplicationoftransformationrulesexpr/.lhs->rhsapplyatransformationruletoaspecificexpressionlhs=rhsassignavaluewhichde
5、finesatransformationruletobeusedwheneverpossibleRemovingassignmentsx=.removethevalueassignedtotheobjectxClear[x,y,...]clearallthevaluesofx,y,...November11,20055StartLearningStepbyStep4.赋值的一些特殊形式Modifyingvaluesofvariablesi++incrementthevalueofiby1i--decrementi++ipre-incr
6、ementi--ipre-decrementii+=diaddditothevalueofii-=disubtractdifromix*=cmultiplyxbycx/=cdividexbycNovember11,20056StartLearningStepbyStep4.赋值的一些特殊形式(续)Assigningvaluestoseveralvariablesatatimex=y=valueassignthesamevaluetobothxandy{x,y}={value1,value2}assigndifferentvaluest
7、oxandy{x,y}={y,x}interchangethevaluesofxandyAssignmentsformodifyinglistsPrependTo[v,elem]prependelemtothevalueofvAppendTo[v,elem]appendelemv={v,elem}makeanestedlistcontaningelemNovember11,20057StartLearningStepbyStep5.索引的定义Manipulatingindexedvariablesa[i]=valueaddorover
8、writeavaluea[i]accessavaluea[i]=.removeavalue?ashowalldefinedvaluesClear[a]clearalldefinedvaluesTable[a[i],{i,