Arithmetic Program Examples

Slides:



Advertisements
Similar presentations
Chapter 6 Control Backtracking LP and Prolog Chapter 62 The Cut ! Cut is the built-in predicate that instructs the interpreter not to backtrack.
Advertisements

The Logic of Quantified Statements
Knowledge Representation
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
Kasabov : CH 1-2 P. 65: A General Approach to Knowledge Engineering.
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
EXAMPLE 1 Solve absolute value inequalities
Sepandar Sepehr McMaster University November 2008
Prolog Programming Lecture Module 13. Objective ● What is Prolog? ● Prolog program ● Syntax of Prolog ● Prolog Control Strategy ● Execution of Prolog.
4.8: Quadratic Formula HW: worksheet
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
Review Topics Test 1. Background Topics Definitions of Artificial Intelligence & Turing Test Physical symbol system hypothesis vs connectionist approaches.
6.5 – Solving Equations with Quadratic Techniques.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Rule Based Systems Chapter 12. Artificial IntelligenceChapter 82 Expert Systems p. 547 MYCIN (1976) see section 8.2 backward chaining + certainty factor.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
TECHNOLOGY GUIDE FOUR Intelligent Systems.
An Introduction to Artificial Intelligence and Knowledge Engineering N. Kasabov, Foundations of Neural Networks, Fuzzy Systems, and Knowledge Engineering,
ProLog PROgramming in LOGic. Description of Prolog Prolog stands for PROgramming in LOGic. It is a nonprocedural and declarative language.
Assoc. Prof. Abdulwahab AlSammak. Course Information Course Title: Artificial Intelligence Instructor : Assoc. Prof. Abdulwahab AlSammak
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
5.4 – Solving Compound Inequalities. Ex. Solve and graph the solution.
Solving Linear Inequalities `. Warm-up -4 < x ≤ 6 x ≤ -4 or x>
Lesson 3-5: Solving Equations with the Variable on Each Side.
 Dr. Syed Noman Hasany 1.  Review of known methodologies  Analysis of software requirements  Real-time software  Software cost, quality, testing.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Logical and Functional Programming
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
5.3 – Solving Quadratic Equations by Factoring. Ex. 1 Solve y = x 2 + 5x + 6 by factoring.
KNOWLEDGE BASED SYSTEMS
Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program.
Solving Quadratic Formula using the discriminant.
Knowledge Based Information System
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
The Prolog Language by Piyabut Thavilthicakul
Artificial Intelligence Midterm 고려대학교 컴퓨터학과 자연어처리 연구실 임 해 창.
Abdul Rahim Ahmad MITM 613 Intelligent System Chapter 10: Tools.
Chapter 2 Syntax and meaning of prolog programs Part 1.
Done By :- -Nesreen Basem -Sara nabil -Rawan Prolog Program.
1 Chapter 13 Artificial Intelligence and Expert Systems.
TECHNOLOGY GUIDE FOUR Intelligent Systems. TECHNOLOGY GUIDE OUTLINE TG4.1 Introduction to Intelligent Systems TG4.2 Expert Systems TG4.3 Neural Networks.
Expert Systems Chapter Artificial IntelligenceChapter 82 Expert System p. 547 MYCIN (1976) see section 8.2 backward chaining + certainty factor.
2.2 Solving Quadratic Equations Algebraically Quadratic Equation: Equation written in the form ax 2 + bx + c = 0 ( where a ≠ 0). Zero Product Property:
Introduction to Artificial Intelligence Heshaam Faili University of Tehran.
Chapter 5 Solving Systems of Linear Equations. Determine Whether a Given Ordered Pair is a Solution of a System Ex. 1.
Chapter 11 Quadratic Equations.
Artificial Intelligence
Chapter 4 Quadratic Equations
Quadratic Inequalities
Copyright 2013, 2010, 2007, 2005, Pearson, Education, Inc.
To solve absolute value equations and inequalities in one variable
TECHNOLOGY GUIDE FOUR Intelligent Systems.
Lesson: Extension Cubic Functions and Equations
Artificial Intelligence (CS 370D)
النظم الخبيرة Expert Systems (ES)
The Quadratic Formula.
Knowledge Representation and Inference
9-6 The Quadratic Formula and Discriminant
TA : Mubarakah Otbi, Duaa al Ofi , Huda al Hakami
Chapter 5 Expert Systems.
Chapter 2 Syntax and meaning of prolog programs
Inference and Resolution for Problem Solving
Warm Up #4 1. Write 15x2 + 6x = 14x2 – 12 in standard form. ANSWER
Chapter 2: Prolog (Introduction and Basic Concepts)
Intersection Method of Solution
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Arithmetic Program Examples Chapter 8 Arithmetic Program Examples

Factorial1.pro factorial(N, Result) :- N > 1, predicates factorial(integer, integer) clauses factorial(1, 1). factorial(N, Result) :- N > 1, M = N-1, factorial(M, RET), Result = N*RET. factorial(N,M) :- M = N, write(“end of datatbase”). Chapter 8

Factorial2.pro factorial(N, Result) :- M = N-1, factorial(M, RET), predicates factorial(integer, integer) clauses factorial(1, 1) :- !. factorial(N, Result) :- M = N-1, factorial(M, RET), Result = N*RET. Chapter 8

Factorial Ex07EX03.pro factorial(X, FactX) /* Recursive program to compute factorials. */ predicates factorial(integer, real) clauses factorial(1, 1) :- !. factorial(X, FactX) :- Y = X-1, factorial(Y, FactY), FactX = X*FactY. Chapter 8

Factorial Ex07EX07.pro predicates factorial(integer, real) factorial_aux(integer, real, integer, real) /* Numbers likely to exceed 32767 are declared as reals. */ clauses factorial(N, FactN) :- factorial_aux(N, FactN, 1, 1). factorial_aux(N, FactN, I, P) :- I <= N, !, NewP = P * I, NewI = I + 1, factorial_aux(N, FactN, NewI, NewP). factorial_aux(N, FactN, I, FactN) :- I > N. Chapter 8

Factorial Ex07EX08.pro /*Turbo Prolog 2.0 Chapter 7, Example Program 8*/ predicates factorial(integer,real) factorial(integer, real, integer, real) /* Numbers likely to exceed 32767 are declared as reals. */ clauses factorial(N,FactN):- factorial(N,FactN,1,1). factorial(N, FactN, N, FactN):- !. factorial(N, FactN, I, P):- NewI = I+1, NewP = P*NewI, factorial(N, FactN, NewI, NewP). Chapter 8

Status Ex3.6status.pro /* Ex3.6 from thai book */ predicates status(symbol). sex(symbol,symbol). father(symbol,symbol). husband (symbol,symbol) clauses husband (suchart,malee). husband (somchai,monta). father(suchart,poo). father(somchai,tik). father(somchai,tum). father(somchai,ta). father(somchai,tu). sex(female,malee). sex(female,monta). sex(male,suchart). sex(male,somchai). sex(female,susy). sex(male,mike). Chapter 8

Status Ex3.6status.pro status(X) :- sex(S,X),write(X, “ is “,S," "),nl,fail. status(X) :- husband(X,W),!, write("married wife = ",W),nl, write(" Chiledren : "),nl, father(X,C),write(" ",C),nl, fail. husband (H,X),!, write("married husband = ",H),nl, father(H,C),write(" ",C),nl, write(X, " is single. \n "). Chapter 8

โจทย์ จงเขียนโปรแกรมภาษาโปรล็อกเพื่อคำนวณหาค่า A = (X/B +B)/2 Chapter 8

Ex5.2 Solution.pro /* Ex5.2 from thai book */ /* Find A = (X/B +B)/2 */ predicates solve(real,real,real). clauses solve(A,X,B) :- A = (X/B + B)/2. Chapter 8

โจทย์ จงเขียนโปรแกรมภาษาโปรล็อกเพื่อคำนวณหาค่า AX^2 + BX + C = 0 X = ( -B +- sqrt(B*B -4AC))/2A Chapter 8

Ex5.3 Solution.pro /* Ex5.3 from thai book */ /* Find AX^2 =BX + C = 0 */ /* Find X = ( -B +-sqrt(B*B -4AC))/2A */ predicates solve(real,real,real). run(real,real,real). clauses run(A,B,C) :- D = B*B - (4*A*C), solve(A,B,D),nl. solve(_,_,D) :- D < 0, write("No solution"). solve(A,B,D) :- D = 0, X = -B / (2*A), write(" x = ",X),!. S = sqrt(D), X1 = (-B + S)/(2*A), X2 = (-B - S)/(2*A), write(" x1 = ",X1," x2 = ",X2). Chapter 8

โจทย์ จงเขียนโปรแกรมภาษาโปรล็อกเพื่อคำนวณหาค่า ระยะห่างจากเมือง 2 เมืองใดๆ route(town, town, distance) road(town1, town2, 200) Chapter 8

Ex18Ex02.pro : Distance /*Turbo Prolog 2.0 Chapter 18, Example Program 2 */ domains town = symbol distance = integer predicates road(town, town, distance) route(town, town, distance) clauses road(tampa, houston, 200). road(gordon, tampa, 300). road(houston, gordon, 100). road(houston, kansas_city, 120). road(gordon, kansas_city, 130). route(Town1, Town2, Distance) :- road(Town1, Town2, Distance). road(Town1, X, Dist1), route(X, Town2, Dist2), Distance=Dist1+Dist2, !. Chapter 8

EX18EX01.pro : Animal goal: run predicates clauses animal_is(symbol) it_is(symbol) ask(symbol, symbol, symbol) positive(symbol, symbol) negative(symbol, symbol) clear_facts run clauses animal_is(cheetah) :- it_is(mammal), it_is(carnivore), positive(has, tawny_color), positive(has, dark_spots). animal_is(tiger) :- it_is(mammal), positive(has, black_stripes). goal: run Chapter 8

EX18EX01.pro : Animal (cont.) animal_is(giraffe) :- it_is(ungulate), positive(has, long_neck), positive(has, long_legs), positive(has, dark_spots). animal_is(zebra) :- it_is(ungulate), positive(has,black_stripes). animal_is(ostrich) :- it_is(bird), negative(does, fly), positive(has, black_and_white_color). animal_is(penguin) :- it_is(bird), positive(does, swim), animal_is(albatross) :- it_is(bird), positive(does, fly_well). Chapter 8

EX18EX01.pro : Animal (cont.) it_is(mammal) :- positive(has, hair). it_is(mammal) :- positive(does, give_milk). it_is(bird) :- positive(has, feathers). it_is(bird) :- positive(does, fly), positive(does,lay_eggs). it_is(carnivore) :- positive(does, eat_meat). it_is(carnivore) :-positive(has, pointed_teeth), positive(has, claws), positive(has, forward_eyes). it_is(ungulate) :- it_is(mammal), positive(has, hooves). it_is(ungulate) :- it_is(mammal), positive(does, chew_cud). positive(X, Y) :- ask(X, Y, yes). negative(X, Y) :- ask(X, Y, no). Chapter 8

EX18EX01.pro : Animal (cont.) ask(X, Y, yes) :- !, write(“Question > “, X, " it ", Y, “?”,’ \n’), readln(Reply), frontchar(Reply, 'y', _). ask(X, Y, no) :- !, write(“Question > “,X, " it ", Y, “?”,’\n’), frontchar(Reply, 'n', _). clear_facts :- write("\n\nPlease press the space bar to exit\n"), readchar(_). run :- animal_is(X), !, write("\nAnswer.... => Your animal may be a (an) ",X), nl, nl, clear_facts. write("\n Answer.... => Unable to determine what"), write("your animal is.\n\n"), clear_facts. Chapter 8

Logic Programming Symbolic Expert System VB Propositional Predicate Logic Prolog True False Fact Rule pred_name(att1,att2,var1) if....then... Chapter 8

Turbo Prolog + - * / mod Symbolic interface ! cut, fail and, or, not factorial interface ! cut, fail Turbo Prolog write read and, or, not window recursive predicates clauses goal domains string variable matching symbol fact rule integer List pred_name(att1,att2,var1) member reverse append head/tail length Chapter 8

Expert System Symbolic Knowledge Engineer Expert Specific Domain Artificial Intelligence Knowledge Representation Expert System Knowledge Engineer Expert Specific Domain User Interface Inference Engine Easy to use Tool Explanation Fact Rule Prolog VB Others if....then... Chapter 8

Knowledge Representation Symbolic Expert System Knowledge Representation semantic network frame conceptual graph predicate Logic slot value isa inheritant pred_name(att1,att2) Chapter 8

DEMO EXPERT SYSTEMS Chapter 8