Theory
The sentence a computer can judge
ज़रा ये 4 sentences पढ़िए:
1. "2 + 3 = 5"
2. "Close the door."
3. "Is it raining?"
4. "Maths is beautiful."
इनमें से सिर्फ एक को computer पूरे भरोसे के साथ TRUE या FALSE का mark दे सकता है, वो है पहला वाला। Commands, questions और opinions का कोई truth value नहीं होता।
Logic असल में पहले जैसे sentences की mathematics है, और आपका code आगे जो भी decision लेगा, सब इसी पर चलता है।
Theory
Grammar for reasoning
जैसे किसी भाषा में grammar होती है ताकि sentences का मतलब बने, वैसे ही reasoning में logic होती है ताकि argument टिका रहे। Grammar बताती है कि "went I home" गलत है, भले ही सारे words सही हों; उसी तरह logic बताती है कि argument गलत है, भले ही सुनने में वो convincing लगे। ये सोच की quality control है।
Theory
Propositions: the atoms of logic
एक proposition वो declarative sentence है जो या तो true हो या false, दोनों एक साथ नहीं।
Propositions: "Delhi is the capital of India" (T), "7 is even" (F).
ये propositions नहीं हैं: "What time is it?" (question), "Please sit down" (command), "Biryani is tasty" (opinion), "x + 1 = 5" (ये x पर depend करता है, तो कोई fixed truth value नहीं)।
Propositions को हम letters से नाम देते हैं: P, Q, R.
Quiz
इनमें से कौन-सा एक proposition है?
- "Solve question 5."
- "Every even number greater than 2 is not prime."
- "How difficult is this exam?"
- "x is greater than 10."
Show the answer
"Every even number greater than 2 is not prime."
Option B declarative है और पक्का true या false है (यहाँ ये true है)। Command और question का कोई truth value नहीं होता, और "x > 10" का तब तक कोई fixed truth value नहीं जब तक x पता न हो, यही वो trap है जिसमें ज़्यादातर students फँसते हैं। Exams में variable वाला distractor बहुत आता है।
Theory
Three basic connectives
Compound statements simple statements से connectives लगाकर बनते हैं:
- NOT (negation) ¬P: P का truth value उल्टा कर देता है
- AND (conjunction) P ∧ Q: तभी true जब दोनों true हों
- OR (disjunction) P ∨ Q: तब true जब कम से कम एक true हो
Logic का OR inclusive होता है: logic में "tea or coffee" में दोनों भी चल जाते हैं। बस इसी एक convention से beginners की ज़्यादातर confusion खत्म हो जाती है।
Think first
P = "7 is odd" (true)। Q = "7 is prime" (true)। R = "7 is even" (false)।
अब इनके truth values निकालिए: ¬R, P ∧ R, P ∨ R. फिर tap कीजिए।
Show the answer
¬R = T (false को उल्टा करने पर true मिलता है)।
P ∧ R = F (AND को दोनों चाहिए; R तो fail है)।
P ∨ R = T (OR को बस एक चाहिए; P काम कर देता है)।
देखिए ये कितना mechanical है: न कोई opinion, न कोई context, बस truth values पर rules लगाना। यही mechanical होना असल में वजह है कि computers logic कर पाते हैं।
Theory
Two more: if-then, if-and-only-if
- Implication P → Q: "if P then Q", हर rule और हर
ifstatement की भाषा यही है। ये सिर्फ तब false होता है जब P हो जाए पर Q न हो। - Biconditional P ↔ Q: "P if and only if Q", ये तभी true होता है जब P और Q दोनों का truth value same हो।
Example: "If it rains, the ground gets wet" एक implication है; "you pass if and only if you score 40 or more" एक biconditional है।
Quiz
"If you top the exam, I will buy you a phone." आपने exam top नहीं किया, और कोई phone भी नहीं मिला। क्या promise टूटा?
- हाँ, phone तो नहीं आया
- नहीं, promise सिर्फ top करने वाले case को cover करता है
- तय नहीं किया जा सकता
- ये sentence proposition ही नहीं है
Show the answer
नहीं, promise सिर्फ top करने वाले case को cover करता है
एक implication P → Q सिर्फ तभी टूटता है जब P true हो और Q false। यहाँ P ("you top") false है, इसलिए आगे कुछ भी हो, promise टूटा नहीं माना जाएगा। यही exact idea अगले topic में implication truth table की एक row बन जाता है, जहाँ बहुत से students फिसल जाते हैं।
Watch out
The classification traps
3 sentences जो exams में students को फँसा देते हैं: "x + 1 = 5" (जब तक x तय न हो, ये proposition नहीं), "This statement is false" (ये एक paradox है, न true न false, इसलिए proposition नहीं), और opinions जो facts का चोला पहने होते हैं ("C is the best language")। जब classify करने को कहें, तो हमेशा reason दीजिए: इसका definite truth value है, या नहीं है।
Theory
Where you will meet this again
आप जो भी condition लिखेंगे, जैसे if (marks >= 40 && attendance >= 75), वो असल में P ∧ Q ही है, बस C के कपड़ों में; और databases WHERE clauses से filter करते हैं जो AND, OR, NOT से ही बनते हैं। अगला topic, truth tables, आज के इन connectives को एक systematic calculation tool बना देता है, और आगे चलकर Boolean algebra इन्हीं T और F को 1 और 0 का नया नाम दे देती है।
Summary
Key takeaways
- Proposition वो declarative sentence है जो exactly true या false, दोनों में से एक होता है।
- Questions, commands, opinions, paradoxes और variables वाले open sentences propositions नहीं होते।
- NOT उल्टा करता है, AND को दोनों चाहिए, OR (inclusive) को कम से कम एक चाहिए।
- P → Q सिर्फ तब fail होता है जब P true और Q false; P ↔ Q तब true जब दोनों match करें।
- याद रखने का हुक: no truth value, no proposition.