Wednesday, November 7, 2012

Object Oriented Programming



The programming process has evolved through many phases. The journey started with programmers who would write programs which some how worked without giving any importance to readability of the program. The languages like FORTRAN and BASIC neither enforced any discipline nor were the programmers trained to write user centric programs. The result was unstructured understandable programs susceptible to bugs acting as time bombs like Y2K problem. The major problem was that the programs were not maintainable.

The structured programming techniques did enforce some discipline on the programmers by way of shunning the use of ‘goto’ statements and encouraging the programmers to use ‘easy to read and difficult to write’ style of code statements i.e. choosing long and meaningful names for the variables, functions, procedures, modules etc. The major emphasis was to use block structures in the program. For instance any code enclosed between a pair of curly braces or the pair of begin – end was termed as a block. Pascal and ‘C’ supported blocks like compound statements, loops, functions, procedures, files etc. This technique worked good for hard core programmers who were able to write large and complex programs using structured programming techniques. Unix operating system was written using ‘C’. Then there were always few hard core programmers available in the market.

Nevertheless, the importance was given to procedures as to how to solve the problem at hand. The algorithm development consumed more time of the developer and least importance was given to the data. So, a program was virtually a collection of decomposed components i.e. interacting functions or modules exchanging data and data structures among them. Such data, especially the global data, was vulnerable to inadvertent corruption by the fellow programmers.

The remedy to the above mentioned drawbacks is that we put more emphasis on data and try to create reusable software components. The reusable components can further be combined to get bigger and more powerful software.

For example, in our day to day life we compose bigger objects from smaller objects. The desktop computer is made up many smaller objects like: mother board, RAM, HDD, SMPS, mouse, keyboard etc. We use the services offered by these objects and never bother as to how they work or who made them?

When we look around then we find that we are surrounded by nothing but objects only. You & I, books, pen, paper, laptop etc. are all objects. In fact any real world program has to be a collection objects. A program about a University would involve objects like students, professors, clerks, class rooms, books, chalk, mark sheets etc. Then why not write programs using objects which would be very natural way of creating useful software comprising of interacting objects.

Object Oriented Programming (OOP) is a paradigm shift in programming which defines, creates, and manipulates objects to develop a reusable software. C++ is an imperative language developed to support OOP components and features like: classes, objects, abstraction, encapsulation, inheritance, polymorphism etc.

A. K. Sharma

Thought to ponder...

True education is that destroys narrow-mindedness,
develops equality and ultimately leads to world peace.

Bhagwan Sri Satya Sai Baba

Sunday, November 4, 2012

बस ऐसे ही


अरनब गोस्वामी  की  इंतज़ार लंबी लगती है 
                  बहरे राजनितीगों पर बहस और भी लंबी लगती है 
 लंबी  लंबी बातें सोचता   हुं 
                  खुली आँखों से ये रात बहुत लंबी  लगती है

सुबह  सुबह की भाग  दौड़  लंबी लगती है
                  दिन  के 9 से 5 की  दूरी और भी लंबी लगती है
 लंबी  लंबी क्लास लेता हुं 
                  सियासत से भरी ये नोकरी बहुत लंबी लगती है

तन्खवाह की इन्तेजार लंबी  लगती है
                 इन्क्रीमेंट की पावत और भी लंबी  लगती है
 लंबी  लंबी  डी ए की किश्त लगती हैं
                   मुझे तो ये महेंगाई  बहुत लंबी लगती है

क्रासिंग की बत्ती लंबी लगती है
                   हर  सड़क और भी लंबी लगती है
 लंबी  लंबी यात्राऐं करता  हूँ
                   मुझे तो ये जिंदगी बहुत लंबी लगती है

अशोक

Thought to ponder...

Your very speech should be soft. Not only soft but also truthful.

Bhagwan Sri Satya Sai Baba

Friday, October 26, 2012

Renaissance - YMCA University News letter

YMCA University of Sc. & Tech. is coming out with 2nd edition of its news letter called "Renaissance" It is edited by Prof. Divya Jyoti Singh. Its link is given below:

www.renaissanceymcaust.blogspot.com

Monday, October 22, 2012

Some Important PROLOG Predicates

Some popular and important PROLOG predicates are given below for the readers. These were discussed in a class of Artificial Intelligence.



1. /*Sum of a list of numbers*/
domains
list=integer*
predicates
sum(list,integer)
clauses
sum([],0).
sum([H|T],R):-sum(T,S),R=S+H.

