Theory
From techniques to a toolkit
Across this unit you met each sutra as a mental shortcut and coded it on its own. Your syllabus asks you to finish by implementing the sutras in a computer lab, gathering them into working code. Since this is the Python subject, you build a small Python toolkit: a few short functions, one per technique, that you can run, test, and reuse.
This closing lesson assembles that toolkit and, importantly, shows how to test each function against ordinary arithmetic, so you trust the code. All outputs here are verified.
Theory
The multiplication and squaring functions
Three of the sutras are calculation shortcuts that map cleanly to functions:
Nikhilam multiplies two numbers near a base (deficiencies, cross-subtract, multiply). Ekadhikena Purvena squares a number ending in 5 (front times one more, append 25). Yavadunam squares a number near a base (number plus deficiency, then deficiency squared).
Each is only a few lines, because each sutra is a compact rule. Gathered together, they form a tiny library of fast special-case calculators, exactly what 'implementing the sutras' means in practice.
Practical
The sutra toolkit (verified outputs)
def nikhilam(a, b, base=100): # multiply near a base
da, db = base - a, base - b
return (a - db) * base + da * db
def square_ending_in_5(n): # Ekadhikena Purvena
f = n // 10
return f * (f + 1) * 100 + 25
def square_near_base(n, base=100): # Yavadunam
d = n - base
return (n + d) * base + d * d
print(nikhilam(97, 96)) # 9312
print(square_ending_in_5(65)) # 4225
print(square_near_base(98)) # 9604
print(square_near_base(103)) # 10609This example runs in Gri-Learn on the web, where you can edit it and see the output.
Theory
An equation-solving function too
Not every sutra is arithmetic. Sankalana-Vyavakalanabhyam solves a pair of simultaneous equations by adding and subtracting, and that too becomes a neat function.
For the sum-and-difference form (x + y = s, x - y = d), the solution is x = (s + d) / 2 and y = (s - d) / 2. So solve_sum_diff(10, 4) returns (7, 3), matching the worked example. Adding an equation-solver to the toolkit shows that the sutras span arithmetic and algebra alike, and both translate directly to code.
Practical
Testing the toolkit against ordinary arithmetic
def solve_sum_diff(s, d): # Sankalana-Vyavakalanabhyam
return (s + d) // 2, (s - d) // 2
# TEST each function against Python's own arithmetic:
assert nikhilam(97, 96) == 97 * 96 # 9312
assert square_ending_in_5(65) == 65 ** 2 # 4225
assert square_near_base(98) == 98 ** 2 # 9604
assert solve_sum_diff(10, 4) == (7, 3)
print("All sutra functions match ordinary arithmetic.")This example runs in Gri-Learn on the web, where you can edit it and see the output.
Quiz
In the toolkit, square_near_base(103) implements Yavadunam. What does it return?
- 10309, an approximation
- 10609, because 103 squared is 10609 (deficiency +3: 103+3=106, 3 squared = 09)
- 1069, dropping a digit
- It raises an error, because 103 is above the base
Show the answer
10609, because 103 squared is 10609 (deficiency +3: 103+3=106, 3 squared = 09)
square_near_base(103) computes the excess d = 103 - 100 = 3, the left part 103 + 3 = 106, and the right part 3 squared = 9 (padded to 09), giving 106 | 09 = 10609, which is exactly 103 squared. Option A is a vague wrong value; the method is exact, not approximate. Option C drops a digit through faulty place-value. Option D is wrong: Yavadunam handles numbers ABOVE the base fine, the deficiency is simply positive (an excess), and the same formula applies. The toolkit function returns 10609, and testing it with assert square_near_base(103) == 103 ** 2 confirms it.
Think first
Why test each sutra function with assert against ordinary multiplication?
The sutras are supposed to be correct, so why bother asserting each function equals normal arithmetic? Then tap.
Show the answer
Because implementing a correct METHOD does not guarantee correct CODE, and an automatic test catches the gap between them instantly. The sutra itself may be sound, but your function could still have a bug: an off-by-one in the front digit, wrong padding of the right part, an integer-division slip, a sign error in the deficiency. Writing assert nikhilam(97, 96) == 97 * 96 pins the function against Python's own reliable multiplication, so if your implementation is even slightly off, the assert fails loudly and you fix it before trusting the code. This is exactly why the earlier lessons kept CHECKING each shortcut against ordinary arithmetic (the whole 'verify by execution' habit): the ordinary calculation is the ground truth, and the fast method must match it. Turning that check into an assert makes it automatic and repeatable, you can rerun all the tests any time you change the code, and they silently confirm nothing broke. It is the same discipline as unit testing in real software: a function is only trustworthy once it is tested against known-correct results. It also documents intent (the assert states what the function should produce) and guards against future edits. So the tests are not redundant with the sutras' correctness; they verify that your TRANSLATION of the sutra into code is faithful. Method plus tested implementation equals code you can rely on. Trust, but verify, with an assert.
Theory
BCA602 complete
You have analysed a real dataset end to end, exploring it, understanding its types and shape, automating EDA with pandas, and stepping into regression and machine learning, and you have implemented a toolkit of classical calculation techniques in Python. That is the full arc of Data Analytics using Python. Follow your institute's own guidance for this unit; present each technique as the method it encodes, from the prescribed text, and cite your source. A strong finish to the subject.
Summary
Key takeaways
- The syllabus asks you to implement the sutras in code; this Python subject builds a small Python toolkit.
- nikhilam multiplies near a base: nikhilam(97, 96) = 9312.
- square_ending_in_5 (Ekadhikena) squares numbers ending in 5: square_ending_in_5(65) = 4225.
- square_near_base (Yavadunam) squares near a base: square_near_base(98) = 9604 and (103) = 10609.
- solve_sum_diff (Sankalana-Vyavakalanabhyam) solves the sum-and-difference system: solve_sum_diff(10, 4) = (7, 3).
- Test each function with assert against ordinary arithmetic, so you trust the implementation, not just the method.
- Memory hook: each sutra becomes a short tested function; verify the code against plain arithmetic.