### Install MF_Algebra Package Source: https://github.com/themathematicfanatic/mf_algebra/blob/main/README.md Installs the MF_Algebra package using pip. This command is used to download and install the library into your Python environment. ```bash pip install MF_Algebra ``` -------------------------------- ### Manim Scene Integration: Quadratic Equation Solver Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt An example of integrating MF-Algebra with Manim to create an animated scene that solves a quadratic equation. It demonstrates setting up the Manim environment, defining the equation, and using MF-Algebra's `Solve` class to animate the solution process. ```python from manimlib import * from MF_Algebra import * algebra_config['multiplication_mode'] = 'auto' algebra_config['always_color'] = {x: RED, y: BLUE, z: GREEN} class QuadraticSolve(Scene): def construct(self): # Create and display equation eq = x**2 - 5*x + 6 & 0 self.play(Write(eq.mob)) self.wait() # Create solver S = Solve( solve_for=x, auto_scale=2, show_past_steps=True ) S >> eq # Animate solution S.play_all(self, wait_between=0.5) self.wait(2) ``` -------------------------------- ### AlgebraicAction for Pattern-Based Transformations Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Explains how to use the AlgebraicAction class to define and apply custom algebraic transformations based on input and output patterns. Examples include distribution, factoring, power rules, logarithm rules, and custom glyph mapping. ```python from MF_Algebra import * # Define algebraic transformation distribute = AlgebraicAction( a * (b + c), # Template 1 (input pattern) a*b + a*c # Template 2 (output pattern) ) # Apply to matching expression expr = 3 * (x + 5) result = distribute.get_output_expression(expr) # 3x + 15 # Factoring (reverse of distribution) factor = AlgebraicAction( a*b + a*c, a * (b + c) ) # Power rules power_product = AlgebraicAction( (a*b)**c, a**c * b**c ) # Logarithm rules log_product = AlgebraicAction( ln(a*b), ln(a) + ln(b) ) # With custom addressmap for animation control custom = AlgebraicAction( x**2 - y**2, (x+y)*(x-y), ['-', '0+'], # Custom glyph mapping ['-', '1-'] ) ``` -------------------------------- ### Pythagorean Identity Substitution Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Shows an example of the Pythagorean identity (`sin(x)**2 + cos(x)**2`) and how to substitute a specific value for the variable `x` using the `.substitute()` method. ```python from MF_Algebra import * identity = sin(x)**2 + cos(x)**2 # sin²x + cos²x evaluated = identity.substitute({x: pi/4}) # Substitutes π/4 ``` -------------------------------- ### Import MF_Algebra with ManimGL Source: https://github.com/themathematicfanatic/mf_algebra/blob/main/README.md Imports necessary classes from ManimGL and MF_Algebra. This setup is required to use the MF_Algebra plugin within a ManimGL project. ```python from manimlib import * from MF_Algebra import * ``` -------------------------------- ### Import MF_Algebra with Manim Community Edition Source: https://github.com/themathematicfanatic/mf_algebra/blob/main/README.md Imports necessary classes from Manim Community Edition and MF_Algebra. This setup is required to use the MF_Algebra plugin within a Manim Community Edition project. ```python from manim import * from MF_Algebra import * ``` -------------------------------- ### Equation Maneuvers - Pre-built Algebra Moves Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Details the use of pre-defined algebraic maneuvers for common equation solving steps. It shows examples of addition and multiplication maneuvers for moving terms across the equals sign and lists available maneuvers. ```python from MF_Algebra import * # Addition maneuver: a + b = c → a = c - b add_R = alg_add_R() eq = x + 5 & 10 result = add_R.get_output_expression(eq) # x = 10 - 5 # Multiplication maneuver: a * b = c → a = c / b mul_R = alg_mul_R() eq = 3*x & 15 result = mul_R.get_output_expression(eq) # x = 15/3 # Available maneuvers: # alg_add_R() - Move addition right side # alg_add_L() - Move addition left side # alg_mul_R() - Move multiplication right side # alg_mul_L() - Move multiplication left side # alg_pow_R() - Move power (creates radical) # alg_pow_L() - Move power (creates logarithm) # alg_neg_R() - Move negative sign ``` -------------------------------- ### Create Trigonometric Equations Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates how to create trigonometric equations using the '&' operator for equality. This allows for setting up and solving equations involving trigonometric functions. ```python from MF_Algebra import * # Create trig equations trig_eq = sin(x) & 1/2 ``` -------------------------------- ### Solve Class for Auto-Solving Equations Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Illustrates the use of the Solve class for automatically solving equations for a specified variable. It demonstrates creating an equation, initializing the solver, feeding the equation, playing the solution steps, and accessing the final solution. ```python from MF_Algebra import * from manimlib import * class SolveDemo(Scene): def construct(self): # Create equation eq = 3*x + 5 & 14 # Create solver for variable x S = Solve( solve_for=x, auto_scale=2, auto_color={x: GREEN}, show_past_steps=True ) # Feed equation and auto-solve S >> eq # Play solution steps self.add(S.mob) S.play_all(self, wait_between=0.5) # Access solution solution = S.solution # Returns: 3 # Solve more complex equations eq2 = (x + 2)**2 & 16 S2 = Solve(x) >> eq2 # Change variable to solve for eq3 = a*x + b & c S3 = Solve(x) >> eq3 S3.set_solve_for(a) # Now solve for 'a' instead ``` -------------------------------- ### Basic Timeline Usage Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Illustrates fundamental usage of the Timeline class for evaluating simple expressions and chaining operations. It shows how to append expressions and trigger evaluations. ```python T = Timeline() T >> (3**2 + 4**2) T >> evaluate_() # Computes to 25 # Chain evaluations T = Timeline() T >> ((2 + 3) * (4 + 1)) T >> evaluate_().pread('0') # (5) * (4 + 1) T >> evaluate_().pread('1') # 5 * (5) T >> evaluate_() # 25 ``` -------------------------------- ### Apply Functions to Expressions and Expand Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates applying predefined or custom functions to symbolic expressions and then expanding the result. This is useful for simplifying or analyzing complex expressions. The `expand_on_args()` method is used for this purpose. ```python from MF_Algebra import * sin_expr = sin(x) cos_expr = cos(theta) tan_expr = tan(pi/4) func_applied = square_plus_one(a + b) expanded = func_applied.expand_on_args() # (a+b)² + 1 ``` -------------------------------- ### Create Equations and Relations in MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Shows how to represent mathematical equations and inequalities using the `Equation` and `Relation` classes in MF-Algebra. It covers creating equations with `&` or `|`, various inequality types, accessing equation sides, and computing boolean results. ```python from MF_Algebra import * # Create equations eq1 = x + 5 & 10 # x + 5 = 10 eq2 = y | 2*x + 3 # y = 2x + 3 quadratic = x**2 - 4 & 0 # x² - 4 = 0 # Create inequalities ineq1 = x > 5 # x > 5 ineq2 = y <= x**2 # y ≤ x² ineq3 = a >= b # a ≥ b # Access sides of equation equation = a*x + b & c left = equation.left # a*x + b right = equation.right # c # Compute boolean result if possible simple_eq = (3 + 4) & 7 result = simple_eq.compute() # Returns: True ``` -------------------------------- ### Manim Scene Integration: Expression Evaluation Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates integrating MF-Algebra with Manim to animate the evaluation of a mathematical expression. It shows how to set up an expression, define an evaluation timeline using MF-Algebra's `Evaluate` class, and animate the substitution and simplification steps. ```python from manimlib import * from MF_Algebra import * class EvaluateExpression(Scene): def construct(self): # Setup expression expr = (a**2 + b**2) / (c**2) # Create evaluation timeline E = Evaluate( auto_color={a: RED, b: GREEN, c: BLUE}, auto_scale=2.5 ) E >> expr E >> substitute_({a: 3, b: 4, c: 5}) # Display and animate self.play(Write(E.mob)) E.play_all(self) # Final result: (9 + 16) / 25 = 25/25 = 1 ``` -------------------------------- ### Evaluate Class for Auto-Evaluation Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Shows how to use the Evaluate class, a specialized Timeline that automatically simplifies expressions step-by-step. It covers initialization, setting expressions, and playing the auto-evaluation animation. ```python from MF_Algebra import * from manimlib import * class EvaluateDemo(Scene): def construct(self): # Create auto-evaluating timeline E = Evaluate( auto_color={x: RED, y: BLUE}, auto_scale=2, mode='one at a time' # or 'all at once' ) # Set up expression with substitution E >> (3*x**2 - (4+x) / sqrt(y-1)) E >> substitute_({x: 8, y: 10}) # Timeline auto-fills evaluation steps self.add(E.mob) E.play_all(self) # Expression is progressively evaluated # 3·8² - (4+8)/√(10-1) # → 192 - 12/√9 # → 192 - 12/3 # → 192 - 4 # → 188 ``` -------------------------------- ### Create and Manipulate Expressions in MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates how to create mathematical expressions using Python operators and MF-Algebra's `Expression` class. It covers creating simple expressions, equations, custom variables, accessing subexpressions, and substituting values. ```python from MF_Algebra import * # Create simple expressions using operators expr1 = 3*x**2 + 5*x - 7 expr2 = (a + b) / (c - d) expr3 = sqrt(x**2 + y**2) # Create equations using & or | operators equation = y & 2*x + 4 # Creates: y = 2x + 4 inequality = x**2 + y**2 < 25 # Create custom variables F, m, a_var = Variables('Fma') physics_eq = F & m * a_var # F = ma # Access the Manim mobject for rendering # scene.add(expr1.mob) # Requires a Manim scene context # Access subexpressions by address subex = expr1.get_subex('0') # Gets the first child (3*x**2) all_vars = expr1.get_all_variables() # Returns {x} # Substitute values result = expr1.substitute({x: 5}) # Replaces x with 5 ``` -------------------------------- ### Timeline Class Usage in Manim Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates how to use the Timeline class within a Manim scene to manage and animate sequences of algebraic expressions and actions. It covers initialization with options, adding expressions, chaining actions, and playing animations. ```python from MF_Algebra import * from manimlib import * class MyScene(Scene): def construct(self): # Create timeline with options T = Timeline( auto_color={x: RED, y: BLUE}, auto_scale=2, show_past_steps=True ) # Add initial expression T >> (x**2 + y**2) # Chain actions using >> T >> div_(z**2) T >> substitute_({x: 3, y: 4}) T >> evaluate_() # Alternative: Expression >> Timeline (a + b) >> T >> mul_(2) >> evaluate_() # Play all animations self.add(T.mob) T.play_all(self, wait_between=0.5) # Access timeline data expressions = T.expressions # List of all expressions actions = T.actions # List of all actions current = T.exp # Current expression ``` -------------------------------- ### Algebraic Manipulation with MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates basic algebraic manipulation functions like reverse and flip from MF-Algebra. These functions are used to represent and transform algebraic equations. ```python from MF_Algebra import alg_add_R reversed_add = alg_add_R().reverse() # a = c - b → a + b = c flipped_add = alg_add_R().flip() # Swap sides first ``` -------------------------------- ### Expression Transformations with Action Class Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Introduces the `Action` class for defining transformations on expressions. Actions can be animated, composed, and target specific subexpressions using preaddressing. ```python from MF_Algebra import * # Substitution action sub = substitute_({x: 5, y: 10}) original = x**2 + y**2 result = sub.get_output_expression(original) # 5² + 10² # Apply operation actions add_action = add_(5) # Adds 5 to expression sub_action = sub_(3) # Subtracts 3 mul_action = mul_(2) # Multiplies by 2 div_action = div_(4) # Divides by 4 pow_action = pow_(2) # Raises to power 2 # Apply to both sides of equation both_sides = add_(5).both() # Adds 5 to both sides # Preaddress to target specific subexpressions left_only = mul_(2).pread('0') # Only affects left child right_only = div_(3).pread('1') # Only affects right child # Combine actions in parallel parallel = add_(5).pread('0') | sub_(3).pread('1') # Swap children swap = swap_children_() swapped = swap.get_output_expression(a + b) # b + a ``` -------------------------------- ### Expression Evaluation with evaluate_ Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates the `evaluate_` action for computing numerical results of expressions. It can be applied to the entire expression or specific subexpressions using preaddressing. ```python from MF_Algebra import * # Evaluate simple expression eval_action = evaluate_() expr = 3 + 4 * 2 result = eval_action.get_output_expression(expr) # 11 # Evaluate at specific address eval_left = evaluate_().pread('0') # Evaluate left child only eval_right = evaluate_().pread('1') # Evaluate right child only # Parallel evaluation parallel_eval = evaluate_().pread('0') | evaluate_().pread('1') ``` -------------------------------- ### Basic Trigonometric Expressions and Unit Circle Values Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Illustrates the use of standard trigonometric functions like `sin`, `cos`, and `tan` within MF-Algebra. The library automatically recognizes and evaluates unit circle values for common angles, simplifying expressions. ```python from MF_Algebra import * # Basic trig expressions expr1 = sin(x) + cos(x) expr2 = tan(theta) / sec(theta) identity = sin(x)**2 + cos(x)**2 # Unit circle values are automatically recognized half = sin(pi/6) # Evaluates to 1/2 sqrt2_over_2 = cos(pi/4) # Evaluates to √2/2 ``` -------------------------------- ### Variable Substitution with substitute_ Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Details the `substitute_` action for replacing variables or subexpressions. It supports various animation modes, maintaining original colors, and lagged animations for sequential substitutions. ```python from MF_Algebra import * # Basic substitution sub = substitute_({x: 5}) expr = x**2 + 2*x + 1 result = sub.get_output_expression(expr) # 5² + 2·5 + 1 # Multiple substitutions multi_sub = substitute_({x: 3, y: 4, z: 5}) expr = x + y + z result = multi_sub.get_output_expression(expr) # 3 + 4 + 5 # Animation modes transform_sub = substitute_({x: a}, mode='transform') # Direct transform swirl_sub = substitute_({x: a}, mode='swirl') # Arc animation fade_sub = substitute_({x: a}, mode='fade') # Fade in/out # Maintain original colors colored_sub = substitute_({x: 5}, maintain_color=True) # Lagged animation (each substitution delayed) lagged_sub = substitute_({x: 1, y: 2, z: 3}, lag=0.3) # In Timeline T = Timeline() T >> (a**2 + b**2) T >> substitute_({a: 3, b: 4}) ``` -------------------------------- ### Nested Radicals and Radicals in Equations Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates creating nested radicals and incorporating radicals into equations. The `Rad` class and shorthand functions handle these complex structures. ```python from MF_Algebra import * # Nested radicals nested = sqrt(sqrt(sqrt(a/b))) # In equations pyth = c & sqrt(a**2 + b**2) ``` -------------------------------- ### Square Root and Cube Root Shorthands Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Introduces the convenience functions `sqrt` and `cbrt` for calculating square roots and cube roots, respectively. These functions can handle both numerical and symbolic arguments. ```python from MF_Algebra import * # Square root (shorthand) expr1 = sqrt(x**2 + y**2) expr2 = sqrt(16) # Cube root (shorthand) expr3 = cbrt(27) expr4 = cbrt(x**3 + y**3) ``` -------------------------------- ### Perform Arithmetic Operations in MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Illustrates how to perform arithmetic operations like addition, subtraction, multiplication, division, and exponentiation using Python operators within MF-Algebra. It also covers configuring multiplication display modes and division rendering. ```python from MF_Algebra import * # Operations are created implicitly with operators addition = a + b + c subtraction = a - b - c multiplication = 3 * x * y division = (x + 1) / (x - 1) power = x**2 + y**3 negative = -x # Configure multiplication display mode # algebra_config['multiplication_mode'] = 'dot' # Shows as a·b # algebra_config['multiplication_mode'] = 'x' # Shows as a×b # algebra_config['multiplication_mode'] = 'juxtapose' # Shows as ab # algebra_config['multiplication_mode'] = 'auto' # Auto-selects # Division modes fraction = Div(a, b, mode='fraction') # Shows as a/b (stacked) inline = Div(a, b, mode='inline') # Shows as a÷b # Access parts of operations expr = a + b left_side = expr.left # Returns: a right_side = expr.right # Returns: b ``` -------------------------------- ### Import MF-Algebra for Manim Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Imports necessary modules from Manim and MF-Algebra. This code snippet shows the correct import statements for both ManimGL and Manim Community Edition. ```python # For ManimGL from manimlib import * from MF_Algebra import * # For Manim Community Edition from manim import * from MF_Algebra import * ``` -------------------------------- ### Calculus Operations with MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Showcases MF-Algebra's support for calculus notation, including differentials, integrals, limits, and series. It demonstrates how to define and manipulate these mathematical concepts programmatically. ```python from MF_Algebra import * # Differential operator diff_x = d(x) # dx diff_y = d(y) # dy diff_expr = d(x**2) # d(x²) # Pre-defined differentials dx, dy, dz # Already available # Integrals integral = Integral(0, 1)(x**2 * dx) # ∫₀¹ x² dx # Limits lim = Limit(x, inf)(1/x) # lim_{x→∞} 1/x # Series and Sums sigma = Sum(n, 0, inf)(1/n**2) # Σ_{n=0}^∞ 1/n² # In Timelines T = Timeline() T >> (x**2 + y**2) T >> apply_func_(d) # Apply differential operator ``` -------------------------------- ### Substitute Expression Into Function with substitute_into_ Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Explains the `substitute_into_` action, which is used to substitute an entire expression into a function or another outer expression. It can target a specific variable for substitution. ```python from MF_Algebra import * # Substitute into a function F = f(x) inner_expr = 2*a + 1 action = substitute_into_(F) result = action.get_output_expression(inner_expr) # f(2a + 1) # With explicit variable outer = x**2 + 2*x + 1 action = substitute_into_(outer, substitution_variable=x) result = action.get_output_expression(a + b) # (a+b)² + 2(a+b) + 1 # In Timeline T = Timeline() T >> (5) T >> substitute_into_(1/(1-x)) # Becomes 1/(1-5) ``` -------------------------------- ### Nth Root using Rad Class Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Explains how to use the `Rad` class to compute arbitrary nth roots. The `Rad(n)` constructor creates an nth root object that can be applied to an expression. ```python from MF_Algebra import * # Nth root using Rad fourth_root = Rad(4)(x) # ⁴√x fifth_root = Rad(5)(32) # ⁵√32 ``` -------------------------------- ### Use Mathematical Functions in MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Demonstrates the usage of the `Function` class in MF-Algebra for representing mathematical functions. It covers pre-defined functions, function composition using the `@` operator, and custom evaluation rules. ```python from MF_Algebra import * # Pre-defined functions expr1 = f(x) # f(x) expr2 = g(x + 1) # g(x + 1) composed = (f @ g)(x) # (f ∘ g)(x) ``` -------------------------------- ### Function Substitution with Preaddressing in MF Algebra Source: https://github.com/themathematicfanatic/mf_algebra/blob/main/to_do_list.txt Demonstrates the use of `substitute_into_` to apply a function `F` to both sides of an expression `A`. The `preaddress` parameter controls the application side. This is useful for applying the same transformation to different parts of an expression. ```python class FunctionSubstituteTest(Scene): def construct(self): F = f(x) A = y & x**2-5 T = A >> ( substitute_into_(F, preaddress='0') | substitute_into_(F, preaddress='1') ) T.propagate() self.add(T.mob) #self.embed() ``` -------------------------------- ### Create Custom Functions with Algebra Rules Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Defines how to create custom algebraic functions using the Function class. It requires a symbol, symbol glyph length, the algebraic rule, and the variables involved in the rule. The function can then be called with numerical or symbolic arguments. ```python from MF_Algebra import * square_plus_one = Function( symbol='F', symbol_glyph_length=1, algebra_rule=x**2 + 1, algebra_rule_variables=[x] ) result = square_plus_one(3) # F(3) ``` -------------------------------- ### Define and Use Mathematical Variables in MF-Algebra Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Explains how to define symbolic variables using the `Variable` class in MF-Algebra. It shows the use of pre-defined variables, Greek letters, custom variables with specific glyph lengths, and variables with subscripts. ```python from MF_Algebra import * # Pre-defined variables (already available) expr = x**2 + y**2 + z**2 # Greek letters trig_expr = sin(theta) + cos(alpha) # Create custom variables m_prime = Variable("m'", 2) # Variable with 2-glyph symbol gamma = Variable('\gamma', 1) # Create multiple variables at once P, V, n, R, T = Variables('PVnRT') ideal_gas = P * V & n * R * T # Special notation with subscripts x_1 = Variable('x_1', 2) x_n = Variable('x_n', 2) ``` -------------------------------- ### Evaluate Function Numerically Source: https://context7.com/themathematicfanatic/mf_algebra/llms.txt Shows how to numerically evaluate a function or expression. The `.evaluate()` method attempts to compute a numerical result if possible, simplifying expressions like trigonometric functions with known values. ```python from MF_Algebra import * computed = sin(pi/6).evaluate() # Returns 1/2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.