Declarative Programming Arithmetic in PROLOG Autumn 2014.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

7.1Variable Notation.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
3-5 Solving Equations with the variable on each side Objective: Students will solve equations with the variable on each side and equations with grouping.
Chapter 3 Math Vocabulary
Multiplication and Division Equations SWBAT solve multiplication equations using the division property of equality; solve division equations using the.
 SWBAT solve two-step algebraic equations.  Two-Step Equations are equations that require two- steps to solve.  You will ADD or SUBTRACT and then.
Solving Equations. Inverse Operations  When solving equations algebraically, use the inverse (opposite) operation that is displayed to determine what.
 Vocabulary: ◦ Variable – A symbol, usually a letter of the alphabet, such as the letter n, that is used to represent a number. ◦ Variable expression.
2440: 211 Interactive Web Programming Expressions & Operators.
Algebra Basics.
ORDER OF OPERATIONS x 2 Evaluate the following arithmetic expression: x 2 Each student interpreted the problem differently, resulting in.
MM218 - Unit 7 Seminar Topics
Chapter 1 Review College Algebra Remember the phrase “Please Excuse My Dear Aunt Sally” or PEMDAS. ORDER OF OPERATIONS 1. Parentheses - ( ) or [ ] 2.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
1-2 Order of Operations and Evaluating Expressions.
Chapter 2 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 2-1 Solving Linear.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Operators in Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Solving Systems of Equations Algebraically Chapter 3.2.
Solving 2-Step Variable Equations. Two Step Equations Essential Question How are inverse operations used to solve two step equations? Why does order matter.
1.6. DEFINITIONS  An equation is a statement that two expressions are equal.  Usually contains 1 or more variables  A variable is a symbol that represents.
One step equations Add Subtract Multiply Divide  When we solve an equation, our goal is to isolate our variable by using our inverse operations.  What.
Lesson 1-8 Solving Addition and Subtraction Equations.
Solving One-Step Equations © 2007 by S - Squared, Inc. All Rights Reserved.
Unit 2 Solve Equations and Systems of Equations
Copyright © Curt Hill Axiomatic Approach Some needed groundwork.
Entry Task Solve for the given variable 1) A = ½bh for h 2) ax + bx = c solve for x LT: I can solve and graph inequalities.
Evaluating Expressions and Combining Like Terms
1.4 Solving Inequalities I can: 1.Graph inequalities 2.Solve inequalities.
Ch 10: Polynomials G) Completing the Square Objective: To solve quadratic equations by completing the square.
Analyzing Equations and Inequalities Objectives: - evaluate expressions and formulas using order of operations - understand/use properties & classifications.
One Step Equations and Inequalities Review
Chapter 2: Reasoning & Proof 2.4 Reasoning in Algebra.
2.2 Solving Two- Step Equations. Solving Two Steps Equations 1. Use the Addition or Subtraction Property of Equality to get the term with a variable on.
Lesson 8.1. » A statement where two mathematical expressions are. » Think of an equation as a balance scale or teeter-totter. The left side must always.
Solving Inequalities. ● Solving inequalities follows the same procedures as solving equations. ● There are a few special things to consider with inequalities:
Solving Algebraic Equations. Equality 3 = = = 7 For what value of x is: x + 4 = 7 true?
Write, Interpret and Use Mathematical Expression and Equations.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Lesson 1-3 Solving Equations. Properties of Equality Reflexive Propertya = a Symmetric PropertyIf a = b, then b = a. Transitive PropertyIf a = b and b.
0.1 Solving One-Step Equations. To solve an equation means to find all values of the variable that make the equation true. Isolate the variable to one.
Operators & Expressions
LT: I can solve and graph inequalities.
3. 3 Solving Equations Using Addition or Subtraction 3
My Equations Booklet.
Properties of Equality and Solving One-Step Equations
2.5 and 2.6 Properties of Equality and Congruence
Assignment statement:
Arithmetic operations & assignment statement
Introduction to Algebra
Solving Equations by Adding or Subtracting
ONE STEP EQUATIONS.
ONE STEP EQUATIONS.
One-Step Equations with Subtraction
ORDER OF OPERATIONS BEMDAS. 1. Brackets - ( ) or [ ]
EQ: How do I solve an equation in one variable?
Use of symbols Objectives:
1.3 Solving Linear Equations
One step equation with Multiplication and Division
Algebraic proofs A proof is an argument that uses logic to show that a conclusion is true. Every time you solved an equation in Algebra you were performing.
Subtract the same value on each side
Solving Inequalities.
Two step equation Brackets
Learn to solve 2-step equations
ONE STEP EQUATIONS.
One-Step Equations with Addition and Subtraction
By: Savana Bixler Solving Equations.
ONE STEP EQUATIONS.
Presentation transcript:

