class19 - PHYS 5900 Class 19 (10/07/2009) Zi-Wei Lin Naming...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PHYS 5900 Class 19 (10/07/2009) Zi-Wei Lin Naming Patterns Names of patterns must be symbols , i.e., Head[patternName] must return Symbol . 2-dimensional forms can not be pattern names. In[1]:= ? Symbol Symbol @ &quot; name &quot; D refers to a symbol with the specified name. In[2]:= Head 8 x5, a, abcde, Sin @ x D , x y &lt; Out[2]= 8 Symbol, Symbol, Symbol, Sin, Power &lt; In[3]:= Head : x y , x y , x z y , x y , x † , x + , x * , x ‘ , x &gt; Out[3]= 8 Power, Subscript, Power, Underscript , SuperDagger , SuperPlus, SuperStar, OverHat, OverBar &lt; x_ stands for any single expression to be named x on the right-hand-side of a definition or transformation rule; full form is Pattern[ x ,Blank] In[4]:= Pattern @ x, Blank @DD Out[4]= x_ In[5]:= H h @ a D + h @ b, c D + h @ a, a DL * h @ d, e, f D . h @ x_, y_ D-&gt; x ^ y Out[5]= H a a + b c + h @ a DL h @ d, e, f D In[6]:= H h @ a D + h @ b, c D + h @ a, a DL * h @ d, e, f D . h @ x_, x_ D-&gt; x ^ x Out[6]= H a a + h @ a D + h @ b, c DL h @ d, e, f D In[7]:= myfunc @ x_ ^ n_ D : = 8 x, n &lt; In[8]:= Map @ myfunc, 8 3, x, a ^ 4, Sqrt @ 1 + x D&lt;D Out[8]= : myfunc @ 3 D , myfunc @ x D , 8 a, 4 &lt; , : 1 + x, 1 2 &gt;&gt; In[9]:= 8 3, x, a ^ 4, Sqrt @ 1 + x D&lt; . I x_ ^ n_ fi 8 x, n &lt;M Out[9]= : 3, x, 8 a, 4 &lt; , : 1 + x, 1 2 &gt;&gt; In[10]:= Clear @ myfunc D x:pattern stands for any expression matching pattern , and this expression is named...
View Full Document

This note was uploaded on 04/25/2010 for the course PHYS 5900 taught by Professor Lin during the Fall '09 term at East Carolina University .

Page1 / 6

class19 - PHYS 5900 Class 19 (10/07/2009) Zi-Wei Lin Naming...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online