-
Notifications
You must be signed in to change notification settings - Fork 162
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
More GMP work #1075
More GMP work #1075
Changes from all commits
1898ea7
8c018e0
e918054
1c6d8ee
b591686
9a3689f
99418d3
b700ea4
af567b1
6a5815f
b8a188c
8454a6f
1c8ae24
cdba5d4
3e44492
42c4845
0950124
9561e9d
fbf656a
9bc7f34
cad52ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,45 +333,7 @@ end ); | |
#F Jacobi( <n>, <m> ) . . . . . . . . . . . . . . . . . . . . Jacobi symbol | ||
## | ||
## | ||
InstallGlobalFunction( Jacobi, function ( n, m ) | ||
local jac, t; | ||
|
||
# check the argument | ||
if m <= 0 then Error("<m> must be positive"); fi; | ||
|
||
# compute the Jacobi symbol similar to Euclid's algorithm | ||
jac := 1; | ||
while m <> 1 do | ||
|
||
# if the gcd of $n$ and $m$ is $>1$ Jacobi returns $0$ | ||
if n = 0 or (n mod 2 = 0 and m mod 2 = 0) then | ||
jac := 0; m := 1; | ||
|
||
# $J(n,2*m) = J(n,m) * J(n,2) = J(n,m) * (-1)^{(n^2-1)/8}$ | ||
elif m mod 2 = 0 then | ||
if n mod 8 = 3 or n mod 8 = 5 then jac := -jac; fi; | ||
m := m / 2; | ||
|
||
# $J(2*n,m) = J(n,m) * J(2,m) = J(n,m) * (-1)^{(m^2-1)/8}$ | ||
elif n mod 2 = 0 then | ||
if m mod 8 = 3 or m mod 8 = 5 then jac := -jac; fi; | ||
n := n / 2; | ||
|
||
# $J(-n,m) = J(n,m) * J(-1,m) = J(n,m) * (-1)^{(m-1)/2}$ | ||
elif n < 0 then | ||
if m mod 4 = 3 then jac := -jac; fi; | ||
n := -n; | ||
|
||
# $J(n,m) = J(m,n) * (-1)^{(n-1)*(m-1)/4}$ (quadratic reciprocity) | ||
else | ||
if n mod 4 = 3 and m mod 4 = 3 then jac := -jac; fi; | ||
t := n; n := m mod n; m := t; | ||
|
||
fi; | ||
od; | ||
|
||
return jac; | ||
end ); | ||
InstallGlobalFunction( Jacobi, JACOBI_INT ); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While its great to be able to do all these in GMP, I would quite like to keep GAP functions around as an alternative. The reason is that while implementing GAP in alternative runtimes, the more code one does not have to write in the runtime the better. I don't know how to do this cleanly right now though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is exactly how I did it before @ChrisJefferson asked me to remove the GAP implementation sigh. It is still around in the .tst files, by the way. I can add it back here again, but I don't want to rewrite the code a third time, so I'll wait until at least @ChrisJefferson signs off on it, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caveat: the new Jacobi accepts more inputs than the old (n negative). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed in the chat, I am happy with moving the function to tests, and I will attempt to make a structured attempt at detecting which functions are delegated to C code (and collect/provide GAP implementations where appropriate). |
||
|
||
############################################################################# | ||
|
@@ -1385,24 +1347,16 @@ end ); | |
|
||
|
||
InstallGlobalFunction(PValuation,function(n,p) | ||
local a,v; | ||
if not IsPrimeInt(p) or not IsRat(n) then | ||
local v; | ||
if not IsInt(p) or not IsRat(n) or p = 0 then | ||
Error("wrong parameters"); | ||
fi; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message could be more helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I hope somebody will make a PR improving it after this PR has been merged :-) |
||
if IsZero(n) then | ||
if n = 0 then | ||
return infinity; | ||
elif not IsInt(n) then | ||
return PValuation(NumeratorRat(n),p)-PValuation(DenominatorRat(n),p); | ||
elif n<0 then n:=-n; | ||
elif IsInt(n) then | ||
return PVALUATION_INT(n,p); | ||
fi; | ||
a:=1; | ||
v:=0; | ||
while n mod p=0 do | ||
a:=a*p; | ||
v:=v+1; | ||
n:=n/p; | ||
od; | ||
return v; | ||
return PVALUATION_INT(NumeratorRat(n),p) - PVALUATION_INT(DenominatorRat(n),p); | ||
end); | ||
|
||
#T ########################################################################## | ||
|
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.
Is it obvious enough that$e \neq 0$ ?
Negative values seem to work (now) if$r$ is invertible, so that should maybe be documented explicitly?
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.
But e can (still) be 0. And negative values were supported before, just not documented.
Documenting this more explicitly is fine by me, but I'd prefer to not do this as part of this PR (which has been in the works for very long by now)...