videos/02-algo2.srt
changeset 773 260e330f7466
parent 772 3bf3f5bb067e
equal deleted inserted replaced
772:3bf3f5bb067e 773:260e330f7466
   579 What would be the
   579 What would be the
   580 derivative of one?
   580 derivative of one?
   581 
   581 
   582 126
   582 126
   583 00:06:32,030 --> 00:06:36,140
   583 00:06:32,030 --> 00:06:36,140
   584 So the derivative of c of one.
   584 So the derivative of c of 1
   585 
   585 
   586 127
   586 127
   587 00:06:36,140 --> 00:06:38,990
   587 00:06:36,140 --> 00:06:38,990
   588 Peaches defined as 0.
   588 would be defined as 0.
   589 
   589 
   590 128
   590 128
   591 00:06:38,990 --> 00:06:41,465
   591 00:06:38,990 --> 00:06:41,465
   592 Okay, fair enough.
   592 Okay, fair enough.
   593 
   593 
   594 129
   594 129
   595 00:06:41,465 --> 00:06:44,960
   595 00:06:41,465 --> 00:06:44,960
   596 If he have any cross one,
   596 If he have n = 1,
   597 
   597 
   598 130
   598 130
   599 00:06:44,960 --> 00:06:48,125
   599 00:06:44,960 --> 00:06:48,125
   600 then we just have one copy
   600 then we just have one copy
   601 of this regular expression.
   601 of this regular expression.
   602 
   602 
   603 131
   603 131
   604 00:06:48,125 --> 00:06:50,120
   604 00:06:48,125 --> 00:06:50,120
   605 So there's not much as we can do.
   605 So there's not much else we can do.
   606 
   606 
   607 132
   607 132
   608 00:06:50,120 --> 00:06:53,735
   608 00:06:50,120 --> 00:06:53,735
   609 We would have to calculate
   609 We would have to calculate
   610 the derivative of air are.
   610 the derivative of r.
   611 
   611 
   612 133
   612 133
   613 00:06:53,735 --> 00:06:57,395
   613 00:06:53,735 --> 00:06:57,395
   614 Now in the n equals two case.
   614 Now in the n = 2 case,
   615 
   615 
   616 134
   616 134
   617 00:06:57,395 --> 00:07:00,245
   617 00:06:57,395 --> 00:07:00,245
   618 That would mean we
   618 that would mean we
   619 have two copies of
   619 have two copies of r.
   620 
   620 
   621 135
   621 135
   622 00:07:00,245 --> 00:07:03,425
   622 00:07:00,245 --> 00:07:03,425
   623 R. And they would be a sequence.
   623 And they would be a sequence.
   624 
   624 
   625 136
   625 136
   626 00:07:03,425 --> 00:07:07,775
   626 00:07:03,425 --> 00:07:07,775
   627 How would be the derivative C of
   627 How would be the derivative c of
   628 
   628 
   629 137
   629 137
   630 00:07:07,775 --> 00:07:10,340
   630 00:07:07,775 --> 00:07:10,340
   631 R four by R be
   631 r followed by r be
   632 
   632 
   633 138
   633 138
   634 00:07:10,340 --> 00:07:13,265
   634 00:07:10,340 --> 00:07:13,265
   635 defined where we would
   635 defined? Well we would
   636 look up the definition.
   636 look up the definition.
   637 
   637 
   638 139
   638 139
   639 00:07:13,265 --> 00:07:15,470
   639 00:07:13,265 --> 00:07:15,470
   640 And it would say that's
   640 And it would say that's
   641 the complicated case
   641 the complicated case,
   642 
   642 
   643 140
   643 140
   644 00:07:15,470 --> 00:07:16,760
   644 00:07:15,470 --> 00:07:16,760
   645 d sequence or
   645 the sequence.
   646 
   646 
   647 141
   647 141
   648 00:07:16,760 --> 00:07:21,875
   648 00:07:16,760 --> 00:07:21,875
   649 if null a bowl of R,
   649 If nullable of r,
   650 
   650 
   651 142
   651 142
   652 00:07:21,875 --> 00:07:25,250
   652 00:07:21,875 --> 00:07:25,250
   653 Then the most complicated case.
   653 then the more complicated case,
   654 
   654 
   655 143
   655 143
   656 00:07:25,250 --> 00:07:28,225
   656 00:07:25,250 --> 00:07:28,225
   657 Else, That's the easy
   657 else, that's the easy
   658 case that would be
   658 case, that would be
   659 
   659 
   660 144
   660 144
   661 00:07:28,225 --> 00:07:32,660
   661 00:07:28,225 --> 00:07:32,660
   662 derivative of c of R four
   662 derivative of c of r, followed
   663 
   663 
   664 145
   664 145
   665 00:07:32,660 --> 00:07:35,540
   665 00:07:32,660 --> 00:07:35,540
   666 by R. And then I
   666 by r. And then I just have to copy
   667 just have to copy
       
   668 
   667 
   669 146
   668 146
   670 00:07:35,540 --> 00:07:40,775
   669 00:07:35,540 --> 00:07:40,775
   671 that derivative of C
   670 that derivative of c
   672 of four by r here.
   671 of r followed by r here.
   673 
   672 
   674 147
   673 147
   675 00:07:40,775 --> 00:07:43,130
   674 00:07:40,775 --> 00:07:43,130
   676 But in this case I have also
   675 But in this case I have also
   677 
   676 
   680 the alternative derivative
   679 the alternative derivative
   681 of c of r. And from that,
   680 of c of r. And from that,
   682 
   681 
   683 149
   682 149
   684 00:07:51,145 --> 00:07:55,030
   683 00:07:51,145 --> 00:07:55,030
   685 it looks like we can
   684 it looks like we can't
   686 do much better than
   685 do much better than
   687 
   686 
   688 150
   687 150
   689 00:07:55,030 --> 00:07:58,390
   688 00:07:55,030 --> 00:07:58,390
   690 that unless we do
   689 that, unless we do
   691 
   690 
   692 151
   691 151
   693 00:07:58,390 --> 00:08:02,560
   692 00:07:58,390 --> 00:08:02,560
   694 a little bit of magic and the
   693 a little bit of magic and the
   695 magic to do with this case.
   694 magic has to do with this case.
   696 
   695 
   697 152
   696 152
   698 00:08:02,560 --> 00:08:07,420
   697 00:08:02,560 --> 00:08:07,420
   699 So let me look at this
   698 So let me look at this
   700 case a bit more closely.
   699 case a bit more closely.
   717 00:08:16,945 --> 00:08:18,550
   716 00:08:16,945 --> 00:08:18,550
   718 And this was defined as
   717 And this was defined as
   719 
   718 
   720 157
   719 157
   721 00:08:18,550 --> 00:08:20,680
   720 00:08:18,550 --> 00:08:20,680
   722 this sequence work
   721 this sequence regular
   723 expression R followed
   722 expression r followed by r.
   724 
   723 
   725 158
   724 158
   726 00:08:20,680 --> 00:08:23,080
   725 00:08:20,680 --> 00:08:23,080
   727 by r. And the question was,
   726 And the question was,
   728 
   727 
   729 159
   728 159
   730 00:08:23,080 --> 00:08:26,365
   729 00:08:23,080 --> 00:08:26,365
   731 can we somehow make sense
   730 can we somehow make sense
   732 out of this derivative
   731 out of this derivative
   736 where we have to build the
   735 where we have to build the
   737 derivative of a sequence.
   736 derivative of a sequence.
   738 
   737 
   739 161
   738 161
   740 00:08:30,370 --> 00:08:33,020
   739 00:08:30,370 --> 00:08:33,020
   741 So features the definition.
   740 So if we just unfold the definition,
   742 
   741 
   743 162
   742 162
   744 00:08:33,020 --> 00:08:36,050
   743 00:08:33,020 --> 00:08:36,050
   745 We would ask if
   744 we would ask if
   746 the r is nullable,
   745 the r is nullable,
   747 
   746 
   748 163
   747 163
   749 00:08:36,050 --> 00:08:39,095
   748 00:08:36,050 --> 00:08:39,095
   750 In this case, we return
   749 In this case, we return
   754 00:08:39,095 --> 00:08:40,640
   753 00:08:39,095 --> 00:08:40,640
   755 And if it's not nullable,
   754 And if it's not nullable,
   756 
   755 
   757 165
   756 165
   758 00:08:40,640 --> 00:08:44,135
   757 00:08:40,640 --> 00:08:44,135
   759 It is just this
   758 it is just this
   760 record expression.
   759 regular expression.
   761 
   760 
   762 166
   761 166
   763 00:08:44,135 --> 00:08:49,550
   762 00:08:44,135 --> 00:08:49,550
   764 Now my claim is that
   763 Now my claim is that
   765 this whole if condition
   764 this whole if condition
   792 decide in which branch we are.
   791 decide in which branch we are.
   793 
   792 
   794 173
   793 173
   795 00:09:08,330 --> 00:09:10,580
   794 00:09:08,330 --> 00:09:10,580
   796 We don't have to
   795 We don't have to
   797 calculate your now,
   796 calculate nullable,
   798 
   797 
   799 174
   798 174
   800 00:09:10,580 --> 00:09:13,880
   799 00:09:10,580 --> 00:09:13,880
   801 but we can just replace
   800 we can just replace
   802 it by this expression.
   801 it by this expression.
   803 
   802 
   804 175
   803 175
   805 00:09:13,880 --> 00:09:16,670
   804 00:09:13,880 --> 00:09:16,670
   806 So if we can
   805 So if we can
   807 substantiate that claim,
   806 substantiate that claim,
   808 
   807 
   809 176
   808 176
   810 00:09:16,670 --> 00:09:19,860
   809 00:09:16,670 --> 00:09:19,860
   811 that will be definitely
   810 that will be definitely
   812 good file algorithm.
   811 good our algorithm.
   813 
   812 
   814 177
   813 177
   815 00:09:20,140 --> 00:09:22,775
   814 00:09:20,140 --> 00:09:22,775
   816 And to substantiate that,
   815 And to substantiate that,
   817 
   816 
   821 record expression here.
   820 record expression here.
   822 
   821 
   823 179
   822 179
   824 00:09:26,795 --> 00:09:31,100
   823 00:09:26,795 --> 00:09:31,100
   825 And notice that this record
   824 And notice that this record
   826 expression the only be
   825 expression will only be
   827 
   826 
   828 180
   827 180
   829 00:09:31,100 --> 00:09:35,780
   828 00:09:31,100 --> 00:09:35,780
   830 called or only be generated
   829 called or only be generated
   831 if r is nullable.
   830 if r is nullable.
   834 00:09:35,780 --> 00:09:38,075
   833 00:09:35,780 --> 00:09:38,075
   835 So in any other case,
   834 So in any other case,
   836 
   835 
   837 182
   836 182
   838 00:09:38,075 --> 00:09:40,060
   837 00:09:38,075 --> 00:09:40,060
   839 I will actually not go into it
   838 I will actually not go into 
   840 
   839 
   841 183
   840 183
   842 00:09:40,060 --> 00:09:43,850
   841 00:09:40,060 --> 00:09:43,850
   843 that if branch and would
   842 that if branch and would
   844 be in the other one.
   843 be in the other one.
   848 So if we are in this if branch,
   847 So if we are in this if branch,
   849 
   848 
   850 185
   849 185
   851 00:09:45,260 --> 00:09:47,705
   850 00:09:45,260 --> 00:09:47,705
   852 we definitely know
   851 we definitely know
   853 that R is nullable.
   852 that r is nullable.
   854 
   853 
   855 186
   854 186
   856 00:09:47,705 --> 00:09:52,955
   855 00:09:47,705 --> 00:09:52,955
   857 Okay? Okay, so here's
   856 Okay, so here's
   858 our regular expression.
   857 our regular expression.
   859 
   858 
   860 187
   859 187
   861 00:09:52,955 --> 00:09:55,940
   860 00:09:52,955 --> 00:09:55,940
   862 And we know it's nullable.
   861 And we know it's nullable.
   879 Let's see what we can do.
   878 Let's see what we can do.
   880 
   879 
   881 192
   880 192
   882 00:10:05,945 --> 00:10:10,160
   881 00:10:05,945 --> 00:10:10,160
   883 So the first thing
   882 So the first thing
   884 actually is we multiplying
   883 actually is we're multiplying
   885 
   884 
   886 193
   885 193
   887 00:10:10,160 --> 00:10:16,595
   886 00:10:10,160 --> 00:10:16,595
   888 this right hand side of the
   887 this right hand side of the
   889 alternative is times one.
   888 alternative with times 1.
   890 
   889 
   891 194
   890 194
   892 00:10:16,595 --> 00:10:19,700
   891 00:10:16,595 --> 00:10:19,700
   893 We can do that
   892 We can do that
   894 because this does not
   893 because this does not
   895 
   894 
   896 195
   895 195
   897 00:10:19,700 --> 00:10:23,090
   896 00:10:19,700 --> 00:10:23,090
   898 change which strings this
   897 change which strings this
   899 work expression can match.
   898 regular expression can match.
   900 
   899 
   901 196
   900 196
   902 00:10:23,090 --> 00:10:25,685
   901 00:10:23,090 --> 00:10:25,685
   903 Remember we even had it
   902 Remember we even had it
   904 as a simplification row,
   903 as a simplification rule,
   905 
   904 
   906 197
   905 197
   907 00:10:25,685 --> 00:10:27,425
   906 00:10:25,685 --> 00:10:27,425
   908 just in this case B,
   907 just in this case we
   909 
   908 
   910 198
   909 198
   911 00:10:27,425 --> 00:10:29,705
   910 00:10:27,425 --> 00:10:29,705
   912 don't apply it as a
   911 don't apply it as a
   913 simplification will
   912 simplification rule,
   914 
   913 
   915 199
   914 199
   916 00:10:29,705 --> 00:10:31,310
   915 00:10:29,705 --> 00:10:31,310
   917 actually make this
   916 actually make this
   918 work expression
   917 regular expression
   919 
   918 
   920 200
   919 200
   921 00:10:31,310 --> 00:10:32,720
   920 00:10:31,310 --> 00:10:32,720
   922 a bit more complicated.
   921 a bit more complicated.
   923 
   922 
   924 201
   923 201
   925 00:10:32,720 --> 00:10:34,910
   924 00:10:32,720 --> 00:10:34,910
   926 But times one doesn't make
   925 But times 1 doesn't make
   927 
   926 
   928 202
   927 202
   929 00:10:34,910 --> 00:10:37,820
   928 00:10:34,910 --> 00:10:37,820
   930 a difference because it
   929 a difference because it
   931 means the end of the string,
   930 means at the end of a string,
   932 
   931 
   933 203
   932 203
   934 00:10:37,820 --> 00:10:40,070
   933 00:10:37,820 --> 00:10:40,070
   935 we still want to match
   934 we still want to match
   936 the empty string.
   935 the empty string.
   949 you will notice that this
   948 you will notice that this
   950 factor derivative of
   949 factor derivative of
   951 
   950 
   952 207
   951 207
   953 00:10:48,410 --> 00:10:51,860
   952 00:10:48,410 --> 00:10:51,860
   954 stuff are exactly the
   953 r are exactly the
   955 same as that one.
   954 same as that one.
   956 
   955 
   957 208
   956 208
   958 00:10:51,860 --> 00:10:54,650
   957 00:10:51,860 --> 00:10:54,650
   959 And in between is a plus.
   958 And in between is a plus.
   976 And I'm inside the parentheses
   975 And I'm inside the parentheses
   977 is left with that.
   976 is left with that.
   978 
   977 
   979 213
   978 213
   980 00:11:06,320 --> 00:11:09,245
   979 00:11:06,320 --> 00:11:09,245
   981 So now I have r plus one.
   980 So now I have r + 1.
   982 
   981 
   983 214
   982 214
   984 00:11:09,245 --> 00:11:13,055
   983 00:11:09,245 --> 00:11:13,055
   985 Usually we cannot
   984 Usually we cannot
   986 simplify r plus one.
   985 simplify r + 1.
   987 
   986 
   988 215
   987 215
   989 00:11:13,055 --> 00:11:15,530
   988 00:11:13,055 --> 00:11:15,530
   990 If it had been R
   989 If it had been r + 0, then yes,
   991 plus 0, then yes,
       
   992 
   990 
   993 216
   991 216
   994 00:11:15,530 --> 00:11:18,665
   992 00:11:15,530 --> 00:11:18,665
   995 we could have got rid of the CRO.
   993 we could have got rid of the 0.
   996 
   994 
   997 217
   995 217
   998 00:11:18,665 --> 00:11:21,590
   996 00:11:18,665 --> 00:11:21,590
   999 Plus one often
   997 But this + 1 often
  1000 makes a difference,
   998 makes a difference,
  1001 
   999 
  1002 218
  1000 218
  1003 00:11:21,590 --> 00:11:22,970
  1001 00:11:21,590 --> 00:11:22,970
  1004 but not in our case.
  1002 but not in our case.
  1005 
  1003 
  1006 219
  1004 219
  1007 00:11:22,970 --> 00:11:25,940
  1005 00:11:22,970 --> 00:11:25,940
  1008 Remember, we know that
  1006 Remember, we know that
  1009 this R is nullable,
  1007 this r is nullable,
  1010 
  1008 
  1011 220
  1009 220
  1012 00:11:25,940 --> 00:11:29,840
  1010 00:11:25,940 --> 00:11:29,840
  1013 so on its own can already
  1011 so on its own can already
  1014 match the empty string.
  1012 match the empty string.
  1026 00:11:35,300 --> 00:11:37,070
  1024 00:11:35,300 --> 00:11:37,070
  1027 Okay, and so now we have
  1025 Okay, and so now we have
  1028 
  1026 
  1029 224
  1027 224
  1030 00:11:37,070 --> 00:11:40,535
  1028 00:11:37,070 --> 00:11:40,535
  1031 a much simpler wound
  1029 a much simpler equivalent
  1032 reg expression.
  1030 regular expression.
  1033 
  1031 
  1034 225
  1032 225
  1035 00:11:40,535 --> 00:11:44,285
  1033 00:11:40,535 --> 00:11:44,285
  1036 And this actually helps a
  1034 And this actually helps a
  1037 lot for our if condition.
  1035 lot for our if-condition.
  1038 
  1036 
  1039 226
  1037 226
  1040 00:11:44,285 --> 00:11:46,925
  1038 00:11:44,285 --> 00:11:46,925
  1041 Look, this was the
  1039 Look, this was the
  1042 original if condition
  1040 original if-condition
  1043 
  1041 
  1044 227
  1042 227
  1045 00:11:46,925 --> 00:11:50,270
  1043 00:11:46,925 --> 00:11:50,270
  1046 and this is direct expression
  1044 and this is the regular expression
  1047 h. We just simplified.
  1045 we just simplified.
  1048 
  1046 
  1049 228
  1047 228
  1050 00:11:50,270 --> 00:11:53,105
  1048 00:11:50,270 --> 00:11:53,105
  1051 If we replace it with this one,
  1049 If we replace it with this one,
  1052 
  1050 
  1060 the if condition is actually
  1058 the if condition is actually
  1061 
  1059 
  1062 231
  1060 231
  1063 00:11:59,510 --> 00:12:02,750
  1061 00:11:59,510 --> 00:12:02,750
  1064 pointless because you
  1062 pointless because you
  1065 check if it's null above,
  1063 check if it's nullable,
  1066 
  1064 
  1067 232
  1065 232
  1068 00:12:02,750 --> 00:12:05,060
  1066 00:12:02,750 --> 00:12:05,060
  1069 we return this reg
  1067 we return this regular
  1070 expression or it's
  1068 expression or it's
  1071 
  1069 
  1072 233
  1070 233
  1073 00:12:05,060 --> 00:12:08,210
  1071 00:12:05,060 --> 00:12:08,210
  1074 not nullable and we
  1072 not nullable and we
  1101 So let's take stock
  1099 So let's take stock
  1102 what we have so far.
  1100 what we have so far.
  1103 
  1101 
  1104 240
  1102 240
  1105 00:12:24,170 --> 00:12:26,915
  1103 00:12:24,170 --> 00:12:26,915
  1106 So we know India CEO case,
  1104 So we know in the 0-case,
  1107 
  1105 
  1108 241
  1106 241
  1109 00:12:26,915 --> 00:12:30,920
  1107 00:12:26,915 --> 00:12:30,920
  1110 the derivative needs
  1108 the derivative needs
  1111 to be defined as 0.
  1109 to be defined as 0.
  1112 
  1110 
  1113 242
  1111 242
  1114 00:12:30,920 --> 00:12:33,095
  1112 00:12:30,920 --> 00:12:33,095
  1115 So because we define this
  1113 Because we define this
  1116 
  1114 
  1117 243
  1115 243
  1118 00:12:33,095 --> 00:12:36,785
  1116 00:12:33,095 --> 00:12:36,785
  1119 and times as one,
  1117 n-times as one,
  1120 the derivative is 0.
  1118 the derivative is 0.
  1121 
  1119 
  1122 244
  1120 244
  1123 00:12:36,785 --> 00:12:39,889
  1121 00:12:36,785 --> 00:12:39,889
  1124 For chest r, this will
  1122 For just r, this will
  1125 be the derivative.
  1123 be the derivative.
  1126 
  1124 
  1127 245
  1125 245
  1128 00:12:39,889 --> 00:12:42,170
  1126 00:12:39,889 --> 00:12:42,170
  1129 And we can't do any
  1127 And we can't do any
  1130 better than that
  1128 better than that.
  1131 
  1129 
  1132 246
  1130 246
  1133 00:12:42,170 --> 00:12:45,620
  1131 00:12:42,170 --> 00:12:45,620
  1134 for our followed by
  1132 For r followed by r, as we
  1135 RB just found out.
  1133 just found out
  1136 
  1134 
  1137 247
  1135 247
  1138 00:12:45,620 --> 00:12:47,270
  1136 00:12:45,620 --> 00:12:47,270
  1139 Actually it is quite simple.
  1137 actually it is quite simple
  1140 
  1138 
  1141 248
  1139 248
  1142 00:12:47,270 --> 00:12:51,410
  1140 00:12:47,270 --> 00:12:51,410
  1143 Reg expression is equivalent
  1141 regular expression is equivalent
  1144 to the derivative.
  1142 to the derivative.
  1145 
  1143 
  1146 249
  1144 249
  1147 00:12:51,410 --> 00:12:53,870
  1145 00:12:51,410 --> 00:12:53,870
  1148 Now, we have to continue with
  1146 Now, we have to continue with
  1156 00:12:56,090 --> 00:12:58,099
  1154 00:12:56,090 --> 00:12:58,099
  1157 now have three copies
  1155 now have three copies
  1158 
  1156 
  1159 252
  1157 252
  1160 00:12:58,099 --> 00:13:02,390
  1158 00:12:58,099 --> 00:13:02,390
  1161 of this or what should
  1159 of this r. What should
  1162 be the derivative?
  1160 be the derivative?
  1163 
  1161 
  1164 253
  1162 253
  1165 00:13:02,390 --> 00:13:05,330
  1163 00:13:02,390 --> 00:13:05,330
  1166 Well, if you look very carefully
  1164 Well, if you look very carefully
  1183 00:13:16,400 --> 00:13:18,275
  1181 00:13:16,400 --> 00:13:18,275
  1184 we end up with this.
  1182 we end up with this.
  1185 
  1183 
  1186 258
  1184 258
  1187 00:13:18,275 --> 00:13:21,290
  1185 00:13:18,275 --> 00:13:21,290
  1188 Because then what we have is.
  1186 Because then what we have is this.
  1189 
  1187 
  1190 259
  1188 259
  1191 00:13:21,290 --> 00:13:25,370
  1189 00:13:21,290 --> 00:13:25,370
  1192 We can define our
  1190 We can define our
  1193 nullable for n times
  1191 nullable for n-times
  1194 
  1192 
  1195 260
  1193 260
  1196 00:13:25,370 --> 00:13:31,025
  1194 00:13:25,370 --> 00:13:31,025
  1197 s. If any cross 0 then
  1195 as if n = 0 then
  1198 true as nullable.
  1196 true, else nullable r.
  1199 
  1197 
  1200 261
  1198 261
  1201 00:13:31,025 --> 00:13:33,875
  1199 00:13:31,025 --> 00:13:33,875
  1202 And for the derivative,
  1200 And for the derivative,
  1203 
  1201 
  1206 we can save if n is equal to 0,
  1204 we can save if n is equal to 0,
  1207 
  1205 
  1208 263
  1206 263
  1209 00:13:37,190 --> 00:13:40,235
  1207 00:13:37,190 --> 00:13:40,235
  1210 then we return the
  1208 then we return the
  1211 Sierra reg expression.
  1209 0 regular expression.
  1212 
  1210 
  1213 264
  1211 264
  1214 00:13:40,235 --> 00:13:43,295
  1212 00:13:40,235 --> 00:13:43,295
  1215 Otherwise, as you can see
  1213 Otherwise, as you can see
  1216 from this pattern here,
  1214 from this pattern here,
  1217 
  1215 
  1218 265
  1216 265
  1219 00:13:43,295 --> 00:13:50,735
  1217 00:13:43,295 --> 00:13:50,735
  1220 it would be derivative of
  1218 it would be derivative of
  1221 c r four by r n minus one.
  1219 c r followed by r{n-1}.
  1222 
  1220 
  1223 266
  1221 266
  1224 00:13:50,735 --> 00:13:54,770
  1222 00:13:50,735 --> 00:13:54,770
  1225 Okay? And the only
  1223 Okay? And the only
  1226 
  1224 
  1227 267
  1225 267
  1228 00:13:54,770 --> 00:13:56,330
  1226 00:13:54,770 --> 00:13:56,330
  1229 thing we have to make choice that
  1227 thing we have to make csure is that
  1230 
  1228 
  1231 268
  1229 268
  1232 00:13:56,330 --> 00:13:58,175
  1230 00:13:56,330 --> 00:13:58,175
  1233 this pattern actually holds.
  1231 this pattern actually holds.
  1234 
  1232 
  1241 00:14:00,470 --> 00:14:03,735
  1239 00:14:00,470 --> 00:14:03,735
  1242 the case for n equals three.
  1240 the case for n equals three.
  1243 
  1241 
  1244 271
  1242 271
  1245 00:14:03,735 --> 00:14:07,810
  1243 00:14:03,735 --> 00:14:07,810
  1246 If we have a wreck expression R
  1244 If we have a regular expression r
  1247 
  1245 
  1248 272
  1246 272
  1249 00:14:07,810 --> 00:14:09,820
  1247 00:14:07,810 --> 00:14:09,820
  1250 and it's followed
  1248 and it's followed
  1251 by r and another r,
  1249 by r and another r,
  1259 We can just unfold
  1257 We can just unfold
  1260 again the definition.
  1258 again the definition.
  1261 
  1259 
  1262 275
  1260 275
  1263 00:14:14,245 --> 00:14:16,930
  1261 00:14:14,245 --> 00:14:16,930
  1264 So we would ask if I is nullable,
  1262 So we would ask if r is nullable,
  1265 
  1263 
  1266 276
  1264 276
  1267 00:14:16,930 --> 00:14:19,765
  1265 00:14:16,930 --> 00:14:19,765
  1268 then we have this if branch.
  1266 then we have this if branch.
  1269 
  1267 
  1270 277
  1268 277
  1271 00:14:19,765 --> 00:14:23,905
  1269 00:14:19,765 --> 00:14:23,905
  1272 And if i is not nullable
  1270 And if r is not nullable,
  1273 or we have this as branch.
  1271 we have this else branch.
  1274 
  1272 
  1275 278
  1273 278
  1276 00:14:23,905 --> 00:14:27,010
  1274 00:14:23,905 --> 00:14:27,010
  1277 Okay? What can we do here?
  1275 Okay? What can we do here?
  1278 
  1276 
  1282 this one is just now
  1280 this one is just now
  1283 
  1281 
  1284 280
  1282 280
  1285 00:14:30,310 --> 00:14:34,510
  1283 00:14:30,310 --> 00:14:34,510
  1286 the derivative of two
  1284 the derivative of two
  1287 Rs, one after another.
  1285 r's, one after another.
  1288 
  1286 
  1289 281
  1287 281
  1290 00:14:34,510 --> 00:14:37,330
  1288 00:14:34,510 --> 00:14:37,330
  1291 But this we just
  1289 But this we just
  1292 calculated a moment ago,
  1290 calculated a moment ago,
  1315 So I can pull that
  1313 So I can pull that
  1316 out to be like that.
  1314 out to be like that.
  1317 
  1315 
  1318 287
  1316 287
  1319 00:14:52,700 --> 00:14:57,380
  1317 00:14:52,700 --> 00:14:57,380
  1320 And I have now followed
  1318 And I have now r followed
  1321 by R plus R. Oh,
  1319 by r plus r. 
  1322 
  1320 
  1323 288
  1321 288
  1324 00:14:57,380 --> 00:14:59,030
  1322 00:14:57,380 --> 00:14:59,030
  1325 hey, man, now you probably
  1323 But now you probably
  1326 
  1324 
  1327 289
  1325 289
  1328 00:14:59,030 --> 00:15:00,680
  1326 00:14:59,030 --> 00:15:00,680
  1329 remember how we did it earlier.
  1327 remember how we did it earlier.
  1330 
  1328 
  1356 in this reasoning.
  1354 in this reasoning.
  1357 
  1355 
  1358 296
  1356 296
  1359 00:15:18,995 --> 00:15:22,700
  1357 00:15:18,995 --> 00:15:22,700
  1360 We go in this if branch
  1358 We go in this if branch
  1361 only if r is nullable,
  1359 only if r is nullable.
  1362 
  1360 
  1363 297
  1361 297
  1364 00:15:22,700 --> 00:15:26,150
  1362 00:15:22,700 --> 00:15:26,150
  1365 so on its own can already
  1363 So r on its own can already
  1366 match the empty string.
  1364 match the empty string.
  1367 
  1365 
  1368 298
  1366 298
  1369 00:15:26,150 --> 00:15:28,895
  1367 00:15:26,150 --> 00:15:28,895
  1370 So I don't need
  1368 So I don't need
  1375 I can just get rid of it.
  1373 I can just get rid of it.
  1376 
  1374 
  1377 300
  1375 300
  1378 00:15:30,695 --> 00:15:33,140
  1376 00:15:30,695 --> 00:15:33,140
  1379 And so I now just have
  1377 And so I now just have
  1380 to rearrange the parent,
  1378 to rearrange the parentheses
  1381 
  1379 
  1382 301
  1380 301
  1383 00:15:33,140 --> 00:15:35,450
  1381 00:15:33,140 --> 00:15:35,450
  1384 the thesis which we
  1382 which we said we can also do.
  1385 said we can also do.
       
  1386 
  1383 
  1387 302
  1384 302
  1388 00:15:35,450 --> 00:15:37,595
  1385 00:15:35,450 --> 00:15:37,595
  1389 So we have something like that.
  1386 So we have something like that.
  1390 
  1387 
  1393 And here again, the
  1390 And here again, the
  1394 same reasoning,
  1391 same reasoning,
  1395 
  1392 
  1396 304
  1393 304
  1397 00:15:39,740 --> 00:15:41,975
  1394 00:15:39,740 --> 00:15:41,975
  1398 we have a if condition
  1395 we have an if condition
  1399 
  1396 
  1400 305
  1397 305
  1401 00:15:41,975 --> 00:15:43,310
  1398 00:15:41,975 --> 00:15:43,310
  1402 where it doesn't
  1399 where it doesn't
  1403 really matter what
  1400 really matter what
  1420 And yes, now we can be
  1417 And yes, now we can be
  1421 pretty sure they'll
  1418 pretty sure they'll
  1422 
  1419 
  1423 310
  1420 310
  1424 00:15:51,920 --> 00:15:55,310
  1421 00:15:51,920 --> 00:15:55,310
  1425 work for all the n times
  1422 work for all the n-times
  1426 regular expressions.
  1423 regular expressions.
  1427 
  1424 
  1428 311
  1425 311
  1429 00:15:55,310 --> 00:15:57,860
  1426 00:15:55,310 --> 00:15:57,860
  1430 And leave that to
  1427 And I leave 
  1431 the calculation for
  1428 the calculation for
  1432 
  1429 
  1433 312
  1430 312
  1434 00:15:57,860 --> 00:16:02,570
  1431 00:15:57,860 --> 00:16:02,570
  1435 maybe R to the four to you.
  1432 maybe r to the four to you.
  1436 
  1433 
  1437 313
  1434 313
  1438 00:16:02,570 --> 00:16:04,490
  1435 00:16:02,570 --> 00:16:04,490
  1439 And the reason why I do it
  1436 And the reason why I do it
  1440 
  1437 
  1458 I'm now back in our
  1455 I'm now back in our
  1459 implementation.
  1456 implementation.
  1460 
  1457 
  1461 318
  1458 318
  1462 00:16:16,250 --> 00:16:20,660
  1459 00:16:16,250 --> 00:16:20,660
  1463 In this Reto, said We have
  1460 In this re2.sc, we said we have
  1464 this explicit constructor now
  1461 this explicit constructor 
  1465 
  1462 
  1466 319
  1463 319
  1467 00:16:20,660 --> 00:16:25,535
  1464 00:16:20,660 --> 00:16:25,535
  1468 for n times b can now fill
  1465 for n-times. We can now fill
  1469 in the cases for nullable.
  1466 in the cases for nullable.
  1470 
  1467 
  1471 320
  1468 320
  1472 00:16:25,535 --> 00:16:27,635
  1469 00:16:25,535 --> 00:16:27,635
  1473 So if we have R in times,
  1470 So if we have r n-times,
  1474 
  1471 
  1475 321
  1472 321
  1476 00:16:27,635 --> 00:16:30,995
  1473 00:16:27,635 --> 00:16:30,995
  1477 if this n is equal to
  1474 if this n is equal to
  1478 0, we return true.
  1475 0, we return true.
  1479 
  1476 
  1480 322
  1477 322
  1481 00:16:30,995 --> 00:16:34,190
  1478 00:16:30,995 --> 00:16:34,190
  1482 Otherwise we have to test
  1479 Otherwise we have to test
  1483 whether eyes nullable.
  1480 whether r is nullable.
  1484 
  1481 
  1485 323
  1482 323
  1486 00:16:34,190 --> 00:16:37,565
  1483 00:16:34,190 --> 00:16:37,565
  1487 And in the derivative case, oi,
  1484 And in the derivative case, 
  1488 
  1485 
  1489 324
  1486 324
  1490 00:16:37,565 --> 00:16:40,339
  1487 00:16:37,565 --> 00:16:40,339
  1491 if this n is equal to 0,
  1488 if this n is equal to 0,
  1492 
  1489 
  1493 325
  1490 325
  1494 00:16:40,339 --> 00:16:43,564
  1491 00:16:40,339 --> 00:16:43,564
  1495 the return this 0
  1492 the return this 0
  1496 wreck expression.
  1493 regular expression.
  1497 
  1494 
  1498 326
  1495 326
  1499 00:16:43,564 --> 00:16:46,700
  1496 00:16:43,564 --> 00:16:46,700
  1500 Otherwise we return the
  1497 Otherwise we return the
  1501 sequence of the derivative
  1498 sequence of the derivative
  1502 
  1499 
  1503 327
  1500 327
  1504 00:16:46,700 --> 00:16:50,270
  1501 00:16:46,700 --> 00:16:50,270
  1505 of psi of r four by n times of r,
  1502 of c of r followed by n times of r,
  1506 
  1503 
  1507 328
  1504 328
  1508 00:16:50,270 --> 00:16:54,545
  1505 00:16:50,270 --> 00:16:54,545
  1509 but n minus one times and
  1506 but n minus one times, and
  1510 everything else stays the same.
  1507 everything else stays the same.
  1511 
  1508 
  1512 329
  1509 329
  1513 00:16:54,545 --> 00:16:56,510
  1510 00:16:54,545 --> 00:16:56,510
  1514 Here's the function for strings,
  1511 Here's the function for strings,
  1517 00:16:56,510 --> 00:16:58,430
  1514 00:16:56,510 --> 00:16:58,430
  1518 derivative function for strings.
  1515 derivative function for strings.
  1519 
  1516 
  1520 331
  1517 331
  1521 00:16:58,430 --> 00:17:01,595
  1518 00:16:58,430 --> 00:17:01,595
  1522 In the main mantra
  1519 In the main matcher
  1523 function as all the same.
  1520 function is all the same.
  1524 
  1521 
  1525 332
  1522 332
  1526 00:17:01,595 --> 00:17:04,820
  1523 00:17:01,595 --> 00:17:04,820
  1527 We still require this
  1524 We still require this
  1528 definition because
  1525 definition because
  1531 00:17:04,820 --> 00:17:06,050
  1528 00:17:04,820 --> 00:17:06,050
  1532 we haven't done anything about
  1529 we haven't done anything about
  1533 
  1530 
  1534 334
  1531 334
  1535 00:17:06,050 --> 00:17:08,090
  1532 00:17:06,050 --> 00:17:08,090
  1536 the optional record
  1533 the optional regular
  1537 expression yet.
  1534 expression yet.
  1538 
  1535 
  1539 335
  1536 335
  1540 00:17:08,090 --> 00:17:10,670
  1537 00:17:08,090 --> 00:17:10,670
  1541 And we have now at this
  1538 And we have now this
  1542 
  1539 
  1543 336
  1540 336
  1544 00:17:10,670 --> 00:17:13,250
  1541 00:17:10,670 --> 00:17:13,250
  1545 either warm and evil
  1542 EVIL1 and EVIL2
  1546 2-break expression.
  1543 regular expression.
  1547 
  1544 
  1548 337
  1545 337
  1549 00:17:13,250 --> 00:17:15,290
  1546 00:17:13,250 --> 00:17:15,290
  1550 And let's test it. And let's be
  1547 And let's test it. And let's be
  1551 
  1548 
  1552 338
  1549 338
  1553 00:17:15,290 --> 00:17:17,000
  1550 00:17:15,290 --> 00:17:17,000
  1554 a bit more ambitious.
  1551 a bit more ambitious.
  1555 Be testing it.
  1552 We're testing it with
  1556 
  1553 
  1557 339
  1554 339
  1558 00:17:17,000 --> 00:17:20,315
  1555 00:17:17,000 --> 00:17:20,315
  1559 The strings between 01000
  1556 strings between 0 and 1000
  1560 
  1557 
  1561 340
  1558 340
  1562 00:17:20,315 --> 00:17:22,580
  1559 00:17:20,315 --> 00:17:22,580
  1563 and let's see what the time say.
  1560 and let's see what the time say.
  1564 
  1561 
  1565 341
  1562 341
  1566 00:17:22,580 --> 00:17:26,210
  1563 00:17:22,580 --> 00:17:26,210
  1567 I'm testing this again
  1564 I'm testing this again
  1568 inside the ammonite rebel.
  1565 inside the Ammonite REPL.
  1569 
  1566 
  1570 342
  1567 342
  1571 00:17:26,210 --> 00:17:30,180
  1568 00:17:26,210 --> 00:17:30,180
  1572 And you'll see it should
  1569 And you'll see it should
  1573 be now much quicker.
  1570 be now much quicker.
  1578 down also around 600.
  1575 down also around 600.
  1579 
  1576 
  1580 344
  1577 344
  1581 00:17:34,640 --> 00:17:40,490
  1578 00:17:34,640 --> 00:17:40,490
  1582 700 needs two seconds,
  1579 700 needs two seconds,
  1583 three seconds, 4800.
  1580 three seconds for 800.
  1584 
  1581 
  1585 345
  1582 345
  1586 00:17:40,490 --> 00:17:43,940
  1583 00:17:40,490 --> 00:17:43,940
  1587 Let's see about it
  1584 Let's see what it
  1588 needs 4 thousand.
  1585 needs for one thousand?
  1589 
  1586 
  1590 346
  1587 346
  1591 00:17:43,940 --> 00:17:47,435
  1588 00:17:43,940 --> 00:17:47,435
  1592 But you have to remember
  1589 But you have to remember
  1593 Ruby and Python.
  1590 Ruby and Python
  1594 
  1591 
  1595 347
  1592 347
  1596 00:17:47,435 --> 00:17:51,530
  1593 00:17:47,435 --> 00:17:51,530
  1597 They needed half a
  1594 needed half a
  1598 minute to just 43 TAs.
  1595 minute for just 30 a's.
  1599 
  1596 
  1600 348
  1597 348
  1601 00:17:51,530 --> 00:17:54,485
  1598 00:17:51,530 --> 00:17:54,485
  1602 We need a little bit
  1599 We need a little bit
  1603 more than six seconds,
  1600 more than six seconds,
  1606 00:17:54,485 --> 00:17:57,110
  1603 00:17:54,485 --> 00:17:57,110
  1607 but we are processing a string of
  1604 but we are processing a string of
  1608 
  1605 
  1609 350
  1606 350
  1610 00:17:57,110 --> 00:18:00,575
  1607 00:17:57,110 --> 00:18:00,575
  1611 1000 days so that success.
  1608 1000 a's. So that success.
  1612 
  1609 
  1613 351
  1610 351
  1614 00:18:00,575 --> 00:18:04,775
  1611 00:18:00,575 --> 00:18:04,775
  1615 So this speed is also explained
  1612 This speed is also explained
  1616 if you look at the sizes.
  1613 if you look at the sizes.
  1617 
  1614 
  1618 352
  1615 352
  1619 00:18:04,775 --> 00:18:08,975
  1616 00:18:04,775 --> 00:18:08,975
  1620 Since we now have this explicit
  1617 Since we now have this explicit
  1621 and times constructor,
  1618 n-times constructor,
  1622 
  1619 
  1623 353
  1620 353
  1624 00:18:08,975 --> 00:18:11,930
  1621 00:18:08,975 --> 00:18:11,930
  1625 it doesn't really matter
  1622 it doesn't really matter
  1626 how big this n is.
  1623 how big this n is.
  1627 
  1624 
  1628 354
  1625 354
  1629 00:18:11,930 --> 00:18:14,540
  1626 00:18:11,930 --> 00:18:14,540
  1630 This evil one reg
  1627 This EVIL1 regular
  1631 expression will always be
  1628 expression will always be
  1632 
  1629 
  1633 355
  1630 355
  1634 00:18:14,540 --> 00:18:17,195
  1631 00:18:14,540 --> 00:18:17,195
  1635 of this size seven,
  1632 of this size seven, at
  1636 the beginning.
  1633 the beginning.
  1637 
  1634 
  1638 356
  1635 356
  1639 00:18:17,195 --> 00:18:20,315
  1636 00:18:17,195 --> 00:18:20,315
  1640 And you can also see if you
  1637 And you can also see if you
  1649 but much more moderately.
  1646 but much more moderately.
  1650 
  1647 
  1651 359
  1648 359
  1652 00:18:24,740 --> 00:18:28,100
  1649 00:18:24,740 --> 00:18:28,100
  1653 And let's try out this
  1650 And let's try out this
  1654 example, this 20 a.
  1651 example with 20 a's.
  1655 
  1652 
  1656 360
  1653 360
  1657 00:18:28,100 --> 00:18:31,685
  1654 00:18:28,100 --> 00:18:31,685
  1658 So we build the derivative
  1655 So we build the derivative
  1659 according to 20 character A's.
  1656 according to 20 character a's.
  1660 
  1657 
  1661 361
  1658 361
  1662 00:18:31,685 --> 00:18:33,890
  1659 00:18:31,685 --> 00:18:33,890
  1663 In the earlier example,
  1660 In the earlier example,
  1664 
  1661 
  1665 362
  1662 362
  1666 00:18:33,890 --> 00:18:35,780
  1663 00:18:33,890 --> 00:18:35,780
  1667 we ended up this a
  1664 we ended up with a
  1668 wreck expression which
  1665 regular expression that
  1669 
  1666 
  1670 363
  1667 363
  1671 00:18:35,780 --> 00:18:37,895
  1668 00:18:35,780 --> 00:18:37,895
  1672 had like 8 million plus nodes.
  1669 had like 8 million plus nodes.
  1673 
  1670 
  1675 00:18:37,895 --> 00:18:39,830
  1672 00:18:37,895 --> 00:18:39,830
  1676 And if we do this now,
  1673 And if we do this now,
  1677 
  1674 
  1678 365
  1675 365
  1679 00:18:39,830 --> 00:18:43,205
  1676 00:18:39,830 --> 00:18:43,205
  1680 then we just have a wreck
  1677 then we just have a regular
  1681 expression with 211 nodes.
  1678 expression with 211 nodes.
  1682 
  1679 
  1683 366
  1680 366
  1684 00:18:43,205 --> 00:18:44,750
  1681 00:18:43,205 --> 00:18:44,750
  1685 And that is much smaller and
  1682 And that is much smaller and
  1689 all the calculations
  1686 all the calculations
  1690 would be much quicker.
  1687 would be much quicker.
  1691 
  1688 
  1692 368
  1689 368
  1693 00:18:47,165 --> 00:18:49,550
  1690 00:18:47,165 --> 00:18:49,550
  1694 So yeah, there's
  1691 So yeah, the Brzozowski
  1695 
  1692 
  1696 369
  1693 369
  1697 00:18:49,550 --> 00:18:52,205
  1694 00:18:49,550 --> 00:18:52,205
  1698 this push off CKY algorithm
  1695 algorithm
  1699 and this improvement.
  1696 and with this improvement,
  1700 
  1697 
  1701 370
  1698 370
  1702 00:18:52,205 --> 00:18:54,890
  1699 00:18:52,205 --> 00:18:54,890
  1703 We're now running
  1700 we're now running
  1704 circles around Ruby and
  1701 circles around Ruby and
  1705 
  1702 
  1706 371
  1703 371
  1707 00:18:54,890 --> 00:18:58,445
  1704 00:18:54,890 --> 00:18:58,445
  1708 Python because they're just
  1705 Python because they're just
  1718 for just 30 a's.
  1715 for just 30 a's.
  1719 
  1716 
  1720 374
  1717 374
  1721 00:19:02,975 --> 00:19:05,930
  1718 00:19:02,975 --> 00:19:05,930
  1722 We now can do something
  1719 We now can do something
  1723 like thousand a's.
  1720 like thousand a's
  1724 
  1721 
  1725 375
  1722 375
  1726 00:19:05,930 --> 00:19:07,580
  1723 00:19:05,930 --> 00:19:07,580
  1727 And in reasonable time.
  1724 in a reasonable time.
  1728 
  1725 
  1729 376
  1726 376
  1730 00:19:07,580 --> 00:19:09,740
  1727 00:19:07,580 --> 00:19:09,740
  1731 I think this must be
  1728 I think this must be
  1732 timing I obtained with
  1729 timing I obtained with
  1740 Because remember we
  1737 Because remember we
  1741 had something like
  1738 had something like
  1742 
  1739 
  1743 379
  1740 379
  1744 00:19:14,210 --> 00:19:16,670
  1741 00:19:14,210 --> 00:19:16,670
  1745 six seconds here, it says 15.
  1742 six seconds. Here it says 15.
  1746 
  1743 
  1747 380
  1744 380
  1748 00:19:16,670 --> 00:19:18,080
  1745 00:19:16,670 --> 00:19:18,080
  1749 So you always have to take
  1746 You always have to take
  1750 
  1747 
  1751 381
  1748 381
  1752 00:19:18,080 --> 00:19:20,885
  1749 00:19:18,080 --> 00:19:20,885
  1753 these times with
  1750 these times with
  1754 the pinch of salt.
  1751 the pinch of salt.
  1762 but it's clear we are
  1759 but it's clear we are
  1763 much, much better.
  1760 much, much better.
  1764 
  1761 
  1765 384
  1762 384
  1766 00:19:25,100 --> 00:19:27,065
  1763 00:19:25,100 --> 00:19:27,065
  1767 So we have worked a lot,
  1764 We have worked a lot,
  1768 
  1765 
  1769 385
  1766 385
  1770 00:19:27,065 --> 00:19:30,720
  1767 00:19:27,065 --> 00:19:30,720
  1771 but we also got something
  1768 but we also got something
  1772 for it in return.
  1769 for it in return.