Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active December 6, 2025 06:04
Show Gist options
  • Select an option

  • Save Hermann-SW/9fd371d850ac1822e0fc3482ed3e7a2f to your computer and use it in GitHub Desktop.

Select an option

Save Hermann-SW/9fd371d850ac1822e0fc3482ed3e7a2f to your computer and use it in GitHub Desktop.
modulus for Gaussian integers, with t_COMPLEX and number field
\\ from Karim Belabas, corresponds to GP nfeltdivrem()
\\ https://pari.math.u-bordeaux.fr/archives/pari-users-2511/msg00054.html
\\
gimod(w, z) = my(q = round(w / z)); w - q*z;
gidivrem(w,z) = my(q = round(w / z)); [q, w - q*z];
@Hermann-SW
Copy link
Author

Hermann-SW commented Nov 27, 2025

Example calculation with t_COMPLEX:

? a=190+190*I;
? b=19+4*I;
? gidivrem(a,b)
[12 + 8*I, -6 - 10*I]
? 

Example calculation with number field:

? K=nfinit(y^2+1);
? a=190+190*y;
? b=19+4*y;
? 
? nfalgtobasis(K,b)
[19, 4]~
? K[1]
y^2 + 1
? 

Many steps:

? nfeltdiveuc(K,a,b)
[12, 8]~
? nfbasistoalg(K,nfeltdiveuc(K,a,b))
Mod(8*y + 12, y^2 + 1)
? a-nfbasistoalg(K,nfeltdiveuc(K,a,b))*b
Mod(-10*y - 6, y^2 + 1)
? lift(a-nfbasistoalg(K,nfeltdiveuc(K,a,b))*b)
-10*y - 6
? 

Better:

? q=nfeltdiveuc(K,a,b)
[12, 8]~
? nfeltadd(K,a,-nfeltmul(K,b,q))
[-6, -10]~
? 

Easiest:

? nfeltdivrem(K,a,b)
[[12, 8]~, [-6, -10]~]
?
? nfbasistoalg(K,nfeltdivrem(K,a,b)[1])
Mod(8*y + 12, y^2 + 1)
? nfbasistoalg(K,nfeltdivrem(K,a,b)[2])
Mod(-10*y - 6, y^2 + 1)
? 

@Hermann-SW
Copy link
Author

Hermann-SW commented Nov 27, 2025

unrelated github markdown test

Tips for collapsed sections

You can add a header

You can add text within a collapsed section.
/* C++ comments allow for code with nested section in markdown

nested collapsed sections */

bla bla

/*

*/

You can add an image or a code block, too.

   puts "Hello World"

foobar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment