You are on page 1of 12

CS F214 Logic in CS

Sem I 2016-17 Tutorials and Materials

Ramprasad Joshi and FDTAs


Nidhi Kadkol, Kratika Chandra, Vassala Routray, Amit Agarwal

BITS Pilani K K Birla Goa Campus

November 10, 2016


Abstract

We collect together, in some organized sequence, all the materials we prepare


and use for tutorial practice and demonstrations during Semester I, 2016-17.
Chapter 1

Introduction, Motivation and


Much Ado about Nothing

In this chapter we consider the question of what the fuss is all about.

1.1 Introduction
A is A and A is not B unless A = B by definition. Every statement is either
true or false, it cannot be both at once, it cannot be none. Oh yeah, so what?
(Why) Is there a need to say all this in so many words?

1.1.1 Naming: Example


A = 52 . B = 15 6
. Answer the following questions. In the conclusion of every
story of Vikram and Betal (see Fig 1.1) the latter demands that Vikramaditya
must answer a moral question pertaining to the storys characters, on pain of
his own death; and upon his answering the question, Betaal returns to his tree.
If you do not answer the following questions, LiCS will return to the infinite
tree that has its root at the bottom of its rendering.

Figure 1.1: Vikram and Betal

1. Is A = B?
2. Suppose your answer to the previous question is yes. Then, will you
assert that every statement about A also holds for B?

1
3. Suppose your answer to the previous question is yes. Then or otherwise,
will you assert that every true (or untrue) statement that involves A re-
mains true (or untrue) when any (or every) A in it is replaced by B and
vice versa?
4. Is the statement The denominator of A is not divisible by 3 true?
5. Answer all the previous questions again but now in the reverse order.
6. Answer all the previous questions again, in the original order, but this
time interchanging mutually A and B.
7. Whats happening here? (That is, let Betal hang by the tree again.)

1.1.2 A Question for 13 Aug


Make another and original Bikram and Vetal story. BTW, in Marathi, Betal
means unbalanced or arhythmic. Vikram can mean, in Sanskrit and all her
family, variously and simultaneously, special sequence, non-sequence, feat, etc.
This time, the moral of the story must be that assuming truth may not be
consistent with its consequences. If not clear, attend Thursday 11 Aug 2016
class at 11-12 noon in LT3, BPGC. If there is no power during the first twenty
minutes, and that makes us wait or waste awhile, still we are good.

1.1.3 Continued for 20 Aug


So here,
1. Make a few statements of the kind X is Y.
2. Make a few more statements of the kind If P is Q then R is S.

3. If you want, you may also add a few statements of the kind, Stibians
klus when they do not get sessapyad from their snedraw.
4. Fix labels for the statements, whichever way you want. No restrictions,
except that the labels themselves must be represented by finite strings.
We are not demanding uniqueness of any kind.

5. All these labels are put in the bag named what is known (to be true).
But up till now, what is known is only what is assumed before.
6. Use the inference, If statement L is true, and it is known that if and when
statement L is true then M is also true, then M is true, in order to bring
into what is known all that that can be brought in; that means, for each
such possible M, it must be brought in.
7. Either show that there is some contradiction in this bag now (if indeed it
is there), or show that there is no such contradiction. In the latter case,
you must also show that all possible Ms are brought in, exhaustively,
that is, nothing new can be added to the bag anymore.

2
Your work will be evaluated on this: adversaries will be asked to either show
a contradiction using less statements than your initial bag (in 5) had, or show
that some statements in that initial bag are consequences of others in it, hence
redundant. If the adversaries are successful, they get the difference (between
your initial bag size and their proposed reduced bag size) as their marks. If not,
you get marks equal to the size of your final bag (in 7). Also, if an adversary
shows that your final bag is not exhaustive, then she gets as much as the bag
size that she shows to be exhaustive. Each of you gets an opportunity to be an
adversary to others too. You get the maximum marks that you can earn during
the exercise all added up. If n adversaries try reducing your initial bag size
and fail, you get the final bag size marks n times. If you punch holes in the bags
of more victims, you get more marks, of course. You are free to prepare sheets
beforehand and bring them. You are free to collude with others beforehand,
we will rely on a randomized adversarial set up to disincentivise it.
Three students so far (August 19, 2016, 1808 hrs) have mailed me their ideas
on the original 13 Aug question. If tomorrow (Aug 20) our game is not played
vigorously, those three get the jackpot.

