Richard Kreckel [Sun, 6 Aug 2023 17:27:51 +0000 (19:27 +0200)]
Fix series of positive powers of polynomials.
Before calling pseries::power_const(), make sure the basis series has
sufficient terms. In particular, do not shrink the order of expansion
- only grow it.
Fix various hairy problems in pseries::power_const() when a polynomial
is raised to a positive integer power.
(The special cases here can actually also be computed by Taylor
expansion but the fixes should be more general.)
Also add test cases.
Thanks to Vitaly Magerya <vmagerya@gmail.com> for reporting this.
Vitaly Magerya [Wed, 21 Jun 2023 18:48:36 +0000 (20:48 +0200)]
[PATCH] Make ginsh evaluate line-by-line in non-interactive mode.
When used interactively ginsh consumes the input line-by-line, so
if a complete expression is entered it is enough to end the line
to get an evaluated result. In the non-interative mode (i.e. if
the input is not a tty) the input is consumed in blocks, making
it impossible to use ginsh as a subprocess.
This patch makes the non-interactive mode reuse the same line
parsing logic as the interactive mode (without readline), but skips
printing the "> " prompt, preserving the backward compatibility.
Richard Kreckel [Sat, 11 Feb 2023 23:09:48 +0000 (00:09 +0100)]
[DOC] Fix build of reference.pdf.
This is obnoxious: It is 2023, the ≥ character is in Unicode since
1993, and UTF-8 is ubiquitous. Yet, pdfLaTeX balks at this.
Maybe the right fix would be to switch to LuaLaTeX. Alas, that doesn't
seem to have reached the necessary maturity yet:
<https://tug.org/pipermail/luatex/2023-February/007799.html>
[PATCH] Fix wrong numeric info on transcendental functions.
Although expression like cos(numeric(1, 2)) is not a symbolic, it
neither is numeric in the sense of CLN library. Without this patch
GiNaC crashes on expressions like cos(cos(ex(1)/ex(2))).
Thanks to Weng Zhanyang <cosine@pcbcos.xyz> for reporting this.
Richard Kreckel [Thu, 29 Dec 2022 20:00:36 +0000 (21:00 +0100)]
Minor refactoring in factor.cpp.
- Substitute the misnamed expt_pos(a,q) with the more specialized
expt_pos_Q(w,a,q,r) function, for use by distinct_degree_factor().
- Rework canonicalize function and change semantics of its hint
argument to be more natural.
- Use the hint argument of canonicalize() in rem().
- Add some documenting comments.
Richard Kreckel [Thu, 22 Dec 2022 17:19:59 +0000 (18:19 +0100)]
Fix internal next_prime(n) function.
This helper function was doing wild things when called the wrong way.
E.g. it would allocate obscene amounts of memory and run for ages when
called with an argument that has never been returned by it before.
In the context where it's being used so far this is not a problem. But
it's better to make it foolproof and spare a new user some possible
despair and distress.
Richard Kreckel [Mon, 19 Dec 2022 17:14:32 +0000 (18:14 +0100)]
[BUGFIX] Fix corner cases of factor_multivariate().
In some rare cases, factor() failed with what looks like an endless
loop trying evaluation homomorphisms with ever increasing moduli (or
maybe it just took eons to complete).
Whether this happened depended on which symbol was left unevaluated
for univariate factorization. As a workaround for this problem, we now
apply the evaluation homomorphism for each symbol in a round-robin
mode until one of them succeeds.
This somewhat speeds up factorization of multivariate polynomials
even in those cases where the old implementation terminated in time.
Thanks to Vitaly Magerya <vmagerya@gmail.com> for reporting this.
Richard Kreckel [Mon, 14 Nov 2022 23:08:28 +0000 (00:08 +0100)]
Refactor internal calc_bound() routines.
Reduce them to computation of absolute values of the polynomial's roots
and document that this is known as Landau's inequality. The multiplication
with a power of two is done by the caller.
Also remove the internal fallback computation using the maxcoeff since
this cannot happen. (In the worst case, there is only one non-zero
coefficient 'a'. Then we compute sqrt(a^2) which is not smaller than a.
Otherwise, we compute sqrt(a^2 + x) > a.)
Richard Kreckel [Mon, 14 Nov 2022 22:05:47 +0000 (23:05 +0100)]
[DEBUG] Make some debug output operators compile in factor.cpp...
...for the case when somebody actually #defines DEBUGFACTOR. The operators
must be in the same anonymous namespace in which umodpoly, upoly and upvec
are typedef'ed. (I'm not really sure I understand why but that's what GCC
and CLang are convinced of.)
[PATCH] Implement info methods for transcendent functions.
Here only easy answers are sought, which can be decided on
info tests of the functions arguments. From such coarse viepoint
functions are grouped into several classes and the respective
routines can be shared.
Richard Kreckel [Wed, 23 Mar 2022 20:21:48 +0000 (21:21 +0100)]
Fix power::subs() in some special cases.
In some cases, after subs'ing in basis and exponent, an extra
substitution was performed. This could lead to messed-up final results
because, e.g. substituting x==1/x in 1/x evaluated to x, but then
another substitution x==1/x was performed.
Jan Rheinländer [Wed, 16 Feb 2022 22:57:36 +0000 (23:57 +0100)]
Work around a compiler bug on MSVC.
The two 'reg_info' declarations introduced in f271f67d2f turned out
to confuse MSVC: It thinks that these declarations are definitions
and then complains about a missing default ctor (error C2512) and
about duplicate definitions later in the .cpp files (error C2766).
But the standard says in [temp.expl.spec] §13:
An explicit specialization of a static data member of a template or
an explicit specialization of a static data member template is a
definition if the declaration includes an initializer; otherwise, it
is a declaration. [Note: The definition of a static data member of a
template that requires default-initialization must use a braced-init-
list:
template<> X Q<int>::x; // declaration
template<> X Q<int>::x (); // error: declares a function
template<> X Q<int>::x { }; // definition
--end note]
There is no initializer at lst.h:35 and at exprseq.h:35. Hence, this
is merely a declaration and the compiler's error message is wrong.
Let's work around by #ifndef'ing the two lines for silly MSVC.
Richard Kreckel [Fri, 5 Nov 2021 13:47:53 +0000 (14:47 +0100)]
Update and clean up autoconf template files.
This is needed for compatibility with newer autoconf:
* Removed macro GINAC_STD_CXX_HEADERS (we use AX_CXX_COMPILE_STDCXX).
* Updated m4/* files from upstream.
* Ran autoupdate on acinclude.m4 and configure.ac.
[PATCH] Improve normalisation of negative exponents.
If an expression contains exponents with opposite signs,
then the respective symbolic substitutions need to be properly
attributed to numerator/denominator slots.
Richard Kreckel [Mon, 5 Apr 2021 18:46:55 +0000 (20:46 +0200)]
[PATCH] Make ex::operator[] const dispatch to basic::operator[] const.
It turned out that ex::operator[] const dispatched to non-const
basic::operator[] because
* member variable ex::bp is non-const and
* ptr<T>::operator*() returns a non-const T &.
As a result, indexing failed for multiply referenced objects.
Thanks to Vitaly Magerya <vmagerya@gmail.com> for reporting this.
Avoid multiple definitions of `lst::info` (MinGW compile fix)
[55/59] Linking CXX shared library bin/libginac.dll
FAILED: bin/libginac.dll ginac/libginac.dll.a
[skipped long list of object files]
/usr/bin/x86_64-w64-mingw32-ld: ginac/CMakeFiles/ginac.dir/lst.cpp.obj: in function `GiNaC::ptr<GiNaC::basic>::~ptr()':
/home/asheplyakov/work/sw/ginac/_build_w64/../ginac/container.h:150: multiple definition of `GiNaC::container<std::__cxx11::list>::info(unsigned int) const'; ginac/CMakeFiles/ginac.dir/integration_kernel.cpp.obj:/home/asheplyakov/work/sw/ginac/_build_w64/../ginac/container.h:116: first defined here
integration_kernel.cpp makes use of GiNaC::lst without including the `lst.h`
header. That's possible since there's a typedef in `registrar.h` (included
by virtually all GiNaC sources) and a defintion in `container.h` (included
via `add.h` -> `expairseq.h` -> `indexed.h` -> `exprseq.h`), so the compiler
can instantiate container<std::list>. However the explicit specialization
of `lst::info` is not available (in integration_kernel.cpp). This violates
17.8.3.6 [templ.expl.spec] which demands
If a template, a member template or a member of a class template is
explicitly specialized then that specialization shall be declared before
the first use of that specialization that would cause an implicit
instantiation to take place, in every translation unit in which such
a use occurs; no diagnostic is required. If the program does not provide
a definition for an explicit specialization and either the specialization
is used ina way that would cause an implicit instantiation to take place
or the member is a virtual member function, the program is ill-formed,
no diagnostic required.
On ELF platforms libginac appears to link just fine despite having two
instantiations of `lst::info` since the of them (in `integration_kernel.o`)
is a weak symbol:
$ find ginac -type f -name '*.o' | xargs -n 1 nm --print-file-name --defined | c++filt | grep -e 'list>::info('
ginac/CMakeFiles/ginac.dir/integration_kernel.cpp.o:0000000000000000 W GiNaC::container<std::__cxx11::list>::info(unsigned int) const
ginac/CMakeFiles/ginac.dir/lst.cpp.o:0000000000000000 T GiNaC::container<std::__cxx11::list>::info(unsigned int) const
so the linker discards the wrong instantiation of `lst::info` method.
However on MinGW there are no weak symbols (in ELF sense):
$ find ginac -type f -name '*.obj' | xargs -n 1 x86_64-w64-mingw32-nm --print-file-name --defined | c++filt | grep -e 'list>::info('
ginac/CMakeFiles/ginac.dir/lst.cpp.obj:0000000000000010 T GiNaC::container<std::__cxx11::list>::info(unsigned int) const
ginac/CMakeFiles/ginac.dir/integration_kernel.cpp.obj:0000000000000000 T GiNaC::container<std::__cxx11::list>::info(unsigned int) const
Hence the above multiple definition error.
To avoid the problem #include "lst.h" (so explicit specialization is available).
While at it explicitly instantiate lst::info method in lst.cpp
A better solution would be to remove declaration of lst from registrar.h,
but that's too disruptive since GiNaC uses lst a lot: subs, unarchive, etc.
Richard Kreckel [Sun, 22 Nov 2020 20:40:58 +0000 (21:40 +0100)]
Avoid 'variable uninitialized when used within its own initialization' warning.
Initialize the static flyweight ex objects with the pointeed numeric
objects instead of using self-assignment. This is 100% equivalent to
before: The objects have already been initialized by the library_init
ctor so all the static object's ctor does is increment the pointeed
object's refcount.
According to the resolution of C++ core language defect 363 the warning is
incorrect because it is allowed to pass a reference to the object, see
<https://wg21.link/cwg363>. Incrementing the bp's refcount is okay too,
because the pointee numeric object has been fully initialized by the
library_init ctor. However, the compiler can hardly know this, so CLang++
issues a warning.
Richard Kreckel [Mon, 12 Oct 2020 18:42:49 +0000 (20:42 +0200)]
Rename test suite files...
...to match any of the three types:
exam* test result for specific input (like a pupil's exam)
check* test coherence of results among each other, for random input
time* measure run-time
All tests are still there, but maybe elsewhere:
* rename match_bug.cpp => exam_match.cpp
* rename heur_gcd_bug.cpp => exam_heur_gcd.cpp
* rename bugme_chinrem_gcd.cpp => exam_chinrem_gcd.cpp
* rename parser_bugs.cpp => exam_parser.cpp
* rename exam_cra.cpp => check_cra.cpp
* include numeric_archive.cpp => exam_archive.cpp
* include pgcd_infinite_loop.cpp => exam_pgcd.cpp
* include pgcd_relatively_prime_bug.cpp => exam_pgcd.cpp
These two have been deleted, since memory leaks are best looked for
using tools on real programs on a regular basis (they were also not
automatically executed):
* delete parser_memleak.cpp
* delete mul_eval_memleak.cpp
[PATCH 3/3] Stronger normalisation method for powers.
Now normalisation method try to express powers with the same base
as monomials of some dummy variables. This allows to make cancellations
of the sort:
(x-1)/(sqrt(x)-1) -> sqrt(x)+1
Signed-off-by: Vladimir V. Kisil <V.Kisilv@leeds.ac.uk>
Richard Kreckel [Sat, 10 Oct 2020 18:20:59 +0000 (20:20 +0200)]
Remove deprecated initialization via overloaded comma operator.
This feature has been marked as deprecated since 1.7.0. There's been more
than four years to switch to initializer lists. Let's hope people have
modified their code since.
Stefan Weinzierl [Sat, 10 Oct 2020 15:11:09 +0000 (17:11 +0200)]
Added new routines for the numerical evaluation of iterated integrals like
elliptic multiple polylogarithms or iterated integrals of modular forms.
Changes to be committed:
modified: check/CMakeLists.txt
modified: check/Makefile.am
new file: check/exam_inifcns_elliptic.cpp
modified: doc/tutorial/ginac.texi
modified: ginac/CMakeLists.txt
modified: ginac/Makefile.am
modified: ginac/ginac.h
modified: ginac/inifcns.h
new file: ginac/inifcns_elliptic.cpp
new file: ginac/integration_kernel.cpp
new file: ginac/integration_kernel.h
new file: ginac/utils_multi_iterator.h
modified: ginsh/ginsh_parser.ypp
* GiNaC can be included as a (CMake) subproject. One can put GiNaC
sources (either from git or a tarball) into a subdirectory (say,
`ginac`) and use the following CMakeLists.txt to build everything:
build: windows: enable automatic imports by default
For now there are no dllexport/dllimport markings in GiNaC and CLN, so
export all symbols when building GiNaC DLL, and enable automatic imports
when linking with it. Note: this works with GNU linker only.
build: CMake: made it easier to run tests in parallel
As of now `make -jN check` executes test suite sequentially
(although it builds test executables in parallel). This takes
a bit too long, so it would be nice to run tests in parallel.
`ctest -jN` or `make test ARGS=-jN` runs tests concurrently,
however it does not build test executables, instead it fails
if any test binary is missing.
Also `test` target is a bit special and it's impossible to add
dependencies to it, see
https://gitlab.kitware.com/cmake/cmake/issues/8438
To work around the problem define `test_suite` target which
builds the tests suite without running it, so one can both
compile and run tests in parallel
config.h is necessary for excompiler only, the rest of the library
is pretty portable. Not including dynamically generated headers
saves compilation time due to more (c)cache hits.
This makes building GiNaC a bit easier for users of "old" distributions
where python 3 is not installed by default (Ubuntu 16.04), or even not
available (CentOS 7).
Scripts themselves work just fine with python 2.7 and python 3.x, so
only minor changes to CMakeLists.txt are required (autotools scripts
already handle python2/3)