unsigned serial;
};
-// utility macros
+// utility functions/macros
+inline const function &ex_to_function(const ex &e)
+{
+ return static_cast<const function &>(*e.bp);
+}
#ifndef NO_NAMESPACE_GINAC
GINAC_ASSERT(serial<registered_functions().size());
if (registered_functions()[serial].derivative_f==0) {
- throw(std::logic_error(string("function::pderivative(") + registered_functions()[serial].name + "): no diff function defined"));
+ return Derivative(*this, diff_param);
}
switch (registered_functions()[serial].nparams) {
// the following lines have been generated for max. ${maxargs} parameters
return pseries(s, point, new_seq);
}
+// Differentiation is handled in function::derivative because of its special requirements
+
REGISTER_FUNCTION(Order, eval_func(Order_eval).
series_func(Order_series));
+//////////
+// Inert differentiation
+//////////
+
+static ex Diff_eval(const ex & f, const ex & x)
+{
+ return Diff(f, x).hold();
+}
+
+static ex Diff_deriv(const ex & f, const ex & x, unsigned deriv_param)
+{
+ GINAC_ASSERT(deriv_param == 0 || deriv_param == 1);
+ if (deriv_param == 1)
+ return Diff(Diff(f, x), x);
+ else
+ return _ex0();
+}
+
+REGISTER_FUNCTION(Diff, eval_func(Diff_eval).
+ derivative_func(Diff_deriv));
+
+//////////
+// Inert partial differentiation operator
+//////////
+
+static ex Derivative_eval(const ex & f, const ex & n)
+{
+ if (is_ex_exactly_of_type(n, numeric) && ex_to_numeric(n).is_nonneg_integer()) {
+ unsigned i = ex_to_numeric(n).to_int();
+ if (is_ex_exactly_of_type(f, function)) {
+ if (i < f.nops() && is_ex_exactly_of_type(f.op(i), symbol))
+ return Diff(f, f.op(i));
+ }
+ }
+ return Derivative(f, n).hold();
+}
+
+REGISTER_FUNCTION(Derivative, eval_func(Derivative_eval));
+
//////////
// Solve linear system
//////////
/** Order term function (for truncated power series). */
DECLARE_FUNCTION_1P(Order)
+/** Inert differentiation. */
+DECLARE_FUNCTION_2P(Diff)
+
+/** Inert partial differentiation operator. */
+DECLARE_FUNCTION_2P(Derivative)
+
ex lsolve(const ex &eqns, const ex &symbols);
ex ncpower(const ex &basis, unsigned exponent);
// (a/b)^n -> {a^n, b^n}
return (new lst(power(n.op(0), exponent), power(n.op(1), exponent)))->setflag(status_flags::dynallocated);
- } else if (exponent.info(info_flags::negint)) {
+ } else if (exponent.info(info_flags::negative)) {
// (a/b)^-n -> {b^n, a^n}
return (new lst(power(n.op(1), -exponent), power(n.op(0), -exponent)))->setflag(status_flags::dynallocated);
}
} else {
+
if (exponent.info(info_flags::positive)) {
- // (a/b)^z -> {sym((a/b)^z), 1}
+ // (a/b)^x -> {sym((a/b)^x), 1}
return (new lst(replace_with_symbol(power(n.op(0) / n.op(1), exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
- } else {
+ } else if (exponent.info(info_flags::negative)) {
if (n.op(1).is_equal(_ex1())) {
} else {
- // (a/b)^-x -> {(b/a)^x, 1}
+ // (a/b)^-x -> {sym((b/a)^x), 1}
return (new lst(replace_with_symbol(power(n.op(1) / n.op(0), -exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
}
+
+ } else { // exponent not numeric
+
+ // (a/b)^x -> {sym((a/b)^x, 1}
+ return (new lst(replace_with_symbol(power(n.op(0) / n.op(1), exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
}
}
}
cout << "You should have received a copy of the GNU General Public License along with\n";
cout << "this program. If not, write to the Free Software Foundation, 675 Mass Ave,\n";
cout << "Cambridge, MA 02139, USA.\n";
-
}
| T_XYZZY {cout << "Nothing happens.\n";}
| T_INVENTORY {cout << "You're not carrying anything.\n";}