def construct(self): clunky_deriv = TexMobject( "{d", "\\big(", "{df", "\\over", "dx}", "\\big)", "\\over", "dx }" ) over_index = clunky_deriv.index_of_part( clunky_deriv.get_parts_by_tex("\\over")[1] ) numerator = VGroup(*clunky_deriv[:over_index]) denominator = VGroup(*clunky_deriv[over_index+1:]) rp = clunky_deriv.get_part_by_tex("(") lp = clunky_deriv.get_part_by_tex(")") dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [ "df", "over", "dx" ]) df_over_dx = VGroup(dfs[0], overs[0], dxs[0]) d = clunky_deriv.get_part_by_tex("d") d_over_dx = VGroup(d, overs[1], dxs[1]) d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}") d2f_over_dx2.highlight_by_tex("dx", YELLOW) for mob in clunky_deriv, d2f_over_dx2: mob.next_to(self.teacher, UP+LEFT) for mob in numerator, denominator: circle = Circle(color = YELLOW) circle.replace(mob, stretch = True) circle.scale_in_place(1.3) mob.circle = circle dx_to_zero = TexMobject("dx \\to 0") dx_to_zero.highlight(YELLOW) dx_to_zero.next_to(clunky_deriv, UP+LEFT) self.student_says( "What's that notation?", target_mode = "raise_left_hand" ) self.change_student_modes("confused", "raise_left_hand", "confused") self.play( FadeIn( clunky_deriv, run_time = 2, submobject_mode = "lagged_start" ), RemovePiCreatureBubble(self.get_students()[1]), self.teacher.change_mode, "raise_right_hand" ) self.wait() self.play(ShowCreation(numerator.circle)) self.wait() self.play(ReplacementTransform( numerator.circle, denominator.circle, )) self.wait() self.play( FadeOut(denominator.circle), Write(dx_to_zero), dxs.highlight, YELLOW ) self.wait() self.play( FadeOut(dx_to_zero), *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()] ) self.play( df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(), df_over_dx.move_to, d_over_dx, RIGHT, FadeOut(VGroup(lp, rp)), d_over_dx.shift, 0.8*LEFT + 0.05*UP, ) self.wait() self.play(*[ ReplacementTransform( group, VGroup(d2f_over_dx2.get_part_by_tex(tex)) ) for group, tex in [ (VGroup(d, dfs[0]), "d^2"), (overs, "over"), (dxs, "dx"), (VGroup(dxs[1].copy()), "^2}"), ] ]) self.wait(2) self.student_says( "How does one... \\\\ read that?", student_index = 0, ) self.play(self.teacher.change, "happy") self.wait(2)
def construct(self): scale_factor = 0.7 sick = "\\text{sick}" positive = "\\text{positive}" formula = TexMobject("P(", sick, "\\,|\\,", positive, ")", "=", "{\\quad P(", sick, "\\text{ and }", positive, ") \\quad", "\\over", "P(", positive, ")}", "=", "{1/1{,}000", "\\over", "1/1{,}000", "+", "(999/1{,}000)(0.01)}") formula.scale(scale_factor) formula.next_to(self.pi_creatures, UP, LARGE_BUFF) formula.shift_onto_screen(buff=MED_LARGE_BUFF) equals_group = formula.get_parts_by_tex("=") equals_indices = [ formula.index_of_part(equals) for equals in equals_group ] lhs = VGroup(*formula[:equals_indices[0]]) initial_formula = VGroup(*formula[:equals_indices[1]]) initial_formula.save_state() initial_formula.shift(3 * RIGHT) over = formula.get_part_by_tex("\\over") num_start_index = equals_indices[0] + 1 num_end_index = formula.index_of_part(over) numerator = VGroup(*formula[num_start_index:num_end_index]) numerator_rect = SurroundingRectangle(numerator) alt_numerator = TexMobject("P(", sick, ")", "P(", positive, "\\,|\\,", sick, ")") alt_numerator.scale(scale_factor) alt_numerator.move_to(numerator) number_fraction = VGroup(*formula[equals_indices[-1]:]) rhs = TexMobject("\\approx 0.09") rhs.scale(scale_factor) rhs.move_to(equals_group[-1], LEFT) rhs.highlight(YELLOW) for mob in formula, alt_numerator: mob.highlight_by_tex(sick, SICKLY_GREEN) mob.highlight_by_tex(positive, YELLOW) #Ask question self.student_says("What does the \\\\ formula look like here?") self.play(self.teacher.change, "happy") self.dither() self.play( Write(lhs), RemovePiCreatureBubble( self.students[1], target_mode="pondering", ), self.teacher.change, "raise_right_hand", self.students[0].change, "pondering", self.students[2].change, "pondering", ) self.dither() #Show initial formula lhs_copy = lhs.copy() self.play( LaggedStart(FadeIn, initial_formula, lag_ratio=0.7), Animation(lhs_copy, remover=True), ) self.dither(2) self.play(ShowCreation(numerator_rect)) self.play(FadeOut(numerator_rect)) self.dither() self.play(Transform(numerator, alt_numerator)) initial_formula.add(*numerator) formula.add(*numerator) self.dither(3) #Show number_fraction self.play(initial_formula.move_to, initial_formula.saved_state, FadeIn(VGroup(*number_fraction[:3]))) self.dither(2) self.play( LaggedStart(FadeIn, VGroup(*number_fraction[3:]), run_time=3, lag_ratio=0.7)) self.dither(2) #Show rhs self.play(formula.shift, UP) self.play(Write(rhs)) self.change_student_modes(*["happy"] * 3) self.look_at(rhs) self.dither(2)
def construct(self): clunky_deriv = TexMobject( "{d", "\\big(", "{df", "\\over", "dx}", "\\big)", "\\over", "dx }" ) over_index = clunky_deriv.index_of_part( clunky_deriv.get_parts_by_tex("\\over")[1] ) numerator = VGroup(*clunky_deriv[:over_index]) denominator = VGroup(*clunky_deriv[over_index+1:]) rp = clunky_deriv.get_part_by_tex("(") lp = clunky_deriv.get_part_by_tex(")") dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [ "df", "over", "dx" ]) df_over_dx = VGroup(dfs[0], overs[0], dxs[0]) d = clunky_deriv.get_part_by_tex("d") d_over_dx = VGroup(d, overs[1], dxs[1]) d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}") d2f_over_dx2.highlight_by_tex("dx", YELLOW) for mob in clunky_deriv, d2f_over_dx2: mob.next_to(self.teacher, UP+LEFT) for mob in numerator, denominator: circle = Circle(color = YELLOW) circle.replace(mob, stretch = True) circle.scale_in_place(1.3) mob.circle = circle dx_to_zero = TexMobject("dx \\to 0") dx_to_zero.highlight(YELLOW) dx_to_zero.next_to(clunky_deriv, UP+LEFT) self.student_says( "What's that notation?", target_mode = "raise_left_hand" ) self.change_student_modes("confused", "raise_left_hand", "confused") self.play( FadeIn( clunky_deriv, run_time = 2, submobject_mode = "lagged_start" ), RemovePiCreatureBubble(self.get_students()[1]), self.teacher.change_mode, "raise_right_hand" ) self.dither() self.play(ShowCreation(numerator.circle)) self.dither() self.play(ReplacementTransform( numerator.circle, denominator.circle, )) self.dither() self.play( FadeOut(denominator.circle), Write(dx_to_zero), dxs.highlight, YELLOW ) self.dither() self.play( FadeOut(dx_to_zero), *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()] ) self.play( df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(), df_over_dx.move_to, d_over_dx, RIGHT, FadeOut(VGroup(lp, rp)), d_over_dx.shift, 0.8*LEFT + 0.05*UP, ) self.dither() self.play(*[ ReplacementTransform( group, VGroup(d2f_over_dx2.get_part_by_tex(tex)) ) for group, tex in [ (VGroup(d, dfs[0]), "d^2"), (overs, "over"), (dxs, "dx"), (VGroup(dxs[1].copy()), "^2}"), ] ]) self.dither(2) self.student_says( "How does one... \\\\ read that?", student_index = 0, ) self.play(self.teacher.change, "happy") self.dither(2)