<!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">Suma de Cubos</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 generateBinomialMultiplicationb() {
                    $a = range(1, 5);
                    $b = range(1, 5);
                    $c = [1,2,3,4,5,6,7,8,9,10];
                    $d = [1,2,3,4,5,6,7,8,9,10];
                    $exponente = range(1, 3);
                    $exponente2 = range(0, 3);

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

                    // Generate random coefficients and variables for the terms
                    $exponente = $exponente[array_rand($exponente)];
                    $exponente2 = $exponente2[array_rand($exponente2)];
                    
                    $a = $a[array_rand($a)];
                    $b = $b[array_rand($b)];
                    $c = $c[array_rand($c)];
                    $d = $d[array_rand($d)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                   


                    $a1=$a*$a*$a;
                    $b1=$b*$b*$b;
                                        
                    $a2=$a*$a;
                    $b2=$b*$b;

                   
                    $exponente1=$exponente*3;
                    $exponente3=$exponente2*3;

                    $exponentea=$exponente*2;
                    $exponenteb=$exponente2*2;

                    $doble= $a*$b ;

                        if ($var1==$var2)
                        {
                            $exponente3=0;
                        }
                    if ($exponente == 1)
                    {
                    $exponente=".";
                    }
                    if ($exponente2 == 1)
                    {
                    $exponente2=".";
                    }

if ($exponente3 ==0)
                    {


                        
                       if ($a1==1)
                    {

                        $term1="$var1^$exponente1";
                        $t1="$var1^$exponente";
                        $t3="$var1^$exponentea";

                    }
                    else
                    {
                        $term1="$a1$var1^$exponente1";
                        $t1="$a$var1^$exponente";
                        $t3="$a2$var1^$exponentea";
                    }
                    if ($b1==1)
                    {
                        $term2="$b1"; 
                        $t2="$b1";
                        $t5="$b1";
                    }
                    
                    else
                    {
                        $term2="$b1"; 
                        $t2="$b";
                        $t5="$b2";
                                          
                    }
                        $t4="$doble$var1^$exponente "; 
                    // Formulate the binomial multiplication expression
                    $expression = "$term1 + $term2 ";
                    $result="($t1 + $t2)($t3 - $t4 + $t5 )";


                    }


else
                    {


                        
                       if ($a1==1)
                    {

                        $term1="$var1^$exponente1";
                        $t1="$var1^$exponente";
                        $t3="$var1^$exponentea";

                    }
                    else
                    {
                        $term1="$a1$var1^$exponente1";
                        $t1="$a$var1^$exponente";
                        $t3="$a2$var1^$exponentea";
                    }
                    if ($b1==1)
                    {
                        $term2="$var2^$exponente3"; 
                        $t2="$var2^$exponente2";
                        $t5="$var2^$exponenteb";
                    }
                    
                    else
                    {
                        $term2="$b1$var2^$exponente3"; 
                        $t2="$b$var2^$exponente2";
                        $t5="$b2$var2^$exponenteb";    
                    }
                        $t4="$doble$var1^$exponente$var2^$exponente2 "; 
                    // Formulate the binomial multiplication expression
                    $expression = "$term1 + $term2 ";
                    $result="($t1 + $t2)($t3 - $t4 + $t5 )";


                    }
                   



                   return [$expression,$result];
                }

                for ($i = 1; $i <= $n; $i++) {
                   list($multiplication, $result) = generateBinomialMultiplicationb();
                   // list($result) = generateBinomialMultiplicationb();
                    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>

<div class="container mt-5">
        <h3 class="mb-4">Resta de Cubos</h3>
    <h6 class="mb-4">Factorar en cada uno de los siguientes Ejercicios</h6>
        <div class="mt-4">
            <?php
                function generateBinomialMultiplicationa() {
                    $a = range(1, 5);
                    $b = range(1, 5);
                    $c = [1,2,3,4,5,6,7,8,9,10];
                    $d = [1,2,3,4,5,6,7,8,9,10];
                    $exponente = range(1, 3);
                    $exponente2 = range(0, 3);

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

                    // Generate random coefficients and variables for the terms
                    $exponente = $exponente[array_rand($exponente)];
                    $exponente2 = $exponente2[array_rand($exponente2)];
                    
                    $a = $a[array_rand($a)];
                    $b = $b[array_rand($b)];
                    $c = $c[array_rand($c)];
                    $d = $d[array_rand($d)];
                    $var1 = $variables[array_rand($variables)];
                    $var2 = $variables[array_rand($variables)];
                   


                    $a1=$a*$a*$a;
                    $b1=$b*$b*$b;
                                        
                    $a2=$a*$a;
                    $b2=$b*$b;

                   
                    $exponente1=$exponente*3;
                    $exponente3=$exponente2*3;

                    $exponentea=$exponente*2;
                    $exponenteb=$exponente2*2;

                    $doble= $a*$b ;

                        if ($var1==$var2)
                        {
                            $exponente3=0;
                        }
                    if ($exponente == 1)
                    {
                    $exponente=".";
                    }
                    if ($exponente2 == 1)
                    {
                    $exponente2=".";
                    }

if ($exponente3 ==0)
                    {


                        
                       if ($a1==1)
                    {

                        $term1="$var1^$exponente1";
                        $t1="$var1^$exponente";
                        $t3="$var1^$exponentea";

                    }
                    else
                    {
                        $term1="$a1$var1^$exponente1";
                        $t1="$a$var1^$exponente";
                        $t3="$a2$var1^$exponentea";
                    }
                    if ($b1==1)
                    {
                        $term2="$b1"; 
                        $t2="$b1";
                        $t5="$b1";
                    }
                    
                    else
                    {
                        $term2="$b1"; 
                        $t2="$b";
                        $t5="$b2";
                                          
                    }
                        $t4="$doble$var1^$exponente "; 
                    // Formulate the binomial multiplication expression
                    $expression = "$term1 - $term2 ";
                    $result="($t1 + $t2)($t3 - $t4 + $t5 )";


                    }


else
                    {


                        
                       if ($a1==1)
                    {

                        $term1="$var1^$exponente1";
                        $t1="$var1^$exponente";
                        $t3="$var1^$exponentea";

                    }
                    else
                    {
                        $term1="$a1$var1^$exponente1";
                        $t1="$a$var1^$exponente";
                        $t3="$a2$var1^$exponentea";
                    }
                    if ($b1==1)
                    {
                        $term2="$var2^$exponente3"; 
                        $t2="$var2^$exponente2";
                        $t5="$var2^$exponenteb";
                    }
                    
                    else
                    {
                        $term2="$b1$var2^$exponente3"; 
                        $t2="$b$var2^$exponente2";
                        $t5="$b2$var2^$exponenteb";    
                    }
                        $t4="$doble$var1^$exponente$var2^$exponente2 "; 
                    // Formulate the binomial multiplication expression
                    $expression = "$term1 - $term2 ";
                    $result="($t1 + $t2)($t3 - $t4 + $t5 )";


                    }
                   



                   return [$expression,$result];
                }

                for ($i = 1; $i <= $n; $i++) {
                   list($multiplication, $result) = generateBinomialMultiplicationa();
                   // list($result) = generateBinomialMultiplicationb();
                    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>
