From: kazzarazza003
Subject: modulus function
Date: 
Message-ID: <bfe397bfbebb05571bc7f68b1b6cf910@localhost.talkaboutprogramming.com>
How does the mod or modulus function work in lisp? I have heard about it
and cant find out what it does exactly.

Thanx. 

From: ···············@gmail.com
Subject: Re: modulus function
Date: 
Message-ID: <1096982848.375037.76310@h37g2000oda.googlegroups.com>
(MOD n d) returns the remainder, r, of n/d, in the same way as (FLOOR n
d). In fact, you could define MOD as:

(defun mod (n d)
(multiple-value-bind (q r) (floor n d)
r))

(REM n d) also returns the remainder r, of n/d, but as if by TRUNCATE:

(defun rem (n d)
(multiple-value-bind (q r) (truncate n d)
r))

FLOOR truncates towards negative infinity; TRUNCATE towards 0. This
means that MOD and REM return the same value if their arguments are
both positive (or negative). MOD is most often used (I would guess)
with positive, integer arguments.

Their values may be different if the signs of the arguments are
different.

(loop for n in '(5 -5) do
(loop for d in '(2 -2) do
(format t "(mod ~a ~a) => ~a ; (rem ~a ~a) => ~a~%"
n d (mod n d) n d (rem n d))))

(mod 5 2) => 1 ; (rem 5 2) => 1
(mod 5 -2) => -1 ; (rem 5 -2) => 1
(mod -5 2) => 1 ; (rem -5 2) => -1
(mod -5 -2) => -1 ; (rem -5 -2) => -1

(loop for n in '(5 -5) do
(loop for d in '(.44 -.44) do
(format t "(mod ~a ~a) => ~a ; (rem ~a ~a) => ~a~%"
n d (mod n d) n d (rem n d))))

(mod 5 0.44) => 0.15999985 ; (rem 5 0.44) => 0.15999985
(mod 5 -0.44) => -0.28000015 ; (rem 5 -0.44) => 0.15999985
(mod -5 0.44) => 0.28000015 ; (rem -5 0.44) => -0.15999985
(mod -5 -0.44) => -0.15999985 ; (rem -5 -0.44) => -0.15999985
From: xstream
Subject: Re: modulus function maximum operand sizes and support for various Galois fields
Date: 
Message-ID: <10m6rg2h93erf24@corp.supernews.com>
Slightly related question since we are talking about modular arithmetic:

Does anyone know what maximum bit size of arguments can be sustained by the
mod function in the ANSI standard (if it addresses this detail)? Or, how big
can a "bignum" be in this occasion (for either divisor or modulus)? Is there
support in CL for different fields (as in Galois fields of numbers (rational
for example, etc.)) to conduct modular arithmetic inherently on, or one is
limited to G[2] and the rest must be encoded from scratch?

Thanks

Panos C. Lekkas


-- 
"Always do things right. It will gratify some of the people, and astonish
the rest."
Mark Twain
From: Bruno Haible
Subject: Re: modulus function maximum operand sizes and support for various Galois fields
Date: 
Message-ID: <ck69q8$30e$1@laposte.ilog.fr>
> Does anyone know what maximum bit size of arguments can be sustained by the
> mod function in the ANSI standard (if it addresses this detail)? Or, how big
> can a "bignum" be in this occasion (for either divisor or modulus)?

The maximum bignum size is an implementation detail, not specified in
the standard. GNU CLISP for example can compute with numbers with 1
million bits (300000 decimal digits) without problems.

> Is there support in CL for different fields (as in Galois fields of
> numbers (rational for example, etc.)) to conduct modular arithmetic
> inherently on, or one is limited to G[2] and the rest must be
> encoded from scratch?

CL doesn't have support for these numbers. For simple applications, I
would write the GF(p^n) support myself. (It's easy; the most important
thing is to cache the primitive root as a function of p^n somewhere.)
For advanced applications, you might instead want to use FFI bindings
to specialized libraries like NTL.

        Bruno
From: Steven M. Haflich
Subject: Re: modulus function
Date: 
Message-ID: <1zr8d.24314$QJ3.10557@newssvr21.news.prodigy.com>
kazzarazza003 wrote:
> How does the mod or modulus function work in lisp? I have heard about it
> and cant find out what it does exactly.

You should look at two sets of ANSI CL functions which implement all the
various mathematical modulus and related functions:

mod rem

floor ffloor ceiling fceiling truncate ftruncate round fround
From: Frank Buss
Subject: Re: modulus function
Date: 
Message-ID: <cjtotk$jql$2@newsreader2.netcologne.de>
"kazzarazza003" <········@students.unisa.edu.au> wrote:

> How does the mod or modulus function work in lisp? I have heard about it
> and cant find out what it does exactly.

http://www.cs.queensu.ca/software_docs/gnudev/gcl-ansi/gcl_780.html :

| mod performs the operation floor on number and divisor and returns the 
| remainder of the floor operation

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de