Programming Paradigms via Mathematica - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Programming Paradigms via Mathematica

Description:

Patterns. A pattern is an expression that is used to specify a set of expressions. ... For example, the pattern {_,_} matches any list with two elements. ... – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 29
Provided by: dejan4
Category:

less

Transcript and Presenter's Notes

Title: Programming Paradigms via Mathematica


1
Programming Paradigms via Mathematica
  • Dr Dejan Toic, ETF Beograd tosic_at_etf.bg.ac.yu
    http//kondor.etf.bg.ac.yu/tosic/

2
Mathematica
  • Mathematica is the world's only fully integrated
    environment for technical computing.
  • The visionary concept of Mathematica was to
    create once and for all a single system that
    could handle all the various aspects of
    technical computing in a coherent and unified
    way.
  • The key intellectual advance that made this
    possible was the invention of a new kind of
    symbolic computer language that could for the
    first time manipulate the very wide range of
    objects involved in technical computing using
    only a fairly small number of basic primitives.

3
Mathematica combines ideas from many different
sources
  • LISP Mathematica can manipulate lists using the
    data structures of the programming language LISP.
  • PROLOG Mathematica uses pattern matching
    capabilities taken from PROLOG to express
    mathematical rules in a simple way.
  • APL Mathematica's simple manipulation of
    structured data has been pioneered by APL.
  • SIMULA, SMALLTALK, and C Object-oriented
    elements make code development easier.
  • PASCAL, FORTRAN, and C Traditional procedural
    programming style.
  • Other Features Modularization and Built-In
    Functions.

4
Software development cycle
5
Square brackets , Curly braces , and
Parentheses ( )
  • Parentheses ( ) are used in Mathematica for
    grouping in arithmetic.
  • Square brackets are used for enclosing the
    arguments of functions.
  • Curly braces are used for entering lists.
  • Using square brackets to enclose function
    arguments avoids the ambiguity in traditional
    mathematical notation between parentheses that
    enclose function arguments and parentheses that
    are used for grouping arithmetic operations.

6
Normal Expression
  • A normal expression is an expression that has a
    head and elements (arguments).
  • The head of the normal expression fa,b, for
    example, is f, and the elements are a and b.
  • The head and the elements in a normal expression
    are also expressions, and can, for example, be
    other normal expressions.

7
Atoms
  • Expressions that are not normal expressions are
    called atoms.
  • Atoms are either
  • symbols,
  • numbers, or
  • strings.
  • All expressions are constructed from atoms.

8
Patterns
  • A pattern is an expression that is used to
    specify a set of expressions.
  • Any expression in the set of expressions
    specified by a pattern is said to match the
    pattern.
  • The simplest non-trivial pattern is Blank,
    which matches any expression. Blank is usually
    entered as a single underscore character _.
  • For example, the pattern _,_ matches any list
    with two elements.

9
Canonical example
10
Built-in Functions
One way to program a function that computes the
factorial of a non-negative integer is to simply
use the built-in function Factorial.
11
Composition of Functions Anonymous (pure)
function
12
Procedural FORTRANesque programming Do
13
Straight-forward implementation Product
14
Functional programming
15
Range generates a list of consecutive integers
16
Times multiplies together its arguments
17
Rule-based programming
18
Transformation rules
  • Rules are a mechanism for replacing a variable
    with a value in an expression.
  • A rule can transform one expression, lhs, into
    another expression, rhs lhs -gt rhs

19
Rule-based programming style
  • The transformations are described by rules which
    separate the description of the sub-object to be
    replaced (the pattern) from the calculation of
    the replacement.
  • Optionally, rules can have further conditions
    that restrict their applicability.
  • The transformations are controlled by explicit or
    implicit strategies.

20
Mixed programming Definitions, Rules, Patterns
21
Dynamically Stored Results
22
Information on objects ? command
23
Recursive programming
24
C-style programming For
25
Iterative programming While
26
Traditional form Product
27
Definition using pure function
28
Benefits
  • Visionary concept of advanced computing
  • Fully integrated mathematical environment
  • Symbolic computer language
  • Various programming paradigms
  • Short software development cycle
Write a Comment
User Comments (0)
About PowerShow.com