Vous êtes sur la page 1sur 44

Advance Programming Language Concepts

Abstract
This documentation will discuss about the two applications. The first application is detecting
Steganography (hidden messages) in images and implemented by using Haskell. To design and
implement of all image processing steps and detection processes use the features of functional
programming and provide the ability of reusability and future enhancement.
The other application is providing details of the Solar system using prolog programming language.
The concepts and features of logical programming languages are used to design and implement
that application.

Advance Programming Language Concepts


Table of Contents
Abstract.............................................................................................................................1
List of Figures ..................................................................................................................3
1 Functional Programming.................................................................................................5
1.1 Introduction...............................................................................................................5
1.2. Scope.....................................................................................................................5
1.3 Assumptions.............................................................................................................6
1.4 Flow of the application.............................................................................................6
1.5 Functional Programming Features...........................................................................7
1.6 Screens..................................................................................................................13
1.7 Test Plans.............................................................................................................18
1.7 Source Code..........................................................................................................19
2 Logical Programming....................................................................................................31
2.1 Introduction.............................................................................................................31
2.2 Scope....................................................................................................................32
2.3 Assumptions..........................................................................................................32
2.4 Logical Programming Features..............................................................................33
Facts............................................................................................................................33

Advance Programming Language Concepts

List of Figures
Figure 1: Main Menu........................................................................................................14
Figure 2: Image Gallery...................................................................................................15
Figure 3: Select LSB Tool................................................................................................15
Figure 4: Detect Hidden Messages.................................................................................16
Figure 5: User Manual.....................................................................................................17
Figure 6: Exit....................................................................................................................17
Figure 7: Query 1.............................................................................................................40
Figure 8:: Query 2............................................................................................................40
Figure 9:Query 3..............................................................................................................40
Figure 10:Query 4............................................................................................................40
Figure 11;:Query 5...........................................................................................................41
Figure 12:Query 6............................................................................................................41
Figure 13:: Query 7..........................................................................................................41
Figure 14: Query 8...........................................................................................................41
Figure 15:Query 9............................................................................................................41
Figure 16:Query 10..........................................................................................................42
Figure 17:Query 11..........................................................................................................42
Figure 18:Query 12..........................................................................................................42
Figure 19:Query 13..........................................................................................................42
Figure 20:Query 14..........................................................................................................42
3

Advance Programming Language Concepts


Figure 21::Query 16.........................................................................................................42
Figure 22:Query 17..........................................................................................................43
Figure 23:Query 19..........................................................................................................43
Figure 24:Query 20..........................................................................................................43
Figure 25:Query21...........................................................................................................43
Figure 26:Query22...........................................................................................................43

Advance Programming Language Concepts

1 Functional Programming
1.1 Introduction

The functional programming paradigms are purely based on mathematical discipline. Collection of
functions made up the whole program. Also not like the imperative programming languages, those
are avoided the side effects.
In this application detect the hidden massages inside the images using Haskell functions. It holds
the five images with the hidden messages. To represent the images use the concept of pixels. Each
pixel includes the binary value of R G B colors. Likewise hold the several pixel data to represent
the images. Then provide the several Steganalysis tools to user to select one of the tools for the
detection process. Finally hidden message will be detecting according to the selected tool.
The following are the functional features that applied in this application.

Create user defined data type called Image to store images.

Store images as a list of triples.

ASCII values of each letter hold as integer (binary) values.

Therefore words are representing in a list of integer values.

Use pure functions to each step.

Use higher order functions to combine useful pure functions.

Use IO programs to provide the sequence of the application.

Divide the application in to several modules to increase the readability and allow for future
enhancement.

1.2. Scope

Users only be able to use the images that listed in the application.
5

Advance Programming Language Concepts

Only can use the characters of A-J of the alphabet.

Users only be able to use the Steganalysis LSB tools which listed in the application.

1.3 Assumptions

Images are including with the hidden messages.

Messages will only contain the letters up to J.

The stated ASCII values are same as the Unicode character values.

Every pixels LSB of R, G, B holds the secret message.

Messages are hidden from the beginning to the end continuously in the image.

1.4 Flow of the application

2. Create user defined data type called as Image to store images.


6

Advance Programming Language Concepts


