Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ set(_BUILD_DIRS
acb_theta dirichlet bernoulli hypgeom

gr gr_generic gr_vec gr_mat
gr_poly gr_mpoly gr_series gr_special
gr_poly gr_mpoly gr_ore_poly gr_series
gr_special

calcium
fmpz_mpoly_q
Expand Down
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ HEADER_DIRS := \
bool_mat partitions \
\
gr gr_generic gr_vec gr_mat \
gr_poly gr_mpoly gr_series gr_special \
gr_poly gr_mpoly gr_ore_poly \
gr_series gr_special \
\
calcium \
\
Expand Down
23 changes: 23 additions & 0 deletions doc/source/gr_domains.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ Polynomial rings
over the given *base_ring*.
Elements have type :type:`gr_poly_struct`.

.. function:: void gr_ctx_init_random_poly(gr_ctx_t ctx, flint_rand_t state)

Initializes *ctx* to a random univariate polynomial ring.

.. function:: void gr_ctx_init_fmpz_mpoly(gr_ctx_t ctx, slong nvars, const ordering_t ord)

Initializes *ctx* to a ring of sparsely represented multivariate
Expand All @@ -345,12 +349,31 @@ Polynomial rings
with monomial ordering *ord*.
Elements have type :type:`gr_mpoly_struct`.

.. function:: void gr_ctx_init_random_mpoly(gr_ctx_t ctx, flint_rand_t state)

Initializes *ctx* to a random multivariate polynomial ring.

Ore polynomials
-------------------------------------------------------------------------------

.. function:: void gr_ctx_init_gr_ore_poly(gr_ctx_t ctx, gr_ctx_t base_ring, slong base_var, const ore_algebra_t which_algebra)

Initializes *ctx* to a ring of densely represented Ore polynomials over the
given *base_ring*, with the choice of Ore algebra structure given by
*which_algebra*. The Ore algebra structure may refer to a distinguished
generator of *base_ring*; this will be the generator of index *base_var*.
Elements have type :type:`gr_ore_poly_struct`.

Power series
-------------------------------------------------------------------------------

See :func:`gr_series_ctx_init` and :func:`gr_series_mod_ctx_init`
in :ref:`gr-series`.

.. function:: void gr_ctx_init_random_series(gr_ctx_t ctx, flint_rand_t state)

Initializes *ctx* to a random power series ring.

Fraction fields
-------------------------------------------------------------------------------

Expand Down
324 changes: 324 additions & 0 deletions doc/source/gr_ore_poly.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Generic rings
gr_mat.rst
gr_poly.rst
gr_mpoly.rst
gr_ore_poly.rst
gr_series.rst

.. only:: not latex
Expand Down
1 change: 1 addition & 0 deletions doc/source/index_generic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
gr_mat.rst
gr_poly.rst
gr_mpoly.rst
gr_ore_poly.rst
gr_series.rst

15 changes: 12 additions & 3 deletions src/generic_files/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <ctype.h> /* isdigit */
#include <stdint.h> /* intmax_t */
#include <stdio.h>
#include <string.h> /* memcpy, memcmp and strchr */
#include <string.h> /* memcpy, strncmp and strchr */
#include <stdarg.h>
#include <wchar.h> /* wchar_t and wint_t */
#include "nmod_types.h"
Expand All @@ -26,6 +26,7 @@
#include "gr.h"
#include "gr_vec.h"
#include "gr_poly.h"
#include "gr_ore_poly.h"
#include "gr_mat.h"
#include "gr_mat/impl.h"

Expand Down Expand Up @@ -202,8 +203,8 @@ static size_t __flint_poly_fprint(FILE *, const void *, flint_type_t);

/* TODO: Add options for compact/spacious printing. */

#define IS_FLINT_BASE_TYPE(ip, str) (memcmp(ip, str, sizeof(str) - sizeof(char)) == 0)
#define IS_FLINT_TYPE(ip, str) (memcmp(ip, str "}", sizeof(str)) == 0)
#define IS_FLINT_BASE_TYPE(ip, str) (strncmp(ip, str, STRING_LENGTH(str)) == 0)
#define IS_FLINT_TYPE(ip, str) (strncmp(ip, str "}", STRING_LENGTH(str) + 1) == 0)

/* Reference used for checks: https://en.cppreference.com/w/c/io/fprintf */
#define IS_PRINTF_FLAG(chr) \
Expand Down Expand Up @@ -735,6 +736,14 @@ int flint_vfprintf(FILE * fs, const char * ip, va_list vlist)
res += out->len;
ip += STRING_LENGTH("gr_poly}");
}
else if (IS_FLINT_TYPE(ip, "gr_ore_poly"))
{
const gr_ore_poly_struct * elem = va_arg(vlist, const gr_ore_poly_struct *);
gr_ctx_struct * ctx = va_arg(vlist, gr_ctx_struct *);
GR_MUST_SUCCEED(gr_ore_poly_write(out, elem, ctx));
res += out->len;
ip += STRING_LENGTH("gr_ore_poly}");
}
else if (IS_FLINT_TYPE(ip, "gr_mat"))
{
const gr_mat_struct * elem = va_arg(vlist, const gr_mat_struct *);
Expand Down
4 changes: 4 additions & 0 deletions src/gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ typedef enum
GR_CTX_FMPZ_MPOLY, GR_CTX_GR_MPOLY,
GR_CTX_FMPZ_MPOLY_Q,
GR_CTX_FMPZ_MOD_MPOLY_Q,
GR_CTX_GR_ORE_POLY,
GR_CTX_GR_FRACTION, GR_CTX_GR_COMPLEX,
GR_CTX_GR_SERIES, GR_CTX_SERIES_MOD_GR_POLY,
GR_CTX_GR_MAT,
Expand Down Expand Up @@ -1384,6 +1385,9 @@ truth_t gr_generic_ctx_predicate_false(gr_ctx_t ctx);
void gr_ctx_uninitialized(gr_ctx_t ctx);

void gr_ctx_init_random(gr_ctx_t ctx, flint_rand_t state);
void gr_ctx_init_random_poly(gr_ctx_t ctx, flint_rand_t state);
void gr_ctx_init_random_mpoly(gr_ctx_t ctx, flint_rand_t state);
void gr_ctx_init_random_series(gr_ctx_t ctx, flint_rand_t state);

void gr_ctx_init_fmpz(gr_ctx_t ctx);
void gr_ctx_init_fmpq(gr_ctx_t ctx);
Expand Down
49 changes: 49 additions & 0 deletions src/gr/init_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,52 @@ void gr_ctx_init_random(gr_ctx_t ctx, flint_rand_t state)
gr_ctx_println(ctx);
*/
}

