<!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 de la forma  \(ax^2 + bx + c\) </h3>
    <h6 class="mb-4">Factorar en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
                function generateBinomialMultiplication() {
                    

                    $sorteo = range(1, 2);
                    

                    $d1=[-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,1,2,3,4,5,6,7,8,9,10];
                    $d2=[-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,1,2,3,4,5,6,7,8,9,10];

                    $a1=range(1, 2);
                    $a2=range(2, 3);



                    $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)];
                    $a1 = $a1[array_rand($a1)];
                    $a2 = $a2[array_rand($a2)];
                    $d1= $d1[array_rand($d1)];
                    $d2= $d2[array_rand($d2)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                    $sorteo = $sorteo[array_rand($sorteo)];
                    // Formulate the binomial multiplication expression
                    
                    if ($d1>0 and $d2>0){
                    $a=$a1*$a2;
                    $b=$a1*$d2+$a2*$d1;
                    $c=$d1*$d2;
                   
                   $expression = "($a1$var1 + $d1)($a2$var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";

                   if ($a1 == 1) 
                    {
                    $expression = "($var1 + $d1)($a2$var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";

                      }
                    if ($a2 == 1) 
                    {
                    $expression = "($a1$var1 + $d1)($var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";

                      }
                    if ($a1 == 1 and $a2 == 1) 
                    {
                    $expression = "($var1 + $d1)($var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";

                      }
                   
                    return [$expression, $result];
                    }

                    




                    if ($d1<0 and $d2>0){
                    $a=$a1*$a2;
                    $b=$a1*$d2+$a2*$d1;
                    $c=$d1*$d2;
                   
                   if ($b>0) {
                   $expression = "($a1$var1  $d1)($a2$var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1  $c ";}
                   else
                   {
                    $expression = "($a1$var1  $d1)($a2$var1+ $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}
                   

                   if ($a1 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($var1  $d1)($a2$var1+ $d2)";
                    $result = "$a$var1^2 + $b$var1  $c ";}
                    else {
                    $expression = "($var1  $d1)($a2$var1+ $d2)";
                    $result = "$a$var1^2  $b$var1  $c";}
                    }

                     
                    if ($a2 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($a1$var1  $d1)($var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1  $c ";}
                   else {
                    $expression = "($a1$var1  $d1)($var1+ $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}
                   }

                    
                    if ($a1 == 1 and $a2 == 1) 
                    {
                        if ($b>0) {
                    $expression = "($var1  $d1)($var1+ $d2)";
                   $result = "$a$var1^2 + $b$var1  $c ";}
                   else{
                    $expression = "($var1  $d1)($var1+ $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}

                   }

                      
                   
                    return [$expression, $result];
                    }



if ($d1>0 and $d2<0){
                    $a=$a1*$a2;
                    $b=$a1*$d2+$a2*$d1;
                    $c=$d1*$d2;
                   
                   if ($b>0) {
                   $expression = "($a1$var1 + $d1)($a2$var1  $d2)";
                   $result = "$a$var1^2 + $b$var1  $c ";}
                   else
                   {
                    $expression = "($a1$var1 + $d1)($a2$var1  $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}
                   

                   if ($a1 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($var1 + $d1)($a2$var1  $d2)";
                    $result = "$a$var1^2 + $b$var1  $c ";}
                    else {
                    $expression = "($var1 + $d1)($a2$var1  $d2)";
                    $result = "$a$var1^2  $b$var1  $c ";}
                    }

                     
                    if ($a2 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($a1$var1 + $d1)($var1  $d2)";
                   $result = "($a$var1^2 + $b$var1  $c) ";}
                   else {
                    $expression = "($a1$var1 + $d1)($var1  $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}
                   }

                    
                    if ($a1 == 1 and $a2 == 1) 
                    {
                        if ($b>0) {
                    $expression = "($var1 + $d1)($var1  $d2)";
                   $result = "($a$var1^2 + $b$var1  $c) ";}
                   else{
                    $expression = "($var1 + $d1)($var1 $d2)";
                   $result = "$a$var1^2  $b$var1  $c ";}

                   }

                      
                   
                    return [$expression, $result];
                    }
if ($d1<0 and $d2<0){
                    $a=$a1*$a2;
                    $b=$a1*$d2+$a2*$d1;
                    $c=$d1*$d2;
                   
                   if ($b>0) {
                   $expression = "($a1$var1  $d1)($a2$var1  $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";}
                   else
                   {
                    $expression = "($a1$var1  $d1)($a2$var1  $d2)";
                   $result = "$a$var1^2  $b$var1 + $c ";}
                   

                   if ($a1 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($var1  $d1)($a2$var1  $d2)";
                    $result = "$a$var1^2 + $b$var1 + $c ";}
                    else {
                    $expression = "($var1  $d1)($a2$var1 $d2)";
                    $result = "($a$var1^2  $b$var1 + $c) ";}
                    }

                     
                    if ($a2 == 1) 
                    {
                    if ($b>0) {
                    $expression = "($a1$var1  $d1)($var1  $d2)";
                   $result = "$a$var1^2 + $b$var1 + $c ";}
                   else {
                    $expression = "($a1$var1  $d1)($var1  $d2)";
                   $result = "$a$var1^2  $b$var1 + $c ";}
                   }

                    
                    if ($a1 == 1 and $a2 == 1) 
                    {
                        if ($b>0) {
                    $expression = "($var1  $d1)($var1  $d2)";
                   $result = "($a$var1^2 + $b$var1 + $c) ";}
                   else{
                    $expression = "($var1  $d1)($var1 $d2)";
                   $result = "$a$var1^2  $b$var1 + $c ";}

                   }

                      
                   
                    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'>Multiplicación: \( $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>


