ENع
→Logs and exponents
الدرس 12 · الرياضيات المتقطّعة

Logarithms and exponents

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

14 دقيقة9 خطوات5 أسئلةIntermediate
عن هذا الدرس

An exponent counts how many times you multiply; a logarithm counts it backwards. Follow one number, 64 = 2⁶: double from 1 six times to build it, then run a binary search that halves 64 items six times down to one. That count, 6, is log₂(64), and it is why searching a million sorted items takes only about 20 steps.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 12 · تفاعلي
01 / 09

Exponents: repeated doubling

An exponent counts repeated multiplication. 2⁶ means six 2s multiplied: 2×2×2×2×2×2 = 64. Start from 1 and double six times. The exponent counts the doublings, and the board lights 1, 2, 4, 8, 16, 32, then 64 squares.

>>> 2 ** 6
64
>>> 2 * 2 * 2 * 2 * 2 * 2
64
>>> [2 ** i for i in range(7)]
[1, 2, 4, 8, 16, 32, 64]
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Exponents: repeated doubling

    An exponent counts repeated multiplication. 2⁶ means six 2s multiplied: 2×2×2×2×2×2 = 64. Start from 1 and double six times. The exponent counts the doublings, and the board lights 1, 2, 4, 8, 16, 32, then 64 squares.

    >>> 2 ** 6
    64
    >>> 2 * 2 * 2 * 2 * 2 * 2
    64
    >>> [2 ** i for i in range(7)]
    [1, 2, 4, 8, 16, 32, 64]
  2. Why 2⁰ is 1

    Walk the powers backwards and each step divides by 2: 2² = 4, 2¹ = 2, 2⁰ = 1. That is why 2⁰ is 1, not 0. One more step gives a fraction: 2⁻¹ = 1/2.

    >>> 2 ** 0
    1
    >>> 2 ** -1
    0.5
    >>> 2 ** -3                 # 1/8
    0.125
  3. Multiply: exponents add

    Multiplying powers of the same base adds their exponents: 2² × 2⁴ = 4 × 16 = 64 = 2⁶, and 2 + 4 = 6. Two doublings and then four more are six doublings in all.

    >>> 2 ** 2 * 2 ** 4
    64
    >>> 2 ** (2 + 4)
    64
    >>> (2 ** 3) ** 2          # a power of a power multiplies
    64
  4. A log undoes a power

    A logarithm asks the reverse question. log₂(64) means: 2 to what power gives 64? Find 64 among the powers of 2. It sits in the 2⁶ cell, so log₂(64) = 6. A log always answers with an exponent.

    >>> import math
    >>> math.log2(64)
    6.0
    >>> 2 ** 6                  # the check
    64
  5. Count the halvings

    A log also counts halvings. To find item 22 among 64 sorted items, check the middle and keep the half that holds it. After six halvings one item is left, so log₂(64) = 6. This is binary search.

    >>> lo, hi, n = 1, 64, 0
    >>> while lo < hi:
    ...     mid = (lo + hi) // 2
    ...     if 22 <= mid: hi = mid
    ...     else: lo = mid + 1
    ...     n += 1
    ...
    >>> lo, n
    (22, 6)
  6. Logs turn × into +

    Exponents add when powers multiply, so logs turn multiplication into addition: log₂(4 × 16) = log₂ 4 + log₂ 16 = 2 + 4 = 6. This product rule works for any positive numbers, not just powers of 2.

    >>> import math
    >>> math.log2(4) + math.log2(16)
    6.0
    >>> math.log2(4 * 16)
    6.0
  7. Between two powers

    Most numbers are not exact powers of 2. 1000 lies between 2⁹ = 512 and 2¹⁰ = 1024, so log₂(1000) ≈ 9.97. Its whole part, 9, plus one gives 10: the number of bits 1000 needs in binary.

    >>> import math
    >>> math.log2(1000)
    9.965784284662087
    >>> bin(1000)
    '0b1111101000'
    >>> (1000).bit_length()
    10
  8. Logs grow slowly

    Logs grow very slowly. 2²⁰ = 1,048,576, just over a million, so log₂ of a million is about 19.9. Binary search through a million sorted items needs at most 20 checks. Reading them one by one could take a million.

    >>> import math
    >>> 2 ** 20
    1048576
    >>> math.log2(1_000_000)
    19.931568569324174
    >>> math.floor(math.log2(1_000_000)) + 1
    20
  9. Other bases

    Logs work in any base. log₁₀(1000) = 3, because 10³ = 1000: count the zeros. Changing base only multiplies a log by a fixed number, about 3.32 from base 10 to base 2. So growth estimates often just write log n.

    >>> import math
    >>> math.log10(1000)
    3.0
    >>> math.log2(1000) / math.log10(1000)
    3.321928094887362
    >>> math.log2(10)
    3.321928094887362

اختبار يتاح بعد الخطوة الأخيرة.