<!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">Trinomio cuadrado perfecto por suma y resta</h3>
    <h6 class="mb-4">Factorar en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
                function generateBinomialMultiplication() {
                    $coefficients = range(1, 10);
                    $exponente = range(1, 4);
                    $cu = [2,4];
                    $variables = ['x', 'y', 'z', 'a', 'b', 'c'];
                    $ca = [4,9,16,25,36,49,64,81,100,121];
                    $cb = [4,9,16,25,36,49,64,81,100,121];
                    $variables = ['x', 'y', 'z', 'a', 'b', 'c'];

                    // Generate random coefficients and variables for the terms
                    $exponente = $exponente[array_rand($exponente)];
                    $exponente1 = $cu[array_rand($cu)];
                    $a = $coefficients[array_rand($coefficients)];
                    $b = $coefficients[array_rand($coefficients)];
                    $m = $ca[array_rand($ca)];
                    $n = $cb[array_rand($cb)];
                    $d = $coefficients[array_rand($coefficients)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                    $a1=$a*$a;
                    $b1=$b*$b;
                    $c1=sqrt($m);
                    $c2=$m;
                    $exponente2=$exponente1 * 2 ;
                    $doble=2*$a*$b-$c2 ;

                    // Formulate the binomial multiplication expression
                    
                    if ($doble <0 )
                    {
                    $expression = "$a1$var1^$exponente2  $doble$var1^$exponente1 + $b1";

                    }
                    else
                    {
                    $expression = "$a1$var1^$exponente2 + $doble$var1^$exponente1 + $b1";

                    }
                   
                    

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

                    $result = "($a$term1 + $c1$var1^2 + $b) ($a$term1 - $c1$var1^2 + $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'>Resultado: \( $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>
    </main>
    <?php include 'subir.php'; ?>
</body>
</html>








