        <!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Matemática Virtual, Ing.MSc. Fernando Carrillo & Ing.MSc. Cecilia Izurieta</title>
    <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <?php include 'encabezado.php'; ?>
    <main>
        <?php include 'menui.php'; ?>
        
    <div class="container mt-5">
        <h3 class="mb-4">Binomio al cubo</h3>
    <h6 class="mb-4">Multiplicar aplicando productos notables en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
            $n=15;
            $n=round($n/3)+2;

                function generateBinomialMultiplication() {
                    $coefficients = range(1, 10);
                    $exponente = range(1, 4);

                    $variables = ['x', 'y', 'z', 'a', 'b', 'c'];

                    // Generate random coefficients and variables for the terms
                    $exponente = $coefficients[array_rand($exponente)];
                    $a = $coefficients[array_rand($coefficients)];
                    $b = $coefficients[array_rand($coefficients)];
                    $c = $coefficients[array_rand($coefficients)];
                    $d = $coefficients[array_rand($coefficients)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                    $a1=$a*$a;
                    $b1=$b*$b;
                    $exponente1=$exponente * 2 ;
                    $doble=2*$a*$b ;

                    // Formulate the binomial multiplication expression
                    $expression = "$a1$var1^$exponente1 - $doble$var1^$exponente + $b1";
                    

                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                    
                    $result = "($a$var1 - $b)^3 ";
                      }
                    else
                    {
                    $term1 = $var1 .'^'.$exponente;

                    $result = "($a$term1 - $b)^3 ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }

                for ($i = 1; $i <= $n; $i++) {
                    list($multiplication, $result) = generateBinomialMultiplication();
                    echo "<div class='card mb-3'>";
                    echo "<div class='card-body'>";
                    echo "<h5 class='card-title'>Ejercicio $i</h5>";
                    //echo "<p class='card-text'> \( $multiplication \)</p>";
                    echo "<p class='card-text'> \( $result \)</p>";
                    echo "</div>";
                    echo "</div>";
                }
            ?>
        </div>
    </div>
    <!-- MathJax -->
    

    <div class="container mt-5">
    
        <div class="mt-4">
            <?php
                function generateBinomialMultiplicationa() {
                    $coefficients = range(1, 10);
                    $exponente = range(1, 4);

                    $variables = ['x', 'y', 'z', 'a', 'b', 'c'];

                    // Generate random coefficients and variables for the terms
                    $exponente = $coefficients[array_rand($exponente)];
                    $a = $coefficients[array_rand($coefficients)];
                    $b = $coefficients[array_rand($coefficients)];
                    $c = $coefficients[array_rand($coefficients)];
                    $d = $coefficients[array_rand($coefficients)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                    $a1=$a*$a;
                    $b1=$b*$b;
                    $exponente1=$exponente * 2 ;
                    $doble=2*$a*$b ;

                    // Formulate the binomial multiplication expression
                    $expression = "$a1$var1^$exponente1 + $doble$var1^$exponente + $b1";
                    

                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                    
                    $result = "($a$var1 + $b)^3 ";
                      }
                    else
                    {
                    $term1 = $var1 .'^'.$exponente;

                    $result = "($a$term1 + $b)^3 ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }

                for ($i = 1; $i <= $n; $i++) {
                    list($multiplication, $result) = generateBinomialMultiplicationa();
                    echo "<div class='card mb-3'>";
                    echo "<div class='card-body'>";
                    echo "<h5 class='card-title'>Ejercicio $i</h5>";
                    //echo "<p class='card-text'> \( $multiplication \)</p>";
                    echo "<p class='card-text'> \( $result \)</p>";
                    echo "</div>";
                    echo "</div>";
                }
            ?>
        </div>
    </div>
    <!-- MathJax -->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>





<div class="container mt-5">
    <div class="mt-4">
        <?php
        // Función para calcular el máximo común divisor (MCD) de dos números
        function gcd($a, $b) {
            while ($b != 0) {
                $t = $b;
                $b = $a % $b;
                $a = $t;
            }
            return $a;
        }

        // Función para simplificar una fracción
        function simplificarFraccion($numerador, $denominador) {
            // Calcular el máximo común divisor (MCD) de los números
            $mcd = gcd($numerador, $denominador);

            // Simplificar la fracción dividiendo el numerador y el denominador por el MCD
            $numeradorSimplificado = $numerador / $mcd;
            $denominadorSimplificado = $denominador / $mcd;

            // Construir la representación LaTeX de la fracción simplificada
            $fraccionSimplificadaLatex = "\\frac{{$numeradorSimplificado}}{{$denominadorSimplificado}}";

            return $fraccionSimplificadaLatex;
        }

        function generateBinomialMultiplication1() {
            $coefficients = range(1, 10);
            $exponentes = range(1, 4);
            $den = range(2, 9);

            $variables = ['x', 'y', 'z', 'w', 'm', 'p'];
            $variables1 = ['d', 'e', 'f', 'a', 'b', 'c'];

            // Generate random coefficients and variables for the terms
            $exponente = $coefficients[array_rand($exponentes)];
            $exponente2 = $coefficients[array_rand($exponentes)];
            $c = $coefficients[array_rand($den)];
            $a = $coefficients[array_rand($coefficients)];
            $b = $coefficients[array_rand($coefficients)];
            $d = $coefficients[array_rand($coefficients)];
            
            // Ensure var1 and var2 are different
            do {
                $var1 = $variables[array_rand($variables)];
                $var2 = $variables1[array_rand($variables1)];
            } while ($var1 == $var2);

            $a1 = $a * $a;
            $b1 = $b * $b;
            $c1 = $c * $c;
            $exponente1 = $exponente * 2;
            $exponente3 = $exponente2 * 2;
            $doble = 2 * $a * $b;
            $fraccionSimplificada = simplificarFraccion($doble, $c);
            $fraccionSimplificada1 = simplificarFraccion($b, $c);

            // Formulate the binomial multiplication expression
            $expression = "$a1$var1^$exponente1 - $fraccionSimplificada$var1^$exponente$var2^$exponente2 + \\frac{{$b1}}{{$c1}}$var2^$exponente3";

            // Calculate the result using distributive property
            if ($exponente == 1) {
                $result = "($a$var1 - $fraccionSimplificada1$var2^$exponente2)^3 ";
            } else {
                $term1 = $var1 .'^'.$exponente;
                $result = "($a$term1 - $fraccionSimplificada1$var2^$exponente2)^3 ";
            }

            return [$expression, $result];
        }

        for ($i = 1; $i <= $n; $i++) {
            list($multiplication, $result) = generateBinomialMultiplication1();
            echo "<div class='card mb-3'>";
            echo "<div class='card-body'>";
            echo "<h5 class='card-title'>Ejercicio $i</h5>";
            //echo "<p class='card-text'>\( $multiplication \)</p>";
            echo "<p class='card-text'> \( $result \)</p>";
            echo "</div>";
            echo "</div>";
        }
        ?>
    </div>
</div>



    <!-- MathJax -->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>





    <div class="container mt-5">
        
        <div class="mt-4">
            <?php
// Función para calcular el máximo común divisor (MCD) de dos números
function gcd1($a, $b) {
    while ($b != 0) {
        $t = $b;
        $b = $a % $b;
        $a = $t;
    }
    return $a;
}

// Función para simplificar una fracción
function simplificarFraccion1($numerador, $denominador) {
    // Calcular el máximo común divisor (MCD) de los números
    $mcd = gcd1($numerador, $denominador);

    // Simplificar la fracción dividiendo el numerador y el denominador por el MCD
    $numeradorSimplificado = $numerador / $mcd;
    $denominadorSimplificado = $denominador / $mcd;

    // Construir la representación LaTeX de la fracción simplificada
    $fraccionSimplificadaLatex = "\\frac{{$numeradorSimplificado}}{{$denominadorSimplificado}}";

    return $fraccionSimplificadaLatex;
}

?>
            <?php
                function generateBinomialMultiplicationd() {
                    $coefficients = range(1, 10);
                    $exponente = range(1, 4);
                    $exponente2 = range(1, 4);
                    $den = range(2, 9);

                    $variables = ['x', 'y', 'z', 'w', 'm', 'p'];
                    $variables1 = ['d', 'e', 'f', 'a', 'b', 'c'];

                    // Generate random coefficients and variables for the terms
                    $exponente = $coefficients[array_rand($exponente)];
                    $exponente2 = $coefficients[array_rand($exponente2)];
                    $c = $coefficients[array_rand($den)];
                    $a = $coefficients[array_rand($coefficients)];
                    $b = $coefficients[array_rand($coefficients)];
                    $c = $coefficients[array_rand($coefficients)];
                    $d = $coefficients[array_rand($coefficients)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables1[array_rand($variables1)];
                    $a1=$a*$a;
                    $b1=$b*$b;
                    $c1=$c*$c;
                    $exponente1=$exponente * 2 ;
                    $exponente3=$exponente2 * 2 ;
                    $doble=2*$a*$b;
                    $fraccionSimplificada = simplificarFraccion1($doble, $c);
                    $fraccionSimplificada1 = simplificarFraccion1($b, $c);
                    
                    // Formulate the binomial multiplication expression
                    $expression = "$a1$var1^$exponente1 + $fraccionSimplificada$var1^$exponente$var2^$exponente2 + \\frac{{$b1}}{{$c1}}$var2^$exponente3";
                    

                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                    
                    $result = "($a$var1 + $fraccionSimplificada1$var2^$exponente2)^3 ";
                      }
                    else
                    {
                    $term1 = $var1 .'^'.$exponente;

                    $result = "($a$term1 + $fraccionSimplificada1$var2^$exponente2)^3 ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }

                for ($i = 1; $i <= $n; $i++) {
                    list($multiplication, $result) = generateBinomialMultiplicationd();
                    echo "<div class='card mb-3'>";
                    echo "<div class='card-body'>";
                    echo "<h5 class='card-title'>Ejercicio $i</h5>";
                    //echo "<p class='card-text'> \( $multiplication \)</p>";
                    echo "<p class='card-text'>B \( $result \)</p>";
                    echo "</div>";
                    echo "</div>";
                }
            ?>
        </div>
    </div>
    <!-- MathJax -->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
     <?php include 'subir.php'; ?>
</body>
</html>

