How do I calculate n modulo 3 in LaTeX?
up vote
42
down vote
favorite
I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
calculations
migrated from stackoverflow.com Nov 11 '11 at 0:54
This question came from our site for professional and enthusiast programmers.
add a comment |
up vote
42
down vote
favorite
I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
calculations
migrated from stackoverflow.com Nov 11 '11 at 0:54
This question came from our site for professional and enthusiast programmers.
add a comment |
up vote
42
down vote
favorite
up vote
42
down vote
favorite
I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
calculations
I don't want to display the modulo symbol, I want to programmatically calculate n modulo 3 and display the result.
calculations
calculations
edited Nov 11 '11 at 1:47
Gonzalo Medina
392k4012861555
392k4012861555
asked Nov 11 '11 at 0:03
mcandre
4111511
4111511
migrated from stackoverflow.com Nov 11 '11 at 0:54
This question came from our site for professional and enthusiast programmers.
migrated from stackoverflow.com Nov 11 '11 at 0:54
This question came from our site for professional and enthusiast programmers.
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
up vote
30
down vote
accepted
You can also use intcalcMod
from the intcalc package:
documentclass{article}
usepackage{amsmath}
usepackage{ifthen}
usepackage{intcalc}
newcounter{mycount}
newcommandNmodiii[1]{%
setcounter{mycount}{0}whiledo{value{mycount}<#1}
{$themycountpmod 3=intcalcMod{value{mycount}}{3}$\stepcounter{mycount}}
}
begin{document}
noindent A little example: $8pmod 3=intcalcMod{8}{3}$
noindent And a little loop:\
Nmodiii{20}
end{document}
The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:
documentclass{article}
usepackage{ifthen}
usepackage{forloop}
usepackage{fmtcount}
usepackage{intcalc}
usepackage{multicol}
begin{document}
begin{multicols}{2}
newcounter{i}
noindentforloop{i}{1}{value{i} < 101}{%
ifthenelse{equal{intcalcMod{value{i}}{15}}{0}}{
FizzBuzz
}{%
ifthenelse{equal{intcalcMod{value{i}}{3}}{0}}{
Fizz
}{%
ifthenelse{equal{intcalcMod{value{i}}{5}}{0}}{
Buzz
}{%
thei
}
}
}\
}
end{multicols}
end{document}
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex
– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should usevalue
(with a backslash). Also, you could have included that code in an edit to your original question.
– Gonzalo Medina
Nov 11 '11 at 1:34
|
show 8 more comments
up vote
29
down vote
There are several nice answers using different packages. I'd like to note that TeX uses integer arithmetics, so it is easy to program the standard formula a-(a/b)*b, where / means integer division.
Plain TeX solution:
newcounttmpcnta
defmodulo#1#2{tmpcnta=#1
dividetmpcnta by #2
multiplytmpcnta by #2
multiplytmpcnta by -1
advancetmpcnta by #1relax
thetmpcnta}
modulo{17}{3}
modulo{19}{3}
bye
LaTeX solution:
documentclass{article}
makeatletter
newcommandmodulo[2]{@tempcnta=#1
divide@tempcnta by #2
multiply@tempcnta by #2
multiply@tempcnta by -1
advance@tempcnta by #1relax
the@tempcnta}
makeatother
begin{document}
modulo{17}{3}
modulo{19}{3}
end{document}
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
Why can't you writedivide#1 by #2
ordividenumbernumexpr#1relax by #2
?
– A.Ellett
Dec 19 '13 at 7:52
1
@A.Ellettdivide
mutates (changes) the thing being divided (as domultiply
andadvance
), and so we want to change our own countertmpcnta
rather than#1
.
– ShreevatsaR
Nov 2 '17 at 20:30
add a comment |
up vote
21
down vote
The fp
package is small and provides the functionality to do quite complex arithmetic. In the minimal example below the macro modulo{<a>}{<b>}
stores the result of <a> mod <b>
in the macro result
, which is then directly printed:
documentclass{article}
usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
newcommand{modulo}[2]{%
FPeval{result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}result%
}
begin{document}
Some modular arithmetic:
begin{itemize}
item $512 pmod{7}=modulo{512}{7}$
item $6 pmod{4}=modulo{6}{4}$
item $15 pmod{4}=modulo{15}{4}$
item $1234567 pmod{3}=modulo{1234567}{3}$
end{itemize}
end{document}
Since the result is stored in result
, it can be used later in the text as well, until another execution of modulo
will overwrite result
.
Similar functionality in terms of mathematical functions is provided with pgf
as well.
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 withfp
verion1995/04/02
.
– Werner
Nov 11 '11 at 0:58
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
|
show 2 more comments
up vote
21
down vote
The "expandable" version, using e-TeX's numexpr
:
deftruncdiv#1#2{((#1-(#2-1)/2)/#2)}
defmoduloop#1#2{(#1-truncdiv{#1}{#2}*#2)}
defmodulo#1#2{numbernumexprmoduloop{#1}{#2}relax}
truncdiv
and moduloop
can be plugged into other expressions. It's necessary to do like this because numexpr
performs rounded integer division.
the same idea was used in thecalendarweek
TeX package.
– ogerard
Jun 5 '13 at 9:27
1
Hmm, fromtruncdiv{0}{64}
I get -1 and somodulo{0}{64}
gives 64.
– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive#2
:defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
anddeftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
add a comment |
up vote
12
down vote
Another solution is to use pgfmath
documentclass{article}
input{pgfutil-common.tex}
usepackage{pgfkeys,pgfmath}
begin{document}
pgfmathparse{mod(20,6)} pgfmathresult %displays 2.0
pgfmathtruncatemacro{myint}{ pgfmathresult}
myint %displays 2
end{document}
add a comment |
up vote
11
down vote
LaTeX3 (the expl3
package) also has a facility for computing modulus (moduli?), namely int_mod:nn
.
documentclass{article}
usepackage{expl3}
ExplSyntaxOn
newcommand{mymod}[2]{int_mod:nn{#1}{#2}}
ExplSyntaxOff
begin{document}
The residue of $45$ modulo $19$ is $mymod{45}{19}$.
end{document}
add a comment |
up vote
7
down vote
You can use the calculator
package then, type this code:
MODULO{14}{3}{sol}
$14pmod{3}=sol$
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx!:)
– Paulo Cereda
Jun 12 '12 at 10:54
add a comment |
up vote
0
down vote
You may use calc
package as long as the absolute values of the numbers are not exceeding 2^31-1=2147483647
. Otherwise you may use bigintcalc
package.
documentclass{article}
usepackage{amsmath}
usepackage{calc}
newcounter{modulo}
newcommandmodulo[2]{%
setcounter{modulo}{#1-(#1/#2)*#2}%
arabic{modulo}%
}
begin{document}
begin{align*}
131 equiv modulo{131}{3} &pmod{3} \
131 equiv modulo{131}{5} &pmod{5} \
131 equiv modulo{131}{7} &pmod{7} \
131 equiv modulo{131}{8} &pmod{8} \
-97 equiv modulo{-97}{3} &pmod{3} \
-97 equiv modulo{-97}{5} &pmod{5} \
-97 equiv modulo{-97}{7} &pmod{7} \
-97 equiv modulo{-97}{8} &pmod{8} \
end{align*}
end{document}
add a comment |
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
30
down vote
accepted
You can also use intcalcMod
from the intcalc package:
documentclass{article}
usepackage{amsmath}
usepackage{ifthen}
usepackage{intcalc}
newcounter{mycount}
newcommandNmodiii[1]{%
setcounter{mycount}{0}whiledo{value{mycount}<#1}
{$themycountpmod 3=intcalcMod{value{mycount}}{3}$\stepcounter{mycount}}
}
begin{document}
noindent A little example: $8pmod 3=intcalcMod{8}{3}$
noindent And a little loop:\
Nmodiii{20}
end{document}
The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:
documentclass{article}
usepackage{ifthen}
usepackage{forloop}
usepackage{fmtcount}
usepackage{intcalc}
usepackage{multicol}
begin{document}
begin{multicols}{2}
newcounter{i}
noindentforloop{i}{1}{value{i} < 101}{%
ifthenelse{equal{intcalcMod{value{i}}{15}}{0}}{
FizzBuzz
}{%
ifthenelse{equal{intcalcMod{value{i}}{3}}{0}}{
Fizz
}{%
ifthenelse{equal{intcalcMod{value{i}}{5}}{0}}{
Buzz
}{%
thei
}
}
}\
}
end{multicols}
end{document}
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex
– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should usevalue
(with a backslash). Also, you could have included that code in an edit to your original question.
– Gonzalo Medina
Nov 11 '11 at 1:34
|
show 8 more comments
up vote
30
down vote
accepted
You can also use intcalcMod
from the intcalc package:
documentclass{article}
usepackage{amsmath}
usepackage{ifthen}
usepackage{intcalc}
newcounter{mycount}
newcommandNmodiii[1]{%
setcounter{mycount}{0}whiledo{value{mycount}<#1}
{$themycountpmod 3=intcalcMod{value{mycount}}{3}$\stepcounter{mycount}}
}
begin{document}
noindent A little example: $8pmod 3=intcalcMod{8}{3}$
noindent And a little loop:\
Nmodiii{20}
end{document}
The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:
documentclass{article}
usepackage{ifthen}
usepackage{forloop}
usepackage{fmtcount}
usepackage{intcalc}
usepackage{multicol}
begin{document}
begin{multicols}{2}
newcounter{i}
noindentforloop{i}{1}{value{i} < 101}{%
ifthenelse{equal{intcalcMod{value{i}}{15}}{0}}{
FizzBuzz
}{%
ifthenelse{equal{intcalcMod{value{i}}{3}}{0}}{
Fizz
}{%
ifthenelse{equal{intcalcMod{value{i}}{5}}{0}}{
Buzz
}{%
thei
}
}
}\
}
end{multicols}
end{document}
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex
– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should usevalue
(with a backslash). Also, you could have included that code in an edit to your original question.
– Gonzalo Medina
Nov 11 '11 at 1:34
|
show 8 more comments
up vote
30
down vote
accepted
up vote
30
down vote
accepted
You can also use intcalcMod
from the intcalc package:
documentclass{article}
usepackage{amsmath}
usepackage{ifthen}
usepackage{intcalc}
newcounter{mycount}
newcommandNmodiii[1]{%
setcounter{mycount}{0}whiledo{value{mycount}<#1}
{$themycountpmod 3=intcalcMod{value{mycount}}{3}$\stepcounter{mycount}}
}
begin{document}
noindent A little example: $8pmod 3=intcalcMod{8}{3}$
noindent And a little loop:\
Nmodiii{20}
end{document}
The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:
documentclass{article}
usepackage{ifthen}
usepackage{forloop}
usepackage{fmtcount}
usepackage{intcalc}
usepackage{multicol}
begin{document}
begin{multicols}{2}
newcounter{i}
noindentforloop{i}{1}{value{i} < 101}{%
ifthenelse{equal{intcalcMod{value{i}}{15}}{0}}{
FizzBuzz
}{%
ifthenelse{equal{intcalcMod{value{i}}{3}}{0}}{
Fizz
}{%
ifthenelse{equal{intcalcMod{value{i}}{5}}{0}}{
Buzz
}{%
thei
}
}
}\
}
end{multicols}
end{document}
You can also use intcalcMod
from the intcalc package:
documentclass{article}
usepackage{amsmath}
usepackage{ifthen}
usepackage{intcalc}
newcounter{mycount}
newcommandNmodiii[1]{%
setcounter{mycount}{0}whiledo{value{mycount}<#1}
{$themycountpmod 3=intcalcMod{value{mycount}}{3}$\stepcounter{mycount}}
}
begin{document}
noindent A little example: $8pmod 3=intcalcMod{8}{3}$
noindent And a little loop:\
Nmodiii{20}
end{document}
The code that appears in the link posted in a comment, there are some spurious blank spaces producing an undesired indentation of the first line; here's a corrected version:
documentclass{article}
usepackage{ifthen}
usepackage{forloop}
usepackage{fmtcount}
usepackage{intcalc}
usepackage{multicol}
begin{document}
begin{multicols}{2}
newcounter{i}
noindentforloop{i}{1}{value{i} < 101}{%
ifthenelse{equal{intcalcMod{value{i}}{15}}{0}}{
FizzBuzz
}{%
ifthenelse{equal{intcalcMod{value{i}}{3}}{0}}{
Fizz
}{%
ifthenelse{equal{intcalcMod{value{i}}{5}}{0}}{
Buzz
}{%
thei
}
}
}\
}
end{multicols}
end{document}
edited Jun 3 '17 at 12:06
Moriambar
7,82731845
7,82731845
answered Nov 11 '11 at 1:03
Gonzalo Medina
392k4012861555
392k4012861555
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex
– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should usevalue
(with a backslash). Also, you could have included that code in an edit to your original question.
– Gonzalo Medina
Nov 11 '11 at 1:34
|
show 8 more comments
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex
– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should usevalue
(with a backslash). Also, you could have included that code in an edit to your original question.
– Gonzalo Medina
Nov 11 '11 at 1:34
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
! Missing number, treated as zero. <to be read again> v l.32 }
– mcandre
Nov 11 '11 at 1:13
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
Thanks, that helps. I'm writing FizzBuzz for LaTeX, so I need to use the mod result in further calculations, not just display it.
– mcandre
Nov 11 '11 at 1:14
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
@mcandre: nothing prevents you from using the result in your calculations!
– Gonzalo Medina
Nov 11 '11 at 1:15
Hmm. When I do this, I get
! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex– mcandre
Nov 11 '11 at 1:30
Hmm. When I do this, I get
! Missing number, treated as zero.
github.com/mcandre/mcandre/blob/master/latex/fizzy.tex– mcandre
Nov 11 '11 at 1:30
You are using "value" in your code and you should use
value
(with a backslash). Also, you could have included that code in an edit to your original question.– Gonzalo Medina
Nov 11 '11 at 1:34
You are using "value" in your code and you should use
value
(with a backslash). Also, you could have included that code in an edit to your original question.– Gonzalo Medina
Nov 11 '11 at 1:34
|
show 8 more comments
up vote
29
down vote
There are several nice answers using different packages. I'd like to note that TeX uses integer arithmetics, so it is easy to program the standard formula a-(a/b)*b, where / means integer division.
Plain TeX solution:
newcounttmpcnta
defmodulo#1#2{tmpcnta=#1
dividetmpcnta by #2
multiplytmpcnta by #2
multiplytmpcnta by -1
advancetmpcnta by #1relax
thetmpcnta}
modulo{17}{3}
modulo{19}{3}
bye
LaTeX solution:
documentclass{article}
makeatletter
newcommandmodulo[2]{@tempcnta=#1
divide@tempcnta by #2
multiply@tempcnta by #2
multiply@tempcnta by -1
advance@tempcnta by #1relax
the@tempcnta}
makeatother
begin{document}
modulo{17}{3}
modulo{19}{3}
end{document}
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
Why can't you writedivide#1 by #2
ordividenumbernumexpr#1relax by #2
?
– A.Ellett
Dec 19 '13 at 7:52
1
@A.Ellettdivide
mutates (changes) the thing being divided (as domultiply
andadvance
), and so we want to change our own countertmpcnta
rather than#1
.
– ShreevatsaR
Nov 2 '17 at 20:30
add a comment |
up vote
29
down vote
There are several nice answers using different packages. I'd like to note that TeX uses integer arithmetics, so it is easy to program the standard formula a-(a/b)*b, where / means integer division.
Plain TeX solution:
newcounttmpcnta
defmodulo#1#2{tmpcnta=#1
dividetmpcnta by #2
multiplytmpcnta by #2
multiplytmpcnta by -1
advancetmpcnta by #1relax
thetmpcnta}
modulo{17}{3}
modulo{19}{3}
bye
LaTeX solution:
documentclass{article}
makeatletter
newcommandmodulo[2]{@tempcnta=#1
divide@tempcnta by #2
multiply@tempcnta by #2
multiply@tempcnta by -1
advance@tempcnta by #1relax
the@tempcnta}
makeatother
begin{document}
modulo{17}{3}
modulo{19}{3}
end{document}
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
Why can't you writedivide#1 by #2
ordividenumbernumexpr#1relax by #2
?
– A.Ellett
Dec 19 '13 at 7:52
1
@A.Ellettdivide
mutates (changes) the thing being divided (as domultiply
andadvance
), and so we want to change our own countertmpcnta
rather than#1
.
– ShreevatsaR
Nov 2 '17 at 20:30
add a comment |
up vote
29
down vote
up vote
29
down vote
There are several nice answers using different packages. I'd like to note that TeX uses integer arithmetics, so it is easy to program the standard formula a-(a/b)*b, where / means integer division.
Plain TeX solution:
newcounttmpcnta
defmodulo#1#2{tmpcnta=#1
dividetmpcnta by #2
multiplytmpcnta by #2
multiplytmpcnta by -1
advancetmpcnta by #1relax
thetmpcnta}
modulo{17}{3}
modulo{19}{3}
bye
LaTeX solution:
documentclass{article}
makeatletter
newcommandmodulo[2]{@tempcnta=#1
divide@tempcnta by #2
multiply@tempcnta by #2
multiply@tempcnta by -1
advance@tempcnta by #1relax
the@tempcnta}
makeatother
begin{document}
modulo{17}{3}
modulo{19}{3}
end{document}
There are several nice answers using different packages. I'd like to note that TeX uses integer arithmetics, so it is easy to program the standard formula a-(a/b)*b, where / means integer division.
Plain TeX solution:
newcounttmpcnta
defmodulo#1#2{tmpcnta=#1
dividetmpcnta by #2
multiplytmpcnta by #2
multiplytmpcnta by -1
advancetmpcnta by #1relax
thetmpcnta}
modulo{17}{3}
modulo{19}{3}
bye
LaTeX solution:
documentclass{article}
makeatletter
newcommandmodulo[2]{@tempcnta=#1
divide@tempcnta by #2
multiply@tempcnta by #2
multiply@tempcnta by -1
advance@tempcnta by #1relax
the@tempcnta}
makeatother
begin{document}
modulo{17}{3}
modulo{19}{3}
end{document}
edited Nov 11 '11 at 4:12
Werner
431k599501628
431k599501628
answered Nov 11 '11 at 3:34
Boris
29.8k262106
29.8k262106
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
Why can't you writedivide#1 by #2
ordividenumbernumexpr#1relax by #2
?
– A.Ellett
Dec 19 '13 at 7:52
1
@A.Ellettdivide
mutates (changes) the thing being divided (as domultiply
andadvance
), and so we want to change our own countertmpcnta
rather than#1
.
– ShreevatsaR
Nov 2 '17 at 20:30
add a comment |
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
Why can't you writedivide#1 by #2
ordividenumbernumexpr#1relax by #2
?
– A.Ellett
Dec 19 '13 at 7:52
1
@A.Ellettdivide
mutates (changes) the thing being divided (as domultiply
andadvance
), and so we want to change our own countertmpcnta
rather than#1
.
– ShreevatsaR
Nov 2 '17 at 20:30
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
I used a similar solution in a calendar.
– starblue
Nov 11 '11 at 14:21
1
1
Why can't you write
divide#1 by #2
or dividenumbernumexpr#1relax by #2
?– A.Ellett
Dec 19 '13 at 7:52
Why can't you write
divide#1 by #2
or dividenumbernumexpr#1relax by #2
?– A.Ellett
Dec 19 '13 at 7:52
1
1
@A.Ellett
divide
mutates (changes) the thing being divided (as do multiply
and advance
), and so we want to change our own counter tmpcnta
rather than #1
.– ShreevatsaR
Nov 2 '17 at 20:30
@A.Ellett
divide
mutates (changes) the thing being divided (as do multiply
and advance
), and so we want to change our own counter tmpcnta
rather than #1
.– ShreevatsaR
Nov 2 '17 at 20:30
add a comment |
up vote
21
down vote
The fp
package is small and provides the functionality to do quite complex arithmetic. In the minimal example below the macro modulo{<a>}{<b>}
stores the result of <a> mod <b>
in the macro result
, which is then directly printed:
documentclass{article}
usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
newcommand{modulo}[2]{%
FPeval{result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}result%
}
begin{document}
Some modular arithmetic:
begin{itemize}
item $512 pmod{7}=modulo{512}{7}$
item $6 pmod{4}=modulo{6}{4}$
item $15 pmod{4}=modulo{15}{4}$
item $1234567 pmod{3}=modulo{1234567}{3}$
end{itemize}
end{document}
Since the result is stored in result
, it can be used later in the text as well, until another execution of modulo
will overwrite result
.
Similar functionality in terms of mathematical functions is provided with pgf
as well.
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 withfp
verion1995/04/02
.
– Werner
Nov 11 '11 at 0:58
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
|
show 2 more comments
up vote
21
down vote
The fp
package is small and provides the functionality to do quite complex arithmetic. In the minimal example below the macro modulo{<a>}{<b>}
stores the result of <a> mod <b>
in the macro result
, which is then directly printed:
documentclass{article}
usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
newcommand{modulo}[2]{%
FPeval{result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}result%
}
begin{document}
Some modular arithmetic:
begin{itemize}
item $512 pmod{7}=modulo{512}{7}$
item $6 pmod{4}=modulo{6}{4}$
item $15 pmod{4}=modulo{15}{4}$
item $1234567 pmod{3}=modulo{1234567}{3}$
end{itemize}
end{document}
Since the result is stored in result
, it can be used later in the text as well, until another execution of modulo
will overwrite result
.
Similar functionality in terms of mathematical functions is provided with pgf
as well.
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 withfp
verion1995/04/02
.
– Werner
Nov 11 '11 at 0:58
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
|
show 2 more comments
up vote
21
down vote
up vote
21
down vote
The fp
package is small and provides the functionality to do quite complex arithmetic. In the minimal example below the macro modulo{<a>}{<b>}
stores the result of <a> mod <b>
in the macro result
, which is then directly printed:
documentclass{article}
usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
newcommand{modulo}[2]{%
FPeval{result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}result%
}
begin{document}
Some modular arithmetic:
begin{itemize}
item $512 pmod{7}=modulo{512}{7}$
item $6 pmod{4}=modulo{6}{4}$
item $15 pmod{4}=modulo{15}{4}$
item $1234567 pmod{3}=modulo{1234567}{3}$
end{itemize}
end{document}
Since the result is stored in result
, it can be used later in the text as well, until another execution of modulo
will overwrite result
.
Similar functionality in terms of mathematical functions is provided with pgf
as well.
The fp
package is small and provides the functionality to do quite complex arithmetic. In the minimal example below the macro modulo{<a>}{<b>}
stores the result of <a> mod <b>
in the macro result
, which is then directly printed:
documentclass{article}
usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
newcommand{modulo}[2]{%
FPeval{result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}result%
}
begin{document}
Some modular arithmetic:
begin{itemize}
item $512 pmod{7}=modulo{512}{7}$
item $6 pmod{4}=modulo{6}{4}$
item $15 pmod{4}=modulo{15}{4}$
item $1234567 pmod{3}=modulo{1234567}{3}$
end{itemize}
end{document}
Since the result is stored in result
, it can be used later in the text as well, until another execution of modulo
will overwrite result
.
Similar functionality in terms of mathematical functions is provided with pgf
as well.
answered Nov 11 '11 at 0:30
Werner
431k599501628
431k599501628
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 withfp
verion1995/04/02
.
– Werner
Nov 11 '11 at 0:58
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
|
show 2 more comments
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 withfp
verion1995/04/02
.
– Werner
Nov 11 '11 at 0:58
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
! Undefined control sequence. FP@@upn ...on string "#2string "}edef FP@tmp {[#2]}expandafter FP@upn... l.38 }
– mcandre
Nov 11 '11 at 0:42
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Do you receive this error when compiling my MWE?
– Werner
Nov 11 '11 at 0:47
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
Yes. Specs: TeXworks on Mac OS X 10.7.2.
– mcandre
Nov 11 '11 at 0:53
What distribution of TeX do you have installed? I have TeX Live 2011 with
fp
verion 1995/04/02
.– Werner
Nov 11 '11 at 0:58
What distribution of TeX do you have installed? I have TeX Live 2011 with
fp
verion 1995/04/02
.– Werner
Nov 11 '11 at 0:58
2
2
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
I like that a LaTeX solution to doing modular arithmetic is to load a package designed to do floating point calculations. WHAT!?
– Seamus
Feb 2 '12 at 17:08
|
show 2 more comments
up vote
21
down vote
The "expandable" version, using e-TeX's numexpr
:
deftruncdiv#1#2{((#1-(#2-1)/2)/#2)}
defmoduloop#1#2{(#1-truncdiv{#1}{#2}*#2)}
defmodulo#1#2{numbernumexprmoduloop{#1}{#2}relax}
truncdiv
and moduloop
can be plugged into other expressions. It's necessary to do like this because numexpr
performs rounded integer division.
the same idea was used in thecalendarweek
TeX package.
– ogerard
Jun 5 '13 at 9:27
1
Hmm, fromtruncdiv{0}{64}
I get -1 and somodulo{0}{64}
gives 64.
– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive#2
:defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
anddeftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
add a comment |
up vote
21
down vote
The "expandable" version, using e-TeX's numexpr
:
deftruncdiv#1#2{((#1-(#2-1)/2)/#2)}
defmoduloop#1#2{(#1-truncdiv{#1}{#2}*#2)}
defmodulo#1#2{numbernumexprmoduloop{#1}{#2}relax}
truncdiv
and moduloop
can be plugged into other expressions. It's necessary to do like this because numexpr
performs rounded integer division.
the same idea was used in thecalendarweek
TeX package.
– ogerard
Jun 5 '13 at 9:27
1
Hmm, fromtruncdiv{0}{64}
I get -1 and somodulo{0}{64}
gives 64.
– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive#2
:defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
anddeftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
add a comment |
up vote
21
down vote
up vote
21
down vote
The "expandable" version, using e-TeX's numexpr
:
deftruncdiv#1#2{((#1-(#2-1)/2)/#2)}
defmoduloop#1#2{(#1-truncdiv{#1}{#2}*#2)}
defmodulo#1#2{numbernumexprmoduloop{#1}{#2}relax}
truncdiv
and moduloop
can be plugged into other expressions. It's necessary to do like this because numexpr
performs rounded integer division.
The "expandable" version, using e-TeX's numexpr
:
deftruncdiv#1#2{((#1-(#2-1)/2)/#2)}
defmoduloop#1#2{(#1-truncdiv{#1}{#2}*#2)}
defmodulo#1#2{numbernumexprmoduloop{#1}{#2}relax}
truncdiv
and moduloop
can be plugged into other expressions. It's necessary to do like this because numexpr
performs rounded integer division.
answered Nov 11 '11 at 6:49
egreg
699k8518613132
699k8518613132
the same idea was used in thecalendarweek
TeX package.
– ogerard
Jun 5 '13 at 9:27
1
Hmm, fromtruncdiv{0}{64}
I get -1 and somodulo{0}{64}
gives 64.
– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive#2
:defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
anddeftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
add a comment |
the same idea was used in thecalendarweek
TeX package.
– ogerard
Jun 5 '13 at 9:27
1
Hmm, fromtruncdiv{0}{64}
I get -1 and somodulo{0}{64}
gives 64.
– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive#2
:defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
anddeftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
the same idea was used in the
calendarweek
TeX package.– ogerard
Jun 5 '13 at 9:27
the same idea was used in the
calendarweek
TeX package.– ogerard
Jun 5 '13 at 9:27
1
1
Hmm, from
truncdiv{0}{64}
I get -1 and so modulo{0}{64}
gives 64.– ShreevatsaR
Nov 2 '17 at 20:26
Hmm, from
truncdiv{0}{64}
I get -1 and so modulo{0}{64}
gives 64.– ShreevatsaR
Nov 2 '17 at 20:26
I'm using the following for now, which works for positive
#2
: defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
and deftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
I'm using the following for now, which works for positive
#2
: defmoduloop#1#2{ifnum numexpr(#1 - (#1/#2)*(#2))relax < 0 (#1 - (#1/#2)*(#2) + #2) else (#1 - (#1/#2)*(#2)) fi}
and deftruncdiv#1#2{((#1 - moduloop{#1}{#2})/(#2))}
– ShreevatsaR
Nov 2 '17 at 20:44
add a comment |
up vote
12
down vote
Another solution is to use pgfmath
documentclass{article}
input{pgfutil-common.tex}
usepackage{pgfkeys,pgfmath}
begin{document}
pgfmathparse{mod(20,6)} pgfmathresult %displays 2.0
pgfmathtruncatemacro{myint}{ pgfmathresult}
myint %displays 2
end{document}
add a comment |
up vote
12
down vote
Another solution is to use pgfmath
documentclass{article}
input{pgfutil-common.tex}
usepackage{pgfkeys,pgfmath}
begin{document}
pgfmathparse{mod(20,6)} pgfmathresult %displays 2.0
pgfmathtruncatemacro{myint}{ pgfmathresult}
myint %displays 2
end{document}
add a comment |
up vote
12
down vote
up vote
12
down vote
Another solution is to use pgfmath
documentclass{article}
input{pgfutil-common.tex}
usepackage{pgfkeys,pgfmath}
begin{document}
pgfmathparse{mod(20,6)} pgfmathresult %displays 2.0
pgfmathtruncatemacro{myint}{ pgfmathresult}
myint %displays 2
end{document}
Another solution is to use pgfmath
documentclass{article}
input{pgfutil-common.tex}
usepackage{pgfkeys,pgfmath}
begin{document}
pgfmathparse{mod(20,6)} pgfmathresult %displays 2.0
pgfmathtruncatemacro{myint}{ pgfmathresult}
myint %displays 2
end{document}
answered Nov 11 '11 at 9:18
Alain Matthes
72k7158291
72k7158291
add a comment |
add a comment |
up vote
11
down vote
LaTeX3 (the expl3
package) also has a facility for computing modulus (moduli?), namely int_mod:nn
.
documentclass{article}
usepackage{expl3}
ExplSyntaxOn
newcommand{mymod}[2]{int_mod:nn{#1}{#2}}
ExplSyntaxOff
begin{document}
The residue of $45$ modulo $19$ is $mymod{45}{19}$.
end{document}
add a comment |
up vote
11
down vote
LaTeX3 (the expl3
package) also has a facility for computing modulus (moduli?), namely int_mod:nn
.
documentclass{article}
usepackage{expl3}
ExplSyntaxOn
newcommand{mymod}[2]{int_mod:nn{#1}{#2}}
ExplSyntaxOff
begin{document}
The residue of $45$ modulo $19$ is $mymod{45}{19}$.
end{document}
add a comment |
up vote
11
down vote
up vote
11
down vote
LaTeX3 (the expl3
package) also has a facility for computing modulus (moduli?), namely int_mod:nn
.
documentclass{article}
usepackage{expl3}
ExplSyntaxOn
newcommand{mymod}[2]{int_mod:nn{#1}{#2}}
ExplSyntaxOff
begin{document}
The residue of $45$ modulo $19$ is $mymod{45}{19}$.
end{document}
LaTeX3 (the expl3
package) also has a facility for computing modulus (moduli?), namely int_mod:nn
.
documentclass{article}
usepackage{expl3}
ExplSyntaxOn
newcommand{mymod}[2]{int_mod:nn{#1}{#2}}
ExplSyntaxOff
begin{document}
The residue of $45$ modulo $19$ is $mymod{45}{19}$.
end{document}
answered Feb 2 '12 at 17:04
Bruno Le Floch
33.7k5112211
33.7k5112211
add a comment |
add a comment |
up vote
7
down vote
You can use the calculator
package then, type this code:
MODULO{14}{3}{sol}
$14pmod{3}=sol$
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx!:)
– Paulo Cereda
Jun 12 '12 at 10:54
add a comment |
up vote
7
down vote
You can use the calculator
package then, type this code:
MODULO{14}{3}{sol}
$14pmod{3}=sol$
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx!:)
– Paulo Cereda
Jun 12 '12 at 10:54
add a comment |
up vote
7
down vote
up vote
7
down vote
You can use the calculator
package then, type this code:
MODULO{14}{3}{sol}
$14pmod{3}=sol$
You can use the calculator
package then, type this code:
MODULO{14}{3}{sol}
$14pmod{3}=sol$
edited Jun 12 '12 at 9:27
Joseph Wright♦
200k21549874
200k21549874
answered Jun 12 '12 at 9:24
Robert Fuster
7111
7111
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx!:)
– Paulo Cereda
Jun 12 '12 at 10:54
add a comment |
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx!:)
– Paulo Cereda
Jun 12 '12 at 10:54
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
Nice, a new package! But you might want to make it clearer that you are the package author...
– clemens
Jun 12 '12 at 10:35
How nice!
:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx! :)
– Paulo Cereda
Jun 12 '12 at 10:54
How nice!
:)
Feel free to add your package to our list. And by the way, welcome to TeX.sx! :)
– Paulo Cereda
Jun 12 '12 at 10:54
add a comment |
up vote
0
down vote
You may use calc
package as long as the absolute values of the numbers are not exceeding 2^31-1=2147483647
. Otherwise you may use bigintcalc
package.
documentclass{article}
usepackage{amsmath}
usepackage{calc}
newcounter{modulo}
newcommandmodulo[2]{%
setcounter{modulo}{#1-(#1/#2)*#2}%
arabic{modulo}%
}
begin{document}
begin{align*}
131 equiv modulo{131}{3} &pmod{3} \
131 equiv modulo{131}{5} &pmod{5} \
131 equiv modulo{131}{7} &pmod{7} \
131 equiv modulo{131}{8} &pmod{8} \
-97 equiv modulo{-97}{3} &pmod{3} \
-97 equiv modulo{-97}{5} &pmod{5} \
-97 equiv modulo{-97}{7} &pmod{7} \
-97 equiv modulo{-97}{8} &pmod{8} \
end{align*}
end{document}
add a comment |
up vote
0
down vote
You may use calc
package as long as the absolute values of the numbers are not exceeding 2^31-1=2147483647
. Otherwise you may use bigintcalc
package.
documentclass{article}
usepackage{amsmath}
usepackage{calc}
newcounter{modulo}
newcommandmodulo[2]{%
setcounter{modulo}{#1-(#1/#2)*#2}%
arabic{modulo}%
}
begin{document}
begin{align*}
131 equiv modulo{131}{3} &pmod{3} \
131 equiv modulo{131}{5} &pmod{5} \
131 equiv modulo{131}{7} &pmod{7} \
131 equiv modulo{131}{8} &pmod{8} \
-97 equiv modulo{-97}{3} &pmod{3} \
-97 equiv modulo{-97}{5} &pmod{5} \
-97 equiv modulo{-97}{7} &pmod{7} \
-97 equiv modulo{-97}{8} &pmod{8} \
end{align*}
end{document}
add a comment |
up vote
0
down vote
up vote
0
down vote
You may use calc
package as long as the absolute values of the numbers are not exceeding 2^31-1=2147483647
. Otherwise you may use bigintcalc
package.
documentclass{article}
usepackage{amsmath}
usepackage{calc}
newcounter{modulo}
newcommandmodulo[2]{%
setcounter{modulo}{#1-(#1/#2)*#2}%
arabic{modulo}%
}
begin{document}
begin{align*}
131 equiv modulo{131}{3} &pmod{3} \
131 equiv modulo{131}{5} &pmod{5} \
131 equiv modulo{131}{7} &pmod{7} \
131 equiv modulo{131}{8} &pmod{8} \
-97 equiv modulo{-97}{3} &pmod{3} \
-97 equiv modulo{-97}{5} &pmod{5} \
-97 equiv modulo{-97}{7} &pmod{7} \
-97 equiv modulo{-97}{8} &pmod{8} \
end{align*}
end{document}
You may use calc
package as long as the absolute values of the numbers are not exceeding 2^31-1=2147483647
. Otherwise you may use bigintcalc
package.
documentclass{article}
usepackage{amsmath}
usepackage{calc}
newcounter{modulo}
newcommandmodulo[2]{%
setcounter{modulo}{#1-(#1/#2)*#2}%
arabic{modulo}%
}
begin{document}
begin{align*}
131 equiv modulo{131}{3} &pmod{3} \
131 equiv modulo{131}{5} &pmod{5} \
131 equiv modulo{131}{7} &pmod{7} \
131 equiv modulo{131}{8} &pmod{8} \
-97 equiv modulo{-97}{3} &pmod{3} \
-97 equiv modulo{-97}{5} &pmod{5} \
-97 equiv modulo{-97}{7} &pmod{7} \
-97 equiv modulo{-97}{8} &pmod{8} \
end{align*}
end{document}
answered 1 hour ago
Z.H.
1,7411326
1,7411326
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f34424%2fhow-do-i-calculate-n-modulo-3-in-latex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown