-
Notifications
You must be signed in to change notification settings - Fork 34
Begin adding fmpz_mod_poly #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
fea7def
Begin adding fmpz_mod_poly
GiacomoPope 6b1611a
Modify methods for contexts
GiacomoPope 6797150
Add conversion and comparison functions
GiacomoPope e6b28d4
Start work on factor; bug
GiacomoPope 4e64490
Monic, Leading Coefficent and Factor
GiacomoPope 36724e3
More progress, but badly unittested currently
GiacomoPope 0a84867
Add additional bool to check if modulus is prime on init
GiacomoPope 6122937
Continue adding functions and docstrings
GiacomoPope 4827066
Address review, add random elements and further methods and docstrings
GiacomoPope 00b87f5
Add more functions to fmpz_mod_poly, also add is_unit to fmpz_mod
GiacomoPope a3fec08
Add a few more functions, coverage currently at 22%
GiacomoPope 586307a
include new types to docstring tests
GiacomoPope b2e2894
Ensure 100% coverage of fmpz_mod, fix docstring test bugs, fmpz_mod_p…
GiacomoPope b060b23
Add base class docstrings
GiacomoPope c30ad7a
Improve docstrings and get coverage to 100%
GiacomoPope a2a7c1f
Include fmpz_mod_poly into documentation:
GiacomoPope 857ee26
Address first round of comments from the review
GiacomoPope 9cabaa2
Add a custom, DomainError, Exception
GiacomoPope 024a09c
Improve based off feedback and add additional functions
GiacomoPope 9a01c5d
Begin adding Berlekamp-Massey algorithm
GiacomoPope 87a77b7
Add minpoly, remove BM, problems with multipoint eval
GiacomoPope 85f82a4
Fix stupid copy paste bug
GiacomoPope 428bece
Add support for vec types
GiacomoPope bc85cd3
Clean up set_any function and improve memory management
GiacomoPope cb60fe7
Add tests
GiacomoPope e57a071
Merge branch 'master' into add_fmpz_mod_poly
GiacomoPope 69b2e50
Address bug from merging in test. Rename shift and (in/de)flation fun…
GiacomoPope a793997
Include new type into generic test, but with some TODO
GiacomoPope 8fd39d1
Address TODO in tests and modify how _div_ works
GiacomoPope 3614a42
Hacky fix for memory?
GiacomoPope 9dfd197
Simplify init function
GiacomoPope 1945859
better handling of dealloc
GiacomoPope 57b8346
Add new poly method to context
GiacomoPope 6a3b447
Return to 100% coverage
GiacomoPope 52dee64
Forgot to push test commit
GiacomoPope b2543b4
Fix docstring types and initalise int type
GiacomoPope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,46 @@ | ||
| from flint.flintlib.flint cimport fmpz_struct, slong, flint_rand_t | ||
| from flint.flintlib.fmpz cimport fmpz_t | ||
| from flint.flintlib.fmpz_mod cimport fmpz_mod_ctx_t | ||
| from flint.flintlib.fmpz_factor cimport fmpz_factor_t | ||
| from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_struct, fmpz_mod_poly_t | ||
|
|
||
| # unimported types {'fmpz_mod_poly_factor_t', 'void', 'fmpz_mod_poly_t'} | ||
|
|
||
| cdef extern from "flint/fmpz_mod_poly_factor.h": | ||
| ctypedef struct fmpz_mod_poly_factor_struct: | ||
| fmpz_mod_poly_struct * poly | ||
| slong *exp | ||
| slong num | ||
| slong alloc | ||
| ctypedef fmpz_mod_poly_factor_struct fmpz_mod_poly_factor_t[1] | ||
|
|
||
| # Parsed from here | ||
| void fmpz_mod_poly_factor_init(fmpz_mod_poly_factor_t fac, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_clear(fmpz_mod_poly_factor_t fac, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_realloc(fmpz_mod_poly_factor_t fac, slong alloc, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_fit_length(fmpz_mod_poly_factor_t fac, slong len, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_set(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_factor_t fac, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_print(const fmpz_mod_poly_factor_t fac, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_insert(fmpz_mod_poly_factor_t fac, const fmpz_mod_poly_t poly, slong exp, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_concat(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_factor_t fac, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_pow(fmpz_mod_poly_factor_t fac, slong exp, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_irreducible(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_irreducible_ddf(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_irreducible_rabin(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_irreducible_rabin_f(fmpz_t r, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int _fmpz_mod_poly_is_squarefree(const fmpz_struct * f, slong len, const fmpz_mod_ctx_t ctx) | ||
| int _fmpz_mod_poly_is_squarefree_f(fmpz_t fac, const fmpz_struct * f, slong len, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_squarefree(const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_is_squarefree_f(fmpz_t fac, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_factor_equal_deg_prob(fmpz_mod_poly_t factor, flint_rand_t state, const fmpz_mod_poly_t pol, slong d, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_equal_deg(fmpz_mod_poly_factor_t factors, const fmpz_mod_poly_t pol, slong d, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_distinct_deg(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t poly, slong * const *degs, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_distinct_deg_threaded(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t poly, slong * const *degs, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_squarefree(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_cantor_zassenhaus(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_kaltofen_shoup(fmpz_mod_poly_factor_t res, const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t ctx) | ||
| void fmpz_mod_poly_factor_berlekamp(fmpz_mod_poly_factor_t factors, const fmpz_mod_poly_t f, const fmpz_mod_ctx_t ctx) | ||
| void _fmpz_mod_poly_interval_poly_worker(void* arg_ptr) | ||
| void fmpz_mod_poly_roots(fmpz_mod_poly_factor_t r, const fmpz_mod_poly_t f, int with_multiplicity, const fmpz_mod_ctx_t ctx) | ||
| int fmpz_mod_poly_roots_factored(fmpz_mod_poly_factor_t r, const fmpz_mod_poly_t f, int with_multiplicity, const fmpz_factor_t n, const fmpz_mod_ctx_t ctx) |
This file contains hidden or 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 hidden or 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,14 @@ | ||
| from flint.flintlib.fmpz_mod cimport fmpz_mod_ctx_t | ||
| from flint.flintlib.fmpz_mod_poly cimport * | ||
|
|
||
| from flint.flint_base.flint_base cimport flint_poly | ||
| from flint.types.fmpz_mod cimport fmpz_mod_ctx | ||
|
|
||
| cdef class fmpz_mod_poly_ctx(fmpz_mod_ctx): | ||
| pass | ||
|
|
||
| cdef class fmpz_mod_poly(flint_poly): | ||
| cdef fmpz_mod_poly_t val | ||
| cdef fmpz_mod_poly_ctx ctx | ||
| cpdef long length(self) | ||
| cpdef long degree(self) |
This file contains hidden or 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,91 @@ | ||
| from flint.flintlib.fmpz_mod_poly cimport * | ||
| from flint.flintlib.fmpz cimport( | ||
| fmpz_equal, | ||
| ) | ||
| from flint.types.fmpz cimport fmpz | ||
| from flint.types.fmpz_mod cimport fmpz_mod_ctx, fmpz_mod | ||
| from flint.types.fmpz_poly cimport any_as_fmpz_poly, fmpz_poly | ||
|
|
||
| from flint.flint_base.flint_base cimport flint_poly | ||
| from flint.utils.typecheck cimport typecheck | ||
|
|
||
| cdef class fmpz_mod_poly_ctx(fmpz_mod_ctx): | ||
| """ | ||
| NOTE: | ||
|
|
||
| Technically this could just be the same as `fmpz_mod_ctx`, | ||
| however, the usage of fmpz_mod_ctx allows the creation of | ||
| `fmpz_mod` types by calling the context class. For symmetry | ||
| we allow this to be the case here. | ||
| """ | ||
| def __eq__(self, other): | ||
| # Most often, we expect both `fmpz_mod_poly` to be pointing | ||
| # to the same ctx, so this seems the fastest way to check | ||
| if self is other: | ||
| return True | ||
|
|
||
| # If they're not the same object in memory, they may have the | ||
| # same modulus, which is good enough | ||
| if typecheck(other, fmpz_mod_poly_ctx): | ||
| return fmpz_equal(self.val.n, (<fmpz_mod_poly_ctx>other).val.n) | ||
| return False | ||
|
|
||
| def __str__(self): | ||
| return f"Context for fmpz_mod_poly with modulus: {self.modulus()}" | ||
|
|
||
| def __repr__(self): | ||
| return f"fmpz_mod_poly_ctx({self.modulus()})" | ||
|
|
||
| def __call__(self, val): | ||
| return fmpz_mod_poly(val, self) | ||
|
|
||
|
|
||
| cdef class fmpz_mod_poly(flint_poly): | ||
| """ | ||
| """ | ||
| def __cinit__(self): | ||
| fmpz_mod_poly_init(self.val, self.ctx.val) | ||
|
|
||
| def __dealloc__(self): | ||
| fmpz_mod_poly_clear(self.val, self.ctx.val) | ||
|
|
||
| def __init__(self, val, ctx): | ||
| if not typecheck(ctx, fmpz_mod_ctx): | ||
| raise TypeError | ||
| self.ctx = ctx | ||
|
|
||
| val = any_as_fmpz_poly(val) | ||
| if val is NotImplemented: | ||
| raise TypeError | ||
|
|
||
| fmpz_mod_poly_set_fmpz_poly( | ||
| self.val, (<fmpz_poly>val).val, self.ctx.val | ||
| ) | ||
|
|
||
| def __getitem__(self, long i): | ||
| cdef fmpz x | ||
| x = fmpz() | ||
| if i < 0: | ||
| return x | ||
| fmpz_mod_poly_get_coeff_fmpz(x.val, self.val, i, self.ctx.val) | ||
| return x | ||
|
|
||
| def __setitem__(self, long i, x): | ||
| if i < 0: | ||
| raise ValueError("cannot assign to index < 0 of polynomial") | ||
| v = self.ctx.any_as_fmpz_mod(x) | ||
| if v is NotImplemented: | ||
| raise TypeError | ||
| fmpz_mod_poly_set_coeff_fmpz(self.val, i, (<fmpz_mod>v).val, self.ctx.val) | ||
|
|
||
| def repr(self): | ||
| return "fmpz_mod_poly([%s])" % (", ".join(map(str, self.coeffs()))) | ||
|
|
||
| def __len__(self): | ||
| return fmpz_mod_poly_length(self.val, self.ctx.val) | ||
|
|
||
| cpdef long length(self): | ||
| return fmpz_mod_poly_length(self.val, self.ctx.val) | ||
|
|
||
| cpdef long degree(self): | ||
| return fmpz_mod_poly_degree(self.val, self.ctx.val) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.