#include "symbol.h"
#include "utils.h"
-#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
//////////
// absolute value
if (is_ex_exactly_of_type(arg, numeric))
return csgn(ex_to_numeric(arg));
- else if (is_ex_exactly_of_type(arg, mul)) {
+ else if (is_ex_of_type(arg, mul) &&
+ is_ex_of_type(arg.op(arg.nops()-1),numeric)) {
numeric oc = ex_to_numeric(arg.op(arg.nops()-1));
if (oc.is_real()) {
if (oc > 0)
return -csgn(I*arg/oc).hold();
}
}
-
+
return csgn(arg).hold();
}
REGISTER_FUNCTION(eta, eval_func(eta_eval).
evalf_func(eta_evalf).
- series_func(eta_series));
+ series_func(eta_series).
+ latex_name("\\eta"));
//////////
REGISTER_FUNCTION(Li2, eval_func(Li2_eval).
evalf_func(Li2_evalf).
derivative_func(Li2_deriv).
- series_func(Li2_series));
+ series_func(Li2_series).
+ latex_name("\\mbox{Li}_2"));
//////////
// trilogarithm
return Li3(x).hold();
}
-REGISTER_FUNCTION(Li3, eval_func(Li3_eval));
+REGISTER_FUNCTION(Li3, eval_func(Li3_eval).
+ latex_name("\\mbox{Li}_3"));
//////////
// factorial
// Differentiation is handled in function::derivative because of its special requirements
REGISTER_FUNCTION(Order, eval_func(Order_eval).
- series_func(Order_series));
+ series_func(Order_series).
+ latex_name("\\mathcal{O}"));
//////////
// Inert partial differentiation operator
for (unsigned c=0; c<symbols.nops(); c++) {
ex co = eq.coeff(ex_to_symbol(symbols.op(c)),1);
linpart -= co*symbols.op(c);
- sys.set(r,c,co);
+ sys(r,c) = co;
}
linpart = linpart.expand();
- rhs.set(r,0,-linpart);
+ rhs(r,0) = -linpart;
}
// test if system is linear and fill vars matrix
for (unsigned i=0; i<symbols.nops(); i++) {
- vars.set(i,0,symbols.op(i));
+ vars(i,0) = symbols.op(i);
if (sys.has(symbols.op(i)))
throw(std::logic_error("lsolve: system is not linear"));
if (rhs.has(symbols.op(i)))
return sollist;
}
-/** non-commutative power. */
-ex ncpower(const ex &basis, unsigned exponent)
+// Symmetrize/antisymmetrize over a vector of objects
+static ex symm(const ex & e, exvector::const_iterator first, exvector::const_iterator last, bool asymmetric)
{
- if (exponent==0) {
- return _ex1();
+ // Need at least 2 objects for this operation
+ int num = last - first;
+ if (num < 2)
+ return e;
+
+ // Sort object vector, transform it into a list, and make a copy so we
+ // will know which objects get substituted for which
+ exlist iv_lst;
+ iv_lst.insert(iv_lst.begin(), first, last);
+ shaker_sort(iv_lst.begin(), iv_lst.end(), ex_is_less());
+ lst orig_lst(iv_lst);
+
+ // Loop over all permutations (the first permutation, which is the
+ // identity, is unrolled)
+ ex sum = e;
+ while (next_permutation(iv_lst.begin(), iv_lst.end(), ex_is_less())) {
+ ex term = e.subs(orig_lst, lst(iv_lst));
+ if (asymmetric) {
+ exlist test_lst = iv_lst;
+ term *= permutation_sign(test_lst.begin(), test_lst.end(), ex_is_less());
+ }
+ sum += term;
}
+ return sum / factorial(numeric(num));
+}
+
+ex symmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last)
+{
+ return symm(e, first, last, false);
+}
+
+ex antisymmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last)
+{
+ return symm(e, first, last, true);
+}
+/** Symmetrize expression over a list of objects (symbols, indices). */
+ex ex::symmetrize(const lst & l) const
+{
exvector v;
- v.reserve(exponent);
- for (unsigned i=0; i<exponent; ++i) {
- v.push_back(basis);
- }
+ v.reserve(l.nops());
+ for (unsigned i=0; i<l.nops(); i++)
+ v.push_back(l.op(i));
+ return symm(*this, v.begin(), v.end(), false);
+}
- return ncmul(v,1);
+/** Antisymmetrize expression over a list of objects (symbols, indices). */
+ex ex::antisymmetrize(const lst & l) const
+{
+ exvector v;
+ v.reserve(l.nops());
+ for (unsigned i=0; i<l.nops(); i++)
+ v.push_back(l.op(i));
+ return symm(*this, v.begin(), v.end(), true);
}
/** Force inclusion of functions from initcns_gamma and inifcns_zeta
unsigned force_include_tgamma = function_index_tgamma;
unsigned force_include_zeta1 = function_index_zeta1;
-#ifndef NO_NAMESPACE_GINAC
} // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC