亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1544 | 回復: 1
打印 上一主題 下一主題

[函數(shù)] 【sets】erlang sets操作 [復制鏈接]

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設計版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設計版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設計版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-01-05 23:42 |只看該作者 |倒序瀏覽
  1. BASIC SET MANIPULATION WITH ERLANG

  2. This article deals with basic set manipulation in Erlang. If you are not fimilar with sets, perhaps now is a good time to do some reading on them here.

  3. Erlang Set Libraries

  4. Erlang offers 2 libraries for dealing with sets. The first one is sets and the second gb_sets. The sets library will generally work better for smaller sets while the gb_sets will work better for larger sets. The exact reason why this is is given here.

  5. In this article the gb_sets library will be used since this set will be primarally used later on.

  6. Example Problem

  7. This is the problem that will be used as an example of working with sets:

  8. A card is to be selected from a deck of 30 cards. The deck consists of 15 red cards numbered 1 to 15 and 15 black cards numbered 1 to 15. A card is to be choosen.

  9. What is the set that describes the outcome that the card is even, black, and less than 5?
  10. What is the set that describes the outcome that the card is greater than 5 and black?
  11. What is the set that describes the outcome that the card is even, black, or less than 5?
  12. What is the set that describes the outcome that the card is even and it is black or less than 5?
  13. What is the set that describes the outcome that the card is not even, not black and not less than 5?
  14. Theory First

  15. From the problem we need to first understand what sets are being asked for. This can be broken into three distinct sets:

  16. A: The event that the card is even.
  17. B: The event that the card is black.
  18. C: The event that the card is less than 5.
  19. So the answers described using A, B, and C are:

  20. A ∩ B ∩ C
  21. B ∩ Cc
  22. A ∪ B ∪ C
  23. A ∩ (B ∪ C)
  24. Ac ∩ Bc ∩ Cc
  25. Implementation

  26. Now the implementation in Erlang.

  27. The sample space is all of the cards, so in Erlang this can be represented as:

  28. gb_sets:from_list([{red, 1}, {red, 2}, {red, 3}, {red, 4}, {red, 5}, {red, 6},
  29.                    {red, 7}, {red, 8}, {red, 9}, {red, 10}, {red, 11}, {red, 12},
  30.                    {red, 13}, {red, 14}, {red, 15},
  31.                    {black, 1}, {black, 2}, {black, 3}, {black, 4}, {black, 5},
  32.                    {black, 6}, {black, 7}, {black, 8}, {black, 9}, {black, 10},
  33.                    {black, 11}, {black, 12}, {black, 13}, {black, 14}, {black, 15}]).
  34. The set A can be represented as:

  35. A = gb_sets:from_list([{red, 2}, {red, 4}, {red, 6}, {red, 8}, {red, 10}, {red, 12},
  36.                        {red, 14}, {black, 2}, {black, 4}, {black, 6}, {black, 8}, {black, 10},
  37.                        {black, 12}, {black, 14}]).
  38. The set B can be represented as:

  39. B = gb_sets:from_list([{black, 1}, {black, 2}, {black, 3}, {black, 4}, {black, 5},
  40.                        {black, 6}, {black, 7}, {black, 8}, {black, 9}, {black, 10},
  41.                        {black, 11}, {black, 12}, {black, 13}, {black, 14}, {black, 15}]).
  42. And the set C can be represented as:

  43. C = gb_sets:from_list([{red, 1}, {red, 2}, {red, 3}, {red, 4}, {red, 5},
  44.                        {black, 1}, {black, 2}, {black, 3}, {black, 4}, {black, 5}]).
  45. Answers

  46. After this point getting the answers is as simple as using the intersection, subtract, and union functions of the gb_sets library. The only trick is that the complement is the equivalent of a subtract from the sample space S.

  47. % 1:
  48. gb_sets:intersection([A, B, C]).

  49. % 2:
  50. gb_sets:intersection(B, gb_sets:subtract(S, C)).

  51. % 3:
  52. gb_sets:union([A, B, C]).

  53. % 4:
  54. gb_sets:intersection(A, gb_sets:union(B, C)).

  55. % 5:
  56. gb_sets:subtract(S, gb_sets:intersection([A, B, C])).
  57. The last answer uses De Morgan's laws, specifically that (A ∪ B)c = Ac ∩ Bc.
復制代碼

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設計版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設計版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設計版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
2 [報告]
發(fā)表于 2015-01-05 23:43 |只看該作者
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP