Back to index

texmacs  1.0.7.15
Functions
math_tree.hpp File Reference
#include "tree.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree neg (tree t1)
tree add (tree t1, tree t2)
tree sub (tree t1, tree t2)
tree mul (tree t1, tree t2)
tree div (tree t1, tree t2)
tree sqrt (tree t)
tree exp (tree t)
tree log (tree t)
tree pow (tree t1, tree t2)
tree sin (tree t)
tree cos (tree t)
tree tan (tree t)
string as_math_string (tree t)
template<typename T >
void parse (tree t, T &result)
void parse (tree t, double &result)
template<typename T >
T parse_as (tree t)

Function Documentation

tree add ( tree  t1,
tree  t2 
)

Definition at line 25 of file math_tree.cpp.

                       {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) + as_double (t2));
  if (t1 == "0") return t2;
  if (t2 == "0") return t1;
  return tree (PLUS, t1, t2);
}

Here is the call graph for this function:

Definition at line 181 of file math_tree.cpp.

                        {
  string r;
  math_print (r, t, 0);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree cos ( tree  t)

Definition at line 90 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (cos (as_double (t)));
  return tree (COS, t);
}

Here is the call graph for this function:

tree div ( tree  t1,
tree  t2 
)

Definition at line 53 of file math_tree.cpp.

                       {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) / as_double (t2));
  if (t1 == "0") return "0";
  if (t2 == "1") return t1;
  return tree (OVER, t1, t2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree exp ( tree  t)

Definition at line 68 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (exp (as_double (t)));
  return tree (EXP, t);
}

Here is the call graph for this function:

tree log ( tree  t)

Definition at line 74 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (log (as_double (t)));
  return tree (LOG, t);
}

Here is the call graph for this function:

tree mul ( tree  t1,
tree  t2 
)

Definition at line 43 of file math_tree.cpp.

                       {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) * as_double (t2));
  if (t1 == "0" || t2 == "0") return "0";
  if (t1 == "1") return t2;
  if (t2 == "1") return t1;
  return tree (TIMES, t1, t2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree neg ( tree  t1)

Definition at line 19 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (-as_double (t));
  return tree (MINUS, t);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
void parse ( tree  t,
T result 
)

Definition at line 33 of file math_tree.hpp.

                          {
  FAILED ("unsupported type");
}
void parse ( tree  t,
double &  result 
) [inline]

Definition at line 38 of file math_tree.hpp.

                               {
  ASSERT (is_double (t), "not a double");
  result= as_double (t);
}

Here is the call graph for this function:

template<typename T >
T parse_as ( tree  t)

Definition at line 44 of file math_tree.hpp.

                  {
  switch (L(t)) {
  case PLUS:
    return parse_as<T> (t[0]) + parse_as<T> (t[1]);
  case MINUS:
    if (N(t) == 1) return -parse_as<T> (t[0]);
    else return parse_as<T> (t[0]) - parse_as<T> (t[1]);
  case TIMES:
    return parse_as<T> (t[0]) * parse_as<T> (t[1]);
  case OVER:
    return parse_as<T> (t[0]) / parse_as<T> (t[1]);
  case MATH_SQRT:
    return sqrt (parse_as<T> (t[0]));
  case EXP:
    return exp (parse_as<T> (t[0]));
  case LOG:
    return log (parse_as<T> (t[0]));
  case POW:
    return pow (parse_as<T> (t[0]), parse_as<T> (t[1]));
  case COS:
    return cos (parse_as<T> (t[0]));
  case SIN:
    return sin (parse_as<T> (t[0]));
  case TAN:
    return tan (parse_as<T> (t[0]));
  default:
    {
      T result;
      parse (t, result);
      return result;
    }
  }
}

Here is the call graph for this function:

tree pow ( tree  t1,
tree  t2 
)

Definition at line 80 of file math_tree.cpp.

                       {
  if (is_double (t1) && is_double (t2))
    return as_tree (pow (as_double (t1), as_double (t2)));
  if (t1 == "0" || t1 == "1") return t1;
  if (t2 == "0") return "1";
  if (t2 == "1") return t1;
  return tree (POW, t1, t2);
}

Here is the call graph for this function:

tree sin ( tree  t)

Definition at line 96 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (sin (as_double (t)));
  return tree (SIN, t);
}

Here is the call graph for this function:

tree sqrt ( tree  t)

Definition at line 62 of file math_tree.cpp.

              {
  if (is_double (t)) return as_tree (sqrt (as_double (t)));
  return tree (MATH_SQRT, t);
}

Here is the call graph for this function:

tree sub ( tree  t1,
tree  t2 
)

Definition at line 34 of file math_tree.cpp.

                       {
  if (is_double (t1) && is_double (t2))
    return as_tree (as_double (t1) - as_double (t2));
  if (t1 == "0") return tree (MINUS, t2);
  if (t2 == "0") return t1;
  return tree (MINUS, t1, t2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree tan ( tree  t)

Definition at line 102 of file math_tree.cpp.

             {
  if (is_double (t)) return as_tree (tan (as_double (t)));
  return tree (TAN, t);
}

Here is the call graph for this function: