This document discusses negation in Prolog. It begins by explaining how to use the not operator to avoid wrong answers when replacing cuts, and gives an example using not for inequality checks. It then discusses negation as failure in Prolog, and how the closed world assumption can lead to surprises. It provides examples and advice on the safe use of negation, and explains that double negation does not cancel out in Prolog. It also introduces the fail predicate and shows how it can be used to define falsehoods and represent exceptions. Throughout it traces examples to illustrate Prolog's behavior with negation.
1. The function f(x) is defined as 2 + x^2 and g(x) is defined as 1 + x^2.
2. It is given that f(g(x)) = 3 + 2(g(x) - 1) + (g(x) - 1)^2.
3. Substituting g(x) = 1 + x^2 into the equation for f(g(x)) yields f(x) = 2 + x^2.
The document discusses a joint work between Georg Gottlob from the Computing Laboratory at the University of Oxford's Department of Computer Science and G. Orsi and A. Pieris. It presents formal logic rules and models, including intensional databases, Datalog rules, and least Herbrand models. It also contains questions regarding these logical expressions.
Cálculo II - Aula 3: Integração por parteswillianv
The document presents the derivation of the integration by parts formula. It shows that the formula can be derived by taking the derivative of the product of two functions f(x) and g(x), and then integrating both sides. This results in the integration by parts formula: the integral of f(x)g(x)dx is equal to f(x)g(x) - the integral of f'(x)g(x)dx. An example is then given of using integration by parts to calculate the integral of xcosxdx.
1) Ontology-based data access (OBDA) combines databases with ontologies to enable advanced querying capabilities by answering queries over the database combined with ontological constraints.
2) The chase procedure is commonly used to answer queries in OBDA by expanding the database according to the constraints, but the chase may be infinite even for simple constraints.
3) The bounded derivation depth property ensures queries can still be answered exactly when the chase is infinite, by computing a finite initial fragment of the chase. When this property holds, the constraints also enjoy first-order rewritability.
Neljä askelta innovaatioon: Opas pienille yrityksillePäivi Eriksson
Haluatko ymmärtää asiakkaitasi entistä paremmin? Haluatko kehittää liiketoimintaasi? Haluatko tehdä yrityksestäsi innovatiivisen? Lue tämä opas ja sovella sen oppeja omassa toiminnassasi.
1. The function f(x) is defined as 2 + x^2 and g(x) is defined as 1 + x^2.
2. It is given that f(g(x)) = 3 + 2(g(x) - 1) + (g(x) - 1)^2.
3. Substituting g(x) = 1 + x^2 into the equation for f(g(x)) yields f(x) = 2 + x^2.
The document discusses a joint work between Georg Gottlob from the Computing Laboratory at the University of Oxford's Department of Computer Science and G. Orsi and A. Pieris. It presents formal logic rules and models, including intensional databases, Datalog rules, and least Herbrand models. It also contains questions regarding these logical expressions.
Cálculo II - Aula 3: Integração por parteswillianv
The document presents the derivation of the integration by parts formula. It shows that the formula can be derived by taking the derivative of the product of two functions f(x) and g(x), and then integrating both sides. This results in the integration by parts formula: the integral of f(x)g(x)dx is equal to f(x)g(x) - the integral of f'(x)g(x)dx. An example is then given of using integration by parts to calculate the integral of xcosxdx.
1) Ontology-based data access (OBDA) combines databases with ontologies to enable advanced querying capabilities by answering queries over the database combined with ontological constraints.
2) The chase procedure is commonly used to answer queries in OBDA by expanding the database according to the constraints, but the chase may be infinite even for simple constraints.
3) The bounded derivation depth property ensures queries can still be answered exactly when the chase is infinite, by computing a finite initial fragment of the chase. When this property holds, the constraints also enjoy first-order rewritability.
Neljä askelta innovaatioon: Opas pienille yrityksillePäivi Eriksson
Haluatko ymmärtää asiakkaitasi entistä paremmin? Haluatko kehittää liiketoimintaasi? Haluatko tehdä yrityksestäsi innovatiivisen? Lue tämä opas ja sovella sen oppeja omassa toiminnassasi.
The document discusses backtracking, which is a technique for solving constraint satisfaction problems using three basic colors (R, G, B) to color graphs without conflicts. It provides rules for using only three colors with no conflicts and describes the backtracking approach. It then provides four practice graph coloring problems to solve using backtracking.
1) A young monkey named Tyler Coconut goes to the Jungle King restaurant and eats an excessive amount of food including a triple banana burger, coconut fries, and a banana shake. The next day, he eats even more food at another restaurant and becomes too full to eat for a week.
2) Katy Banana is a very picky eater who refuses to eat liver. Her parents trick her into eating liver by hiding it inside a banana. However, once Katy discovers it is liver, she becomes ill all night and refuses to eat dinner again.
3) The Monkey Tails blog provides stories, news, and information for monkeys online and through their website.
1) A young monkey named Tyler Coconut goes to the Jungle King restaurant and eats an excessive amount of food including a triple banana burger, coconut fries, and a banana shake. The next day, he eats even more food at another restaurant and becomes too full to eat for a week.
2) Katy Banana is a very picky eater who refuses to eat liver. Her parents trick her into eating liver by hiding it inside a banana. However, once Katy discovers it is liver, she becomes ill all night and refuses to eat dinner again.
3) The Monkey Tails blog provides stories, news, and information for monkeys online and through their website.
The document describes the backtracking method for solving problems that require finding optimal solutions. Backtracking involves building a solution one component at a time and using bounding functions to prune partial solutions that cannot lead to an optimal solution. It then provides examples of applying backtracking to solve the 8 queens problem by placing queens on a chessboard with no attacks. The general backtracking method and a recursive backtracking algorithm are also outlined.
The document presents a logic puzzle about a monkey trying to reach bananas hung from the ceiling. It describes the problem setup, with a monkey and bananas in a room, along with a chair. It then provides the logical representation of the problem using predicates and axioms. The goal is to use resolution logic to prove that the monkey can reach the bananas by placing the chair below them and climbing on top of it. Through a series of resolvents applying the given information, it is shown that the monkey can indeed reach the bananas.
The document discusses solving the 8 queens problem using backtracking. It begins by explaining backtracking as an algorithm that builds partial candidates for solutions incrementally and abandons any partial candidate that cannot be completed to a valid solution. It then provides more details on the 8 queens problem itself - the goal is to place 8 queens on a chessboard so that no two queens attack each other. Backtracking is well-suited for solving this problem by attempting to place queens one by one and backtracking when an invalid placement is found.
The document discusses cuts and negation in Prolog. It explains that a cut (!) allows for controlling backtracking by committing to choices made before it. Negation as failure uses fail/0 to force backtracking and, combined with a cut, can write programs to capture negation. For example, a rule saying p holds if a and b, or if not a and c, can be written as p :- a,!,b and p :- c.
Prolog is a logic programming language used for artificial intelligence and computational linguistics. It is declarative and logic is expressed through relations represented as facts and rules. A Prolog program consists of clauses that define relations, either facts with no body or rules with a head and body. Execution is initiated by a query, which tries to find a resolution refutation by using SLD resolution. Examples demonstrate writing to output, relations between family members, and an implementation of quicksort.
This document discusses various problems that can be solved using backtracking, including graph coloring, the Hamiltonian cycle problem, the subset sum problem, the n-queen problem, and map coloring. It provides examples of how backtracking works by constructing partial solutions and evaluating them to find valid solutions or determine dead ends. Key terms like state-space trees and promising vs non-promising states are introduced. Specific examples are given for problems like placing 4 queens on a chessboard and coloring a map of Australia.
This document provides an overview of logic programming and the logic programming language Prolog. It discusses declarative programming and how Prolog uses declarative rules, facts, and predicates. It explains how Prolog performs logical operations like unification and resolution to evaluate queries against its knowledge base. It provides examples of using Prolog to represent graphs, lists, arithmetic, and more.
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.
The cut (!) in Prolog allows for more direct control over backtracking by preventing it from certain points. It is used to ensure that a clause is fully executed before trying alternatives. For example, a cut used in the second clause of p(X) means only the first matching clause is tried, cutting off the other alternatives. Negation as failure uses cut and fail together to express negation, allowing a goal to succeed if another fails. The order of goals matters in Prolog as it tries to satisfy them sequentially from left to right.
Artificial intelligence (AI) refers to computer systems capable of performing complex tasks that historically only a human could do, such as reasoning, making decisions, or solving problems.In summary, the goal of AI is to provide software that can reason on input and explain on output. AI will provide human-like interactions with software and offer decision support for specific tasks, but it's not a replacement for humans – and won't be anytime soon
The document discusses cuts and negation in Prolog. It explains that the cut (!) operator controls backtracking by committing to choices made before it. Negation as failure allows defining predicates based on the failure of other predicates, using the fail operator combined with cut. Examples show how cut and negation as failure can be used to define preferences and conditions.
This document provides an overview of the Prolog programming language. It begins with an outline of the topics that will be covered, including syntax of terms, simple programs, terms as data structures, the cut operator, and writing real programs. It then defines Prolog as a logic programming language that uses logical variables and unification. The rest of the document explains key aspects of Prolog like clauses, facts, rules, queries, compound terms, and unification through examples. It also discusses how Prolog programs are executed and how clauses can be read both declaratively and procedurally.
Scala has many symbols, operators, and syntax elements that can be confusing for beginners. The underscore character in particular takes on many different meanings depending on context. Type erasure in Scala means that types are not always available at runtime. Initialization order of vals follows a defined rule where traits are initialized before subclasses. Having a deep understanding of Scala's semantics is important to explain unexpected behavior.
This document describes the solutions and questions for a midterm exam in 6.036: Spring 2018. It provides instructions for taking the exam such as writing your name on each page and coming to the front to ask questions. The exam consists of 6 multiple choice questions worth a total of 100 points. Question 1 involves linear classification and calculating margins. Question 2 asks about sources of error in machine learning models. Question 3 involves choosing appropriate representations and loss functions for different prediction problems. Question 4 introduces radial basis features for nonlinear classification. Question 5 discusses shortcut connections in neural networks.
This document provides an introduction to Prolog programming through examples of syllogisms and modeling logic problems. It discusses SWI-Prolog, facts and rules, queries, variables, structures, predicates, programs, and modeling change. Key concepts are summarized such as backward chaining, cuts, dynamic facts, and modeling "real life" problems through games and adventure programs. The document uses a dragon adventure game to demonstrate Prolog programming concepts in action.
Query Rewriting and Optimization for Ontological DatabasesGiorgio Orsi
Ontological queries are evaluated against a knowledge base consisting of an extensional database and an ontology (i.e., a set of logical assertions and constraints that derive new intensional knowledge from the extensional database), rather than directly on the extensional database. The evaluation and optimization of such queries is an intriguing new problem for database research. In this article, we discuss two important aspects of this problem: query rewriting and query optimization. Query rewriting consists of the compilation
of an ontological query into an equivalent first-order query against the underlying extensional database.
We present a novel query rewriting algorithm for rather general types of ontological constraints that is well suited for practical implementations. In particular, we show how a conjunctive query against a knowledge base, expressed using linear and sticky existential rules, that is, members of the recently introduced Datalog+/- family of ontology languages, can be compiled into a union of conjunctive queries (UCQ) against the underlying database. Ontological query optimization, in this context, attempts to improve this rewriting process soas to produce possibly small and cost-effective UCQ rewritings for an input query.
Abstract : For many years, Machine Learning has focused on a key issue: the design of input features to solve prediction tasks. In this presentation, we show that many learning tasks from structured output prediction to zero-shot learning can benefit from an appropriate design of output features, broadening the scope of regression. As an illustration, I will briefly review different examples and recent results obtained in my team.
Following a game show format made popular by Joshua Bloch and Neal Gafter's Java Puzzlers this presentation intends to both entertain and inform. Snippets of Python code the whose behaviour is not entirely obvious are shown, the audience will then be asked to pick from a number of options what the behaviour of the program is. The correct and sometimes non-intuitive answer will then be given along with a brief explanation of the idea the puzzle exposes. Only a modest working knowledge of the Python language is required to understand the puzzles, but the puzzles may also entertain the more experienced Python programmer.
I am Jayson L. I am a Signals and Systems Homework Expert at matlabassignmentexperts.com. I hold a Master's in Matlab, from the University of Sheffield. I have been helping students with their homework for the past 7 years. I solve homework related to Signals and Systems.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Signals and Systems homework.
The document discusses backtracking, which is a technique for solving constraint satisfaction problems using three basic colors (R, G, B) to color graphs without conflicts. It provides rules for using only three colors with no conflicts and describes the backtracking approach. It then provides four practice graph coloring problems to solve using backtracking.
1) A young monkey named Tyler Coconut goes to the Jungle King restaurant and eats an excessive amount of food including a triple banana burger, coconut fries, and a banana shake. The next day, he eats even more food at another restaurant and becomes too full to eat for a week.
2) Katy Banana is a very picky eater who refuses to eat liver. Her parents trick her into eating liver by hiding it inside a banana. However, once Katy discovers it is liver, she becomes ill all night and refuses to eat dinner again.
3) The Monkey Tails blog provides stories, news, and information for monkeys online and through their website.
1) A young monkey named Tyler Coconut goes to the Jungle King restaurant and eats an excessive amount of food including a triple banana burger, coconut fries, and a banana shake. The next day, he eats even more food at another restaurant and becomes too full to eat for a week.
2) Katy Banana is a very picky eater who refuses to eat liver. Her parents trick her into eating liver by hiding it inside a banana. However, once Katy discovers it is liver, she becomes ill all night and refuses to eat dinner again.
3) The Monkey Tails blog provides stories, news, and information for monkeys online and through their website.
The document describes the backtracking method for solving problems that require finding optimal solutions. Backtracking involves building a solution one component at a time and using bounding functions to prune partial solutions that cannot lead to an optimal solution. It then provides examples of applying backtracking to solve the 8 queens problem by placing queens on a chessboard with no attacks. The general backtracking method and a recursive backtracking algorithm are also outlined.
The document presents a logic puzzle about a monkey trying to reach bananas hung from the ceiling. It describes the problem setup, with a monkey and bananas in a room, along with a chair. It then provides the logical representation of the problem using predicates and axioms. The goal is to use resolution logic to prove that the monkey can reach the bananas by placing the chair below them and climbing on top of it. Through a series of resolvents applying the given information, it is shown that the monkey can indeed reach the bananas.
The document discusses solving the 8 queens problem using backtracking. It begins by explaining backtracking as an algorithm that builds partial candidates for solutions incrementally and abandons any partial candidate that cannot be completed to a valid solution. It then provides more details on the 8 queens problem itself - the goal is to place 8 queens on a chessboard so that no two queens attack each other. Backtracking is well-suited for solving this problem by attempting to place queens one by one and backtracking when an invalid placement is found.
The document discusses cuts and negation in Prolog. It explains that a cut (!) allows for controlling backtracking by committing to choices made before it. Negation as failure uses fail/0 to force backtracking and, combined with a cut, can write programs to capture negation. For example, a rule saying p holds if a and b, or if not a and c, can be written as p :- a,!,b and p :- c.
Prolog is a logic programming language used for artificial intelligence and computational linguistics. It is declarative and logic is expressed through relations represented as facts and rules. A Prolog program consists of clauses that define relations, either facts with no body or rules with a head and body. Execution is initiated by a query, which tries to find a resolution refutation by using SLD resolution. Examples demonstrate writing to output, relations between family members, and an implementation of quicksort.
This document discusses various problems that can be solved using backtracking, including graph coloring, the Hamiltonian cycle problem, the subset sum problem, the n-queen problem, and map coloring. It provides examples of how backtracking works by constructing partial solutions and evaluating them to find valid solutions or determine dead ends. Key terms like state-space trees and promising vs non-promising states are introduced. Specific examples are given for problems like placing 4 queens on a chessboard and coloring a map of Australia.
This document provides an overview of logic programming and the logic programming language Prolog. It discusses declarative programming and how Prolog uses declarative rules, facts, and predicates. It explains how Prolog performs logical operations like unification and resolution to evaluate queries against its knowledge base. It provides examples of using Prolog to represent graphs, lists, arithmetic, and more.
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.
The cut (!) in Prolog allows for more direct control over backtracking by preventing it from certain points. It is used to ensure that a clause is fully executed before trying alternatives. For example, a cut used in the second clause of p(X) means only the first matching clause is tried, cutting off the other alternatives. Negation as failure uses cut and fail together to express negation, allowing a goal to succeed if another fails. The order of goals matters in Prolog as it tries to satisfy them sequentially from left to right.
Artificial intelligence (AI) refers to computer systems capable of performing complex tasks that historically only a human could do, such as reasoning, making decisions, or solving problems.In summary, the goal of AI is to provide software that can reason on input and explain on output. AI will provide human-like interactions with software and offer decision support for specific tasks, but it's not a replacement for humans – and won't be anytime soon
The document discusses cuts and negation in Prolog. It explains that the cut (!) operator controls backtracking by committing to choices made before it. Negation as failure allows defining predicates based on the failure of other predicates, using the fail operator combined with cut. Examples show how cut and negation as failure can be used to define preferences and conditions.
This document provides an overview of the Prolog programming language. It begins with an outline of the topics that will be covered, including syntax of terms, simple programs, terms as data structures, the cut operator, and writing real programs. It then defines Prolog as a logic programming language that uses logical variables and unification. The rest of the document explains key aspects of Prolog like clauses, facts, rules, queries, compound terms, and unification through examples. It also discusses how Prolog programs are executed and how clauses can be read both declaratively and procedurally.
Scala has many symbols, operators, and syntax elements that can be confusing for beginners. The underscore character in particular takes on many different meanings depending on context. Type erasure in Scala means that types are not always available at runtime. Initialization order of vals follows a defined rule where traits are initialized before subclasses. Having a deep understanding of Scala's semantics is important to explain unexpected behavior.
This document describes the solutions and questions for a midterm exam in 6.036: Spring 2018. It provides instructions for taking the exam such as writing your name on each page and coming to the front to ask questions. The exam consists of 6 multiple choice questions worth a total of 100 points. Question 1 involves linear classification and calculating margins. Question 2 asks about sources of error in machine learning models. Question 3 involves choosing appropriate representations and loss functions for different prediction problems. Question 4 introduces radial basis features for nonlinear classification. Question 5 discusses shortcut connections in neural networks.
This document provides an introduction to Prolog programming through examples of syllogisms and modeling logic problems. It discusses SWI-Prolog, facts and rules, queries, variables, structures, predicates, programs, and modeling change. Key concepts are summarized such as backward chaining, cuts, dynamic facts, and modeling "real life" problems through games and adventure programs. The document uses a dragon adventure game to demonstrate Prolog programming concepts in action.
Query Rewriting and Optimization for Ontological DatabasesGiorgio Orsi
Ontological queries are evaluated against a knowledge base consisting of an extensional database and an ontology (i.e., a set of logical assertions and constraints that derive new intensional knowledge from the extensional database), rather than directly on the extensional database. The evaluation and optimization of such queries is an intriguing new problem for database research. In this article, we discuss two important aspects of this problem: query rewriting and query optimization. Query rewriting consists of the compilation
of an ontological query into an equivalent first-order query against the underlying extensional database.
We present a novel query rewriting algorithm for rather general types of ontological constraints that is well suited for practical implementations. In particular, we show how a conjunctive query against a knowledge base, expressed using linear and sticky existential rules, that is, members of the recently introduced Datalog+/- family of ontology languages, can be compiled into a union of conjunctive queries (UCQ) against the underlying database. Ontological query optimization, in this context, attempts to improve this rewriting process soas to produce possibly small and cost-effective UCQ rewritings for an input query.
Abstract : For many years, Machine Learning has focused on a key issue: the design of input features to solve prediction tasks. In this presentation, we show that many learning tasks from structured output prediction to zero-shot learning can benefit from an appropriate design of output features, broadening the scope of regression. As an illustration, I will briefly review different examples and recent results obtained in my team.
Following a game show format made popular by Joshua Bloch and Neal Gafter's Java Puzzlers this presentation intends to both entertain and inform. Snippets of Python code the whose behaviour is not entirely obvious are shown, the audience will then be asked to pick from a number of options what the behaviour of the program is. The correct and sometimes non-intuitive answer will then be given along with a brief explanation of the idea the puzzle exposes. Only a modest working knowledge of the Python language is required to understand the puzzles, but the puzzles may also entertain the more experienced Python programmer.
I am Jayson L. I am a Signals and Systems Homework Expert at matlabassignmentexperts.com. I hold a Master's in Matlab, from the University of Sheffield. I have been helping students with their homework for the past 7 years. I solve homework related to Signals and Systems.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Signals and Systems homework.
I am Kennedy, G. I am a Stochastic Processes Assignment Expert at excelhomeworkhelp.com. I hold a Ph.D. in Stochastic Processes, from Indiana, USA. I have been helping students with their homework for the past 7 years. I solve assignments related to Stochastic Processes. Visit excelhomeworkhelp.com or email info@excelhomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Stochastic Processes Assignments.
This document appears to be an exam for a course on machine learning or artificial intelligence. It contains instructions for taking the exam, which is closed book and does not allow calculators. It then lists 6 multiple choice or short answer questions worth various point values that assess knowledge of topics like linear separators, sources of error in machine learning models, designing neural network architectures, and radial basis feature transformations.
Introduction to Lisp. A survey of lisp's history, current incarnations and advanced features such as list comprehensions, macros and domain-specific-language [DSL] support.
Prolog Programming is a document about the Prolog programming language. It discusses key features of Prolog such as logical variables, unification, backtracking, defining procedures with clauses, and using Prolog as a relational database. It provides examples of Prolog code including simple programs involving terms, facts, and rules. It also covers syntax of Prolog terms and compound terms, and how Prolog interprets clauses both declaratively and procedurally.
This document summarizes built-in predicates in Prolog including:
- Utility goals like help and halt
- Loading and testing types of Prolog programs
- Arithmetic, equality, and database manipulation predicates
- Input/output predicates for writing, reading, and file handling
- Control predicates for negation, conjunction, disjunction
- Finding all solutions with findall, bagof, and setof
Structured regression for efficient object detectionzukun
This document summarizes research on structured regression for efficient object detection. It proposes framing object localization as a structured output regression problem rather than a classification problem. This involves learning a function that maps images directly to object bounding boxes. It describes using a structured support vector machine with joint image/box kernels and box overlap loss to learn this mapping from training data. The document also outlines techniques for efficiently solving the resulting argmax problem using branch-and-bound optimization and discusses extensions to other tasks like image segmentation.
The document summarizes Prolog, a logic programming language. It provides an introduction to Prolog including that it is declarative and based on logic programming. It describes the basic components of Prolog programs including facts and rules. It also covers topics like variables, lists, recursion, and solving problems like merging lists and Sudoku puzzles using Prolog. Advanced topics discussed include structure inspection, meta-logical predicates, cuts, and extra-logical predicates.
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...APNIC
Adli Wahid, Senior Internet Security Specialist at APNIC, delivered a presentation titled 'Honeypots Unveiled: Proactive Defense Tactics for Cyber Security' at the Phoenix Summit held in Dhaka, Bangladesh from 23 to 24 May 2024.
Securing BGP: Operational Strategies and Best Practices for Network Defenders...APNIC
Md. Zobair Khan,
Network Analyst and Technical Trainer at APNIC, presented 'Securing BGP: Operational Strategies and Best Practices for Network Defenders' at the Phoenix Summit held in Dhaka, Bangladesh from 23 to 24 May 2024.
HijackLoader Evolution: Interactive Process HollowingDonato Onofri
CrowdStrike researchers have identified a HijackLoader (aka IDAT Loader) sample that employs sophisticated evasion techniques to enhance the complexity of the threat. HijackLoader, an increasingly popular tool among adversaries for deploying additional payloads and tooling, continues to evolve as its developers experiment and enhance its capabilities.
In their analysis of a recent HijackLoader sample, CrowdStrike researchers discovered new techniques designed to increase the defense evasion capabilities of the loader. The malware developer used a standard process hollowing technique coupled with an additional trigger that was activated by the parent process writing to a pipe. This new approach, called "Interactive Process Hollowing", has the potential to make defense evasion stealthier.
1. Fall 2008 Prolog: Negation
The current topic: Prolog
! Introduction
! Object-oriented programming: Python
! Functional programming: Scheme
! Python GUI programming (Tkinter)
! Types and values
• Logic programming: Prolog
! Introduction
! Rules, unification, resolution, backtracking, lists.
! More lists, math, structures.
! More structures, trees, cut.
– Next up: Negation.
• Syntax and semantics
• Exceptions
1 Fall 2008 Prolog: Negation
Announcements
• Term Test 2 has been marked.
– Handed back at the end of class today.
– The deadline for submitting a re-mark request is the end of class, Friday
November 28th. Make sure you understand the posted solutions before
submitting a re-mark request.
– Average: 68.4%
2
Fall 2008 Prolog: Negation
Using not instead of cut to avoid wrong answers
• Prolog has a not operator, but its behaviour is more subtle than in other
languages.
• Example: Replacing a cut with not:
– With cut:
A :- B, !, C.
A :- D.
– With not:
A :- B, C.
A :- not(B), D.
• Observe that not can be more cumbersome than cut.
– repetitive if-then-else
3 Fall 2008 Prolog: Negation
Using not for inequality
• Example:
crispy(snap).
crispy(crackle).
crispy(pop).
breakfast(A,B,C) :- crispy(A), crispy(B), crispy(C).
?- breakfast(A,B,C).
A = snap
B = snap
C = snap ;
A = snap
B = snap
C = crackle ;
...
• But we really want A, B, and C to be different from each other.
4
2. Fall 2008 Prolog: Negation
Using not for inequality
crispy(snap).
crispy(crackle).
crispy(pop).
breakfast(A,B,C) :- crispy(A), crispy(B), crispy(C), not(A=B),
not(A=C), not(B=C).
?- breakfast(A,B,C).
A = snap
B = crackle
C = pop ;
A = snap
B = pop
C = crackle ;
...
5 Fall 2008 Prolog: Negation
Negation in Prolog
• not(B) can also be written as + B.
– And not(X=Y) can also be written as X = Y.
• The goal + X succeeds iff X fails.
• Examples:
?- + member(b, [a,b,c]).
No
?- + member(x, [a,b,c]).
Yes
?- + member(X, [a,b,c]).
No
6
Fall 2008 Prolog: Negation
Negation in Prolog
?- + member(X, [a,b,c]).
No
• It might look like this query is asking "Does there exist an X for which
member(X, [a,b,c]) does not succeed?".
– We know there are lots of values of X for which member(X, [a,b,c]) does not
succeed.
– But that's not what negation means in Prolog.
– There exists X for which member(X, [a,b,c]) succeeds.
– So then + member(X, [a,b,c]) fails.
7 Fall 2008 Prolog: Negation
Negation as failure
• Prolog assumes that if it can't prove an assertion, then the assertion is
false.
– And Prolog assumes that if it can prove an assertion, then the assertion is true.
• This is the "closed world assumption": in the universe of facts Prolog
knows about, failure to prove is proof of failure.
– But if we know something Prolog doesn't, this can lead to surprises: things that
Prolog thinks are false when we know they're true, and the opposite.
– Example:
university(uoft).
?- university(york).
No
?- + university(york).
Yes
8
3. Fall 2008 Prolog: Negation
?- sad(michael).
No
?- sad(jim).
Yes
?- sad(Someone).
No
• Isn't anyone sad?
• No, that just means that it's
not true we can't find anyone
happy.
– In other words, there exists
someone who is happy.
Be careful with negation
sad(X) :- + happy(X).
happy(X) :- beautiful(X), rich(X).
rich(bill).
beautiful(michael).
rich(michael).
beautiful(cinderella).
?- sad(bill).
Yes
?- sad(cinderella).
Yes
9 Fall 2008 Prolog: Negation
Tracing negation
• Let's look at how Prolog answers sad(Someone).:
?- sad(Someone).
Call: (7) sad(_G283) ? creep
Call: (8) happy(_G283) ? creep
Call: (9) beautiful(_G283) ? creep
Exit: (9) beautiful(michael) ? creep
Call: (9) rich(michael) ? creep
Exit: (9) rich(michael) ? creep
Exit: (8) happy(michael) ? creep
Fail: (7) sad(_G283) ? creep
No
10
Fall 2008 Prolog: Negation
Set overlap
• Write a predicate overlap(S1, S2) that succeeds if lists S1 and S2
have a common element. Then write a predicate disjoint(S1, S2)
that succeeds if S1 and S2 have no common element.
overlap(S1, S2) :- member(X, S1), member(X, S2).
disjoint(S1, S2) :- + overlap(S1, S2).
?- overlap([a,b,c], [c,d,e]).
Yes
?- disjoint([a,b,c], [c,d,e]).
No
?- overlap([a,b,c], [d,e,f]).
No
?- disjoint([a,b,c], [d,e,f]).
Yes
?- disjoint([a,b,d], S).
No
11 Fall 2008 Prolog: Negation
What does that mean?
?- disjoint([a,b,d], S).
No
• The query should mean "can you find a list S that is disjoint from the list
[a,b,d] (and if so what is it)?".
• Obviously there are many such sets, so why "No"?
• Answer: because Prolog succeeded in finding a set that did overlap with
S, so it announced failure of the original query.
?- overlap([a,b,d], S).
S = [a|_G226] ;
S = [_G225, a|_G229] ;
S = [_G225, _G228, a|_G232] ;
...
12
4. Fall 2008 Prolog: Negation
Safe use of negation
• The goal not(G) is safe if either:
– G is fully instantiated when not(G) is processed, or
– G has uninstantiated variables, but they don't appear anywhere else in the clause.
• Safe example:
childlessMan(X) :- male(X), + parent(X,Y).
– X is instantiated in male(X), and Y isn't used elsewhere.
• Unsafe example:
childlessMan(X) :- + parent(X,Y), male(X).
– X is not instantiated before the negation, and is used elsewhere.
• If necessary, add a precondition to warn the programmer.
– recall that +Var means that Var must be instantiated.
% disjoint(+S1, +S2) succeeds if...
disjoint(S1, S2) :- + overlap(S1, S2).
– When the precondition is satisfied, this negation is safe.
13 Fall 2008 Prolog: Negation
Double-negation doesn't "cancel out"
• In other languages, not(not(<expression>)) is equivalent to
<expression>.
– But not in Prolog.
?- member(X,[a,b,c]).
X = a ;
X = b ;
X = c ;
No
?- not(not(member(X,[a,b,c]))).
X = _G166 ;
No
14
Fall 2008 Prolog: Negation
Double-negation doesn't "cancel out"
?- not(not(member(X,[a,b,c]))).
X = _G166 ;
No
• Why is X uninstantiated in this example?
– Since member(X, [a,b,c]) succeeds (by instantiating X to, say, a),
not(member(X, [a,b,c])) fails.
– When a goal fails, the variables it instantiated get uninstantiated. So X gets
uninstantiated.
– But since not(member(X, [a,b,c])) fails, not(not(member(X,
[a,b,c]))) succeeds.
15 Fall 2008 Prolog: Negation
fail
• The fail predicate fails immediately. Example:
p(X) :- fail.
?- p(csc326).
No
• We can use fail to state that something is false.
16
5. Fall 2008 Prolog: Negation
fail
• Example: We want to represent "Colbert does not like bears (regardless
of whatever else he likes)."
– One solution: Add "not(bear(X))" to every rule describing what Colbert likes.
For example:
likes(colbert, X) :- animal(X), not(bear(X)).
likes(colbert, X) :- toy(X), not(bear(X)).
likes(colbert, X) :- livesInArctic(X), not(bear(X)).
...
– Let's try to use fail instead.
– First attempt:
bear(yogi).
animal(yogi).
likes(colbert, X) :- bear(X), fail.
likes(colbert, X) :- animal(X).
?- likes(colbert, yogi).
Yes
17 Fall 2008 Prolog: Negation
fail
• We need to add a cut to prevent other rules from being tried after the
first rule reaches fail.
– Second attempt:
bear(yogi).
cat(tom).
animal(yogi).
animal(tom).
likes(colbert, X) :- bear(X), !, fail.
likes(colbert, X) :- animal(X).
?- likes(colbert, yogi).
No
?- likes(colbert, tom).
Yes
?- likes(colbert, X).
No
– Downside: This solution only works when X is instantiated.
18
Fall 2008 Prolog: Negation
fail
• Another example: Define a predicate different(X, Y) that succeeds
if X and Y don't unify.
different(X, Y) :- X=Y, !, fail.
different(_, _).
?- different(a, b).
Yes
?- different(a, a).
No
• Notice that the above definition is equivalent to:
different(X, Y) :- not(X=Y).
19 Fall 2008 Prolog: Negation
Defining "not" using cut and fail
• We can define the not predicate as follows:
not(X) :- X, !, fail.
not(_).
• (To test this out, use a name other than "not", since Prolog won't let
you redefine the built-in "not").
20
7. Fall 2008 Prolog: Negation
fail
• What went wrong?
– fail only affects the present goal (bstmem(empty, 1) in the example).
– It does not directly cause the failure of a previous goal (so, in the example, Prolog
still looks for other rules for the goal bstmem(node(3,empty,empty), 1)).
25 Fall 2008 Prolog: Negation
Advice on writing Prolog
To minimize bugs, especially with cut and not:
• Use cut and not as necessary to avoid wrong answers.
• Follow the rules for safe use of not.
• Follow the rules for doing arithmetic.
• Always use ";" when testing to check all possible answers.
– It's easy to get first answer right and rest wrong if "else" misused.
• Test with variables in every combination of positions.
• Use preconditions to state where variables are disallowed.
• Use cut to avoid duplicate answers.
• Use cut where possible for efficiency.
• Use _ where possible for efficiency.
26
Fall 2008 Prolog: Negation
Summary: logic programming and Prolog
• Logic programming:
– Unification, resolution, backtracking.
– Specify kind of result wanted (what you want), not how to get it.
• Prolog:
– The major logic programming language.
– Efficiency can be a worry:
• cut
• ordering the predicates
27 Fall 2008 Prolog: Negation
Bubble sort
• Write a predicate bsort(+Before, ?After) that succeeds if After is
a sorted version of Before. bsort should use bubble sort to sort the list.
bsort(Before, After) :- bsortaux(Before, [], After).
• Helper predicate bsortaux(+Prelower, +Preupper, ?Sorted)
succeeds if Sorted is a list that consists of a sorted version of
Prelower followed by (an unchanged) Preupper.
bsortaux([], Preupper, Preupper) :- !.
bsortaux(Prelower, Preupper, Sorted) :-
bubble(Prelower, Preupper, Postlower, Postupper),
bsortaux(Postlower, Postupper, Sorted).
28
9. Fall 2008 Prolog: Negation
Exercises
• Fix the sibling predicate (that we previously defined) so that it doesn't
consider a person to be there own sibling. Then make sure that this fix
has eliminated any unusual behaviour in the aunt, uncle, nephew, and
niece predicates that you defined in a previous set of exercises.
• Trace bsort on more interesting (and larger) examples. For example,
trace the call:
bsort([1,5,2,6,3,4], S).
• Challenge: Recall that the efficiency of bubble sort can be improved by
halting after the first iteration during which no swaps are performed (we
can halt at that point since if no swaps are performed, the list must be
already sorted). Modify bsort by adding this improvement.
33