https://blog.csdn.net/john_f_lau/article/details/55254324?utm_source=itdadao&utm_medium=referral
https://swtch.com/~rsc/thread/#2
https://www.cnblogs.com/foxmailed/p/3509359.html
https://www.zhihu.com/question/26192499
https://golang.org/test/chan/powser1.go
https://codegolf.stackexchange.com/questions/2403/implement-lazy-lists-preferably-in-a-language-you-dont-know-well
https://en.wikipedia.org/wiki/CAR_and_CDR
https://en.wikipedia.org/wiki/Cons
image.png
image.png
https://github.com/jessehzj/golang-playground/blob/master/powerSeries/powerSeries.go
1 / 24
------------seperate line---------------
split
1
1
1
1
1 / 2
1 / 2
1 / 6
1 / 6
1 / 24
1 / 24
Basic splitter
1
2
2
4 / 3
2 / 3
Optimized splitter
1
2
添加
image.png
image.png
image.png
两个ones相乘:
只加上F0 <- f的情况
加上
case <-wait:
.......
case f = <- F:
case F0 <-= f:
begin do_split_new(F, F0, F1, signal);
become do_split_mid(f, F1, wait, signal);
case F1 <-= f:
begin do_split_new(F, F1, F0, signal);
become do_solit_mid(f, F0, wait, signal);
image.png
split的问题:
image.png
一直卡着:证明在一直递归调用do_split_new
image.png
基本方法的进程数,可以看到大概是n^2
image.png
这个是没有疑问的
其他的差别不大,基本呈线性
下图是做了优化之后的,在250到370左右
image.png
下图是增加了demand channel之后的:大概在290~500之间,没有上面的好???
image.png
下面是官方版本的在230~240之间
image.png
https://stackoverflow.com/questions/29775836/no-op-explicitly-do-nothing-in-go
image.pnghttps://courses.cs.washington.edu/courses/cse341/08au/haskell/InfiniteDataStructures.txt
http://www.cs.cornell.edu/courses/cs3110/2011fa/supplemental/lec24-streams/streams.htm
http://crypto.stanford.edu/~blynn/c/haskell.html
这样是有bug的,我还是改回去吧。。。改成被注释掉的部分,goroutine数变最多了。。。WHY!!!
image.png
下一个任务是
image.png1.分清发信号和收信号的区别,不然死锁了
2.第二个错误
image.png
image.png
怎么越变越多了???
image.png
增加lazy evaluation以及把do_split_new改成下面那样取得最小的goroutine数(产生50个数时最大为261,一般为215):
image.png
power series 的Scala版本
https://www.cs.dartmouth.edu/~doug/powser.html
interesting things about exponetial:
因为积分后的第一项的计算不依赖于输入,所以不会死锁,用论文的话来说就是,Deadlock is avoided because the integral operator produces the first term of its output(the constant of integration )before it needs any input. This result gets fed onto stream X to help calculate the next term, and so on.
scala的lazy list天生有splitting和demand channel的特性,但是却没有memorization,有这个就更好了,
不对是有的吧,看multiplication的公式,
https://en.m.wikibooks.org/wiki/Haskell/Pattern_matching
https://stackoverflow.com/questions/36771251/lazy-evaluation-for-list-generating-functions
https://www.cs.dartmouth.edu/~doug/powser1.html
https://kseo.github.io/posts/2017-01-14-memoization-in-hasekll.html
http://okmij.org/ftp/ML/index.html
论文power series, power serious
https://www.scala-exercises.org/scala_tutorial/lazy_evaluation
https://stackoverflow.com/questions/8566532/scala-streams-and-their-memory-usage
网友评论