views:

260

answers:

4

Hi all.

Can someone please tell me how I can implement the following line of pseudo-code.

c[k]=c[k] (mod M) with |c[k]|<=M/2

I do not understand what the 'with' means, does it mean that I have to ensure that after reduction modulo M, c[k] must be less than or equal to M/2. What does 'with' usually mean (if anything) in pseudo-code?

Note that M is of type int. I'm implementing this in Java if it helps.

Thanks in advance.

A: 

Is this necessarily pseudo-code? Typically, pseudo-code is just describing what code will do, but in a more natural language (e.g. more like English). In this case, I'm not exactly sure what is even being described. Additionally, I don't think 'with' necessarily has a specialized meaning, especially without seeing the context of the rest of what is written. It might be helpful if you provide more information.

JasCav
AKA = "Also Known As", I think you meant to say "e.g." (exempli gratia; for example) here. It can even be left away. /nitpick ;)
BalusC
@BalusC - Good catch. Didn't even think about it when I was typing.
JasCav
+2  A: 

I think it means set c[k] = c[k] + x*M, where -M/2 <= c[k] + x*M <= M/2 (choose the positive or negative integer x such that this is true).

For example, if M = 5, we would have:

       Previous value         New value
          of c[k]              of c[k]
            8                    -2
            9                    -1
           10                     0
           11                     1
           12                     2
           13                    -2
Simon Nickerson
You could implement this as `int d = c[k] % M; if (d > M/2) d -= M else if (d < -(M/2)) d += M; c[k] = d;`.
Steve Jessop
A: 

Hmm. Sloppy pseudo-code, heh. But I think he is saying that the absolute value of c[k] will be less than or equal too the modulo value of M divided by 2. This is more or less just a guess however. I have never encountered pseudo code with this terminology (the with) being used. Maybe he is just trying to let people know that c[k] is always insured to be with in bounds because of the modulo arithmetic.

in70x
If the value of `c[k]` is always in bounds of the modulo, then the modulo isn't necessary.
Pindatjuh
A: 

c[k]=c[k] (mod M) with |c[k]|<=M/2

if(Math.abs(c[k]) <= M/2){
  c[k] %= M;
}

The "With" comes from mathematics, and means "If the condition is true, then do so"

You've tagged this "java", so I used the Java math library.

David Souther
Actually, if it were `if then`, then it would say `if`, not `with`. "With" in mathematics is more a constraint or bound.
Pindatjuh
I think, as mentioned several times already, the question suffers from a severe case of no-one's quite sure what the question is.
David Souther