2. /*Compare 2 Lists of numbers*/
domains
list=integer*
predicates
ifEqual(list,list)
clauses
ifEqual([],[]).
ifEqual([H1|T1],[H2|T2]):-H1=H2,ifEqual(T1,T2).

3. /*Find the last element of a list*/
domains
list=integer*
predicates
last(list,integer)
clauses
last([X],X).
last([H|T],L):-last(T,L).

4. /*delete last the last element of a list */
domains
list=integer*
predicates
deleteLast(list,list)
clauses
deleteLast([X],[]).
deleteLast([H|T],[H|NT]):-deleteLast(T,NT).


5. /*Separate positive and negative numbers from a list and put them in two separate lists*/
domains
list=integer*
predicates
separate(list,list,list)
clauses
separate([],[],[]).
separate([H|T],[H|PL],NL):-H>0,separate(T,PL,NL).
separate([H|T],PL,[H|NL]):-H<0 br="br" separate="separate">
6. /*Partition a list into two lists lessX and GreatX which contains elements less than X and greater than X respectively*/
domains
list=integer*
predicates
partition(integer,list,list,list)
clauses
partition(X,[],[],[]).
partition(X,[H|T],[H|LX],GX):-H<=X,partition(X,T,LX,GX).
partition(X,[H|T],LX,[H|GX]):-H>X,partition(X,T,LX,GX).

7. /*Find the smallest in a given list*/
domains
list=integer*
predicates
smallest(list,integer)
clauses
smallest([X],X).
smallest([H|T],X):-smallest(T,X),X smallest([H|T],H):-smallest(T,X),H
8. /*Find wheather a given number X is a member of a list or not */
domains
list=integer*
predicates
member(integer,list)
clauses
member(X,[X]).
member(X,[H|T]):-X=H.
member(X,[H|T]):-X<>H,member(X,T).

9. /*Create union of two given lists*/
domains
list=integer*
predicates
member(integer,list)
union(list,list,list)
clauses
member(X,[X]).
member(X,[H|T]):-X=H.
member(X,[H|T]):-X<>H,member(X,T).
union([],L2,L2).
union(L1,[],L1).
union([H|T],L2,[H|NL]):-NOT(member(H,L2)),union(T,L2,NL).
union([H|T],L2,NL):-member(H,L2),union(T,L2,NL).

10. /* Create intersection of two given lists*/
domains
list=integer*
predicates
member(integer,list)
intersection(list,list,list)
clauses
member(X,[X]).
member(X,[H|T]):-X=H.
member(X,[H|T]):-X<>H,member(X,T).
intersection([],L2,[]).
intersection(L1,[],[]).
intersection([H|T],L2,NL):-NOT(member(H,L2)),intersection(T,L2,NL).
intersection([H|T],L2,[H|NL]):-member(H,L2),intersection(T,L2,NL).

11. /*Give ListA minus ListB*/
domains
list=integer*
predicates
member(integer,list)
AminusB(list,list,list)
clauses
member(X,[X]).
member(X,[H|T]):-X=H.
member(X,[H|T]):-X<>H,member(X,T).
AminusB([],L2,[]).
AminusB(L1,[],L1).
AminusB([H|T],L2,[H|NL]):-NOT(member(H,L2)),AminusB(T,L2,NL).
AminusB([H|T],L2,NL):-member(H,L2),AminusB(T,L2,NL).

12. /*concatenate two lists */
domains
list=integer*
predicates
concatenation(list,list,list)
clauses
concatenation([],L2,L2).
concatenation(L1,[],L1).
concatenation([H|T],L2,[H|NL]):-concatenation(T,L2,NL).

13. /*replace X by Y of all occurrences of X in a list*/
domains
list=integer*
predicates
replace(integer,integer,list,list)
clauses
replace(X,Y,[],[]).
replace(X,Y,[H|T],[Y|NL]):-H=X,replace(X,Y,T,NL).
replace(X,Y,[H|T],[H|NL]):-H<>X,replace(X,Y,T,NL).

14. /*Reverse a given list */
domains
list=integer*
predicates
Reverse(list,list)
append(list,list,list)
clauses
append([],L2,L2).
append(L1,[],L1).
append([H|T],L2,[H|NL]):-append(T,L2,NL).
Reverse([],[]).
Reverse([H|T],NL):-Reverse(T,RL),append(RL,[H],NL).

