1 00:00:00,190 --> 00:00:06,589 okay let's finish our derivation of the condom problem we started Oct 2 00:00:06,589 --> 00:00:09,840 leads a very simple brewed for solution 3 00:00:09,840 --> 00:00:13,830 then and the second step we took 4 00:00:13,830 --> 00:00:18,130 an the generation process and we made sure that we 5 00:00:18,130 --> 00:00:21,369 never generates expressions that were invalid 6 00:00:21,369 --> 00:00:25,230 and what we're going to do in this third step is we're going to 7 00:00:25,230 --> 00:00:29,869 shrink the search space by and leveraging 8 00:00:29,869 --> 00:00:33,280 a algebraic properties of expression in particular 9 00:00:33,280 --> 00:00:36,800 the fact that multiplication is committed F 10 00:00:36,800 --> 00:00:41,030 and the fact that Wong is the new char element 11 00:00:41,030 --> 00:00:44,500 for multiplication game saw 12 00:00:44,500 --> 00:00:48,129 these are the property we're going to use multiplication 13 00:00:48,129 --> 00:00:52,870 is commuted F and and 14 00:00:52,870 --> 00:00:56,000 Wong is the new char element for 15 00:00:56,000 --> 00:00:59,510 multiplication alright 16 00:00:59,510 --> 00:01:04,390 sure here's the I am previous definition of whether an 17 00:01:04,390 --> 00:01:07,890 expression was valid and every member 18 00:01:07,890 --> 00:01:11,750 an expression was valid when the 19 00:01:11,750 --> 00:01:15,130 numbers %uh which it was composure your boss in Excel 20 00:01:15,130 --> 00:01:18,170 when we added to an 21 00:01:18,170 --> 00:01:22,640 values well thats now let's because adding to positive numbers is 22 00:01:22,640 --> 00:01:26,369 get a positive number when we subtract two numbers 23 00:01:26,369 --> 00:01:30,310 the result is positive when the first number is larger than the second 24 00:01:30,310 --> 00:01:35,220 multiplication of two numbers positive numbers is always positive 25 00:01:35,220 --> 00:01:38,329 and here we had to make sure that 26 00:01:38,329 --> 00:01:41,829 we I'm remains within the integer domain 27 00:01:41,829 --> 00:01:47,290 well in this case instead of just returning true 28 00:01:47,290 --> 00:01:52,159 well we do now is we say we want actually be less than why so we're going 29 00:01:52,159 --> 00:01:53,939 to make this thing biased so 30 00:01:53,939 --> 00:01:57,009 adding X to Y is valid 31 00:01:57,009 --> 00:02:02,070 if axes less than why and we were doing we're going to do the same 32 00:02:02,070 --> 00:02:05,829 for multiplication K and now 33 00:02:05,829 --> 00:02:09,530 am we also want to say that 34 00:02:09,530 --> 00:02:13,150 if the axe is Wong 35 00:02:13,150 --> 00:02:16,610 and we don't considered distinct sell it 36 00:02:16,610 --> 00:02:19,920 case you were drawing up on the way so what we're what we did 37 00:02:19,920 --> 00:02:24,780 is really biased the representation we say we always want the wall on the left 38 00:02:24,780 --> 00:02:28,569 to be larger than the right and by that we have lemon and 39 00:02:28,569 --> 00:02:32,700 eliminated ads y ax as a valid expression 40 00:02:32,700 --> 00:02:37,780 shit is funny clever trick so if action wired the same it's still that let 41 00:02:37,780 --> 00:02:41,690 but they've X is less than why that's very cool then why 42 00:02:41,690 --> 00:02:45,250 we have eliminated an the 43 00:02:45,250 --> 00:02:48,780 an committed if expression at YX 44 00:02:48,780 --> 00:02:52,920 good and then we also 45 00:02:52,920 --> 00:02:56,170 onto an used to gauge where 46 00:02:56,170 --> 00:03:00,769 X or why is wrong K so this takes into account 47 00:03:00,769 --> 00:03:05,360 the community devotee of multiplication and addition 48 00:03:05,360 --> 00:03:09,800 and the fact that an Wong is the neutral element 49 00:03:09,800 --> 00:03:13,450 of multiplication I'm and finally 50 00:03:13,450 --> 00:03:16,890 also when we and divide by Wong 51 00:03:16,890 --> 00:03:21,220 that's the same as X lemme 52 00:03:21,220 --> 00:03:25,590 applied is very simple an extension dude ass 53 00:03:25,590 --> 00:03:29,959 it as quite dramatic result so when we look at the solutions 54 00:03:29,959 --> 00:03:35,700 for this there's now only two hundred fifty dollars and valid expressions 55 00:03:35,700 --> 00:03:39,610 K so that's about twenty times less than before 56 00:03:39,610 --> 00:03:42,790 and and when we look at the solutions 57 00:03:42,790 --> 00:03:47,830 there are about sixteen time less because all the solutions that we had 58 00:03:47,830 --> 00:03:51,510 were duplicates of each other all the solution there were many duplicates 59 00:03:51,510 --> 00:03:55,030 and ocean oceans so when we run this now 60 00:03:55,030 --> 00:03:59,489 runs it finds the first solution 61 00:03:59,489 --> 00:04:05,129 and to understand the second but even more important 62 00:04:05,129 --> 00:04:08,860 it's fine all the solutions and under 63 00:04:08,860 --> 00:04:11,909 hot of a second so is she 64 00:04:11,909 --> 00:04:15,409 really all that 65 00:04:15,409 --> 00:04:19,130 and problems from this TV program 66 00:04:19,130 --> 00:04:23,160 are solved by then of a second 67 00:04:23,160 --> 00:04:27,139 and we started out with all solutions being about 68 00:04:27,139 --> 00:04:30,990 44 seconds over this is quite a dramatic improvement 69 00:04:30,990 --> 00:04:34,850 you see there was not that difficult we made to small steps 70 00:04:34,850 --> 00:04:39,300 starting with obviously correction ocean that was slow 71 00:04:39,300 --> 00:04:42,780 and MBB factor it to remain correct 72 00:04:42,780 --> 00:04:46,690 but become fast and this is the way 73 00:04:46,690 --> 00:04:50,120 and Haskell programmers like to work so 74 00:04:50,120 --> 00:04:54,250 start with something that's right and then you make it better 75 00:04:54,250 --> 00:04:57,470 great thank you so much happy hacking 76 00:04:57,470 --> 00:05:00,210 make sure you do your homework and then see you next week