0

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.

3
  • In my mind, this isn't pseudo-code, it's more like language-agnostic code. Pseudo-code is supposed to be comprised of English words structured as an algorithm. Commented Mar 7, 2010 at 22:06
  • Can you specify the algorithm in which this arises? Commented Mar 7, 2010 at 22:27
  • More context would definitely help us out. Commented Mar 7, 2010 at 22:55

4 Answers 4

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

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;.
0

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.

1 Comment

If the value of c[k] is always in bounds of the modulo, then the modulo isn't necessary.
0

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.

2 Comments

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 - Good catch. Didn't even think about it when I was typing.
-1

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.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.