2009 Aug 30 23:53:37 -*- inimino got up to 3.62 2009 Aug 30 23:56:46 solid 2009 Aug 30 23:56:50 -*- aamar got up to 3.66 2009 Aug 30 23:57:16 ah 2009 Aug 31 00:00:52 mariorz: you around? 2009 Aug 31 00:04:48 perhaps not 2009 Aug 31 00:05:46 looks like no 2009 Aug 31 00:06:03 alright, should we start? 2009 Aug 31 00:06:07 yes, let's 2009 Aug 31 00:06:19 ok 2009 Aug 31 00:06:24 3.47 2009 Aug 31 00:06:32 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.47 2009 Aug 31 00:07:01 Actually of the time I spent these two weeks, most of it was on 3.47 and 3.60 2009 Aug 31 00:07:05 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L914-953 2009 Aug 31 00:10:03 wow 2009 Aug 31 00:10:48 I don't think my solution to (a) is a good one. 2009 Aug 31 00:10:53 these look similar, I notice in a) we took the mutex in different places 2009 Aug 31 00:11:12 I think yours makes much more sense. 2009 Aug 31 00:11:31 Basically have one mutex control the semaphore itself, and keep a counter. 2009 Aug 31 00:11:48 and you have additional mutexes inside 2009 Aug 31 00:11:57 The problem asked for "mutexes" which I thought meant that there was some reasonably good solution involving a list of mutexes. 2009 Aug 31 00:12:13 ah 2009 Aug 31 00:12:16 Yeah, but they're useless, as far as I can tell. 2009 Aug 31 00:12:40 The counter seems far simpler and more effective. 2009 Aug 31 00:14:06 looks like yours would work 2009 Aug 31 00:14:12 I think it would. 2009 Aug 31 00:14:21 For (b) we have pretty similar answers. 2009 Aug 31 00:15:47 I'm still reading yours 2009 Aug 31 00:15:52 3.48 ? 2009 Aug 31 00:16:03 ok 2009 Aug 31 00:16:09 I see we loop in a different place in acquire-one/acquire-first-free 2009 Aug 31 00:16:19 though it doesn't look like a significant difference 2009 Aug 31 00:17:27 hm, good point about release-one not being atomic 2009 Aug 31 00:17:48 yes, you have the loop in dispatch -- equivalent, I think 2009 Aug 31 00:18:01 the problem being that two calls to release-one at the same time might both 'free' the same cell 2009 Aug 31 00:18:22 right, right 2009 Aug 31 00:18:32 so the semaphore becomes gradually filled with dead entries 2009 Aug 31 00:18:44 hard to fix that without having some function that does the opposite of "test-and-set!" 2009 Aug 31 00:18:57 I guess the way to do that would be to store the number of the cell when you set it 2009 Aug 31 00:18:58 or using a mutex -- which seems to go against the spirit of the problem. 2009 Aug 31 00:19:28 yes 2009 Aug 31 00:19:53 hm -- how does that fix it? 2009 Aug 31 00:20:08 well, it doesn't quite fix it 2009 Aug 31 00:20:20 or does it 2009 Aug 31 00:20:40 I think it does 2009 Aug 31 00:20:52 say you have a counter in acquire-first-free 2009 Aug 31 00:21:21 you just store the index of the cell on which test-and-set! succeeded 2009 Aug 31 00:21:42 then when you release, you release that same cell, regardless of whatever other cells are free or not 2009 Aug 31 00:22:32 okay, but then you need to wrap a mutex around access to that cell-index and releasing that cell. 2009 Aug 31 00:22:45 so given that no other process can have successfully taken that same cell, the free operation will always have a unique effect 2009 Aug 31 00:23:18 serialize { retrieve cell-index, clear that cell, clear that cell-index } 2009 Aug 31 00:23:55 It works, but it suggests that the only correct solution that solves for that is to use test-and-set! like a mutex 2009 Aug 31 00:23:57 you already have the cell-index stored in a variable inside the semaphore 2009 Aug 31 00:24:16 that I know 2009 Aug 31 00:24:30 ok, so why do you need to serialize clearing it? 2009 Aug 31 00:24:39 I'm looking at the case where two processes attempt to 'release at the same time. 2009 Aug 31 00:24:49 nothing else could have gotten that same index until you do clear it 2009 Aug 31 00:24:53 You need to block for the case where both grab the same cell-index and release the same cell. 2009 Aug 31 00:25:22 so any two that are releasing will be releasing different cells, and I think there's no problem 2009 Aug 31 00:25:50 so if the code enters the-semaphore's dispatch, both calling 'release... 2009 Aug 31 00:25:57 at most n processes will have taken the semaphore at any time, and at each one will have a unique cell-index stored in its local state 2009 Aug 31 00:26:10 oh I see 2009 Aug 31 00:26:16 between 0 and n-1 2009 Aug 31 00:26:17 but 2009 Aug 31 00:26:31 then you're creating local state per-each process 2009 Aug 31 00:26:41 so then each one enters 'release, each one clears a different cell 2009 Aug 31 00:26:48 each process needs to remember which index it's pointing to -- how do you store that per the process? 2009 Aug 31 00:27:16 oh you're right, we didn't have that previously 2009 Aug 31 00:27:47 you could pass something like a process id to the 'acquire call, and require it to be passed back when you run 'release. 2009 Aug 31 00:27:54 it's have to pass back a token in 'acquire and then provide that token when calling ... yeah 2009 Aug 31 00:28:07 something like that 2009 Aug 31 00:28:09 ok 2009 Aug 31 00:28:12 I think it works. 2009 Aug 31 00:28:39 This guy wrote (b) very much like your (a) solution, but essentially replicated mutex-like functionality with test-and-set! 2009 Aug 31 00:28:40 http://eli.thegreenplace.net/2007/10/26/sicp-334/ 2009 Aug 31 00:29:25 (I only look at online help on SICP during/after these meetings, btw :)) 2009 Aug 31 00:30:19 ah yeah 2009 Aug 31 00:31:03 that seems like a more correct solution than mine 2009 Aug 31 00:31:09 to (b) 2009 Aug 31 00:31:52 he just kind of inlined the test-and-set! mutex implementation into (a) 2009 Aug 31 00:32:27 yes 2009 Aug 31 00:32:47 alright, I think we've killed this one, next? 2009 Aug 31 00:33:46 yes, let's go 2009 Aug 31 00:34:02 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L956-993 2009 Aug 31 00:34:59 ok 2009 Aug 31 00:35:06 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.48 2009 Aug 31 00:37:13 these look similar 2009 Aug 31 00:37:42 ha, yes, very -- I should have factored out the "let" -- then they would be the same, looks like. 2009 Aug 31 00:37:58 yeah 2009 Aug 31 00:38:15 alright, next one? 2009 Aug 31 00:38:19 yes 2009 Aug 31 00:38:20 3.49 2009 Aug 31 00:38:21 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L995-1004 2009 Aug 31 00:38:45 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.49 2009 Aug 31 00:38:59 This one was a bit useless, because the hint is basically the answer. 2009 Aug 31 00:39:40 yeah, exactly 2009 Aug 31 00:39:50 alright, moving on 2009 Aug 31 00:40:09 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.50 2009 Aug 31 00:40:15 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1007-1015 2009 Aug 31 00:40:28 exactly the same 2009 Aug 31 00:40:43 indeed 2009 Aug 31 00:41:00 this streams section was fun 2009 Aug 31 00:41:14 Yeah, completely agree. 2009 Aug 31 00:41:17 and I was glad to be out of 3.4 2009 Aug 31 00:41:49 3.51? 2009 Aug 31 00:42:01 That's what they want! They want you to hate program state! 2009 Aug 31 00:42:13 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1016-1020 2009 Aug 31 00:42:16 hehe, yeah 2009 Aug 31 00:42:52 -*- inimino is a puppet, reaches up and feels strings 2009 Aug 31 00:42:58 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.51 2009 Aug 31 00:43:06 ha 2009 Aug 31 00:43:21 oh, forgot to include the actual return value of these calls 2009 Aug 31 00:43:48 hehe 2009 Aug 31 00:44:13 well, 3.52? 2009 Aug 31 00:44:26 yes 2009 Aug 31 00:44:26 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1021-1042 2009 Aug 31 00:45:51 same, except for the display-stream output 2009 Aug 31 00:46:02 whoops, looks like I display-streamed the wrong thing 2009 Aug 31 00:46:06 oh well 2009 Aug 31 00:46:34 3.53: http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.53 2009 Aug 31 00:46:42 looks like these are the same as well... 2009 Aug 31 00:47:08 and 3.54... 2009 Aug 31 00:47:15 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.54 2009 Aug 31 00:48:07 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1021-1042 2009 Aug 31 00:48:27 wow! 2009 Aug 31 00:49:00 oh, no -- they're the same 2009 Aug 31 00:49:06 got confused there for a minute 2009 Aug 31 00:49:08 3.55 ? 2009 Aug 31 00:49:18 looks like we put the arguments in different order 2009 Aug 31 00:49:19 sure 2009 Aug 31 00:49:23 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1055-1060 2009 Aug 31 00:49:30 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.55 2009 Aug 31 00:51:09 ah 2009 Aug 31 00:51:38 I think there may be a difference in efficiency 2009 Aug 31 00:52:38 in your (add-streams (partial-sums s) (stream-cdr s)) 2009 Aug 31 00:53:24 (partial-sums s) will need to be recalculated 2009 Aug 31 00:53:54 interesting 2009 Aug 31 00:54:01 I see that, agreed. 2009 Aug 31 00:54:32 okay, see how your solution avoids that. 2009 Aug 31 00:54:34 Cool. 2009 Aug 31 00:54:41 ok, next one? 2009 Aug 31 00:55:47 ok 2009 Aug 31 00:56:02 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1062-1088 2009 Aug 31 00:56:05 this one had a very long question and very short answer... 2009 Aug 31 00:56:08 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.56 2009 Aug 31 00:56:40 yes 2009 Aug 31 00:57:04 and the same answer :) 2009 Aug 31 00:57:25 I thought that this answer would be wrong, since it was so simple... but testing it made it look right. 2009 Aug 31 00:57:27 cool 2009 Aug 31 00:57:28 nice problem, too, I thought 2009 Aug 31 00:57:45 3.57 ? 2009 Aug 31 00:57:45 3.57? 2009 Aug 31 00:57:47 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1090-1092 2009 Aug 31 00:57:59 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.57 2009 Aug 31 00:58:23 same answer 2009 Aug 31 00:58:36 yep 2009 Aug 31 00:58:51 alright, 3.58? 2009 Aug 31 00:59:05 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.58 2009 Aug 31 00:59:09 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1094-1099 2009 Aug 31 00:59:38 liked that one, though it wasn't very hard 2009 Aug 31 00:59:51 yeah, me too 2009 Aug 31 01:00:18 3.59 ? 2009 Aug 31 01:00:22 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1108-1123 2009 Aug 31 01:00:26 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.59 2009 Aug 31 01:01:00 whoo stream-map and integers 2009 Aug 31 01:01:05 nice solution 2009 Aug 31 01:01:27 mine is a bit ... kludgy 2009 Aug 31 01:01:37 thanks 2009 Aug 31 01:02:04 looks right, though 2009 Aug 31 01:02:40 also, scale-stream in (b) which I forgot all about until a later exercises 2009 Aug 31 01:03:16 same here, though I went back and changed it 2009 Aug 31 01:03:19 yeah, these all look right 2009 Aug 31 01:03:25 yes, looks good 2009 Aug 31 01:03:29 ah :) 2009 Aug 31 01:03:39 3.60 was a tough one for me 2009 Aug 31 01:03:41 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1108-1123 2009 Aug 31 01:04:07 oh yes, this one 2009 Aug 31 01:04:14 this one took most of the time for me too 2009 Aug 31 01:04:38 glad it wasn't just me 2009 Aug 31 01:04:39 :) 2009 Aug 31 01:04:58 same solution though 2009 Aug 31 01:05:05 Yes 2009 Aug 31 01:05:07 yeah, I found it quite hard 2009 Aug 31 01:05:27 It just wasn't intuitive to have one branch be recursive, the other simply be a scale-stream 2009 Aug 31 01:05:34 had to take a several breaks and go look up power series on Wikipedia, which didn't really help that much 2009 Aug 31 01:05:41 yeah 2009 Aug 31 01:06:24 originally I had something symmetrical and completely wrong 2009 Aug 31 01:06:39 basically mul-series in both branches? 2009 Aug 31 01:06:50 It looks right at first, but quickly introduces too many terms. 2009 Aug 31 01:06:55 scale-series in both 2009 Aug 31 01:07:03 Ok 2009 Aug 31 01:07:16 after I called it done and was working on the next problem I realized it had far too few terms ;) 2009 Aug 31 01:07:24 right, similar problem 2009 Aug 31 01:07:34 yeah 2009 Aug 31 01:07:58 ok, should we go to 3.61 ? 2009 Aug 31 01:08:06 ok, sure 2009 Aug 31 01:08:14 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1148-1154 2009 Aug 31 01:08:15 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.61 2009 Aug 31 01:09:33 forgot to make it efficient again 2009 Aug 31 01:09:41 similar answers, yeah 2009 Aug 31 01:10:04 that and the order of calls are the only differences I see 2009 Aug 31 01:11:29 looks otherwise the same, right 2009 Aug 31 01:11:34 and 3.62 ? 2009 Aug 31 01:11:49 http://inimino.org/~inimino/projects/2009/SICP/chap_3/3.62 2009 Aug 31 01:11:58 this is the last one I finished 2009 Aug 31 01:12:08 http://github.com/aalearn/aalearn-sicp/blob/668d7df57a8c542709dbcc920630a64ad4c6decd/ch3-outline.scm#L1156-1166 2009 Aug 31 01:13:45 I think I wrote "scale-series" where I mean "scale-stream" 2009 Aug 31 01:14:08 but we could have defined a scale-series to be the same, I guess 2009 Aug 31 01:15:10 hm, I think I put the scale in the wrong place too 2009 Aug 31 01:15:11 right, ok 2009 Aug 31 01:15:27 I think yours will work too, though... still looking 2009 Aug 31 01:16:23 I think my (/ 1 scale) should actually just be (scale) to cancel out properly 2009 Aug 31 01:16:37 or rather, it should be (/ 1 scale) in both places 2009 Aug 31 01:16:59 or better yet it should be defined as the reciprocal in the first place 2009 Aug 31 01:17:15 just tested your code and it gives the same answer as mine 2009 Aug 31 01:17:40 hm 2009 Aug 31 01:17:52 we both are scaling s2 by 1/(stream-car s2) 2009 Aug 31 01:17:55 and then inverting 2009 Aug 31 01:18:07 and then multiplying by s1 2009 Aug 31 01:19:26 oh 2009 Aug 31 01:19:30 did your test have a fractional first term in the divisor? 2009 Aug 31 01:19:31 my test is a bad one 2009 Aug 31 01:19:31 ! 2009 Aug 31 01:20:25 no, that is the problem 2009 Aug 31 01:21:01 :) 2009 Aug 31 01:21:11 so I think your code is correct 2009 Aug 31 01:21:16 and mine has the error 2009 Aug 31 01:21:43 ok 2009 Aug 31 01:22:23 (define (div-series s1 s2) 2009 Aug 31 01:22:23 (if (eq? (stream-car s2) 0) 2009 Aug 31 01:22:23 (error "zero constant term in denominator") 2009 Aug 31 01:22:23 (let ((scale (/ 1 (stream-car s2)))) 2009 Aug 31 01:22:23 (mul-series (scale-series s1 scale) 2009 Aug 31 01:22:23 (invert-unit-series (scale-series s2 scale)))))) 2009 Aug 31 01:22:29 I think that's corrected 2009 Aug 31 01:23:47 This should produce tangent, correct? 2009 Aug 31 01:23:48 (div-series (scale-stream sine-series 1/5) (scale-stream cosine-series 1/5)) 2009 Aug 31 01:24:13 (sin/5)/(cos/5) ? 2009 Aug 31 01:24:52 why the 1/5? 2009 Aug 31 01:25:19 just so it's a better test of the scaling factor 2009 Aug 31 01:25:26 oh 2009 Aug 31 01:25:34 -*- inimino has a short attention span 2009 Aug 31 01:25:38 ok, just checked it. 2009 Aug 31 01:25:56 checked the new code you just put in here, it does give the right power series for tan 2009 Aug 31 01:26:02 yeah it should produce tan 2009 Aug 31 01:26:09 ok, good 2009 Aug 31 01:26:53 alright, I guess that's all for today since that's as far as I got 2009 Aug 31 01:27:01 what should we aim for next time? 2009 Aug 31 01:27:37 Well, I only got a little further, but the next few were fairly quick 2009 Aug 31 01:28:04 20 exercises would get us to the end of chapter 3 2009 Aug 31 01:28:29 we got through 16 this time, so that's pretty aggressive if there are some tough ones ahead 2009 Aug 31 01:28:43 3.76 ? 2009 Aug 31 01:28:57 true 2009 Aug 31 01:29:20 alright, 3.76 sounds good 2009 Aug 31 01:29:27 great 2009 Aug 31 01:29:54 -*- inimino really should learn to spread the work over more days ;-) 2009 Aug 31 01:30:04 same here! 2009 Aug 31 01:30:12 heh 2009 Aug 31 01:30:53 alright, so Sept 13, 3.63 - 3.76 2009 Aug 31 01:36:09 see you next time :) 2009 Aug 31 01:36:17 see you!