3. Define ASCII values for characters.
4. User will be able to select an image among the list of images.
5. Then separate the R, G, B color values of selected image.
6. Then require selecting a Steganalysis LSB tool.
7. According to the selected tool, take only the list of values of the corresponding color.
8. Then split out the all values and get as the one value (in to one list).
9. Filter the LSB values in to a separate list from the splitted list.
10. Then combine separated filtered value into group of five elements (size of the one character).
11. Then check whether those values are valid ASCII codes according to the given character
ASCII codes.
12. After checking the validness of the ASCII values, convert that values into its corresponding
characters.
13. Then display the hidden message.
14. In this application provide user manual instructions to avoid the user confusion. It explains step
by step how to execute the application.
15. Finally terminate the program.

1.5

Functional Programming Features

User define data types


Name

Type

Usage
7

Advance Programming Language Concepts

Image

[(Int, Int, Int)]

Store the images.

Pure functions
Function

Type

Usage
Separate the R, G, B color values into

separateColors

Image ([Int],[Int],[Int])

separate lists.
[(Int, Int, Int)] ([Int],[Int],[Int])
Filter only the red color values.
(based on input value)

getRvalue

Int ([Int],[Int],[Int]) [Int]


([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[11100]
Filter only the green color values.

getGvalue

Int ([Int],[Int],[Int]) [Int]

([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[00110]
Filter only the green color values.

getBvalue

Int ([Int],[Int],[Int]) [Int]

([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[10100]
Split the individual values into a list.

splitValue

Int [Int]
11100 [1,1,1,0,0]

Advance Programming Language Concepts


Get the final bit value.
getLSB

[Int] [Int]
[10001,11110,11111] [1,0,1]

isElement

Checking that given element is

Int Bool

existing or not.
Converting the integer values into

binaryToChar

their corresponding characters.

Int Char

User defined higher order functions


Function

Type

Usage
Take the splitValue function (split
individual values) and the required
integer list as parameters and split all
the values in to one list.

splitValues

(Int [Int]) [Int] [Int]


[11111,10000,10101]

[1,1,1,1,0,0,0,1,0,1,0,1]
Take each 5th element from the splitted
list in to separate list. Get
getNth

(Int [Int] [Int]) Int

getAboveNth function and splitted list

[Int] [Int]

as inputs.
[1,1,1,1,1,0,0,0,0,0] [1,0]
9

Advance Programming Language Concepts


Check the combined values are related
checking

(Int Bool) [Int] [Int]

to the letters ASCII codes. Get


isElement function (check with
individual value) and list as inputs.

Built-in functions and higher order functions


Function

Type

Usage

map

(a b) [a] [b]

concatMap

(a [b]) [a] [b]

unzip3

[(a, b, c)] ([a], [b], [c])

Apply some action for all elements in


the list.

Same as the map and combine all


resulted values together.

Separate the triple into their individual


lists.
Take input value (integer value n) and

take

Int [a] [a]

a list and get the first n elements in to


another list.

drop

Int [a] [a]

concat

[[a]] [a]

Drop the elements until given (index)


number and place in a separate list.

Combine the list of list of value into


one list.

10

Advance Programming Language Concepts


Convert string type value into another

read

String a

show

a String

Convert any type value in to a string.

Type

Usage

type

Primitive recursion
Function

Take set of values according to given


index value.
getAboveNth

Int [Int] [Int]


3 [1,1,1,0,0,0,1,0,1] [1,1,1],[0,0,0],
[1,0,1]
Take the last bit value of every

getLSB

individual value.

[Int] [Int]

[11110,10001,11111] [0,1,1]
Creates the groups of splitted
elements.
First take the first five element
(character ASCII size) and then drop
groupSpliter

those values from the list and check

[Int] [Int]

for next five elements. Likewise it will


repeat the same process until list
become empty.
[1,1,0,1,1,1,0,0,1,0] [1,1,0,1,1],
[1,0,0,1,0]
11

Advance Programming Language Concepts


Check first combined value is related
to the letters ASCII codes. And then
checking

(Int Bool) [Int] [Int]

it will check for whole lists elements.


[11111,100001] 11111 = A
100001 = J

binaryToString

[Int] String

Check whether the first value is


related to some ASCII code and if
exists, display that character. This will
process until list become empty.
[11111,100001] 11111 = A
100001 = J
AJ

IO Functions
Name

Type

Usage

askUser

IO ()

Provide all the functionalities of input


output operations.

Modules
Name

Type

Usage

common

Common.hs

Keep all common pure functions,


higher order functions and primitive
recursion which required for this
12

Advance Programming Language Concepts

application.

images

Images.hs

Keep all images.

Keep all pure functions, higher order


steganalysis

Steganalysis.hs

functions and primitive recursion


which required for steganalysis section
(detecting section).
Keep the interface (main menu) with

main

Main.hs

IO functions to provide the sequence


of the program.

1.6

Screens

Main menu

13

Advance Programming Language Concepts

Figure 1: Main Menu

This is the main menu of this application. This will provide the ability to select an option at a time.

Image Gallery

14

Advance Programming Language Concepts

Figure 2: Image Gallery

Application will display the images after selecting option 1. User must require toselect an image to
run the application.

Select LSB Tool

Figure 3: Select LSB Tool

After selecting option 2, steganalysis LSB tools will be displayed. User must require selecting one
of the tools to detect the hidden message.
15

Advance Programming Language Concepts

Delete Hidden messages

Figure 4: Detect Hidden Messages

After selecting steganalysis LSB tool, application will be detect the hidden message and displays it.

User Manual

16

Advance Programming Language Concepts

Figure 5: User Manual

If select option 4, user will be able to see the instruction of the application.

Exit

Figure 6: Exit

Application will be terminated after completing all the processes.

17

Advance Programming Language Concepts

1.7 Test Plans

Test Case number

Expected output

Actual output

Main module

Application should display the Display the menu (Steganalysis


main menu.
If

user

software).

selects

option

1, Display the images with the menu

required to display all the name image gallery.


images.

Display the LSB tools.

If user selects option 2,


required to display all the LSB
Displays Successfully detected!!

detection tools.
If

user

selects

option

3,

required to display the hidden

message and shows the detected


message.

message.
Displays the software instructions
If

user

selects

required

to

option

display

4,
the

with

the

menu

name

instructions.

software instructions.
Terminate the application.
If

user

required

selects
to

terminate

application.

Image module

option

5,
the

(Therefore main module work


properly).

If user selects option 1, all the Displays all the images.


18

Advance Programming Language Concepts


images should be displayed.

(Therefore image module work


properly).

Common module

Application should be navigate Application is navigates properly.


correctly.

(Therefore functions which under


this modules work properly).

Steganalysis module

Application should be able to Displays the hidden message with


display the hidden message.

the message

of

Successfully

detected!!
(Therefore functions which under
this modules work properly).

1.7

Source Code

Main.hs
module Main where

19

Advance Programming Language Concepts


import Char
import Images
import Steganalysis
import Common

main=do askUser

askUser :: IO ()
askUser
= do putStrLn " "
putStrLn "(Detecting Steganography (hidden messages) in Images) "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "\t \t******************************"
putStrLn "\t \t** STEGANALYSIS SOFTWARE **"
putStrLn "\t \t**

**"

putStrLn "\t \t******************************"


putStrLn " "
putStrLn " "
putStrLn "\t \t [1] Select Image "
putStrLn " "
putStrLn "\t \t [2] Select LSB tool "
putStrLn " "
putStrLn "\t \t [3] Detect Hidden message "
putStrLn " "
putStrLn "\t \t [4] User Manual "
putStrLn " "
putStrLn "\t \t [5] Exit "
putStrLn " "

20

Advance Programming Language Concepts


putStrLn " "
putStrLn "\t \t Please enter your choice: "
choice1 <- getLine
putStrLn " "
do
if(choice1=="1")
then
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "\t \t******************************"
putStrLn "\t \t**

IMAGE GALLARY

putStrLn "\t \t**

**"

putStrLn "\t \t******************************"


putStrLn " "
putStrLn " "
putStrLn "\t \t [a] Image1 "
putStrLn " "
putStrLn "\t \t [b] Image2 "
putStrLn " "
putStrLn "\t \t [c] Image3 "
putStrLn " "
putStrLn "\t \t [d] Image4 "
putStrLn " "
putStrLn "\t \t [e] Image5 "
putStrLn " "
putStrLn " "
putStrLn "\t \t Please enter your choice: "

21

**"

Advance Programming Language Concepts


choice2 <- getLine
return choice2
putStrLn "Press any key to contiune "
var <- getLine
askUser
putStrLn " "

do

if(choice2=="a")
then
do let im = image1
--print im
return im
putStrLn " "

else if(choice2=="b")
then
do let im = image2
--print im
return im
putStrLn " "

else if(choice2=="c")
then
do let im = image3
--print im
return im
putStrLn " "

22

Advance Programming Language Concepts


else if(choice2=="d")
then
do let im = image4
--print im
return im
putStrLn " "

else
do let im = image5
--print im
return im
putStrLn " "

else if(choice1=="2")
then
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "Please select LSB Steganography Tool: "
putStrLn " "
putStrLn " "
putStrLn "\t \t [1] Stego one bit RED color "
putStrLn " "
putStrLn "\t \t [2] Stego one bit GREEN color "
putStrLn " "
putStrLn "\t \t [3] Stego one bit BLUE color "

23

Advance Programming Language Concepts


choice3 <- getLine
putStrLn "Press any key to contiune "
var <- getLine
askUser
putStrLn " "

do

if(choice3=="1")
then
do let get_red = getRvalue
--print get_red
return get_red
putStrLn" "

else if(choice3=="2")
then
do let get_green = getGvalue
--print get_green
return get_green
putStrLn" "
else

do let get_blue = getBvalue


--print get_blue
return get_blue
putStrLn" "

else if(choice1=="3")
then

24

Advance Programming Language Concepts


do putStrLn " "
let separate_colors = separateColors image1
let get_red = getRvalue 25 separate_colors
let split_values = splitValues splitValue get_red
--print split_values
let lsb = getNth getAboveNth 5 split_values
--print lsb
let combine = groupSpliter lsb
--print combine
let chk = checking isElement combine
--print chk
let binary_to_string = binaryToString chk
--print binary_to_string
putStrLn "Successfully detected!! "
putStr "Hidden message is:"
print binary_to_string
putStrLn " "
putStrLn "Press any key to contiune "
var <- getLine
askUser
putStrLn " "

else if(choice1=="4")
then
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "\t \t******************************"
putStrLn "\t \t**

INSTRUCTIONS

25

**"

Advance Programming Language Concepts


putStrLn "\t \t**

**"

putStrLn "\t \t******************************"


putStrLn " "
putStrLn " "
putStrLn "\t \t 1. First you need to select a image "
putStrLn " "
putStrLn "\t \t 2. Then select a LSB tool,which you like to apply for detection "
putStrLn " "
putStrLn "\t \t 3. After that software will be detect the hidden message for you (only if
exist)"
putStrLn " "
putStrLn "\t \t 4. You need to select option 5 to terminate the program "
putStrLn " "
putStr "\t \t 5. Make sure not to change the sequnce of the program.you have to obey the
instruction. "
putStrLn "otherwise software can be currpted."
putStrLn " "
putStrLn "Press any key to contiune "
var <- getLine
askUser
putStrLn " "

else
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " \t \t Thank you for using!!"
putStrLn " "

26

Advance Programming Language Concepts

images.hs
module Images where

type Image= [(Int,Int,Int)]

image1 :: Image
image2 :: Image
image3 :: Image
image4 :: Image
image5 :: Image

image1
=
(11011,10001,10011),

[(10001,10001,10101),(11000,10010,10000),(11100,10100,11110),(11110,10000,10100),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),

(11110,11010,10000),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(10001,11001,10001),
(10111,10001,11111),
(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),(11011,10001,10011),
(10001,11101,11111),
(10101,11101,10111),(10011,10011,10101),(11001,11001,10111),(11001,10001,10101),
(11001,10011,11101)]

image2
=
(11111,10111,11011),

[(11001,10001,10111),(11011,10001,10011),(11101,10111,11111),(10100,10100,11100),
(11111,10001,10011),(10001,10101,10011),(10010,10010,10100),(10001,11001,10001),

(10111,10001,11111),
(10001,10001,10101),(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),
(11011,10001,10011),

27

Advance Programming Language Concepts


(11011,10101,10001),(11111,10111,11011),(11111,10001,10101),(10001,10101,10011),
(10011,10011,10101),
(11001,11001,10111),(11001,10001,10101),(11001,10011,11101),(11001,11111,10101),
(11101,10101,11001)]

image3
=
(11001,10011,10001),

[(10011,10111,11111),(11110,10000,10100),(11111,10001,10011),(10101,11101,10111),
(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),(11010,10000,10010),

(10000,11100,11110),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(11111,11011,10001),
(10001,11101,11111),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),
(11111,11011,10001),
(10101,11001,10011),(10101,10111,11111),(11111,10111,11011),(11111,10001,10101),
(10111,11111,10001)]

image4
=
(10011,10111,11111),

[(10101,11101,10111),(10011,10011,10101),(10100,10100,11100),(11000,10010,10000),
(10101,11101,10111),(10010,10010,10100),(11000,11000,10110),(11001,10001,10101),

(11001,10011,11101),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),
(11111,11011,10001),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(10001,11001,10001),
(10111,10001,11111),
(11001,11001,10111),(11001,10001,10101),(11001,10011,11101),(11001,11111,10101),
(11101,10101,11001)]

image5
=
(10010,10010,10100),

[(11011,10101,10001),(11111,10111,11011),(11110,10000,10100),(10000,10100,10010),
(11111,10001,10101),(11110,10000,10010),(10100,11100,10110),(10100,10100,11100),

(11110,10110,11010),
(11011,10101,10001),(11111,10111,11011),(11111,10001,10101),(10001,10101,10011),
(10011,10011,10101),
(10011,10111,11111),(11111,10001,10101),(11111,10001,10011),(10101,11101,10111),
(11001,10011,10001),

28

Advance Programming Language Concepts


(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(11111,11011,10001),
(10001,11101,11111)]

common.hs
module Common where
splitValues ::(Int -> [Int])-> [Int] -> [Int]
splitValues f x = concatMap f x
splitValue :: Int -> [Int]
splitValue 0 = []
splitValue x = splitValue (x `div` 10) ++ [x `mod` 10]
getAboveNth:: Int -> [Int] -> [Int]
getAboveNth _ [] = []
getAboveNth n xs = head xs : getAboveNth n (drop n xs)
getNth :: (Int -> [Int] -> [Int]) -> Int -> [Int] -> [Int]
getNth f n = f n . drop (n-1)
getLSB :: [Int] -> [Int]
getLSB [] = []
getLSB (x:xs) = (x `mod` 2) : getLSB xs
groupSpliter ::[Int]->[Int]
groupSpliter []=[]
groupSpliter xs = toSingleNum (take 5 xs):(groupSpliter (drop 5 xs))
where toSingleNum ys = read $ concat $ map show ys
isElement :: Int -> Bool
isElement x | x==11111 || x==11110 || x==11101 || x==11011 || x==10111 || x==11100 || x==11001 || x==10011 ||
x==11000 || x==10001 = True
|otherwise

= False

checking :: (Int -> Bool) -> [Int] -> [Int]


checking a [] = []
checking f (x:xs)

29

Advance Programming Language Concepts


| f x = x : checking f xs
| otherwise = []
binaryToString :: [Int] -> String
binaryToString [] = []
binaryToString (x:xs) = (binaryToChar) x : binaryToString xs

binaryToChar :: Int -> Char


binaryToChar x | x == 11111 = 'A'
| x == 11110 = 'B'
| x == 11101 = 'C'
| x == 11011 = 'D'
| x == 10111 = 'E'
| x == 11100 = 'F'
| x == 11001 = 'G'
| x == 10011 = 'H'
| x == 11000 = 'I'
| x == 10001 = 'J'
|otherwise = ' '

Steganalysis.hs

module Steganalysis where


import Images
separateColors :: Image -> ([Int],[Int],[Int])
separateColors x = unzip3 x

getRvalue :: Int -> ([Int],[Int],[Int]) -> [Int]


getRvalue n (xs,_,_) = take n xs

30

Advance Programming Language Concepts


getGvalue :: Int -> ([Int],[Int],[Int]) -> [Int]
getGvalue n (_,ys,_) = take n ys

getBvalue :: Int -> ([Int],[Int],[Int]) -> [Int]


getBvalue n (_,_,zs) = take n zs

2 Logical Programming
2.1 Introduction

Logical paradigms are based on the basic facts and rules relations according to the problem
domain. Therefore those are seems less natural in more general areas of computation. Collection of
facts and rules are made up the whole program and required to generate queries to run the program.
This application is about the solar system. At the beginning, enter the basic details of the solar
system as facts in to the application. Then user will be able to ask questions about the solar system
using queries.
The following are the logical features that applied in this application.

Create different kind of facts, such as simple facts, facts with one argument, facts with two
arguments and facts with more arguments.
31

Advance Programming Language Concepts

Create conditional facts using rules.

Finally provide the answers according to related queries.

2.2 Scope

Due to large scale of the solar system, provide only planets details.

Facts and rules are containing only the basic details.

2.3 Assumptions

User will be generating queries according to the pre-defined details.

Entered details are based on true details.

32

Advance Programming Language Concepts

2.4 Logical Programming Features

Facts

Simple facts
Fact

Explanation

solar_system_is_elliptical_in_shape.

Solar system is elliptical in shape.

the_Sun_is_in_the_center_of_the_solar_system.

The Sun is in the center of the solar


system.

our_solar_system_is_always_in_motion.

Our solar system is always in motion.

the_Sun_is_the_biggest_object_in_our_solar_system.

The Sun is the biggest object in our solar


system.

solar_system_is_more_than_4_billion_years_old.

Solar system is more than 4 billion years


old.

33

Advance Programming Language Concepts

Facts with Arguments


Fact

explanation

planet(mercury).

Mercury is a planet.

planet(venus).

Venus is a planet.

planet(earth).

Earth is a planet.

planet(mars).

Mars is a planet.

planet(jupiter).

Jupiter is a planet.

Facts with two arguments


Fact

explanation

planet_of(mercury,solar_system).

Mercury is a planet of solar system.

similar(venus,earth).

Venus is similar to the earth.

calledAs(mars,red_planet).

Mars is called as red planet.

moons(fobos,dimos,mars).

fabos and dimos are the moons of mars.

Facts with more arguments


Fact

explanation

planets(mercury,venus,earth,mars,ju All those are planets.


piter,saturn,uranus,neptune,pluto).

Variables and Unification


Fact

explanation

brightest(sun,solar_system).

Sun is the brightest of the solar system.


34

Advance Programming Language Concepts


planet(1,mercury,days_88

planet(num,name,revolution around sun,revolution around

,days_59 ,no_natural_planets).

own,no of satellit)

Rules
Rule

explanation

If ,
high_temperature(sun).

high temperature in sun.

high_temperature(venus).

high temperature in venus.

high_temperature(jupiter).

high temperature in jupiter.

impossible_to_live(X):- high_temperature(X).

if high temperature (in some


planet), impossible to live.
if impossible to live, because of no

no_oxygen(X):- impossible_to_live(X).

no_water(X):-

oxygen.

no_oxygen(X).

if no oxygen, there is no water.

no_oxygen(X).
no_oxygen(X).
no_oxygen(X).

If,
temp_high(saturn).

high temperature in saturn.


35

Advance Programming Language Concepts


oxy_less(pluto).

no oxygen in pluto.

oxy_less(saturn).

no oxygen in Saturn.

wat_less(mars).

no water in mars.

wat_less(saturn).

no water in Saturn.

cant_live_in(Y):- temp_high(Y), oxy_less(Y), wat_less(Y). impossible to live in some planet


if, is high temperrature `and`, no
oxygen `and`, no water .
If,
high_temp(jupiter).

high temperature in jupiter.

high_temp(venus).

high temperature in venus.

oxy_no(mars).

no oxygen in jupiter.

oxy_no(jupiter).

no oxygen in venus.

wat_no(venus).

no water in venus.

wat_no(mars).

no water in mars.

impossible_to_live_in_planet(Z):- high_temp(Z); oxy_no(Z);

impossible to live in some planet

wat_no
(Z).

if, is high temperrature `or`


no oxygen `or` no water.

wat_no(Z).
wat_no(Z).

If,
bigger_than(earth,mercury).

earth is bigger than mercury.


36

Advance Programming Language Concepts


bigger_than(mercury,pluto).

mercury is bigger than pluto.

bigger_than(saturn,earth).

saturn is bigger than earth.

bigger_than(earth,pluto).

earth is bigger than pluto.

biggest(X,Y):- bigger_than(X,Z), bigger_than(Z,Y).

if x > z and z > y ---> x > y

smallest(Y,X):-

biggest

(X,Y). if x is biggest when compare to the


y, then y become the smallest.

biggest(X,Y).

If,
closer(sun,mercury).

mercury is closer to sun.

closer(mercury,venus).

venus is closer to mercury.

closer(venus,earth).

earth is closer to venus.

beyond(X,Y):- closer(X,A),closer(A,B),closer(B,Y).

if x >> y --> X,A,B,...Y

beyonds(X,Y):-closer(X,Z),closer(Z,Y).

if X > Z , Z > Y --> X > Y

can_see(X) :-

people can see x, if x must be a


planet

(X),

closer

(X,

planet(X),
planet(X),

Queries
37

earth).

planet and closer to the earth.

Advance Programming Language Concepts


Queries for simple facts
Queries

result

?-solar_system_is_elliptical_in_shape.

true.

?-the_Sun_is_in_the_center_of_the_solar_system.

true..

?-our_solar_system_is_always_in_motion.

true.

?-the_Sun_is_the_biggest_object_in_our_solar_system.

true.

?-solar_system_is_more_than_4_billion_years_old.

true.

Queries for Facts with Arguments


Queries

result

?-planet(mercury).

true.

?-planet(venus).

true.

?-planet(star).

false.

?-planet(astroid).

false.

Queries for Facts with two Arguments


Queries

result

?-planet_of(mercury,solar_system).

true.

?-similar(venus,earth).

true.

?-bigger(jupiter,mars).

false.

?-moons(fobos,dimos,saturn).

false.

Queries for Facts with more Arguments


Queries

result
38

Advance Programming Language Concepts


?-planets(mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).

true.

?-planets(mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,star).

false.

?-planets(astroid,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).

false.

?-planets(astroid,venus,earth,mars,satellite,saturn,uranus,neptune,pluto

false.

Queries for Variables and Unification


Queries

result

?- brightest(Who,solar_system).

Who = sun.

?- planet(1,Which_is_first,days_88 ,days_59 ,no_natural_planets).

Which_is_first

mercury.
?- planet(2,venus,Rev_around_sun,days_243,no_natural_planets).

Rev_around_sun

days_225.
?- planet(3,earth,year_1,Rev_around_own,one_natural_planets).

Rev_around_own

hrs_24.
?- planet(4,mars,year_2,hrs_25,Howmay_natural_planets).

Howmay_natural_planets
= two_natural_planets.

Queries for Rules


Queries

result

?- high_temperature(X).

sun; venus; jupiter

?- high_temperature(venus).

true.

?- impossible_to_live(pluto).

false.

?- impossible_to_live(X).

X = sun; x = venus; x = jupiter.

?- no_oxygen(X).

X = sun; x = venus; x = jupiter.

?- cant_live_in(Y).

Y = saturn.

?- cant_live_in(saturn).

true.

?- cant_live_in(pluto).

false.
39

Advance Programming Language Concepts


?- impossible_to_live_in_planet(Z).

Z =jupiter; Z = venus; Z = mars

?- impossible_to_live_in_planet(mars).

true

?- impossible_to_live_in_planet(earth).

false.

Screen Shorts
1. solar_system_is_elliptical_in_shape.

Figure 7: Query 1

2. the_Sun_is_in_the_center_of_the_solar_system.

Figure 8:: Query 2

3. planet(mercury).

Figure 9:Query 3

4. planet(venus).

Figure 10:Query 4

5. planet_of(mercury,solar_system).
40

Advance Programming Language Concepts

Figure 11;:Query 5

6. similar(venus,earth).

Figure 12:Query 6

7. planet_of(X,solar_system).

Figure 13:: Query 7

8. similar(venus,X).

Figure 14: Query 8

9. planets(mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).

Figure 15:Query 9

10. planets(A,B,earth,mars,jupiter,saturn,uranus,neptune,pluto).

41

Advance Programming Language Concepts

Figure 16:Query 10

11. planets(A,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).

Figure 17:Query 11

12. brightest(Who,solar_system)

Figure 18:Query 12

13. planet(1,Which_is_first,days_88 ,days_59 ,no_natural_planets).

Figure 19:Query 13

14. high_temperature(X).

Figure 20:Query 14

15. impossible_to_live(sun).

Figure 21::Query 16

42

Advance Programming Language Concepts


16. impossible_to_live(X).

Figure 22:Query 17

17. cant_live_in(Y).

Figure 23:Query 19

18. cant_live_in(saturn).

Figure 24:Query 20

19. impossible_to_live_in_planet(Z).

Figure 25:Query21

20. biggest(X,pluto).

Figure 26:Query22

43

Advance Programming Language Concepts

44

Vous aimerez peut-être aussi