non-deterministic

How can non-determinism be modeled with a List monad?

醉酒当歌 提交于 2019-11-28 22:34:30
Can anyone explain (better with an example in plain English) what a list monad can do to model non-deterministic calculations? Namely what the problem is and what solution a list monad can offer. Here's an example based on coin tossing. The problem is as follows: You have two coins, labeled Biased and Fair . The Biased coin has two heads, and the Fair coin has one head and one tail. Pick one of these coins at random, toss it and observe the result. If the result is a head, what is the probability that you picked the Biased coin? We can model this in Haskell as follows. First, you need the

Creating Nondeterministic functions in SQL Server using RAND()

你离开我真会死。 提交于 2019-11-28 12:09:12
After a bit of searching and reading the documentation, it's clear that you can write user defined functions in SQL Server that are marked as either deterministic or nondeterministic depending on which built-infunctions are used within the body. RAND() is listed under the nondeterministic functions (see msdn article ). So why can't I use it in a function? Because it has side effects. Constructs with side effects are not allowed in a function. The side effect that it has is to change some internal state that keeps track of the last rand() value issued. I think you can get around it by including

What is the default type evaluation of MonadPlus in Haskell?

若如初见. 提交于 2019-11-28 07:47:34
问题 I have the following code: import Control.Monad coin :: MonadPlus m => m Int coin = return 0 `mplus` return 1 If I evaluate coin :: Maybe Int on the interpreter, it prits Just 0 . That's normal because of the implementation of Maybe as instance of MonadPlus. If I evaluate coin :: [Int] on the interpreter, it prints [0, 1] , because the implementation of mplus on list is an append . But if I evaluate coin , without any type decorators, it prints 0 . Why? What type does the interpreter

Can a multi-threaded program ever be deterministic?

落爺英雄遲暮 提交于 2019-11-27 15:13:08
Normally it is said that multi threaded programs are non-deterministic, meaning that if it crashes it will be next to impossible to recreate the error that caused the condition. One doesn't ever really know what thread is going to run next, and when it will be preempted again. Of course this has to do with the OS thread scheduling algorithm and the fact that one doesn't know what thread is going to be run next, and how long it will effectively run. Program execution order also plays a role as well, etc... But what if you had the algorithm used for thread scheduling and what if you could know

How can non-determinism be modeled with a List monad?

删除回忆录丶 提交于 2019-11-27 14:23:50
问题 Can anyone explain (better with an example in plain English) what a list monad can do to model non-deterministic calculations? Namely what the problem is and what solution a list monad can offer. 回答1: Here's an example based on coin tossing. The problem is as follows: You have two coins, labeled Biased and Fair . The Biased coin has two heads, and the Fair coin has one head and one tail. Pick one of these coins at random, toss it and observe the result. If the result is a head, what is the

Sql Server deterministic user-defined function

与世无争的帅哥 提交于 2019-11-26 20:59:52
I have the following user-defined function: create function [dbo].[FullNameLastFirst] ( @IsPerson bit, @LastName nvarchar(100), @FirstName nvarchar(100) ) returns nvarchar(201) as begin declare @Result nvarchar(201) set @Result = (case when @IsPerson = 0 then @LastName else case when @FirstName = '' then @LastName else (@LastName + ' ' + @FirstName) end end) return @Result end I can't create an Index on a computed column using this function cause it's not deterministic. Someone could explain why is it not deterministic and eventually how to modify to make it deterministic? Thanks You just need

Can a multi-threaded program ever be deterministic?

会有一股神秘感。 提交于 2019-11-26 18:29:04
问题 Normally it is said that multi threaded programs are non-deterministic, meaning that if it crashes it will be next to impossible to recreate the error that caused the condition. One doesn't ever really know what thread is going to run next, and when it will be preempted again. Of course this has to do with the OS thread scheduling algorithm and the fact that one doesn't know what thread is going to be run next, and how long it will effectively run. Program execution order also plays a role as

Sql Server deterministic user-defined function

本小妞迷上赌 提交于 2019-11-26 05:39:13
问题 I have the following user-defined function: create function [dbo].[FullNameLastFirst] ( @IsPerson bit, @LastName nvarchar(100), @FirstName nvarchar(100) ) returns nvarchar(201) as begin declare @Result nvarchar(201) set @Result = (case when @IsPerson = 0 then @LastName else case when @FirstName = \'\' then @LastName else (@LastName + \' \' + @FirstName) end end) return @Result end I can\'t create an Index on a computed column using this function cause it\'s not deterministic. Someone could

Why is dictionary ordering non-deterministic?

天涯浪子 提交于 2019-11-25 23:50:06
问题 I recently switched from Python 2.7 to Python 3.3, and it seems that while in Python 2 the ordering of dictionary keys was arbitrary but consistent, in Python 3 the ordering of the keys of a dictionary obtained with e.g. vars() appears non-deterministic. If I run: class Test(object): pass parameters = vars(Test) print(list(parameters.keys())) in both Python 2.7 and Python 3.3, then: Python 2.7 consistently gives me [\'__dict__\', \'__module__\', \'__weakref__\', \'__doc__\'] With Python 3.3,