-
Notifications
You must be signed in to change notification settings - Fork 233
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
Ashishtest #51
Merged
Merged
Ashishtest #51
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
532fcc5
Corrected a bug in printf functions and added pow function in nmod_mat
ashish1294 6896c4e
New Branch Created
ashish1294 d982ded
edited the pow function and changed the identity function name
ashish1294 9677dd8
deleted the copy and setiden files
ashish1294 687a7c2
Removed junk files
ashish1294 441882c
Function to evaluate polynomial with matrix argument added
ashish1294 619ffd5
Added test functions and Docs for pow and evaluate_mat
ashish1294 5d1fcc6
Edited nmod_mat_pow to eliminate the last squaring
ashish1294 b2737f6
Improved the test functions for pow and evaluate_mat
ashish1294 8283053
Edited Copyright Information of all files edited by me
ashish1294 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,42 @@ | ||
/*============================================================================= | ||
|
||
This file is part of FLINT. | ||
|
||
FLINT is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
|
||
FLINT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with FLINT; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
=============================================================================*/ | ||
/****************************************************************************** | ||
|
||
Copyright (C) 2010 William Hart | ||
Copyright (C) 2010 Fredrik Johansson | ||
|
||
******************************************************************************/ | ||
|
||
#include <stdlib.h> | ||
#include <gmp.h> | ||
#include "flint.h" | ||
#include "nmod_mat.h" | ||
|
||
/*Function to convert a square matrix to an identity matrix | ||
The matrix is assumed to be a square one*/ | ||
void | ||
nmod_mat_one(nmod_mat_t mat) | ||
{ | ||
slong i,j; | ||
for(i = 0; i < mat->r; i++) | ||
for(j=0; j < mat->c; j++) | ||
if(i==j) nmod_mat_entry(mat, i, j) = 1; | ||
else nmod_mat_entry(mat, i, j) = 0; | ||
} |
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,99 @@ | ||
/*============================================================================= | ||
|
||
This file is part of FLINT. | ||
|
||
FLINT is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
|
||
FLINT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with FLINT; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
=============================================================================*/ | ||
/****************************************************************************** | ||
|
||
Copyright (C) 2010 William Hart | ||
Copyright (C) 2010 Fredrik Johansson | ||
|
||
******************************************************************************/ | ||
|
||
#include <stdlib.h> | ||
#include <gmp.h> | ||
#include "flint.h" | ||
#include "nmod_mat.h" | ||
|
||
void | ||
_nmod_mat_pow(nmod_mat_t dest, const nmod_mat_t mat, ulong pow) | ||
{ | ||
nmod_mat_t temp1, temp2; | ||
if (mat->r == 0) | ||
{ | ||
return; | ||
} | ||
if (pow == 0) | ||
{ | ||
nmod_mat_one(dest); | ||
return; | ||
} | ||
if (pow == 1) | ||
{ | ||
nmod_mat_set(dest, mat); | ||
return; | ||
} | ||
if (pow == 2) | ||
{ | ||
nmod_mat_mul(dest, mat, mat); | ||
return; | ||
} | ||
|
||
nmod_mat_init(temp1, mat->r, mat->c, mat->mod.n); | ||
|
||
if(pow == 3) | ||
{ | ||
nmod_mat_mul(temp1, mat, mat); | ||
nmod_mat_mul(dest, temp1, mat); | ||
nmod_mat_clear(temp1); | ||
return; | ||
} | ||
|
||
nmod_mat_one(dest); | ||
nmod_mat_init_set(temp2, mat); | ||
while(pow > 0) | ||
{ | ||
if(pow%2 == 1) | ||
{ | ||
nmod_mat_mul(temp1, dest, temp2); | ||
nmod_mat_swap(temp1, dest); | ||
} | ||
if (pow > 1) | ||
{ | ||
nmod_mat_mul(temp1, temp2, temp2); | ||
nmod_mat_swap(temp1, temp2); | ||
} | ||
pow /= 2; | ||
} | ||
nmod_mat_clear(temp1); | ||
nmod_mat_clear(temp2); | ||
} | ||
void | ||
nmod_mat_pow(nmod_mat_t dest, const nmod_mat_t mat, ulong pow) | ||
{ | ||
nmod_mat_t temp; | ||
if (mat == dest) | ||
{ | ||
nmod_mat_init_set(temp, mat); | ||
_nmod_mat_pow(dest, temp, pow); | ||
nmod_mat_clear(temp); | ||
} | ||
else | ||
{ | ||
_nmod_mat_pow(dest, mat, pow); | ||
} | ||
} |
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,38 @@ | ||
/*============================================================================= | ||
|
||
This file is part of FLINT. | ||
|
||
FLINT is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
|
||
FLINT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with FLINT; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
=============================================================================*/ | ||
/****************************************************************************** | ||
|
||
Copyright (C) 2010 Fredrik Johansson | ||
|
||
******************************************************************************/ | ||
|
||
#include <stdlib.h> | ||
#include <gmp.h> | ||
#include "flint.h" | ||
#include "nmod_mat.h" | ||
|
||
void | ||
nmod_mat_swap(nmod_mat_t mat1, nmod_mat_t mat2) | ||
{ | ||
nmod_mat_t temp; | ||
*temp = *mat1; | ||
*mat1 = *mat2; | ||
*mat2 = *temp; | ||
} |
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,88 @@ | ||
/*============================================================================= | ||
|
||
This file is part of FLINT. | ||
|
||
FLINT is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
|
||
FLINT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with FLINT; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
=============================================================================*/ | ||
/****************************************************************************** | ||
|
||
Copyright (C) 2010 Fredrik Johansson | ||
|
||
******************************************************************************/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <limits.h> | ||
#include <gmp.h> | ||
#include "flint.h" | ||
#include "nmod_mat.h" | ||
#include "ulong_extras.h" | ||
|
||
int | ||
main() | ||
{ | ||
slong i; | ||
FLINT_TEST_INIT(state); | ||
|
||
flint_printf("pow...."); | ||
fflush(stdout); | ||
|
||
for (i = 0; i < 1000 * flint_test_multiplier(); i++) | ||
{ | ||
nmod_mat_t A, B, C, D; | ||
mp_limb_t mod; | ||
slong m, j; | ||
ulong exp; | ||
|
||
mod = n_randtest_not_zero(state); | ||
m = n_randint(state, 20); | ||
exp = n_randint(state, 50); | ||
|
||
nmod_mat_init(A, m, m, mod); | ||
nmod_mat_init(B, m, m, mod); | ||
nmod_mat_init(C, m, m, mod); | ||
nmod_mat_init(D, m, m, mod); | ||
nmod_mat_randtest(A, state); | ||
|
||
nmod_mat_pow(B, A, exp); | ||
nmod_mat_one(C); | ||
for(j = 1; j <= exp; j++) | ||
{ | ||
nmod_mat_mul(D, C, A); | ||
nmod_mat_swap(D, C); | ||
} | ||
nmod_mat_pow(A, A, exp); | ||
|
||
if (!(nmod_mat_equal(C, B) && nmod_mat_equal(C, A))) | ||
{ | ||
flint_printf("FAIL: results not equal\n");fflush(stdout); | ||
nmod_mat_print_pretty(A); | ||
nmod_mat_print_pretty(B); | ||
nmod_mat_print_pretty(C); | ||
abort(); | ||
} | ||
|
||
nmod_mat_clear(A); | ||
nmod_mat_clear(B); | ||
nmod_mat_clear(C); | ||
nmod_mat_clear(D); | ||
} | ||
|
||
FLINT_TEST_CLEANUP(state); | ||
|
||
flint_printf("PASS\n"); | ||
return 0; | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
j=0 ===> j = 0