15. /*Determine whether a list is palindrome or not*/
domains
list=integer*
predicates
palindrome(list)
last(list,integer)
deleteLast(list,list)
clauses
last([X],X).
last([H|T],L):-last(T,L).
deleteLast([X],[]).
deleteLast([H|T],[H|NT]):-deleteLast(T,NT).
palindrome([]).
palindrome([X]).
palindrome([H|T]):-last(T,L),H=L,deleteLast(T,NT),palindrome(NT).

16. /*merge two co sequential lists into a third list*/
domains
list=integer*
predicates
merge(list,list,list)
clauses
merge([],L2,L2).
merge(L1,[],L1).
merge([H1|T1],[H2|T2],[H1|NL]):-H1<=H2,merge(T1,[H2|T2],NL).
merge([H1|T1],[H2|T2],[H2|NL]):-H2


17. / *Quick sort a given list of numbers*/

domains
list=integer*
predicates
partition(integer,list,list,list)
append(list,list,list)
quickSort(list,list)
clauses
partition(X,[],[],[]).
partition(X,[H|T],[H|LX],GX):-H<=X,partition(X,T,LX,GX).
partition(X,[H|T],LX,[H|GX]):-H>X,partition(X,T,LX,GX).
append(L1,[],L1).
append([],L2,L2).
append([H|T],L2,[H|NT]):-append(T,L2,NT).
quickSort([],[]).
quickSort([H|T],FL):-partition(H,T,LH,GH),quickSort(LH,LSL),quickSort(GH,GSL),append(LSL,[H|GSL],FL).


18. /*merge sort a given list of numbers*/
domains
list=integer*
predicates
merge(list,list,list)
divide(list,list,list)
append(list,list,list)
mergeSort(list,list)
last(list,integer)
deleteLast(list,list)
clauses
last([X],X).
last([H|T],L):-last(T,L).
deleteLast([X],[]).
deleteLast([H|T],[H|NT]):-deleteLast(T,NT).
divide([],[],[]).
divide([H|T],[H|NT1],NL):-last([H|T],L),deleteLast(T,NT),divide(NT,NT1,NT2),append(NT2,[L],NL).
merge([],L2,L2).
merge(L1,[],L1).
merge([H1|T1],[H2|T2],[H1|NL]):-H1<=H2,merge(T1,[H2|T2],NL).
merge([H1|T1],[H2|T2],[H2|NL]):-H2


append(L1,[],L1).
append([],L2,L2).
append([H|T],L2,[H|NT]):-append(T,L2,NT).
mergeSort([],[]).
mergeSort([H],[H]).
mergeSort(L,FL):-d(L,L1,L2),mergeSort(L1,SL1),mergeSort(L2,SL2),merge(SL1,SL2,FL).

19. /* Sort a given list of numbers using selection sort*/
domains
list=integer*
predicates
selectionSort(list,list)
smallest(list,integer)
replace(integer,integer,list,list)
clauses
smallest([X],X).
smallest([H|T],X):-smallest(T,X),X smallest([H|T],H):-smallest(T,X),H replace(X,Y,[],[]).
replace(X,Y,[H|T],[Y|T]):-H=X.
replace(X,Y,[H|T],[H|NT]):-H<>X,replace(X,Y,T,NT).
selectionSort([],[]).
selectionSort([H],[H]).
selectionSort([H|T],[S|SL]):-smallest(T,S),H>S,replace(S,H,T,RL),selectionSort(RL,SL).
selectionSort([H|T],[H|SL]):-smallest(T,S),S>H,selectionSort(T,SL).

20. /* Sort a given list of numbers using insertion sort*/
domains
list=integer*
predicates
insert(integer,list,list)
append(list,list,list)
insertionSort(list,list)
clauses
insert(X,[],[X]).
insert(X,[H|T],NL):-X<=H,append([X],[H|T],NL).
insert(X,[H|T],[H|NT]):-X>H,insert(X,T,NT).
append(L1,[],L1).
append([],L2,L2).
append([H|T],L2,[H|NT]):-append(T,L2,NT).
insertionSort([],[]).
insertionSort([H|T],SL):-insertionSort(T,NT),insert(H,NT,SL).




Thought to ponder....

The sanctification of the five senses is the way to truth.

Bhagwan Sri Satya Sai Baba 

Monday, September 3, 2012

