Modulus and Non-Negative Finite Field - Hewlett Packard

This is a discussion on Modulus and Non-Negative Finite Field - Hewlett Packard ; Hello all, I noticed that when I set a modulus in the HP, say 8, it uses the field (-3, -2, -1, 0, 1, 2, 3, 4). How do I get it to instead use the field (0, 1, 2, ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: Modulus and Non-Negative Finite Field

  1. Modulus and Non-Negative Finite Field

    Hello all,

    I noticed that when I set a modulus in the HP, say 8, it uses the field
    (-3, -2, -1, 0, 1, 2, 3, 4). How do I get it to instead use the field
    (0, 1, 2, 3, 4, 5, 7) for its calculations? For addition and subtract, I
    can just internally shift, but what about things like inverse mod?

    Thanks,

    Titus

  2. Re: Modulus and Non-Negative Finite Field

    On Sep 22, 2:06*pm, Titus Barik wrote:
    > Hello all,
    >
    > I noticed that when I set a modulus in the HP, say 8, it uses the field
    > (-3, -2, -1, 0, 1, 2, 3, 4). How do I get it to instead use the field
    > (0, 1, 2, 3, 4, 5, 7) for its calculations? For addition and subtract, I
    > can just internally shift, but what about things like inverse mod?
    >
    > Thanks,
    >
    > Titus


    You can do that for inverse mod, too. In the ring of congruence
    classes modulo n, a is congruent to a+kn for k any integer. Thus they
    can be used interchangably. (in other words, if the calculator gives
    you a negative result, just add the modulus to it to get an equivalent
    non-negative result)

    The HP chooses to use negative values in the congruence classes to
    minimize absolute values. In fact, when doing modular arithmetic by
    hand, it is often advantageous to use the ring containing negative
    residues to simplify the arithmetic.

    S.C.

  3. Re: Modulus and Non-Negative Finite Field

    On Sep 22, 2:06*pm, Titus Barik wrote:
    > but what about things like inverse mod?



    Inverses modulo a composite modulus do not always exist. For example,
    modulo 8, the inverse of 3 is 3 because 3*3 (mod 8) is congruent to 1.
    However, 2 has no inverse modulo 8. If it did, then the inverse n
    would satisfy 2*n = 1 (mod 8). Then multiply both sides by 4 and get
    0*n = 4 (mod 8) which is clearly impossible.

    In the ring Z/nZ for n not prime, there exist zero-divisors. This
    means that modulo n, if a*b = 0, that does not imply that either a or
    b is 0. Here, modulo 8, 2*4 = 0, but neither 2 nor 4 is congruent to
    0. On the other hand, of n is prime, then there exist no zero
    divisors, implying that all elements of the ring have inverses.

    S.C.

  4. Re: Modulus and Non-Negative Finite Field

    On Sep 22, 2:06*pm, Titus Barik wrote:
    > Hello all,
    >
    > I noticed that when I set a modulus in the HP, say 8, it uses the field
    > (-3, -2, -1, 0, 1, 2, 3, 4). How do I get it to instead use the field
    > (0, 1, 2, 3, 4, 5, 7) for its calculations? For addition and subtract, I
    > can just internally shift, but what about things like inverse mod?
    >
    > Thanks,
    >
    > Titus


    Assuming x and m are on the stack, in that order, then use a short
    program like
    \<< DUP UNROT MOD DUP 0 < {+} {NIP} IFTE \>>
    instead of the straight MOD command to assure a non-negative result.

    I also have a RCLMOD library program which returns the value of MODULO
    stored in the CASDIR directory:
    \<< PATH { HOME CASDIR MODULO } RCL SWAP EVAL
    which I use in conjunction with
    \<< DUP UNROT MOD DUP 0 < {+} {NIP} IFTE \>>
    when using those modulo commands which access that MODULO value directly.

  5. Re: Modulus and Non-Negative Finite Field

    On Mon, 22 Sep 2008 18:37:25 -0500:

    | @ To recall the current MODULO value
    | \<< PATH { HOME CASDIR MODULO } RCL SWAP EVAL \>>

    { HOME CASDIR MODULO } RCL is sufficient,
    since it doesn't change the current path.

    However, due to inheritance from the earliest HP49G,
    when the variables in CASDIR were initially in HOME,
    the calculator's internal functions
    will use any "CAS variables" found instead in HOME,
    if they are not also in CASDIR!
    (move them all to HOME and see)

    Purists who want to be absolutely compatible with the calculator
    may therefore want to adjust for that, since
    { HOME CASDIR MODULO } RCL errors if 'MODULO' exists in HOME,
    but doesn't exist in CASDIR!

    \<< PATH HOME CASDIR 'MODULO' RCL SWAP EVAL \>> ???

    The above accounts neither for the possible current non-existence
    of CASDIR, nor for the possible current non-existence of MODULO,
    even though CASDIR exists (as a directory?) --
    this may serve as an indication of why programming of built-in ROM
    (or of any generalized system
    which hasn't control of everything in its environment)
    can require more than just casual attention,
    although for casual user programming purposes,
    it may be suitable to just let { HOME CASDIR MODULO } RCL
    error out if things aren't already exactly where most commonly found.

    [r->] [OFF]

  6. Re: Modulus and Non-Negative Finite Field

    Virgil wrote:
    > Assuming x and m are on the stack, in that order, then use a short
    > program like
    > \<< DUP UNROT MOD DUP 0 < {+} {NIP} IFTE \>>
    > instead of the straight MOD command to assure a non-negative result.


    Hello,

    Thanks, but how would I go about getting the inverse of a matrix whose
    elements are modulo 26 (ring: 0 to 25)? For example, for X = (7 8; 17 3)
    the inverse would be (9 2; 1 15). I tried INVMOD and it returns SOME
    sort of a matrix back but then it gives me 'Bad Argument Value'.

    Titus

  7. Re: Modulus and Non-Negative Finite Field

    In article ,
    Titus Barik wrote:

    > Virgil wrote:
    > > Assuming x and m are on the stack, in that order, then use a short
    > > program like
    > > \<< DUP UNROT MOD DUP 0 < {+} {NIP} IFTE \>>
    > > instead of the straight MOD command to assure a non-negative result.

    >
    > Hello,
    >
    > Thanks, but how would I go about getting the inverse of a matrix whose
    > elements are modulo 26 (ring: 0 to 25)? For example, for X = (7 8; 17 3)
    > the inverse would be (9 2; 1 15). I tried INVMOD and it returns SOME
    > sort of a matrix back but then it gives me 'Bad Argument Value'.
    >
    > Titus


    To start with, unless your original matrix has a determinant whose value
    is relatively prime to your modulus, it may well not have any modular
    inverse even if it has a regular one.

    The determinant of [[7 8][ 17 3]] is -115, or 15 mod 26, so that it will
    actually have the desired inverse, as 15 and 26 are relatively prime,
    having no common factor larger than 1.

    In order to guarantee in general that a modular matrix having non-zero
    determinant for that modulus will have an inverse relative to that
    modulus, the modulus must be a prime number, which your modulus, 26 is
    not.


    Also, [[7 8][ 17 3]] times [[9 2][1 15]] mod 26 is

    [[ 19 4][ 0 1]] , which is not an identity matrix, so

    [[7 8][ 17 3]] and [[9 2][1 15]] are not inverses, even mod 26.

    Also INVMOD does not accept matrices as input.


    On the other hand:

    The actual inverse, mod 26, of [[7 8][ 17 3]] does exist and is
    [[21 33 ][ 11 23]].

    Their regular ( non-modular) product, in the order shown, is
    [[235 338][ 390 443]], which reduces, modulo 26, to [[1 0][ 0 1]]

    Their regular product in reverse order, while different, also reduces
    mod 26 to the identity matrix.

  8. Re: Modulus and Non-Negative Finite Field

    In article ,
    "John H Meyers" wrote:

    > On Mon, 22 Sep 2008 18:37:25 -0500:
    >
    > | @ To recall the current MODULO value
    > | \<< PATH { HOME CASDIR MODULO } RCL SWAP EVAL \>>
    >
    > { HOME CASDIR MODULO } RCL is sufficient,
    > since it doesn't change the current path.


    Right!
    >
    > However, due to inheritance from the earliest HP49G,
    > when the variables in CASDIR were initially in HOME,
    > the calculator's internal functions
    > will use any "CAS variables" found instead in HOME,
    > if they are not also in CASDIR!
    > (move them all to HOME and see)
    >
    > Purists who want to be absolutely compatible with the calculator
    > may therefore want to adjust for that, since
    > { HOME CASDIR MODULO } RCL errors if 'MODULO' exists in HOME,
    > but doesn't exist in CASDIR!
    >
    > \<< PATH HOME CASDIR 'MODULO' RCL SWAP EVAL \>> ???
    >
    > The above accounts neither for the possible current non-existence
    > of CASDIR, nor for the possible current non-existence of MODULO,
    > even though CASDIR exists (as a directory?) --
    > this may serve as an indication of why programming of built-in ROM
    > (or of any generalized system
    > which hasn't control of everything in its environment)
    > can require more than just casual attention,
    > although for casual user programming purposes,
    > it may be suitable to just let { HOME CASDIR MODULO } RCL
    > error out if things aren't already exactly where most commonly found.
    >


    I had forgot that little quirk.

    Thanks.

  9. Re: Modulus and Non-Negative Finite Field

    To do what you want, try the programme:
    INV EXPANDMOD

    --
    Message posted using http://www.talkaboutcomputing.com/group/comp.sys.hp48/
    More information at http://www.talkaboutcomputing.com/faq.html


  10. Re: Modulus and Non-Negative Finite Field

    To do what you want, try the programme:
    INV EXPANDMOD

    --
    Message posted using http://www.talkaboutcomputing.com/group/comp.sys.hp48/
    More information at http://www.talkaboutcomputing.com/faq.html


+ Reply to Thread