问题标签 [non-deterministic]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
11544 浏览

python - 为什么字典排序是不确定的?

我最近从 Python 2.7 切换到 Python 3.3,似乎虽然在 Python 2 中字典键的顺序是任意但一致的,但在 Python 3 中,使用 eg 获得的字典键的顺序vars()似乎是不确定的。

如果我运行:

在 Python 2.7 和 Python 3.3 中,然后:

  • Python 2.7 始终如一地给我

    /li>
  • 使用 Python 3.3,我可以获得任何随机顺序——例如:

    /li>

这种不确定性从何而来?为什么是这样的

......在运行之间保持一致,总是给予

……?

0 投票
2 回答
521 浏览

haskell - Can I model a list of successes with short circuiting failure via the composition of applicative functors?

The user 'singpolyma' asked on reddit if there was some general structure underlying:

A free monad was suggested, but I wondered if this could be modeled more generally via applicative functors. In Abstracting with Applicatives, Bazerman shows us that the sum of two applicative functors is also an applicative functor, with bias to the left/right, provided we have a natural transformation in the direction of the bias. This sounds like it's what we need! Thus, I started my proposal, but then quickly ran into problems. Can anyone see solutions to these problems?:


Firstly, we start with the definition of the sum of two functors. I started here because we want to model sum types - either successes or successes and a failure.

And the two functors we want to work with are:

Success is straight forward - it's essentially Const [a]. However, Failure e I'm not so sure about. It's not an applicative functor, because pure doesn't have any definition. It is, however, an instance of Apply:

Next, we can define the sum of these functors, with a natural transformation from right to left (so a left bias):

And the only thing we now have to do is define our natural transformation, and this is where it all comes crumbling down.

The inability to create a Failure seems to be the problem. Furthermore, even being hacky and using ⊥ isn't an option, because this will be evaluated, in the case where you have InR (Success ...) <*> InL (Failure ...).

I feel like I'm missing something, but I have no idea what it is.

Can this be done?

0 投票
1 回答
78 浏览

deterministic - 使用不同的cpu会导致同一个程序的输出不同吗?

如果同一个程序不使用任何随机数或 I/O,是否应该始终输出相同的结果,或者它是否有可能在不同的 cpu 上输出不同的东西(但相同的架构,不需要重新编译)?我特别考虑使用浮点数和双精度数的计算,这严重依赖于精度,如数值近似值中使用的那样。

0 投票
1 回答
342 浏览

python - 为什么这个 opencl 代码是不确定的?

以下 python 代码使用 PyOpenCL 用数组 b 中的元素之和填充数组a_plus_b(这不是我的实际目标,但它是我能找到的最简单的代码,但仍然显示了问题)。

给出输出:

但是,如果我将宽度从 32 更改为 33,则数组不再是同一个元素。

事实上,每次运行代码时,都会产生不同的结果。

造成差异的原因是什么?什么不是

0 投票
3 回答
283 浏览

haskell - 您如何使用 list monad 来计算/表示非确定性计算的结果?

我想构建一个计算,其中上下文是引导现在的所有路径的历史(形成一棵树),而函数是当前状态,以过去状态为条件。该函数本身是不确定的,因此一个过去的状态可能会导致几个未来的状态,因此是树分支。将此计算的结果表示为一棵树是有意义的,但是有没有办法用 list monad 简洁地表达它?还是我不知道的其他构造?

0 投票
1 回答
109 浏览

mysql - 在 Perl 中跟踪非确定性 MySQL 错误

我有一个在托管共享服务器上运行的单线程 Perl 脚本,主要执行以下代码:

有时(<1%)代码会遇到回滚情况并失败。在我的本地系统上,我无法重现此错误。数据库是 MySQL 5。

如何追踪此错误?任何帮助将不胜感激。

0 投票
2 回答
541 浏览

complexity-theory - 什么是非确定性程序?

我有一个问题......什么是非确定性程序?我有这个练习

为以下语言提供一个非确定性过程: L = {: G=(V,E) 有一个独立集 I st |I| >= k 和顶点 V\I 形成一个哈密顿循环}

谢谢!

0 投票
3 回答
238 浏览

tsql - t-sql 中的 select * 是确定性的吗?

具体来说,我需要知道查询是否

将始终以相同的顺序返回列。

我没有看到任何迹象表明它是不确定的,但由于我的应用程序的规格,我不能假设这是真的。谁能以一种或另一种方式指出我的文档?我的搜索没有运气。

提前致谢。

0 投票
2 回答
1091 浏览

audio - FMOD 频谱数据确定性

我正在使用 FMOD 进行音频分析,使用 system::getSpectrum 来获取频率数据。我的问题是关于 FMOD 在幕后使用哪些数据来执行 FFT。例如,如果我的输出速率为 44100Hz,并且我每秒调用 getSpectrum() 30 次(每 0.03333 秒),有 1024 个样本:

FMOD 是否只获取最后播放的 1024 个 PCM 样本并对其执行 FFT?在这种情况下,如果在 getSpectrum() 调用之间实际读取并播放了 1470 个样本,则仅处理最后 1024 个样本,并且我们丢失了中间 446 个浮点数的信息。然后我调用 getSpectrum 的时间间隔的精度变得非常重要,因为如果我在 0.033 秒后调用它一次和在 0.034 秒后调用它,我不会得到相同的结果,这使得整个事情非常依赖于 FPS 并且完全未定。谁能向我提供有关 FMOD 的底层机制以及如何使其具有确定性的见解?

0 投票
0 回答
265 浏览

c++ - “printf”在 Qt 中似乎是不确定的?

我知道“printf”是标准c,应该是确定性的。但是当在 Qt 中运行时,我看到了一个更加不确定的响应(时钟周期)。这可能是由于 Qt 在其响应中添加了一些“猪肉”吗?

我有多个线程调用使用互斥锁的函数。当一个线程进入时,它会设置一个开关,以便其他线程在它完成之前不能。事情似乎正常工作了几秒钟,然后线程似乎从 10 到 1 个线程被杀死。所以我尝试添加延迟:(k=k+1:没有帮助),然后(循环 k=k+1:没有帮助),(usleep 有效),(printf)也可以创建随机延迟并允许所有线程继续运行。