1.1.4 The Story Goes On


Many students have sent in their stories by now (August 23, 1855 hrs). I (rsj)
am happy but not satisfied. But I am satisfiable and there is no contradiction
here.
Here I present some stories that can be formulated into a very engaging yet
(il)logical answer to the tutorial question.

Finding an Address in Pune If amchi Mumbai is the maximum city, then


amchem Pune is the optimum city: they take pains to be optimal in everything
except unsolicited advice. Moreover, Pune is the center of the civilized world
and the center of knowledge itself! Thus if you go around asking for directions
to your friends address printed in her visiting card, you will not be surprised
to hear, Oh, so you did not take detailed directions from your addressee. You
see, the youngsters of these days have become so dependent on that
they forget that they are walking on a road and keep their eyes on the smart-
phone screen and keep listening to its robotic prompts and lose the direction to
their life itself. What has this nation come to ...! etc. Only your own wit can
save you from losing both your head and your direction in the midst of the in-
tricate labyrinthian lanes, by-lanes, and their residents pains; aha, that means
g
L o c! So, let us assume that, whatever Pune claims about itself, anywhere
on the Earths surface (including the surface of water bodies) at every possi-
ble junction there can be at most 4 directional choices: Left, Right, Forward,
Backward. Let us conclude, as a general theorem, that therefore, given any
two points on the Earths surface, it is sufficient to give a sequence of instruc-
tions each of which is one of {L, R, F, B} such that at each next junction from
the starting point (the source), if the next instruction (directional choice) is fol-
lowed then at the end of that sequence the second point (the destination) will
be reached. Looks plausible? Has the young generation found its direction
despite ? Or we need to rush to Punes by-lanes to seek guidance?

3
The Burning Question of Old Times The Phlogistontheory is a superseded
scientific theory that postulated that a fire-like element called phlogiston is con-
tained within combustible bodies and released during combustion. Phlogisti-
cated substances are substances that contain phlogiston and dephlogisticate
when burned. Dephlogisticating is when the substance simply releases the
phlogiston inside of it and that phlogiston is absorbed by the air. Growing
plants then absorb this phlogiston, which is why air does not spontaneously
combust and also why plant matter burns as well as it does. In general, sub-
stances that burned in air were said to be rich in phlogiston; the fact that com-
bustion soon ceased in an enclosed space was taken as clear-cut evidence that
air had the capacity to absorb only a finite amount of phlogiston. When air had
become completely phlogisticated it would no longer serve to support com-
bustion of any material, nor would a metal heated in it yield a calx; nor could
phlogisticated air support life. Breathing was thought to take phlogiston out of
the body. Freshly discovered nitrogen in 1772 was sought to be explained using
the theory. The residue of air left after burning, in fact a mixture of nitrogen and
carbon dioxide, was sometimes referred to as phlogisticated air, having taken
up all of the phlogiston. Conversely, when oxygen was first discovered, it was
thought to be dephlogisticated air, capable of combining with more phlogiston
and thus supporting combustion for longer than ordinary air.
Eventually, quantitative experiments revealed problems, including the fact
that some metals gained mass when they burned, even though they were sup-
posed to have lost phlogiston. Some phlogiston proponents explained this by
concluding that phlogiston had negative mass; others gave the more conven-
tional argument that it was lighter than air. However, a more detailed analysis
showed that just being lighter than air could not account for the increase in
mass.
During the eighteenth century, as it became clear that metals gained mass
when they were oxidized, phlogiston was increasingly regarded as a principle
rather than a material substance. By the end of the eighteenth century, for the
few chemists who still used the term phlogiston, the concept was linked to
hydrogen.
Phlogiston remained the dominant theory until the 1780s when Antoine-
Laurent Lavoisier showed that combustion requires a gas that has mass (oxy-
gen) and could be measured by means of weighing closed vessels. The use
of closed vessels also negated the buoyancy that had disguised the mass of
the gases of combustion. These observations solved the mass paradox and set
the stage for the new oxygen theory of combustion. Experienced chemists who
supported phlogiston theory attempted to respond to the challenges suggested
by Lavoisier and the newer chemists. In doing so, phlogiston theory became
more complicated and assumed too much, contributing to the overall demise
of the theory.
You may be fond of wearing your high-school farewell T-shirt, but wearing
it often will eventually wear it down and out. Wearing it with patches will not
be the same as wearing faded jeans.
So, do you believe that, in chemistry, the role of theory historically has
been a retrospective one, summarizing experimental data and predicting the
outcome of similar experiments; however, with the increasing power of com-
putational methods in chemistry, it has become possible to predict whether a
hypothetical compound is stable or not before experimental data is available?

