X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Ffunction.cppy;h=6739eb9ebafdf6ebf8108e4b3a30125f0493ef78;hp=0a521e11a19e333d3ca0b3769248815018de1a05;hb=3d5c30286146e192d4c22cbb989997cdfe306200;hpb=faf8c206bdcd01eee758103d56b83a634f787e7a diff --git a/ginac/function.cppy b/ginac/function.cppy index 0a521e11..6739eb9e 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -7,7 +7,7 @@ * Please do not modify it directly, edit function.cppy instead! * function.py options: maxargs=@maxargs@ * - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,6 @@ #include "power.h" #include "archive.h" #include "inifcns.h" -#include "tostring.h" #include "utils.h" #include "hash_seed.h" #include "remember.h" @@ -76,11 +75,11 @@ function_options::~function_options() void function_options::initialize() { - set_name("unnamed_function", "\\\\mbox{unnamed}"); + set_name("unnamed_function", "\\mbox{unnamed}"); nparams = 0; eval_f = evalf_f = real_part_f = imag_part_f = conjugate_f = expand_f - = derivative_f = expl_derivative_f = power_f = series_f = 0; - info_f = 0; + = derivative_f = expl_derivative_f = power_f = series_f = nullptr; + info_f = nullptr; evalf_params_first = true; use_return_type = false; eval_use_exvector_args = false; @@ -105,7 +104,7 @@ function_options & function_options::set_name(std::string const & n, { name = n; if (tn==std::string()) - TeX_name = "\\\\mbox{"+name+"}"; + TeX_name = "\\mbox{"+name+"}"; else TeX_name = tn; return *this; @@ -143,7 +142,7 @@ function_options & function_options::set_return_type(unsigned rt, const return_t { use_return_type = true; return_type = rt; - if (rtt != 0) + if (rtt != nullptr) return_type_tinfo = *rtt; else return_type_tinfo = make_return_type_t(); @@ -229,7 +228,7 @@ function::function(unsigned ser) : serial(ser) // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): function::function(unsigned ser, @seq('const ex & param%(n)d', N)@) - : exprseq(@seq('param%(n)d', N)@), serial(ser) + : exprseq{@seq('param%(n)d', N)@}, serial(ser) { } --- @@ -242,8 +241,8 @@ function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser) clearflag(status_flags::evaluated); } -function::function(unsigned ser, const exvector & v, bool discardable) - : exprseq(v,discardable), serial(ser) +function::function(unsigned ser, const exvector & v) + : exprseq(v), serial(ser) { } @@ -260,18 +259,20 @@ function::function(unsigned ser, exvector && v) void function::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); - // Find serial number by function name + // Find serial number by function name and number of parameters + unsigned np = seq.size(); std::string s; if (n.find_string("name", s)) { unsigned int ser = 0; for (auto & it : registered_functions()) { - if (s == it.name) { + if (s == it.name && np == registered_functions()[ser].nparams) { serial = ser; return; } ++ser; } - throw (std::runtime_error("unknown function '" + s + "' in archive")); + throw (std::runtime_error("unknown function '" + s + + "' with " + std::to_string(np) + " parameters in archive")); } else throw (std::runtime_error("unnamed function in archive")); } @@ -363,11 +364,10 @@ next_context: } } -ex function::eval(int level) const +ex function::eval() const { - if (level>1) { - // first evaluate children, then we will end up here again - return function(serial,evalchildren(level)); + if (flags & status_flags::evaluated) { + return *this; } GINAC_ASSERT(serialhold(); } @@ -416,26 +416,23 @@ ex function::eval(int level) const return eval_result; } -ex function::evalf(int level) const +ex function::evalf() const { GINAC_ASSERT(serialsetflag(status_flags::dynallocated | - status_flags::evaluated); + return dynallocate(*this, power_param).setflag(status_flags::evaluated); } ex function::expand(unsigned options) const @@ -844,8 +840,8 @@ void function::store_remember_table(ex const & result) const unsigned function::register_new(function_options const & opt) { size_t same_name = 0; - for (size_t i=0; i