COMPUTATIONAL MODELS Chapter No 1 What Is Computational

  • Slides: 35
Download presentation
COMPUTATIONAL MODELS Chapter No. 1

COMPUTATIONAL MODELS Chapter No. 1

What Is Computational Model? z. The common basis of programming language and computer architecture

What Is Computational Model? z. The common basis of programming language and computer architecture is known as computational model. z. Provides higher level of abstraction than the programming language and the architecture. z. Computational model is the combination of the above two.

What Is Computational Model? cont’n z. E. g Von Neuman Architecture and imperative languages,

What Is Computational Model? cont’n z. E. g Von Neuman Architecture and imperative languages, reduction architecture and functional languages.

What Is Computational Model? cont’n

What Is Computational Model? cont’n

What is a computer program? z It is an executable representation of some algorithm

What is a computer program? z It is an executable representation of some algorithm designed to solve some real world problem. z There are thus two elements to a computer program: z Logic - what we what the program to achieve. z Control - how we are going to achieve the end goal. ALGORITHM = LOGIC + CONTROL

Imperative Languages z Model of computation based on a step by step sequences of

Imperative Languages z Model of computation based on a step by step sequences of commands. z Program states exactly how the result is to be obtained. z Destructive assignment of variables.

Imperative Languages con’t z Order of execution is crucial, commands can only be understood

Imperative Languages con’t z Order of execution is crucial, commands can only be understood in context of previous computation due to side effects. z Control is the responsibility of the programmer. z E. g ALGOL, Pascal, Ada and C

Functional Languages z A program in a functional language consists of a set of

Functional Languages z A program in a functional language consists of a set of (possibly recursive) function definitions and expression whose value is output as the program's result. z Functional languages are one kind of declarative language. z Declarative languages allow the programmer to concentrate on the logic of an algorithm (declarative languages are goal driven, control is not the concern of the programmer)

Declarative Langauge z Model of computation based on a system where relationships are specified

Declarative Langauge z Model of computation based on a system where relationships are specified directly in terms of the constituents of the input data. z Made up of sets of definitions or equations describing relations which specify what is to be computed, not how it is to be computed. z Non-destructive assignment of variables. z Order of execution does not matter (no side effects). z Expressions/definitions can be used as values. z Programmer no longer responsible for control.

Interpretation of the Concept of a Computational Model z The computational model comprises of

Interpretation of the Concept of a Computational Model z The computational model comprises of three sets of abstraction: Computational Model Basic Items of Computation Problem Description Model Execution Model

Basic Items of Computation z This is the specification of the items the computation

Basic Items of Computation z This is the specification of the items the computation refers to the kind computations (operations) that can be performed on them. z E. g of items of computations are: ydata, objects or messages, arguments and functions, elements of sets and predicate declared on them.

Problem Description Model z Refers to both style and method of problem description. Problem

Problem Description Model z Refers to both style and method of problem description. Problem Description Model Style Method

Problem Description Style z It specifies how the problems in a particular computational model

Problem Description Style z It specifies how the problems in a particular computational model are described. Style Procedural Declarative

Procedural Style z In a procedural style the algorithm for solving the problem is

Procedural Style z In a procedural style the algorithm for solving the problem is stated. A particular solution is then declared. (Imperative languages uses procedural style) int nfac (int n) { int fac = 1; if (n > 0) for ( int i = 2; i <= n; i++ ) fac = fac * i; return fac; }

Declarative Style z Facts and relationships related to the problem have to be stated.

Declarative Style z Facts and relationships related to the problem have to be stated. Declarative Style Using Functions (applicative computational model) Using predicts (predict logic based computational model)

