https://github.com/lukius/fmtgp
From Mathematics to Generic Programming
https://github.com/lukius/fmtgp
Last synced: 4 months ago
JSON representation
From Mathematics to Generic Programming
- Host: GitHub
- URL: https://github.com/lukius/fmtgp
- Owner: lukius
- License: mit
- Created: 2014-12-15T04:00:29.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-02T05:27:21.000Z (over 11 years ago)
- Last Synced: 2025-12-20T23:56:59.211Z (6 months ago)
- Language: C++
- Size: 2.15 MB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
* This repository contains solutions -and related work- for some of the exercises presented in [From Mathematics to Generic Programming](http://www.amazon.com/Mathematics-Generic-Programming-Alexander-Stepanov/dp/0321942043). So far,
**Chapter 3: Ancient Greek Number Theory**
- [X] Exercise 3.6: Prove that if `n` and `m` are coprime, then `sigma(nm) = sigma(n) sigma(m)`.
- [X] Exercise 3.7: Prove that every even perfect number is a triangular number.
- [X] Exercise 3.8: Prove that the sum of the reciprocals of the divisors of a perfect number is always 2.
**Chapter 4: Euclid's Algorithm**
- [X] Exercise 4.3: Prove that `sqrt_3(16) + sqrt_3(54) = sqrt_3(250)`.
- [X] Exercise 4.4: Prove that, for any odd square number `x` there is an even square number `y` such that `x+y` is a square number.
- [X] Exercise 4.5: Prove that, if `x` and `y` are both sums of two squares, then so is their product `xy`.
**Chapter 5: The Emergence of Modern Number Theory**
- [X] Exercise 5.1: Prove that if `n > 4` is composite, then `(n-1)!` is a multiple of `n`.
**Chapter 6: Abstraction in Mathematics**
- [X] Exercise 6.3: Prove that any group has at least one element.
- [X] Exercise 6.4: What is the order of `e`? Prove that `e` is the only element of such order.
- [X] Exercise 6.5: Prove that if `a` is an element of order `n`, then `a^{-1} = a^{n-1}`.
- [X] Exercise 6.7: Prove that any subgroup of a cyclic group is cyclic.
- [X] Exercise 6.8: Prove that any cyclic group is abelian.
- [X] Exercise 6.10: Prove that every group of prime order is cyclic.
**Chapter 7: Deriving a Generic Algorithm**
- [X] Exercise 7.1: How many additions are needed to compute `fib0(n)`?
- [X] Exercise 7.2: Implement Fibonacci numbers using `power` (code for solving arbitrary linear recurrences also provided).
**Chapter 8: More Algebraic Structures**
- [X] Exercise 8.7: Compute the transitive closure of a graph using matrix multiplication on boolean semirings.
- [X] Exercise 8.8: Compute shortest paths on a graph using matrix multiplication on tropical semirings.
**Chapter 11: Permutation Algorithms**
- [X] Exercise 11.1: Prove Cayley's theorem.
- [X] Exercise 11.2: What is the order of Sn?
- [X] Exercise 11.3: Prove that if n > 2, Sn is not abelian.
- [X] Exercise 11.5: Design an in-place reverse algorithm for forward iterators.
- [X] Exercise 11.9: Prove that if a rotation of `n` elements has a trivial cycle, then it has `n` trivial cycles.
- [X] Exercise 11.11: How many assignments does 3-reverse rotate perform?
**Chapter 12: Extensions of GCD**
- [X] Exercise 12.2:
* Prove that an ideal `I` is closed under subtraction.
* Prove that `I` contains 0.
- [X] Exercise 12.3: Prove that all the elements of a linear combination ideal are divisible by any of the common divisors of `a` and `b`.
- [X] Exercise 12.4: Prove that any element in a principal ideal is divisible by the principal element.
- [X] Exercise 12.5: Using Bézout's identity, prove that if `p` is prime, then any 0 < `a` < `p` has multiplicative inverse modulo `p`.
- [X] Exercise 12.7: Develop a version of the extended GCD algorithm based on Stein's algorithm.
**Chapter 13: A Real-World Application**
- [X] Exercise 13.1: Implement the function `bool is_carmichael(n)`.
- [X] Exercise 13.2: Find the first seven Carmichael numbers using your function.