@@ -50,8 +50,8 @@ def construct(self):
5050 ]
5151
5252 # Create graph
53- graph = self .create_graph ()
54- graph .to_edge ( RIGHT , buff = 1.5 )
53+ graph = self .create_graph (). scale ( 0.7 )
54+ graph .next_to ( title , DOWN , buff = 0.3 )
5555
5656 with self .voiceover (
5757 """Consider this graph. Node zero connects to node one. Node one
@@ -66,20 +66,6 @@ def construct(self):
6666 # R_0 = A (direct connections)
6767 R0_data = A_data
6868
69- R0_mat = create_sparse_matrix (R0_data , scale = 0.32 , v_buff = 0.55 , h_buff = 0.55 )
70- R0_label = MathTex ("R_0 = A" ).scale (0.6 )
71- R0_small_graph = create_small_graph_from_matrix (R0_data , scale = 0.22 , directed = False , edge_color = BLUE )
72- R0_desc = Text ("Direct edges" , font_size = 16 , color = GRAY )
73- R0_group = VGroup (R0_label , R0_mat , R0_small_graph , R0_desc ).arrange (DOWN , buff = 0.1 ).to_edge (LEFT , buff = 0.8 ).shift (UP * 1.5 )
74-
75- with self .voiceover (
76- """We compute transitive closure iteratively. Start with R-zero
77- equal to A, the direct connections. Then repeatedly add new
78- reachable pairs by multiplying."""
79- ):
80- self .play (Write (R0_group ))
81- self .wait (1 )
82-
8369 # R_1 = R_0 | (A @ R_0) - adds 2-hop connections
8470 # Union of direct and 2-hop paths
8571 R1_data = [
@@ -90,21 +76,6 @@ def construct(self):
9076 [0 , 0 , 1 , 1 , 1 ], # 4 can reach 2,3,4
9177 ]
9278
93- R1_mat = create_sparse_matrix (R1_data , scale = 0.32 , v_buff = 0.55 , h_buff = 0.55 )
94- R1_label = MathTex (r"R_1 = R_0 \cup (A \times R_0)" ).scale (0.5 )
95- R1_small_graph = create_small_graph_from_matrix (R1_data , scale = 0.22 , directed = False , edge_color = GREEN )
96- R1_desc = Text ("+ 2-hop paths" , font_size = 16 , color = GREEN )
97- R1_group = VGroup (R1_label , R1_mat , R1_small_graph , R1_desc ).arrange (DOWN , buff = 0.1 ).next_to (R0_group , DOWN , buff = 0.3 )
98-
99- with self .voiceover (
100- """R-one equals R-zero union A times R-zero. This adds all
101- two-hop paths to our reachability. Notice how the matrix
102- fills in as new pairs become connected."""
103- ):
104- self .play (Write (R1_group ))
105- # Highlight new entries that appeared
106- self .wait (1 )
107-
10879 # R_2 = R_1 | (A @ R_1) - converges (all pairs now reachable)
10980 R2_data = [
11081 [1 , 1 , 1 , 1 , 1 ], # 0 can reach all
@@ -114,11 +85,44 @@ def construct(self):
11485 [1 , 1 , 1 , 1 , 1 ], # 4 can reach all
11586 ]
11687
88+ R0_mat = create_sparse_matrix (R0_data , scale = 0.32 , v_buff = 0.55 , h_buff = 0.55 )
89+ R0_label = MathTex ("R_0 = A" ).scale (0.6 )
90+ R0_small_graph = create_small_graph_from_matrix (R0_data , scale = 0.45 , directed = False , edge_color = BLUE )
91+ R0_desc = Text ("Direct edges" , font_size = 16 , color = GRAY )
92+ R0_group = VGroup (R0_label , R0_mat , R0_small_graph , R0_desc ).arrange (DOWN , buff = 0.15 )
93+
94+ R1_mat = create_sparse_matrix (R1_data , scale = 0.32 , v_buff = 0.55 , h_buff = 0.55 )
95+ R1_label = MathTex (r"R_1 = R_0 \cup (A \times R_0)" ).scale (0.5 )
96+ R1_small_graph = create_small_graph_from_matrix (R1_data , scale = 0.45 , directed = False , edge_color = GREEN )
97+ R1_desc = Text ("+ 2-hop paths" , font_size = 16 , color = GREEN )
98+ R1_group = VGroup (R1_label , R1_mat , R1_small_graph , R1_desc ).arrange (DOWN , buff = 0.15 )
99+
117100 R2_mat = create_sparse_matrix (R2_data , scale = 0.32 , v_buff = 0.55 , h_buff = 0.55 )
118101 R2_label = MathTex (r"R_2 = R_1 \cup (A \times R_1)" ).scale (0.5 )
119- R2_small_graph = create_small_graph_from_matrix (R2_data , scale = 0.22 , directed = False , edge_color = YELLOW )
102+ R2_small_graph = create_small_graph_from_matrix (R2_data , scale = 0.45 , directed = False , edge_color = YELLOW )
120103 R2_desc = Text ("Fixed point" , font_size = 16 , color = YELLOW )
121- R2_group = VGroup (R2_label , R2_mat , R2_small_graph , R2_desc ).arrange (DOWN , buff = 0.1 ).next_to (R1_group , DOWN , buff = 0.3 )
104+ R2_group = VGroup (R2_label , R2_mat , R2_small_graph , R2_desc ).arrange (DOWN , buff = 0.15 )
105+
106+ # Arrange the three iteration groups in a horizontal row below the chain graph
107+ r_row = VGroup (R0_group , R1_group , R2_group ).arrange (RIGHT , buff = 0.6 , aligned_edge = UP )
108+ r_row .next_to (graph , DOWN , buff = 0.4 )
109+
110+ with self .voiceover (
111+ """We compute transitive closure iteratively. Start with R-zero
112+ equal to A, the direct connections. Then repeatedly add new
113+ reachable pairs by multiplying."""
114+ ):
115+ self .play (Write (R0_group ))
116+ self .wait (1 )
117+
118+ with self .voiceover (
119+ """R-one equals R-zero union A times R-zero. This adds all
120+ two-hop paths to our reachability. Notice how the matrix
121+ fills in as new pairs become connected."""
122+ ):
123+ self .play (Write (R1_group ))
124+ # Highlight new entries that appeared
125+ self .wait (1 )
122126
123127 with self .voiceover (
124128 """After another iteration, R-two fills completely. Every node
0 commit comments