Advanced Programming Language Concepts (functional programming and logical programming concepts)
-
Upload
isuripabasara -
Category
Documents
-
view
257 -
download
0
Transcript of Advanced Programming Language Concepts (functional programming and logical programming concepts)
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
1/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.
1
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
2/44
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
2
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
3/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
4/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
5/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
6/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
7/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
8/44
Advance Programming Language Concepts
Image [(Int, Int, Int)] Store the images.
Pure functions
Function Type Usage
separateColors Image ([Int],[Int],[Int])
Separate the R, G, B color values into
separate lists.
[(Int, Int, Int)] ([Int],[Int],[Int])
getRvalue Int ([Int],[Int],[Int]) [Int]
Filter only the red color values.
(based on input value)
([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[11100]
getGvalue Int ([Int],[Int],[Int]) [Int]
Filter only the green color values.
([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[00110]
getBvalue Int ([Int],[Int],[Int]) [Int]
Filter only the green color values.
([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[10100]
splitValue Int [Int]
Split the individual values into a list.
11100 [1,1,1,0,0]
8
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
9/44
Advance Programming Language Concepts
getLSB [Int] [Int]
Get the final bit value.
[10001,11110,11111] [1,0,1]
isElement Int BoolChecking that given element is
existing or not.
binaryToChar Int Char
Converting the integer values into
their corresponding characters.
User defined higher order functions
Function Type Usage
splitValues (Int [Int]) [Int] [Int]
Take the splitValue function (split
individual values) and the required
integer list as parameters and split all
the values in to one list.
[11111,10000,10101]
[1,1,1,1,0,0,0,1,0,1,0,1]
getNth(Int [Int] [Int]) Int
[Int] [Int]
Take each 5th element from the splitted
list in to separate list. GetgetAboveNth function and splitted list
as inputs.
[1,1,1,1,1,0,0,0,0,0] [1,0]
9
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
10/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
11/44
Advance Programming Language Concepts
read String aConvert string type value into another
type
show a String Convert any type value in to a string.
Primitive recursion
Function Type Usage
getAboveNth Int [Int] [Int]
Take set of values according to given
index value.
3 [1,1,1,0,0,0,1,0,1] [1,1,1],[0,0,0],
[1,0,1]
getLSB [Int] [Int]
Take the last bit value of every
individual value.
[11110,10001,11111] [0,1,1]
groupSpliter [Int] [Int]
Creates the groups of splitted
elements.
First take the first five element
(character ASCII size) and then drop
those values from the list and check
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
12/44
Advance Programming Language Concepts
checking (Int Bool) [Int] [Int]
Check first combined value is related
to the letters ASCII codes. And then
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
13/44
Advance Programming Language Concepts
application.
images Images.hs Keep all images.
steganalysis Steganalysis.hs
Keep all pure functions, higher order
functions and primitive recursion
which required for steganalysis section
(detecting section).
main Main.hs
Keep the interface (main menu) with
IO functions to provide the sequence
of the program.
1.6 Screens
Main menu
13
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
14/44
Advance Programming Language Concepts
This is the main menu of this application. This will provide the ability to select an option at a time.
Image Gallery
14
Figure 1: Main Menu
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
15/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
16/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
17/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
18/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
19/44
Advance Programming Language Concepts
images should be displayed. (Therefore image module work
properly).
Common module Application should be navigate
correctly.
Application is navigates properly.
(Therefore functions which under
this modules work properly).
Steganalysis module Application should be able to
display the hidden message.
Displays the hidden message with
the message of Successfully
detected!!
(Therefore functions which under
this modules work properly).
1.7 Source Code
Main.hs
module Main where
19
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
20/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
21/44
Advance Programming Language Concepts
putStrLn " "
putStrLn "\t \t Please enter your choice: "
choice1
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
22/44
Advance Programming Language Concepts
choice2
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
23/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
24/44
Advance Programming Language Concepts
choice3
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
25/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
26/44
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 ifexist)"
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 theinstruction. "
putStrLn "otherwise software can be currpted."
putStrLn " "
putStrLn "Press any key to contiune "
var
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
27/44
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 = [(10001,10001,10101),(11000,10010,10000),(11100,10100,11110),(11110,10000,10100),(11011,10001,10011),
(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 = [(11001,10001,10111),(11011,10001,10011),(11101,10111,11111),(10100,10100,11100),(11111,10111,11011),
(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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
28/44
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 = [(10011,10111,11111),(11110,10000,10100),(11111,10001,10011),(10101,11101,10111),(11001,10011,10001),
(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 = [(10101,11101,10111),(10011,10011,10101),(10100,10100,11100),(11000,10010,10000),(10011,10111,11111),
(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 = [(11011,10101,10001),(11111,10111,11011),(11110,10000,10100),(10000,10100,10010),(10010,10010,10100),
(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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
29/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
30/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
31/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
32/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
33/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
34/44
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
piter,saturn,uranus,neptune,pluto).
All those are planets.
Variables and Unification
Fact explanation
brightest(sun,solar_system). Sun is the brightest of the solar system.
34
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
35/44
Advance Programming Language Concepts
planet(1,mercury,days_88
,days_59 ,no_natural_planets).
planet(num,name,revolution around sun,revolution around
own,no of satellit)
Rules
Rule explanation
If ,
high_temperature(sun).
high_temperature(venus).
high_temperature(jupiter).
impossible_to_live(X):- high_temperature(X).
no_oxygen(X):- impossible_to_live(X).
no_water(X):- no_oxygen(X).
no_oxygen(X).
no_oxygen(X).
no_oxygen(X).
high temperature in sun.
high temperature in venus.
high temperature in jupiter.
if high temperature (in some
planet), impossible to live.
if impossible to live, because of no
oxygen.
if no oxygen, there is no water.
If,
temp_high(saturn). high temperature in saturn.
35
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
36/44
Advance Programming Language Concepts
oxy_less(pluto).
oxy_less(saturn).
wat_less(mars).
wat_less(saturn).
cant_live_in(Y):- temp_high(Y), oxy_less(Y), wat_less(Y).
no oxygen in pluto.
no oxygen in Saturn.
no water in mars.
no water in Saturn.
impossible to live in some planet
if, is high temperrature `and`, no
oxygen `and`, no water .
If,
high_temp(jupiter).
high_temp(venus).
oxy_no(mars).
oxy_no(jupiter).
wat_no(venus).
wat_no(mars).
impossible_to_live_in_planet(Z):- high_temp(Z); oxy_no(Z);
wat_no
(Z).
wat_no(Z).
wat_no(Z).
high temperature in jupiter.
high temperature in venus.
no oxygen in jupiter.
no oxygen in venus.
no water in venus.
no water in mars.
impossible to live in some planet
if, is high temperrature `or`
no oxygen `or` no water.
If,
bigger_than(earth,mercury). earth is bigger than mercury.
36
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
37/44
Advance Programming Language Concepts
bigger_than(mercury,pluto).
bigger_than(saturn,earth).
bigger_than(earth,pluto).
biggest(X,Y):- bigger_than(X,Z), bigger_than(Z,Y).
smallest(Y,X):- biggest (X,Y).
biggest(X,Y).
mercury is bigger than pluto.
saturn is bigger than earth.
earth is bigger than pluto.
if x > z and z > y ---> x > y
if x is biggest when compare to the
y, then y become the smallest.
If,
closer(sun,mercury).
closer(mercury,venus).
closer(venus,earth).
beyond(X,Y):- closer(X,A),closer(A,B),closer(B,Y).
beyonds(X,Y):-closer(X,Z),closer(Z,Y).
mercury is closer to sun.
venus is closer to mercury.
earth is closer to venus.
if x >> y --> X,A,B,...Y
if X > Z , Z > Y --> X > Y
can_see(X) :-
planet (X), closer (X, earth).
planet(X),
planet(X),
people can see x, if x must be a
planet and closer to the earth.
Queries
37
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
38/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
39/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
40/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
41/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
42/44
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
43/44
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
-
7/31/2019 Advanced Programming Language Concepts (functional programming and logical programming concepts)
44/44
Advance Programming Language Concepts