4
Too many people, too many opinions The Malthusian theory of population,
laid out in this essay, is perhaps the most (in)famous economic theory that even
a common man (in a theoretically over-populated country like India). Let us
ignore the fact that Japan, for example, has much more population density per
square km of land (and much more so per square km of cultivable land) than
India. Let us take him seriously. The central argument of the Essay lies in two
postulates:

That food is necessary to the existence of man;


That the passion between the sexes is necessary, and will remain
nearly in its present state [p.11];

and four conclusions:


. . . that the power of population is indefinitely greater than the power
in the earth to produce subsistence for man.
population, when unchecked, increases in a geometrical ratio. Sub-
sistence increases only in arithmetical ratio. A slight acquaintance
with numbers will shew the immensity of the first power in com-
parison with the second.
By that law of our nature which makes food necessary to the life of
man, the effects of those two unequal powers must be kept equal.
This implies a strong and constantly operating check on population
from the difficulty of subsistence [p. 13].
The postulates are taken as self-evident; the deduced consequences are exam-
ined in more detail, including the various checks on population, such as post-
poned marriage, infant mortality, epidemics, and famine. He presented no
numerical data to support either the tendency to geometrical rate of growth of
the population or the arithmetical rate of growth of food supply; these suppo-
sitions are reasonable but largely intuitive.
What has happened to the world population and resources before and after
Malthus? After all, theories are theories. Apples dont fall because of Newtons
theory; moreover, they must have been falling to Earth before him as well.

Counting or measuring? I remember the definitions of countable and un-


countable given in the early primary school language classes. I am sure you
will recall them now too. Grain is not countable (unless you want to tell a story
to your niece at bed-time about countless sparrows coming one-by-one to pick
a grain of wheat each). Sand is not, and of course wheat flour is not. Natural
numbers are countable, reals are not.
Suppose we decide that if there is a continous interval, closed or open ([0, 1]
is closed with both the end-points included, etc.), its length is the absolute
numeric difference between its endpoints. The length of a union of disjoint
intervals is the sum of their lengths. Can there be an uncountable set of real
numbers that has no positive length?
Take the [0, 1] closed interval. Take out from this interval its middle third
( 31 , 23 ). Do the same (removal of the middle third) to the remaining thirds each;
and continue ad infinitum. Let us fix some notation. Given an interval S = [a, b],

5
a real number r, Sr = [ ar , rb ]. Similarly S + r = [a + r, b + r]. Thus the nth set
obtained in this process is
 
