<!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">Producto de binomios con un término común</h3>
    <h6 class="mb-4">Aplicar el producto notable en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
            $n = 15;
            $n = round($n);
                function generateBinomialMultiplication() {
                    $sorteo = range(1, 4);
                    $coefficients = range(1, 10);
                    $coefficients2 = range(1, 10);
                    $coefficients3= range(11, 20);
                    $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 = $coefficients2[array_rand($coefficients2)];
                    $c = $coefficients3[array_rand($coefficients3)];
                    $d = $coefficients[array_rand($coefficients)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                    $sorteo = $sorteo[array_rand($sorteo)];
                    $a1=$a*$a;
                    $b1=$b*$b;
                    $exponente1=$exponente * 2 ;
                    $doble=2*$a*$b ;
//echo $sorteo;
                    // Formulate the binomial multiplication expression
                     if ($sorteo == 1){
                    $d=$b+$c;
                    $e=$b*$c;

                   
                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                     $expression = "($var1 + $b)($var1 + $c)";
                    $result = "$var1^2  + $d$var1 + $e ";

                      }
                    else
                    {
                    $expression = "($var1^$exponente + $b)($var1^$exponente + $c)";
                    $term1 = $var1 .'^'.$exponente;

                    $result = "$var1^$exponente1 + $d$var1^$exponente + $e ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }

                if ($sorteo == 2){
                     $d=$b-$c;
                    $e=$b*$c;
                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                     $expression = "($var1 + $b)($var1 - $c)";
                    $result = "$var1^2  $d$var1 - $e ";

                      }
                    else
                    {
                    $expression = "($var1^$exponente + $b)($var1^$exponente - $c)";
                    $term1 = $var1 .'^'.$exponente;

                    $result = "$var1^$exponente1  $d$var1^$exponente - $e ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }

                 if ($sorteo == 4){
                     $d=-$b+$c;
                    $e=$b*$c;
                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                     $expression = "($var1 + $b)($var1 - $c)";
                    $result = "$var1^2 + $d$var1 - $e ";

                      }
                    else
                    {
                    $expression = "($var1^$exponente - $b)($var1^$exponente + $c)";
                    $term1 = $var1 .'^'.$exponente;

                    $result = "$var1^$exponente1  + $d$var1^$exponente - $e ";
                    }    
                    

                    // Combine terms into a single result string
                    

                    return [$expression, $result];
                }
            

            if ($sorteo == 3){
                     $d=-$b+$c;
                    $e=$b*$c;
                    // Calculate the result using distributive property
                    if ($exponente == 1) 
                    {
                     $expression = "($var1 - $b)($var1 + $c)";
                    $result = "$var1^2 + $d$var1 - $e ";

                      }
                    else
                    {
                    $expression = "($var1^$exponente - $b)($var1^$exponente + $c)";
                    $term1 = $var1 .'^'.$exponente;

                    $result = "$var1^$exponente1 + $d$var1^$exponente - $e ";
                    }    
                    

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