The Programming Paradigms


The programming process has evolved through many phases. The journey started with programmers who would write programs which some how worked without giving any importance to readability of the program. The languages like FORTRAN and BASIC neither enforced any discipline nor were the programmers trained to write user centric programs. The result was unstructured understandable programs susceptible to bugs acting as time bombs like Y2K problem. The major problem was that the programs were not maintainable.

The structured programming techniques did enforce some discipline on the programmers by way of shunning the use of ‘goto’ statements and encouraging the programmers to use ‘easy to read and difficult to write’ style of code statements i.e. choosing long and meaningful names for the variables, functions, procedures, modules etc. The major emphasis was to use block structures in the program. For instance any code enclosed between a pair of curly braces or the pair of begin – end was termed as a block. Pascal and ‘C’ supported blocks like compound statements, loops, functions, procedures, files etc. This technique worked good for hard core programmers who were able to write large and complex programs using structured programming techniques. Unix operating system was written using ‘C’. Then there were always few hard core programmers available in the market.

Nevertheless, the importance was given to procedures as to how to solve the problem at hand. The algorithm development consumed more time of the developer and least importance was given to the data. So, a program was virtually a collection of decomposed components i.e. interacting functions or modules exchanging data and data structures among them. Such data, especially the global data, was vulnerable to inadvertent corruption by the fellow programmers.

The remedy to the above mentioned drawbacks is that we put more emphasis on data and try to create reusable software components. The reusable components can further be combined to get bigger and more powerful software.

For example, in our day to day life we compose bigger objects from smaller objects. The desktop computer is made up many smaller objects like: mother board, RAM, HDD, SMPS, mouse, keyboard etc. We use the services offered by these objects and never bother as to how they work or who made them?

When we look around then we find that we are surrounded by nothing but objects only. You & I, books, pen, paper, laptop etc. are all objects. In fact any real world program has to be a collection objects. A program about a University would involve objects like students, professors, clerks, class rooms, books, chalk, mark sheets etc. Then why not write programs using objects which would be very natural way of creating useful software comprising of interacting objects.

Object Oriented Programming (OOP) is a paradigm shift in programming which defines, creates, and manipulates objects to develop a reusable software. C++ is an imperative language developed to support OOP components and features like: classes, objects, abstraction, encapsulation, inheritance, polymorphism etc.

A. K. Sharma

Thought to ponder...

We should realize that man has not only a mind which conceives thoughts,
but also a heart which can put them into practice

Bhagwan Sri Satya Sai baba

Monday, May 7, 2012

Water and Food Security




We as human being are basically composed of five sheaths. The physical body (annmaya Kosha), energy body (pranmaya Kosha), mind body (manmaya Kosha), wisdom body (gyanmaya kosha), and the bliss body (anandmaya kosha).

The annmaya kosha by name itself suggests that it is made from anna the food and it requires a continuous supply of food and water. Therefore the topic of the day is very relevant to us all.

The almighty God has blessed us with 5 resources: material, water, air, energy, and  space. धरती , जल , वायु , अग्नी  , और  आकाश . These are unbounded buffers. One can draw as much amount as needed of these non shareable but consumable resources. Non shareable in the sense that my thirst would only be quenched by drinking a glass of water and not by the water drunk by some body else. Similarly, the space occupied by me mutually excludes others other from occupying the same space.  Food is a manifestation of all these resources. It is a material, occupies space, contains water and air, and is the basic source of energy for our physical and energy bodies.

What is meant by Food and water security – All people at all times must have both physical and economic access to the basic food and potable water they need. 

But the statistics tell us that more than half of the population of the poor countries go empty stomach to their beds i.e. the security is anything but guaranteed.

The insecurity comes from factors like climate change, urban development, population growth, bad governance, and agriculture abuse in terms CLU and perverted use of agri-products such as bio-fuels.

A closer look on the factors indicate rather establish that the man himself is the cause this insecurity. As the saying is “Jis chieez ko sukh hai usika to dukh hai”. The same object is capable of giving you the pain or pleasure. Civilized societies are on the verge of destroying the civilization. For instance, deforestation, global warming, ozone hole, melting of glaciers, unusual weathers, femine etc. can all be attributed to the follies of mankind.

The threat to the availability of Water.

