Help with understanding Pseudo-code
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 l开发者_如何学Cess 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.
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
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.
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.
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.
精彩评论