SlideShare a Scribd company logo
Principles of
Mathematica
Programming
kobayashikorio@gmail.com
Oct.31, 2016
Blank is the alpha
_
_
Expression
_[]
_[]
Expression with Blank between the brackets
_[_]
_[_]
Expression with Sequence
_[_,_]
_[_,_]
Blank can be replaced by the Expression
introduces Expression Nested
_[_[_]]
_[_[_]]
Blank can be replaced by the Expression
introduces Expression Serialized
_[_][_]
_[_][_]
Blank can be replaced by the Expression
introduces Sequenced Expression
_[_[_],_[_]]
_[_[_],_[_]]
So, Blank, Expression, Sequence,
and Symbol is the Atom of
Mathematica
Blank of Blank
__
__
Blank of Blank produce Named Type and Named
Pattern Replacing the Blank with Symbol
_h
_h
a_
a_
Blank of Blank of Blank produce Named
Pattern having Type
___
___
a_h
a_h
Replacing Blank with Symbol makes Named
Expression and Expression to the Function
x[_]
x[_]
x[a_h]
x[a_h]
Expression Compound
x[_];x[_,_]
x[_,_]
So, Named-Expression,
Pure-Function, Pattern, Boolean,
Type, and Number is the static
Primitive of Mathematica
Running
Evaluator
Predefined Expression “Set” lets run the
evaluator
Set[x,1]
1
Evaluation of Symbol “x”
x
1
Predefined Expression “Plus”
Plus[x,a]
1+a
Set Something
to
Expression
Expression Definition with Pattern
Set[f[a_],Plus[1,a]]
1+a
Evaluation of Definition
f[b]
1+b
Syntax Sugar for Expression Definition with
Pattern
f[a_]=1+a
1+a
Expression Predefined, “List”
List[1,2,a]
{1,2,a}
Syntax Sugar for “List”
{1,☺,a,f[2],a=2,{a,0}}
{1,☺,a,3,a=2,{2,0}}
Set
and
SetDelayed
Set and SetDelayed - Set
a=2;f[a_]=1+a
3
f[y]
3
Set and SetDelayed - SetDelayed
a=2;f[a_]:=1+a
3
f[y]
1+y
Listable
Plus is Listable
Plus[{1,2,3,b},c]
{1+c,2+c,3+c,a+c}
{1,2,3,b}+c
{1+c,2+c,3+c,b+c}
Apply Expression to List
Map[g,{2,3,4,b}]
{g[2],g[3],g[4],g[b]}
Apply User Defined Expression to List
f[a_]:=1+a;
Map[f,{1,2,3,b}]
{2,3,4,1+b}
Making List
Table[i,{i,5}]
{1,2,3,4,5}
Direct Replacement of List Components
n={1,2,3,4,5,6,7};
n[[{3,5}]]=☺;n
{1,2,☺,4,☺,6,7}
n={1,2,3,4,5,6,7};
n[[3;;5]]=☺;n
{1,2,☺,☺,☺,6,7}
Symbolic
Computation
Each of Blank and Expression is Member of the
Ring
{_+_,_*1,_*0,_^-1*_}
{2_,_,0,1}
{_[_]*1,_[_]*0,_[_]^-1*_[_]}
{_[_],0,1}
Any Symbol can name the Expression
{0[],☺[],{1}[],Sin[_]}
{0[],☺[],{1}[],Sin[_]}
Pure Function
Function and Pure Function
f[a_]:=a^2; Map[f,{1,2,3,b}]
{1,4,9,b^2}
Map[#^2&,{1,2,3,b}]
{1,4,9,b^2}
List Element Selection with Pure Function
Select[{1,2,3,4,5},#>3&]
{4,5}
Pure Function returned from Evaluation
h[x_]:=x^3+x^2;h'
2#1+3#1^2&
h'[2]
16
Replacing with
Rules
Replacement with Rules
Unset[x];
ReplaceAll[{x,y,z},x->5]
{5,y,z}
{x,y,z}/.x->5
{5,y,z}
Expression Replacement Applying
Rules
g=p*z+q/.z->y
q+py
g/.{q->2,p->3}
2+3y
Replacement of List components
{1,2,3,4,5,6,7}/.(2|4|7)->w
{1,w,3,w,5,6,w}
{i,j,k,l}/.{j->k,k->j}
{i,k,j,l}
Applying Answer Set of Solve to the Original
Equation
x=.;
solution=Solve[y^2==x,y]
{{y->-Sqrt[x]},{y->Sqrt[x]}}
y^2==x/.solution
{True,True}
Pattern and
Replacement
Pattern Priority
q[_]= -1;
q[1]= 0;
q[x_Integer]:= 1;
q[x_List]:=Total[x];
{q[2],q[1],q[{1,2}],q[a],q[a=1]}
{1,0,3,-1,0}
Replacement of List Components with
Conditioned Rule
x=9;{2,3,4,5}/.x_/;x>3->0
{2,3,0,0}
x=9;{1.,2,3}/.x_Integer->0
{1.,0,0}
Replacement of List Components by Pattern Test
x=1;
{1,2,3,4}/.x_?(#>2&):>x+1
{1,2,4,5}
{{1,2},{2,4}}/.
{x_/;EvenQ[x],y_}:>{y,x}
{{1,2},{4,2}}
Programming
Paradigms
Procedural Programming
sum=0;
Do[sum=sum+i,{i,10}];
sum
55
Functional Programming
sum[0]=0;
sum[n_/;n>0]:=n+sum[n-1];
sum[10]
55
Mathematica List Oriented Programming
Apply[Plus,Range[10]]
55
Object Oriented Programming
class[nam_] := Module[{a},
put[nam[x_]] ^:= a = x;
get[nam] ^:= a; ];
class[alpha]; class[beta];
{put[alpha[2]], put[beta[1]]};
{get[alpha], get[beta]}
{2,1}
eof

More Related Content

What's hot

The Properties of Mathematics
The Properties of MathematicsThe Properties of Mathematics
The Properties of Mathematicsarinedge
 
Integers and Opposites
Integers and OppositesIntegers and Opposites
Integers and Opposites
Kathy Favazza
 
Relations and functions
Relations and functions Relations and functions
Relations and functions
Leslie Amoguis
 
Sets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeySets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeyravingeek
 
Properties of addition and multiplication
Properties of addition and multiplicationProperties of addition and multiplication
Properties of addition and multiplicationShiara Agosto
 
Commutative And Associative Properties
Commutative And  Associative  PropertiesCommutative And  Associative  Properties
Commutative And Associative PropertiesEunice Myers
 
Relations & functions.pps
Relations  &  functions.ppsRelations  &  functions.pps
Relations & functions.ppsindu psthakur
 
The Associative Property
The Associative PropertyThe Associative Property
The Associative Propertykmspruill
 
Working with text_aclm
Working with text_aclmWorking with text_aclm
Lesson 2.1 what is a function
Lesson 2.1    what is a functionLesson 2.1    what is a function
Lesson 2.1 what is a function
Dreams4school
 
Relations & functions
Relations & functionsRelations & functions
Relations & functions
chrystal_brinson
 
Set Theory
Set TheorySet Theory
Set Theoryitutor
 
2 5math Laws
2 5math Laws2 5math Laws
2 5math Lawstaco40
 
Properties of addition and multiplication
Properties of addition and multiplicationProperties of addition and multiplication
Properties of addition and multiplicationShiara Agosto
 
8.1 Relations And Functions
8.1 Relations And Functions8.1 Relations And Functions
8.1 Relations And Functions
Jessca Lundin
 
Showing the associative property of addition
Showing the associative property of additionShowing the associative property of addition
Showing the associative property of additionMaylord Bonifaco
 
Distributive property
Distributive propertyDistributive property
Distributive propertyMike Seitz
 
1 functions
1 functions1 functions
1 functions
Tzenma
 
A wonderful tutorial about an Array
A wonderful tutorial about an Array  A wonderful tutorial about an Array
A wonderful tutorial about an Array
Lakshmi Gopathi
 

What's hot (20)

The Properties of Mathematics
The Properties of MathematicsThe Properties of Mathematics
The Properties of Mathematics
 
Integers and Opposites
Integers and OppositesIntegers and Opposites
Integers and Opposites
 
Relations and functions
Relations and functions Relations and functions
Relations and functions
 
Sets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeySets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabey
 
Properties of addition and multiplication
Properties of addition and multiplicationProperties of addition and multiplication
Properties of addition and multiplication
 
Commutative And Associative Properties
Commutative And  Associative  PropertiesCommutative And  Associative  Properties
Commutative And Associative Properties
 
Relations & functions.pps
Relations  &  functions.ppsRelations  &  functions.pps
Relations & functions.pps
 
The Associative Property
The Associative PropertyThe Associative Property
The Associative Property
 
Working with text_aclm
Working with text_aclmWorking with text_aclm
Working with text_aclm
 
Lesson 2.1 what is a function
Lesson 2.1    what is a functionLesson 2.1    what is a function
Lesson 2.1 what is a function
 
Relations & functions
Relations & functionsRelations & functions
Relations & functions
 
Set Theory
Set TheorySet Theory
Set Theory
 
2 5math Laws
2 5math Laws2 5math Laws
2 5math Laws
 
Aa c1 s2
Aa c1 s2Aa c1 s2
Aa c1 s2
 
Properties of addition and multiplication
Properties of addition and multiplicationProperties of addition and multiplication
Properties of addition and multiplication
 
8.1 Relations And Functions
8.1 Relations And Functions8.1 Relations And Functions
8.1 Relations And Functions
 
Showing the associative property of addition
Showing the associative property of additionShowing the associative property of addition
Showing the associative property of addition
 
Distributive property
Distributive propertyDistributive property
Distributive property
 
1 functions
1 functions1 functions
1 functions
 
A wonderful tutorial about an Array
A wonderful tutorial about an Array  A wonderful tutorial about an Array
A wonderful tutorial about an Array
 

Recently uploaded

Toxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and ArsenicToxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and Arsenic
sanjana502982
 
platelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptxplatelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptx
muralinath2
 
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Studia Poinsotiana
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
moosaasad1975
 
Introduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptxIntroduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptx
zeex60
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
KrushnaDarade1
 
nodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptxnodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptx
alishadewangan1
 
bordetella pertussis.................................ppt
bordetella pertussis.................................pptbordetella pertussis.................................ppt
bordetella pertussis.................................ppt
kejapriya1
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdfMudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
frank0071
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
ChetanK57
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
RenuJangid3
 
ESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptxESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptx
PRIYANKA PATEL
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills MN
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
yqqaatn0
 
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdfDMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
fafyfskhan251kmf
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
SAMIR PANDA
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Sérgio Sacani
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
IshaGoswami9
 

Recently uploaded (20)

Toxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and ArsenicToxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and Arsenic
 
platelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptxplatelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptx
 
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
Salas, V. (2024) "John of St. Thomas (Poinsot) on the Science of Sacred Theol...
 
What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
 
Introduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptxIntroduction to Mean Field Theory(MFT).pptx
Introduction to Mean Field Theory(MFT).pptx
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
 
nodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptxnodule formation by alisha dewangan.pptx
nodule formation by alisha dewangan.pptx
 
bordetella pertussis.................................ppt
bordetella pertussis.................................pptbordetella pertussis.................................ppt
bordetella pertussis.................................ppt
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdfMudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
Mudde & Rovira Kaltwasser. - Populism - a very short introduction [2017].pdf
 
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATIONPRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
PRESENTATION ABOUT PRINCIPLE OF COSMATIC EVALUATION
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
 
ESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptxESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptx
 
Deep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless ReproducibilityDeep Software Variability and Frictionless Reproducibility
Deep Software Variability and Frictionless Reproducibility
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
 
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdfDMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
 
Phenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvementPhenomics assisted breeding in crop improvement
Phenomics assisted breeding in crop improvement
 

Mathematica言語の原理