lecture_04

lecture_04 - BIOS 735: Statistical Computing Michael Wu...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
BIOS 735: Statistical Computing Michael Wu Lecture 4: Functional Programming and Intro to Programming Structures August 30, 2011 Michael Wu (Lecture 4) BIOS 735 August 30, 2011 1 / 14
Background image of page 1

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

View Full DocumentRight Arrow Icon
Functional Programming Functional programming = programming paradigm that treats computation as evaluation of mathematical functions without side effects (Wiki) Subparadigm of Declarative Programming Key Concept: you are asking for a result without clear, in-depth description of how to get the result NOT like what we typically learn in CS Another Key Concept: no side effects . Beyond returning a value, functions do not generally modify particular parameters. Doesn’t interact as much with outside world. a = 10 f = function(x) { print(a); a = 20; print(a); return(x)} f(99) a Generally slower and less efficient than imperative languages, but specialized operations can be very fast Emphasis on composition and arrangement of functions (without details) while imperative progamming focuses on the steps to carry out actions. Michael Wu (Lecture 4) BIOS 735 August 30, 2011 2 / 14
Background image of page 2
Example Imperative programming (C++) int fibonacci(int iterations) { int first = 0, second = 1; // seed values for (int i = 0; i < iterations; ++i) { int sum = first + second; first = second; second = sum; } return first; } std::cout << fibonacci(10) << "\n"; Functional programming (R) hold = function(a, b){ if (a <100) return(c(b, hold(b,a+b))) else return(a+b) } hold(0,1) key difference: Imperative puts commands in a loop. On the other hand, the Functional allows focus on the mathematical relationship (recursion) that defines fibonnacci. Michael Wu (Lecture 4) BIOS 735 August 30, 2011 3 / 14
Background image of page 3

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

View Full DocumentRight Arrow Icon
R is a very well thought out and well designed language. Why functional programming? Clearer, more compact. Possibly faster execution depending on your goal. Less Code = Less Debugging Easy transition to parallel programming Very natural for statisticians and mathematicians. Michael Wu (Lecture 4)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/18/2011 for the course BIOS 735 taught by Professor Staff during the Spring '10 term at UNC.

Page1 / 15

lecture_04 - BIOS 735: Statistical Computing Michael Wu...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online