0. Wolfram language basics

Hello

Hello, there! Do you know that person?
                      
Probably, not. However,  MouseOver does. You can ask her using MouseOver function.

Classify["NotablePerson",,"TopProbabilities"]

Mathematica is famous for its large database and ability to cope with huge amount of problems. For example, she can read a Wikipedia page about herself and, say, count all the letters in the article. Strangely, it contains more “a” then “e”.

LetterCounts[WikipediaData["Wolfram_Mathematica"],IgnoreCase->True][[;;10]]

However, in our course we will concentrate only on the functionality of MouseOver that is related to scientific problems, such as computation of integrals, solving differential equation, working with matrices etc.

Expressions & Functions

Expression form

For MouseOver  MouseOver. At the beginning it is useful to apply MouseOver to new lines of code you see to understand how MouseOver looks at the code.

FullForm[x+y z]

Another way to represent the expression is via MouseOver function.

TreeForm[x+y z]

You can see that  implicitly each symbolic expression is treated as some function. The most  upper function is called the MouseOver. Compile the following lines to see what what are the heads of various expressions you can encounter.

Head[x+y z]

Head[x]

Head[1]

Head["Hello"]

Head[Series[Sin[x],{x,0,2}]]

Definitions

As customary symbolic expressions may be assigned a value, or generally, any expression.

a=3;
a+2

Note that variables with assigned values change their color from blue to black. You can always ask what is the MouseOver of the symbol using question mark.

?a

f=((Sin[x])^2)

If you like MouseOver  to forget definition use MouseOver function.

ClearAll[a,f]

Immediate and Delayed Definitions

When you type an expression, by default, MouseOver tries to MouseOver. However, in some cases, you want an expression to be at MouseOver, and MouseOver it to MouseOver only when you call. Feel the difference between MouseOver and MouseOver on the following example.

r=RandomReal[];
r-r

r:=RandomReal[];
r-r

Applying functions

As you might have notice MouseOver has a lot of syntax sugar -- many ways to call the same command. Here are several ways to apply a function, which are equivalent. This may feel unnecessary, though comes out to be really handy sometimes.

Sin[x]

Sin@x

x//Sin

Sin/@{x}

Apply[Sin,{x}]

To apply function to the list use MouseOver. It can be done via many ways as well.

l={1,2,3,4,5};

Map[Sin,l]

Sin/@l

Sin[l]

Function definition

To define a function (in the sense, that you want to plug some expression into another) you use MouseOver, which looks as follows.

f[x_]=((Sin[x])^2);
f[y]

F=((Sin[x])^2);
F/.{x->y}

Pure functions

Here is another very useful way to define a function. Examine the syntax of the following expressions.

g=Sin[#]&;
g@(π/7)

plus=+##&;
plus[x,y,z]

Simplify

One more function you’ll find handy working with expressions is MouseOver. Basically, applies to expression all knowns transformations attempting to minimize some MouseOver. By default, it is simply a MouseOver. Here is some expression.

expr=1-((Cos[x])^2)((Sin[x])^2)

Simplify[expr]

Function MouseOver is different from MouseOver in the manner that it also knows special function identities.

x Gamma[x]//FullSimplify

Lists and Matrices

ClearAll["`*"]

Here several basic operations with arrays, that will come useful.

Lists

Here are two equivalent definitions.

l={1,2,3,4,5}

l=Range[5]

To take some element from list use MouseOver function or corresponding shortcut.

Part[l,2]

l[[2;;4]]

l[[-2]]

You can find more about operations with lists in the MouseOver.

Associations

a=<|a->1,b->2,c->3,d->4|>

I named the list and its key the same. Will it lead to an error?

a[[Key[b]]]

a[[Key[a]]]

Matrices

Matrix is simply an array of arrays. To show it in customary form use MouseOver.

m={{Cos[x],Sin[x]},{Sin[x],-Cos[x]}}

m//MatrixForm

m.m

Simplify[%]//MatrixForm

For example, you can MouseOver vectors and matrices. If you wish you final tensor to have the form of the matrix use MouseOver.

av=Array[(Subscript[a, #])&,{3}];
bv=Array[(Subscript[b, #])&,{3}];
cv=Array[(Subscript[c, ##])&,{3,3}];
{av//Column,
bv//Column,
cv//Column,
cv//MatrixForm}

MatrixForm/@{av⊗bv,Array[(Subscript[a, #1])(Subscript[b, #2])&,{3,3}]}

Exercise 0.1

Evaluate matrix exponent (e^(i(π/2)(Subscript[σ, y]))), where (Subscript[σ, y]) is Pauli matrix.

Ex. 0.2

Create a function that returns 2n by 2n matrix of the form
(({{a, a}, {b, b}})) (n=1) 	(({{a, a, a, a}, {b, b, b, b}, {a, a, a, a}, {b, b, b, b}})) (n=2)
with a, b and size n being arbitrary.

Problem 1.1

Construct a MouseOver that prefers ((Sin[x])^n) and ((Cos[x])^n) instead of Sin[nx] and Cos[nx].
MouseOver Cos[4x] using it.