代写COMPSCI 1JC3 Introduction to Computational Thinking Fall 2025 Assignment 2代做留学生SQL 程序
- 首页 >> CSCOMPSCI 1JC3
Introduction to Computational Thinking
Fall 2025
Assignment 2
The purpose of Assignment 2 is to write a program in Haskell that im- plements standard operations over the Gaussian rationals. The require- ments for Assignment 2 are given below. Please submit Assignment 2 as a single Assign 2 .hs file to the Assignment 2 folder on Avenue under As- sessments/Assignments. Assignment 2 is due Sunday, October 26, 2025 before midnight.
Late submissions will not be accepted! So it is suggested that you submit a preliminary Assign 2 .hs file well before the deadline so that your mark is not zero if, e.g., your computer fails at 11:50 PM on October 26.
Although you are allowed to receive help from the instructional staff and other students, your submitted program must be your own work. Plagiarism — that is, copying a solution from someone else or from the Internet — will be treated as academic dishon- esty! If any of the ideas used in your submission were obtained from other students or sources outside of the lectures, discussion sessions, and tutorials, you must acknowledge in your Assign 2 .hs file where or from whom these ideas were obtained. Turnitin may be used to detect plagiarism. You may be asked to orally defend your solutions.
SUBMITTING CODE THAT DOES NOT COMPILE WILL RESULT IN AN OBJECTIVE MARK OF ZERO. Test your code before you submit it.
1 Background
A Gaussian rational is simply a complex number whose coefficients are ra- tional numbers. Stated formally, they are the set Q[i] such that
Q[i] = {a + bi | a, b ∈ Q}
where i2 = — 1. The structure
(Q[i], 0, 1, +, *, — , · -1 )
is a field where +, *, —, and ·-1 are complex addition, multiplication, addi- tive inverse, and multiplicative inverse restricted to the rational numbers.
Historical note: The Gaussian rationals are an extension of the Gaussian integers that were introduced by the great mathematician Carl Friedrich Gauss in 1832.
2 Assignment 2
The purpose of this assignment is to create a Haskell module that imple- ments the standard operations over the Gaussian rationals.
2.1 Requirements
1. Download from Avenue Assign2 Project Template .zip which con-tains the Stack project files for this assignment. Modify the Assign 2 .hs in the src folder so that the following requirements are satisfied.
2. Add your name and the date in the comments at the top of your Assign 2 .hs file. Define macid to be your MacID.
3. The file contains the type definition
type GaussianRat = (Rational,Rational).
in which a Gaussian rational a+bi is represented by a pair of rational numbers.
4. The file contains two functions gaussReal and gaussImag of type GaussianRat -> Rational that return the real and imaginary (first and second) parts, respectively, of a Gaussian rational.
5. The file includes a function named gaussConj of type GaussianRat -> GaussianRat that returns the conjugate of it’s input. The conjugate of a complex number a + bi is a — bi
6. The file includes a function named gaussAdd of type GaussianRat -> GaussianRat -> GaussianRat that adds two Gaussian rationals. The addition of two Gaussian rationals (a0 + b0i) and (a1 + b1i) is (a0+ a1) + (b0+ b1)i.
7. The file includes a function named gaussMul of type GaussianRat -> GaussianRat -> GaussianRat that multiplies two Gaussian ra- tionals. The multiplication of two Gaussian rationals (a0 + b0i) and (a1+ b1i) is a0a1 — b0b1+ (a0b1+ b0a1)i.
8. The file includes a function named gaussRecip of type GaussianRat -> GaussianRat returns the reciprical (multiplicative inverse) of a Gaussian rational. The reciprical of a Gaussian rational (a + bi) is a/(a2 + b2 ) - (b/(a2 + b2 ))i.
9. The file includes a function named gaussNorm of type GaussianRat -> Rational that implements the norm. The norm of a Gaussian rational is the multiplication of it with its conjugate, i.e., (a + bi) * (a - bi) = a2 +b2 . Note: You could define this function using just gaussAdd and gaussMul.
10. The file includes a function named gaussAddList of type [GaussianRat] -> GaussianRat that adds a list of Gaussian ratio- nals using gaussAdd. Assume that gaussAddList [] is (0,0), the member of GaussianRat that represents the Gaussian rational 0. You are not allowed to use either foldl or foldr in your code.
11. The file includes a function named gaussMulList of type [GaussianRat] -> GaussianRat that multiplies a list of Gaussian ra- tionals using gaussMul. Assume that gaussMulList [] is (1,0), the member of GaussianRat that represents the Gaussian rational 1. You are not allowed to use either foldl or foldr in your code.
12. The file includes a function named gaussCircle of type [GaussianRat] -> Rational -> [GaussianRat] that given a list xs of type [GaussianRat] and a nonnegative rational r of type Rational returns a list xs’ of the members x of xs such that gaussNorm x is strictly less than r. You are not allowed to use filter in your code.
13. Your file can be imported into GHCi and all of your functions perform. correctly.
2.2 Testing
Include in your file a test plan for the functions gaussConj, gaussAdd, gaussMul, gaussRecip, gaussNorm, gaussAddList, gaussMulList, and gaussCircle. The test plan must include at least three test cases for each function. Each test case should have following form.
Function: Name of the function being tested.
Test Case Number: The number of the test case.
Input: Inputs for function.
Expected Output: Expected output for the function.
Actual Output: Actual output for the function.
The test plan should be at the bottom of your file in a comment region beginning with a {- line and ending with a -} line.
	
	
	
