Skip to content

Dwandwa Yoga — Duplex Method for Squaring Any Number

DodaTech Updated 2026-06-23 9 min read

In this tutorial, you'll learn about Dwandwa Yoga. We cover key concepts, practical examples, and best practices.

Dwandwa Yoga (Duplex Method) is a Vedic sutra that squares any number — not just those ending in 5 — using a simple cross-multiplication pattern called the duplex.

ℹ️ Info

What you'll learn: The Dwandwa Yoga duplex method for squaring 2-digit, 3-digit, and 4-digit numbers mentally. Why it matters: This single method replaces all other squaring techniques and works for any number with equal speed. Real-world use: Financial analysts compute squares of stock prices instantly; competitive exam takers solve square problems in 5 seconds; programmers use the duplex pattern in checksum algorithms.

The Sutra: Duplex (Dwandwa) Method

The Dwandwa Yoga sutra computes the square of a number by calculating the duplex of each digit group. The duplex D of a number is defined as:

  • For a single digit a: D = a^2
  • For two digits a and b: D = 2ab
  • For three digits a, b, c: D = 2ac + b^2
  • For four digits a, b, c, d: D = 2ad + 2bc

The square is constructed by arranging the duplex values of all groups, propagating carries from right to left.

Duplex Flow

flowchart TD
    A["Number to square
e.g., 234"] --> B["Identify digits
a=2, b=3, c=4"] B --> C["Compute duplex of each group"] C --> D["D(4) = 4² = 16"] C --> E["D(34) = 2×3×4 = 24"] C --> F["D(234) = 2×2×4 + 3² = 16+9 = 25"] C --> G["D(23) = 2×2×3 = 12"] C --> H["D(2) = 2² = 4"] D --> I["Arrange: 4 | 12 | 25 | 24 | 16"] E --> I F --> I G --> I H --> I I --> J["Carry propagation
right to left"] J --> K["234² = 54756"] style A fill:#1a73e8,color:#fff,stroke:none style B fill:#34a853,color:#fff,stroke:none style C fill:#fbbc04,color:#333,stroke:none style J fill:#ea4335,color:#fff,stroke:none style K fill:#46bdc6,color:#fff,stroke:none

Worked Examples

Example 1: 32² (2-digit)

Digits: a = 3, b = 2

Step 1: Compute duplex values.

  • D(a) = 3² = 9
  • D(ab) = 2 x 3 x 2 = 12
  • D(b) = 2² = 4

Step 2: Write as 9 | 12 | 4.

Step 3: Propagate carries right to left.

  • 4 stays.
  • 12 → write 2, carry 1.
  • 9 + 1 = 10 → write 0, carry 1.

Answer: 1024

Check: 32 x 32 = 1024

Example 2: 47² (2-digit)

Digits: a = 4, b = 7

Step 1: Compute duplex.

  • D(4) = 16
  • D(47) = 2 x 4 x 7 = 56
  • D(7) = 49

Step 2: Write as 16 | 56 | 49.

Step 3: Carry propagation.

  • 49 → write 9, carry 4.
  • 56 + 4 = 60 → write 0, carry 6.
  • 16 + 6 = 22.

Answer: 2209

Check: 47 x 47 = 2209

Example 3: 234² (3-digit)

Digits: a = 2, b = 3, c = 4

Step 1: Compute duplex of each group.

  • D(2) = 2² = 4
  • D(23) = 2 x 2 x 3 = 12
  • D(234) = 2 x 2 x 4 + 3² = 16 + 9 = 25
  • D(34) = 2 x 3 x 4 = 24
  • D(4) = 4² = 16

Step 2: Write as 4 | 12 | 25 | 24 | 16.

Step 3: Carry propagation.

  • 16 → write 6, carry 1.
  • 24 + 1 = 25 → write 5, carry 2.
  • 25 + 2 = 27 → write 7, carry 2.
  • 12 + 2 = 14 → write 4, carry 1.
  • 4 + 1 = 5.

Answer: 54756

Check: 234 x 234 = 54756

Example 4: 1024² (4-digit)

Digits: a = 1, b = 0, c = 2, d = 4

Step 1: Compute duplex of each group.

  • D(1) = 1² = 1
  • D(10) = 2 x 1 x 0 = 0
  • D(102) = 2 x 1 x 2 + 0² = 4 + 0 = 4
  • D(1024) = 2 x 1 x 4 + 2 x 0 x 2 = 8 + 0 = 8
  • D(024) = 2 x 0 x 4 + 2² = 0 + 4 = 4
  • D(24) = 2 x 2 x 4 = 16
  • D(4) = 4² = 16

Step 2: Write as 1 | 0 | 4 | 8 | 4 | 16 | 16.

Step 3: Carry propagation.

  • 16 → write 6, carry 1.
  • 16 + 1 = 17 → write 7, carry 1.
  • 4 + 1 = 5.
  • 8 stays.
  • 4 stays.
  • 0 stays.
  • 1 stays.

Answer: 1048576

Check: 1024 x 1024 = 1048576

Example 5: 999² (3-digit near base)

Digits: a = 9, b = 9, c = 9

Step 1: Compute duplex.

  • D(9) = 81
  • D(99) = 2 x 9 x 9 = 162
  • D(999) = 2 x 9 x 9 + 9² = 162 + 81 = 243
  • D(99) = 162
  • D(9) = 81

Step 2: Write as 81 | 162 | 243 | 162 | 81.

Step 3: Carry propagation.

  • 81 → write 1, carry 8.
  • 162 + 8 = 170 → write 0, carry 17.
  • 243 + 17 = 260 → write 0, carry 26.
  • 162 + 26 = 188 → write 8, carry 18.
  • 81 + 18 = 99.

Answer: 998001

Check: 999 x 999 = 998001

Code Snippet: Python Implementation

def duplex(n):
    """Compute the duplex of a list of digits."""
    count = len(n)
    if count == 1:
        return n[0] ** 2
    elif count == 2:
        return 2 * n[0] * n[1]
    elif count == 3:
        return 2 * n[0] * n[2] + n[1] ** 2
    elif count == 4:
        return 2 * n[0] * n[3] + 2 * n[1] * n[2]
    else:
        # Generalized: outer pairs + middle if odd
        total = 0
        for i in range(count // 2):
            total += 2 * n[i] * n[count - 1 - i]
        if count % 2 == 1:
            total += n[count // 2] ** 2
        return total


def dwandwa_square(num):
    """Square a number using Dwandwa Yoga duplex method."""
    digits = [int(d) for d in str(num)]
    n = len(digits)
    result = []

    for width in range(1, n + 1):
        group = digits[:width]
        result.append(duplex(group))

    for width in range(n - 1, 0, -1):
        group = digits[-width:]
        result.append(duplex(group))

    # Carry propagation
    carry = 0
    final = []
    for val in reversed(result):
        val += carry
        final.append(str(val % 10))
        carry = val // 10
    while carry:
        final.append(str(carry % 10))
        carry //= 10

    return int(''.join(reversed(final)))


tests = [32, 47, 234, 1024, 999]
for t in tests:
    result = dwandwa_square(t)
    expected = t ** 2
    status = "OK" if result == expected else "FAIL"
    print(f"{t}^2 = {result} ({status})")

Expected output:

32^2 = 1024 (OK)
47^2 = 2209 (OK)
234^2 = 54756 (OK)
1024^2 = 1048576 (OK)
999^2 = 998001 (OK)

Code Snippet: JavaScript Implementation

function duplex(digits) {
    const n = digits.length;
    if (n === 1) return digits[0] ** 2;
    if (n === 2) return 2 * digits[0] * digits[1];
    if (n === 3) return 2 * digits[0] * digits[2] + digits[1] ** 2;
    if (n === 4) return 2 * digits[0] * digits[3] + 2 * digits[1] * digits[2];

    let total = 0;
    for (let i = 0; i < Math.floor(n / 2); i++) {
        total += 2 * digits[i] * digits[n - 1 - i];
    }
    if (n % 2 === 1) total += digits[Math.floor(n / 2)] ** 2;
    return total;
}

function dwandwaSquare(num) {
    const digits = String(num).split('').map(Number);
    const n = digits.length;
    const result = [];

    for (let w = 1; w <= n; w++) result.push(duplex(digits.slice(0, w)));
    for (let w = n - 1; w > 0; w--) result.push(duplex(digits.slice(-w)));

    let carry = 0;
    const final = [];
    for (const val of result.reverse()) {
        const v = val + carry;
        final.push(v % 10);
        carry = Math.floor(v / 10);
    }
    while (carry > 0) {
        final.push(carry % 10);
        carry = Math.floor(carry / 10);
    }
    return parseInt(final.reverse().join(''));
}

[32, 47, 234, 1024, 999].forEach(t => {
    console.log(`${t}^2 = ${dwandwaSquare(t)}`);
});

Expected output:

32^2 = 1024
47^2 = 2209
234^2 = 54756
1024^2 = 1048576
999^2 = 998001

Common Errors

  1. Forgetting to include all group duplex values. For a 3-digit number, you need 5 groups (expanding out from the center). For a 4-digit number, you need 7 groups. Always expand from 1 digit to full, then back to 1 digit.

  2. Using the wrong duplex formula for each group width. A 2-digit group uses 2ab, not a^2 + b^2. A 3-digit group uses 2ac + b^2, not 2ab + 2bc.

  3. Skipping carry propagation from right to left. Carries must be propagated sequentially from the rightmost duplex value to the left. Skipping this step gives an incorrect result.

  4. Mishandling zero digits. Zero digits are valid — they produce zero cross-products but still contribute to the duplex. For 1024, D(102) = 2x1x2 + 0^2 = 4, not 0.

  5. Applying Dwandwa Yoga to non-integers. This method works for integers only. For decimals, square the integer part and adjust the decimal point afterward.

Practice Questions

  1. 56^2 = ?
  2. 123^2 = ?
  3. 2048^2 = ?

Answers:

  1. 56^2 = 3136 (D(5)=25, D(56)=60, D(6)=36 → 25|60|36 → 3136)
  2. 123^2 = 15129 (D(1)=1, D(12)=4, D(123)=2x1x3+2^2=10, D(23)=12, D(3)=9 → 1|4|10|12|9 → 15129)
  3. 2048^2 = 4194304

Mini Project: Square Speed Test

import time

def speed_test(numbers):
    """Compare Dwandwa Yoga vs standard multiplication."""
    for n in numbers:
        start = time.perf_counter()
        r1 = dwandwa_square(n)
        t1 = time.perf_counter() - start

        start = time.perf_counter()
        r2 = n ** 2
        t2 = time.perf_counter() - start

        print(f"{n}^2 = {r1} | Dwandwa: {t1:.6f}s | Standard: {t2:.6f}s | Match: {r1==r2}")

speed_test([32, 123, 999, 2048, 9999])

FAQ

What does Dwandwa Yoga mean literally?

"Dwandwa" means "pair" or "duplex" in Sanskrit. The sutra refers to the method of pairing digits and computing cross-products to find the square of any number.

Does this work for numbers with an odd number of digits?

Yes. For odd-digit numbers, the middle digit forms a single-digit group and contributes its own square (b^2) in addition to the cross-products of outer pairs.

Can I use Dwandwa for decimal numbers?

For decimals, square the integer part using Dwandwa Yoga, then adjust the decimal point. For example, 3.2^2 = (32^2)/(10^2) = 1024/100 = 10.24.

How is this different from Ekadhikena Purvena?

Ekadhikena Purvena only works for numbers ending in 5. Dwandwa Yoga works for any number. The duplex method is universal and considered the most powerful Vedic squaring technique.

Next Steps

Continue with Yavadunam Tavadunam for cube computations using the Vedic method.

Related tutorials:

  • Ekadhikena Purvena — squaring numbers ending in 5
  • Vedic Maths Overview — introduction to all Vedic sutras

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro