<commit_before><!DOCTYPE html>
<html>
<head>
  <title>math.js | plot</title>
  <meta charset="utf-8">


  <!-- load http://maurizzzio.github.io/function-plot/ -->
  <script src="js/d3.min.js"></script>
  <script src="js/function-plot.js"></script>
  <script src="js/math.js"></script>
  <style type="text/css" rel="stylesheet" href="css/bootstrap.css"></style>
  <style type="text/css" rel="stylesheet" href="css/bootstrap-theme.css"></style>

  <style>
    input[type=text] {
      width: 300px;
    }
    input {
      padding: 6px;
    }
    body, html, input {
      font-family: sans-serif;
      font-size: 11pt;

    }
    form {
      margin: 20px 0;
    }
  </style>
</head>
<body>

<form id="graph-form">
  <label for="eq">Digite a equação:</label>
  <input type="text" id="eq" placeholder="4 * sin(x) + 5 * cos(x/2)" />
  <br>
  <input type="submit" value="Plotar gráfico" />
</form>

<form id="limit-form">
  <label for="eq">Digite o valor para calcular o limite:</label>
  <input type="text" id="x-to-limit" placeholder="2" />
  <br>
  <input type="submit" name="limit" value="Calcular Limite">
</form>

<div id="plot"></div>
<p id="limit-result"></p>

<p>
  Plot library: <a href="https://github.com/maurizzzio/function-plot">https://github.com/maurizzzio/function-plot</a>
</p>
<script type="text/javascript" src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/Ratio-0.4.1.min.js"></script>
<script type="text/javascript" src="js/nerdamer.core.js"></script>
<script type="text/javascript" src="js/Calculus.js"></script>

