Chapterبەش 6 · Lectureوانە 6.1
Notation in Computing: mod, Bases, Big-O and Code Operatorsهێماکان لە کۆمپیوتەردا: mod، بنچینەکان، نیشانەی O-ی گەورە و کارپێکەرەکانی کۆد
How to read the notation of computing: and vs % and // with negative numbers; base subscripts and the prefixes 0b, 0o, 0x (and Java's leading-zero octal); powers of two, b, B and Ki; , , Θ and Ω; steps; maths vs Python, Java, MATLAB and Excel operators; indexes from 1 or from 0; σ, π and ⋈ in databases.
چۆن بخوێنیتەوە: و بەرامبەر % و // لەگەڵ ؛ ، و 0b، 0o، 0x (و سفری پێشەوەی Java)؛ 2، b، B و Ki؛ ، ، Θ و Ω؛ هەنگاوەکانی ؛ بیرکاری بەرامبەر Python، Java، MATLAB و Excel؛ لە 1ـەوە یان لە 0ـەوە؛ σ، π و ⋈ لە .
What you will learnچی فێر دەبیت
- Read , , div and , and predict
%and//with negative numbers in Python and Java. - Read base subscripts and code prefixes, check that the digits fit the base, and avoid Java's leading-zero octal.
- Read , Θ and Ω, know that big-O's = goes one way, and count binary-search steps with .
- Translate maths signs into Python, Java, MATLAB and Excel operators (
**vs^,==,!=~=<>,←) and say them in Kurdish. - Move between ,
v(1)andv[0], and read σ, π and ⋈ in a database book.
- ، ، div و بخوێنیتەوە و ئەنجامی
%و//لەگەڵ لە Python و Javaـدا پێشبینی بکەیت. - و کۆد بخوێنیتەوە، بپشکنیت لەگەڵ دەگونجێن و خۆت لە سفری پێشەوەی Java بپارێزیت.
- ، Θ و Ω بخوێنیتەوە، بزانیت =ـی تەنیا یەک ئاڕاستەیە و هەنگاوەکانی بە بژمێریت.
- بیرکاری بکەیت بە Python، Java، MATLAB و Excel (
**بەرامبەر^،==،!=~=<>،←) و بە کوردی بیانخوێنیتەوە. - لە نێوان ،
v(1)وv[0]ـدا بگوازیتەوە و σ، π و ⋈ لە کتێبێکی بخوێنیتەوە.
and و
mod has two jobs. As an operation, is the remainder when a is divided by n: , because . Read it “seventeen mod five”. As a relation, says that a and b leave the same remainder: , “17 is congruent to 2 modulo 5” (≡ and :=). The quotient has names too: or . Always . A clock works mod 12, as the animation shows.
mod دوو کاری هەیە. وەک ، بریتییە لەو کە لە a بەسەر nـدا دەمێنێتەوە: ، چونکە . بیخوێنەوە «17 مۆد 5» یان « 17 بەسەر 5». وەک پەیوەندی، دەڵێت a و b هەمان هەیە: ، بە ئینگلیزی 17 is congruent to 2 modulo 5 ( و ). ئەنجامی ناوی هەیە: یان . هەمیشە . کاتژمێر بە mod 12 کار دەکات، وەک ئەنیمەیشنەکە پیشانی دەدات.


