www.renaissanceymcaust.blogspot.com
Friday, October 26, 2012
Renaissance - YMCA University News letter
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.
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
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
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
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).
Monday, September 3, 2012
The Programming Paradigms
Sunday, July 15, 2012
Monday, May 7, 2012
Water and Food Security
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
Monday, November 21, 2011
What is a thought
Baba says : When we see something – a thought comes in our mind.
I have contemplated on the words of Baba. I find them to be true. But it still remains to be understood as to what exactly is thought?. Is it a biological wave that emanates from the body in general or the brain in particular. If it is so then during its entourage, it must connect to something that I have not seen yet or had an experienced with. i.e. occasionally I may think about something which I have never seen, read, or experienced. But I have yet to think about something that does not exist for me. This absence of thought about unknown, not previously perceived objects demolishes the existence of a biological wave.
So to answer this, I go back to my basics which tell me that as soon as I perceive a new object, I cognize it and categorize it to a class of objects so that I recognize it at later stage. In the database, a multi link node is created to store the object with its characteristics (identity, states, behaviours, and an emotional quotient). The multi-links are connected to its related objects and events.
When I see or perceive something, an internal marquee takes me on a tour of the related objects and events. The sequence of objects or events traversed by me during the process of recognition is nothing but a thought.
For instance, when I see a rose, it takes on an internal tour of several objects and events, the rose that graces the coat of Chacha Nehru, the rose I clicked by my Nikon in the garden of University of Roorkee, or the roses I bring to my house on various ceremonies, and even the couplet of an Urdu poet about its beauty, and many more of them. During this tour, if the rose at Roorkee has a stronger emotional quotient, then the detour of Roorkee starts bringing forth objects like, the teachers ( Dr. J. P. Gupta, Dr. Padam Kumar, Dr. Joshi…..), the magnificent central Dome of the University, the computer centre, the chhapo place, the SBI, the Sarswati temple an it goes on.
The other way round is that say I go to meet Gupta Sir, the meeting itself may connect me to Roorkee and might lead to the rose and then to my Nikon. The Nikon would definitely connect me to Jalanadhar , where I not only bought it but spent most of my golden youth. This maquee and the tour is unending and so is the sequence of objects and events. I would tend to term this sequence as a thought or a train of thought.
Then what is thinking. I would say that for a given problem or situation, we try to search the solution through a guided tour of our inner database.
I will write more…
A. K. Sharma
Thought to ponder….
Every living being in this world; be it an animal, a bird or even a small insect, has emerged from a truth. Those who realize the truth are yogis. There can be no activity in this world without truth.
Truth is present everywhere. It can manifest in you also when you think of it and contemplate on it.
Bhagwan Sri Satya Sai Baba.
Monday, November 7, 2011
AI:Can Intelligenece be artificial ?
I have been teaching this subject of AI for quit long. The main aim is to create intelligent machines and if some machine or object depicts some kind of intelligence then it has to be rated as artificial. This is purely an occidental egoistic view.
I disagree with this kind of superficial superiority of homo sapience. Reason being that the so called intelligence exhibited by machines , particularly the computers is limited by the intelligence of the programmer who has written the inference mechanism and the level of knowledge base (KB) created from or by the experts. If there is a fault in the program the inferences would be faulty. Similarly if the KB is insufficient or uncertain, so would be the results. So where is the intelligence of the machine?. And why call it artificial.
On the contrary, the orient view is that every object has some kind of consciousness. There are umpteen examples which can be quoted from history, puranas, and personal experiences. For example the telepathic coordination between Maharana Partap and Chetak are well known. Ahilya bai turning into stone and back is very well known story from Ramayan. A mountain started wailing when it was not used by Lord Rama for construction of the setu over ocean. Only after the assurance from the Lord, the mountain was pacified. In the next avtar, Lord Krishna used the same mountain to save the peasents from the wrath of Indra, the rain god. The mountain is very popularly known as Giriraj ji.
Try to abuse your tools and you will find that they do not deliver. The pen with which you scratch your back or poke your ear will never result in a worth while research paper, book, essay, prose or poem. Let some body else place shoes on your pillow in your absence and remove them before you retire for sleep. Would you get a sound sleep? - definitely not. The experiments of Basu with vegetables and plants also confirm that they cognize there surroundings and events occurring around them
In fact, Sai Ram says that every seemingly non living thing is living and has a level of consciousness. कण कण में भगवान्। Thus there are emotions, feelings, consiousness, and intelligence of there own in the objects, which otherwise are considered as non living.
So, the objects have either no intelligence as per the western view or they have intelligence of their own as per the oriental belief.
A. K. Sharma
Thought to Ponder...
The Vedas declare that God prevades the body in the form of essence (rasa)
Bhagwan Sri Satya Sai Baba