Pure Kevin Edelmann.

Slides:



Advertisements
Similar presentations
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
Advertisements

Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
Logic Gate Level Part 2. Constructing Boolean expression from truth table First method: write nonparenthesized OR of ANDs Each AND is a 1 in the result.
CS 151 Digital Systems Design Lecture 6 More Boolean Algebra A B.
Lecture 3. Boolean Algebra, Logic Gates
CS 300 – Lecture 3 Intro to Computer Architecture / Assembly Language Digital Design.
Exponents and Polynomials
Algebra Form and Function by McCallum Connally Hughes-Hallett et al. Copyright 2010 by John Wiley & Sons. All rights reserved. 6.1 Integer Powers and the.
Lecture 2 – Boolean Algebra Lecturer: Amy Ching Date: 21 st Oct 2002.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Chapter 10 Exponents and Polynomials.
Chapter 1 Review College Algebra Remember the phrase “Please Excuse My Dear Aunt Sally” or PEMDAS. ORDER OF OPERATIONS 1. Parentheses - ( ) or [ ] 2.
Logic Gates Shashidhara H S Dept. of ISE MSRIT. Basic Logic Design and Boolean Algebra GATES = basic digital building blocks which correspond to and perform.
Lecture 4 Nand, Nor Gates, CS147 Circuit Minimization and
Discrete Mathematics CS 2610 September Equal Boolean Functions Two Boolean functions F and G of degree n are equal iff for all (x 1,..x n )  B.
Com Functional Programming Lazy Evaluation Marian Gheorghe Lecture 13 Module homepage Mole & ©University of Sheffieldcom2010.
ENGIN112 L6: More Boolean Algebra September 15, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 6 More Boolean Algebra A B.
Computer Systems 1 Fundamentals of Computing Simplifying Boolean Expressions.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 4 Dr. Shi Dept. of Electrical and Computer Engineering.
ECE DIGITAL LOGIC LECTURE 8: BOOLEAN FUNCTIONS Assistant Prof. Fareena Saqib Florida Institute of Technology Spring 2016, 02/11/2016.
Lecture 5 More Boolean Algebra A B. Overview °Expressing Boolean functions °Relationships between algebraic equations, symbols, and truth tables °Simplification.
Algebra The greatest mathematical tool of all!!. This is a course in basic introductory algebra. Essential Prerequisites: Ability to work with directed.
Boolean Algebra.
WARM UP 1.Multiply and simplify 2. Rationalize the denominator 3. Rationalize the denominator 1.
CHAPTER 6 Quine-McCluskey Method
3.1 – Simplifying Algebraic Expressions
ECE 301 – Digital Electronics
Conditional Expressions
Logic Gates and Boolean Algebra
Types CSCE 314 Spring 2016.
Combinational Logic Design&Analysis.
Lecture 4 Nand, Nor Gates, CS147 Circuit Minimization and
Factoring Quadratic Expressions Lesson 4-4 Part 2
Variables and Expressions
Theory of Computation Lecture 4: Programs and Computable Functions II
The greatest mathematical tool of all!!
Digital Logic.
CHAPTER 2 Boolean Algebra This chapter in the book includes:
Give qualifications of instructors: DAP
Component 1 – 2A, B, C Binary Logic
Boolean algebra Last time we talked about Boolean functions, Boolean expressions, and truth tables. Today we’ll learn how to how use Boolean algebra to.
PROGRAMMING IN HASKELL
CSE 341 : Programming Languages Section 5 Haskell: Round 3
CSE341: Programming Languages Lecture 12 Equivalence
PROGRAMMING IN HASKELL
Reading: Hambley Ch. 7 through 7.5
Boolean Algebra.
Type & Typeclass Syntax in function
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 12 Equivalence
PROGRAMMING IN HASKELL
CSCE 314: Programming Languages Dr. Dylan Shell
Matrices.
Haskell Types, Classes, and Functions, Currying, and Polymorphism
CS 457/557: Functional Languages Folds
Theory of Computation Lecture #
ECE 352 Digital System Fundamentals
Bell Ringer (NWEA) 1. Katie completed the following problem and got it incorrect. Can you tell Katie what you did wrong?  
CSE341: Programming Languages Lecture 12 Equivalence
Analysis of Logic Circuits Example 1
Multiplication of Matrices
Analysis of Logic Circuits Example 1
Theory of Computation Lecture 4: Programs and Computable Functions II
CSE341: Programming Languages Lecture 12 Equivalence
PROGRAMMING IN HASKELL
CSE341: Programming Languages Lecture 12 Equivalence
Boolean Algebra.
Reading: Hambley Ch. 7 through 7.5
Presentation transcript:

