帮助理解伪代码

发布于 2024-08-23 23:59:54 字数 240 浏览 6 评论 0原文

有人可以告诉我如何实现以下伪代码行。

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

我不明白“with”是什么意思,这是否意味着我必须确保在对 M 进行约减后,c[k] 必须小于或等于 M/2。伪代码中的“with”通常意味着什么(如果有的话)?

请注意,M 是 int 类型。如果有帮助的话,我正在用 Java 实现这个。

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心在旅行 2024-08-30 23:59:54

我认为这意味着设置c[k] = c[k] + x*M,其中-M/2 <= c[k] + x*M <= M/ 2(选择正整数或负整数x,以使该结果为真)。

例如,如果 M = 5,我们将有:

       Previous value         New value
          of c[k]              of c[k]
            8                    -2
            9                    -1
           10                     0
           11                     1
           12                     2
           13                    -2

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
兮颜 2024-08-30 23:59:54

唔。草率的伪代码,呵呵。但我认为他是说 c[k] 的绝对值也将小于或等于 M 除以 2 的模值。但这或多或少只是一个猜测。我从未遇到过使用这个术语(the with)的伪代码。也许他只是想让人们知道,由于模运算,c[k] 总是在范围内。

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.

葬﹪忆之殇 2024-08-30 23:59:54

这一定是伪代码吗?通常,伪代码只是描述代码将做什么,但是用更自然的语言(例如更像英语)。在这种情况下,我什至不确定所描述的是什么。此外,我认为“with”不一定有专门的含义,尤其是在没有看到其余内容的上下文的情况下。如果您提供更多信息可能会有所帮助。

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.

川水往事 2024-08-30 23:59:54

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

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

“With”来自数学,意思是“如果条件为真,则这样做

”标记了这个“java”,所以我使用了Java数学库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文