1 /*
2     Copyright (C) 2011 Sebastian Pancratz
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 "fmpz_mat.h"
13 #include "padic_mat.h"
14 
padic_mat_fprint(FILE * file,const padic_mat_t A,const padic_ctx_t ctx)15 int padic_mat_fprint(FILE * file, const padic_mat_t A, const padic_ctx_t ctx)
16 {
17     const slong r = padic_mat(A)->r;
18     const slong c = padic_mat(A)->c;
19 
20     if (padic_mat_is_empty(A))
21     {
22         flint_fprintf(file, "%wd %wd\n", r, c);
23         return 1;
24     }
25 
26     if (ctx->mode == PADIC_TERSE)
27     {
28         slong i, j, v;
29         fmpz_t s, t;
30 
31         fmpz_init(s);
32         fmpz_init(t);
33 
34         flint_fprintf(file, "%wd %wd ", r, c);
35 
36         for (i = 0; i < r; i++)
37             for (j = 0; j < c; j++)
38             {
39                 flint_fprintf(file, " ");
40 
41                 if (fmpz_is_zero(padic_mat_entry(A, i, j)))
42                 {
43                     flint_fprintf(file, "0");
44                 }
45                 else
46                 {
47                     v = A->val
48                       + fmpz_remove(t, padic_mat_entry(A, i, j), ctx->p);
49 
50                     if (v == 0)
51                     {
52                         fmpz_fprint(file, t);
53                     }
54                     else if (v > 0)
55                     {
56                         fmpz_pow_ui(s, ctx->p, v);
57                         fmpz_mul(t, s, t);
58                         fmpz_fprint(file, t);
59                     }
60                     else  /* v < 0 */
61                     {
62                         fmpz_pow_ui(s, ctx->p, -v);
63                         _fmpq_fprint(file, t, s);
64                     }
65                 }
66             }
67 
68         fmpz_clear(s);
69         fmpz_clear(t);
70     }
71     else if (ctx->mode == PADIC_SERIES)
72     {
73         flint_printf("ERROR (_padic_mat_fprint).  Mode PADIC_SERIES not implemented yet.\n");
74         flint_abort();
75     }
76     else if (ctx->mode == PADIC_VAL_UNIT)
77     {
78         slong i, j, v;
79         fmpz_t t;
80 
81         fmpz_init(t);
82 
83         flint_fprintf(file, "%wd %wd ", r, c);
84 
85         for (i = 0; i < r; i++)
86             for (j = 0; j < c; j++)
87             {
88                 flint_fprintf(file, " ");
89 
90                 if (fmpz_is_zero(padic_mat_entry(A, i, j)))
91                 {
92                     flint_fprintf(file, "0");
93                 }
94                 else
95                 {
96                     v = A->val
97                       + fmpz_remove(t, padic_mat_entry(A, i, j), ctx->p);
98 
99                     if (v == 0)
100                     {
101                         fmpz_fprint(file, t);
102                     }
103                     else if (v == 1)
104                     {
105                         fmpz_fprint(file, ctx->p);
106                         flint_fprintf(file, "*");
107                         fmpz_fprint(file, t);
108                     }
109                     else
110                     {
111                         fmpz_fprint(file, ctx->p);
112                         flint_fprintf(file, "^%wd*", v);
113                         fmpz_fprint(file, t);
114                     }
115                 }
116             }
117 
118         fmpz_clear(t);
119     }
120     else
121     {
122         flint_printf("ERROR (_padic_mat_fprint).  Unknown print mode.\n");
123         flint_abort();
124     }
125 
126     return 1;
127 }
128 
129