diff options
Diffstat (limited to 'poly_mul.c')
-rw-r--r-- | poly_mul.c | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -180,6 +180,18 @@ void poly_mul_in_ring(fmpz_poly_t res, fmpz_poly_t poly1, fmpz_poly_t poly2, poly_to_ring(res, ctx); } +void poly_add_in_ring(fmpz_poly_t res, fmpz_poly_t poly1, fmpz_poly_t poly2, + poly_ring_ctx_t ctx) { + fmpz_poly_add(res, poly1, poly2); + poly_to_ring(res, ctx); +} + +void poly_sub_in_ring(fmpz_poly_t res, fmpz_poly_t poly1, fmpz_poly_t poly2, + poly_ring_ctx_t ctx) { + fmpz_poly_sub(res, poly1, poly2); + poly_to_ring(res, ctx); +} + int main(const int argc, const char* const* const argv) { fmpz_t prime; /* integer for modulo operations */ mod_centered_0_ctx_t mod_ctx; @@ -226,28 +238,34 @@ int main(const int argc, const char* const* const argv) { } /* End of experiment 1 */ { /* Experiment 2 */ - fmpz_poly_t poly1, poly2, poly_prod; + fmpz_poly_t poly1, poly2, poly_computed; slong divisor_degree; poly_ring_ctx_t poly_ring_ctx; - printf("Give first polynomial to multiply:\n"); + printf("Give first polynomial for the experiment:\n"); init_read_poly(poly1, stdin); printf("Read polynomial: "); fmpz_poly_print_pretty(poly1, "x"); putchar('\n'); - printf("Give second polynomial to multiply:\n"); + printf("Give second polynomial for the experiment:\n"); init_read_poly(poly2, stdin); printf("Read polynomial: "); fmpz_poly_print_pretty(poly2, "x"); putchar('\n'); + fmpz_poly_init(poly_computed); + printf("Normal product of polynomials:\n"); - fmpz_poly_init(poly_prod); - fmpz_poly_mul(poly_prod, poly1, poly2); - fmpz_poly_print_pretty(poly_prod, "x"); + fmpz_poly_mul(poly_computed, poly1, poly2); + fmpz_poly_print_pretty(poly_computed, "x"); + putchar('\n'); + + printf("Normal sum of polynomials:\n"); + fmpz_poly_add(poly_computed, poly1, poly2); + fmpz_poly_print_pretty(poly_computed, "x"); putchar('\n'); printf("Give the degree m of X^m+1 polynomial to be used as "); @@ -260,13 +278,18 @@ int main(const int argc, const char* const* const argv) { poly_ring_ctx_init(poly_ring_ctx, mod_ctx, divisor_degree); printf("Product of polynomials in the ring:\n"); - poly_mul_in_ring(poly_prod, poly1, poly2, poly_ring_ctx); - fmpz_poly_print_pretty(poly_prod, "x"); + poly_mul_in_ring(poly_computed, poly1, poly2, poly_ring_ctx); + fmpz_poly_print_pretty(poly_computed, "x"); + putchar('\n'); + + printf("Sum of polynomials in the ring:\n"); + poly_add_in_ring(poly_computed, poly1, poly2, poly_ring_ctx); + fmpz_poly_print_pretty(poly_computed, "x"); putchar('\n'); fmpz_poly_clear(poly1); fmpz_poly_clear(poly2); - fmpz_poly_clear(poly_prod); + fmpz_poly_clear(poly_computed); poly_ring_ctx_clear(poly_ring_ctx); } /* End of experiment 2 */ |