diff --git a/Languages/en/00_Set/readme.md b/Languages/en/00_Set/readme.md index 6a55bd1..2c0fa43 100644 --- a/Languages/en/00_Set/readme.md +++ b/Languages/en/00_Set/readme.md @@ -1,33 +1,33 @@ --- -title: 00. Set +title: 00. Sets tags: - zk - basic - set --- -# WTF zk Tutorial Lesson 0: Set +# WTF zk Tutorial Part 0: Sets -Abstract algebra, also known as modern algebra, is one of the important foundations of modern mathematics. It studies the algebraic structures of groups, rings, and fields. The concepts of abstract algebra are widely used in zero-knowledge proof (zk) theory, so learners should be familiar with the basic knowledge of abstract algebra. +Abstract algebra, also known as modern algebra, is an important foundation of modern mathematics. It studies the structural theory of three fundamental algebraic structures: groups, rings, and fields. Abstract algebra concepts are extensively used in zk theory, so learners should have a basic understanding of abstract algebra. -In this tutorial, we will mainly study the basics of abstract algebra: set theory. +In this tutorial, we will focus on the fundamentals of abstract algebra, specifically set theory. ## 1. Definition of Sets -A set is a mathematical model of a collection of different objects, which are called the elements of the set. Integers, rational numbers, real numbers, complex numbers, matrices, polynomials, polygons, and many other concepts are essentially sets. +A set is a mathematical model of a collection of different objects, called elements. Concepts such as integers, rational numbers, real numbers, complex numbers, matrices, polynomials, polygons, and many others can be thought of as sets. -> Abbreviations commonly used for sets: $\mathbb{N}$ represents the set of natural numbers, $\mathbb{Z}$ represents the set of integers (Zahl in German means Integer), $\mathbb{Q}$ represents the set of rational numbers, $\mathbb{R}$ represents the set of real numbers, and $\mathbb{C}$ represents the set of complex numbers. +> Common set abbreviations: $\mathbb{N}$ represents the set of natural numbers, $\mathbb{Z}$ represents the set of integers, $\mathbb{Q}$ represents the set of rational numbers, $\mathbb{R}$ represents the set of real numbers, $\mathbb{C}$ represents the set of complex numbers. -The number of elements in a set is defined as the cardinality of the set. When the cardinality is finite, the set is called a finite set; otherwise, it is an infinite set. There is a special type of set that does not contain any elements, called the empty set $\emptyset$, which has the following characteristics: +The number of elements in a set is called the cardinality of the set. If the cardinality is finite, the set is called a finite set; otherwise, it is an infinite set. There is a special type of set that does not contain any elements, called the empty set $\emptyset$. It has the following characteristics: - The empty set is a proper subset of any non-empty set. - The empty set is a subset of any set. ## 2. Characteristics of Sets -Determinism: Given a set S and an element a, the element either belongs to the set (a∈S) or does not belong to the set (a∉S). There is no ambiguity. +Determinism: Given a set $S$ and an element $a$, the element either belongs to the set ($a\in S$) or does not belong to the set ($a\notin S$). There is no ambiguity. -Uniqueness: In a set, any two elements are considered distinct, and each element can only appear once. Sometimes, it is necessary to describe the situation where the same element appears multiple times, which can be done using multiset, where elements are allowed to appear multiple times. +Distinctness: In a set, each element is considered distinct, meaning that each element can only appear once. Sometimes it is necessary to describe a situation where the same element appears multiple times. This can be done using a multiset, where elements are allowed to appear multiple times. ```python S = {1, 1, 2} @@ -37,7 +37,7 @@ for elem in S: # 2 ``` -Unorderedness: In a set, the position of each element is the same, and the elements are unordered. An order relation can be defined on a set, and once defined, the elements can be sorted according to the order relation. However, in terms of the nature of the set itself, there is no inherent order among the elements. +Unorderedness: In a set, the position of each element is irrelevant, and the elements are unordered. Although an order relation can be defined on a set, the inherent nature of a set itself does not have a specific order among its elements. ```python S = {'0xaa', 123, 'a', 0.123} @@ -51,73 +51,73 @@ for elem in S: # a ``` -## 3. Basic Relationships between Sets +## 3. Basic Relations Between Sets ### Subset and Superset -Consider the sets of integers and rational numbers. There seems to be a certain relationship between them: all integers are rational numbers, but not all rational numbers are integers. We define: the set of integers is a subset of the set of rational numbers, and conversely, the set of rational numbers is a superset of the set of integers. +Consider the sets of integers and rational numbers. There is a relationship between them: all integers are rational numbers, but not all rational numbers are integers. We define: the set of integers is a subset of the set of rational numbers, and conversely, the set of rational numbers is a superset of the set of integers. -Note: A is a subset of B does not necessarily mean A is strictly smaller than B. Therefore, it can be said that the set of integers is a subset of itself. When A is a subset of B and A is strictly smaller than B, it can be further said that A is a proper subset of B. +Note: $A$ is a subset of $B$ does not require $A$ to be strictly smaller than $B$. Therefore, we can say that the set of integers is a subset of itself. When $A$ is a subset of $B$ and $A$ is strictly smaller than $B$, we can further say that $A$ is a proper subset of $B$. ### Intersection and Union -- Intersection: The set consisting of elements that belong to both set A and set B, denoted as A∩B (or B∩A). -- Union: The set consisting of all elements that belong to set A or set B, denoted as A∪B (or B∪A). +- Intersection: The set containing elements that belong to both $A$ and $B$ is denoted as $A\bigcap B$ (or $B \bigcap A$). +- Union: The set containing all elements that belong to either set $A$ or set $B$ is denoted as $A\bigcup B$ (or $B\bigcup A$). -Both operations follow the commutative, associative, and distributive laws. +Both intersection and union follow the commutative, associative, and distributive laws. ### Equality/Equivalence -If two sets contain exactly the same elements (without considering the order), they are considered equivalent. In strict mathematical language, if A ⊆ B and B ⊆ A, then A = B. +If two sets contain exactly the same elements (without considering the order), they are considered equivalent. Mathematically, if $A \subseteq B \wedge B \subseteq A$, then $A=B$. ### Cardinality -As mentioned earlier, the number of elements in a set is defined as the cardinality. In general, the cardinality of a finite set is meaningful, and it is denoted as |A|. For infinite sets, if it is a set of integers, it can be expressed in words, which is called countably infinite; if it is a set of complex numbers, it is impossible to count its elements, so it is called uncountably infinite. +As mentioned earlier, the number of elements in a set is called its cardinality. The cardinality of a finite set is meaningful and is denoted as $|A|$. For infinite sets, if it can be put in one-to-one correspondence with the set of integers, it is called countably infinite; if it cannot be counted, it is called uncountably infinite. ## 4. Ordered Pairs -The elements of a set are unordered, and ordered pairs are a new data structure derived from sets. In the programming world, programmers prefer to call them tuples. +The elements of a set are unordered, but ordered pairs are a new data structure generated from a set. In the programming world, programmers commonly refer to them as tuples. -So how do we generate ordered pairs from an unordered set? The specific implementation is to represent the tuple (a, b) in set form as {a, {b}}. Note that the elements of such a set are either letters or sets with a cardinality of 1. Therefore, we say (a, b) ≠ (b, a) because {{a, {b}}} ≠ {{b, {a}}}. +So how do we generate ordered pairs from an unordered set? The specific implementation is to represent the tuple $(a, b)$ as a set in the form of $\{a, \{b\}\}$. It can be seen that the elements of such a set are either individual elements or sets with a cardinality of 1. Therefore, we say $(a, b)\neq(b,a)$ because $\{\{a, \{b\}\}\neq\{b,\{a\}\}$. Note that the number of elements in an ordered pair (tuple) can be any number. ## 5. Cartesian Product -Given two sets A and B, we can define another set C, in which the elements of C are ordered pairs with the first element from A and the second element from B. This set is called the Cartesian product. +Given two sets $A$ and $B$, we can define another set $C$, where the elements of $C$ are ordered pairs with the first element from set $A$ and the second element from set $B$. This set is called the Cartesian product. The Cartesian product does not follow the commutative law. ## 6. Functions -With the Cartesian product operation, we can define functions from a mathematical perspective. For example, if we need to define a function f such that f(1)=x, f(2)=y, and f(3)=z, we only need to define two sets {1, 2, 3} and {x, y, z}, take the Cartesian product of the two sets, and select a subset of the results to obtain the desired mapping relationship (1, x), (2, y), (3, z). +With the Cartesian product operation, we can define functions from a mathematical perspective. For example, if we need to define a function $f$ such that $f(1)=x,f(2)=y, f(3)=z$, we only need to define two sets $\{1, 2, 3\}$ and $\{x, y, z\}$, take the Cartesian product of the two sets, and take a subset of the result to obtain the desired mapping relationship $(1, x), (2, y), (3, z)$. -Therefore, in set theory, a function is a subset of the Cartesian product of a domain set and a codomain set. In other words, as long as we have a domain set and a codomain set, the Cartesian product of the two sets can obtain all possible mapping relationships from the domain to the codomain. A function is defined as a subset of these mapping relationships. +Therefore, in set theory, a function is a subset of the Cartesian product of the domain set and the codomain set. In other words, as long as we have a domain set and a codomain set, we can obtain all possible mapping relationships from the domain to the codomain by taking the Cartesian product of the two sets. A function is defined as a subset of these mapping relationships. -> Mathematicians rarely care about computability. That is, mathematicians define a function between two sets, but they are not concerned about how this function is computed (the specific mathematical formula). -> -> Programmers, on the other hand, believe that all functions are computable and have specific mathematical formulas. +> Mathematicians are not concerned with the computability of functions. They define a function between two sets without specifying how the function is computed (the specific mathematical formula). +> +> On the other hand, programmers believe that all functions are computable and have specific mathematical formulas. -In most cases, the term function is equivalent to mapping. Of course, the definition of mapping (function) determines its usability. For example, if we map everything to 0, it is reasonable, but such a mapping is generally not useful. +In most cases, the term "function" is equivalent to "mapping". However, the definition of a mapping (function) determines its usefulness. For example, if we map everything to 0, it is a valid function but not very useful. -Axiom of Choice: The Cartesian product of a set of non-empty sets is non-empty. +Axiom of Choice: The Cartesian product of a collection of non-empty sets is non-empty. -## 7. Injective, Surjective, and Bijective +## 7. Injective, Surjective, and Bijective Functions -We define a function as a subset of the Cartesian product of two sets, but this subset is not arbitrary and needs to be restricted: for a given input, the output of the function is unique. +We define a function as a subset of the Cartesian product of two sets, but this subset is not arbitrary; it needs to satisfy a restriction: for a given input, the output of the function is unique. -There are three types of mappings that satisfy the requirements of a function: -- Injective function: Each element in the codomain corresponds to at most one element in the domain (also known as the preimage). An element in the codomain can correspond to no element in the domain. However, if multiple elements in the domain correspond to the same element in the codomain, the function does not satisfy injectivity. -- Surjective function: Each element in the codomain corresponds to at least one element in the domain. If there exists an element in the codomain with no corresponding preimage, the function does not satisfy surjectivity. -- Bijective function: A function is bijective if and only if it satisfies both injectivity and surjectivity. +There are three types of mappings that satisfy this restriction: +- Injective function: Each element in the codomain is associated with at most one preimage (also called an inverse image) in the domain. Elements in the codomain may not have any corresponding preimage in the domain. However, if multiple preimages in the domain correspond to the same element in the codomain, then the function is not injective. +- Surjective function: Each element in the codomain is associated with at least one element in the domain. If there is an element in the codomain that has no corresponding preimage, the function is not surjective. +- Bijective function: A function is bijective if and only if it is both injective and surjective. -For the above mappings, the most important thing is how to define the domain and codomain. Different choices of domain and codomain will result in different mappings. +The choice of domain and codomain determines the specific mappings for these types of functions. -Bijective and surjective mappings are also important when discussing the concepts of isomorphism and homomorphism, so please remember these basic definitions. +Bijective and surjective functions are also important when discussing the concepts of isomorphism and homomorphism, so please remember these basic definitions. ## 8. Relations -Relations are a very subtle concept, and you will often come across this concept when reading ZKP-related papers. In fact, we have already encountered relations in the descriptions above, such as intersection and union, subset and superset, and equality, which are all relations between sets. +Relations are a subtle concept and often encountered when reading papers related to ZKP. In fact, we have already encountered relations in the descriptions above, such as intersection, union, subset, and equality, which are all relations between sets. -However, mathematically speaking, a relation is defined as "taking a subset of the Cartesian product of two sets". It can be seen that this definition is no different from the definition of a function (or mapping). +Mathematically, a relation is defined as "a subset of the Cartesian product of two sets". It can be seen that this definition is similar to the definition of a function (or mapping). -Since it involves a definite relationship between two sets, it is also called a binary relation, which will continue to be mentioned in the study of the theory of groups, rings, and fields later. +Since it involves a relationship between two sets, it is also called a binary relation. This will be mentioned again in the study of group, ring, and field theories. \ No newline at end of file diff --git a/Languages/en/01_Integer/readme.md b/Languages/en/01_Integer/readme.md index 947b491..d8e29f7 100644 --- a/Languages/en/01_Integer/readme.md +++ b/Languages/en/01_Integer/readme.md @@ -1,26 +1,27 @@ --- -title: 01. Integer Arithmetic Basics +title: 01. Basic Integer Operations tags: - zk - basic - integer --- -# WTF zk Tutorial Lesson 1: Integer Arithmetic Basics +# Zero-Knowledge Proof Tutorial Lesson 1: Basic Integer Operations As a beginner-friendly tutorial on zero-knowledge proofs, we will start by learning the basics of integer arithmetic. Most of you have probably learned this in secondary school, so it should be quite easy. We will also implement integer arithmetic using Python, making it easy for beginners to get started. -For those who haven't used Python before, it is recommended to install [Anaconda](https://www.anaconda.com/download) to install and manage the Python environment. + +If you are new to Python, we recommend installing [Anaconda](https://www.anaconda.com/download) to easily set up and manage your Python environment. ## 1. Basic Definitions -An integer is a number without a decimal part and can be either positive, negative, or zero. We use $\mathbb{Z}$ to represent the set of all integers. +An integer is a whole number without a decimal part. It can be positive, negative, or zero. We use the symbol $\mathbb{Z}$ to represent the set of all integers. $$ \mathbb{Z} = \lbrace \ldots, -3, -2, -1, 0, 1, 2, 3, \ldots \rbrace $$ -For an integer $a \in \mathbb{Z}$, we use $\lvert a \rvert$ to represent the absolute value of $a$, which is the non-negative value of $a$ regardless of its sign. +For an integer $a \in \mathbb{Z}$, the absolute value of $a$, denoted as $\lvert a \rvert$, represents the non-negative value of $a$ without considering its sign. $$ \lvert 69 \rvert = 69 @@ -30,47 +31,47 @@ $$ \lvert -69 \rvert = 69 $$ -We often use the natural numbers $\mathbb{N}$, which are a subset of integers and include all positive integers. +We often use the term "natural numbers" to refer to positive integers. It is a subset of the set of integers and includes all positive integers. $$ \mathbb{N} = \lbrace 1, 2, 3, \ldots \rbrace $$ -In addition, we sometimes use non-negative integers, which we denote as $\mathbb{N_0}$: +Additionally, we sometimes refer to non-negative integers as $\mathbb{N_0}$: $$ \mathbb{N_0} = \lbrace 0, 1, 2, 3, \ldots \rbrace $$ -> Note: Some textbooks include 0 in the set of natural numbers, and there is currently [debate](https://zh.wikipedia.org/wiki/%E8%87%AA%E7%84%B6%E6%95%B0) on whether 0 should be included. - -## 2. Integer Arithmetic +> Note: The inclusion of 0 in the set of natural numbers is a topic of debate. Some textbooks include 0, while others do not. (Source: [Wikipedia](https://en.wikipedia.org/wiki/Natural_number)) -Integer arithmetic includes addition, subtraction, multiplication, and division. Let's review the rules for these basic operations: +## 2. Integer Operations -- **Addition ( $+$ ):** For integers $a$ and $b$, their sum $a + b$ is the result of adding them together. +Integer operations include addition, subtraction, multiplication, and division. Let's review the rules for these basic operations: +- **Addition ($+$):** To add two integers $a$ and $b$, simply sum them up. + ```python a, b = 7, 5 sum_result = a + b - print(f'Addition example: {sum_result}') - # Addition example: 12 + print(f'Example: {sum_result}') + # Example: 12 ``` -- **Subtraction ( $-$ ):** For integers $a$ and $b$, their difference $a - b$ is the result of subtracting $b$ from $a$. - +- **Subtraction ($-$):** To subtract an integer $b$ from another integer $a$, subtract $b$ from $a$. + ```python diff_result = a - b - print(f'Subtraction example: {diff_result}') - # Subtraction example: 2 + print(f'Example: {diff_result}') + # Example: 2 ``` -- **Multiplication ( $\times$ ):** For integers $a$ and $b$, their product $a \times b$ is the result of multiplying them together. - +- **Multiplication ($\times$):** To multiply two integers $a$ and $b$, multiply them together. + ```python product_result = a * b - print(f'Multiplication example: {product_result}') - # Multiplication example: 35 + print(f'Example: {product_result}') + # Example: 35 ``` @@ -78,21 +79,21 @@ Integer arithmetic includes addition, subtraction, multiplication, and division. Integers have some important properties: -- **Closure:** Integer addition and multiplication are closed operations within the set of integers, meaning that the sum or product of any two integers is still an integer. +- **Closure Property:** Integer addition and multiplication are closed within the set of integers. This means that the sum or product of any two integers will still be an integer. -- **Commutativity:** Integer addition and multiplication are commutative, meaning that $a + b = b + a$ and $a \times b = b \times a$ hold true for any integers $a$ and $b$. +- **Commutative Property:** Integer addition and multiplication are commutative. This means that the order of the integers does not affect the result. For any integers $a$ and $b$, $a + b = b + a$ and $a \times b = b \times a$. -- **Associativity:** Integer addition and multiplication are associative, meaning that $(a + b) + c = a + (b + c)$ and $(a \times b) \times c = a \times (b \times c)$ hold true for any integers $a$, $b$, and $c$. +- **Associative Property:** Integer addition and multiplication are associative. This means that the grouping of integers does not affect the result. For any integers $a$, $b$, and $c$, $(a + b) + c = a + (b + c)$ and $(a \times b) \times c = a \times (b \times c)$. ## 4. Euclidean Division The division we commonly use is real number division, where the result of dividing two integers may not be an integer, e.g., $7 \div 5 = 1.4$ is not an integer. Therefore, we introduce integer division, also known as Euclidean Division. Its result consists of two parts: the quotient and the remainder. The definition of Euclidean Division is as follows: -For integers $a$ and $b$ (where $b \neq 0$), there exists a unique pair of integers $(q, r)$ such that $a = bq + r$, where $q$ is the quotient, $r$ is the remainder, and $0 \leq r \lt |b|$. +For integers $a$ and $b$ (where $b \neq 0$), there exists a unique pair of integers $(q, r)$ such that $a = bq + r$. Here, $q$ represents the quotient, $r$ represents the remainder, and $0 \leq r \lt |b|$. -If the remainder when dividing $a$ by $b$ is zero, we say that $a$ is divisible by $b$ ($b$ divides $a$) and write $b \mid a$. We can also call $b$ a factor of $a$. If the remainder is not zero, we write $b \nmid a$. +If the remainder of $a$ divided by $b$ is zero, we say that $a$ is divisible by $b$ ($b$ divides $a$), denoted as $b \mid a$. We can also say that $b$ is a factor of $a$. If the remainder is not zero, we denote it as $b \nmid a$. -We can implement Euclidean Division in Python, taking care to handle the case when $a$ or $b$ is negative: the `divmod` function in Python allows for negative remainders, whereas Euclidean Division requires $0 \leq r \lt |b|$. On the contrary, the modulo operation (`%`) in Python allows for negative numbers. Here, it is necessary to understand the internal implementation formula for the modulo operation in programming languages: $a\%b=a-(a//b) * b$. (The `//` here is Python's internal implementation of Euclidean Division, ensuring a positive remainder less than the divisor). +We can implement Euclidean Division in Python. When implementing it, we need to handle the cases where $a$ or $b$ is negative. The `divmod` function in Python allows for negative remainders, but Euclidean Division requires the remainder to be non-negative and less than the divisor. On the other hand, the modulo operation (`%`) in Python allows for negative remainders. It is necessary to understand the internal implementation formula of the modulo operation in programming languages: $a\%b=a-(a//b) * b$ (where `//` represents the internal implementation of Euclidean Division in Python, ensuring that the remainder is positive and less than the divisor). ```python def euclidean_division(a, b): @@ -100,15 +101,15 @@ def euclidean_division(a, b): if remainder < 0: # Adjust the remainder to ensure it is non-negative remainder += abs(b) - # Adjust the quotient to maintain the equation + # Adjust the quotient to maintain the equation's validity quotient += 1 return quotient, remainder quotient, remainder = euclidean_division(a, b) -print(f'Division example: quotient is {quotient}, remainder is {remainder}') -# Division example: quotient is 1, remainder is 2 +print(f'Example: Quotient is {quotient}, Remainder is {remainder}') +# Example: Quotient is 1, Remainder is 2 ``` ## 5. Summary -In this lesson, we introduced the basics of integers, including their definitions and basic operations (addition, subtraction, multiplication, and Euclidean Division), and implemented them using Python. We believe that most of you have learned these concepts in secondary school and find them straightforward. Let's continue the WTF zk journey! \ No newline at end of file +In this lesson, we introduced the basics of integers, including their definitions and basic operations (addition, subtraction, multiplication, and Euclidean Division), and implemented them using Python. These concepts are usually covered in middle school and are relatively simple. Now, let's continue our journey into the world of Zero-Knowledge Proofs (ZKPs)! \ No newline at end of file diff --git a/Languages/en/02_Prime/readme.md b/Languages/en/02_Prime/readme.md index 5f015b2..a1372cd 100644 --- a/Languages/en/02_Prime/readme.md +++ b/Languages/en/02_Prime/readme.md @@ -1,25 +1,18 @@ ---- -title: 02. Prime Number Basics -tags: - - zk - - basic - - integer ---- +# WTF zk Series: Tutorial 02 - Basics of Prime Numbers # WTF zk Tutorial Lesson 2: Prime Number Basics Welcome to the second lesson of the WTF zk tutorial series! In this tutorial, we will explore the basics of prime numbers. Prime numbers play a crucial role in cryptography, making it essential to understand them for learning zero-knowledge proofs. + ## 1. Definition of Prime Numbers -Prime numbers are also known as prime numbers and are defined as follows: For a natural number greater than 1, if it cannot be divided evenly by any natural number other than 1 and itself, then it is a prime number. +Prime numbers are natural numbers greater than 1 that cannot be evenly divided by any other natural number except 1 and itself. In other words, a prime number has no factors other than 1 and itself. -2, 3, 5, and 7 are all prime numbers because they can only be divided evenly by 1 and themselves. In addition, all even numbers except 2 are not prime numbers because they can be divided evenly by 2 in addition to 1 and themselves. +For example, 2, 3, 5, and 7 are prime numbers because they can only be divided evenly by 1 and themselves. On the other hand, all even numbers (except 2) are not prime numbers because they can be divided evenly by 2. ## 2. Properties of Prime Numbers -Prime numbers are fundamental units of all natural numbers, and the fundamental theorem of arithmetic tells us: - -> Any natural number greater than 1 can be expressed as a unique product of prime numbers, regardless of the order of the prime numbers. +Prime numbers are the basic building blocks of all natural numbers. The fundamental theorem of arithmetic states that any natural number greater than 1 can be expressed as a unique product of prime numbers, regardless of the order of the prime numbers. For example: @@ -27,37 +20,37 @@ $$ 84 = 2^2 \times 3 \times 7 $$ -Here, 2, 3, and 7 are prime numbers, and this factorization is unique. +In this example, 2, 3, and 7 are prime numbers, and this factorization is unique. Prime Number Theorem: The number of prime numbers less than or equal to N is approximately $N/\ln{N}$, and there are infinitely many prime numbers. Proof: -Euclidean proof +Euclidean Proof -1. **Assume a Finite Number of Prime Numbers:** First, assume that there are a finite number of prime numbers, which we denote as $p_1, p_2, \ldots, p_n$. +1. **Assume a Finite Number of Prime Numbers:** Let's assume that there are only a finite number of prime numbers and denote them as $p_1, p_2, \ldots, p_n$. -2. **Construct a New Number:** Consider the new number $N = p_1 \times p_2 \times \ldots \times p_n + 1$, which is obtained by multiplying all known prime numbers and adding 1. +2. **Construct a New Number:** Consider a new number $N = p_1 \times p_2 \times \ldots \times p_n + 1$. This number is obtained by multiplying all known prime numbers and adding 1. -3. **Properties of the New Number:** The number N is obviously a prime number because it is not a multiple of any known prime number, as dividing it by any known prime number leaves a remainder of 1. +3. **Properties of the New Number:** The number N is obviously a prime number because it is not divisible by any known prime number. Dividing N by any known prime number leaves a remainder of 1. -4. **Contradiction:** Hence, this leads to a contradiction, because if N is not a prime number, it must have a prime factor, which either is a known prime number or a new prime number different from the known prime numbers. +4. **Contradiction:** This leads to a contradiction because if N is not a prime number, then it must have a prime factor. This prime factor either belongs to the known prime numbers or is a new prime number different from the known ones. -5. **Conclusion:** In any case, this results in a contradiction with the initial assumption of a finite number of prime numbers. Therefore, the initial assumption is incorrect, and there must be infinitely many prime numbers. +5. **Conclusion:** In either case, this contradicts the initial assumption of a finite number of prime numbers. Therefore, the initial assumption is incorrect, and the number of prime numbers must be infinite. ## 3. Prime Numbers and Composite Numbers -We can classify natural numbers into prime numbers and composite numbers. Composite numbers are the complements of prime numbers: For a natural number greater than 1, if it has factors other than 1 and itself, it is a composite number. For example, 4, 6, 8, and 9 are composite numbers. +Natural numbers can be divided into two categories: prime numbers and composite numbers. Composite numbers are the opposite of prime numbers. A composite number is a natural number greater than 1 that has factors other than 1 and itself. For example, 4, 6, 8, and 9 are all composite numbers. ## 4. Finding Prime Numbers -Finding prime numbers is an important task in number theory, which has attracted attention since medieval times. People tried to find prime number formulas (formulas that can generate prime numbers only) during that time. By the time of Gauss, it was basically confirmed that simple prime number formulas do not exist. Therefore, Gauss believed that primality testing is a fairly difficult problem. Since then, this problem has attracted a large number of mathematicians. Primality testing algorithms can be divided into two main categories: deterministic algorithms and probabilistic algorithms. The former provides a definite result but is usually slower, while the latter provides a result that may vary. +Finding prime numbers is an important task in number theory. This problem gained attention in the Middle Ages when people tried to find formulas that could generate prime numbers exclusively. In the era of Gauss, it was basically confirmed that simple prime formulas do not exist. Gauss believed that determining primality is a very difficult problem. Since then, many mathematicians have been fascinated by this problem. Primality testing algorithms can be divided into two categories: deterministic algorithms and random algorithms. Deterministic algorithms provide a definite result but are usually slower, while random algorithms are the opposite. ### Deterministic Algorithms - [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) -The most commonly used method is the Sieve of Eratosthenes. Its logic is very simple: first, determine a range to search, then eliminate all multiples of prime numbers between 0 and $\sqrt n$, leaving behind all prime numbers within the range. +The most commonly used method is the Sieve of Eratosthenes. Its logic is very simple: first, determine a range to search, then eliminate all multiples of prime numbers between 0 and $\sqrt{n}$. The remaining numbers within the range are all prime numbers. We can implement this method in Python: @@ -78,19 +71,19 @@ print(f'Prime numbers less than or equal to {limit}: {prime_numbers}') # Prime numbers less than or equal to 20: [2, 3, 5, 7, 11, 13, 17, 19] ``` -- [Lucas-Lehmer Primality Test](https://en.wikipedia.org/wiki/Lucas-Lehmer_test) +- [Lucas-Lehmer Primality Test](https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test) - [AKS Primality Test](https://en.wikipedia.org/wiki/AKS_primality_test) -### Probabilistic Algorithms +### Random Algorithms - Fermat Primality Test - - Uses [Fermat's Little Theorem](../07_Exp/readme.md) for testing. + - Test using [Fermat's Little Theorem](../07_Exp/readme.md). - [Miller-Rabin Primality Test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test) -## 5. Applications of Prime Numbers in Cryptography +## 5. Application of Prime Numbers in Cryptography -Prime numbers play a significant role in the field of cryptography, particularly in public-key cryptography. For example, RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses the product of large prime numbers as part of the public and private keys: Calculating the product of prime numbers is simple, but factoring a large composite number into prime factors is extremely difficult, ensuring the security of the RSA encryption algorithm. +Prime numbers play a crucial role in cryptography, especially in public-key cryptography. For example, RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses the product of large prime numbers as part of the public and private keys. Calculating the product of prime numbers is simple, but factoring large composite numbers into prime factors is very difficult. This difficulty ensures the security of the RSA encryption algorithm. -## 6. Conclusion +## 6. Summary -In this tutorial, we have learned the basics of prime numbers, including their definition, properties, and methods for finding prime numbers. Prime numbers have important applications in both mathematics and cryptography, laying the foundation for understanding zero-knowledge proofs. +In this tutorial, we have learned the basics of prime numbers, including their definition, properties, and methods for finding prime numbers. Prime numbers have important applications in mathematics and cryptography, laying the foundation for our understanding of zero-knowledge proofs. \ No newline at end of file diff --git a/Languages/en/03_Euclidean/readme.md b/Languages/en/03_Euclidean/readme.md index 9e61699..8f7ea9c 100644 --- a/Languages/en/03_Euclidean/readme.md +++ b/Languages/en/03_Euclidean/readme.md @@ -1,64 +1,62 @@ --- -title: 03. Euclidean Algorithm +title: 03. Greatest Common Divisor and Euclidean Algorithm tags: - zk - basic - euclidean --- -# WTF zk Tutorial Lesson 3: Euclidean Algorithm +# Zero-Knowledge Tutorial 03: Greatest Common Divisor and Euclidean Algorithm -In this tutorial, we will learn about the greatest common divisor (GCD) and its calculation using the Euclidean Algorithm, which has wide applications in cryptography. +In this tutorial, we will learn about the concept of the greatest common divisor (GCD) and how to calculate it using the Euclidean Algorithm. Understanding these concepts is essential in cryptography. ## 1. Greatest Common Divisor ### 1.1 Definition -The greatest common divisor (GCD) is the largest positive integer that can simultaneously divide both integers. For example, the GCD of 10 and 15 is 5, which can be written as: +The greatest common divisor (GCD) is the largest positive integer that divides two integers without leaving a remainder. For example, the GCD of 10 and 15 is 5, which can be written as: $$ \gcd(10, 15) = 5 $$ +### 1.2 Properties of GCD -### 1.2 Properties of the Greatest Common Divisor - -For natural numbers $a$ and $b$ (assuming $a > b$), the GCD has the following properties: +The GCD of two natural numbers a and b (assuming a > b) has the following properties: 1. Commutative property: $\gcd(a, b) = \gcd(b, a)$ -2. The GCD of $a$ and $b$ is also the GCD of the remainder when $a$ is divided by $b$: $\gcd(a, b) = \gcd(b, a \bmod b)$ +2. The GCD of a and b is also the GCD of b and the remainder when a is divided by b: $\gcd(a, b) = \gcd(b, a \mod b)$ -3. The GCD of $a$ and 0 is $a$: $\gcd(a, 0) = a$ +3. The GCD of a and 0 is equal to a: $\gcd(a, 0) = a$ -4. If $b$ divides $a$ (denoted as $b \mid a$), then $\gcd(a, b) = b$ +4. If b divides a (denoted as $b \mid a$), then $\gcd(a, b) = b$ -You can try to derive these properties. +You can try to prove these properties yourself. -### 1.3 How to Calculate the Greatest Common Divisor +### 1.3 How to Calculate GCD -We commonly use two methods to calculate the greatest common divisor: prime factorization and the Euclidean Algorithm. Let's first introduce the prime factorization method, which consists of three steps: +There are two commonly used methods to calculate the GCD: prime factorization and the Euclidean Algorithm. Let's first introduce the prime factorization method, which consists of three steps: -1. Prime factorization: Perform prime factorization for the two integers, $a$ and $b$, separately. +1. Prime factorization: Perform prime factorization on the given integers a and b. -2. Identify common prime factors: Compare the prime factors of the two numbers and identify the ones they have in common. +2. Find common prime factors: Compare the prime factors of both numbers and find the common factors. -3. Multiply to obtain the greatest common divisor: Multiply the common prime factors to obtain the GCD. +3. Multiply to obtain the GCD: Multiply the common prime factors to obtain the GCD. -For example, let's calculate the GCD of $a = 30$ and $b = 24$. First, perform prime factorization: +For example, let's calculate the GCD of a = 30 and b = 24. First, perform prime factorization: $$ -30 = 2 \times 3 \times 5 +30 = 2 \cdot 3 \cdot 5 $$ - $$ -24 = 2^3 \times 3 +24 = 2^3 \cdot 3 $$ -The common factors are $2 \times 3$, so the GCD is 6. +The common factors are 2 and 3, so the GCD of a and b is 6. -However, prime factorization of large numbers can be very difficult. The Euclidean Algorithm is a more efficient method for calculating the GCD. +However, prime factorization of large numbers can be difficult. The Euclidean Algorithm provides a more efficient method for calculating the GCD. ## 2. Euclidean Algorithm @@ -66,15 +64,15 @@ The Euclidean Algorithm (also known as the division algorithm) is a commonly use ### 2.1 Basic Idea -Let $a$ and $b$ be two integers, where $a \geq b$. Using Euclidean division, we have: +Let's assume we have two integers a and b, where a ≥ b. Using the Euclidean division, we can express a as: $$ a = bq + r $$ -where $q$ and $r$ are natural numbers, and $0 \leq r \lt |b|$. +where q and r are natural numbers, and $0 \leq r \lt |b|$. -According to the properties of the greatest common divisor (Property 2 in section 1.2), $\gcd(a, b) = \gcd(b, r)$, and since $r < b \leq a$, we can transform the problem of finding the GCD between two large numbers to finding the GCD between two smaller numbers. When $r \neq 0$, we can continuously replace $a$ with $b$ and $b$ with $r$, applying the Euclidean division: +According to the properties of the GCD (mentioned in section 1.2, property 2), we have $\gcd(a, b) = \gcd(b, r)$. Since $r < b \leq a$, we can transform the problem of finding the GCD between two large numbers into finding the GCD between two smaller numbers. When r ≠ 0, we can repeatedly replace a with b and b with r using the Euclidean division: $$ b = rq_1 + r_1 @@ -85,27 +83,26 @@ $$ $$ $$ -r_{i-2} = r_{i-1}q_{i} + r_i +r_{i-2} = r_{i-1}q_i + r_i $$ - $$ ... $$ $$ -r_{n-2} = r_{n-1}q_{n} + r_n +r_{n-2} = r_{n-1}q_n + r_n $$ -During the iteration, the GCD has the following relation: +During the iteration, the GCD has the following relationship: $$ -\gcd(a, b) = \gcd(b, r) = ... = \gcd(r_{n-2}, r_{n-1}) = \gcd(r_{n-1}, r_{n}) +\gcd(a, b) = \gcd(b, r) = ... = \gcd(r_{n-2}, r_{n-1}) = \gcd(r_{n-1}, r_n) $$ -Since $0 \leq r_n < r_{n-1} < r$, the value of $r_n$ decreases with each iteration until $r_n = 0$. +Since $0 \leq r_n < r_{n-1} < r$, the value of r decreases with each iteration until r_n = 0. -When $r_n = 0$, according to the property of the GCD (Property 3 in Section 1.2), we have: +When r_n = 0, according to the properties of the GCD (mentioned in section 1.2, property 3), we have: $$ \gcd(r_{n-1}, r_n) = \gcd(r_{n-1}, 0) = r_{n-1} @@ -115,30 +112,32 @@ Therefore, the GCD $\gcd(a, b) = r_{n-1}$. ### 2.2 Algorithm Steps -1. Let $r$ be the remainder when $a$ is divided by $b$, i.e. $r = a \mod b$. -2. If $r$ is not zero, replace $a$ with $b$, and $r$ with $b$, and return to step 1. -3. If $r$ is zero, $b$ is the GCD. - -### 2.3 Example +The Euclidean Algorithm can be implemented with the following steps: -Let's calculate the GCD of $a = 30$ and $b = 24$: +1. Let r be the remainder when a is divided by b, i.e., $r = a \mod b$. +2. If r is not zero, replace a with b, replace b with r, and go back to step 1. +3. If r is zero, b is the GCD. -1. Step 1: Apply the Euclidean division, $30 = 1 \cdot 24 + 6$. +### 2.3 Example -2. Step 2: Since the remainder $r = 6$ is not zero, replace $a$ with $b$, and $r$ with $b$, and continue with the Euclidean division: $24 = 4 \cdot 6 + 0$. +Let's calculate the GCD of a = 30 and b = 24: -3. Step 3: The remainder in the previous step, $r = 0$, is zero. Stop the iteration. The GCD is $\gcd(30, 24) = 6$. +1. Step 1: Using the Euclidean division, we have 30 = 1 * 24 + 6. +2. Step 2: Since the remainder r = 6 is not zero, we replace a with b, b with r, and continue with the Euclidean division: 24 = 4 * 6 + 0. +3. Step 3: The remainder r = 0 is zero, so we stop the iteration. The GCD of 30 and 24 is $\gcd(30, 24) = 6$. ### 2.4 Intuitive Understanding + Suppose we have a rectangular room with length $a$ and width $b$. We want to tile the room with square tiles, and each side of the square tiles should be as long as possible. The maximum side length is actually the GCD $\gcd(a, b)$, and the Euclidean method allows us to find it: -First, we try to tile the rectangle with $b \times b$ square tiles. However, this leaves a leftover rectangle with dimensions $r \times b$, where $r < b$. Then, we try to tile the remaining rectangle with $r \times r$ square tiles, which leaves another residual rectangle with dimensions $r_1 \times r$. We continue this process by attempting to tile each leftover rectangle with $r_i \times r_i$ square tiles. When there is no residual rectangle left, i.e., when the square tiles completely cover the previous leftover rectangle, the sequence ends. The side length of the smallest square tile is the GCD $\gcd(a, b)$. + +First, we try to cover the rectangle with b × b square tiles. However, this leaves a remaining rectangle with dimensions r × b, where r < b. Then, we try to cover the remaining rectangle with r × r square tiles, leaving another remaining rectangle with dimensions r1 × r. We continue this process, trying to cover the remaining rectangles with smaller and smaller square tiles. When there is no remaining rectangle, i.e., when the square tiles completely cover the previous remaining rectangle, the sequence ends. The side length of the smallest square tile is the GCD. ![Image from Wikipedia](./img/3-1.gif) ### 2.5 Code Implementation -We can implement the Euclidean Algorithm using Python with just 6 lines of code: +We can implement the Euclidean Algorithm in Python with just 6 lines of code: ```python def euclidean_algorithm(a, b): @@ -152,10 +151,10 @@ def euclidean_algorithm(a, b): num1 = 30 num2 = 24 gcd_result = euclidean_algorithm(num1, num2) -print(f'The greatest common divisor of {num1} and {num2} is {gcd_result}') -# Output: The greatest common divisor of 30 and 24 is 6 +print(f'The GCD of {num1} and {num2} is {gcd_result}') +# Output: The GCD of 30 and 24 is 6 ``` ## 3. Summary -The greatest common divisor is crucial in cryptography, and the Euclidean Algorithm is a commonly used algorithm to solve the GCD of integers. By understanding this algorithm, we have laid the foundation for further learning zero-knowledge proofs and cryptography. +The greatest common divisor (GCD) is an important concept in cryptography, and the Euclidean Algorithm is a commonly used algorithm for finding the GCD of integers. By understanding this algorithm, we have laid the foundation for further learning about zero-knowledge proofs and cryptography. \ No newline at end of file diff --git a/Languages/en/07_Exp/readme.md b/Languages/en/07_Exp/readme.md index 12f43eb..1d4a93e 100644 --- a/Languages/en/07_Exp/readme.md +++ b/Languages/en/07_Exp/readme.md @@ -1,78 +1,86 @@ -# WTF zk Tutorial Lesson 7: Fermat's Little Theorem +--- +title: 07. Fermat's Little Theorem +tags: + - zk + - basic + - chinese remainder theorem +--- -Previously we introduced addition, subtraction, multiplication, and division in modular arithmetic. In this tutorial, we will introduce modular exponentiation and Fermat's Little Theorem. +# Tutorial 07: Fermat's Little Theorem + +In the previous tutorial, we introduced addition, subtraction, multiplication, and division in modular arithmetic. In this tutorial, we will introduce modular exponentiation and Fermat's Little Theorem. ## 1. Modular Exponentiation -Modular exponentiation refers to the operation of raising a number to a power modulo n, which is commonly used in cryptography: +Modular exponentiation is the operation of exponentiation performed on a modulus and is widely used in cryptography: $$ b = a^c \mod{n} $$ -where $0 \leq b < n$. +where $0 \le b < n$. -For example, given $(a, c, n) = (7, 5, 13)$, we can calculate $7^5=16807$, which leaves a remainder of 11 when divided by 13, so $b = 11$. +For example, given $(a, c, n) = (7, 5, 13)$, we can calculate that $7^5=16807$, which when divided by 13 leaves a remainder of 11, so $b = 11$. -Of course, modular exponentiation can also be expressed in congruence form: +Modular exponentiation can also be written in congruence form: $$ b \equiv a^c \pmod{n} $$ -### 1.1 Optimized Algorithm +### 1.1 Optimization Algorithm -$a^c$ can be a very large number, taking up a lot of memory in a computer, while the result of modular arithmetic is $0 \leq b < n$. Therefore, we can save memory by utilizing the properties of modular arithmetic. +Computing $a^c$ can require a significant amount of memory, while the result of the modular operation, $0 \le b < n$, can be much smaller. Therefore, we can optimize memory usage by leveraging the properties of modular arithmetic. According to modular arithmetic, we have: $$ -x \cdot y \mod{n} = (x \mod{n}) \cdot (y \mod{n}) \mod{n} +x \cdot y \mod{n} = (x \mod{n}) \cdot (y \mod{n}) \mod{n} $$ -If both x and y are large, we can first perform the modulo operation and then multiply, saving memory usage. Exponentiation can be expanded into repeated multiplication: +If both $x$ and $y$ are large, we can first perform the modulus operation on them and then perform the multiplication to save memory. Additionally, exponentiation can be expressed as repeated multiplication: $$ -a^c \mod{n} = a \cdot a \cdot a \cdot ... \mod{n} +a^c \mod{n} = a \cdot a \cdot a \cdot ... \mod{n} $$ -Therefore, we can multiply a by a and then take modulo in each step, transforming the product into a smaller number, and continue to multiply a and take modulo until the operation is complete: +Therefore, we can multiply $a$ at each step and then take the modulus, reducing the number in each step, and continue this process until the operation is completed. $$ -a^c \mod{n} = (((a \cdot a \mod{n}) \cdot a \mod{n}) \cdot ... )\mod{n} +a^c \mod{n} = (((a \cdot a \mod{n}) \cdot a \mod{n}) \cdot ... )\mod{n} $$ -Taking $(a, c, n) = (7, 5, 13)$ as an example: +Let's take $(a, c, n) = (7, 5, 13)$ as an example: -1. In the first step, calculate $7 * 7 \mod{13} = 10$. +1. In the first step, we calculate $7 * 7 \mod{13} =10$. -2. In the second step, calculate $10 * 7 \mod{13} = 5$. +2. In the second step, we calculate $10 * 7 \mod{13} = 5$. -3. In the third step, calculate $5 * 7 \mod{13} = 9$. +3. In the third step, we calculate $5 * 7 \mod{13} = 9$. -4. In the fourth step, calculate $9 * 7 \mod{13} = 11$, and it is finished. Therefore, $b = 11$. +4. In the fourth step, we calculate $9 * 7 \mod{13} = 11$, and we are done. Therefore, $b = 11$. ## 1.2 Code Implementation -We implement the optimized algorithm for modular exponentiation in Python: +We can implement the optimized algorithm for modular exponentiation in Python as follows: ```python def mod_pow(base, exponent, modulus): result = 1 - # Expand the exponent into binary form and process each bit from highest to lowest + # Expand the exponent into binary form and process each bit from high to low while exponent > 0: - # If the current bit is 1, multiply it by the current base and then take modulo + # If the current bit is 1, multiply by the current base and then take the modulus if exponent % 2 == 1: result = (result * base) % modulus - # Square the base and then take modulo + # Square the base and then take the modulus base = (base * base) % modulus - # Right shift one bit, which is equivalent to dividing by 2 + # Right shift by one bit, equivalent to dividing by 2 exponent //= 2 return result -# Example: Calculate (7^5) % 13 +# Example: calculate (7^5) % 13 a = 7 c = 5 n = 13 @@ -83,35 +91,35 @@ print(f"{a}^{c} mod {n} = {result}") ## 2. Fermat's Little Theorem -Fermat's Little Theorem is an important theorem in number theory, providing a powerful tool for solving modular exponentiation problems. +Fermat's Little Theorem is an important theorem in number theory that provides a powerful tool for solving modular exponentiation problems. ### 2.1 Definition -Fermat's Little Theorem states that if p is a prime number, then for any integer a: +Fermat's Little Theorem states that if $p$ is a prime number, then for any integer $a$, we have $$ a^{p} \equiv a \pmod{p} $$ -In other words, $a^p -a$ is divisible by p. For example, for $a = 3$ and $p = 5$, we have $3^5 - 3 = 240 = 48 \cdot 5$. +In other words, $a^p -a$ is divisible by $p$. For example, when $a = 3$ and $p = 5$, we have $3^5 - 3 = 240 = 48 \cdot 5$. -Fermat's Little Theorem can also be written in another form. When a is coprime with p, we can divide both sides of the equation by a to get the following form: +Fermat's Little Theorem can also be written in another form. When $a$ is coprime to $p$, we can divide both sides of the equation by $a$ to obtain the following form: $$ a^{p-1} \equiv 1 \pmod{p} $$ -In other words, $a^{p-1} -1$ is divisible by p. For example, for $a = 3$ and $p = 5$, we have $3^4 -1 = 80 = 16 \cdot 5$. +In other words, $a^{p-1} -1$ is divisible by $p$. For example, when $a = 3$ and $p = 5$, we have $3^4 -1 = 80 = 16 \cdot 5$. ### 2.2 Proof -First, we need to prove that the following equation holds for prime number p: +First, we need to prove that the following equation holds for prime numbers $p$: $$ (x+y)^p \equiv x^p +y^p \pmod{p} $$ -We expand the equation using the binomial theorem. Except for $x^p$ and $y^p$, the remaining terms contain p and can be canceled by dividing by p: +We expand the original equation using the binomial theorem. Except for $x^p$ and $y^p$, all other terms contain $p$ and can be eliminated by dividing by $p$: $$ (x+y)^p \equiv x^p +y^p + p(...) \equiv x^p +y^p \pmod{p} @@ -123,30 +131,29 @@ $$ (x_1 + ... + x_n)^p \equiv x_1^p + ... + x_n^p \pmod{p} $$ -If we expand a as a sum of a's, $a = 1+ ... +1$, and substitute it into the equation, we have: +If we expand $a$ as $a$ ones added together $a = 1+ ... +1$, and substitute it into the above equation, we have: $$ a^p \equiv (1 + ... + 1)^p \equiv 1^p + ... + 1^p \equiv a \pmod{p} $$ -Proof is complete. +Therefore, the proof is complete. ### 2.3 Applications +#### 2.3.1 Calculating Modular Inverses -#### 2.3.1 Calculation of Modular Inverse - -Fermat's Little Theorem can also be used to calculate the modular inverse. If p is a prime number and a is not divisible by p, then $a^{p-2}$ is the modular inverse of a modulo p. That is: +Fermat's Little Theorem can also be used to calculate modular inverses. If $p$ is a prime number and $a$ is not divisible by $p$, then $a^{p-2}$ is the modular inverse of $a$ modulo $p$. In other words: $$ a \cdot a^{p-2} \equiv 1 \pmod{p} $$ -For example, for $a = 3$ and $p = 5$, the modular inverse of a is $3^{5-2} \equiv 27 \equiv 2 \pmod{5}$. +For example, when $a = 3$ and $p = 5$, the modular inverse of $a$ is $3^{5-2} \equiv 27 \equiv 2 \pmod{5}$. #### 2.3.2 Primality Testing -Fermat's Little Theorem can be used for probabilistic primality testing. For a given prime number p, randomly choose an integer a and check if it satisfies $a^{p-1} \equiv 1 \pmod{p}$. If it does not, then p is definitely not prime; if it does, then p is potentially prime. However, it is important to note that there exist pseudoprimes, which are numbers that pass the test but are not prime. +Fermat's Little Theorem can be used for probabilistic primality testing. For a given prime number $p$, randomly choose an integer $a$ and check if it satisfies $a^{p-1} \equiv 1 \pmod{p}$. If it does not satisfy the equation, then $p$ is definitely not a prime number; if it satisfies the equation, then $p$ may be a prime number. However, it should be noted that there are pseudoprimes, which are numbers that are not prime but pass the test. ## 3. Summary -In this tutorial, we introduced modular exponentiation and Fermat's Little Theorem. Fermat's Little Theorem is a very useful tool in the fields of number theory and cryptography, with a wide range of applications. By understanding Fermat's Little Theorem deeply, we can better apply it to solve mathematical problems related to primality testing, modular inverses, and more. +In this tutorial, we introduced modular exponentiation and Fermat's Little Theorem. Fermat's Little Theorem is a very useful tool in number theory and cryptography, with a wide range of applications. By understanding Fermat's Little Theorem in depth, we can better apply it to solve mathematical problems related to primality testing, modular inverses, and more. \ No newline at end of file diff --git a/Languages/en/08_Remainder/readme.md b/Languages/en/08_Remainder/readme.md index a088a54..46770bc 100644 --- a/Languages/en/08_Remainder/readme.md +++ b/Languages/en/08_Remainder/readme.md @@ -1,332 +1 @@ -# WTF zk Tutorial 8: Chinese Remainder Theorem - -In this tutorial, we will introduce the concept of residue classes and the famous Chinese Remainder Theorem, which can be used to solve systems of congruences. - -## 1. The Problem of Unknown Number - -In the "Sunzi Suanjing" of the Northern and Southern Dynasties in China (420-589 AD), there is a problem known as the "Problem of Unknown Number". The warrior who solves this problem will receive BTC (Balance: 0) held by Sunzi. - -> There is an unknown number, when divided by 3, the remainder is 2; when divided by 5, the remainder is 3; when divided by 7, the remainder is 2. What is the number? - -Translated into ancient Chinese: There is an unknown number $x$, when divided by 3, the remainder is 2; when divided by 5, the remainder is 3; when divided by 7, the remainder is 2. Find the value of $x$. - -In fact, this is a problem of solving a system of linear congruences, that is, finding $x$ that satisfies the following system of equations: - -$$ -x \equiv 2 \pmod{3} -$$ - -$$ -x \equiv 3 \pmod{5} -$$ - -$$ -x \equiv 2 \pmod{7} -$$ - -The Chinese Remainder Theorem we are about to introduce is used to solve this problem. - -## 2. Residue Classes - -In Lesson 5, we briefly learned about the concept of residue classes in modular arithmetic. Now we need to introduce it more systematically. - -Residue classes are a type of equivalence relation used to divide integers into sets that are congruent. They are defined as follows: - -> Given an integer $m$, we define the residue class of an integer $a$ modulo $m$ as the set of all integers congruent to $a$ modulo $m$. This set is usually denoted by $[a]_m$ and can be expressed as: - -$$ -[a]_m = \{ b \in \mathbb{Z} \mid a \equiv b \pmod{m} \} -$$ - -Here, $\equiv$ denotes the congruence relation. - -For example, for modulo $m = 5$, there are residue classes $[0]_5, [1]_5, [2]_5, [3]_5, [4]_5$, etc: - -$$ -[0]_5 = \{..., -10, -5, 0, 5, 10, ... \} -$$ - -$$ -[1]_5 = \{..., -9, -4, 1, 6, 11, ... \} -$$ - -$$ -[2]_5 = \{..., -8, -3, 2, 7, 12, ... \} -$$ - -$$ -[3]_5 = \{..., -7, -2, 3, 8, 13, ... \} -$$ - -$$ -[4]_5 = \{..., -6, -1, 4, 9, 14, ... \} -$$ - -Residue classes are not unique; for example, $[5]_5, [6]_5, [7]_5, [8]_5, [9]_5$ are also residue classes modulo 5. But we usually choose the smallest non-negative integers as representatives of the residue classes, and they are called the representative elements of the residue classes. For example, the representative elements of the residue classes modulo 5 are $\{0_5, 1_5, 2_5, 3_5, 4_5\}$ or simply $\{0, 1, 2, 3, 4\}$, which can also be written as $Z_5$. - -### 2.1. Properties - -Residue classes form a partition of the set of integers and satisfy the three properties of an equivalence relation: - -- **Reflexivity:** Any integer $a$ is congruent to itself, $a \equiv a \pmod{m}$, so $[a]_m$ is not empty. - -- **Symmetry:** If $a \equiv b \pmod{m}$, then $b \equiv a \pmod{m}$, which can also be written as $[a]_m = [b]_m$. - -- **Transitivity:** If $a \equiv b \pmod{m}$ and $b \equiv c \pmod{m}$, then $a \equiv c \pmod{m}$, which can also be written as $[a]_m = [b]_m = [c]_m$. - -### 2.2 Operations on Residue Classes - -Since residue classes divide integers into congruent sets, they can be seen as an abstraction and generalization of congruence relations, so their operations are the same as those of congruences. - -For example, for two residue classes $[a]_m$ and $[b]_m$, we have: - -$$ -[a]_m + [b]_m = [a + b]_m -$$ - -$$ -[a]_m \cdot [b]_m = [a \cdot b]_m -$$ - -## 3. Systems of Congruences - -### 3.1 Congruence Equations - -Congruence equations are an important type of equations in number theory, of the form $ax \equiv b \pmod{m}$. Solving congruence equations involves concepts such as modular arithmetic and modular inverses. - -Example: $4x \equiv 2 \pmod{6}$ - -First, we notice that both sides of the equation have 2, and $\gcd(2, 6) = 2$. Therefore, we can divide both sides of the equation by 2 and the modulus, getting: - -$$ -2x \equiv 1 \pmod{3} -$$ - -Since 2 and 3 are coprime, $2^{-1} \pmod{3}$ exists. We can write the equation as: - -$$ -x \equiv 2^{-1} \pmod{3} -$$ - -By exhaustive search, we find that $2^{-1} \pmod{3} \equiv 2$, so the solution is: - -$$ -x = [2]_3 -$$ - -### 3.2 Systems of Congruences - -A system of congruences is a set of equations composed of multiple congruence equations, each involving modular arithmetic. - -Let's first look at an example with only two equations: - -$$ -x \equiv 2 \pmod{3} -$$ - -$$ -x \equiv 3 \pmod{5} -$$ - -By observation, we know that if $y$ is a solution, so is $y+15$. By exhaustive search, we easily find $y = 8$ is a solution, so the general solution of the system is $[8]_{15}$, which is: - -$$ -x = 8 + 15k -$$ - -where $k \in \mathbb{Z}$. - -## 4. Chinese Remainder Theorem - -The Chinese Remainder Theorem provides conditions for the existence and methods for solving a system of linear congruences. - -### 4.1 Simple Form - -Let's first look at a system of congruences with only two equations, and then generalize to $n$ equations. - -Let integers $p$ and $q$ be coprime, and the system of equations is as follows: - -$$ -x \equiv a \pmod{p} -$$ - -$$ -x \equiv b \pmod{q} -$$ - -According to the Chinese Remainder Theorem, this system of equations has a unique solution: - -$$ -x \equiv aqq_1+bpp_1 \pmod{pq} -$$ - -where $p_1 = p^{-1} \pmod{q}$, and $q_1 = q^{-1} \pmod{p}$. - -
Click to expand proof👀 - -Taking modulo $p$ of the above equation, we have $x \equiv aqq_1 \pmod{p}$, because $bpp_1$ is divisible by $p$. Also, since $qq_1\pmod{p} = 1$, we have $x \equiv a \pmod{p}$, which satisfies the condition. - -Similarly, taking modulo $q$ of the above equation, we have $x \equiv b \pmod{q}$, which satisfies the condition. - -Thus, $x \equiv aqq_1+bpp_1 \pmod{pq}$ is a solution of the system of equations. - -Next, we prove the uniqueness of the solution: - -Assume there is another solution $y$ that satisfies the system of equations. - -1. Since $y \equiv a \pmod{p}$, we have $p|y-x$. - -2. Since $y \equiv b \pmod{q}$, we have $q|y-x$. - -3. Because $p$ and $q$ are coprime, we have $pq|y-x$, hence $y \equiv x \pmod{pq}$, and the solution is unique. - -
- -#### Example - -Let's use the Chinese Remainder Theorem to solve the example in 3.2: - -$$ -x \equiv 2 \pmod{3} -$$ - -$$ -x \equiv 3 \pmod{5} -$$ - -Here, $pq = 15$, $p_1= 3^{-1} = 2 \pmod{5}$, $q_1 = 5^{-1} = 2\pmod{3}$. Therefore: - -$$ -x \equiv 2 \times 5 \times 2 + 3 \times 3 \times 2 \equiv 38 \equiv 8 \pmod{15} -$$ - -This matches the result we obtained earlier using exhaustive search. - -### 4.2 General Solution - -Now, let's introduce the general form of the Chinese Remainder Theorem. - -Let $m_1, m_2, ..., m_n$ be pairwise coprime (for $i \ne j$, we have $\gcd(m_i,m_j) = 1$), and consider a system of equations with $n$ congruence equations: - -$$ -x \equiv a_1 \pmod{m_1} -$$ - -$$ -x \equiv a_2 \pmod{m_1} -$$ - -$$ -... -$$ - - -$$ -x \equiv a_n \pmod{m_n} -$$ - -The system of equations has a unique solution modulo $M = m_1 \cdot m_2 \cdot ... \cdot m_n$: - -$$ -x \equiv \sum_{i=1}^{n}{a_ib_ib_i'} \pmod{M} -$$ - -where $b_i = M/m_i$ (i.e., the product of all moduli except $m_i$), and $b_i'=b_i^{-1} \pmod{m_i}$ (i.e., the inverse of $b_i$ modulo $m_i$). - -
Click to expand proof👀 - -Taking the general solution modulo $m_i$, we get $x \equiv a_ib_ib_i' \pmod{m_i}$, because except for the $i$-th term, the rest can be divided by $m_i$. Moreover, because $b_ib_i' \equiv 1 \pmod{m_i}$, we have $x \equiv a_i \pmod{m_i}$, which satisfies the condition and is a solution of the system of equations. - -
- -### 4.3 Solving the Problem of Unknown Number - -With the Chinese Remainder Theorem, we can easily solve the problem of the unknown number: - -$$ -x \equiv 2 \pmod{3} -$$ - -$$ -x \equiv 3 \pmod{5} -$$ - -$$ -x \equiv 2 \pmod{7} -$$ - -First, we calculate $M = 3 \times 5 \times 7 = 105$. - -Next, we calculate $a_i, b_i, b_i'$. - -$a_1 = 2, b_1 = 35, b_1' \equiv 35^{-1} = 2\pmod{3}$ - -$a_2 = 3, b_2 = 21, b_2' \equiv 21^{-1} = 1\pmod{5}$ - -$a_3 = 2, b_3 = 15, b_3' \equiv 15^{-1} = 1\pmod{7}$ - -Therefore, the solution of the system of equations is $x \equiv 2 \times 35 \times 2 + 3 \times 21 \times 1 + 2 \times 15 \times 1 \equiv 233 \equiv 23 \pmod{105}$. - -Let's try substituting the solution into the equations. 23 is congruent to 2 modulo 3, 3 modulo 5, and 2 modulo 7, which satisfies the conditions. - -### 4.4 Code Implementation - -We can implement the Chinese Remainder Theorem in Python: - -```python -def extended_gcd(a, b): - if b == 0: - return a, 1, 0 - else: - d, x, y = extended_gcd(b, a % b) - return d, y, x - (a // b) * y - -def chinese_remainder_theorem(congruences): - """ - Function to solve the Chinese Remainder Theorem - - :param congruences: The system of linear congruences, in the format [(a1, m1), (a2, m2), ..., (an, mn)], representing the equations as x ≡ ai (mod mi) - :return: The solution x of the system of equations - """ - # Calculate the product of moduli M - M = 1 - for _, mi in congruences: - M *= mi - - # Calculate Mi and the modular inverse of Mi - M_values = [M // mi for _, mi in congruences] - Mi_values = [extended_gcd(Mi, mi)[1] for Mi, (_, mi) in zip(M_values, congruences)] - - # Calculate the solution x - x = sum(ai * Mi * mi for (ai, _), Mi, mi in zip(congruences, Mi_values, M_values)) % M - - return x - -# Example: Solve x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7) -congruences = [(2, 3), (3, 5), (2, 7)] -solution = chinese_remainder_theorem(congruences) -print(f"The solution to the system of congruences is x ≡ {solution} (mod {congruences[0][1] * congruences[1][1] * congruences[2][1]})") -# The solution to the system of congruences is x ≡ 23 (mod 105) -``` - -### 4.5 Reverse Use - -The Chinese Remainder Theorem can be used in reverse, decomposing the solution $X$ of an equation into multiple congruence equations. For example, in the problem of unknown numbers, if we obtain the solution $x \equiv 23 \pmod{105}$, we can decompose it into 3 equations: - -$$ -x \equiv 2 \pmod{3} -$$ - -$$ -x \equiv 3 \pmod{5} -$$ - -$$ -x \equiv 2 \pmod{7} -$$ - -In this way, we can break down the "big problem" into "small problems", which is very important in zero-knowledge proofs. - -## 5. Summary - -In this lesson, we learned about residue classes, systems of congruences, and the Chinese Remainder Theorem. The Chinese Remainder Theorem not only solves systems of congruences but also allows for reverse use, decomposing a big problem into smaller problems, which is crucial in zero-knowledge proofs. +Error during translation: 524 Server Error: for url: https://api.dify.ai/v1/workflows/run \ No newline at end of file diff --git a/Languages/en/09_Unit/readme.md b/Languages/en/09_Unit/readme.md index 7ab880f..4238d33 100644 --- a/Languages/en/09_Unit/readme.md +++ b/Languages/en/09_Unit/readme.md @@ -1,14 +1,22 @@ -# Tutorial 09: Euler's Totient Function +--- +title: 09. Euler's Totient Function +tags: + - zk + - basic + - euler's totient function +--- -Given an integer $n$, how many positive integers less than or equal to $n$ are relatively prime to $n$? In this tutorial, we will study this problem, including the concepts of unit set and Euler's totient function. +# Tutorial 9: Euler's Totient Function + +Given an integer $n$, how many positive integers less than or equal to $n$ are coprime with $n$? In this tutorial, we will explore this problem and introduce the concepts of unit set and Euler's totient function. ## 1. Unit Set -If $x \in \mathbb{Z}_n$ is invertible (i.e., has a multiplicative inverse), we call $x$ a unit of $\mathbb{Z}_n$. The set of all units of $\mathbb{Z}_n$ is called the unit set and is denoted as $\mathbb{Z}_n^*$. +If an integer $x \in \mathbb{Z}_n$ is invertible (i.e., it has a multiplicative inverse), we call it a unit of $\mathbb{Z}_n$. The set of all units of $\mathbb{Z}_n$ is called the unit set, denoted as $\mathbb{Z}_n^*$. -From our previous study, we know that $x \in \mathbb{Z}_n$ is invertible if and only if $x$ is relatively prime to $n$. Therefore, the elements in $\mathbb{Z}_n^*$ are the positive integers in the range $[1, ..., n-1]$ that are relatively prime to $n$. In congruence theory, this set is also known as the set of coprime residues modulo $n$. +From our previous study, we know that $x \in \mathbb{Z}_n$ is invertible if and only if $x$ is coprime with $n$. Therefore, the elements in $\mathbb{Z}_n^*$ are the positive integers in the range $[1, ..., n-1]$ that are coprime with $n$. In congruence theory, this set is also known as the coprime congruence class modulo $n$. -Here are some examples: +Here are a few examples: $\mathbb{Z}^*_2 = \{1\}$ @@ -24,92 +32,99 @@ $\mathbb{Z}^*_{15} = \{1, 2, 4, 7, 8, 11, 13, 14\}$ ## 2. Euler's Totient Function -Euler's totient function, denoted as $\phi(n) = |\mathbb{Z}_n^*|$, calculates the number of elements in the unit set $\mathbb{Z}_n^*$. In other words, it counts the number of positive integers in the range $[1, ..., n-1]$ that are relatively prime to $n$. Additionally, we define $\phi(1) = 1$. +The Euler's totient function is denoted as $\phi(n) = |\mathbb{Z}_n^*|$, which represents the number of elements in the unit set $\mathbb{Z}_n^*$. In other words, it is the number of positive integers in the range $[1, ..., n-1]$ that are coprime with $n$. Additionally, we define $\phi(1) = 1$. -Here are some examples: $\phi(2) = 1$, $\phi(3) = 2$, $\phi(5) = 4$, $\phi(8) = 4$, $\phi(9) = 6$, $\phi(15) = 8$. +Here are a few examples: $\phi(2) = 1$, $\phi(3) = 2$, $\phi(5) = 4$, $\phi(8) = 4$, $\phi(9) = 6$, $\phi(15) = 8$. ### 2.1 Properties of Euler's Totient Function -Euler's totient function has some magical properties that make it easy to calculate the number of elements in $\mathbb{Z}_n^*$. The first two properties apply when $n$ is a prime number. The third property is the multiplicativity property of Euler's totient function, which allows us to express the totient function of a composite number as a product of the totient functions of its prime factors. +The Euler's totient function has some interesting properties that facilitate the calculation of the number of elements in $\mathbb{Z}_n^*$. The first two properties are applicable to prime numbers $p$, and the third property concerns the multiplicativity of the Euler's totient function, enabling the calculation for composite numbers as a product of the Euler's totient functions of their prime factors. + +#### 1. For prime numbers $p$, we have $\phi(p) = p-1$ -#### 1. For a prime number $p$, we have $\phi(p) = p-1$ +Here are a few examples: $\phi(2) = 1$, $\phi(3)=2$, $\phi(13)=12$. -Here are some examples: $\phi(2) = 1$, $\phi(3)=2$, $\phi(13)=12$. +
Proof -Proof: +Since $p$ is a prime number, every $x \in \mathbb{Z}_p$ is coprime with $p$, which means there are $p-1$ elements in the range $[1, ..., p-1]$ that are coprime with $p$. -Since $p$ is a prime number, any $x \in \mathbb{Z}_p$ is relatively prime to $p$, which means $[1, ..., p-1]$ contains $(p-1)$ elements. +
-#### 2. For a prime number $p$ and a positive integer $k$, we have $\phi(p^k) = p^k - p^{k-1}$ +#### 2. For prime numbers $p$ and positive integer $k$, we have $\phi(p^k) = p^k - p ^{k-1}$. -Here are some examples: +Here are a few examples: $$ -\phi(8)=\phi(2^3) = 2^3 - 2^2 = 4 +\phi(8)= \phi(2^3) = 2^3 - 2^2 = 4 $$ $$ \phi(9)=\phi(3^2) = 3^2 - 3^1 = 6 $$ -Proof: +
Proof -In the range $[1, ..., p^k]$, there are a total of $p^k$ elements. Since $p$ is a prime number, only the multiples of $p$, which are $[p, 2p, 3p, ..., p^k -p, p^k]$, are not relatively prime to $p$. Therefore, among every $p$ numbers, only $1$ number is not relatively prime to $p$, and there are a total of $p^k / p = p^{k-1}$ such sets of $p$ numbers. Thus, the number of elements that are relatively prime to $p^k$ is $p^k - p ^{k-1}$, which is equal to $\phi(p^k) = p^k - p ^{k-1}$. +There are a total of $p^k$ elements in the range $[1, ..., p^k]$. Since $p$ is a prime number, only the multiples of $p$ in the range $[p, 2p, 3p, ..., p^k -p, p^k]$ can be divided by $p$ and are not coprime with $p$. Therefore, among every $p$ numbers, only one is not coprime with $p$. There are a total of $p^k / p = p^{k-1}$ such sets of $p$ numbers. Therefore, there are $p^k - p ^{k-1}$ numbers that are coprime with $p$, and $\phi(p^k) = p^k - p ^{k-1}$. -#### 3. If $m$ and $n$ are relatively prime (i.e., $\gcd(m,n)=1$), we have $\phi(mn) = \phi(m)\phi(n)$ +
-Here are some examples: +#### 3. If $m$ and $n$ are coprime, i.e., $\gcd(m,n)=1$, then $\phi(mn) = \phi(m)\phi(n)$ +Here are a few examples: + $$ -\phi(15)=\phi(3) \times \phi(5) = 2 \times 4 = 8 +\phi(15)= \phi(3) \times \phi(5) = 2 \times 4 = 8 $$ $$ -\phi(18)=\phi(2) \times \phi(3^2) = 1 \times (3^2 - 3^1) = 6 +\phi(18)= \phi(2) \times \phi(3^2) = 1 \times (3^2 - 3^1) = 6 $$ -Proof: +
Proof -We need to show that there is a bijection between ${\mathbb{Z}_{mn}^*}$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, meaning that they have the same number of elements. The number of elements in $\mathbb{Z}_{mn}^*$ is $\phi(mn)$, and the number of elements in $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$ is $\phi(m)\phi(n)$. Therefore, we want to prove that $\phi(mn) = \phi(m)\phi(n)$. +We need to prove that the sets ${\mathbb{Z}_{mn}^*}$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$ have a bijective relationship, which means their elements correspond one-to-one, and therefore, they have the same number of elements. The number of elements in $\mathbb{Z}_{mn}^*$ is $\phi(mn)$, and the number of elements in $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$ is $\phi(m)\phi(n)$, so $\phi(mn) = \phi(m)\phi(n)$. -We establish a mapping $f: \mathbb{Z}_{mn}^* \rightarrow \mathbb{Z}_m^* \times \mathbb{Z}_n^*$, which uniquely determines the residues $a, b$ modulo $m$ and modulo $n$, respectively. Thus, this mapping is well-defined. +We can establish a mapping $f: \mathbb{Z}_{mn}^* \to{\mathbb{Z}_m^* \times \mathbb{Z}_n^*}$, which uniquely determines the residues $a, b$ modulo $m$ and modulo $n$, respectively. Therefore, this mapping is well-defined. -**Surjective**: Since $m$ and $n$ are relatively prime, by the Chinese Remainder Theorem, for any $(a, b) \in \mathbb{Z}_m^* \times \mathbb{Z}_n^*$, consider the congruence system: +**Surjective**: Since $m$ and $n$ are coprime, by the Chinese Remainder Theorem, for any $(a, b) \in \mathbb{Z}_m^* \times \mathbb{Z}_n^*$, consider the system of congruences: $x \equiv a \pmod{m}$ $x \equiv b \pmod{n}$ -It has a unique solution $x$. Therefore, for any element in $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, there exists an $x$ such that $f(x) = (a, b)$. Thus, $f$ is surjective, meaning that the mapping covers the entire set $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$. +there exists a unique solution $x$. Therefore, for any element in $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, there exists an $x$ such that $f(x) = (a, b)$. Therefore, $f$ is surjective, which means the mapping covers the entire set $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$. -**Injective**: Suppose we have two different elements $x_1$ and $x_2$. Then, we have $f(x_1) = f(x_2)$, which means +**Injective**: Suppose we have two different elements $x_1$ and $x_2$. We have $f(x_1) = f(x_2)$, which means $(x_1 \mod m, x_1 \mod n) = (x_2 \mod m, x_2 \mod n)$ -This implies $x_1 \equiv x_2 \pmod{m}$ and $x_1 \equiv x_2 \pmod{n}$. Therefore, we have $x_1 \equiv x_2 \pmod{mn}$. Thus, $x_1$ and $x_2$ are equal modulo $mn$, proving that $f$ is injective. +This implies that $x_1 \equiv x_2 \pmod{m}$ and $x_1 \equiv x_2 \pmod{n}$. Therefore, we have $x_1 \equiv x_2 \pmod{mn}$. Thus, $x_1$ and $x_2$ are equal modulo $mn$, proving that $f$ is injective. + +Since $f$ is both surjective and injective, it is bijective. Therefore, ${\mathbb{Z}_{mn}^*}$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$ have a bijective relationship, and their elements correspond one-to-one, so $\phi(mn) = \phi(m)\phi(n)$. -Since $f$ is both surjective and injective, it is a bijection. Therefore, ${\mathbb{Z}_{mn}^*}$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$ are in a bijective relationship, and they have the same number of elements, $\phi(mn) = \phi(m)\phi(n)$. +
-Based on these three properties, we can express the totient function of a large number as the product of the totient functions of its prime factorization: If $n$ has a prime factorization $p_1^{k_1}p_2^{k_2}...p_r^{k_r}$ (where $p_i$ are distinct prime factors and $k_i \geq 1$ is the exponent of $p_i$), then the value of the totient function at that point is: + +Based on these three properties, we can express the Euler's totient function of a large number as a product of the Euler's totient functions of its prime factors: if $n$ has a prime factorization $p_1^{k_1}p_2^{k_2}...p_r^{k_r}$ (where $p_i$ are distinct prime factors and $k_i \ge 1$ is the exponent of each prime factor), then the Euler's totient function at that point is: $$ -\phi(n) = p_1^{k_1-1}p_2^{k_2-1}...p_r^{k_r-1} (p_1 - 1)(p_2 -1)...(p_r-1) +\phi(n)= p_1^{k_1-1}p_2^{k_2-1}...p_r^{k_r-1} (p_1 - 1) (p_2 -1)...(p_r-1) $$ -It can also be equivalently written as: +Alternatively, we can write it as: $$ -\phi(n) = n (1 - 1/p_1)(1 -1/p_2)...(1-1/p_r) +\phi(n)= n (1 - 1/p_1) (1 -1/p_2)...(1-1/p_r) $$ -In general, since any positive integer greater than $1$ can be decomposed into the product of prime numbers, let's assume $N=\prod_{i=1}^lp_i^{\alpha_i}$, then $\varphi(N)=\prod_{i=1}^lp_i^{\alpha_i-1}(p_i-1)$. Specifically, if $N=p^\alpha$, then $\varphi(N)=p^{\alpha-1}(p-1)$. More specifically, if $N=p$, then $\varphi(N)=p-1$. +To summarize: since any positive integer greater than $1$ can be factored into the product of prime numbers, let's assume $N=\prod_{i=1}^lp_i^{\alpha_i}$, then $\phi(N)=\prod_{i=1}^lp_i^{\alpha_i-1}(p_i-1)$. In particular, if $N=p^\alpha$, then $\phi(N)=p^{\alpha-1}(p-1)$. Even more specifically, if $N=p$, then $\phi(N)=p-1$. -### 2.2 Code Implementation: +### 2.2 Implementation in Python: -We can implement the Euler's totient function in Python. The code includes two functions: `prime_factors()` for prime factorization of $n$, and `euler_phi()` for calculating $\phi(n)$ using the formula: +We can implement the Euler's totient function in Python. The code includes two functions, `prime_factors()`, which factors $n$ into prime factors, and `euler_phi`, which calculates $\phi(n)$ using the formula: ```python -# Prime factorization is currently a challenge for large integers +# Prime factorization can be challenging for large integers def prime_factors(n): factors = [] p = 2 @@ -133,11 +148,10 @@ def euler_phi(n): # Example n = 15 - -print(f"Euler's function phi({n}): {euler_phi(n)}") -# Euler's function phi(15): 8 +print(f"Euler's totient function phi({n}): {euler_phi(n)}") +# Euler's totient function phi(15): 8 ``` ## Summary -In this lesson, we introduced the concept of unit set and Euler's function, which can be used to calculate the number of positive integers less than or equal to $n$ that are coprime to $n$. In the next lesson, we will discuss Euler's theorem, which utilizes Euler's function. \ No newline at end of file +In this tutorial, we introduced the concepts of unit set and Euler's totient function, which can be used to calculate the number of positive integers less than or equal to $n$ that are coprime with $n$. In the next tutorial, we will explore Euler's theorem, which utilizes the Euler's totient function. diff --git a/Languages/en/09_Unit/test.md b/Languages/en/09_Unit/test.md deleted file mode 100644 index 51c8b55..0000000 --- a/Languages/en/09_Unit/test.md +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: 09. Euler's Totient Function -tags: - - zk - - basic - - euler's totient function ---- - -# WTF zk Tutorial 09: Euler's Totient Function - -Given an integer $n$, how many positive integers less than or equal to $n$ are coprime to $n$? In this tutorial, we will explore this problem and introduce the concepts of unit sets and Euler's totient function. - -## 1. Unit Sets - -If $x \in \mathbb{Z}_n$ is invertible (i.e. has a multiplicative inverse), we call $x$ a unit of $\mathbb{Z}_n$. The set of all units of $\mathbb{Z}_n$ is called the unit set, denoted as $\mathbb{Z}_n^*$. - -As we have learned before, $x \in \mathbb{Z}_n$ is invertible if and only if $x$ is coprime to $n$. Therefore, the elements of $\mathbb{Z}_n^*$ are the positive integers in the range $[1, ..., n-1]$ that are coprime to $n$. In the theory of congruences, this set is also known as the coprime residue class modulo $n$. - -Here are a few examples: - -$\mathbb{Z}^*_2 = \{1\}$ - -$\mathbb{Z}^*_3 = \{1,2\}$ - -$\mathbb{Z}^*_5 = \{1, 2, 3, 4\}$ - -$\mathbb{Z}^*_8 = \{1, 3, 5, 7\}$ - -$\mathbb{Z}^*_9 = \{1, 2, 4, 5, 7, 8\}$ - -$\mathbb{Z}^*_{15} = \{1, 2, 4, 7, 8, 11, 13, 14\}$ - -## 2. Euler's Totient Function - -The Euler's totient function, denoted as $\phi(n)$, represents the number of elements in the unit set $\mathbb{Z}_n^*$. In other words, it counts the number of positive integers in the range $[1, ..., n-1]$ that are coprime to $n$. Additionally, we define $\phi(1) = 1$. - -Here are a few examples: $\phi(2) = 1$, $\phi(3) = 2$, $\phi(5) = 4$, $\phi(8) = 4$, $\phi(9) = 6$, $\phi(15) = 8$. - -### 2.1 Properties of Euler's Totient Function - -Euler's totient function has some remarkable properties that make it easy to calculate the number of elements in $\mathbb{Z}_n^*$. The first two properties apply to prime numbers $p$, while the third property is the multiplicative property of Euler's totient function, which allows us to calculate it for composite numbers by expressing them as products of their prime factors' Euler's totient functions. - -#### 1. For a prime number $p$, we have $\phi(p) = p-1$ - -Here are a few examples: $\phi(2) = 1$, $\phi(3) = 2$, $\phi(13) = 12$. - -
Click to expand the proof👀 - -Since $p$ is a prime number, every $x \in \mathbb{Z}_p$ is coprime to $p$, which means the set $[1, ..., p-1]$ has a total of $p-1$ elements. - -
- -#### 2. For a prime number $p$ and a positive integer $k$, we have $\phi(p^k) = p^k - p^{k-1}$. - -Here are a few examples: - -$$ -\phi(8) = \phi(2^3) = 2^3 - 2^2 = 4 -$$ - -$$ -\phi(9) = \phi(3^2) = 3^2 - 3^1 = 6 -$$ - -
Click to expand the proof👀 - -In the range $[1, ..., p^k]$, there are a total of $p^k$ elements. Since $p$ is a prime number, only the multiples of $p$ in this range, i.e. $[p, 2p, 3p, ..., p^k - p, p^k]$, are divisible by $p$ and not coprime to $p$. Therefore, out of every $p$ numbers, only $1$ number is not coprime to $p$. There are a total of $p^k / p = p^{k-1}$ such groups of $p$ numbers. Thus, the number of numbers coprime to $p$ is $p^k - p^{k-1}$, and $\phi(p^k) = p^k - p^{k-1}$. - -
- -#### 3. If $m$ and $n$ are coprime, i.e. $\gcd(m,n)=1$, we have $\phi(mn) = \phi(m)\phi(n)$. - -Here are a few examples: - -$$ -\phi(15) = \phi(3) \times \phi(5) = 2 \times 4 = 8 -$$ - -$$ -\phi(18) = \phi(2) \times \phi(3^2) = 1 \times (3^2 - 3^1) = 6 -$$ - -
Click to expand the proof👀 - -To prove that there is a bijective relationship between $\mathbb{Z}_{mn}^*$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, we need to establish a mapping relationship $f: \mathbb{Z}_{mn}^* \to{\mathbb{Z}_m^* \times \mathbb{Z}_n^*}$, which uniquely determines the residues $a$ and $b$ modulo $m$ and $n$ respectively. - -**Surjection**: Since $m$ and $n$ are coprime, the Chinese Remainder Theorem tells us that for any $(a, b) \in \mathbb{Z}_m^* \times \mathbb{Z}_n^*$, considering the system of congruences: - -$x \equiv a \pmod{m}$ - -$x \equiv b \pmod{n}$ - -there exists a unique solution $x$. Therefore, for any element in $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, there exists an $x$ such that $f(x) = (a, b)$. Thus, $f$ is surjective, covering the entire set $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$. - -**Injection**: Assuming there are two different elements $x_1$ and $x_2$, we have $f(x_1) = f(x_2)$, which means - -$(x_1 \mod m, x_1 \mod n) = (x_2 \mod m, x_2 \mod n)$ - -This implies that $x_1 \equiv x_2 \pmod{m}$ and $x_1 \equiv x_2 \pmod{n}$. Therefore, we have $x_1 \equiv x_2 \pmod{mn}$. Thus, $x_1$ and $x_2$ are congruent modulo $mn$, proving that $f$ is injective. - -Since $f$ is both surjective and injective, $f$ is bijective. Therefore, there exists a bijective relationship between $\mathbb{Z}_{mn}^*$ and $\mathbb{Z}_m^* \times \mathbb{Z}_n^*$, and their number of elements are equal, i.e. $\phi(mn) = \phi(m)\phi(n)$. - -
- - -Based on these three properties, we can transform the Euler's totient function of a large number into the product of the Euler's totient functions of its prime factors. If $n$ has a prime factorization of $p_1^{k_1}p_2^{k_2}...p_r^{k_r}$ (where the $p_{i}$ are distinct prime factors and $k_i \ge 1$ is the exponent of $p_i$), then the value of the Euler's totient function at that point is: - -$$ -\phi(n) = p_1^{k_1-1}p_2^{k_2-1}...p_r^{k_r-1} (p_1 - 1) (p_2 -1)...(p_r-1) -$$ - -Alternatively, it can be written as: - -$$ -\phi(n) = n (1 - 1/p_1) (1 -1/p_2)...(1-1/p_r) -$$ - -In summary: since any positive integer greater than $1$ can be factored into the product of prime numbers, let's assume $N=\prod_{i=1}^lp_i^{\alpha_i}$. Then, $\varphi(N)=\prod_{i=1}^lp_i^{\alpha_i-1}(p_i-1)$. In particular, if $N=p^\alpha$, then $\varphi(N)=p^{\alpha-1}(p-1)$. More specifically, if $N=p$, then $\varphi(N)=p-1$. - -### 2.2 Code Implementation: - -We can implement the Euler's totient function in Python. The code includes two functions: `prime_factors()`, which factorizes $n$ into prime numbers, and `euler_phi()`, which calculates $\phi(n)$ using the formula: - -```python -# Factoring large integers is currently a difficult task -def prime_factors(n): - factors = [] - p = 2 - while p * p <= n: - while n % p == 0: - factors.append(p) - n //= p - p += 1 - if n > 1: - factors.append(n) - return factors - -def euler_phi(n): - result = n - factors = prime_factors(n) - - for p in set(factors): - result -= result // p - - return result - -# Example -n = 15 -print(f"Euler's totient function phi({n}): {euler_phi(n)}") -# Euler's totient function phi(15): 8 -``` - -## Summary - -In this tutorial, we introduced the concepts of unit sets and Euler's totient function, which can be used to calculate the number of positive integers less than or equal to $n$ that are coprime to $n$. In the next tutorial, we will introduce Euler's theorem, which utilizes the Euler's totient function. -``` \ No newline at end of file diff --git a/Languages/en/16_Abel/readme.md b/Languages/en/16_Abel/readme.md index 6824fb8..9310ac8 100644 --- a/Languages/en/16_Abel/readme.md +++ b/Languages/en/16_Abel/readme.md @@ -1,5 +1,5 @@ --- -title: 16. Abel Group +title: 16. Abelian Group tags: - zk - abstract algebra @@ -7,96 +7,88 @@ tags: - abelian group --- -# WTF zk Tutorial Lesson 16: Abel Group +# WTF zk Tutorial 16: Abelian Group -In this lecture, we will introduce a type of group commonly used in cryptography: the Abel Group, which is characterized by the commutative property. +In this tutorial, we will introduce a type of group commonly used in cryptography: the Abelian group, which satisfies the commutative law. -## 1. Abel Group +## 1. Abelian Group -In addition to satisfying the four basic properties of a group, an Abel Group also needs to satisfy the commutative property. If a group $(G, 🐔)$ satisfies the following five properties, then we call $G$ an Abel Group: +An Abelian group is a group that satisfies the commutative law, in addition to the four basic properties of a group. If a group $(G, \cdot)$ satisfies the following 5 properties, it is called an Abelian group: -1. **Closure:** For any $a, b \in G$, $a 🐔 b \in G$. -2. **Associativity:** For any $a, b, c \in G$, $(a 🐔 b) 🐔 c = a 🐔 (b 🐔 c)$. -3. **Identity Element:** There exists an element $e \in G$ such that for any $a \in G$, $a 🐔 e = e 🐔 a = a$. -4. **Inverse Element:** For any $a \in G$, there exists an element $b \in G$ such that $a 🐔 b = b 🐔 a = e$, where $e$ is the identity element. -5. **Commutative Property:** For any $a, b \in G$, $a 🐔 b = b 🐔 a$. +1. **Closure**: For any $a, b \in G$, we have $a \cdot b \in G$. +2. **Associativity**: For any $a, b, c \in G$, we have $(a \cdot b) \cdot c = a \cdot (b \cdot c)$. +3. **Identity Element**: There exists an element $e \in G$ such that for any $a \in G$, we have $a \cdot e = e \cdot a = a$. +4. **Inverse Element**: For any $a \in G$, there exists an element $b \in G$ such that $a \cdot b = b \cdot a = e$, where $e$ is the identity element. +5. **Commutative Law**: For any $a, b \in G$, we have $a \cdot b = b \cdot a$. -Therefore, Abel Group refers to a group that satisfies the commutative property. Since addition and multiplication operations both satisfy the commutative property, many common groups belong to the Abel Group, including: +Therefore, an Abelian group is a group that satisfies the commutative law. Many common groups, such as the group of integer addition $(\mathbb{Z}, +)$ and the group of non-zero integer multiplication $(\mathbb{Z}, \times)$, belong to the Abelian group because both addition and multiplication operations satisfy the commutative law. Similarly, the group of integer addition modulo $n$ $(\mathbb{Z}_n, +)$ and the group of integer multiplication modulo $n$ $(\mathbb{Z}_n^*, \times)$ are also Abelian groups. -1. Integers under addition $(\mathbb{Z}, +)$, because $a + b = b + a$. +## 2. Properties of Abelian Groups -2. Non-zero integers under multiplication $(\mathbb{Z}, \times)$, because $ab = ba$. +In this section, we will discuss some properties of Abelian groups and review the concepts of subgroup, normal subgroup, quotient group, and homomorphism. -3. Integers modulo n under addition $(\mathbb{Z}_n, +)$, because $a + b \equiv b + a \pmod{n}$. +**1. A group $(G, \cdot)$ is an Abelian group if and only if for any $a,b \in G$, we have $(a\cdot b)^2 = a^2 \cdot b^2$** -4. Non-zero integers modulo n under multiplication $(\mathbb{Z}_n^*, \times)$, because $ab \equiv ba \pmod{n}$. +
Click to expand the proof👀 -## 2. Properties of Abel Group +We want to prove that the group $(G, \cdot)$ satisfies the commutative law. For any $a,b \in G$, $(a\cdot b)^2 = a\cdot b\cdot a\cdot b$ -In this section, we will discuss some properties of the Abel Group and review the concepts of subgroup, normal subgroup, quotient group, and homomorphism. - -**1. A group $(G, 🐔)$ is an Abel Group if and only if for any $a, b \in G$, $(a🐔b)^2 = a^2🐔b^2$.** - -
Click to expand proof👀 - -We want to prove that the group $(G, 🐔)$ satisfies the commutative property. For any $a, b \in G$, $(a🐔b)^2 = a🐔b🐔a🐔b$ - -And $(a🐔b)^2 = a^2🐔b^2$ can be written as $a🐔b🐔a🐔b = a🐔a🐔b🐔b$, by canceling the leftmost $a$ and the rightmost $b$, we have $b🐔a = a🐔b$, thus the commutative property holds and the group $(G, 🐔)$ is an Abel Group. QED. +And $(a\cdot b)^2 = a^2\cdot b^2$ can be written as $a\cdot b\cdot a\cdot b = a\cdot a\cdot b\cdot b$, by canceling the leftmost $a$ and the rightmost $b$, we have $b\cdot a = a\cdot b$, thus the commutative law holds and the group $(G, \cdot)$ is an Abelian group. Proof complete.
-Taking $(\mathbb{Z}, \times)$ as an example, we have $(2 \times 3)^2 = 2^2 \times 3^2 = 36$. +For example, in the group $(\mathbb{Z}, \times)$, we have $(2 \times 3)^2 = 2^2 \times 3^2 = 36$. -**2. A group $(G, 🐔)$ is an Abel Group if for any $a, b \in G$, $(a🐔b)^n = a^n🐔b^n$.** +**2. A group $(G, \cdot)$ is an Abelian group if for any $a,b \in G$, we have $(a\cdot b)^n = a^n \cdot b^n$** -
Click to expand proof👀 +
Click to expand the proof👀 -$(G, 🐔)$ is an Abel Group, $(a🐔b)^n = a🐔b🐔...🐔a🐔b = a🐔a🐔...🐔b🐔b = a^n🐔b^n$. QED. +$(G, \cdot)$ is an Abelian group, $(a\cdot b)^n = a\cdot b\cdot...\cdot a\cdot b = a\cdot a\cdot...\cdot b\cdot b = a^n\cdot b^n$. Proof complete.
-Taking $(\mathbb{Z}, \times)$ as an example, we have $(2 \times 3)^n = 2^n \times 3^n$. +For example, in the group $(\mathbb{Z}, \times)$, we have $(2 \times 3)^n = 2^n \times 3^n$. -**3. Subgroups of an Abel Group are also Abel Groups.** +**3. Subgroups of an Abelian group are also Abelian groups.** -
Click to expand proof👀 +
Click to expand the proof👀 -Let $(G, 🐔)$ be an Abel Group, and let $H$ be a subgroup of $G$. For any $a, b \in H$, we have $a, b \in G$, therefore $a 🐔 b = b 🐔 a$. Thus, the subgroup $H$ is also an Abel Group. QED. +Let $(G, \cdot)$ be an Abelian group, and let $H$ be a subgroup of $G$. For any $a, b \in H$, we have $a, b \in G$, thus $a \cdot b = b \cdot a$. Therefore, the subgroup $H$ is also an Abelian group. Proof complete.
-Taking $(\mathbb{Z}, +)$ as an example, the even additive group is a subgroup of it, and it is also an Abel Group, satisfying the commutative property. +For example, in the group $(\mathbb{Z}, +)$, the group of even numbers is a subgroup of it, and it is also an Abelian group that satisfies the commutative law. -**4. For an Abel Group $(G, 🐔)$, for any integer $n$, the group $G$ raised to the power of $n$ forms a subgroup of $G$, denoted as $G^n = \set{a^n \mid a \in G}$.** +**4. For an Abelian group $(G, \cdot)$, for any integer $n$, the group $G^n$ consisting of the $n$th powers of each element in $G$ is a subgroup of $G$, $G^n = \{a^n \mid a \in G\}$.** -
Click to expand proof👀 +
Click to expand the proof👀 -Let $(G, 🐔)$ be an Abel Group, and let $a, b \in G$, we have $a^n, b^n \in G^n$. We have $a^n (b^n)^{-1} = a^n (b^{-1})^{n} = (ab^{-1})^n$. Based on closure, $ab^{-1} \in G$, therefore $(ab^{-1})^n \in G$, thus the group $G^n$ is a subgroup of $G$. QED. +Let $(G, \cdot)$ be an Abelian group, for any $a, b \in G$, we have $a^n, b^n \in G^n$. We have $a^n (b^n)^{-1} = a^n (b^{-1})^{n} = (ab^{-1})^n$. According to the closure property, $ab^{-1} \in G$, thus $(ab^{-1})^n \in G$. Therefore, the group $G^n$ is a subgroup of $G$. Proof complete.
-Taking $(\mathbb{Z}, \times)$ as an example, the group composed of all squares of integers, $\set{1, 4, 9, ...}$, is a subgroup of it. Taking $(\mathbb{Z}_5^*, \times)$ as an example, the set of squares of all elements $(\mathbb{Z}_5^*)^2 = \set{1^2, 2^2, 3^2, 4^2} = \set{1,4,4,1} = \set{1,4}$ is a subgroup of it. This property is helpful for us to understand quadratic residues later on. +For example, in the group $(\mathbb{Z}, \times)$, the group consisting of the squares of all integers $\{1, 4, 9, ...\}$ is a subgroup of it. Similarly, in the group $(\mathbb{Z}_5^*, \times)$, the set of squares of all elements $(\mathbb{Z}_5^*)^2 = \{1^2, 2^2, 3^2, 4^2\} = \{1,4,4,1\} = \{1,4\}$ is a subgroup of it. This property is helpful for us to understand quadratic residues later. -**5. Subgroups of an Abel Group are all normal subgroups.** +**5. Subgroups of an Abelian group are normal subgroups.** -
Click to expand proof👀 +
Click to expand the proof👀 -Let $(G, 🐔)$ be an Abel Group, and let $H$ be any subgroup of $G$. For any $g \in G$ and $h \in H$, we have $hg= gh$. Therefore, $H$ is a normal subgroup. QED. +Let $(G, \cdot)$ be an Abelian group, and let $H$ be any subgroup of $G$. For any $g \in G$ and $h \in H$, we have $hg= gh$, thus $H$ is a normal subgroup. Proof complete.
-The commutative property of the Abel Group can be passed down to subgroups, where left and right cosets are equal, so all subgroups are normal subgroups and quotient groups can be constructed. +The commutative law of an Abelian group can be passed on to subgroups, and the left and right cosets are equal, so all subgroups are normal subgroups and quotient groups can be constructed. -**6. Quotient groups of an Abel Group are also Abel Groups.** +**6. Quotient groups of an Abelian group are also Abelian groups.** -
Click to expand proof👀 +
Click to expand the proof👀 -Let $(G, 🐔)$ be an Abel Group, and let $H$ be any subgroup of $G$. Since $H$ is a normal subgroup, we can construct the quotient group $G/H$. For any $a, b \in G$ and $h \in H$, according to the commutative property, we have $(ah) (bh) = ahbh = bhah = (bh) (ah)$. Therefore, $(aH)(bH) = (bH)(aH)$. Thus, quotient groups of an Abel Group are also Abel Groups. QED. +Let $(G, \cdot)$ be an Abelian group, and let $H$ be any subgroup of $G$ that is also a normal subgroup. We can construct the quotient group $G/H$. For any $a, b \in G$ and $h \in H$, according to the commutative law, we have $(ah) (bh) = ahbh = bhah = (bh) (ah)$, thus $(aH)(bH) = (bH)(aH)$. Therefore, quotient groups of an Abelian group are also Abelian groups. Proof complete.
-The commutative property of the Abel Group can be passed down to quotient groups. +The commutative law of an Abelian group can be passed on to quotient groups. ## 3. Summary -In this lecture, we introduced the Abel Group, which has the commutative property, and its properties. Abel Groups are commonly used in cryptography and zero-knowledge proofs, and we will encounter them frequently in the future. +In this tutorial, we introduced the Abelian group, which satisfies the commutative law, and its properties. Many commonly used groups in cryptography and zero-knowledge proofs are Abelian groups, and we will frequently encounter them in the future. \ No newline at end of file diff --git a/Languages/en/17_Cyclic/readme.md b/Languages/en/17_Cyclic/readme.md index 81b4a38..1c43b28 100644 --- a/Languages/en/17_Cyclic/readme.md +++ b/Languages/en/17_Cyclic/readme.md @@ -1,141 +1 @@ -For any element $g \in G$, $g^n = e$, where $n$ is the order of $g$. Since $G$ is a cyclic group generated by $g$, all the elements in $G$ can be expressed as powers of $g$, i.e., $G = \{g^0, g^1, g^2, ..., g^{n-1}\}$. Therefore, $|G| = n$. - -**Necessity** - -If $|G| = n$, we can prove that the order of the generator $g$ is also $n$. Since $g^n = e$, the order of $g$ must be at most $n$. If the order of $g$ is less than $n$, then there exists an element $g^k$ such that $k < n$ and $g^k = e$. However, this contradicts the fact that $G$ is generated by $g$ and all the elements in $G$ can be expressed as powers of $g$. Therefore, the order of $g$ can only be $n$. -**Group Homomorphism:** For any $a, b \in \mathbb{Z}$, it holds that $f(a + b) = g^{a+b} = g^ag^b = f(a)f(b)$. Therefore, $f$ is a group homomorphism. - -**Surjective Homomorphism:** The image of the homomorphism $\{f(a) | a \in Z_n\} = \{g^a | a \in Z_n\} = \left \langle \, g \, \right \rangle$. So, the image of the homomorphism is equal to the group $G$, and $f$ is a surjective homomorphism. - -**Injective Homomorphism:** The order of the generator $g$ of group $G$ is $n$, so we have $g^{kn} = e_G$, where $k$ is an integer. Therefore, the kernel of the homomorphism $\text{ker}(f)= \{kn \mod n| k \in Z\}=\{0\}$, which is the identity element of $Z_n$. According to the necessary and sufficient conditions for injective homomorphism, $f$ is an injective homomorphism. - -Since the group homomorphism $f$ is both surjective and injective, any finite cyclic group $G$ of order $n$ is isomorphic to the additive group $Z_n$ of integers modulo $n$. Proof is complete. - -
- -Therefore, for any cyclic group $G$, it is isomorphic either to the additive group $Z_n$ of integers modulo $n$ or to the group of integers $Z$. Isomorphism represents that two groups have the same structure, which means that the properties of $Z_n$ or $Z$ that we introduced earlier can be transferred to any cyclic group. - -## 4. Review of Euler's theorem - -In the foundation of number theory, we introduced Euler's theorem, connecting the properties of Euler's function and the cyclic property of the multiplicative group modulo n. - -**Euler's theorem:** If the integer $a$ and the positive integer $n$ are coprime (i.e., $\gcd(a,n)=1$), then $a^{\phi(n)} \equiv 1 \pmod{n}$. - -Now let's prove it using the properties of cyclic groups. - -First, consider the multiplicative group modulo n, denoted as $Z^* _n$, whose order is $\phi(n)$. Suppose the integer $a$ is coprime with $n$, that is, $\gcd(a,n)= 1$, we have $a \equiv 1 \mod n$, so $a \in Z^* _n$. We can construct a cyclic group $A$ with $a$ as the generator, then $A$ is a subgroup of $Z^* _n$. Let the order of group $A$ be $k$, then $a^k \equiv 1 \pmod{n}$. According to Lagrange's theorem, the order of subgroup $A$ divides the order of $Z^* _n$, that is, $k | \phi(n)$. In other words, there exists an integer $q$ such that $\phi(n) = kq$. We have: - -$$ -a^{\phi(n)} = a^{kq} = (a^k)^q = 1^q = 1 \pmod{n} -$$ - -That is, $a^{\phi(n)} \equiv 1 \pmod{n}$, and the proof is complete. - -## 5. Summary - -In this lesson, we introduced cyclic groups, which have a simple structure and can be generated by a single element (generator). All cyclic groups are Abel groups, and subgroups and quotient groups of cyclic groups are also cyclic groups. The order of cyclic groups and the order of elements have a special relationship. There are many properties, so it is recommended to review them several times to become familiar with them. Any infinite cyclic group is isomorphic to $Z$, and any finite cyclic group is isomorphic to $Z_n$. -According to the definition, the cyclic group G is generated by g. If the order of G is n, the group G = = {e, g, ..., g^(n-1)} contains n distinct elements, so the order of the element g is n. - -**Necessity** - -According to the definition, the cyclic group G is generated by g. If the order of g is n, the group G = = {e, g, ..., g^(n-1)} contains n distinct elements, so the order of the group G is n. - -
- -In the integer modulo 5 multiplication group (Z*_5, ×), the order of the generator 2 or 3 is 4, and the order of the group is also 4. - -**3. If G is an n-order cyclic group and d is a positive integer that divides n, then G has a unique d-order subgroup.** - -
Click to expand proof👀 - -First, we prove the existence of a d-order subgroup. Since the order of the cyclic group G is n and d is a positive integer that divides n, we can use g^(n/d) as the generator to generate the cyclic group = {e, g^(n/d), g^(2n/d),..., g^(n-n/d)}, which has an order of d. Therefore, a d-order subgroup exists. - -Next, we prove the uniqueness of the d-order subgroup. Using proof by contradiction, assume that there exists another d-order cyclic subgroup in the group G, where k is an element of Z. According to the definition of order, (g^(k))^d = g^(kd) = e. According to the property of order, n divides kd, which means n/d divides k. Therefore, according to the property of Abel groups, is a subgroup of . Since they both have an order of d, they are the same cyclic group . Therefore, the d-order subgroup is unique. - -
- -The order of the integer modulo 6 addition group (Z_6) is 6, so it has 4 subgroups with orders of 1, 2, 3, 6, which are {0}, {0,3}, {0,2,4}, and {0,1,2,3,4,5}, respectively. - -The order of the integer modulo 5 multiplication group (Z^*_5) is 4, so it has 3 subgroups with orders of 1, 2, 4, which are {1}, {1, 4}, and {1,2,3,4}, respectively. - -**4. The order of the element g^k in an n-order cyclic group is n/gcd(n,k).** - -
Click to expand proof👀 - -Assume that the order of the element g^k is m, according to the definition of order, m is the smallest positive integer that satisfies (g^k)^m = e. According to the property of order, n divides km, which can be simplified to m congruent to 0 modulo (n/gcd(n,k)). The smallest positive integer that satisfies this condition is m = n/gcd(n,k). Therefore, the order of the element g^k is n/gcd(n,k). Proof complete. - -
- -The order of the integer modulo 6 addition group (Z_6) is 6. The element 2 = 1 + 1 = 1^2 has an order of 3, the element 3 = 1 + 1 +1 = 1^3 has an order of 2, the element 4 = 1^4 has an order of 3, and the element 5 = 1^5 has an order of 6. - -The order of the integer modulo 5 multiplication group (Z^*_5) is 4. The element 2 = 2^1 has an order of 4, the element 3 = 2^3 has an order of 4, the element 4 = 2^2 has an order of 2, and the element 1 = 2^4 has an order of 1. - -**5. An n-order cyclic group has phi(n) generators.** - -
Click to expand proof👀 - -According to the previous property, only when gcd(n, k) = 1, the order of the element g^k is n, which means it is a generator. According to Euler's totient function, there are phi(n) integers less than n and coprime to n. In other words, there are phi(n) values of k that make g^k a generator. Therefore, an n-order cyclic group has phi(n) generators. Proof complete. - -
- -The order of the integer modulo 6 addition group (Z_6) is 6, so it has phi(6) = phi(2) * phi(3) = 1 * 2 = 2 generators, which are 1 and 5. - -The order of the integer modulo 5 multiplication group (Z^*_5) is 4, so it has phi(4) = phi(2^2) = 2^2 - 2 = 2 generators, which are 2 and 3. - -**6. The order of an element in an n-order finite group G is a factor of n.** - -
Click to expand proof👀 - -Let a be an element in group G. According to Lagrange's theorem, the order of a subgroup divides the order of an element. Therefore, || divides |G|. Also, since |G| = n and |a| = ||, the order of an element is a factor of n. Proof complete. - -
- -The order of the integer modulo 6 addition group (Z_6) is 6. The element 2 has an order of 3, which is a factor of 6. - -The order of the integer modulo 5 multiplication group (Z^*_5) is 4. The element 4 has an order of 2, which is a factor of 4. - -**7. If p is a prime number, then the integer modulo p multiplication group Z^*_p has phi(p-1) generators.** - -
Click to expand proof👀 - -First, we need to determine the order of Z^*_p, which contains phi(p) elements. Since p is a prime number, phi(p) = p-1, so the order of Z^*_p is p-1. According to property 5, Z^*_p has phi(p-1) generators. Proof complete. - -
- -5 is a prime number, so Z^*_5 has phi(4) = phi(2^2) = 2^2 - 2^1 = 2 generators, which are 2 and 3. - -## 3. Isomorphism of Cyclic Groups - -In this section, we introduce the isomorphism of cyclic groups. Cyclic groups are the simplest type of groups and can be classified into two categories, one is isomorphic to Z and the other is isomorphic to Z_n. Therefore, when studying the properties of cyclic groups, we can study the simpler Z or Z_n. - -**1. Any infinite cyclic group is isomorphic to the integer addition group Z.** - -
Click to expand proof👀 - -Let G be an infinite cyclic group generated by g. Let the mapping f: Z -> G be defined as f(x) = g^x. - -**Group homomorphism:** For any a, b in Z, we have f(a + b) = g^(a+b) = g^a * g^b = f(a) * f(b). Therefore, f is a group homomorphism. - -**Surjective homomorphism:** The image of the homomorphism, {f(a) | a in Z} = {g^a | a in Z} = , is equal to the group G. Therefore, the homomorphism f is surjective. - -**Injective homomorphism:** Since the infinite cyclic group has an infinite order, there is only g^0 = e_G. Therefore, the kernel of the homomorphism, ker(f) = 0. According to the condition of injective homomorphism, f is an injective homomorphism. - -The group homomorphism f is both surjective and injective, therefore the infinite cyclic group G is isomorphic to the integer addition group Z. Proof complete. - -
- -**2. Any n-order finite cyclic group is isomorphic to the integer modulo n addition group Z_n.** - -
Click to expand proof👀 - -Let G be an n-order finite cyclic group G = = {g^a | a in Z_n}. Let the mapping f: Z_n -> G be defined as f(x) = g^x. - -**Group homomorphism:** For any a, b in Z_n, we have f(a + b) = g^(a+b) = g^a * g^b = f(a) * f(b). Therefore, f is a group homomorphism. - -**Surjective homomorphism:** The image of the homomorphism, {f(a) | a in Z_n} = {g^a | a in Z_n} = , is equal to the group G. Therefore, the homomorphism f is surjective. - -**Injective homomorphism:** The n-order finite cyclic group has n elements. Therefore, there are n distinct powers of g. Therefore, the homomorphism is injective. - -The group homomorphism f is both surjective and injective, therefore the n-order finite cyclic group G is isomorphic to the integer modulo n addition group Z_n. Proof complete. - -
\ No newline at end of file +Error reading file: 'NoneType' object has no attribute 'get' \ No newline at end of file diff --git a/Languages/en/18_DirectProduct/readme.md b/Languages/en/18_DirectProduct/readme.md index 3334cf1..b75e579 100644 --- a/Languages/en/18_DirectProduct/readme.md +++ b/Languages/en/18_DirectProduct/readme.md @@ -7,85 +7,85 @@ tags: - direct product --- -# WTF zk Tutorial Lesson 18: Direct Product of Groups +# Tutorial 18: Direct Product of Groups -In this tutorial, we introduce the direct product of groups, which can generate complex groups from simple groups. Furthermore, we will revisit the Chinese Remainder Theorem and prove the Chinese Remainder Mapping using it. +In this tutorial, we will explore the direct product of groups, a method of combining simple groups to generate more complex groups. We will also revisit the Chinese Remainder Theorem and prove its connection to the direct product of groups. ## 1. Direct Product of Groups -The direct product of groups is a combination of the operations of two or more groups, which can be used to generate a new group. +The direct product of groups combines the operations of two or more groups to form a new group. -**Definition:** Given two groups $(G, 🐔)$ and $(H, 🦆)$, their direct product $G \times H$ is a new group consisting of all possible ordered pairs $(g, h)$, where $g \in G$ and $h \in H$. The operation on $G \times H$ is denoted by $🐶$, and for any $g_1, g_2 \in G$ and $h_1, h_2 \in H$, +**Definition:** Given two groups $(G, \cdot)$ and $(H, \circ)$, their direct product $G \times H$ is a new group consisting of all possible ordered pairs $(g, h)$, where $g \in G$ and $h \in H$. The operation on $G \times H$ is denoted by $*$, and for any $g_1, g_2 \in G$ and $h_1, h_2 \in H$, $$ -(g_1, h_1) 🐶 (g_2, h_2) = (g_1 🐔 g_1, h_1 🦆 h_2) +(g_1, h_1) * (g_2, h_2) = (g_1 \cdot g_2, h_1 \circ h_2) $$ -$(G \times H, 🐶)$ satisfies the four fundamental properties of a group: +The group $(G \times H, *)$ satisfies the four fundamental properties of a group: -1. **Closure:** For any elements $(g_1, h_1)$ and $(g_2, h_2)$ belonging to $G \times H$, $(g_1, h_1) 🐶 (g_2, h_2) = (g_1 🐔 g_1, h_1 🦆 h_2)$ still belongs to $G \times H$. +1. **Closure:** For any elements $(g_1, h_1), (g_2, h_2)$ belonging to $G \times H$, $(g_1, h_1) * (g_2, h_2) = (g_1 \cdot g_2, h_1 \circ h_2)$ still belongs to $G \times H$. 2. **Associativity:** Inherited from groups $G$ and $H$. 3. **Identity Element:** The identity element of $G \times H$ is $(e_g, e_h)$. -4. **Inverse Element:** For every element $(g, h)$ in the group, there exists an inverse element $(g, h)^{-1} = (g^{-1}, h^{-1})$ such that $(g, h) 🐶 (g^{-1}, h^{-1}) = (e_g, e_h)$. +4. **Inverse Element:** For every element $(g, h)$ in the group, there exists an inverse element $(g, h)^{-1} = (g^{-1}, h^{-1})$, such that $(g, h) * (g^{-1}, h^{-1}) = (e_g, e_h)$. -For example, the direct product of two additive groups of integers, $\mathbb{Z}^2$, is the additive group formed by all integer vectors $(x,y)$. The operation is vector addition, given by $(x_1, y_1) + (x_2, y_2) = (x_1 + x_2, y_1 + y_2)$. +For example, the direct product $\mathbb{Z}^2$ of two additive groups of integers is a group formed by all integer vectors $(x, y)$. The operation is vector addition, given by $(x_1, y_1) + (x_2, y_2) = (x_1 + x_2, y_1 + y_2)$. -Another example is the direct product of $\mathbb{Z}_3$ and $\mathbb{Z}_5$, denoted $\mathbb{Z}_3 \times \mathbb{Z}_5$, which consists of all possible ordered pairs $(x, y)$, where $x \in \mathbb{Z}_3$ and $y \in \mathbb{Z}_5$. The order (number of elements) of this direct product group is $15$, which is equal to $3 \times 5$. +Another example is the direct product $\mathbb{Z}_3 \times \mathbb{Z}_5$ of $\mathbb{Z}_3$ and $\mathbb{Z}_5$, which is a set of all possible ordered pairs $(x, y)$, where $x \in \mathbb{Z}_3$ and $y \in \mathbb{Z}_5$. The order (number of elements) of this direct product group is $15$, exactly equal to $3 \times 5$. -## 2. Properties of the Direct Product +## 2. Properties of Direct Product **Property 1: The order of the direct product of two groups is equal to the product of their orders.** That is, $|G \times H| = |G||H|$.
Click to expand the proof👀 -According to the definition, the direct product $G \times H$ consists of all possible ordered pairs $(g, h)$, where $g \in G$ and $h \in H$. For each element in $G$, we can construct $|H|$ different elements in $G \times H$. There are $|G|$ distinct elements in group $G$. Therefore, $G \times H$ has $|G||H|$ elements, which means $|G \times H| = |G||H|$. Proof complete. +According to the definition, the direct product $G \times H$ consists of all possible ordered pairs $(g, h)$, where $g \in G$ and $h \in H$. For each element in $G$, we can construct $|H|$ different elements in $G \times H$. Group $G$ has $|G|$ distinct elements in total. Therefore, $G \times H$ has $|G||H|$ elements, i.e., $|G \times H| = |G||H|$. Proof completed.
$|\mathbb{Z}_3| = 3$, $|\mathbb{Z}_5| = 5$, so $|\mathbb{Z}_3 \times \mathbb{Z}_5| = 15$. -**Property 2: The order of an element $(g, h)$ in the direct product $G \times H$ is the least common multiple of $|g|$ and $|h|$.** That is, $|(g,h)| = \text{lcm}(|g|,|h|)$. In particular, if $|g|$ and $|h|$ are coprime, then the order of $(g, h)$ is $|g||h|$. +**Property 2: The order of an element $(g, h)$ in the direct product $G \times H$ is the least common multiple of $|g|$ and $|h|$.** That is, $|(g, h)| = \text{lcm}(|g|,|h|)$. In particular, if $|g|$ and $|h|$ are coprime, then the order of $(g, h)$ is $|g||h|$.
Click to expand the proof👀 -Let $k = |(g,h)|$ be the smallest positive integer such that $(g,h)^k = (e_g, e_h)$. Since $(g,h)^k = (g^k, h^k)$, we have $g^k = e_g$ and $h^k = e_h$. Thus, $k$ is a common multiple of $|g|$ and $|h|$, and since it is the smallest such multiple, $k = \text{lcm}(|g|,|h|)$. Proof complete. +Let $k = |(g, h)|$ be the smallest integer such that $(g, h)^k = (e_g, e_h)$. Since $(g, h)^k = (g^k, h^k)$, we have $g^k = e_g$ and $h^k = e_h$. Hence, $k$ is divisible by both $|g|$ and $|h|$. As $k$ is the smallest integer satisfying this condition, we have $k = \text{lcm}(|g|,|h|)$. Proof completed. -If $|g|$ and $|h|$ are coprime, then $\text{lcm}(|g|,|h|) = |g||h|$. Proof complete. +If $|g|$ and $|h|$ are coprime, then $\text{lcm}(|g|,|h|) = |g||h|$. Proof completed.
-In $\mathbb{Z}_3$, the order of element $1$ is $|1| = 3$; in $\mathbb{Z}_5$, the order of element $1$ is $|1| = 5$. Since $\gcd(3,5) = 1$, the order of element $1$ in $\mathbb{Z}_3 \times \mathbb{Z}_5$ is $|1| = 3 \times 5 = 15$. +In $\mathbb{Z}_3$, the order of element $1$ is $|1|= 3$; in $\mathbb{Z}_5$, the order of element $1$ is $|1|= 5$. Since $\gcd(3,5)=1$, the order of element $1$ in $\mathbb{Z}_3 \times \mathbb{Z}_5$ is $|1|= 3 \times 5 = 15$. -**Property 3: If the groups $G$ and $H$ are cyclic groups with orders $|G|$ and $|H|$ respectively, then the direct product $G \times H$ is a cyclic group if and only if $|G|$ and $|H|$ are coprime.** +**Property 3: If groups $G$ and $H$ are cyclic groups with orders $|G|$ and $|H|$, respectively, then the direct product $G \times H$ is a cyclic group if and only if $|G|$ and $|H|$ are coprime.**
Click to expand the proof👀 -**Necessity** +**Necessity:** -Let $G = \left \langle \, x \, \right \rangle$ and $H = \left \langle \, y \, \right \rangle$ be cyclic groups with orders $|G| = m$ and $|H| = n$, where $m$ and $n$ are coprime. Suppose $|(x, y)| = k$, then we have $(x,y)^k = (x^k, y^k) = (e_G, e_H)$. +Let $G = \left \langle \, x \, \right \rangle$ and $H = \left \langle \, y \, \right \rangle$ be cyclic groups with orders $|G| = m$ and $|H| = n$, respectively, such that $m$ and $n$ are coprime. Let $(x, y)^k = (e_G, e_H)$. Then we have $(x, y)^k = (x^k, y^k) = (e_G, e_H)$. -This implies $x^k = e_G$ and $y^k = e_H$. According to the property of the order of an element, we have $m|k$ and $n|k$. Since $\gcd(m,n) = 1$, we have $mn|k$. +Therefore, we have $x^k = e_G$ and $y^k = e_H$. According to the properties of the order of elements, we have $m|k$ and $n|k$. As $\gcd(m,n) = 1$, we have $mn|k$. -Also, $(x,y)^{mn} = (x^k, y^k) = (e_G, e_H)$, so $k|mn$. Therefore, the order of the element $|(x, y)| = k = mn$. Using Property 1, we have $|G \times H| = |G||H| = mn$. Thus, the element $(x,y)$ can generate the entire group, and $G \times H$ is a cyclic group. Proof complete. +Also, we have $(x, y)^{mn} = (x^k, y^k) = (e_G, e_H)$, which implies $k|mn$. Thus, the order $|(x, y)| = k = mn$. According to Property 1, we have $|G \times H| = |G||H| = mn$. Therefore, the element $(x, y)$ can generate the entire group $G \times H$, and thus $G \times H$ is a cyclic group. Proof completed. -**Sufficiency** +**Sufficiency:** -$|G| = m$ and $|H| = n$. Suppose $G \times H = \left \langle \, (x,y) \, \right \rangle$ is a cyclic group. According to Property 1, we have $|G \times H| = |G||H| = mn$. Since the order of a cyclic group is equal to the order of its generating element, we have $|(x,y)| = mn$. According to Property 2, we have $|(x,y)| = \text{lcm}(|x|, |y|)$. Thus, $\text{lcm}(|x|, |y|) = mn$. +$|G| = m$ and $|H| = n$. Assume that $G \times H = \left \langle \, (x, y) \, \right \rangle$ is a cyclic group. According to Property 1, we have $|G \times H| = |G||H| = mn$. Since the order of a cyclic group is equal to the order of its generator, we have $|(x, y)| = mn$. According to Property 2, we have $|(x, y)| = \text{lcm}(|x|, |y|)$. Therefore, $\text{lcm}(|x|, |y|) = mn$. -Using the relationship between the greatest common divisor and the least common multiple, we have $|x||y| = \gcd(|x||y|) \text{lcm}(|x|, |y|) = \gcd(|x||y|) mn$. And since $|x| \leq m$ and $|y| \leq n$, we have $|x||y| \leq mn$. Therefore, the equation holds if and only if $\gcd(|x||y|) = 1$, which means $m$ and $n$ are coprime. Proof complete. +According to the relationship between the greatest common divisor and the least common multiple, we have $|x||y| = \gcd(|x||y|) \text{lcm}(|x|, |y|) = \gcd(|x||y|) mn$. As $|x| \leq m$ and $|y| \leq n$, we have $|x||y| \leq mn$. Thus, the equation holds if and only if $\gcd(|x||y|) = 1$, which means $m$ and $n$ are coprime. Proof completed.
-The direct product $\mathbb{Z}_3 \times \mathbb{Z}_5$ is a cyclic group with the generator $(1,1)$ and order $15$. +The direct product $\mathbb{Z}_3 \times \mathbb{Z}_5$ is a cyclic group with the generator $(1, 1)$ and order $15$. ## 3. Revisiting the Chinese Remainder Theorem -In number theory, we learned about the Chinese Remainder Theorem, which can be used to solve systems of congruences. Let's briefly review it: +In number theory, we have learned about the Chinese Remainder Theorem, which can be used to solve systems of congruences. Let's briefly review it: -For a set of integers $m_1, m_2, ..., m_n$ that are pairwise coprime (for $i \ne j$, $\gcd(m_i,m_j) = 1$), the system of congruences consists of $n$ equations: +Given pairwise coprime integers $m_1, m_2,...,m_n$, where $\gcd(m_i,m_j) = 1$ for $i \ne j$, the system of congruences consists of $n$ equations: $$ x \equiv a_1 \pmod{m_1} @@ -103,17 +103,17 @@ $$ x \equiv a_n \pmod{m_n} $$ -The system has a unique solution modulo $M=m_1 \cdot m_2 \cdot ... \cdot m_n$: +The system of congruences has a unique solution modulo $M=m_1 \cdot m_2 \cdot... \cdot m_n$: $$ x \equiv \sum_{i=1}^{n}{a_ib_ib_i'} \pmod{M} $$ -where $b_i = M/m_i$ (the product of all modulus except $m_i$) and $b_i' = b_i^{-1} \pmod{m_i}$ (the inverse of $b_i$ modulo $m_i$). +where $b_i = M/m_i$ (i.e., the product of all moduli except $m_i$) and $b_i'=b_i^{-1} \pmod{m_i}$ (i.e., the inverse of $b_i$ modulo $m_i$). -Now we can better understand the Chinese Remainder Theorem through group isomorphism and direct product: +Now we can better understand the Chinese Remainder Theorem using the concepts of group isomorphism and direct product: -If $m_i$ are pairwise coprime, then the mapping $f: x \mod M \to (x \mod m_1, ..., x \mod m_n)$ defines an isomorphism between $Z_M$ and $Z_{m_1} \times ... \times Z_{m_n}$. This mapping is also known as the Chinese Remainder Mapping. +If $m_i$ are pairwise coprime, then the mapping $f: x \mod M \to (x \mod m_1,..., x \mod m_n)$ defines an isomorphism between the group $Z_M$ and the direct product $Z_{m_1} \times ... \times Z_{m_n}$. This mapping is also known as the Chinese Remainder Isomorphism.
Click to expand the proof👀 @@ -123,12 +123,12 @@ First, we prove that $f$ is a group homomorphism. For any $a, b \in \mathbb{Z}_M **Isomorphism** -The $m_i$'s are pairwise coprime, and $Z_{m_i}$ is a cyclic group with order $m_i$. We can easily generalize property 3 of direct product to the case of $n$ groups, and get the result that $Z_{m_1} \times ... \times Z_{m_n}$ is a cyclic group with order $M = m_1 \cdot m_2 \cdot... \cdot m_n$. Using the isomorphism property of cyclic groups, any finite cyclic group of order $M$ is isomorphic to the additive group $Z_M$ of integers modulo $M$. Therefore, $Z_M$ is isomorphic to $Z_{m_1} \times ... \times Z_{m_n}$. Proof completed. - -Due to the isomorphism between $Z_M$ and $Z_{m_1} \times ... \times Z_{m_n}$, their elements correspond one-to-one. Therefore, the system of congruences has a unique solution modulo M. +Since $m_i$ are pairwise coprime and $Z_{m_i}$ are cyclic groups with orders $m_i$, we can easily extend Property 3 about direct products to the case of $n$ groups, which implies that $Z_{m_1} \times ... \times Z_{m_n}$ is a cyclic group with order $M = m_1 \cdot m_2 \cdot... \cdot m_n$. Using the isomorphism property of cyclic groups, we know that any finite cyclic group of order $M$ is isomorphic to the additive group $Z_M$. Therefore, $Z_M$ is isomorphic to $Z_{m_1} \times ... \times Z_{m_n}$. Proof completed.
+Since $Z_M$ and $Z_{m_1} \times ... \times Z_{m_n}$ are isomorphic, their elements are in one-to-one correspondence, which means that the system of congruences has a unique solution modulo $M$. + ## 4. Summary -In this lesson, we introduced the direct product of groups, which is a way to generate a complex group using several simple groups. By using the properties of group direct product, we revisited the Chinese Remainder Theorem and understood why a system of congruences with coprime moduli has a unique solution from the perspective of group theory. +In this tutorial, we introduced the direct product of groups, a method of combining simple groups to generate more complex groups. By exploring the properties of the direct product, we gained a better understanding of the Chinese Remainder Theorem and its connection to group theory. \ No newline at end of file diff --git a/Languages/en/19_DLP/readme.md b/Languages/en/19_DLP/readme.md index 190db8e..1397e5b 100644 --- a/Languages/en/19_DLP/readme.md +++ b/Languages/en/19_DLP/readme.md @@ -1,148 +1,153 @@ -# WTF zk Tutorial Lesson 19: Discrete Logarithm Problem +--- +title: 19. Discrete Logarithm Problem +tags: + - zk + - abstract algebra + - group theory + - primitive root + - DLP + - discrete logarithm problem +--- -In this tutorial, we will explore primitive roots and the discrete logarithm problem. The discrete logarithm problem serves as the foundation for many encryption algorithms. +# Introduction to Discrete Logarithm Problem + +In this lecture, we will explore the concept of primitive roots and the discrete logarithm problem. The discrete logarithm problem is a fundamental concept in cryptography and serves as the basis for many cryptographic algorithms. ### 1. Multiplicative Order -We usually discuss the concept of primitive roots in the multiplicative group modulo n, denoted as Z_n^*. Therefore, before introducing the definition of a primitive root, let's first talk about the multiplicative order. +We often discuss primitive roots in the context of the multiplicative group $Z_n^*$ modulo $n$. Before we dive into the definition of primitive roots, let's first understand the concept of multiplicative order. -**Definition of Multiplicative Order:** In the group Z_n^*, for any element a, its multiplicative order is defined as the smallest positive integer k such that a^k ≡ 1 (mod n). The multiplicative order is usually denoted as ord_n(a). +**Definition of multiplicative order:** In the group $Z_n^*$, the multiplicative order of an element $a$ is the smallest positive integer $k$ such that $a^k \equiv 1 \mod n$. The multiplicative order is denoted as $\text{ord}_n(a)$. -In simpler terms, the multiplicative order is the minimum number of times an element needs to be multiplied with itself to obtain the group's identity element. +In simpler terms, the multiplicative order is the minimum number of times an element needs to be multiplied by itself to obtain the identity element of the group. -For example, consider the multiplicative group modulo 5, Z_5^* = {1,2,3,4}. We can verify that the multiplicative order of 4 is 2 because: +For example, in the multiplicative group $Z_5^* = \{1,2,3,4\}$, we can observe that the multiplicative order of $4$ is $2$: -- 4^1 ≡ 4 (mod 5) -- 4^2 ≡ 1 (mod 5) +- $4^1 \equiv 4 \mod 5$ +- $4^2 \equiv 1 \mod 5$ ## 2. Primitive Roots -**Definition of a Primitive Root:** For an element g in Z^*_n, if the various powers of g can generate all the elements in the group Z^*_n, then g is called a primitive root of Z^*_n. - -In other words, for every a ∈ Z_n^*, there exists an integer k such that g^k ≡ a (mod n). +Now, let's move on to the concept of primitive roots. -The concept of a primitive root is closely related to the generator of a cyclic group: while the multiplicative group modulo n is not necessarily a cyclic group, when it is a cyclic group, a primitive root serves as its generator. Therefore, the properties of a generator can also be applied to a primitive root. The order (multiplicative order) of a primitive root is equal to the order of Z^*_n, which is φ(n). +**Definition of primitive roots:** In the multiplicative group $Z_n^*$, an element $g$ is called a primitive root if all powers of $g$ can generate all elements in the group $Z_n^*$. -For example, consider the multiplicative group modulo 7, Z_7^* = {1, 2, 3, 4, 5, 6}. We can verify that 3 is a primitive root because: +In other words, for every $a \in Z_n^*$, there exists an integer $k$ such that $g^k \equiv a \mod n$. -- 3^1 ≡ 3 (mod 7) -- 3^2 ≡ 2 (mod 7) -- 3^3 ≡ 6 (mod 7) -- 3^4 ≡ 4 (mod 7) -- 3^5 ≡ 5 (mod 7) -- 3^6 ≡ 1 (mod 7) +The concept of primitive roots is closely related to the generator of a cyclic group. While the multiplicative group modulo $n$ may not always be a cyclic group, when it is a cyclic group, the primitive root serves as its generator. Therefore, the properties of generators can also be applied to primitive roots. The multiplicative order of a primitive root is equal to the order of $Z_n^*$, which is denoted as $\phi(n)$. -In this example, the powers of 3 generate all the elements in the group Z_7^*. +For example, consider the multiplicative group $Z_7^* = \{1, 2, 3, 4, 5, 6\}$. We can observe that $3$ is a primitive root: -As another example, consider the multiplicative group modulo 8, Z_8^* = {1, 3, 5, 7}. Let's calculate the powers of its elements: +- $3^1 \equiv 3 \mod 7$ +- $3^2 \equiv 2 \mod 7$ +- $3^3 \equiv 6 \mod 7$ +- $3^4 \equiv 4 \mod 7$ +- $3^5 \equiv 5 \mod 7$ +- $3^6 \equiv 1 \mod 7$ -- 1^1 ≡ 1 (mod 8) -- 3^1 ≡ 3 (mod 8), 3^2 ≡ 1 (mod 8) -- 5^1 ≡ 5 (mod 8), 5^2 ≡ 1 (mod 8) -- 7^1 ≡ 7 (mod 8), 7^2 ≡ 1 (mod 8) +In this example, the powers of $3$ generate all elements in the group $Z_7^*$. -We can see that none of the powers of the elements can generate the entire group, which means Z_8^* has no primitive roots and is not a cyclic group. +Let's consider another example: the multiplicative group $Z_8^* = \{1, 3, 5, 7\}$. If we calculate the powers of the elements, we can see that no power of any element can generate the entire group. Therefore, $Z_8^*$ does not have a primitive root and is not a cyclic group. ### 2.1 Properties of Primitive Roots -**Property 1. Existence of Primitive Roots:** A primitive root exists in Z_n^* if and only if n is of the form 2, 4, p^k, or 2p^k, where p is an odd prime and k is a positive integer. +**Property 1: Existence of primitive roots:** A primitive root exists in $Z_n^*$ if and only if $n$ is of the form $2, 4, p^k, 2p^k$, where $p$ is an odd prime number and $k$ is a positive integer. -The proof of this property is complex and beyond the scope of this tutorial. Just remember the conclusion. +The proof of this property is complex and beyond the scope of this tutorial. It is sufficient to remember the conclusion. -For example, Z_5^* has a primitive root, such as 2; Z_7^* also has a primitive root, such as 3. Both of these are cyclic groups. However, Z_8^* has no primitive roots and is not a cyclic group because 8 = 2^3 does not satisfy the form n = 2, 4, p^k, or 2p^k. +Here are a few examples: $Z_5^*$ has a primitive root, such as $2$; $Z_7^*$ also has a primitive root, such as $3$. Both of them are cyclic groups. On the other hand, $Z_8^*$ does not have a primitive root and is not a cyclic group because $8 = 2^3$, which does not fit the form $n = 2, 4, p^k, 2p^k$. -**Property 2. Number of Primitive Roots:** When Z_n^* has a primitive root (n = 2, 4, p^k, 2p^k), the number of primitive roots is φ(φ(n)). +**Property 2: Number of primitive roots:** When $Z_n^*$ has a primitive root (i.e., $n = 2, 4, p^k, 2p^k$), the number of primitive roots is $\phi(\phi(n))$.
Click to expand the proof👀 -Assume g is a primitive root of Z_n^*, and its order is equal to the order of the group Z_n^*, which is φ(n). According to Property 5 of the order of a cyclic group, the number of generators is φ(φ(n)). Proof complete. +Assume that $g$ is a primitive root of $Z_n^*$. Its order is equal to the order of the group $Z_n^*$, which is $\phi(n)$. According to Property 5 of the order of a cyclic group, the number of generators is $\phi(\phi(n))$. Proof completed.
-For example, Z_5^* has φ(φ(5)) = φ(4) = 2^2-2 = 2 primitive roots. +Here are a few examples: $Z_5^*$ has $\phi(\phi(5)) = \phi(4) = 2^2-2$ generators. -**Property 3. Corollary of the Number of Primitive Roots:** When p is a prime number, the number of primitive roots in Z_p^* is φ(p-1). +**Property 3: Corollary of the number of primitive roots:** When $p$ is a prime number, the number of primitive roots in $Z_p^*$ is $\phi(p-1)$.
Click to expand the proof👀 -When p is a prime number, φ(p) = p-1. According to the previous property, the number of primitive roots in Z_p^* is φ(p-1). +When $p$ is a prime number, $\phi(p) = p-1$. According to the previous property, the number of primitive roots in $Z_p^*$ is $\phi(p-1)$.
-**Property 4. Relationship between Multiplicative Order and Euler's Totient Function:** For a ∈ Z^*_n, ord_n(a) divides φ(n). +**Property 4: Relationship between multiplicative order and Euler's totient function:** For $a \in Z_n^*$, we have $\text{ord}_n(a)|\phi(n)$.
Click to expand the proof👀 -The order of Z_n^* is φ(n). According to Property 6 of the order of a cyclic group, the order of the element a divides the order of the group, which means ord_n(a) divides φ(n). Proof complete. +The order of $Z_n^*$ is $\phi(n)$. According to Property 6 of the order of a cyclic group, the order of the element $a$ divides the order of the group, i.e., $\text{ord}_n(a)|\phi(n)$. Proof completed.
## 3. Discrete Logarithm -The discrete logarithm is usually discussed in the multiplicative group modulo n, denoted as Z^*_n. When n is in the form 2, 4, p^k, or 2p^k, Z^*_n is a cyclic group, and a primitive root exists. +The discrete logarithm is usually discussed in the multiplicative group $Z^*_n$ modulo $n$. When $n = 2, 4, p^k, 2p^k$, $Z^*_n$ is a cyclic group and has a primitive root. -For the group Z^*_n, with a primitive root g and an element a, the discrete logarithm log_gb is the value of x such that g^x ≡ a. It is denoted as x = log_gb. +For the group $Z^*_n$, with the primitive root $g$ and the element $a$, the discrete logarithm $\log_gb$ is the value of $x$ that satisfies $g^x \equiv a$, denoted as $x = \log_gb$. ### 3.1 Properties of Discrete Logarithm -**Property 1. Relationship between Discrete Logarithm and Euler's Totient Function:** For the group Z^*_n, if gcd(g, n) = 1, then a ≡ g^r (mod n) if and only if log_ga ≡ r (mod φ(n)), which means the discrete logarithm is congruent to r modulo φ(n). +**Property 1: Relationship between discrete logarithm and Euler's totient function:** For the group $Z^*_n$, if $\gcd(g,n) = 1$, then $a \equiv g^r \pmod{n}$ if and only if $\log_ga=r \pmod{\phi(n)}$, which means the discrete logarithm is congruent to $r$ modulo $\phi(n)$.
Click to expand the proof👀 **Necessity** -Let x = log_ga. According to a ≡ g^r (mod n), we have g^x ≡ g^r (mod n). According to Euler's theorem: If integers a and n are coprime (i.e., gcd(g,n)=1), then g^φ(n) ≡ 1 (mod n). This means that we can multiply g^φ(n) anywhere in the equation, and the congruence still holds. For any integer k, we have g^x ≡ g^r g^(kφ(n)) ≡ g^(r + kφ(n)) (mod n), which means x = r + kφ(n), or x ≡ r (mod φ(n)). Proof complete. +Let $x = \log_ga$. According to $a \equiv g^r \pmod{n}$, we have $g^x \equiv g^r \pmod{n}$. According to Euler's theorem: if the integer $a$ and the positive integer $n$ are coprime (i.e., $\gcd(g,n)=1$), then $g^{\phi(n)} \equiv 1 \pmod{n}$. In other words, we can multiply $g^{\phi(n)}$ anywhere in the equation, and the congruence relationship still holds. For any integer $k$, we have $g^x \equiv g^r g^{k\phi(n)} \equiv g^{r +k\phi(n)}\pmod{n}$, which means $x = r +k\phi(n)$, i.e., $x \equiv r \pmod{\phi(n)}$. Proof completed. **Sufficiency** -If x ≡ r (mod φ(n)), which means x = r + kφ(n). We have g^x ≡ g^(r + kφ(n)) ≡ g^r g^(kφ(n)) (mod n) holds. According to Euler's theorem, g^φ(n) = 1, so we have g^x ≡ g^r (mod n). +If $x \equiv r \pmod{\phi(n)}$, i.e., $x = r + k\phi(n)$, we have $g^x \equiv g^{r + k\phi(n)} \equiv g^{r} g^{k\phi(n)} \pmod{n}$ holds. According to Euler's theorem, $g^{\phi(n)} = 1$, so $g^x \equiv g^r \pmod{n}$.
-For example, consider Z^*_5, which has a primitive root g = 2, and φ(5) = 4. We have 4 ≡ 2^2 (mod 5), so 4 ≡ 2^6 (mod 5) and 4 ≡ 2^10 (mod 5) also hold. You can add or subtract any multiple of φ(n) to the exponent, and the congruence relation still holds modulo n. +For example, in $Z^*_5$, with the primitive root $2$, we have $4 \equiv 2^2 \pmod{5}$. Therefore, $4 \equiv 2^6 \pmod{5}$ and $4 \equiv 2^{10} \pmod{5}$ also hold. You can add or subtract multiples of $\phi(n)$ to the exponent, and the congruence relationship still holds modulo $n$. -We can also use this property to simplify the calculation of modular exponentiation. For Z^*_7, let's take 3 as the primitive root, and φ(7) = 6. We have 3^100 ≡ 3^(100 mod 6) ≡ 3^(4 mod 6) ≡ 81 ≡ 4 (mod 7). +This property can be used to simplify the calculation of modular exponentiation. For $Z^*_7$, with the primitive root $3$, we have $\phi(7) = 6$. Therefore, $3^{100} \equiv 3^{100 \pmod{6}} \equiv 3^{4 \pmod{6}} \equiv 81 \equiv 4 \pmod{7}$. ## 4. Discrete Logarithm Problem -The Discrete Logarithm Problem (DLP) deals with finding the discrete logarithm x such that a ≡ g^x (mod n) for a given generator g and element a in the group Z^*_p where p is a prime. This problem is computationally challenging, as currently there are no known efficient algorithms to solve it in polynomial time. +The Discrete Logarithm Problem (DLP) involves finding the discrete logarithm $x$ such that $a \equiv g^x \pmod{p}$, where $p$ is a prime number in the group $Z^*_p$, given the generator $g$ and the element $a$. This problem is computationally difficult, and no efficient algorithm is currently known to solve it in polynomial time. ### 4.1 Difficulty of the Problem -Forward computation is easy: given a and x, computing a^x is straightforward and can be done using efficient algorithms. +Forward calculation is easy: Given $a$ and $x$, calculating $a^x$ is straightforward, and efficient algorithms exist for this. -However, reverse computation is difficult: given a and b, computing x = log_a(b) is extremely challenging due to the following reasons: +Reverse calculation is difficult: Given $a$ and $b$, calculating $x = \log_a{b}$ is challenging due to the following reasons: -1. Nonlinearity: The group's multiplication operation is usually a non-linear operation, and finding the exponent that satisfies the condition typically requires iterating through the entire group. +1. Non-linearity: The multiplication operation in the group is usually non-linear, and finding the exponent that satisfies the condition often requires traversing the entire group. -2. No efficient algorithms: When n is a large prime, no algorithm has been discovered to solve this problem in polynomial time. +2. No efficient algorithm: When $p$ is a large prime number, no algorithm has been discovered that can solve the problem in polynomial time. -3. Large search space: The difficulty of the discrete logarithm problem also depends on the existence of primitive roots. When the modulus n has a primitive root, the discrete logarithm problem is typically difficult because the powers of the primitive root form a complete residue system modulo n. Conversely, if there are no primitive roots, the solution to the discrete logarithm problem may be easier to find. +3. Large search space: The difficulty of the discrete logarithm problem also depends on the existence of primitive roots. When the modulus $n$ has a primitive root, the discrete logarithm problem is usually difficult because the powers of the primitive root form a complete residue system modulo $n$. Conversely, if there is no primitive root, the solution to the discrete logarithm problem may be easier to find. -Let's take a simple example: for Z^*_5, find the integer x that satisfies 3^x ≡ 2 (mod 5). We can iterate through the powers of 3: +Let's start with a simple example: for $Z^*_5$, find the integer $x$ that satisfies $3^x \equiv 2 \pmod{5}$. By iterating through the powers of $3$, we find: - $3^2 \equiv 4 \pmod{5}$ - - $3^3 \equiv 2 \pmod{5}$ Therefore, in $Z^*_5$, $3 = \log_3{2}$. -Here's a challenging example: For $Z^*_{31}$, find an integer $x$ that satisfies $13^x \equiv 17 \pmod{31}$. You can try it out. As $n$ continues to increase, the difficulty will also increase. +Here's a more challenging example: for $Z^*_{31}$, find the integer $x$ that satisfies $13^x \equiv 17 \pmod{31}$. You can try it out. As $n$ grows larger, the difficulty of the problem increases. ### 4.2 Applications in Cryptography -The discrete logarithm problem has wide applications in cryptography, especially in public key cryptography. Here are some examples: +The discrete logarithm problem has widespread applications in cryptography, particularly in public key cryptography. Here are some examples: -1. **RSA encryption algorithm:** We have introduced the [RSA algorithm](https://github.com/WTFAcademy/WTF-zk/blob/main/MS01_RSA/readme.md) in our milestone course on number theory. It is an asymmetric encryption algorithm based on the hardness of integer factorization and the discrete logarithm problem. +1. **RSA encryption algorithm:** We introduced the [RSA algorithm](https://github.com/WTFAcademy/WTF-zk/blob/main/MS01_RSA/readme.md) in a previous course on number theory. It is an asymmetric encryption algorithm based on the difficulty of factoring large integers and the discrete logarithm problem. -2. **Diffie-Hellman key exchange:** The Diffie-Hellman key exchange protocol is a method for negotiating keys over an insecure communication channel. It is based on the discrete logarithm problem, where two communicating parties choose a large prime number and a generator, and then each selects a private key. The public key is derived by performing the discrete logarithm operation on the generator, and the shared key is computed in the end. The hardness of the discrete logarithm problem ensures that even if an attacker intercepts the public information, it is difficult to derive the private key. +2. **Diffie-Hellman key exchange:** The Diffie-Hellman key exchange protocol is a method of securely negotiating keys over an insecure channel. It is based on the discrete logarithm problem. In this protocol, two parties choose a large prime number and a generator, each selects a private key, and calculates the public key through the discrete logarithm operation on the generator. Finally, they can compute a shared secret key. The difficulty of the discrete logarithm problem ensures that even if an attacker intercepts the public information, it is difficult to deduce the private key. -3. **ElGamal encryption algorithm:** The ElGamal encryption algorithm is a public key encryption algorithm based on the discrete logarithm problem. In ElGamal encryption, the encryptor chooses a generator and a private key, and the public key is generated by performing the discrete logarithm operation on the generator. The decryptor uses their private key for decryption. The hardness of the discrete logarithm problem ensures the security of the algorithm. +3. **ElGamal encryption algorithm:** The ElGamal encryption algorithm is a public key encryption algorithm based on the discrete logarithm problem. In ElGamal encryption, the encryptor chooses a generator and a private key, and generates the public key through the discrete logarithm operation on the generator. The decryptor uses their private key to decrypt. The difficulty of the discrete logarithm problem ensures the security of the algorithm. -4. **Elliptic curve cryptography:** Elliptic curve cryptography uses points on an elliptic curve for encryption and signing. The elliptic curve discrete logarithm problem (ECDLP) is the intractable problem of finding points on an elliptic curve. Elliptic curve cryptography provides more efficient encryption algorithms compared to traditional RSA, while offering the same or higher level of security. +4. **Elliptic curve cryptography:** Elliptic curve cryptography utilizes points on an elliptic curve for encryption and digital signatures. The elliptic curve discrete logarithm problem (ECDLP) is the challenging problem of finding points on an elliptic curve. Elliptic curve cryptography provides more efficient encryption algorithms compared to traditional RSA, while maintaining the same or higher level of security. -## 5. Summary +## 5. Conclusion -In this lecture, we introduced primitive roots and the discrete logarithm problem. A primitive root is a generator of the multiplicative group modulo $n$ and is important in number theory. The discrete logarithm problem is closely related to primitive roots and is a significant challenge in cryptography, as the security of many encryption algorithms relies on the difficulty of the discrete logarithm problem. +In this lecture, we introduced the concept of primitive roots and the discrete logarithm problem. Primitive roots play a significant role in number theory, while the discrete logarithm problem is a challenging problem in cryptography that guarantees the security of many encryption algorithms. -With this, we conclude the content on group theory in the WTF zk tutorial. Next, we will study the topics of ring theory and field theory! +With this, we conclude the content of the group theory section in the WTF zk tutorial. Next, we will delve into ring theory and field theory! \ No newline at end of file