I find that the shortage of water in cities is because of its misuse by the man himself. We know that the population of  Delhi is more than a crore . If on an average, there are five person in a house, we have about 20 lacs houses in this city. Out of that approximately 10 lacs houses have air coolers. Each cooler consumes around 100 litres of water per day (24 hours). That means 100 million liters of water vanishes into the air thereby creating two major problems : A very significant shortage of this costly resource and  unnatural artificial increase of humidity in the air causing discomfort.
Soln: Cost reduction of electricity and air conditioners.

The vehicle density in Delhi itself is 135 vehicles per km. Because of shortage of covered parking space, most of the cars in cities are parked in open. Every car needs at least 1-2 buckets of water for its washing. Car washing has become an industry Delhi. That means about 30 to 40 lacs litres of water is going into nowhere.

In India itself there are thousands of cities in Gangatic planes.

Soln. Cover the cars.

In fact almost all the 5 lacs villages of this country at one point of time had ponds called johars.

My Nanihal is in a village of Karnal Distt., where I spent my most of the summer vacations during my childhood i.e. 1960s. That village had two ponds. One medium sized pond to collect rain water and another large wetland cum lake blooming with small lotuses.  I don’t know what happened but now there are none.  The cause is urbanization and increase in population. I guess same is the case with a large number of villages which fall in the vicinity of cities.

What to talk about ponds, the villages themselves are vanishing at the altar of urbanization.. Khanpur, Tigri, madangir, chirag dilli and many more were villages at one time in south Delhi. Ajrondha, Mavla Mahrajpur, Saria Khwaja were the villages of Faridabad dist. The agriculture land is being bought  by industrialists , builders, and promoters of private engg. Colleges.

Hauz Khas and Hauz Kazi, the names suggest that the places were at one time water bodies.


The threat to the availability of food.

Climate change, population pressure, and increased demand for food and feed are the major threats to food availability. Global warming has drastically affected water availability and agriculture. In Kashmir alone, the productivity of maize and cherry has very significantly reduced.

The food items are available on the shelves of the super markets but beyond the reach of the poor. The cause is:  Lobh or greed, the most prominent vice of a man. The greed to amass or accumulate necessities especially the food beyond one’s basic requirements. It brings in the risk of others remaining hungry. The greed to amass creates a virtual paucity of food in the market in terms of trader holdings. Consequently, the prices go high and beyond the reach of poor.

We should rather learn from animals. An animal eats only when it is hungry. We can take a cue from a Camel which carries a minimum amount of food into its hump. Besides the hump it has three stomachs : first contains chewed cud and a small pocket containing water, the second contains digestive juices, and the third is used on need felt basis to digest only a small quantity of cud by mixing it with the digestive juices.

Fossil fuels also add to the inflation causing the rate of food items going high.

Bad governance is another factor. Yesterday, there was a news that about 77000 tonnes of wheat is rotting in FCI Godowns of Panjab, a glaring example of faulty distribution and storage system. Similar must be the case in other states also.

Every year thousand tones of fruits rot in hills or fed to the pets for want of fast transport systems.

In some countries the usual crops have been replaced by plants which can produce bio fuels such as bio diesel, ethanol etc. Brazil grows sugarcane to produce ethanol which, mixed with ammonia, is used as a fuel for auto-mobiles
Suggestions 

Rural India needs agriculture experts who are in possession of theoretical and practical knowledge to bring agriculture reforms. The agriculture reforms means land reforms and implementation of support services such as credit, marketing, pricing. Rural infrastructure is another important area. We must establish canals, roads, bridges, schools and hospitals in the villages. Fast and all weather roads connecting to cities and metros is need of the hour.

The Question is : Can we make farming a profitable or lucrative business for the farmers? Information Communication Technologies (ICT) holds the answer.  ICT can bring effective information flow between all stake holders of the agriculture industry i.e. the farmer, cooperatives, farm machinery vendors, fertilizer industries, insurance companies, farm advisors, consultants etc.

In fact, the access to information, resources and markets are needed for improvements in agricultural productivity in India.

Therefore the rural experts need to be trained in two major fields: Agriculture and Informatics. The amalgam of the two is called as Agri-informatics. Some universities have already started Master level courses in Agricultural Informatics.

A. K. Sharma

Thought to ponder

We must ensure that eating must be in a limited quantity. You must be able to getup from your plate with the same ease and lightness with which you sat down to eat. This is the correct limit. You come quite easily to eat. But when you get up you need a support ! Many people develop a paunch like that.

Bhagwan Shri Satya Sai Baba