void
gr_ctx_init_random_poly(gr_ctx_t ctx, flint_rand_t state)
{
switch (n_randint(state, 8))
{
case 0:
gr_ctx_init_fmpz_poly(ctx);
break;
case 1:
gr_ctx_init_fmpq_poly(ctx);
break;
default:
gr_ctx_init_gr_poly(ctx, _gr_random_base_ring(state));
break;
}
}

void
gr_ctx_init_random_mpoly(gr_ctx_t ctx, flint_rand_t state)
{
ordering_t ordering = mpoly_ordering_randtest(state);

switch (n_randint(state, 2))
{
case 0:
gr_ctx_init_gr_mpoly(ctx, _gr_random_base_ring(state), n_randint(state, 3), ordering);
break;
case 1:
gr_ctx_init_fmpz_mpoly(ctx, n_randint(state, 3), mpoly_ordering_randtest(state));
break;
}
}

void
gr_ctx_init_random_series(gr_ctx_t ctx, flint_rand_t state)
{
gr_ctx_struct * base_ring = _gr_random_base_ring(state);

switch (n_randint(state, 2))
{
case 0:
gr_series_ctx_init(ctx, base_ring, n_randint(state, 6));
break;
case 1:
gr_series_mod_ctx_init(ctx, base_ring, n_randint(state, 6));
break;
}
}
18 changes: 18 additions & 0 deletions src/gr/ore_poly.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright (C) 2025 Ricardo Buring

This file is part of FLINT.

FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "gr_ore_poly.h"

void
gr_ctx_init_gr_ore_poly(gr_ctx_t ctx, gr_ctx_t base_ring, slong base_var, const ore_algebra_t which_algebra)
{
gr_ore_poly_ctx_init(ctx, base_ring, base_var, which_algebra);
}
Loading
Loading