1 /*============================================================================= 2 3 This file is part of Antic. 4 5 Antic is free software: you can redistribute it and/or modify it under 6 the terms of the GNU Lesser General Public License (LGPL) as published 7 by the Free Software Foundation; either version 2.1 of the License, or 8 (at your option) any later version. See <http://www.gnu.org/licenses/>. 9 10 =============================================================================*/ 11 /****************************************************************************** 12 13 Copyright (C) 2013 Fredrik Johansson 14 Copyright (C) 2015 William Hart 15 16 ******************************************************************************/ 17 18 #include "nf_elem.h" 19 nf_elem_print_pretty(const nf_elem_t a,const nf_t nf,const char * var)20void nf_elem_print_pretty(const nf_elem_t a, const nf_t nf, const char * var) 21 { 22 if (nf->flag & NF_LINEAR) 23 { 24 const fmpz * const den = LNF_ELEM_DENREF(a); 25 fmpz_print(LNF_ELEM_NUMREF(a)); 26 if (!fmpz_is_one(den)) 27 { 28 flint_printf("/"); 29 fmpz_print(LNF_ELEM_DENREF(a)); 30 } 31 } else if (nf->flag & NF_QUADRATIC) 32 { 33 const fmpz * const anum = QNF_ELEM_NUMREF(a); 34 const fmpz * const aden = QNF_ELEM_DENREF(a); 35 int den1 = fmpz_is_one(aden); 36 int lead0 = fmpz_is_zero(anum + 1); 37 38 if (!den1 && !lead0) 39 flint_printf("("); 40 if (!lead0) 41 { 42 fmpz_print(anum + 1); 43 flint_printf("*%s", var); 44 if (fmpz_sgn(anum) >= 0) 45 printf("+"); 46 } 47 fmpz_print(anum); 48 if (!den1 && !lead0) 49 flint_printf(")"); 50 if (!den1) 51 { 52 flint_printf("/"); 53 fmpz_print(aden); 54 } 55 } else 56 { 57 fmpq_poly_print_pretty(NF_ELEM(a), var); 58 } 59 } 60 61