This talk will cover various aspects of Logic Programming. We examine Logic Programming in the contexts of Programming Languages, Mathematical Logic and Machine Learning.
We will we start with an introduction to Prolog and metaprogramming in Prolog. We will also discuss how miniKanren and Core.Logic differ from Prolog while maintaining the paradigms of logic programming.
We will then cover the Unification Algorithm in depth and examine the mathematical motivations which are rooted in Skolem Normal Form. We will describe the process of converting a statement in first order logic to clausal form logic. We will also discuss the applications of the Unification Algorithm to automated theorem proving and type inferencing.
Finally we will look at the role of Prolog in the context of Machine Learning. This is known as Inductive Logic Programming. In that context we will briefly review Decision Tree Learning and it's relationship to ILP. We will then examine Sequential Covering Algorithms for learning clauses in Propositional Calculus and then the more general FOIL algorithm for learning sets of Horn clauses in First Order Predicate Calculus. Examples will be given in both Common Lisp and Clojure for these algorithms.
Pierre de Lacaze has over 20 years’ experience with Lisp and AI based technologies. He holds a Bachelor of Science in Applied Mathematics and Computer Science and a Master’s Degree in Computer Science. He is the president of LispNYC.org
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
Babar is a research project in the field of Artificial Intelligence. It aims to bridge together Neural AI and Symbolic AI. As such it is implemented in three different programming languages: Clojure, Python and CLOS.
The Clojure component (Clobar) implements the graphical user interface to Babar. Examples of the Clojure Hiccup library and interfacing Clojure to Javascript will be presented. The Python module (Pybar) implements the web crawling and scraping and the Neural Networks aspect of Babar. The Word Embedding and and LSTM (Long Short-Term Memory) components of Pybar will be described in detail. Finally the Common Lisp module (Lispbar) implements the Symbolic AI aspect of Babar. This latter includes an English Language Parser and Semantic Networks implemented as an in-memory Hypergraph.
We will present each of these components and target individual aspects with code examples. Specifically we will first present the web developments and Neural Networks components. Then the English Language parser will be examined in detail. We will also present the knowledge extraction aspect and bridge this with the Neural Network component.
Ultimately we will argue what can be termed "Neural AI" and "Symbolic AI" are at not at odds with each other but rather complement each other. In summary Artificial Intelligence is not a question of "brain" or "mind", but rather a question of "brain" and "mind".
This talk will cover various aspects of Logic Programming. We examine Logic Programming in the contexts of Programming Languages, Mathematical Logic and Machine Learning.
We will we start with an introduction to Prolog and metaprogramming in Prolog. We will also discuss how miniKanren and Core.Logic differ from Prolog while maintaining the paradigms of logic programming.
We will then cover the Unification Algorithm in depth and examine the mathematical motivations which are rooted in Skolem Normal Form. We will describe the process of converting a statement in first order logic to clausal form logic. We will also discuss the applications of the Unification Algorithm to automated theorem proving and type inferencing.
Finally we will look at the role of Prolog in the context of Machine Learning. This is known as Inductive Logic Programming. In that context we will briefly review Decision Tree Learning and it's relationship to ILP. We will then examine Sequential Covering Algorithms for learning clauses in Propositional Calculus and then the more general FOIL algorithm for learning sets of Horn clauses in First Order Predicate Calculus. Examples will be given in both Common Lisp and Clojure for these algorithms.
Pierre de Lacaze has over 20 years’ experience with Lisp and AI based technologies. He holds a Bachelor of Science in Applied Mathematics and Computer Science and a Master’s Degree in Computer Science. He is the president of LispNYC.org
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
Babar is a research project in the field of Artificial Intelligence. It aims to bridge together Neural AI and Symbolic AI. As such it is implemented in three different programming languages: Clojure, Python and CLOS.
The Clojure component (Clobar) implements the graphical user interface to Babar. Examples of the Clojure Hiccup library and interfacing Clojure to Javascript will be presented. The Python module (Pybar) implements the web crawling and scraping and the Neural Networks aspect of Babar. The Word Embedding and and LSTM (Long Short-Term Memory) components of Pybar will be described in detail. Finally the Common Lisp module (Lispbar) implements the Symbolic AI aspect of Babar. This latter includes an English Language Parser and Semantic Networks implemented as an in-memory Hypergraph.
We will present each of these components and target individual aspects with code examples. Specifically we will first present the web developments and Neural Networks components. Then the English Language parser will be examined in detail. We will also present the knowledge extraction aspect and bridge this with the Neural Network component.
Ultimately we will argue what can be termed "Neural AI" and "Symbolic AI" are at not at odds with each other but rather complement each other. In summary Artificial Intelligence is not a question of "brain" or "mind", but rather a question of "brain" and "mind".
This paper describes BABAR, a knowledge extraction and representation system, completely implemented in CLOS, that is primarily geared towards organizing and reasoning about knowledge extracted from the Wikipedia Website. The system combines natural language processing techniques, knowledge representation paradigms and machine learning algorithms. BABAR is currently an ongoing independent research project that when sufficiently mature, may provide various commercial opportunities.
BABAR uses natural language processing to parse both page name and page contents. It automatically generates Wikipedia topic taxonomies thus providing a model for organizing the approximately 4,000,000 existing Wikipedia pages. It uses similarity metrics to establish concept relevancy and clustering algorithms to group topics based on semantic relevancy. Novel algorithms are presented that combine approaches from the areas of machine learning and recommender systems. The system also generates a knowledge hypergraph which will ultimately be used in conjunction with an automated reasoner to answer questions about particular topics.
These are the slides for the talk I gave in Harvard IQSS's "tech talk" series. The commands and files for the demo ("REPL") part of the lecture can be obtained here: http://www.mbarsinai.com/blog/2013/08/04/invitation-to-scala/.
Introduction to Category Theory for software engineersPranav Prakash
An Introduction to Category Theory for Software Engineers. By Dr Steve Easterbrook
Associate Professor,
Dept of Computer Science,
University of Toronto
sme@cs.toronto.edu
Explains the basic concepts of Category Theory, useful terminology to help understand the literature, and why it's so relevant to software engineering.
Efficient end-to-end learning for quantizable representationsNAVER Engineering
발표자: 정연우(서울대 박사과정)
발표일: 2018.7.
유사한 이미지 검색을 위해 neural network를 이용해 이미지의 embedding을 학습시킨다. 기존 연구에서는 검색 속도 증가를 위해 binary code의 hamming distance를 활용하지만 여전히 전체 데이터 셋을 검색해야 하며 정확도가 떨어지는 다는 단점이 있다. 이 논문에서는 sparse한 binary code를 학습하여 검색 정확도가 떨어지지 않으면서 검색 속도도 향상시키는 해쉬 테이블을 생성한다. 또한 mini-batch 상에서 optimal한 sparse binary code를 minimum cost flow problem을 통해 찾을 수 있음을 보였다. 우리의 방법은 Cifar-100과 ImageNet에서 precision@k, NMI에서 최고의 검색 정확도를 보였으며 각각 98× 와 478×의 검색 속도 증가가 있었다.
A generalized class of normalized distance functions called Q-Metrics is described in this presentation. The Q-Metrics approach relies on a unique functional, using a single bounded parameter (Lambda), which characterizes the conventional distance functions in a normalized per-unit metric space. In addition to this coverage property, a distinguishing and extremely attractive characteristic of the Q-Metric function is its low computational complexity. Q-Metrics satisfy the standard metric axioms. Novel networks for classification and regression tasks are defined and constructed using Q-Metrics. These new networks are shown to outperform conventional feed forward back propagation networks with the same size when tested on real data sets.
This paper describes BABAR, a knowledge extraction and representation system, completely implemented in CLOS, that is primarily geared towards organizing and reasoning about knowledge extracted from the Wikipedia Website. The system combines natural language processing techniques, knowledge representation paradigms and machine learning algorithms. BABAR is currently an ongoing independent research project that when sufficiently mature, may provide various commercial opportunities.
BABAR uses natural language processing to parse both page name and page contents. It automatically generates Wikipedia topic taxonomies thus providing a model for organizing the approximately 4,000,000 existing Wikipedia pages. It uses similarity metrics to establish concept relevancy and clustering algorithms to group topics based on semantic relevancy. Novel algorithms are presented that combine approaches from the areas of machine learning and recommender systems. The system also generates a knowledge hypergraph which will ultimately be used in conjunction with an automated reasoner to answer questions about particular topics.
These are the slides for the talk I gave in Harvard IQSS's "tech talk" series. The commands and files for the demo ("REPL") part of the lecture can be obtained here: http://www.mbarsinai.com/blog/2013/08/04/invitation-to-scala/.
Introduction to Category Theory for software engineersPranav Prakash
An Introduction to Category Theory for Software Engineers. By Dr Steve Easterbrook
Associate Professor,
Dept of Computer Science,
University of Toronto
sme@cs.toronto.edu
Explains the basic concepts of Category Theory, useful terminology to help understand the literature, and why it's so relevant to software engineering.
Efficient end-to-end learning for quantizable representationsNAVER Engineering
발표자: 정연우(서울대 박사과정)
발표일: 2018.7.
유사한 이미지 검색을 위해 neural network를 이용해 이미지의 embedding을 학습시킨다. 기존 연구에서는 검색 속도 증가를 위해 binary code의 hamming distance를 활용하지만 여전히 전체 데이터 셋을 검색해야 하며 정확도가 떨어지는 다는 단점이 있다. 이 논문에서는 sparse한 binary code를 학습하여 검색 정확도가 떨어지지 않으면서 검색 속도도 향상시키는 해쉬 테이블을 생성한다. 또한 mini-batch 상에서 optimal한 sparse binary code를 minimum cost flow problem을 통해 찾을 수 있음을 보였다. 우리의 방법은 Cifar-100과 ImageNet에서 precision@k, NMI에서 최고의 검색 정확도를 보였으며 각각 98× 와 478×의 검색 속도 증가가 있었다.
A generalized class of normalized distance functions called Q-Metrics is described in this presentation. The Q-Metrics approach relies on a unique functional, using a single bounded parameter (Lambda), which characterizes the conventional distance functions in a normalized per-unit metric space. In addition to this coverage property, a distinguishing and extremely attractive characteristic of the Q-Metric function is its low computational complexity. Q-Metrics satisfy the standard metric axioms. Novel networks for classification and regression tasks are defined and constructed using Q-Metrics. These new networks are shown to outperform conventional feed forward back propagation networks with the same size when tested on real data sets.
A generalized class of normalized distance functions called Q-Metrics is described in this presentation. The Q-Metrics approach relies on a unique functional, using a single bounded parameter Lambda, which characterizes the conventional distance functions in a normalized per-unit metric space. In addition to this coverage property, a distinguishing and extremely attractive characteristic of the Q-Metric function is its low computational complexity. Q-Metrics satisfy the standard metric axioms. Novel networks for classification and regression tasks are defined and constructed using Q-Metrics. These new networks are shown to outperform conventional feed forward back propagation networks with the same size when tested on real data sets.
This is the entrance exam paper for ISI MSQE Entrance Exam for the year 2008. Much more information on the ISI MSQE Entrance Exam and ISI MSQE Entrance preparation help available on http://crackdse.com
Köhler, Sven, Bertram Ludäscher, and Yannis Smaragdakis. 2012. “Declarative Datalog Debugging for Mere Mortals.” In Datalog in Academia and Industry, edited by Pablo Barceló and Reinhard Pichler, 111–22. Lecture Notes in Computer Science 7494. Springer Berlin Heidelberg. doi:10.1007/978-3-642-32925-8_12.
Abstract. Tracing why a “faulty” fact A is in the model M = P(I) of program P on input I quickly gets tedious, even for small examples. We propose a simple method for debugging and “logically profiling” P by generating a provenance-enriched rewriting P̂, which records rule firings according to the logical semantics. The resulting provenance graph can be easily queried and analyzed using a set of predefined and ad-hoc queries. We have prototypically implemented our approach for two different Datalog engines (DLV and LogicBlox), demonstrating the simplicity, effectiveness, and system-independent nature of our method.
Fosdem 2013 petra selmer flexible querying of graph dataPetra Selmer
These are the slides from a talk I presented at the Graph Processing room at FOSDEM 2013, in which I discussed my PhD topic: a query language allowing for the flexible querying of complex paths within graph structured data
The generation of Gaussian random fields over a physical domain is a challenging problem in computational mathematics, especially when the correlation length is short and the field is rough. The traditional approach is to make use of a truncated Karhunen-Loeve (KL) expansion, but the generation of even a single realisation of the field may then be effectively beyond reach (especially for 3-dimensional domains) if the need is to obtain an expected L2 error of say 5%, because of the potentially very slow convergence of the KL expansion. In this talk, based on joint work with Ivan Graham, Frances Kuo, Dirk Nuyens, and Rob Scheichl, a completely different approach is used, in which the field is initially generated at a regular grid on a 2- or 3-dimensional rectangle that contains the physical domain, and then possibly interpolated to obtain the field at other points. In that case there is no need for any truncation. Rather the main problem becomes the factorisation of a large dense matrix. For this we use circulant embedding and FFT ideas. Quasi-Monte Carlo integration is then used to evaluate the expected value of some functional of the finite-element solution of an elliptic PDE with a random field as input.
We start with motivation, few examples of uncertainties. Then we discretize elliptic PDE with uncertain coefficients, apply TT format for permeability, the stochastic operator and for the solution. We compare sparse multi-index set approach with full multi-index+TT.
Tensor Train format allows us to keep the whole multi-index set, without any multi-index set truncation.
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...ssuser7dcef0
Power plants release a large amount of water vapor into the
atmosphere through the stack. The flue gas can be a potential
source for obtaining much needed cooling water for a power
plant. If a power plant could recover and reuse a portion of this
moisture, it could reduce its total cooling water intake
requirement. One of the most practical way to recover water
from flue gas is to use a condensing heat exchanger. The power
plant could also recover latent heat due to condensation as well
as sensible heat due to lowering the flue gas exit temperature.
Additionally, harmful acids released from the stack can be
reduced in a condensing heat exchanger by acid condensation. reduced in a condensing heat exchanger by acid condensation.
Condensation of vapors in flue gas is a complicated
phenomenon since heat and mass transfer of water vapor and
various acids simultaneously occur in the presence of noncondensable
gases such as nitrogen and oxygen. Design of a
condenser depends on the knowledge and understanding of the
heat and mass transfer processes. A computer program for
numerical simulations of water (H2O) and sulfuric acid (H2SO4)
condensation in a flue gas condensing heat exchanger was
developed using MATLAB. Governing equations based on
mass and energy balances for the system were derived to
predict variables such as flue gas exit temperature, cooling
water outlet temperature, mole fraction and condensation rates
of water and sulfuric acid vapors. The equations were solved
using an iterative solution technique with calculations of heat
and mass transfer coefficients and physical properties.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSveerababupersonal22
It consists of cw radar and fmcw radar ,range measurement,if amplifier and fmcw altimeterThe CW radar operates using continuous wave transmission, while the FMCW radar employs frequency-modulated continuous wave technology. Range measurement is a crucial aspect of radar systems, providing information about the distance to a target. The IF amplifier plays a key role in signal processing, amplifying intermediate frequency signals for further analysis. The FMCW altimeter utilizes frequency-modulated continuous wave technology to accurately measure altitude above a reference point.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
2. Introduction to Logic Programming
Declarative programming describes what is desired
from the program, not how it should be done
Declarative language: statements of facts and
propositions that must be satisfied by a solution to the
program
real(x). proposition: x is a real number.
x > 0. proposition: x is greater than 0.
3. Declarative Languages
what is a "declarative language"?
give another example (not Prolog) of a declarative
language.
SELECT * FROM COUNTRY WHERE CONTINENT = 'Asia';
4. Facts, Rules, ...
What is a proposition?
What are facts?
What are rules?
What is a predicate?
What is a compound term?
6. A Really Simple Directed Graph
a
b c
d
(1) edge(a, b).
(2) edge(a, c).
(3) edge(c, d).
(4) path(X, X).
(5) path(X, Y)
edge(X, N), path(N, Y).
Question: What are the...
atoms
facts
rules
7. Clausal Form
Problem: There are too many ways to express
propositions.
difficult for a machine to parse or understand
Clausal form: standard form for expressing propositions
n
m A
A
A
B
B
B
2
1
2
1
Example:
path(X, Y) edge(X, N) path(N, Y).
Antecedent
Consequent
8. Clausal Form Example
Meaning:
if there is an edge from X to N and there a path from N
to Y,
then there is a path from X to Y.
The above is also called a "headed Horn clause".
In Prolog this is written as a proposition or rule:
path(X, Y) edge(X, N) path(N, Y).
path(X, Y) :- edge(X, N) , path(N, Y).
9. Query
A query or goal is an input proposition that we want
Prolog to "prove" or disprove.
A query may or may not require that Prolog give us a
value that satisfies the query (instantiation).
1 ?- edge(a,b).
Yes
2 ?- path(c,b).
No
3 ?- path(c,X).
X = c ;
X = d ;
No
10. Logical Operations on Propositions
What are the two operations that a logic programming
language performs on propositions to establish a
query?
That is, how does it satisfy a query, such as:
11. Unification
Unification is a process of finding values of variables
(instantiation) to match terms. Uses facts.
(1-3) edge(a,b). edge(a,c). edge(c,d). (Facts)
(4) path(X,X). (Rule)
(5) path(X,Y) := edge(X,N), path(N,Y). (Rule)
?- path(a,d). This is the query (goal).
Instantiate { X=a, Y=d }, and unify path(a,d) with Rule 5.
After doing this, Prolog must satisfy:
edge(a,N). This is a subgoal.
path(N,d). This is a subgoal.
12. Unification in plain English
Compare two atoms and see if there is a substitution
which will make them the same.
How can we unify 6 with 5?
Let X := a
Let Y := Z
1. edge(a, b). (Fact)
5. path(X, Y) :- edge(X, N) , path(N, Y).
6. path(a, Z). (Query)
13. Resolution
Resolution is an inference rule that allows propositions to
be combined.
Idea: match the consequent (LHS) of one proposition
with the antecedent (RHS term) of another.
).
(
)
(
then
)
(
)
(
If
)
(
)
(
)
(
)
(
2
1
1
2
2
1
2
1
y
Q
y
P
y
Q
y
P
X
Q
X
Q
X
P
X
P
Examples are in the textbook and tutorials.
14. Resolution Example
How can we unify 6 with 5?
Let X := a
Let Y := Z
Resolution:
1. edge(a, b). (Fact)
5. path(X, Y) :- edge(X, N) , path(N, Y).
6. path(a, Z). (Query)
15. Resolution
Resolution is an inference rule that allows propositions to
be combined.
Idea: match the consequent (LHS) of one proposition
with the antecedent (RHS term) of another.
).
(
)
(
then
)
(
)
(
If
)
(
)
(
)
(
)
(
2
1
1
2
2
1
2
1
y
Q
y
P
y
Q
y
P
X
Q
X
Q
X
P
X
P
Examples are in the textbook and tutorials.
16. How to handle failures
Prolog can work backwards towards the facts using
resolution, instantiation, and unification.
As it works, Prolog must try each of several choices.
These choices can be stored as a tree.
?- path(a,d). The goal.
Unify: unify path(a,d)with Rule 5 by instantiate { X=a,Y=d }
Subgoal: edge(a,N).
Instantiate: N=b which is true by Fact 1.
Subgoal: path(b,d).
Unify: path(b,d)with Rule 5: path(b,d) :- edge(b,N),path(N,d)
Failure: can't instantiate edge(b,N) using any propositions.
17. How to handle failures (2)
When a solution process fails, Prolog must undo some
of the decisions it has made.
This is called backtracking.
same as backtracking you use in recursion.
Marks a branch of the tree as failed.
18. How it Works (1)
There are 2 search/execution strategies that can be
used by declarative languages based on a database of
facts.
1. Forward Chaining
2. Backward Chaining
what are the meanings of these terms?
19. How it Works (2)
1. Forward Chaining
2. Backward Chaining
Which strategy does Prolog use?
Under what circumstances is one strategy more
effective than the other?
Consider two cases:
large number of rules, small number of facts
small number of rules, large number of facts
21. 3 Parts of a Prolog Program
1. A database contains two kinds of information.
What information is in a database?
2. A command to read or load the database.
in Scheme you can use load("filename")
in Prolog use consult('filename')
3. A query or goal to solve.
23. Query the Ancestors
?- consult('/pathname/ancestors.pl').
ancestor(bill,sam).
Yes
?- ancestor(bill,X).
X = jill ;
X = sam ;
ERROR: Out of local stack
?- ancestor(X,bob).
ERROR: Out of local stack
24. Understanding the Problem
You need to understand how Prolog finds a solution.
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :-
ancestor(X,Z), ancestor(Z,Y).
parent(X,Y) :- mother(X,Y).
parent(X,Y) :- father(X,Y).
father(bill,jill).
mother(jill,sam).
father(bob,sam).
Depth-first search
causes immediate
recursion
25. Factorial
factorial(0,1).
factorial(N,N*M) :- factorial(N-1,M).
The factorial of 0 is 1.
The factorial of N is N*M if the the factorial of N-1 is M
File: factorial1.pl
?- consult('/path/factorial1.pl').
?- factorial(0,X).
X = 1
Yes
?- factorial(1,Y).
ERROR: Out of global stack
26. Query Factorial
?- consult('/path/factorial1.pl').
?- factorial(2,2).
No
?- factorial(1,X).
ERROR: Out of global stack
?- 2*3 = 6.
No
?- 2*3 = 2*3.
Yes
Problem: Arithmetic is not performed automatically.
?- 6 is 2*3.
Yes
?- 2*3 is 6.
No
is(6,2*3).
l-value = r-value ?
27. Arithmetic via Instantiation: is
"=" simply means comparison for identity.
factorial(N, 1) :- N=0.
"is" performs instantiation if the left side doesn't have a
value yet.
product(X,Y,Z) :- Z is X*Y.
this rule can answer the query:
product(3,4,N).
Answer: N = 12.
but it can't answer:
product(3,Y,12).
28. is does not mean assignment!
This always fails: N is N - 1.
% sumto(N, Total): compute Total = 1 + 2 + ... + N.
sumto(N, 0) :- N =< 0.
sumto(N, Total) :=
Total is Subtotal + N,
N is N-1, always fails
sumto(N, Subtotal).
?- sumto(0, Sum).
Sum = 0.
Yes
?- sumto(1, Sum).
No
29. is : how to fix?
How would you fix this problem?
% sumto(N, Total): compute Total = 1 + 2 + ... + N.
sumto(N, 0) :- N =< 0.
sumto(N, Total) :=
N1 is N-1, always fails
sumto(N1, Subtotal),
Total is Subtotal + N.
?= sumto(5, X).
30. Factorial revised
factorial(0,1).
factorial(N,P) :- N1 is N-1,
factorial(N1,M), P is M*N.
Meaning:
The factorial of 0 is 1.
factorial of N is P
if N1 = N-1
and factorial of N1 is M
and P is M*N.
File: factorial2.pl
31. Query Revised Factorial
?- consult('/path/factorial2.pl').
?- factorial(2,2).
Yes
?- factorial(5,X).
X = 120
Yes
?- factorial(5,X).
X = 120 ;
ERROR: Out of local stack
?- factorial(X,120).
but still has some problems...
request another solution
33. Readability: one clause per line
factorial(0,1).
factorial(N,P) :- not(N=0), N1 is N-1,
factorial(N1,M), P is M*N.
factorial(0,1).
factorial(N,P) :-
not(N=0),
N1 is N-1,
factorial(N1,M),
P is M*N.
Better
34. Finding a Path through a Graph
edge(a, b).
edge(b, c).
edge(b, d).
edge(d, e). edge(d, f).
path(X, X).
path(X, Y) :- edge(X, Z), path(Z, Y).
a
b
c d
e f
?- edge(a, b).
Yes
?- path(a, a).
Yes
?- path(a, e).
Yes
?- path(e, a).
No
35. How To Define an Undirected Graph?
edge(a, b).
edge(b, c).
edge(b, d).
edge(d, e).
edge(d, f).
edge(X, Y) := not(X=Y), edge(Y, X).
path(X, X).
path(X, Y) :- edge(X, Z), path(Z, Y).
a
b
c d
e f
?- edge(b, a).
Yes
?- path(a, b).
Yes
?- path(b, e).
No
36. Queries and Answers
When you issue a query in Prolog, what are the
possible responses from Prolog?
% Suppose "likes" is already in the database
:- likes(jomzaap, 219212). % Programming Languages.
Yes.
:- likes(papon, 403111). % Chemistry.
No.
:- likes(Who, 204219). % Theory of Computing?
Who = pattarin
Does this mean Papon doesn't like Chemistry?
37. Closed World Assumption
What is the Closed World Assumption?
How does this affect the interpretation of results from
Prolog?
38. List Processing
[Head | Tail] works like "car" and "cdr" in Scheme.
Example:
?- [H | T ] = [a,b,c,d,e].
returns:
H = a
T = [b,c,d,e]
This can be used to build lists and decompose lists.
Can use [H|T] on the left side to de/construct a list:
path(X, Y, [X|P]) :-
edge(X, Node),
path(Node, Y, P).
39. member Predicate
Test whether something is a member of a list
?- member(a, [b,c,d]).
No.
can be used to have Prolog try all values of a list as
values of a variable.
?- member(X, [a1,b2,c3,d4] ).
X = a1
X = b2
X = c3
40. member Predicate example
Use member to try all values of a list.
Useful for problems like
Queen safety
enumerating possible rows and columns in a game.
% dumb function to find square root of 9
squareroot9(N) :-
member(N,[1,2,3,4,5,5,6,7,8,9]),
9 is N*N.
41. appending Lists
?- append([a,b],[c,d,e],L).
L = [a,b,c,d,e]
append can resolve other parameters, too:
?- append(X, [b,c,d], [a,b,c,d] ).
X = a
?- append([],[a,b,c],L).
L = [a,b,c]
42. Defining your own 'append'
append([], List, List).
append([Head|Tail], X, [Head|NewTail]) :-
append(Tail, X, NewTail).
43. Type Determination
Prolog is a weakly typed language.
It provides propositions for testing the type of a variable
PREDICATE SATISFIED (TRUE) IF
var(X) X is a variable
nonvar(X) X is not a variable
atom(A) A is an atom
integer(K) K is an integer
real(R) R is a floating point number
number(N) N is an integer or real
atomic(A) A is an atom or a number or a string
functor(T,F,A) T is a term with functor F, arity A
T =..L T is a term, L is a list.
clause(H,T) H :- T is a rule in the program
45. Solution Process
Stack Substitution (Instantiation)
[path(a,c), path(X,X)]
[path(a,c), path(a,a)] X = a
Undo.
[path(a,c), path(X,X)]
[path(a,c), path(c,c)] X = c
Undo.
(1) path(X,X).
(2) path(X,Y) := edge(X,Z), path(Z,Y).
?- path(a,c).
46. Solution Process (2)
Stack Substitution (Instantiation)
[path(a,c), path(X,Y)] (Rule 2)
[path(a,c), path(a,Y)] X = a
X = a, Y = c
edge(a,Z), path(Z,c) new subgoals
edge(a,b), path(b,c) X = a, Y = c, Z = b
path(b,c) edge(a,b) is a fact - pop it.
(1) path(X,X).
(2) path(X,Y) := edge(X,Z), path(Z,Y).
?- path(a,c).
47. What does this do?
% what does this do?
sub([], List).
sub([H|T], List) :-
member(H, List),
sub(T, List).
48. What does this do?
% what does this do?
foo([], _, []).
foo([H|T], List, [H|P]) :-
member(H, List),
foo(T, List, P).
foo([H|T], List, P) :-
not( member(H, List) ),
foo(T, List, P).
Underscore (_) means "don't care".
It accepts any value.
49. Max Function
Write a Prolog program to find the max of a list of
numbers:
max( List, X).
max( [3, 5, 8, -4, 6], X).
X = 8.
Strategy:
use recursion
divide the list into a Head and Tail.
compare X to Head and Tail. Two cases:
Head = max( Tail ). in this case answer is X is Head.
X = max( Tail ) and Head < X.
what is the base case?
50. Max Function
% max(List, X) : X is max of List members
max([X], X). base case
max([H|Tail], H) :- 1st element is max
max(Tail, X),
H >= X.
max([H|Tail], X) :- 1st element not max
complete this
case.
51. Towers of Hanoi
% Move one disk
move(1,From,To,_) :-
write('Move top disk from '),
write(From),
write(' to '),
write(To),
nl.
% Move more than one disk.
move(N,From,To,Other) :-
N>1,
M is N-1,
move(M,From,Other,To),
move(1,From,To,_),
move(M,Other,To,From).
See tutorials at:
www.csupomona.edu and
www.cse.ucsc.edu
52. Learning Prolog
The Textbook - good explanation of concepts
Tutorials:
http://www.thefreecountry.com/documentation/onlineprolog.sht
ml has annotated links to tutorials.
http://www.cse.ucsc.edu/classes/cmps112/Spring03/languages
/prolog/PrologIntro.pdf last section explains how Prolog
resolves queries using a stack and list of substitutions.
http://cs.wwc.edu/~cs_dept/KU/PR/Prolog.html explains
Prolog syntax and semantics.
http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/conte
nts.html has many examples