Skip to content

Conversation

@fredrik-johansson
Copy link
Collaborator

This should somewhat speed up fraction field arithmetic over gr_poly rings, among other things.

Sample benchmark:

#include "gr.h"
#include "gr_poly.h"
#include "profiler.h"

int main()
{
    gr_ctx_t R, Rx, Rxy, Rxyz;
    gr_ptr f, g, h;

    gr_ctx_init_fmpzi(R);
    gr_ctx_init_gr_poly(Rx, R);
    GR_MUST_SUCCEED(gr_ctx_set_gen_name(Rx, "x"));
    gr_ctx_init_gr_poly(Rxy, Rx);
    GR_MUST_SUCCEED(gr_ctx_set_gen_name(Rxy, "y"));
    gr_ctx_init_gr_poly(Rxyz, Rxy);
    GR_MUST_SUCCEED(gr_ctx_set_gen_name(Rxyz, "z"));

    f = gr_heap_init(Rxyz);
    g = gr_heap_init(Rxyz);
    h = gr_heap_init(Rxyz);

    GR_MUST_SUCCEED(gr_set_str(f, "(1+I+x+2*y+3*z)^10", Rxyz));
    GR_MUST_SUCCEED(gr_set_str(g, "(1+I-x+2*y-3*z)^10", Rxyz));
    GR_MUST_SUCCEED(gr_mul(h, f, g, Rxyz));

    TIMEIT_START
    GR_MUST_SUCCEED(gr_divexact(f, h, g, Rxyz));
    TIMEIT_STOP
    TIMEIT_START
    GR_MUST_SUCCEED(gr_gcd(f, h, g, Rxyz));
    TIMEIT_STOP
}

Before:

cpu/wall(s): 0.00129 0.00129
cpu/wall(s): 0.00864 0.00863

After:

cpu/wall(s): 0.000745 0.000744
cpu/wall(s): 0.00825 0.00825

@fredrik-johansson fredrik-johansson merged commit 726ee2d into flintlib:main Apr 27, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant