-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic polynomial arithmetic (#48)
* feat: basic polynomial arithmetic * fix: remove polynomial const generics
- Loading branch information
1 parent
2637594
commit eea6702
Showing
7 changed files
with
663 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Define a finite field, our `GF101` which is | ||
# a field of 101 elements (101 being prime). | ||
F = GF(101) | ||
|
||
# Define the polynomial ring over GF(101) | ||
R.<x> = PolynomialRing(F) | ||
|
||
# Create the polynomials | ||
a = 4*x^3 + 3*x^2 + 2*x^1 + 1 | ||
b = 9*x^4 + 8*x^3 + 7*x^2 + 6*x^1 + 5 | ||
|
||
# Perform polynomial division | ||
q_ab, r_ab = a.quo_rem(b) | ||
|
||
# Print the results | ||
print("For a / b :") | ||
print("Quotient:", q_ab) | ||
print("Remainder:", r_ab) | ||
|
||
# Perform polynomial division | ||
q_ba, r_ba = b.quo_rem(a) | ||
|
||
# Print the results | ||
print("\nFor b / a :") | ||
print("Quotient:", q_ba) | ||
print("Remainder:", r_ba) | ||
|
||
# Polynomials easy to do by hand | ||
p = x^2 + 2*x + 1 | ||
q = x + 1 | ||
|
||
# Perform polynomial division | ||
quot, rem = p.quo_rem(q) | ||
print("\nFor p / q :") | ||
print("Quotient:", quot) | ||
print("Remainder:", rem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.