Top Banner
Miranda A Functional Language Dan Vasicek March 16, 2008
24

Miranda A Functional Language Dan Vasicek March 16, 2008.

Dec 17, 2015

Download

Documents

Meghan Rose
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Miranda A Functional Language Dan Vasicek March 16, 2008.

Miranda A Functional Language

Dan Vasicek

March 16, 2008

Page 2: Miranda A Functional Language Dan Vasicek March 16, 2008.

References

• “Introduction to Functional Programming” – Richard Bird, and Philip Wadler– Prentice – Hall, 1988, 291 pages

• Structure and Interpretation of Computer Programs

• Abelson and Sussman

• MIT Press 1985

Page 3: Miranda A Functional Language Dan Vasicek March 16, 2008.

Historical

• 1986 Study Scheme using Ableson and Sussman, Structure and Interpretation of Computer Programs

• 1988 Miranda using Bird and Wadler• 1988 Study reservoir modeling problem

– 100 Man*year Amoco Effort• 1990 Begin the Miranda Reservoir Model• Use Claris Works to organize the project• 1992 AMOCO cancels the project• 1992 Disk Crash destroys most records of the

project

Page 4: Miranda A Functional Language Dan Vasicek March 16, 2008.

Miranda

• Miranda concepts– “Pure” functional language– Lazy evaluation (allows infinite lists)– Single assignment (Parallel Computation)

• Reservoir Models– Darcy’s Law (Flow in porous media)– Constitutive relationships (pv=nrT)

• Miranda Reservoir Experiment

Page 5: Miranda A Functional Language Dan Vasicek March 16, 2008.

Synthesis of Programs from Specifications

• Equational reasoning used to derive a program from a specification

• Building definitions

• Program Transformation

• Constructing a function to solve a given problem

• Without specification the sequence of steps in the process

Page 6: Miranda A Functional Language Dan Vasicek March 16, 2008.

Miranda = a pure functional language

• All computations are done by applying functions to data (purely functional)

• The top level program is a function call that produces the desired result

• Characteristics of functional languages– Order of execution is irrelevant – Each function call encapsulates the relationship

between some inputs and outputs– Higher level of abstraction is available– Less development time– Less code

Page 7: Miranda A Functional Language Dan Vasicek March 16, 2008.

Miranda does not

• Provide iterative constructs such as the “for” or “do” loop

• Provide any way to change the value of a “variable” (single assignment)

• Once a “variable” has a value, it cannot change

Page 8: Miranda A Functional Language Dan Vasicek March 16, 2008.

Procedural vs. Functional

• Procedural Cake Recipe– Specifies the process – Specifies the sequence of steps for making a

cake

• Functional Cake Recipe– Specifies the steps but not the sequence– Abstract the steps from the sequence

Page 9: Miranda A Functional Language Dan Vasicek March 16, 2008.

Recipe – Bake a Cake

• Procedural Recipe (“Fortran” Program)– Buy cake mix, eggs, milk– Preheat oven to 350– Beat eggs until frothy– Add milk– Fold in mix– Grease pan– Put batter in pan– Put pan in oven– Bake 350 degrees for 30 minutes

Page 10: Miranda A Functional Language Dan Vasicek March 16, 2008.

Recipe – Bake a Cake

• Functional recipe– Cake=Bake_a_cake(Cake_in_oven)– Cake_in_oven=batter_in_oven(hot_oven,

b_in_pan)– hot_oven=heat_oven( turn_on_oven())– b_in_pan=mix_ingredients(eggs, milk, c_mix)

Page 11: Miranda A Functional Language Dan Vasicek March 16, 2008.

Recursion

• Mathematical theorems are frequently proven using a recursive argument such as “Proof by Induction”

• Recursion provides an alternative to iteration in programs

• Factorial Example:– F(0)=1– F(n)=n*F(n-1)

Page 12: Miranda A Functional Language Dan Vasicek March 16, 2008.

List Processing

• Miranda is a descendent of LISP

• [1,2,3] :: [num]

• [‘h’,’e’,’l’,’l’,’o’] :: [char]

• [(+), (*)] ::[num num num]

• [1,2,..4]=[1,2,3,4]

• [1..] = infinite list of all positive digits

Page 13: Miranda A Functional Language Dan Vasicek March 16, 2008.

LaTeX In-Line Documentation

• Miranda allows one text file containing both the program and the documentation

• Process the file with LaTeX Document

• Process the file with Miranda compiler executable program

Page 14: Miranda A Functional Language Dan Vasicek March 16, 2008.

Reservoir Model Ideas

• Darcy’s Law

• Compositional Relationships

• Finite Differences

• Linear Algebra

• Reference: Page, Sexton, and Wainwright (1990 IEEE)

• http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=82145

Page 15: Miranda A Functional Language Dan Vasicek March 16, 2008.

Darcy’s Law for Flow in Porous Media

• P=pressure, =permeability Tensor

• q= fluid flux, =fluid viscosity

Page 16: Miranda A Functional Language Dan Vasicek March 16, 2008.

Equations of State

• Van der Waals

• ( P + a / Vm2 )( Vm - b ) = R T

• P = pressure

• Vm = molar volume

• R = ideal gas constant

• T = temperature

Page 17: Miranda A Functional Language Dan Vasicek March 16, 2008.

Discretization of the Reservoir

• Continuous reservoir Discrete 3 d grid

• PDE Linear Algebra

• Derivatives Finite differences

• Large linear systems sparse, iterative, system solvers

• Conjugate gradient method

Page 18: Miranda A Functional Language Dan Vasicek March 16, 2008.

Oil Reservoir Characterization

• Seismic Data – location of layers

• Exploration wells – measure properties in the layers (pressure, gas, oil, and water concentration, rock properties…)

• Extrapolate between the wells using the seismically derived layers

Page 19: Miranda A Functional Language Dan Vasicek March 16, 2008.

Oil Reservoir

Page 20: Miranda A Functional Language Dan Vasicek March 16, 2008.
Page 21: Miranda A Functional Language Dan Vasicek March 16, 2008.

Fluid Velocity in a Reservoir

Page 22: Miranda A Functional Language Dan Vasicek March 16, 2008.

Basic Ideas of the Model

• 100 man years of programming effort to construct the Fortran version of the reservoir model

• Many input data files existed for the Fortran version of the model

• Difficult to achieve effective parallelism in the code

• Huge effort in maintenance and development • Documentation difficult

Page 23: Miranda A Functional Language Dan Vasicek March 16, 2008.

Miranda Reservoir Model

• 2 man years of effort– Rex Page– Roger Wainwright– Julio Diaz– Dan Vasicek

• LaTeX in-line documentation

• Accepts existing structures intended for input to the Fortran reservoir model

Page 24: Miranda A Functional Language Dan Vasicek March 16, 2008.

Functional Languages

• “Pure” & Single Assignment constraints– Make explicit the dependence of the functions

on the data– Allow a simple operating system to take

advantage of the opportunities for parallel computation

• High level language– Decreases the programming effort