Theory
From verse to code
The last two topics covered the Lilavati's documented mathematics: a multiplication method that breaks numbers into parts, and the right-triangle relationship. Your syllabus asks you to do something satisfying with them: implement them in code.
This is a normal programming exercise, exactly the kind you have done since BCA104: take a well-defined method and express it as a function. It connects a nearly-900-year-old mathematical text to the coding skills you have built across your BCA. This lesson shows both methods as short Python programs, with their outputs, so you can see classical arithmetic run on a modern machine.
Theory
Implementing the multiplication method
The Lilavati's part-by-part multiplication (from topic 1) breaks the multiplier into place-value parts and sums the partial products, which is the distributive law. In code, the simplest faithful version splits the multiplier digit by digit (by place value), multiplies, and adds.
For the worked example 125 × 12, splitting 12 into 10 + 2 gives 125×10 + 125×2 = 1250 + 250 = 1500. A program can generalise this. (Of course Python's * multiplies directly; the point of the exercise is to EXPRESS the documented METHOD, showing how the historical technique maps to code, not to replace the operator.)
Practical
Part-by-part multiplication (the documented method)
# Multiply by breaking the multiplier into place-value parts,
# summing partial products (the Lilavati's distributive method).
def multiply_by_parts(a, b):
total = 0
place = 1 # 1, 10, 100, ... (place values)
for digit in reversed(str(b)): # process b digit by digit
total += a * int(digit) * place
place *= 10
return total
print(multiply_by_parts(125, 12)) # 1500
# 125*2*1 + 125*1*10 = 250 + 1250 = 1500
This example runs in Gri-Learn on the web, where you can edit it and see the output.
Practical
The right-triangle relationship in code
import math
# Check the right-triangle relationship: a^2 + b^2 == c^2
def is_right_triangle(a, b, c):
return a*a + b*b == c*c
# Or compute the hypotenuse from the two shorter sides:
def hypotenuse(a, b):
return math.sqrt(a*a + b*b)
print(is_right_triangle(3, 4, 5)) # True (9 + 16 = 25)
print(hypotenuse(3, 4)) # 5.0
print(is_right_triangle(3, 4, 6)) # False (9 + 16 = 25, not 36)
This example runs in Gri-Learn on the web, where you can edit it and see the output.
Quiz
The function is_right_triangle(a, b, c) returns a*a + b*b == c*c. What does is_right_triangle(3, 4, 5) return, and why?
- False, because 3 + 4 is not 5
- True, because 3*3 + 4*4 = 9 + 16 = 25, and 5*5 = 25, so the equality holds
- An error
- True, but only by coincidence
Show the answer
True, because 3*3 + 4*4 = 9 + 16 = 25, and 5*5 = 25, so the equality holds
The function checks aa + bb == cc: for 3, 4, 5 that is 9 + 16 = 25 on the left and 55 = 25 on the right, so the equality holds and it returns True. This correctly implements the documented right-triangle relationship (the theorem known in the West as Pythagorean). Option A adds the sides instead of squaring them (a common confusion the code avoids). Option C is wrong: the code runs fine. Option D undersells it: 3-4-5 satisfying the relationship is not coincidence, it is a genuine right triangle, and the method identifies it correctly. The exercise shows how documented historical mathematics maps directly and cleanly to a few lines of code.
Think first
Why implement a method Python could do with *?
Python multiplies with a simple *, so why bother coding the Lilavati's part-by-part method? What is the educational value? Then tap.
Show the answer
The value is not to REPLACE the * operator but to UNDERSTAND and EXPRESS the historical method, and to connect two things you have learned: classical mathematics and programming. Implementing the part-by-part multiplication forces you to understand HOW the method works (splitting by place value, summing partial products), which deepens your grasp of both the historical technique AND the distributive principle underneath. It is the same educational reason you once implemented sorting or searching by hand rather than calling a library: coding a method teaches the method. It also demonstrates that documented mathematics from centuries ago maps cleanly onto modern code, a nice bridge across time. So the exercise is about comprehension and connection, not efficiency. The insight transfers: to truly understand an algorithm, implement it.
Watch out
Implementation traps
Adding sides instead of squaring: the right-triangle check is aa + bb == c*c, not a + b.
c squared vs c: c*c is 25 for a 5-side; c itself is 5 (take the square root for the length).
Floating-point comparison: math.sqrt returns a float; comparing floats for exact equality can be fragile, prefer the squared-form check (aa + bb == c*c) with integers.
Fabricating verse text in comments: keep code comments factual; cite the method, not invented shlokas.
Overcomplicating: a faithful, simple implementation beats a clever obscure one.
Theory
Methods coded; now the capstone project
You have implemented the Lilavati's documented methods in Python, bridging historical mathematics and modern code. The final topic of the whole subject is the capstone PROJECT: building a small application based on Units 1 to 3 (MongoDB, React, Angular). The next lesson gives guidance on scoping and building it well, tying together everything you learned in Advance Web Designing.
Summary
Key takeaways
- The syllabus asks you to implement the Lilavati's documented methods in code (Python/C): a normal programming exercise.
- The part-by-part multiplication (distributive method) can be coded by splitting the multiplier by place value and summing partial products: multiply_by_parts(125, 12) = 1500.
- The right-triangle relationship is coded as aa + bb == c*c: is_right_triangle(3, 4, 5) is True (9 + 16 = 25).
- Compute the hypotenuse as math.sqrt(aa + bb): hypotenuse(3, 4) = 5.0.
- The value is understanding and connecting the historical method to code, not replacing built-in operators.
- Prefer the integer squared-form check over float comparison; keep comments factual (no fabricated verses).
- Memory hook: documented math maps to a few clean lines of code.