Theory
The vending machine test
देखिए, एक vending machine का बस एक ही काम होता है: आपने B4 दबाया, तो जो item B4 पर रखा है वही मिलेगा। हर button आपको कुछ न कुछ देता है, और कभी अलग-अलग दिन अलग-अलग चीज़ नहीं देता।
अब सोचिए एक खराब machine: कुछ buttons कुछ देते ही नहीं, और एक button कभी chips तो कभी cold drink दे देता है। तो आप उस पर भरोसा करना बंद कर देंगे, है ना?
तो जिस machine पर आप भरोसा कर सकें, उसे mathematics में एक नाम दिया गया है: function।
Theory
Input goes in, one output comes out
हर function वही भरोसे वाली machine है: आप allowed inputs के एक fixed set में से एक input डालिए, तो वो आपको exactly one output लौटाएगा। कल भी वही input डाला, तो कल भी वही output। पूरी formal definition बस इसी promise को symbols में लिखने का तरीका है।
Theory
The definition, formally
मान लीजिए A और B 2 sets हैं। तो function f: A → B एक ऐसा rule है जो A के each element a ∈ A को B का exactly one element assign करता है, जिसे हम f(a) लिखते हैं।
अब इस एक sentence में 2 conditions छिपी हुई हैं:
- each: A का कोई भी element output के बिना नहीं रहना चाहिए
- exactly one: A का कोई भी element 2 outputs नहीं ले सकता
इनमें से एक भी condition टूटी, तो वो rule function नहीं रहा।
Theory
Domain, codomain, range
मान लीजिए f: A → B है:
- Domain = A, यानी allowed inputs का set
- Codomain = B, यानी वो set जहाँ से outputs आने declared किए गए हैं
- Range = वो outputs जो actually निकलते हैं
Example लीजिए: f: ℤ → ℤ जिसमें f(x) = 2x। यहाँ domain और codomain दोनों सारे integers हैं, लेकिन range सिर्फ even integers है। Range हमेशा codomain के अंदर ही बैठती है: range ⊆ codomain।
Quiz
f: ℤ → ℤ जिसमें f(x) = x², तो इसकी range क्या होगी?
- सारे integers, codomain जितने ही
- Perfect squares {0, 1, 4, 9, 16, ...}
- सारे non-negative integers {0, 1, 2, 3, ...}
- सारे even integers
Show the answer
Perfect squares {0, 1, 4, 9, 16, ...}
Range वो है जो machine actually बनाती है: 0, 1, 4, 9, 16 वगैरह। Codomain तो पूरा ℤ declared है, लेकिन इससे हर integer output नहीं बन जाता। Option A और C तो range-vs-codomain की वही classic गलतियाँ हैं जो students अक्सर करते हैं।
Think first
2 rules हैं, दोनों people को people या numbers से map करते हैं। हर एक के लिए decide कीजिए: function है या नहीं?
1. हर person → उसका Aadhaar number
2. हर person → उसका parent
Show the answer
1 एक function है: एक person, एक Aadhaar number।
2 function नहीं है: एक person के 2 parents होते हैं, तो एक input से 2 outputs निकल रहे हैं, यानी "exactly one" टूट गया। और अगर कोई rule किसी person को output ही न दे, तो "each" टूट जाएगा। किसी rule के fail होने के बस यही 2 तरीके हैं।
Theory
The rule polices inputs, not outputs
अब फिर से f(x) = x² देखिए: f(2) = 4 और f(−2) = 4। 2 अलग-अलग inputs, पर output एक ही।
ये बिल्कुल allowed है। Definition कहीं नहीं कहती कि outputs अलग-अलग होने चाहिए। वो सिर्फ इतना कहती है कि एक input 2 outputs में नहीं बँट सकता।
Inputs वैसे behave करते हैं जैसे students अपने roll numbers के साथ: हर student का exactly one roll number होता है, लेकिन 2 students के marks same हो सकते हैं।
Quiz
इनमें से कौन सा आपके classmates के set से numbers तक एक function IS?
- हर student → Maths में जो marks उसने score किए
- हर student → उसके siblings की ages
- हर student → जो subjects उसे पसंद हैं
- हर student → एक number, जो उसके पास हो भी सकता है और नहीं भी
Show the answer
हर student → Maths में जो marks उसने score किए
Marks हर student को exactly one number देते हैं। Siblings की ages कोई हो ही न, या कई हों (दोनों conditions टूटीं), पसंद के subjects कई हो सकते हैं ("exactly one" टूटा), और "हो भी सकता है नहीं भी" वाला case "each" तोड़ देता है। Function में न कोई gap चलता है, न कोई double।
Watch out
जो trap marks खा जाता है
Students अक्सर valid functions को reject कर देते हैं यह कहकर कि "2 inputs same output दे रहे हैं"। अरे, वो तो allowed है! f(x) = x² एक function ही है। सिर्फ ये 2 असली conditions check कीजिए: हर input covered हो, और हर एक को एक ही output मिले। और बिना check किए कभी मत लिख दीजिए कि range = codomain; ज़्यादातर तो होती ही नहीं।
Formula
The two-question exam check
कोई भी rule दिया हो और पूछा जाए "is it a function?", तो 2 checks से answer दीजिए: (1) क्या domain का every element को output मिलता है? (2) क्या किसी element को एक से ज़्यादा output मिलता है? अगर 1 का जवाब हाँ और 2 का जवाब ना, तो वो function है। Full marks के लिए answer में दोनों checks लिखिए।
Theory
यह आपको फिर कहाँ मिलेगा
C या Python में आप जो भी function लिखेंगे, वो यही idea है: arguments अंदर, एक return value बाहर। एक database primary key भी हर key को exactly one row से map करती है, इसी वजह से। और आगे के topics सीधे आज की बात पर बनते हैं: पहले domain और range detail में, फिर types of functions।
Summary
Key takeaways
- Function f: A → B, A के हर element को B का exactly one element देता है।
- Domain = allowed inputs, codomain = declared output set, range = actual outputs, और range ⊆ codomain।
- एक rule सिर्फ 2 तरह से fail होता है: कोई input बिना output के, या कोई input 2 outputs के साथ।
- अलग-अलग inputs का एक ही output share करना allowed है: f(x) = x² इसका सबूत है।
- याद रखने का तरीका: one input, one output, कोई बहाना नहीं।