Giter Club home page Giter Club logo

prolog_for_noobs's Introduction

prolog_for_noobs

Some very basic concepts and codes for prolog language!

About Prolog

Prolog, derived from the French for Programming in Logic, is a Declarative programming language, especially seen in the field of Artificial Intelligence(AI). The language is declarative, in the sense that it handles the working of logic all by itself for finding the answers to logical questions/queries, once it is given some facts and rules determining the working of the logic.

Some basic concepts and syntaxes

Prolog scripts/queries basically are consisted of the following three entities:

  • Atoms and numbers: Atoms are entities which are named such that they begin with a small letter only. They can also be represented by names surrounded by single quotes ' '. Numbers represent any real floating point number.

    % Examples of atoms
    % tony
    % child
    % 'Joker' % Notice the atom surrounded by ' '
    % doesHomeWork
    % goesShopping
    % 'likesToEat'
    % 'action(percepts)'
  • Variables: Variables are entities capable of binding to (say, storing) any atom or number. They must be named so that the names begin with either a capital letter or the underscore _ character.

    % Examples of variables
    % _ % This is the 'anonymous variable'
    % X
    % Y
    % Tony
    % _child
    % _80days
    % Lives9
    
  • Complex Terms: Complex Terms can be thought of as a function which defines the relationship between one or more number of entities. The name of the complex term is known as functor. The number of arguments the functor takes is known as the arity of the functor/complex term. As such, the complex terms can also be represented as <name of the functor>/<arity of the functor>.

    The functors with different arities are treated as distinct functors.

    % Example of complex terms
    % sour(grapes) % represented as sour/1
    % likes(charlie, chocolate) % represented as likes/2
    % makes(wonka, chocolate) % represented as makes/2
    % makes(elon, cars, cybertruk) % represented as makes/3
    % runs(deer, cheetah, human) % represented as runs/3

In a prolog script, every statement either consists of a fact, or a rule, terminated by ..

% the statement below denotes a fact.
man(socrates). % Read as socrates is a man.

% the statement below denotes a rule.
mortal(X) :- man(X). % Read as 'X' is mortal if 'X' is a man.

When querying the above script, the following output could be obtained

?- mortal(socrates).
true.

The prolog interactive replies to queries by either yes/true, no/false, or a list of matching values/atoms.

Contents of the repo

  1. Logic
  2. Variables
  3. Facts and Rules
  4. Conjunctions(AND)
  5. Disjunctions(OR)
  6. Anonymous variables
  7. Transitive Logic Example

How to run the codes

  • Navigate to /codes directory.

  • Launch prolog console.

  • Type the name of the file you want to run queries on without the extension in [ ].

    1 ?- [logic0].
    true.
  • If the console returns true, you are all set!

prolog_for_noobs's People

Contributors

royarg02 avatar f0rkb0mbz avatar arig23498 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

prolog_for_noobs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.