Cn1 [ Cn1 2
Cn = + ;
3 3 3

starting at C0 = [0, 1]. The Cantor ternary set is the set of all the points in [0, 1]
that are not removed by this process:
\ [
C = lim Cn = Cn = [0, 1]\ ([0, 1]\Cn ).
n
n1 n1

Now let us measure the total length of this set. To obtain it, we measure the
lengths of the removed sets. In each n + 1st iteration, we remove 2n intervals
of length 3n+1 each. In the first iteration 1 = 20 interval of length 13 = 311 , next
4 = 22 intervals of length 19 = 312 each, etc. So the total length removed in the
infinite process is n

X 2n 1 1 23
= lim = 1.
n=0
3n+1 3 n 1 32

Hence the total length of C is 1 1 = 0. Hence it cannot contain any interval of


positive length. But since we are removing only a countable number (sequence)
of subsets, and not obtaining an empty set, the remainder C is uncountable.
Thus we have an uncountable set that is obtained by a countable construction
but without any positive length interval, hence only uncountable singletons. Is
there anything amiss here?

More stories ... they are now pouring in ...

6
Chapter 2

Test 1 and Beyond

First, the solution. For Q3:


% formulacount .m:
f u n c t i o n f =formulacount (No, M1,M2)
% Counts t h e number o f e x p r e s s i o n s t h a t use M1 o p e r a t o r s
% and any number o f non o p e r a t o r l e a v e s o b t a i n e d from M2 d i s t i n c t l a b e l s
% o f which No 1 p o s s i b l e o p e r a t o r s a r e binary , 1 unary
% and l e a v e s may r e p e a t l a b e l s
i f (M1<0)
f =0;
e l s e i f (M1==0)
f =M2;
e l s e i f (M1==1)
f =M2 * (M2+ 1 ) ;
else
f =formulacount (No, M1 1 , M2 ) ;
f o r r = 0 :M1
for k=1: r 1
f += No * formulacount (No, r k 1 , M2) * formulacount (No, k ,M2 ) ;
end
end
end
end
and it works like:
rsjWork$ octave c l i
GNU Octave , v e r s i o n 4 . 0 . 0
Copyright (C) 2015 John W. Eaton and o t h e r s .
This i s f r e e s o f t w a r e ; s e e t h e s o u r c e code f o r copying c o n d i t i o n s .
There i s ABSOLUTELY NO WARRANTY; not even f o r MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE . For d e t a i l s , type warranty .

Octave was c o n f i g u r e d f o r x86 64 pc l i n u x gnu .

A d d i t i o n a l i n f o r m a t i o n about Octave i s a v a i l a b l e a t h t t p ://www. o c t a v e . org .

7
P l e a s e c o n t r i b u t e i f you f i n d t h i s s o f t w a r e u s e f u l .
For more i n f o r m a t i o n , v i s i t h t t p ://www. o c t a v e . org/get involved . html

Read h t t p ://www. o c t a v e . org/bugs . html t o l e a r n how t o submit bug r e p o r t s .


For i n f o r m a t i o n about changes from p re vi ou s v e r s i o n s , type news .

o c t a v e :1 > formulacount ( 9 , 4 , 2 )
ans = 64158
o c t a v e :2 >
To get the actual formulas:
; formulamake . l i s p :
( defun unary ( formula )
( l i s t not formula )
)

( defun j o i n ( formulas op )
( i f formulas
( append
( mapcar ( lambda ( x ) ( l i s t ( f i r s t formulas ) op x ) ) formulas )
( mapcar ( lambda ( x ) ( l i s t x op ( f i r s t formulas ) ) ) ( r e s t formulas ) )
( j o i n ( r e s t formulas ) op )
)
)
)

( defun formulamake ( ops nops v a r s )


( cond
(( < nops 0 ) n i l )
( ( = nops 0 ) v a r s )
(t
( let
( ( s h o r t e r ( formulamake ops ( nops 1 ) v a r s ) ) )
( append ( mapcar ( lambda ( op ) ( j o i n s h o r t e r op ) ) ops ) ( mapcar # unary s h o r t e r ) )
)
)
)
)
and it works like:
r s j @ L i b OptiPlex 3 0 1 0 : / Desktop/Sanchay/Courses/Logic / . Work$ c l i s p
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ + / I 8 8 8 8 8 8
\ + / 8 8 8 ooooo 8oooo
| 8 8 8 8 8
| 8 o 8 8 o 8 8
+ ooooo 8oooooo ooo8ooo ooooo 8

Welcome t o GNU CLISP 2 . 4 9 ( 2 0 1 0 0 7 0 7 ) <h t t p :// c l i s p . cons . org/>

Copyright ( c ) Bruno Haible , Michael S t o l l 1 9 9 2 , 1993

8
Copyright (c) Bruno Haible , Marcus D a n i e l s 1 9 9 4 1 9 9 7
Copyright (c) Bruno Haible , P i e r p a o l o Bernardi , Sam S t e i n g o l d 1998
Copyright (c) Bruno Haible , Sam S t e i n g o l d 1 9 9 9 2 0 0 0
Copyright (c) Sam S t e i n g o l d , Bruno Haible 2 0 0 1 2 0 1 0

Type : h and h i t E n t e r f o r c o n t e x t help .

[1] > ( load formulamake . l i s p )


; ; Loading f i l e formulamake . l i s p . . .
; ; Loaded f i l e formulamake . l i s p
T
[2] > ( formulamake ( or ) 0 ( p q ) )
( P Q)
[3] > ( formulamake ( or ) 1 ( p q ) )
( ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q) ) (NOT P ) (NOT Q) )
[4] > ( formulamake ( or ) 2 ( p q ) )
( ( ( ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q) ) OR ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q ) ) )
( ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q) ) OR (NOT P ) )
( ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q) ) OR (NOT Q) ) ( (NOT P ) OR ( ( P OR P ) ( P OR Q)
(Q OR P ) (Q OR Q ) ) )
( (NOT Q) OR ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q ) ) ) ( (NOT P ) OR (NOT P ) )
( (NOT P ) OR (NOT Q) ) ( (NOT Q) OR (NOT P ) ) ( (NOT Q) OR (NOT Q ) ) )
(NOT ( ( P OR P ) ( P OR Q) (Q OR P ) (Q OR Q ) ) ) (NOT (NOT P ) ) (NOT (NOT Q ) ) )
[5] >