Declarative Programming Arithmetic in PROLOG Autumn 2014

A way to do arithmetic in PROLOG How to define natural numbers? Giuseppe Peano For every natural number x, x = x. That is, equality is reflexive. For all natural numbers x and y, if x = y, then y = x. That is, equality is symmetric. For all natural numbers x, y and z, if x = y and y = z, then x = z. That is, equality is transitive. For all a and b, if a is a natural number and a = b, then b is also a natural number. That is, the natural numbers are closed under equality. Peano axioms (definition of equality)

A way to do arithmetic in PROLOG How to define natural numbers? Giuseppe Peano

A way to do arithmetic in PROLOG How to define natural numbers? 0 is a natural number for each number x there is a successor number x+1

A way to do arithmetic in PROLOG How to define natural numbers? 0 is a natural number for each number x there is a successor number x+1 numb(nil). numb(s(X)) :- numb(X).

A way to do arithmetic in PROLOG How to add 2 numbers? x+0 = 0 x + ( /*n time */) = x /*n times*/

A way to do arithmetic in PROLOG How to add 2 numbers? x+0 = 0 x + ( /*n time */) = x /*n times*/ sum(X,nil,X). sum(X,s(Y),s(Z)) :- sum(X,Y,Z).

A way to do arithmetic in PROLOG How to add 2 numbers? x+0 = 0 x + ( /*n time */) = x /*n times*/ sum(X,nil,X). sum(X,s(Y),s(Z)) :- sum(X,Y,Z). subtr(X,nil,X). subtr(X,s(Y),Z) :- subtr(X,Y,s(Z)).

A way to do arithmetic in PROLOG How to multiply 2 numbers? x*0 = 0 x * ( /*n times */) = x+x+...+x /*n times*/

A way to do arithmetic in PROLOG How to multiply 2 numbers? x*0 = 0 x * ( /*n time */) = x+x+...+x /*n times*/ mult(X,nil,nil). mult(X,s(Y),W) :- mult(X,Y,Z),sum(X,Z,W).

Built-in arithmetic Position. infix operators: +, , *, / prefix operator:  postfix operator: ! Precedence. Each operator has a precedence value associated with it. Precedence values are used to decide which operator is carried out first. In Prolog, multiplication and division have higher precedence values than addition and subtraction. Associativity. An operator is either left associative or right associative. In Prolog, arithmetic operations are left associative. Round brackets can be used to enforce precedence and associativity.

Built-in arithmetic Some other functions may be available sin/1 cos/1 tan/1 log/1 exp/1

Built-in arithmetic The predicates +/2,  /2, */2, //2,  /1, !/1 sin/1, cos/1, tan/1, log/1, exp/1 etc. are just structure names Their “arithmetical” meaning is only that they are interpreted by truly arithmetical predicate is

Built-in arithmetic Predicate is performs arithmetical operations as a side effect The logical value of is is always true A correct usage: X is expression where expression is syntactically correct arithmetical expression, containing only numerical constants (or variables instantiated to numerical constants)

Built-in arithmetic is cannot be used to solve equations e.g. X*X is 2*X + 17

Built-in arithmetic Besides is arithmetic expressions are evaluated by comparison predicates: –X =:= Ythe values of X and Y are equal. –X =\= Ythe values of X and Y are not equal. –X < YX is less than Y. –X > Y X is greater than Y. –X =< Y X is less than or equal to Y (sometimes <=...). –X >= Y X is greater than or equal to Y. In this case both X and Y are not allowed to contain uninstantiated variables

Arithmetic - example ax 2 + bx + c = 0 solve(A,B,C,X1,X2) :- discr(A,B,C,D),X1 is ( – B + D)/(2*A), X2 is ( – B)/(2*A). discr(A,B,C,D) :- D1 is B*B – 4*A*C,D1 >= 0,D is sqrt(D1).