Bill Allombert on Tue, 06 Jun 2023 20:42:18 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Different behavior in library mode (PARI) vs. in GP (when using Z_issmooth)
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Different behavior in library mode (PARI) vs. in GP (when using Z_issmooth)
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Tue, 6 Jun 2023 20:37:27 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686076637; c=relaxed/relaxed; bh=6TITqXRLnuaVffYyNEPHZ/Nl1dGoApqwUai0U5EpyDU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; b=Idesj/ngPeOl9VJsJsvsJ5GQo9P5abRZIOR1asJRuJr9iWTzVb6MRkOpcwGHNI8oji64J/hxKpD4kyjG8lP/zMKYz6+xXxd08WLPTV9+UUJ2R7ZfDPqc2QkVYbAfe+ww2WdsdZe2Cf4tYxuvsBRaax8zAFgJ21RX+ug3iE+CuPcxSKPDAsNahqZu2gNyB00StroFxajlupxhr9DUON8pCBwtEQJRX/swOzLu+3rfJuYXvBQhFXhEhpsk4XWE8GgdjjKQKxQ2D4cVcDSp6g1XNZfquVnyuTzr/TtWYb3nKJNopszkTac6OxoecLptPVIwUqRX9xSmLzESuFYaKIAAR+EVQ9IT2cfRIxba9+M9e/K5WGVBCb6RmuAeWXYqLbAzCzZKounPINDyHhQSErOd3uy60Tq6fk/UQeoHdn+KXB9Raq/OlU/awbNKCd8ZVJ8lKST5wz/8mmCB3UQd2frBWnjRi4ktc/4rayvhNu5i0qYWJvKWk1y6M8M9wZleS/2k1DYYvpyumLmRhdroky3uKJkuKhbfo55JRBuilxF8SGrjszxb5bxmfRZ4L2AUEZp7ILb4NxRqPD1iSDFV8go0GmmWUBoF2GkWDKOGcZbUAzbIbblJAH20L2p2+DpKwhbrgPM3QWsaoe+M0UkAvmwmW8pBuVKWxyil7BLu15OcoSU=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686076637; cv=none; b=aJNidx2htuu5hsRh6EdutrSry+wa767Meh8hVj8Zv4OekvcHfYNNmIOqb1Hs+B2RZTIbDbPc+uCcb5PD10ri7zRdRdtS28oOpl0bKdETJW79V0r9ljgjsfvUGTy7h5jZEfmMCTTmApDPBjEaMwGVJGf/Y2xWZ04YGmBnf21Xf+8kHSlRW+wRlDDJlsiXsdmV0YGjP67IT2feq9yxKq69/8GPHeMIMf5QAdliwzwF2GdUspU4OpG5fHgFdqgHXqXQFMshi8FYRolIOWSXjtq4rbK004Ez7/XmWWvX33MCpO2ndGl3LYCIC0uPNVvyexuUF1p5ojFYpwDZgrluBr418ewtVvMLeXl/63Q4fMJgwXaVkFtQGrawj0RikBdH5YvchqdPCXP234A863tBFQFZ+UaFjnuuDbKbBkYdYZaCdG1GIGFrejS3hRW9oRKYHMLRIBfGVARuLSi9SV2U0GtI7caYenr1i8l6vkUKHrbVc2K5lpCmxxu/pX5N3cqaYfTzbVjuPfqm10lyjJGUCTItaopH+FGe2/r1DUyfM8dYKUD34OFLc8wWQ8XlPMQbVKy9nUNmDJqOK52/H5DbafR7X+i7kdhTPDSaSKo4BMO5maPBl4aw65l3NzbeAnkBp6TkQrIcbYJPOyXL2E3tMclIrwXRhVAz4YLWxGDQUPkGPeM=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Tue, 06 Jun 2023 20:42:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1686076637; bh=6TITqXRLnuaVffYyNEPHZ/Nl1dGoApqwUai0U5EpyDU=; h=Date:From:To:Subject:References:In-Reply-To:From; b=SjMUxRAWPkTC9NrqiGBKV/Zf8FXmkqQWvkAATcXLzB0O4M+DA+ciQhu8Hx8RdzDEw QoRUggzYmeIwUDekd3nbdLo82Jvh9ZloOqWotcLqZa157wlnDduA98LteosJWRTKRw jGVCK8RPBtXZ/EBYJv1zcfUG8erH/3Ih6Ulcun1sNbj+ilSGnVETTaDg3WLx5Awn8a hqwdyKN27Vgr5ZO4Xc0BLSyZbC6Ju42APBPpCaB5aargHz8EB6/ZeKLv5Q4uFgc1yv 2RxPFe/gkbST/wepTdGe96eGAsW0c/v3nhXXINYpJj+q4mmc4CBTWTcNbnVohs3/6T dUVuQcj9qNx6q4UUnlfk4JQz6xlvcApBRBb2apNYAqIUTv7d4lJTWfE2l9EBaKz6Rd VNIAqODq7gzCf2tBiXUIYoPOO7+DZ19WMIinMGXkdVQwWop9HEAC5XhNxWidcQjFIL +YmBhkp0HAj6kMZw7KNPBdO1eN6cIKl2uoBxuFTsw8nUyzLlcvWX96WgOaqySdx6Pf ZO9oT3UHIC4y0AN2uuFyCisVrt48BnyPxaCX9JHiMJ4GtaNwAlByWw6hCDnsEZAfJh VkOCOJSbj28LVWUDu58VRLofkdOEZO0iamirKgBieThmy7yD3OifFlZN00W5owu1Ti HCqjxtJbNZKatR670JX3xA+4=
- In-reply-to: <1c6bf1e7-736d-8c24-451f-9bacc0a1fc39@hs-rm.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <1c6bf1e7-736d-8c24-451f-9bacc0a1fc39@hs-rm.de>
On Tue, Jun 06, 2023 at 07:52:19PM +0200, Daniel Berger wrote:
> Hello,
>
> a simplified version of what I am doing is the following code using PARI:
>
> ```C
> #include <pari/pari.h>
> GEN
> function(ulong B, GEN d, ulong m)
> {
> GEN I, e, e_, ret = NULL;
> ulong i;
> pari_sp ltop = avma;
> I = const_vecsmall(m+1,1);
> e = quadunit0(d,-1);
> if (gsigne(gnorm(e)) == -1) e = gsqr(e);
> e_ = e
> for (i = 1; i < lg(I); i++)
> {
> if(!gel(I,i)) continue;
> if(Z_issmooth(gel(e,3),B))
> {
> if (ret == NULL) ret =
> mkvec(diviiexact(subii(gel(e,2),gen_1),gen_2));
> else ret =
> vec_append(ret,diviiexact(subii(gel(e,2),gen_1),gen_2));
> }
> else for (j = i; j < lg(I); j += i= gel(I,j) = 0;
> e = gmul(e,e_);
> }
> //copy ret to a clean place in memory
> return gerepileupto(ltop,ret);
> }
(Your code do not compile for multiple reasons)
You should not use gel() with t_VECSMALL component. use I[1], I[2] etc.
> Now when i run this code as part of compiled C code, it works fine and does
> what it's supposed to do. For example `function(10, 2, 3)` returns `[1, 8,
> 49]`
>
> If I however compile this as part of a shared library and install it for use
> in gp, it doesn't. It appears to me that `Z_issmooth` always returns 1, for
> example `function(10, 2, 3)` now returns `[1, 8, 49, 288]`. I tried testing
> `Z_issmooth` separately in gp by installing it with
> `install(Z_issmooth,"GU",smoothtest,"libpari.so")` and for example
> `smoothtest(408,10)` (should return 0) but it breaks with a segmentation
> fault.
Z_issmooth returns a 'long' so the code should be "lGU"
? install(Z_issmooth,"lGU",smoothtest)
? smoothtest(408,10)
%2 = 0
> Any insights as to what I might be doing wrong are appreciated.
Send me your correct C file.
Two possibilities come to mind:
- maybe the primetable is not initialised in the same way in the
C program than in GP (Z_issmooth use the primetable).
- maybe your are mixing different copies of libpari.so and get strange result.
Under GP it is safer to omit "libpari.so" in install().
Cheers,
Bill.