9
Chapter 3

Puzzling Times

3.1 Introduction
So it is the T1 puzzle again:
Your smartphone has a camera-app that can detect two white or two black marbles
together, but cannot tell exactly when a white and a black marble are together or
when there is a single marble. There are nine marbles, each white or black, in a box
and you are blindfolded. You can pick as many marbles as you want, put one or two
on a special dock whereupon the smartphone announces what it detects (or when it
misses). You can also put them in another (initially empty) storage box, or back to
the original box. Suggest a way to count the number of black marbles blindfolded,
using this smartphone and boxes-and-dock arrangement.

We need to formulate this using Horn Clause FOL first: Let us take predi-
cate w(X) as saying X is white; w2(X, Y ) as saying X and Y are declared
white by the smartphone when put on the dock; and b(X), b2(X, Y ) similarly
for black.

X[w(X) b(X)] (3.1)


X, Y [w2(X, Y ) (X = Y )] (3.2)
X, Y [b2(X, Y ) (X = Y )] (3.3)
X[(Y [w2(X, Y )]) w(X)] (3.4)
X[((Y [w2(X, Y )]) (Y, Z[b2(Y, Z) b2(X, Y )])) w(X)] (3.5)

How to count, given some b2(., .) and w2(., .) facts? How to make sure that the
given such facts are enough to give an exact count, or how to give all possible
counts for a given set of insufficient facts? We assume that the rules given
above exhaust the possibilities of having w(X) true.

10

You might also like