{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# class34 - PHYS 5900 Class 34 Zi-Wei Lin Rule-Based...

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

PHYS 5900 Class 34 (11/23/2009) Zi-Wei Lin Rule-Based Programming in the form of a collection of user-defined rules (assignments, function definitions); lhs=rhs i.e. Set[lhs,rhs] lhs^=rhs UpSet[lhs,rhs] lhs:=rhs SetDelayed[lhs,rhs] lhs^:=rhs UpSetDelayed[lhs,rhs] lhs is usually in the form of fname[patt1, patt2, ...] In[1]:= ?UpSet lhs ^ = rhs assigns rhs to be the value of lhs , and associates the assignment with symbols that occur at level one in lhs . Immediate assignments/function-definitions: In[2]:= a = Random @ Integer, 10 D Out[2]= 10 In[3]:= ?a Global`a a = 10 In[4]:= 8 a, a < Out[4]= 8 10, 10 < In[5]:= f @ n_ D * g @ m_ D ^ = Random @ Integer, 8 20, 30 <D ^ H n * m L Out[5]= 20 mn In[6]:= ?f Global`f f : f @ n_ D g @ m_ D = 20 mn In[7]:= ?g

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

View Full Document
Global`g g : f @ n_ D g @ m_ D = 20 mn In[8]:= f @ 2 D * g @ 3 D Out[8]= 64000000 In[9]:= f @ 2 D * g @ 3 D Out[9]= 64000000 The above 2 calls give the same output. Delayed assignments/function-definitions: In[10]:= b : = Random @ Integer, 10 D In[11]:= ?b Global`b b : = Random @ Integer, 10 D In[12]:= 8 b, b < Out[12]= 8 8, 5 < In[13]:= p @ n_ D * q @ m_ D ^: = Random @ Integer, 8 20, 30 <D ^ H n * m L In[14]:= ?p Global`p p : p @ n_ D q @ m_ D : = Random @ Integer, 8 20, 30 <D nm In[15]:= p @ 2 D * q @ 3 D Out[15]= 729000000 In[16]:= p @ 2 D * q @ 3 D Out[16]= 191102976 The above 2 calls give different outputs. In[17]:= ClearAll @ a, b, f, g, p, q D 2 class34.nb
Example: Implement relations for non-commutative multiplication ** (the case for linear operators in quantum physics, or for matrices).

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.

{[ snackBarMessage ]}

### Page1 / 6

class34 - PHYS 5900 Class 34 Zi-Wei Lin Rule-Based...

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

View Full Document
Ask a homework question - tutors are online