Mod is everywhere in computing. The Caesar cipher shifts letters with , so Z wraps round to A (The oldest example: the Caesar cipher), and a mod-n counter starts again at 0 after n − 1 (Counters that stop early: mod-n).
mod لە هەموو شوێنێکی هەیە. پیتەکان بە دەجووڵێنێت، بۆیە Z دەگەڕێتەوە سەر A (کۆنترین نموونە: شفرەی قەیسەر) و mod-n دوای n − 1 دیسان لە 0ـەوە دەست پێدەکاتەوە (ژمێرەرە دیجیتاڵەکانی mod-n).
% and // in code: watch the negative numbers% و // لە کۆددا: ئاگاداری ژمارە سالبەکان بە
Most languages write mod as %. For positive numbers they all agree: 17 % 5 is 2. For a negative number they do not. Python's % takes the sign of the number you divide by, like in maths, Excel's MOD and MATLAB's mod: -7 % 3 is 2. And Python's // is floor division, : -7 // 3 is −3, because −2.33… rounded down is −3.
زۆربەی زمانەکان mod بە % دەنووسن. بۆ هەموویان کۆکن: 17 % 5 دەکاتە 2. بۆ کۆک نین. %ـی Python نیشانەی ئەو ژمارەیە وەردەگرێت کە بەسەریدا دابەش دەکەیت، وەک لە بیرکاریدا، MODـی Excel و modـی MATLAB: -7 % 3 دەکاتە 2. هەروەها //ـی Python ، : -7 // 3 دەکاتە −3، چونکە −2.33… بەرەو خوار دەبێتە −3.
print(17 % 5, 17 // 5) # remainder, then the floor of 17/5
print(-7 % 3, -7 // 3) # the remainder takes the sign of 3
print(7 % -3, 7 // -3) # ... and here the sign of -3
print(divmod(-7, 3)) # quotient and remainder together
print(-1 % 12) # one hour before 12 o'clock2 3 2 -3 -2 -3 (-3, 2) 11
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
: the remainder 2 has the sign of 3.
: 2 نیشانەی 3ـی هەیە.
- Lineدێڕی 5
The clock of the animation: one hour before 12 is 11.
کاتژمێرەکەی ئەنیمەیشنەکە: یەک کاتژمێر پێش 12 دەکاتە 11.
% and // in code: watch the negative numbers% و // لە کۆددا: ئاگاداری ژمارە سالبەکان بە
Java, C and JavaScript: the sign of the left numberJava، C و JavaScript: نیشانەی ژمارەی لای چەپ
Java, C, C# and JavaScript give % the sign of the left number, like MATLAB's rem. Java, C and C# also cut / on whole numbers toward 0 (JavaScript's / gives −2.33…). So in Java -7 % 3 is −1 and -7 / 3 is −2. For the maths answers Java has Math.floorMod and Math.floorDiv (Negative numbers and %, Dividing whole numbers, Dividing negative numbers).
Java، C، C# و JavaScript نیشانەی ژمارەی لای چەپ دەدەنە %، وەک remـی MATLAB. Java، C و C# هەروەها / بۆ بەرەو 0 دەبڕن (/ـی JavaScript −2.33… دەدات). کەواتە لە Javaـدا -7 % 3 دەکاتە −1 و -7 / 3 دەکاتە −2. بۆ وەڵامەکانی بیرکاری Java Math.floorMod و Math.floorDivـی هەیە (ژمارە سالبەکان و %، دابەشکردنی ژمارەی تەواو، دابەشکردنی ژمارە سالبەکان).
public class Remainders {
public static void main(String[] args) {
System.out.println(17 % 5 + " " + 17 / 5);
System.out.println(-7 % 3 + " " + -7 / 3); // sign of the left number
System.out.println(Math.floorMod(-7, 3) + " " + Math.floorDiv(-7, 3));
System.out.println(Math.floorMod(-1, 12));
}
}$ java Remainders 2 3 -1 -2 2 -3 11
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
Java cuts −2.33… toward 0, so
-7 / 3is −2 and-7 % 3is −1.Java −2.33… بەرەو 0 دەبڕێت، بۆیە
-7 / 3دەکاتە −2 و-7 % 3دەکاتە −1.- Lineدێڕی 5-6
floorModandfloorDivgive the maths answers, as Python does.floorModوfloorDivوەڵامەکانی بیرکاری دەدەن، وەک Python.
% and / cut toward 0; floorMod and floorDiv go down, as Python's % and // do.% و /ـی Java بەرەو 0 دەبڕن؛ floorMod و floorDiv بەرەو خوار دەچن، وەک % و //ـی Python.CêITBase subscripts: , ژێرنووسی بنچینە: ،
A small number written low after a number names its base: is binary, octal, decimal and hexadecimal; many books drop the brackets, . Read “one zero one zero, base two”, never “one thousand and ten”. Hexadecimal needs six more digits, A = 10 up to F = 15. Every digit must be smaller than the base, so a B in a base-2 number, as in the slip , shows that the base must be 16. In the place-value formula the base is usually called r (for radix) or b: .
ژمارەیەکی بچووک کە لە خوارەوەی دوای ژمارەیەک دەنووسرێت ناوی دەڵێت: ، ، و ؛ زۆر کتێب کەوانەکان لادەبەن: . بخوێنەوە «یەک سفر یەک سفر، 2»، هەرگیز «هەزار و دە» نا. شەش زیاتری پێویستە: A = 10 تا F = 15. هەموو دەبێت لە بچووکتر بێت، بۆیە Bـێک لە ژمارەیەکی 2ـدا، وەک لە هەڵەی ـدا، پیشان دەدات کە دەبێت 16 بێت. لە زۆرجار r (لە radixـەوە) یان b ناو دەنرێت: .
A bar repeats digits in every base: means 23D.51EB851EB8… (Repeating decimals). Conversions are taught in Decimal, binary, octal and hexadecimal and The only table you need.
هێڵێکی سەرەوە لە هەموو دووپاتە دەکاتەوە: واتە 23D.51EB851EB8… (ژمارەی دەیی دووپاتەبووەوە). لە دەیی، دووانی، هەشتی و شانزەیی و تاکە خشتەیەک کە پێویستتە فێر دەکرێت.
Prefixes in code: 0b, 0o, 0xپێشگرەکان لە کۆددا: 0b، 0o، 0x
Code cannot write subscripts, so it marks the base with a prefix: 0b1010 is binary, 0o12 octal (Python) and 0xA hexadecimal, in Python, Java and C alike. Other places use other marks: 0Ah with an h in assembly language, &HA in Visual Basic, #FF8800 for a colour in CSS and U+0041 for a Unicode code point. Windows error codes such as 0xc0000005 are hexadecimal numbers too (Write a useful ticket).
کۆد ناتوانێت بنووسێت، بۆیە بە نیشان دەدات: 0b1010 ، 0o12 (Python) و 0xA ، لە Python، Java و Cـدا وەک یەک. شوێنی تر نیشانەی تر بەکار دەهێنن: 0Ah بە h لە زمانی ئەسێمبلیدا، &HA لە Visual Basicـدا، #FF8800 بۆ ڕەنگێک لە CSSـدا و U+0041 بۆ Unicode. کۆدی هەڵەکانی Windows وەک 0xc0000005یش ژمارەی (تیکێتێکی بەسوود بنووسە).
n = 0b1010 # binary literal
print(n, 0o12, 0xA, 10) # four spellings, one number
print(bin(42), oct(42), hex(42))
print(int("101010", 2), int("2A", 16), int("52", 8))
print(f"{255:b} {255:o} {255:x} {255:X}")10 10 10 10 0b101010 0o52 0x2a 42 42 42 11111111 377 ff FF
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-4
bin,octandhexwrite a number with a prefix;int(text, base)reads it back.bin،octوhexژمارەیەک بە دەنووسن؛int(text, base)دەیخوێنێتەوە.
Prefixes in code: 0b, 0o, 0xپێشگرەکان لە کۆددا: 0b، 0o، 0x
A leading zero: twelve, ten or an error?سفرێکی پێشەوە: دوازدە، دە یان هەڵە؟
On paper, a zero in front changes nothing: 012 is twelve. In Java, C and C++, a number that starts with 0 is octal, so 012 is ten and 017 is fifteen. Python 3 refuses such numbers and asks for the clear prefix 0o.
لەسەر کاغەز سفرێک لە پێشەوە هیچ ناگۆڕێت: 012 دوازدەیە. لە Java، C و C++ـدا ژمارەیەک کە بە 0 دەست پێبکات ، بۆیە 012 دەیە و 017 پازدە. Python 3 ئەم جۆرە ژمارانە ڕەت دەکاتەوە و ڕوونی 0o داوا دەکات.
public class Literals {
public static void main(String[] args) {
System.out.println(0b1010 + " " + 0xA + " " + 012); // 012 starts with 0: octal!
System.out.println(017);
System.out.println(Integer.toBinaryString(42) + " " + Integer.toHexString(42));
}
}$ java Literals 10 10 10 15 101010 2a
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-4
012and017start with 0, so Java reads them in base 8: 10 and 15.012و017بە 0 دەست پێدەکەن، بۆیە Java بە 8 دەیانخوێنێتەوە: 10 و 15.
b, B, Ki and powers of twob، B، Ki و توانەکانی 2
Powers of two count possibilities: n bits give patterns (How many patterns do N bits give?). One byte has patterns, 16 bits , and an IPv4 address has 32 bits, so there are billion addresses. Subnetting uses the same powers: S borrowed bits give subnets (Borrowing host bits in the Computer Networks course). A logic program that tries every true/false choice for 25 facts checks million cases (Model checking). is close to 1000, which is why computers have two prefixes: k = 1000 and Ki = 1024. Copy the letters exactly: b is a bit, B a byte (Prefixes are powers of ten, b or B).
2 ژمارەی هەڵبژاردە جیاوازەکان دەژمێرن: n ، شێوەی جیاواز دەدات (N بیت چەند شێوە دەدات؟). یەک شێوەی هەیە، 16 و ناونیشانێکی IPv4 32 ، بۆیە ملیار ناونیشان هەیە. هەمان بەکار دەهێنێت: S قەرزکراو دەدات (قەرزکردنی بیتەکانی میوانگر لە کۆرسی کۆمپیوتەردا). لۆجیکی کە هەموو هەڵبژاردنێکی ڕاست/هەڵە بۆ 25 ڕاستی تاقی دەکاتەوە ملیۆن بار دەپشکنێت (پشکنینی مۆدێل). نزیکە لە 1000، بۆیە دوو هەیە: k = 1000 و Ki = 1024. پیتەکان وەک خۆیان بنووسە: b و B (پێشگرەکان توانەکانی 10ـن، بیت یان بایت).
Big-O: , , , and Θ and Ωنیشانەی O-ی گەورە: ، ، ، هەروەها Θ و Ω
Big-O describes how the work of an algorithm, the time it takes or the memory it needs, grows with the input size n. is read “big-O of n squared” or “order n squared” (the O stands for “order”: Why one letter?): the work grows at most like . The common orders are (constant), , , , and . The = in works one way only: it means “is at most of the order of”, so is true as well, but nobody writes . Some books write a set instead: .
وەسفی ئەوە دەکات کە کاری ، واتە ئەو کاتەی دەیخایەنێت یان ئەو پێویستیەتی، لەگەڵ قەبارەی ، n، چۆن گەورە دەبێت. بە ئینگلیزی big-O of n squared یان order n squared دەخوێنرێتەوە (یەک شێوەی کوردی: «O-ی گەورەی n دووجا»؛ O بۆ «پلە»یە، order: بۆچی یەک پیت؟): کارەکە زۆرترین وەک گەورە دەبێت. پلە ناسراوەکان: ()، ، ، ، و . هێمای = لە ـدا تەنیا بە یەک ئاڕاستە کار دەکات: واتە «زۆرترین لە پلەی … دایە»، بۆیە ـیش ڕاستە، بەڵام کەس نانووسێت. هەندێک کتێب لەبری ئەوە دەنووسن: .
Two relatives: , “big-Omega”, means at least of that order (a lower bound), and , “big-Theta”, means exactly that order. So Ω has a third job here, after the ohm and the sample space (One letter, many jobs). In big-O the base of the log does not matter (log x with no base). The idea itself: Big-O notation in one screen and How fast is fast?
دوو خزم: ، big-Omega، واتە لانیکەم لەو پلەیەدایە (سنووری خوارەوە) و ، big-Theta، واتە ڕێک لەو پلەیەدایە. کەواتە Ω لێرەدا کاری سێیەمی هەیە، لە دوای ئۆم و (یەک پیت، چەند کار). لە گرنگ نییە (log x بەبێ بنچینە). خودی بیرۆکەکە: نیشانەی O-ی گەورە لە یەک شاشەدا و خێرا چەندە خێرایە؟
: how many halvings?: چەند جار نیوەکردن؟
Each look of a binary search halves the part of the sorted list that is still possible, so the number of looks is a binary logarithm: at most , the same as . That is the of the last screen. Python's math.log2 gives the logarithm, and math.floor the floor (log on calculators, in Excel and in code, How many steps?).
هەر سەیرکردنێکی ئەو بەشەی ڕیزکراوەکە نیوە دەکات کە هێشتا دەشێت وەڵامەکەی تێدا بێت، بۆیە ژمارەی سەیرکردنەکان : زۆرترین ، کە هەمان ـە. ئەمە هەمان ـی شاشەی پێشووە. math.log2ـی Python دەدات و math.floor بەرەو خوار دەیبات (log لەسەر حاسیبە، لە Excel و لە کۆددا، چەند هەنگاو؟).
import math
for n in [15, 1000, 1_000_000, 2**30]:
looks = math.floor(math.log2(n)) + 1 # binary search, worst case
print(f"{n:>13,} items: at most {looks} looks") 15 items: at most 4 looks
1,000 items: at most 10 looks
1,000,000 items: at most 20 looks
1,073,741,824 items: at most 31 looksMaths signs and code signsهێماکانی بیرکاری و هێماکانی کۆد
Code writes maths with keyboard signs, and one sign can mean different things. Python writes powers as **; its ^ is XOR, exclusive or (XOR: one or the other, not both), as in Java, which has no power sign and calls Math.pow(2, 3) (it prints 8.0). MATLAB and Excel use ^ for powers. Equality is asked with == (Excel: =); not-equal is !=, in MATLAB ~= and in Excel <>. A single = stores a value; pseudocode writes x ← 5, and some books x := 5 (“=” and “==” in programming, Pseudocode).
کۆد بیرکاری بە نیشانەکانی دەنووسێت و یەک نیشانە دەتوانێت واتای جیاوازی هەبێت. Python بە ** دەنووسێت؛ ^ـی ئەو XORـە (XOR: یەکێکیان، نەک هەردووکیان)، وەک Java کە نیشانەی نییە و Math.pow(2, 3) بانگ دەکات (8.0 چاپ دەکات). MATLAB و Excel ^ بۆ بەکار دەهێنن. یەکسانی بە == دەپرسرێت (Excel: =)؛ یەکسان نەبوون !=ـە، لە MATLABـدا ~= و لە Excelـدا <>. یەک = نرخێک هەڵدەگرێت؛ دەنووسێت x ← 5 و هەندێک کتێب x := 5 («=» و «==» لە بەرنامەسازیدا، نیمچەکۆد).
Maths signs and code signsهێماکانی بیرکاری و هێماکانی کۆد
Saying code operators in Kurdishخوێندنەوەی کارپێکەرەکان بە کوردی
A Kurdish MATLAB guide reads the comparison and logic operators aloud like this. The same readings work for Python, Java and Excel.
ڕێبەرێکی کوردیی MATLAB و بەم شێوەیە دەخوێنێتەوە. هەمان خوێندنەوە بۆ Python، Java و Excelـیش دەگونجێت.
| Operator | Say it (EN)بە ئینگلیزی | Say it (Kurdish)بە کوردی |
|---|---|---|
a == b | a is equal to b | a یەکسانە بە b«a یەکسانە بە b» |
a ~= b | a is not equal to b | a یەکسان نییە بە b (Python, Java: !=)«a یەکسان نییە بە b» (Python، Java: !=) |
a < b | a is less than b | a بچووکترە لە b«a بچووکترە لە b» |
a > b | a is greater than b | a گەورەترە لە b«a گەورەترە لە b» |
a & b | a and b | a و b«a و b» |
a | b | a or b | a یان b«a یان b» |
x ← 5 | store 5 in x | 5 بخە ناو x«5 بخە ناو x» |
print(2 ** 3, 2 ^ 3) # power, then XOR
print(5 ^ 3) # 101 XOR 011 = 110
print(7 != 3, 7 == 7.0)
x = 5 # = stores a value
x = x + 1
print(x == 6) # == asks a question8 1 6 True True True
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
**is the power;^is XOR: 5 is 101, 3 is 011, and 101 XOR 011 = 110, which is 6.**؛^XORـە: 5 بریتییە لە 101، 3 لە 011 و 101 XOR 011 = 110، کە 6ـە.- Lineدێڕی 4-6
=stores,==asks:x == 6givesTrue.=هەڵدەگرێت،==دەپرسێت:x == 6دەداتTrue.
Indexes: , v(1) or v[0]?ئیندێکسەکان: ، v(1) یان v[0]؟
Maths counts from 1: is the first value. MATLAB and Excel do the same: v(1) is the first element and A1 the first cell. Python, Java, C and many other languages count from 0, so the first element is v[0] and the last of four is v[3]. The same matrix entry is A(2,3) in MATLAB but A[1][2] in Python. Forgetting this shift by one is the classic off-by-one error.
بیرکاری لە 1ـەوە دەژمێرێت: یەکەم نرخە. MATLAB و Excelـیش هەروا: v(1) یەکەم و A1 یەکەم خانە. Python، Java، C و زۆر زمانی تر لە 0ـەوە دەژمێرن، بۆیە یەکەم v[0]ـە و دوایینی چوار دانە v[3]. هەمان ژمارەی ، ، لە MATLABـدا A(2,3)ـە بەڵام لە Pythonـدا A[1][2]. لەبیرکردنی ئەم یەک جیاوازییە هەڵەی ناسراوی «یەک زیاد یان یەک کەم»ـە (off-by-one error).
marks = [8, 3, 5, 6] # x1, x2, x3, x4 in maths
print(marks[0], marks[3]) # the first and the last: indexes 0 and 3
print(len(marks))
A = [[7, -2, 5],
[4, 9, -1]]
print(A[1][2]) # a23 in maths: row 2, column 38 6 4 -1
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 6
Row 2 is index 1 and column 3 is index 2.
ڕیزی 2 1ـە و ستوونی 3 2.
σ, π and ⋈ in databasesσ، π و ⋈ لە بنکەدراوەدا
Database books reuse Greek letters with new meanings. is read “select the rows of Student where dept is CS” (Selection σ: choose rows); is “project Student on name”, keeping only that column (Projection π). renames a table, (“bowtie”) joins two tables, answers “for all” questions, ⟕ is a left outer join that keeps every row of the left table (Outer joins), and ×, ∪, ∩ and − work as with sets. In a statistics book the same σ is the standard deviation, and π is 3.14159….
کتێبەکانی پیتە یۆنانییەکان بە واتای نوێ بەکار دەهێننەوە. دەخوێنرێتەوە «ئەو ڕیزانەی Student هەڵبژێرە کە deptـیان CSـە» (هەڵبژاردن σ)؛ واتە «تەنیا ستوونی name لە Student بهێڵەرەوە» (دەرهێنانی ستوون π). ناوی خشتەیەک دەگۆڕێت، (bowtie) دوو خشتە پێکەوە دەبەستێت ()، وەڵامی پرسیاری «بۆ هەموو» دەداتەوە، ⟕ چەپە و هەموو ڕیزەکانی خشتەی چەپ دەهێڵێتەوە (لێکبەستنە دەرەکییەکان) و ×، ∪، ∩ و − وەک لە کار دەکەن. لە کتێبێکی هەمان σ و π ژمارەی 3.14159…ـە.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Why it is wrongبۆچی هەڵەیە | Do thisئەمە بکە |
|---|---|---|
Expecting -7 % 3 to give the same answer in every languageچاوەڕوانیی هەمان وەڵام بۆ -7 % 3 لە هەموو زمانێکدا | Python gives 2, Java and C give −1Python 2 دەدات، Java و C −1 | Use Math.floorMod in Java for the maths answerلە Javaـدا Math.floorMod بەکار بهێنە بۆ وەڵامی بیرکاری |
| Reading as one thousand and tenخوێندنەوەی وەک هەزار و دە | The subscript 2 says binary 2 دەڵێت | “one zero one zero, base two” = 10«یەک سفر یەک سفر، 2» = 10 |
| Writing نووسینی | Base 2 has only 0 and 1 2 تەنیا 0 و 1ـی هەیە | Check the digits: بپشکنە: |
Writing 012 in Java and expecting twelveنووسینی 012 لە Javaـدا و چاوەڕوانیی دوازدە | A leading 0 means octal: tenسفری پێشەوە واتە : دە | Write 12; for octal write it on purpose12 بنووسە؛ بۆ بە ئەنقەست بینووسە |
2 ^ 3 for a power in Python or Java2 ^ 3 بۆ لە Python یان Javaـدا | ^ is XOR there: it gives 1لەوێ ^ XORـە: 1 دەدات | 2 ** 3, Math.pow(2, 3)2 ** 3، Math.pow(2, 3) |
| Reading as an equationخوێندنەوەی وەک | The = works one way: “is at most of the order”= تەنیا بە یەک ئاڕاستە کار دەکات: «زۆرترین لەو پلەیەدایە» | Never turn it round; or write هەرگیز پێچەوانەی مەکەرەوە؛ یان بنووسە |
Using v[1] for the first element in Pythonبەکارهێنانی v[1] بۆ یەکەم لە Pythonـدا | Python counts from 0Python لە 0ـەوە دەژمێرێت | = v(1) in MATLAB = v[0] in Python = v(1) لە MATLAB = v[0] لە Python |
| Reading σ in a database book as a standard deviationخوێندنەوەی σ لە کتێبی وەک | There it selects rowsلەوێ ڕیز هەڵدەبژێرێت | Ask which book you are readingبزانە کام کتێب دەخوێنیتەوە |
Practiceڕاهێنان
Write each one in Python and in MATLAB: (a) (b) (c) (d) “is x not equal to 0?” (e) the first element of a list v.
هەر یەکەیان بە Python و بە MATLAB بنووسە: (a) (b) (c) (d) «ئایا x یەکسان نییە بە 0؟» (e) یەکەم لیستی v.
Show answerوەڵامەکە پیشان بدە
| Mathsبیرکاری | Python | MATLAB |
|---|---|---|
2 ** 10 | 2^10 | |
17 % 5 | mod(17, 5) | |
17 // 5 | floor(17/5) | |
x != 0 | x ~= 0 | |
v[0] | v(1) |
Read each statement aloud and say what it means: (a) binary search is (b) bubble sort is (c) trying every sequence of d actions with b choices each is .
هەر ڕستەیەک بە دەنگی بەرز بخوێنەوە و بڵێ واتای چییە: (a) ـە (b) ـە (c) تاقیکردنەوەی هەموو زنجیرەیەکی d کار کە هەر جارێک b هەڵبژاردەی هەیە ـە.
Show answerوەڵامەکە پیشان بدە
- (a) “big-O of log n”: doubling the list adds only one look.
- (b) “order n squared”: twice the data, about four times the work.
- (c) “big-O of b to the d”: exponential; each extra step multiplies the work by b.
- (a) «O-ی گەورەی log n»: دوو هێندەکردنی تەنیا یەک سەیرکردن زیاد دەکات.
- (b) «O-ی گەورەی n دووجا» (order n squared): دوو هێندە ، نزیکەی چوار هێندە کار.
- (c) «O-ی گەورەی b بە d»: هەر هەنگاوێکی زیادە کارەکە b جار زیاتر دەکات.
Write each number in decimal: (a) (b) 0x2A (c) 0o17 (d) (e) 012 in Java.
هەر ژمارەیەک بە بنووسە: (a) (b) 0x2A (c) 0o17 (d) (e) 012 لە Javaـدا.
Show answerوەڵامەکە پیشان بدە
In (e) the leading 0 makes Java read the digits in base 8.
لە (e)ـدا سفری پێشەوە وا دەکات Java بە 8 بخوێنێتەوە.
Summaryپوختە
- is the remainder; means the same remainder; div,
//and give the quotient. %with negative numbers: Python, ExcelMODand MATLABmodfollow the divisor; Java, C and MATLABremfollow the left number.- Bases: ,
0b1010,0o12,0xA; every digit is smaller than the base; a leading 0 is octal in Java and C. - n bits give patterns; is Ki; b is a bit, B a byte.
- “order n squared”: an upper bound, a one-way =; Ω a lower bound, Θ the exact order; binary search needs looks.
**vs^,==vs=,!=~=<>,←and:=; indexes from 1 in maths and MATLAB, from 0 in Python and Java; σ π ⋈ in databases.- All these signs, with their readings, are in the Symbol dictionary: Notation in computing.
- ؛ واتە هەمان ؛ div،
//و ئەنجامی دەدەن. %لەگەڵ : Python،MODـی Excel وmodـی MATLAB شوێن دابەشکەرەکە دەکەون؛ Java، C وremـی MATLAB شوێن ژمارەی لای چەپ دەکەون.- : ،
0b1010،0o12،0xA؛ هەموو لە بچووکترە؛ سفری پێشەوە لە Java و Cـدا . - n ، شێوە دەدات؛ Kiـیە؛ b و B .
- «O-ی گەورەی n دووجا»: سنووری سەرەوە، = بە یەک ئاڕاستە؛ Ω سنووری خوارەوە، Θ پلەی ڕێک؛ سەیرکردنی پێویستە.
**بەرامبەر^،==بەرامبەر=،!=~=<>،←و:=؛ لە بیرکاری و MATLABـدا لە 1ـەوە، لە Python و Javaـدا لە 0ـەوە؛ σ π ⋈ لە .- هەموو ئەم نیشانانە، لەگەڵ خوێندنەوەکانیان، لە فەرهەنگی هەن: هێماکان لە کۆمپیوتەردا.
How do you read ? چۆن دەخوێنیتەوە؟
“17 is congruent to 2 modulo 5”: both leave the remainder 2 when divided by 5.
«17 و 2 یەکسانە بەسەر 5ـدا» (17 is congruent to 2 modulo 5): هەردووکیان لە بەسەر 5ـدا 2 دەدەن.
What is 0xFF?0xFF چییە؟
The hexadecimal number FF: .
ژمارەی FF: .
Why does v[0] hold in Python?بۆچی لە Pythonـدا v[0] هەڵدەگرێت؟
Python counts its indexes from 0, while maths counts from 1.
Python لە 0ـەوە دەژمێرێت، بەڵام بیرکاری لە 1ـەوە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Typing Mathematics: Keyboards, Word, LaTeX and Unicodeچۆن بیرکاری بنووسیت: کیبۆرد، Word، LaTeX و Unicode
Related lecturesوانە پەیوەندیدارەکان
- Equals, Not Equal, Approximately and Other Relationsیەکسان، یەکسان نییە، نزیکەی یەکسان و پەیوەندییەکانی تر
- Logic Symbols and Boolean Algebraهێماکانی لۆجیک و جەبری بوول
- Letters, Subscripts, Superscripts and the Greek Alphabetپیتەکان، ژێرنووسەکان، ژوورنووسەکان و ئەلفوبێی یۆنانی
- Powers, Roots, Absolute Value, Factorial, Floor and Ceilingتوانەکان، ڕەگەکان، نرخی ڕووت، فاکتۆریێل، نەخشەی گەورەترین ژمارەی تەواو و نەخشەی بچووکترین ژمارەی تەواو
- Vectors and Matrices: Arrows, Bold Letters, Aᵀ, A⁻¹ and detئاڕاستەبڕەکان و ماتریکسەکان: تیر، پیتی تۆخ، Aᵀ، A⁻¹ و det
- Number Systems and Place Valueسیستەمە ژمارەییەکان و بەهای خانەیی
- Binary, Octal and Hex Shortcutsڕێگا کورتەکانی دووانی، هەشتی و شانزەیی
- Operators and Expressionsکارپێکەرەکان و دەربڕینەکان
- Arithmetic, Increment and Assignment Operatorsکارپێکەرە ژمێرەییەکان و کارپێکەرەکانی دانانی نرخ،
++و-- - Encryption, Hashing and Digital Signaturesشفرەکردن، هاشکردن و واژووە دیجیتاڵییەکان
- Agent Programs, Pseudocode and Algorithm Analysisبەرنامەکانی ئەیجێنت، نیمچەکۆد و شیکارکردنی ئەلگۆریزم
- Binary Search and Hashingگەڕانی دووانی و هاشکردن
- Bubble Sort, Insertion Sort and How Fast Sorting Isڕیزکردنی بڵقی، ڕیزکردن بە تێخستن و خێرایی ڕیزکردن
- Algorithms, Pseudocode and Flowchartsئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوت
- Indexing, the Colon, Adding and Deleting Elementsئیندێکسەکان، دوو خاڵ، زیادکردن و سڕینەوەی توخمەکان
- Relational Algebra and Relational Calculusجەبری پەیوەندیدار و ژمێرکاریی پەیوەندیدار
- Bits, Bytes and Storage Unitsبیتەکان، بایتەکان و یەکەکانی خەزنکردن
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- NIST Dictionary of Algorithms and Data Structures: big-O notation (definition; the one-way “=”; Θ for “equal to”)
- Wikipedia: Big O notation (Bachmann 1894, Landau; Knuth’s Ω and Θ; f ∈ O(g))
- Wikipedia: Modular arithmetic (a ≡ b (mod n) vs the operation b mod n; the 12-hour clock)
- Python documentation: Expressions (% takes the sign of the second operand; // floors; ** binds tighter than unary minus; ^ is bitwise XOR)
- Python documentation: Lexical analysis, integer literals (0b, 0o, 0x; leading zeros not allowed)
- Java Language Specification (Java SE 17), §15.17.3 Remainder Operator % (the result has the sign of the dividend)
- MathWorks: mod (result has the sign of the divisor; rem has the sign of the dividend)
- MathWorks: MATLAB Operators and Special Characters (^, ==, ~=, &, |, ', .')
- Microsoft Support: Calculation operators and precedence in Excel (^, =, <>)
- Microsoft Support: MOD function (the result has the sign of the divisor)
- Wikipedia: Hexadecimal (0x, h suffix, $, &H, # and U+ markers)
- NIST: Prefixes for binary multiples (Ki, Mi, Gi …; IEC 1998)
- Wikipedia: Zero-based numbering (C and Java count from 0; Fortran from 1; Dijkstra 1982)
- Wikipedia: Relational algebra (σ selection, π projection, ρ rename, ⋈ join; Codd 1970)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.