Prolog examples continued
|
|
- Madlyn Garrett
- 6 years ago
- Views:
Transcription
1 Prolog examples continued arithmetic functions translating a simple Lisp function modelling an addition circuit puzzle solving 1 arithmetic functions we keep arithmetic functions as functions for convenience:?- X is exp(1). % exp(1) = e 1 X = How does is compare with =, and with assignment? 2
2 operators some functors are represented by infix or prefix operators. is is an infix operator others? =, +, *, /, etc., (as "and") :- ("if") +, - are both prefix and infix :- as prefix is a command: means "do"; used for declarations 3 Lisp to Prolog (DEFUN 2Tosquare (X) (EXPT 2 (* X X))) square(x, Result) :- Result is X*X. twotosquare(x, Result) :- square(x, Square), Result is 2**Square. a simpler version: twotosquare(x, Result) :- Result is 2**(X*X). 4
3 more translation (DEFUN equalreverse (phr1 phr2) (EQUAL phr1 (REVERSE phr2) ) ) Boolean functions are already relational! equalreverse(phr1, phr2) :- reverse(phr2, phr2reversed), phr1 = phr2reversed. simplification: eliminate the = equalreverse(phr1, phr2) :-reverse(phr2, phr1). 5 reverse is built in?- help(reverse). reverse(+list1, -List2) Reverse the order of the elements in List1 and unify the result with the elements of List2. + = input, - = output but reverse allows either for each parameter! 6
4 reverse examples?- reverse(x, X). X = [] ; X = [_G230] ; X = [_G230, _G230]...?- reverse(x, Y). X = [] Y = [] ; X = [_G245] Y = [_G245] ; X = [_G245, _G248] Y = [_G248, _G245] reversible programming good predicates are steadfast they gives correct answers even if unusual values are supplied e. g. variables for 'inputs', constants for 'outputs'. non-steadfast predicates require specific arguments to be instantiated (input) or variables (output). 8
5 online-help examples?- help(lists). No help available for lists Yes?- apropos(lists). merge/3 append/3 Section 11-1 Section Merge two sorted lists Concatenate lists % try apropos (list) for a long list of predicates "lists: List Manipulation" "lists" Yes?- help(merge/3). merge(+list1, +List2, -List3) List1 and List2 are lists, sorted to the standard order of terms (see section 4.6). List3 will be unified with an ordered list holding both the elements of List1 and List2. Duplicates are not removed. (END) (exit with q) 9 apropos is not steadfast?- apropos(x). ERROR: Arguments are not sufficiently instantiated ^ Exception: (11) findall(_g233-_g234- _G231, apropos_predicate(_g180, _G233, _G234, _G231), _L199)? 10
6 adder example 11 logic facts construct a 2-bit adder in Prolog, using predicates for binary logic. the logic predicates: xor(0,0,0). xor(0,1,1). xor(1,0,1). xor(1,1,0). or(0,0,0). or(0,1,1). or(1,0,1). or(1,1,1). and(0,0,0). and(0,1,0). and(1,0,0). and(1,1,1). 12
7 a half-adder X Y Carry Sum 13 half-adder code halfa([x, Y], [Sum, Carry]) :- xor(x, Y, Sum), and(x,y, Carry). note the "destructuring" 14
8 1 bit adder X Y CarryIn halfa Sum1 halfa Carry1 Carry2 Sum CarryOut 15 1-bit adder code adder1([x,y,carryin], [Sum, CarryOut]) :- halfa([x,y], [Sum1, Carry1]), halfa([sum1,carryin], [Sum, Carry2]), or(carry1, Carry2, CarryOut). arrows show data flow for addition 16
9 subtracting with an adder?-adder1([x,y, 0], [1, 0]). X = 0 Y = 1 ; X = 1 Y = 0 ; no?-adder1([x, 0, Y], [1, 1]). no % no two bits add to bit subtraction adder1([x,y,carryin], [Sum, CarryOut]) :- halfa([x,y], [Sum1, Carry1]), halfa([sum1,carryin], [Sum, Carry2]), or(carry1, Carry2, CarryOut). arrows show data flow for subtraction example 18
10 2-bit adder code 2-bit adder with "ripple" carry: X1 X0 10 Y1 Y0 11 Sum1 Sum bit adder X1 Y1 X0 Y0 0 adder1 adder1 Carry0 CarryOut Sum1 Sum0 20
11 code for 2-bit adder adder2([x1, X0], [Y1, Y0], [Sum1, Sum0, CarryOut]) :- adder1([x0, Y0, 0], [Sum0, Carry0]), adder1([x1, Y1, Carry0], [Sum1, CarryOut]). 21 solving a logic puzzle with Prolog 22
12 the zebra puzzle ************ THE FACTS ************************* 1. There are 5 houses, occupied by politically-incorrect gentlemen of 5 different nationalities, who all have different coloured houses, keep different pets, drink different drinks, and smoke different (now-extinct) brands of cigarettes. */ 2. The Englishman lives in a red house. 3. The Spaniard keeps a dog. 4. The owner of the green house drinks coffee.. 6. The ivory house is just to the left of the green house The Chesterfields smoker lives next to a house with a fox.... Who owns the zebra and who drinks water? 23 prolog implementation represent the houses by a list of 5 terms house(color, Nationality, Pet, Drink, Cigarettes) create a partial structure using variables, to be filled in by the solution process use constraints to bind variables 24
13 house building makehouses(0,[]). makehouses(n, [house(color,nat,pet,drink,cig) List]) :- N>0, N1 is N - 1, makehouses(n1,list). we could express this more cleanly using anonymous variables: makehouses(n, [house(_, _,_, _, _) List]) :- N>0, N1 is N - 1, makehouses(n1,list). Why is this equivalent? (See p. 159.) 25 entering code at the terminal?- consult(user). : makehouses(0, []). : makehouses(n, [house(color,nat,pet,drink,cig) List]) : :- N>0, N1 is N - 1, makehouses(n1,list). Warning: (user://1:12): Singleton variables: [Color, Nat, Pet, Drink, Cig] : end_of_file. % control-d also works % user://1 compiled 0.00 sec, 796 bytes 26
14 the empty houses?- makehouses(5, List). List = [house(_g233, _G234, _G235, _G236, _G237), house(_g245, _G246, _G247, _G248, _G249), house(_g257, _G258, _G259, _G260, _G261), house(_g269, _G270, _G271, _G272, _G273), house(_g281, _G282, _G283, _G284, _G285)] 27 constraints % The Englishman lives in a red house. house( red, englishman, _, _, _) on List, % The Spaniard keeps a dog. house( _, spaniard, dog, _, _) on List, % The owner of the green house drinks coffee. house(green, _, _, coffee, _) on List, % The Ukrainian drinks tea. house( _, ukrainian, _, tea, _) on List, % etc. 28
15 on = member on is a user-defined infix operator version of member/2 see p for definition of member :- op(100,xfy,on). % a bit of grammar X on List :- member(x, List). equivalent to X on [X R]. X on [_ R] :- X on R. 29
zebra puzzle continued recap Prolog concepts family relations
zebra puzzle continued recap Prolog concepts family relations 1 recapping the Zebra puzzle 2 ****** the facts ****** There are 5 houses, occupied by politicallyincorrect gentlemen of 5 different nationalities,
More informationProlog Core Concepts and Notation
Prolog Core Concepts and Notation Yves Lespérance Adapted from Peter Roosen-Runge Readings: C & M Ch 1, 2, 3.1-3.3, 8 1 declarative/logic programming idea: write a program that is a logical theory about
More informationLogic-Oriented Programming (5/11/2004)
1 Logic-Oriented Programming (5/11/2004) Daniel P. Friedman, David W. Mack, William E. Byrd Computer Science Department, Indiana University Bloomington, IN 47405, USA Oleg Kiselyov Fleet Numerical Meteorology
More informationSolving Constraint Satisfaction Problems Using Equivalence Relations. Author: Carl Devore
LogicProblem.mws 31 March 2001 Solving Constraint Satisfaction Problems Using Equivalence Relations Author: Carl Devore If you use this program, please send me email at ,
More informationPrologue to Prolog. Logic Programming Sterling and Shapiro. Constraint Logic Programming Marriott and Stuckey
In the Lecture Series Aims and Objectives This course aims to discuss the basic aspects of constraint and logic programming. It will focus on constraint logic programming and its realisation in Eclipse,
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationProlog Lecture 1. David Eyers Michaelmas Notes derived from those created by Andy Rice and Kate Taylor, used with permission
Prolog Lecture 1 David Eyers Michaelmas 2009 Notes derived from those created by Andy Rice and Kate Taylor, used with permission Course aims Introduce a declarative style of programming Explain fundamental
More informationPropositional Calculus. Math Foundations of Computer Science
Propositional Calculus Math Foundations of Computer Science Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they can use it to
More informationHow a Digital Binary Adder Operates
Overview of a Binary Adder How a Digital Binary Adder Operates By: Shawn R Moser A binary adder is a digital electronic component that is used to perform the addition of two binary numbers and return the
More informationConstraint Satisfaction Problems (CSP)
Constraint Satisfaction Problems (CSP) (Where we postpone making difficult decisions until they become easy to make) R&N: Chap. 5 1 What we will try to do... Search techniques make choices in an often
More informationComputer Programming C++ (wg) CCOs
Computer Programming C++ (wg) CCOs I. The student will analyze the different systems, and languages of the computer. (SM 1.4, 3.1, 3.4, 3.6) II. The student will write, compile, link and run a simple C++
More informationBasic Arithmetic (adding and subtracting)
Basic Arithmetic (adding and subtracting) Digital logic to show add/subtract Boolean algebra abstraction of physical, analog circuit behavior 1 0 CPU components ALU logic circuits logic gates transistors
More informationAn Interactive Desk Calculator. Project P2 of. Common Lisp: An Interactive Approach. Stuart C. Shapiro. Department of Computer Science
An Interactive Desk Calculator Project P2 of Common Lisp: An Interactive Approach Stuart C. Shapiro Department of Computer Science State University of New York at Bualo January 25, 1996 The goal of this
More informationChapter 3: part 3 Binary Subtraction
Chapter 3: part 3 Binary Subtraction Iterative combinational circuits Binary adders Half and full adders Ripple carry and carry lookahead adders Binary subtraction Binary adder-subtractors Signed binary
More information15 Unification and Embedded Languages in Lisp
15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed
More informationProlog Introduction. Gunnar Gotshalks PI-1
Prolog Introduction PI-1 Physical Symbol System Hypothesis A physical symbol system has the necessary and sufficient means for general intelligent action. Allen Newell and Herbert A. Simon PI-2 Physical
More informationIntroduction to Computer Engineering (E114)
Introduction to Computer Engineering (E114) Lab 1: Full Adder Introduction In this lab you will design a simple digital circuit called a full adder. You will then use logic gates to draw a schematic for
More informationFunctional programming with Common Lisp
Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions
More informationConstraint Satisfaction Problems (CSP) (Where we postpone making difficult
Constraint Satisfaction Problems (CSP) (Where we postpone making difficult decisions until they become easy to make) R&N: Chap. What we will try to do... Search techniques make choices in an often arbitrary
More informationScheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax
Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is
More informationExperiment 7 Arithmetic Circuits Design and Implementation
Experiment 7 Arithmetic Circuits Design and Implementation Introduction: Addition is just what you would expect in computers. Digits are added bit by bit from right to left, with carries passed to the
More informationLecture 21: Combinational Circuits. Integrated Circuits. Integrated Circuits, cont. Integrated Circuits Combinational Circuits
Lecture 21: Combinational Circuits Integrated Circuits Combinational Circuits Multiplexer Demultiplexer Decoder Adders ALU Integrated Circuits Circuits use modules that contain multiple gates packaged
More information2/14/2016. Hardware Synthesis. Midia Reshadi. CE Department. Entities, Architectures, and Coding.
Hardware Synthesis MidiaReshadi CE Department Science and research branch of Islamic Azad University Email: ce.srbiau@gmail.com Midia Reshadi 1 Chapter 2 Entities, Architectures, and Coding Styles Midia
More informationLecture 1. Introduction
Lecture 1 1 Constraint Programming Alternative approach to programming Combination of reasoning and computing Constraint on a sequence of variables: a relation on their domains Constraint Satisfaction
More informationCLIP - A Crytographic Language with Irritating Parentheses
CLIP - A Crytographic Language with Irritating Parentheses Author: Duan Wei wd2114@columbia.edu Yi-Hsiu Chen yc2796@columbia.edu Instructor: Prof. Stephen A. Edwards July 24, 2013 Contents 1 Introduction
More informationFunctional Programming
Functional Programming Function evaluation is the basic concept for a programming paradigm that has been implemented in functional programming languages. The language ML ( Meta Language ) was originally
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
More informationExperiment 8 Introduction to VHDL
Experiment 8 Introduction to VHDL Objectives: Upon completion of this laboratory exercise, you should be able to: Enter a simple combinational logic circuit in VHDL using the Quartus II Text Editor. Assign
More information3 Lists. List Operations (I)
3 Lists. List Operations (I) The list is the simplest yet the most useful Prolog structure. A list is a sequence of any number of objects. Example 3.1: L = [1, 2, 3], R = [a, b, c], T = [john, marry, tim,
More informationProlog Assessed Exercise
Prolog Assessed Exercise David Eyers 21st April 2009 The purpose of this exercise is to implement in Prolog the Bellman-Ford algorithm for computing singlesource shortest paths
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationProgramming Languages 3. Definition and Proof by Induction
Programming Languages 3. Definition and Proof by Induction Shin-Cheng Mu Oct. 22, 2015 Total Functional Programming The next few lectures concerns inductive definitions and proofs of datatypes and programs.
More informationInteger Encoding and Manipulation
CSE 2421: Systems I Low-Level Programming and Computer Organization Integer Encoding and Manipulation Presentation D Study: Bryant Chapter 2.1 2.3 Gojko Babić 01-24-2018 Unsigned & Signed Integer Encoding
More informationPage 1 of 5. University of Toronto CSC326 Programming Languages, Fall 2009
University of Toronto CSC326 Programming Languages, Fall 2009 Assignment # 4 Part B (Due: Monday, Dec. 7rd 2009, 11:00am sharp) Details: - Programming in Prolog. This is the Part B of assignment 4, and
More informationMaterial. Thought Question. Outline For Today. Example: Map-Coloring EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS
EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 6, 4/20/2005 University of Washington, Department of Electrical Engineering Spring 2005 Instructor: Professor Jeff A. Bilmes Material Read all of chapter
More informationEXPERIMENT #8: BINARY ARITHMETIC OPERATIONS
EE 2 Lab Manual, EE Department, KFUPM EXPERIMENT #8: BINARY ARITHMETIC OPERATIONS OBJECTIVES: Design and implement a circuit that performs basic binary arithmetic operations such as addition, subtraction,
More informationModern Programming Languages. Lecture LISP Programming Language An Introduction
Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationChapter 3 Arithmetic for Computers
Chapter 3 Arithmetic for Computers 1 Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing the Architecture operation
More informationLisp Basic Example Test Questions
2009 November 30 Lisp Basic Example Test Questions 1. Assume the following forms have been typed into the interpreter and evaluated in the given sequence. ( defun a ( y ) ( reverse y ) ) ( setq a (1 2
More informationArithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit
Nurul Hazlina 1 1. Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit Nurul Hazlina 2 Introduction 1. Digital circuits are frequently used for arithmetic operations 2. Fundamental
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationA Simple Syntax-Directed Translator
Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called
More informationReview. Steps to writing (stateless) circuits: Create a logic function (one per output)
MIPS ALU Review Steps to writing (stateless) circuits: Create a truth table Go through all different combinations of inputs For each row, generate each output based on the problem description Create a
More information11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT
Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the
More informationTests, Backtracking, and Recursion
Tests, Backtracking, and Recursion Artificial Intelligence Programming in Prolog Lecture 3 30/09/04 30/09/04 AIPP Lecture 3: Rules, Results, and Backtracking 1 Re-cap A Prolog program consists of predicate
More informationLCSL Reference Manual
LCSL Reference Manual Sachin Nene, Chaue Shen, Bogdan Caprita, Julian Maller 1.1 Lexical Conventions 1.1.1 Comments Comments begin with (* and end with *) 1.1.2 Variables Variables consist solely of alphanumeric
More informationBuilt-in Module BOOL. Lecture Note 01a
Built-in Module BOOL Lecture Note 01a Topics! Built-in Boolean Algebra module BOOL and the equivalence of two boolean expressions (or SAT problems)! Study important concepts about CafeOBJ system through
More informationSOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)
SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:
More informationBinary Adders: Half Adders and Full Adders
Binary Adders: Half Adders and Full Adders In this set of slides, we present the two basic types of adders: 1. Half adders, and 2. Full adders. Each type of adder functions to add two binary bits. In order
More informationChapter 4 Arithmetic Functions
Logic and Computer Design Fundamentals Chapter 4 Arithmetic Functions Charles Kime & Thomas Kaminski 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Overview Iterative combinational
More informationIntroduction to Computer Science. Homework 1
Introduction to Computer Science Homework. In each circuit below, the rectangles represent the same type of gate. Based on the input and output information given, identify whether the gate involved is
More informationBinary Addition. Add the binary numbers and and show the equivalent decimal addition.
Binary Addition The rules for binary addition are 0 + 0 = 0 Sum = 0, carry = 0 0 + 1 = 0 Sum = 1, carry = 0 1 + 0 = 0 Sum = 1, carry = 0 1 + 1 = 10 Sum = 0, carry = 1 When an input carry = 1 due to a previous
More informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationBasic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.
More informationChapter 2 Basic Logic Circuits and VHDL Description
Chapter 2 Basic Logic Circuits and VHDL Description We cannot solve our problems with the same thinking we used when we created them. ----- Albert Einstein Like a C or C++ programmer don t apply the logic.
More informationCombinational Logic II
Combinational Logic II Ranga Rodrigo July 26, 2009 1 Binary Adder-Subtractor Digital computers perform variety of information processing tasks. Among the functions encountered are the various arithmetic
More informationLECTURE 4. Logic Design
LECTURE 4 Logic Design LOGIC DESIGN The language of the machine is binary that is, sequences of 1 s and 0 s. But why? At the hardware level, computers are streams of signals. These signals only have two
More informationMethods for Interactive Constraint Satisfaction
JEPPE NEJSUM MADSEN nejsum@diku.dk Methods for Interactive Constraint Satisfaction MASTER S THESIS February 14, 2003 DEPARTMENT OF COMPUTER SCIENCE University of Copenhagen Abstract A constraint satisfaction
More informationFunctional Programming in Haskell Part I : Basics
Functional Programming in Haskell Part I : Basics Madhavan Mukund Chennai Mathematical Institute 92 G N Chetty Rd, Chennai 600 017, India madhavan@cmi.ac.in http://www.cmi.ac.in/ madhavan Madras Christian
More informationRealization of Forward Checking in Logic. Christian Holzbaur. Department of Medical Cybernetics and AI. University of Vienna, and
Realization of Forward Checking in Logic Programming via Extended Unication Christian Holzbaur (email: christian@ai-vie.uucp) Department of Medical Cybernetics and AI University of Vienna, and Austrian
More informationTopic 5: Examples and higher-order functions
CITS 3242 Programming Paradigms Topic 5: Examples and higher-order functions This lecture includes some larger examples in F# and introduces higher-functions. 1 Examples: append Now that we have lists,
More informationa little more on macros sort of like functions, but..
a little more on macros 1 sort of like functions, but.. one of the most interesting but tricky aspects of Lisp. unlike functions, macros don't evaluate their arguments; they compute on unevaluated expressions
More informationHenry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012
Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012 1 Digital vs Analog Digital signals are binary; analog
More informationECE 341 Midterm Exam
ECE 341 Midterm Exam Time allowed: 75 minutes Total Points: 75 Points Scored: Name: Problem No. 1 (8 points) For each of the following statements, indicate whether the statement is TRUE or FALSE: (a) A
More informationLists. Michael P. Fourman. February 2, 2010
Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce
More informationChapter 4. Combinational Logic. Dr. Abu-Arqoub
Chapter 4 Combinational Logic Introduction N Input Variables Combinational Logic Circuit M Output Variables 2 Design Procedure The problem is stated 2 The number of available input variables & required
More informationPropositional Calculus. Math Foundations of Computer Science
Propositional Calculus Math Foundations of Computer Science Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they can use it to
More informationLAB K Basic Verilog Programming
LAB K Basic Verilog Programming Perform the following groups of tasks: LabK1.v 1. Create a directory to hold the files of this lab. 2. Launch your favourite editor and a command-prompt console; you will
More informationCOMPUTER SCIENCE TRIPOS
CST.2011.3.1 COMPUTER SCIENCE TRIPOS Part IB Monday 6 June 2011 1.30 to 4.30 COMPUTER SCIENCE Paper 3 Answer five questions. Submit the answers in five separate bundles, each with its own cover sheet.
More informationData Types. Operators, Assignment, Output and Return Statements
Pseudocode Reference Sheet rev 4/17 jbo Note: This document has been developed by WeTeach_CS, and is solely based on current study materials and practice tests provided on the TEA website. An official
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have
More informationWhat are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)).
What are Operators? - 1 Functors Introduce operators to improve the readability of programs Operators syntactic sugar Based on Clocksin & Mellish Sections 2.3, 5.5 O-1 O-2 The arithmetic expression:» x
More informationMIDTERM EXAMINATION - CS130 - Spring 2003
MIDTERM EXAMINATION - CS130 - Spring 2003 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 120 + 10 extra credit This exam counts for
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationA flow chart is a graphical or symbolic representation of a process.
Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of
More informationComputer Architecture and Organization: L04: Micro-operations
Computer Architecture and Organization: L4: Micro-operations By: A. H. Abdul Hafez Abdul.hafez@hku.edu.tr, ah.abdulhafez@gmail.com, hafez@research.iiit.ac.in 1 Outlines 1. Arithmetic microoperation 2.
More informationLISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.
LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,
More informationISC SPECIMEN PAPER Computer Science Paper 1 (Theory) Part I Question 1. [ 2 x 5 = 10] Question 2. [ 2 x 5 = 10] Question 3.
ISC SPECIMEN PAPER Computer Science Paper 1 (Theory) Part I While working questions in this part, indicate briefly your working and reasoning wherever required. Question 1. a) State the two distributive
More informationCSC 101: Lab #5 Boolean Logic Practice Due Date: 5:00pm, day after lab session
Name: Email Username: Lab Date and Time: CSC 101: Lab #5 Boolean Logic Practice Due Date: 5:00pm, day after lab session Lab Report: Answer the questions within this document as you encounter them. Also,
More informationTypes and Type Inference
CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of
More informationLast Lecture: Adder Examples
Last Lecture: Adder Examples module fulladder(input logic a, b, cin, output logic s, cout); logic p, g; // internal nodes assign p = a ^ b; assign g = a & b; assign s = p ^ cin; assign cout = g (p & cin);
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationDefining Binary & Unary Operators DO-1
Defining Binary & Unary Operators DO-1 English-French Dictionary 1 Can use compound terms to represent a dictionary» list is a structure that contains an entry followed by the rest of the list» For example
More informationCode No: R Set No. 1
Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional
More informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationVerilog Lab. Two s Complement Add/Sub Unit. TA: Xin-Yu Shi
Verilog Lab. Two s Complement Add/Sub Unit TA: Xin-Yu Shi genius@access.ee.ntu.edu.tw Introduction In previous lecture, what you have learned : Complete representation for binary negative number Arithmetic
More informationTopic B: Backtracking and Lists
Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 3 2. Applications... 3 3. Examples... 4 4. FPL Characteristics:... 5 5. Lambda calculus (LC)... 6 5.1. LC expressions forms... 6 5.2. Semantic of
More informationA Verilog Primer. An Overview of Verilog for Digital Design and Simulation
A Verilog Primer An Overview of Verilog for Digital Design and Simulation John Wright Vighnesh Iyer Department of Electrical Engineering and Computer Sciences College of Engineering, University of California,
More informationINF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is
More informationArithmetic-logic units
Arithmetic-logic units An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the heart of a processor you could say that everything else in the CPU is there
More informationCARLETON UNIVERSITY. Laboratory 2.0
CARLETON UNIVERSITY Department of Electronics ELEC 267 Switching Circuits Jan 3, 28 Overview Laboratory 2. A 3-Bit Binary Sign-Extended Adder/Subtracter A binary adder sums two binary numbers for example
More informationReal Digital Problem Set #6
Real igital Problem et #6. (2 points) ketch a block diagram for a magnitude comparator bit-slice circuit. Create K-maps to define the bit-slice circuit, and use them to find optimal logic equations. ketch
More informationProgramming Paradigms
PP 2016/17 Unit 16 Erlang Modules, Functions and Control Structures 1/31 Programming Paradigms Unit 16 Erlang Modules, Functions and Control Structures J. Gamper Free University of Bozen-Bolzano Faculty
More informationComputer Organization and Levels of Abstraction
Computer Organization and Levels of Abstraction Announcements Today: PS 7 Lab 8: Sound Lab tonight bring machines and headphones! PA 7 Tomorrow: Lab 9 Friday: PS8 Today (Short) Floating point review Boolean
More informationSMURF Language Reference Manual Serial MUsic Represented as Functions
SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu
More informationELEC 326: Class project
ELEC 326: Class project Kartik Mohanram 1 Introduction For this project you will design and test a three-digit binary-coded-decimal (BCD) adder capable of adding positive and negative BCD numbers. In the
More informationObjectives. Principles of Constraint Programming Krzysztof R. Apt. Chapter 2 Constraint Satisfaction Problems: Examples. Example: SEND + MORE = MONEY
Objectives Principles of Constraint Programming Krzysztof R. pt Chapter 2 Constraint Satisfaction Problems: xamples Define formally Constraint Satisfaction Problems (CSP), Modeling: representation of a
More informationIntroduction to Functional Programming and basic Lisp
Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to
More information