<script>


  function calculateLimit (equation, xToLimit){
    parser = math.parser();

    if (equation.indexOf('/') >=0){
      // temos que pegar a equação antes da barra e a equação depois da barra para dar eval separado
      // result = numerador + '/'+ denominador
      // em seguida mandamos o Ratio simplificar..\

      // separamos as equações
      numerador   = equation.split("/")[0].replace("(","").replace(")","");
      denominador = equation.split("/")[1].replace("(","").replace(")","");

      // validamos e calculamos os valores dos limites
      numerador   = parser.eval("f(x)="+numerador);
      numerador   = parser.eval("f("+xToLimit+")");

      denominador = parser.eval("f(x)="+denominador);
      denominador = parser.eval("f("+xToLimit+")");

      // montamos o resultado
      result = numerador + "/" + denominador;
    }
    else{
      result = parser.eval("f(x)="+equation);
      result = parser.eval("f("+xToLimit+")");
    }

    if (!Number.isInteger(result) && typeof result != "string"){
      // result = result.toString().substring(2);
      // result = decimalToFraction(result);
      // usar o Ratio
      result = Ratio.parse(result).simplify();
    }else if (isNaN(result)){
      // deu indeterminação
      result = "0/0 (Indeterminação matemátic)";
    }

    return result;
  }

  function drawGraph(equationId){
    try {
      functionPlot({
        target: '#plot',
        data: [{
          fn: document.querySelector(equationId).value,
          sampler: 'builtIn',  // this will make function-plot use the evaluator of math.js
          graphType: 'polyline'
        }]
      });
    }
    catch (err) {
      console.log(err);
      alert(err);
    }
  }
  /*
  */
  function calculateDerivative (equation, symbol){
    var derivative = nerdamer (`diff(${equation},x)`);
    console.log(`Derivada de ${equation} é : ${derivative.text()}`)
  }

  function invertFunction (equation){
    var invert = nerdamer().invert(equation);
    console.log(invert);
  }
  document.getElementById('graph-form').onsubmit = function (event) {

    event.preventDefault();
    drawGraph("#eq");

    // document.querySelector("#limit-result").textContent = `O valor do limite é: ${calculateLimit.calculate()}`;
  };

  document.getElementById('limit-form').onsubmit = function (event) {

    event.preventDefault();
    let equation = document.querySelector("#eq").value;
    let xToLimit = document.querySelector("#x-to-limit").value;
    let limit = calculateLimit(equation, xToLimit);
    document.querySelector("#limit-result").textContent = `O resultado do limite é: ${limit}`;
    calculateDerivative(equation)
    invertFunction(equation);<commit_msg>Delete de função de inverter as equações<commit_after><!DOCTYPE html>
<html>
<head>
  <title>math.js | plot</title>
  <meta charset="utf-8">


  <!-- load http://maurizzzio.github.io/function-plot/ -->
  <script src="js/d3.min.js"></script>
  <script src="js/function-plot.js"></script>
  <script src="js/math.js"></script>
  <style type="text/css" rel="stylesheet" href="css/bootstrap.css"></style>
  <style type="text/css" rel="stylesheet" href="css/bootstrap-theme.css"></style>

  <style>
    input[type=text] {
      width: 300px;
    }
    input {
      padding: 6px;
    }
    body, html, input {
      font-family: sans-serif;
      font-size: 11pt;

    }
    form {
      margin: 20px 0;
    }
  </style>
</head>
<body>

<form id="graph-form">
  <label for="eq">Digite a equação:</label>
  <input type="text" id="eq" placeholder="4 * sin(x) + 5 * cos(x/2)" />
  <br>
  <input type="submit" value="Plotar gráfico" />
</form>

<form id="limit-form">
  <label for="eq">Digite o valor para calcular o limite:</label>
  <input type="text" id="x-to-limit" placeholder="2" />
  <br>
  <input type="submit" name="limit" value="Calcular Limite">
</form>

<div id="plot"></div>
<p id="limit-result"></p>

<p>
  Plot library: <a href="https://github.com/maurizzzio/function-plot">https://github.com/maurizzzio/function-plot</a>
</p>
<script type="text/javascript" src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/Ratio-0.4.1.min.js"></script>
<script type="text/javascript" src="js/nerdamer.core.js"></script>
<script type="text/javascript" src="js/Calculus.js"></script>

<script>


  function calculateLimit (equation, xToLimit){
    parser = math.parser();

    if (equation.indexOf('/') >=0){
      // temos que pegar a equação antes da barra e a equação depois da barra para dar eval separado
      // result = numerador + '/'+ denominador
      // em seguida mandamos o Ratio simplificar..\

      // separamos as equações
      numerador   = equation.split("/")[0].replace("(","").replace(")","");
      denominador = equation.split("/")[1].replace("(","").replace(")","");

      // validamos e calculamos os valores dos limites
      numerador   = parser.eval("f(x)="+numerador);
      numerador   = parser.eval("f("+xToLimit+")");

      denominador = parser.eval("f(x)="+denominador);
      denominador = parser.eval("f("+xToLimit+")");

      // montamos o resultado
      result = numerador + "/" + denominador;
    }
    else{
      result = parser.eval("f(x)="+equation);
      result = parser.eval("f("+xToLimit+")");
    }

    if (!Number.isInteger(result) && typeof result != "string"){
      // result = result.toString().substring(2);
      // result = decimalToFraction(result);
      // usar o Ratio
      result = Ratio.parse(result).simplify();
    }else if (isNaN(result)){
      // deu indeterminação
      result = "0/0 (Indeterminação matemátic)";
    }

    return result;
  }

  function drawGraph(equationId){
    try {
      functionPlot({
        target: '#plot',
        data: [{
          fn: document.querySelector(equationId).value,
          sampler: 'builtIn',  // this will make function-plot use the evaluator of math.js
          graphType: 'polyline'
        }]
      });
    }
    catch (err) {
      console.log(err);
      alert(err);
    }
  }
  /*
  */
  function calculateDerivative (equation, symbol){
    var derivative = nerdamer (`diff(${equation},x)`);
    console.log(`Derivada de ${equation} é : ${derivative.text()}`)
  }

  // function invertFunction (equation){
  //   var invert = nerdamer().invert(equation);
  //   console.log(invert);
  // }
  document.getElementById('graph-form').onsubmit = function (event) {

    event.preventDefault();
    drawGraph("#eq");

    // document.querySelector("#limit-result").textContent = `O valor do limite é: ${calculateLimit.calculate()}`;
  };

  document.getElementById('limit-form').onsubmit = function (event) {

    event.preventDefault();
    let equation = document.querySelector("#eq").value;
    let xToLimit = document.querySelector("#x-to-limit").value;
    let limit = calculateLimit(equation, xToLimit);
    document.querySelector("#limit-result").textContent = `O resultado do limite é: ${limit}`;
    calculateDerivative(equation)
    invertFunction(equation);
{'fraction_non_alphanumeric': 0.18493070921159893, 'fraction_numerical': 0.00558984511470828, 'mean_word_length': 3.2242990654205608, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 113, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7163733', 'n_tokens_mistral': 2895, 'n_tokens_neox': 2823, 'n_words': 573}