Pure Kevin Edelmann

“Fun” facts Functional programming language Syntactically similar to Haskell Successor to the Q programming language Dynamically typed

No Monads! using system; puts "Hello, world!"; Ironically, this makes Pure less “purely” functional Then again, Scala allows “direct” printing as well But it’s also easier to read and use! using system; puts "Hello, world!";

Rewriting A Pure program is a collection of equations. Equations are used to symbolically reduce expressions to normal form (no other equations can be applied). Expressions are evaluated in a leftmost-innermost fashion Equations are considered from the top-down when matching expressions Similar to Prolog

Simple Rewriting Example Simple equations look like normal function definitions. Bottom row shows rewriting steps as applied by Pure. >square x = x*x; >square(5+8); 169 square (5+8) => square 13 => 13*13 => 169

Pattern Matching > sum [] = 0; > sum (x:xs) = x+sum xs; Functions can be defined via pattern matching (As well as in other ways, but nothing we haven’t seen elsewhere) > sum [] = 0; > sum (x:xs) = x+sum xs; > sum (1..30); 465

Pattern Matching with Arbitrary Stuff Pattern matching can match any sort of data BST Tree generation example: > nonfix nil; > insert nil y = bin y nil nil; > insert (bin x L R) y = bin x (insert L y) R if y<x; > = bin x L (insert R y) otherwise; > foldl insert nil [7,3,9,18]; bin 7 (bin 3 nil nil) (bin 9 nil (bin 18 nil nil))

Arbitrary Polymorphism Because Pure is dynamically typed, it supports an arbitrary degree of polymorphism. Any operation, even those built into Pure, can be extended by equations. > f + g = \x -> f x + g x if nargs f > 0 && nargs g > 0; > f - g = \x -> f x - g x if nargs f > 0 && nargs g > 0; > f x = 2*x+1; g x = x*x; h x = 3; > map (f+g-h) (1..10); [1,6,13,22,33,46,61,78,97,118] > (max-min) 2 5; 3

Symbolic Rewriting In Pure, attempting to evaluate an expression containing one or more undefined variables returns a symbolic evaluation of the result. In other languages, the compiler gets angry at you. > square (a+b); (a+b)*(a+b) > sum [a,b,c]; a+(b+(c+0)) > map f [a,b+c,x*y]; [2*a+1,2*(b+c)+1,2*(x*y)+1]

More Symbolic Rewriting In Pure, attempting to set two expressions equal to each other is totally okay; it’s just another rewriting rule. Arbitrary functions and operators are allowed on the left, just as is so on the right. In other languages, the compiler gets even angrier than the previous slide. Example including associative and distributive rules for + and *: > (x+y)*z = x*z+y*z; x*(y+z) = x*y+x*z; > x+(y+z) = (x+y)+z; x*(y*z) = (x*y)*z; > square (a+b); a*a+a*b+b*a+b*b > sum [a,b,c]; a+b+c+0 > map f [a,b+c,x*y]; [2*a+1,2*b+2*c+1,2*x*y+1]

One More Symbolic Rewriting example (Seriously, this is really cool to me) Converting logical expressions to disjunctive normal form using de Morgan’s Laws Distributive Laws Associative Laws > ~~a = a; > ~(a || b) = ~a && ~b; > ~(a && b) = ~a || ~b; > a && (b || c) = a && b || a && c; > (a || b) && c = a && c || b && c; > (a && b) && c = a && (b && c); > (a || b) || c = a || (b || c); > a || ~(b || (c && ~d)); a||~b&&~c||~b&&d

In Summary Pure can do someone’s Algebra homework for them More importantly, you can control the flow of how an expression is evaluated by first re-writing the expression You can also use undefined variables to see how Pure will evaluate an input expression (since it will simply output the symbolic version of what it would otherwise calculate)

Further Reading/Source https://bitbucket.org/purelang/pure-lang/wiki/Home

?