Declarative Style z Functional style yrelationships are expressed using functions. z E. g. (square

Declarative Style z Functional style yrelationships are expressed using functions. z E. g. (square (n) (* n n)) z This is a function square, that express the relationship between the input n and the output value n*n. z Logic style yrelationships are declared using expressions known as clauses. z E. g. square(N, M): M is N*N z Clauses can be used to express both facts and rules.

Problem Description Method z Procedural style ythe problem description model states how a solution

Problem Description Method z Procedural style ythe problem description model states how a solution of the given problem has to described. z Declarative style ythe problem description model states how the problem itself has to be described.

Execution Model z Execution model consists of three components. Execution Model Interpretation of the

Execution Model z Execution model consists of three components. Execution Model Interpretation of the computation Execution Semantics Control of the execution sequence

Interpretation of the Execution z How to perform the computation? z It relates to

Interpretation of the Execution z How to perform the computation? z It relates to problem description method z Problem description method and the interpretation of the computation mutually determines and presumes each other. z In Von Neumann computational model, problem description is the sequence of instructions which specify data and sequence of control instructions and the execution of the given sequence of instructions is the interpretation of the computation.

Execution Semantics z A rule that prescribes how a single execution step is to

Execution Semantics z A rule that prescribes how a single execution step is to be performed. z The rule is associated with the chosen problem description method and how the execution of the computation is interpreted.

Execution Semantics Execution Model State transition semantics Dataflow semantics Reduction semantics SLDresolution

Execution Semantics Execution Model State transition semantics Dataflow semantics Reduction semantics SLDresolution

Control of the Execution Sequence Control of the execution sequence Control Driven Data Driven

Control of the Execution Sequence Control of the execution sequence Control Driven Data Driven Demand Driven

Control Driven z In control driven execution it is assumed there exist a program

Control Driven z In control driven execution it is assumed there exist a program consisting of sequence of instructions. z The execution sequence implicitly given by the order of the instructions z Explicit control instructions can also be used to specify a departure from the implicit execution sequence.

Data Driven z It is characterized by the fact that an operation is activated

Data Driven z It is characterized by the fact that an operation is activated as soon as the data is available. z Also, known as eager evaluation.

Demand Driven z The operations will be activated only when their execution is needed

Demand Driven z The operations will be activated only when their execution is needed to achieve the final result. z Also known as lazy evaluation because the ‘delayed until needed ‘ philosophy is applied.

Relationships Between the Concepts of Computational Model, Programming Language and the Architecture Implementation tool

Relationships Between the Concepts of Computational Model, Programming Language and the Architecture Implementation tool Programming language Computational model Specification tool Computer architecture

Basic Computational Models z. Turing zvon Neumann zdataflow zapplicative zobject based zpredicate logic based

Basic Computational Models z. Turing zvon Neumann zdataflow zapplicative zobject based zpredicate logic based

Von Neumann Computational Model z Basic items of computation ydata is the basic item

Von Neumann Computational Model z Basic items of computation ydata is the basic item of computation ydata items are identified by names in order to distinguish between different data items used in the same computation. y. The named entities are known as variables in a programming language and in architectures y. Multiple data assignments are allowed.

Von Neumann Computational Model z Problem description model y. The computational task is specified

Von Neumann Computational Model z Problem description model y. The computational task is specified as a sequence of instructions (Procedural Model). z Execution model ythe computation is performed according to the given sequence of instructions. y. Instruction execution follows a state transition semantics and the model behaves just like finite state machine. y. Each instruction transfers the state of the machine to the present state to next one, in a definite way as specified by the semantics of the instruction.

Computational Model Corresponding programming languages Corresponding architectures

Computational Model Corresponding programming languages Corresponding architectures

Key Concepts Related to Computational Model z Granularity y. From computational model’s point of

Key Concepts Related to Computational Model z Granularity y. From computational model’s point of view granularity is interpreted as the complexity of the items computation. y. From parallel architectures point of view granularity is interpreted as size of parallel computations that can be executed without any synchronization or communication. . y. Granularity can be classified as fine grained and coarse grained.

Granularity Example Granularity Low High Language Class Conventional assembly language Conventional High language Fig

Granularity Example Granularity Low High Language Class Conventional assembly language Conventional High language Fig 1. 21 The interpretation of granularity for programming languages

Key Concepts Related to Computational Model z Typing ythe concept of typing is used

Key Concepts Related to Computational Model z Typing ythe concept of typing is used at a higher level in connection with programming languages but from computational model’s point of view typing of languages and architecture is closely related. y. In typed languages there exist a concept of data type and the compiler or interpreter checks the consistency of the types used in function invocation, expressions etc. ythe language may be strongly typed or weakly typed. y. Strongly typed languages are Pascal, Miranda, hope, C

Typing y. Weekly type languages are LISP, FP. They are also know as untyped

Typing y. Weekly type languages are LISP, FP. They are also know as untyped languages y. Typed architectures are commonly known as tagged. y. They provide a mechanism for typing the data being stored or processed, by extending the data word by tag. y. The tag contain the type identification and usually 35 bits long. y. Tagging bridge the gap between untyped architecture and weakly typed language