Use modular arithmetic to model clocks, normalize residues, solve congruences and reason about divisibility.
The focus of this experiment is to identify residue classes and canonical modular representatives. Students then calculate positive and negative reductions and congruence checks, and verify equivalence through divisibility rather than ordinary equality. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.
Learning objectives
Identify residue classes and canonical modular representatives.
Calculate positive and negative reductions and congruence checks.
Verify equivalence through divisibility rather than ordinary equality.
Record the relevant inputs, intermediate states and final verification result before changing the reference configuration.
Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.
Expected learning outcomes
On completion, students can identify residue classes and canonical modular representatives, calculate positive and negative reductions and congruence checks, and verify equivalence through divisibility rather than ordinary equality.
Required deliverables
Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing verify equivalence through divisibility rather than ordinary equality. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to Modular arithmetic II — Euclid, totient, Affine and Hill.
Environment and experimental methodology
The included teaching workstation and the listed Python/Colab or WSL implementation. Historical and small-number constructions are instructional, not deployment recommendations.
Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.
How to investigate Modular arithmetic I — Congruences and residues
Use modular arithmetic to model clocks, normalize residues, solve congruences and reason about divisibility.
Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.
Experiment-specific guided practice
Objective: Use modular arithmetic to model clocks, normalize residues, solve congruences and reason about divisibility.
Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
12-hour clock — complete its numbered steps and record the requested evidence.
Congruence substitution and signed residues — complete its numbered steps and record the requested evidence.
Divisibility, proof and counterexample — complete its numbered steps and record the requested evidence.
Reference check: Clock 10 + 80 displays 6:00. Each remainder is nonnegative and less than the modulus. The congruence class is generated by −1+25k.
Model boundary: Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser.
Independent task and submission evidence
2. 12-hour clock — complete its numbered steps and record the requested evidence. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.
Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.
Trial
Changed setting
Fixed settings
Predicted result
Actual observation / units
Evidence / uncertainty
A: baseline
Reference
Record
Predict
Record
Record
B: one change
Record
Same as A
Predict
Record
Record
A: repeat
Restore
Same as A
Predict
Record
Record
Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.
Scientific concepts and engineering principles
Scientific architecture · EC03 · Modular arithmetic I — Congruences and residues
Scientific concept map: Integer a — Signed value; Modulus m — Positive integer; Division — a=q·m+r; Residue — 0≤r<m; Congruence — Compare same residue.
Euclidean division
For a positive modulus m, write a=mq+r with 0≤r<m. Congruence a≡b (mod m) means m divides a−b. Negative operands still have a nonnegative canonical remainder.
Congruence under operations
Replacing an operand by a congruent representative preserves sums, differences, products and nonnegative integer powers. A modular clock is a useful visualization of this equivalence class. For a twelve-hour clock, display residue 0 as 12.
Proof and counterexample
A numerical example can disprove a universal claim but cannot by itself prove it. To establish divisibility, introduce an integer multiplier. For a square modulo 4, enumerate the four possible residues and use the resulting set to rule out impossible sums of squares.
Prerequisites: EC02 and earlier foundations as applicable.
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.
Engineering diagrams
Residue and quotient distinguish equivalent integers.
Scientific foundations and worked examples
Clock arithmetic and signed residues
A clock is the quotient of integer hours by multiples of 12. Starting from 10, 80 hours later gives 90 mod 12=6. Starting at 4 and moving back 40 hours gives −36 mod 12=0, displayed as 12. The quotient can be negative; the canonical residue is always in [0,m−1]. For example −101=−8×13+3.
Algebra of congruences
If a≡7 and b≡3 modulo 11, addition and multiplication may be performed on the representatives: 7a+3b≡49+9≡3; 2a²+3b²≡98+27≡4; \(a^{3}\)+4b³≡343+108≡0. The class of −1 modulo 25 is {25k−1:k∈Z}; restricting k gives all members in a finite interval. Congruence is reflexive, symmetric and transitive because divisibility of differences has these properties.
Divisibility and proof construction
The relation a|b means b=ak for an integer k. Mutual divisibility of nonzero integers gives |a|=|b|, not necessarily a=b. If ac|bc and c≠0, cancel c from bc=ack to obtain b=ak. If a|bc, it does not follow that a divides either factor: 6|2×3 but neither 2 nor 3 is divisible by 6. If a divides b and a+b is odd, a must be odd because an even a would make both terms even. Integer squares are 0 or 1 modulo 4, hence a sum of two squares cannot be 3 modulo 4.
Engineering principles · additional worked teaching example
For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence.
From theory to experiment
Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.
Worked engineering reasoning and boundary conditions
Euclidean division writes a=qn+r with 0≤r<n. For −23 mod 7, q=−4 and r=5. Congruence preserves addition and multiplication.
Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.
Mathematical representation and interpretation
Euclidean remainder and congruence
n is a positive modulus, q the quotient, r the canonical nonnegative residue. Equality of residues does not mean equality of integers.
Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.
Step 1 of 4 · Dividend
Dividend
Dividend
−23, modulus 7
Quotient
Dividend
−23, modulus 7
Quotient
floor(−23/7)=−4
Remainder
Dividend
−23, modulus 7
Quotient
floor(−23/7)=−4
Remainder
−23−(−4×7)=5
Verify
Dividend
−23, modulus 7
Quotient
floor(−23/7)=−4
Remainder
−23−(−4×7)=5
Verify
−23=−28+5
Teaching example only; inspect live calculations or real practical evidence separately.
Interactive flashcards
Self-rated study progress is stored locally, not used for official grades.
Browse all explanationsWhat is a residue?
The remainder in the chosen modulus range.
When are integers congruent?
Their difference is divisible by the modulus.
Why use modular clocks?
They visualize cyclic arithmetic.
What is 29 mod 7?
1.
What is the canonical residue of −3 modulo 7?
4.
What is 17 modulo 5?
2.
When are a and b congruent modulo n?
When n divides a−b.
What is a congruence class?
All integers with the same remainder modulo n.
What happens after moving n positions around a modular clock?
The initial residue is restored.
Is congruence preserved by addition?
Yes, when both congruences use the same modulus.
Is congruence preserved by multiplication?
Yes, under the same modulus.
Can ordinary division always be used in modular arithmetic?
No. Modular division requires an invertible divisor.
What are the possible square residues modulo 4?
0 and 1.
How do you check a claimed residue?
Verify its difference from the integer is divisible by the modulus.
Evaluate −17 mod 5 as a least nonnegative residue.
−17=−4×5+3, so the residue is 3.
Are 17 and −3 congruent modulo 5?
Yes. Their difference is 20, which is divisible by 5.
If a≡b mod n, is a²≡b² mod n? Explain.
Yes: \(a^{2}\)−\(b^{2}\)=(a−b)(a+b), so divisibility by n follows.
Choose a workstation, edit the inputs, and observe recalculated results. Play or step through the actual calculation trace. Hash-search stations calculate successive candidates during playback. All inputs are fictional training data.
Where the browser requires Web Crypto, launch the local portal on localhost or use the HTTPS deployment. The classroom algorithms and keys are not intended for production use.
Independent theoretical exercises
Complete every question independently on paper or in the fields below before using the simulation or programming activities. Show formulas, intermediate steps, tables, proofs and units. Afterward verify your work using the simulator and Python, and explain discrepancies. Worked examples in Concepts do not replace your own derivation.
01 · Clock arithmetic
Calculate the readings 80 hours after 10:00, 40 hours before 4:00, and 100 hours after 6:00. Show signed arithmetic and canonical residues.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Congruence algebra
Given a ≡ 7 and b ≡ 3 (mod 11), compute the canonical residues of 7a, 14b, a−b, 7a+3b, 2a²+3b², and \(a^{3}\)+4b³.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Signed remainder
Evaluate −17 mod 2, 144 mod 7, −101 mod 13, and 199 mod 19. Write the quotient–remainder identity for each.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
04 · Congruence class
List every integer between −100 and 100 congruent to −1 modulo 25. Show how you bound the integer multiplier.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
05 · Mutual divisibility
For integers a,b, show a=b implies mutual divisibility. Is the converse valid? Prove or give a counterexample; state any zero-case convention.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
06 · Cancellation
For integers a,b,c with a≠0 and c≠0, prove or disprove ac|bc implies a|b.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
07 · Parity
For nonzero integers a,b with a|b and a+b odd, prove or disprove that a is odd.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
08 · Product divisibility
For positive integers a,b,c, prove or disprove a|bc implies a|b or a|c.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
09 · Square residues
Show that \(n^{2}\) is congruent to 0 or 1 modulo 4 for every integer n.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
10 · Sum of squares
Use the previous result to show that a positive integer 4k+3 cannot be written as the sum of two integer squares.
Engineering method — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
11 · Calculation
Calculation · Independent work
Reduce −28 and 47 modulo 9, then calculate their sum and product modulo 9 using residues.
Calculation — For modulus m>0, a=q m+r with 0≤r<m. Example −19=−3×7+2, so −19≡2 mod7. Congruence compares residues rather than ordinary equality; addition and multiplication preserve congruence. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Responses are saved locally when browser storage is available. Export your work for submission. No automatic grading or remote upload occurs.
Expanded independent theoretical exercise bank
Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.
Foundational · Apply the principle
Independent theoretical exercise · EC03-01
Calculate −39 mod 11.
Intermediate · Calculate or trace
Independent theoretical exercise · EC03-02
Reduce 17+25 modulo 9.
Intermediate · Interpret the result
Independent theoretical exercise · EC03-03
Reduce 13·18 modulo 7 using reduced operands.
Advanced · Analyze a condition
Independent theoretical exercise · EC03-04
Which of 14,−4,22 is congruent to 6 modulo 8?
Advanced · Diagnose or compare
Independent theoretical exercise · EC03-05
Explain why 0≤r<n must hold when computing a remainder with positive n.
Challenging · Engineering verification
Independent theoretical exercise · EC03-06
Check whether cancellation of 2 from 2x≡2 mod 6 is valid.
Activity sequence
Follow the setup commands, then each named activity. The detailed instructions, given values and recording fields appear below.
Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
12-hour clock — complete its numbered steps and record the requested evidence.
Compare observations with the reference checks and submit the required evidence.
Analytical preparation — before Python
Complete this written or hand-calculation activity first, then compare it with the simulator and executable implementation.
Derive the three clock answers and prove the divisibility claims symbolically. Provide a counterexample for a|bc implying a|b or a|c. Explain the sum-of-squares restriction.
Evidence: show the derivation, intermediate values and independent checks; explain any mismatch with the practical result.
Practical laboratory manual
Scientific experimental protocol
Research question: Does the quotient–remainder identity hold for negative and positive integers?
Independent variables
Start time, signed displacement, integer, modulus
Dependent observations
Canonical residue; matching integer set
Controls
Use positive moduli; keep the modulus fixed for one-variable comparisons.
Validation and evidence
Before running a trial, predict its output. Use the baseline conditions below to check your method, then vary one independent variable. Save calculated outputs or the actual Python trace. Keep browser results and local Python execution distinct.
Trial
Controlled configuration
Reference check
Student observation (editable)
Clock
10:00 + 80 hours
6:00
Enter observation
Negative input
−101 mod 13
3; quotient −8
Enter observation
Congruence
−1 mod 25, −100 through 100
All members satisfy (n+1) divisible by 25
Enter observation
Analysis: Compare the result with a hand calculation. A numerical counterexample disproves a universal claim; finite checks do not prove it.
Use modular arithmetic to model clocks, normalize residues, solve congruences and reason about divisibility.
Equipment and execution
Browser-based simulator, Python 3, notebook or local evidence folder. Use WSL Setup only if you need a Linux runtime.
2. Follow these commands in sequence (Linux/WSL). For browser-only activities, open Simulation first; the code activities are independent.
BASH · Command
cd code
python lab03.py
3. Run the check before changing inputs. Record the exact Python version and any dependency error. Use Python visualizer to inspect the recorded traces; for edited code, generate and import a new trace using the instructions in that tab.
Complete the activities in order. Hold the controlled conditions fixed, record the input and actual output, and compare your observations with an independent calculation or test vector.
01
12-hour clock
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Run the modular clock at 10:00 with +80 h, 4:00 with −40 h and 6:00 with +100 h. Use modulus 12, display residue zero as 12:00.
Calculate by hand and inspect the quotient/remainder for each displacement.
Evidence to record
Three time readings and corresponding congruences.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
02
Congruence substitution and signed residues
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Set a≡7 and b≡3 (mod 11). Evaluate 7a, 14b, a−b, 7a+3b, 2a²+3b² and \(a^{3}\)+4b³, reducing to 0…10.
Evaluate −17 mod 2, 144 mod 7, −101 mod 13 and 199 mod 19. Verify a=mq+r with 0≤r<m.
Enumerate integers −100…100 congruent to −1 modulo 25 and confirm every difference is divisible by 25.
Evidence to record
Six expressions, four quotient/remainder records, complete congruence class.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
03
Divisibility, proof and counterexample
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
For each provided divisibility assertion below write a proof or a counterexample: equality vs mutual divisibility, cancellation in ac|bc, oddness of a when a|b and a+b is odd, and a|bc implying a|b or a|c.
Use numerical examples to find counterexamples, then use the definition b=ka to justify valid statements. Treat zero and sign assumptions exactly .
Evidence to record
Four explicit conclusions with proof or counterexample.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
04
Squares and modular impossibility
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Evaluate \(n^{2}\) for residues 0,1,2,3 modulo 4. Generalize to all integers.
Use the possible sums of two square residues to prove that no integer 4k+3 can be a sum of two integer squares.
Evidence to record
Residue table and written proof.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
Challenge data and additional questions
If a=b, then a|b and b|a (under the standard divisibility convention). Is the converse true?
For nonzero a,c, does ac|bc imply a|b?
If nonzero a,b satisfy a|b and a+b is odd, must a be odd?
For positive a,b,c, does a|bc imply a|b or a|c?
Verification criteria
Clock 10 + 80 displays 6:00. Each remainder is nonnegative and less than the modulus. The congruence class is generated by −1+25k.
Deliverables
Submit the clock trace, six congruence evaluations, four remainder identities, congruence class and justified proofs/counterexamples.
Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.
Execution scope: Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# EC03 · Modular arithmetic I — Congruences and residues
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## 1. Scientific objective
Follow the setup commands, then each named activity. The detailed instructions, given values and recording fields appear below.
Complete the analytical worksheet in the portal first. Record your predictions before running this notebook. This notebook is a bounded local computational investigation; use the portal’s separate WSL, hardware or Remix procedure for real interfaces.
02Instructions · Markdown
## Experiment-specific preparation
Use modular arithmetic to model clocks, normalize residues, solve congruences and reason about divisibility.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
2. 12-hour clock — complete its numbered steps and record the requested evidence.
3. Congruence substitution and signed residues — complete its numbered steps and record the requested evidence.
4. Divisibility, proof and counterexample — complete its numbered steps and record the requested evidence.
5. Squares and modular impossibility — complete its numbered steps and record the requested evidence.
**Evidence:** Clock 10 + 80 displays 6:00. Each remainder is nonnegative and less than the modulus. The congruence class is generated by −1+25k.
**Boundary:** Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser.
03Instructions · Markdown
## 2. Reference configuration and investigation
1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
2. 12-hour clock — complete its numbered steps and record the requested evidence.
3. Congruence substitution and signed residues — complete its numbered steps and record the requested evidence.
4. Divisibility, proof and counterexample — complete its numbered steps and record the requested evidence.
5. Squares and modular impossibility — complete its numbered steps and record the requested evidence.
6. Compare observations with the reference checks and submit the required evidence.
Run cells in order; do not substitute model results for physical measurements.
04Instructions · Markdown
## 3. Algorithm implementation
Read each definition and relate it to the equations and scientific SVGs in Concepts.
05Instructions · Markdown
### Implementation cell 1
Inspect the definitions, then execute to make them available for the investigation.
06Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC03 | Code cell 01 | Modular arithmetic I — Congruences and residues
# Purpose: Implementation cell 1 Inspect the definitions, then execute to make them available for the investigation.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
"""Essential 03 — canonical residues and congruence classes."""
# Define the reusable operation clock; keep its logic separate from the trial.
def clock(hour,delta):
if not 1<=hour<=12: raise ValueError('Start hour 1–12')
return (hour+delta)%12 or 12
# Define the reusable operation residue; keep its logic separate from the trial.
def residue(a,m):
if m<=0: raise ValueError('Modulus must be positive')
q,r=divmod(a,m); return q,r
### Implementation cell 2
Inspect the definitions, then execute to make them available for the investigation.
08Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC03 | Code cell 02 | Modular arithmetic I — Congruences and residues
# Purpose: Implementation cell 2 Inspect the definitions, then execute to make them available for the investigation.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Define the reusable operation congruent; keep its logic separate from the trial.
def congruent(a,b,m): return residue(a-b,m)[1]==0
# Define the reusable operation congruence class; keep its logic separate from the trial.
def congruence_class(a,m,low,high):
return [n for n in range(low,high+1) if congruent(n,a,m)]
## 4. Execute reference controls
The program checks selected algorithm outcomes. Record the observed output. These checks do not replace the independent calculation assignment.
10Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC03 | Code cell 03 | Modular arithmetic I — Congruences and residues
# Purpose: 4. Execute reference controls The program checks selected algorithm outcomes. Record the observed output. These checks do not replace the independent calculation assignment.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert [clock(10, 80), clock(4, -40), clock(6, 100)] == [6, 12, 10]
# Repeat the same operation for each configured input so observations are comparable.
for a, m in [(-17, 2), (144, 7), (-101, 13), (199, 19)]:
q, r = residue(a, m)
assert a == q * m + r and 0 <= r < m
print(a, '=', q, '*', m, '+', r)
print('Congruence class:', congruence_class(-1, 25, -100, 100))
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert all((n * n % 4 in (0, 1) for n in range(-100, 101)))
## 5. Controlled variation
Predict the effect of the parameter changes below. Compare each actual result to your prediction.
12Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC03 | Code cell 04 | Modular arithmetic I — Congruences and residues
# Purpose: 5. Controlled variation Predict the effect of the parameter changes below. Compare each actual result to your prediction.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Repeat the same operation for each configured input so observations are comparable.
for a in (-29,-1,0,27,54):
print(a,a%26)
assert (a-a%26)%26==0
## Experimental analysis and submission
1. Record the reference input, predicted output and actual result.
2. Modify one independent variable and run the relevant cells again.
3. Explain the result using the theory and identify model limitations.
4. Save the notebook with outputs and retain the separate theoretical worksheet.
**Your derivation and conclusion:**
(Complete independently.)
14Instructions · Markdown
## Guided reasoning and evidence
A controlled comparison changes one independent input while keeping the other relevant inputs fixed; the dependent variable is the recorded output. Use this lab’s reference condition above.
**Independent task:** 2. 12-hour clock — complete its numbered steps and record the requested evidence. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.
| Trial | Input/configuration | Prediction | Observation | Evidence / limitation |
|---|---|---|---|---|
| A | Reference | | | |
| B | Changed input | | | |
| A repeat | Reference | | | |
A conclusion is supported only when it cites the recorded values or observed states and explains them with the experiment theory.
Python implementation
Download the complete practical toolkit and extract it to a new directory. Keep the code and challenges folders together.
Explore actual CPython execution traces from the included laboratory programs. Play, pause, step, inspect the current line, local variable values, function call stack, return values and output. Green variable cells changed relative to the preceding event. Line events show state before the highlighted line executes.
Run and visualize your own modified Python program
Download the Essential Cryptography Toolkit, extract it, and open a terminal in its code directory. Run the worked example or edit a copy. The trace generator executes your actual local Python file and creates an importable JSON record. Only run trusted code and use fictional keys and data.
Choose Import your trace in the visualizer and select my-trace.json. This works offline; the portal does not execute arbitrary Python on its server. The optional external Python Tutor link is suitable for standalone standard-library code, but external dependencies or local imports may not work.
For AES/DES exercises, install either supported cryptographic backend in an isolated Python environment as described in the Python code tab. Native library internals are not traced; the algorithm-specific browser workstations display the intermediate mathematics.
Can examples alone establish a universal implication?
Submission: Submit the clock trace, six congruence evaluations, four remainder identities, congruence class and justified proofs/counterexamples.
Export actual calculated observations from each workstation. Record your own predictions and conclusions, and distinguish browser calculations from local or physical measurements.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research