<!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">Diferencia de cuadrados</h3>
    <h6 class="mb-4">Factorar en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
            $n=15;
            $n=round($n/2)+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 ;

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

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

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

                    // 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>

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

                    $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)];
                    $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;
                    $exponente1=$exponente * 2 ;
                    $exponente3=$exponente2 * 2 ;

                    // Formulate the binomial multiplication expression
                    $expression = "$a1$var1^$exponente1 - $b1$var2^$exponente3";
                    

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

                    $result = "($a$term1 + $b$term2)($a$term1 - $b$term2) ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    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>
     <?php include 'subir.php'; ?>
</body>
</html>
