1 /*
2     Copyright (C) 2018 Daniel Schultz
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "fmpq_mpoly.h"
13 
14 
15 /* return 1 if quotient is exact */
fmpq_mpoly_sub(fmpq_mpoly_t poly1,const fmpq_mpoly_t poly2,const fmpq_mpoly_t poly3,const fmpq_mpoly_ctx_t ctx)16 void fmpq_mpoly_sub(fmpq_mpoly_t poly1,
17                   const fmpq_mpoly_t poly2, const fmpq_mpoly_t poly3,
18                                                     const fmpq_mpoly_ctx_t ctx)
19 {
20     fmpz_mpoly_t temp2, temp3;
21     fmpz_t n2d3, d2n3, d2d3, one;
22 
23     fmpz_init(n2d3);
24     fmpz_init(d2n3);
25     fmpz_init(d2d3);
26     fmpz_init_set_ui(one, 1);
27     fmpz_mpoly_init(temp2, ctx->zctx);
28     fmpz_mpoly_init(temp3, ctx->zctx);
29 
30     fmpz_mul(n2d3, fmpq_numref(poly2->content), fmpq_denref(poly3->content));
31     fmpz_mul(d2n3, fmpq_denref(poly2->content), fmpq_numref(poly3->content));
32     fmpz_mul(d2d3, fmpq_denref(poly2->content), fmpq_denref(poly3->content));
33 
34     fmpz_mpoly_scalar_mul_fmpz(temp2, poly2->zpoly, n2d3, ctx->zctx);
35     fmpz_mpoly_scalar_mul_fmpz(temp3, poly3->zpoly, d2n3, ctx->zctx);
36 
37     fmpz_mpoly_sub(poly1->zpoly, temp2, temp3, ctx->zctx);
38     fmpq_set_fmpz_frac(poly1->content, one, d2d3);
39 
40     fmpz_mpoly_clear(temp3, ctx->zctx);
41     fmpz_mpoly_clear(temp2, ctx->zctx);
42     fmpz_clear(one);
43     fmpz_clear(d2d3);
44     fmpz_clear(d2n3);
45     fmpz_clear(n2d3);
46 
47     fmpq_mpoly_reduce(poly1, ctx);
48 }
49