My Project
Loading...
Searching...
No Matches
ipprint.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT: interpreter: printing
6*/
7
8#include "kernel/mod2.h"
9
10#include "misc/intvec.h"
11
12#include "polys/matpol.h"
13
14#include "kernel/polys.h"
15#include "kernel/ideals.h"
16
17#include "tok.h"
18#include "ipid.h"
19#include "subexpr.h"
20#include "ipshell.h"
21#include "ipprint.h"
22#include "attrib.h"
23
24/*2
25* print for: int, string, poly, vector, ideal
26*/
27/*2
28* print for: intvec
29*/
31{
32 v->show();
33 PrintLn();
34 return FALSE;
35}
36
37/*2
38* print for: intmat
39*/
41{
42 int i,j;
43 for(i=0;i<v->rows();i++)
44 {
45 for(j=0;j<v->cols();j++)
46 {
47 Print(" %5d",IMATELEM(*v,i+1,j+1));
48 }
49 PrintLn();
50 }
51 return FALSE;
52}
53
54/*2
55* internal print for: matrix
56*/
57void ipPrint_MA0(matrix m, const char *name)
58{
59 if ((MATCOLS(m)>0)&&(MATROWS(m)>0))
60 {
61 char **s=(char **)omAlloc(MATCOLS(m)*MATROWS(m)*sizeof(char*));
62 char *ss;
63 int *l=(int *)omAlloc0(MATCOLS(m)*sizeof(int));
64 int i,j,k;
65 int vl=si_max(colmax/MATCOLS(m),8);
66
67 /* make enough space for the "largest" name*/
68 size_t len=14+strlen(name);
69 ss=(char *)omAlloc(len);
70 snprintf(ss,len,"%s[%d,%d]",name,MATCOLS(m),MATROWS(m));
71 vl=si_max(vl,(int)strlen(ss));
72 omFreeBinAddr(ss);
73
74 /* convert all polys to string */
75 i=MATCOLS(m)*MATROWS(m)-1;
76 ss=pString(m->m[i]);
77 if ((int)strlen(ss)>colmax) { s[i]=NULL; omFree(ss); }
78 else s[i]=ss;
79 for(i--;i>=0;i--)
80 {
81 StringSetS("");
82 pString0(m->m[i]);
83 StringAppendS(",");
84 ss=StringEndS();
85 if ((int)strlen(ss)>colmax) { s[i]=NULL; omFree(ss); }
86 else s[i]=ss;
87 }
88 /* look up the width of all columns, put it in l[col_nr] */
89 /* insert names for very long entries */
90 for(i=MATROWS(m)-1;i>=0;i--)
91 {
92 for(j=MATCOLS(m)-1;j>=0;j--)
93 {
94 if (s[i*MATCOLS(m)+j]==NULL)
95 {
96 ss=(char *)omAlloc(len);
97 s[i*MATCOLS(m)+j]=ss;
98 ss[0]='\0';
99 snprintf(ss,len,"%s[%d,%d]",name,i+1,j+1);
100 if ((i!=MATROWS(m)-1) || (j!=MATCOLS(m)-1))
101 {
102 strcat(ss,",");
103 vl=si_max(vl,(int)strlen(ss));
104 }
105 }
106 k=strlen(s[i*MATCOLS(m)+j]);
107 if (k>l[j]) l[j]=k;
108 }
109 }
110 /* does it fit on a line ? */
111 int maxlen=0;
112 for(j=MATCOLS(m)-1;j>=0;j--)
113 {
114 maxlen+=l[j];
115 }
116 if (maxlen>colmax)
117 {
118 /* NO, it does not fit, so retry: */
119 /* look up the width of all columns, clear very long entriess */
120 /* put length in l[col_nr] */
121 /* insert names for cleared entries */
122 size_t len=14+strlen(name);
123 for(j=MATCOLS(m)-1;j>=0;j--)
124 {
125 for(i=MATROWS(m)-1;i>=0;i--)
126 {
127 k=strlen(s[i*MATCOLS(m)+j]);
128 if (/*strlen(s[i*MATCOLS(m)+j])*/ k > vl)
129 {
130 omFree((ADDRESS)s[i*MATCOLS(m)+j]);
131 ss=(char *)omAlloc(len);
132 s[i*MATCOLS(m)+j]=ss;
133 ss[0]='\0';
134 snprintf(ss,len,"%s[%d,%d]",name,i+1,j+1);
135 if ((i!=MATROWS(m)-1) || (j!=MATCOLS(m)-1))
136 {
137 strcat(ss,",");
138 }
139 l[j]=strlen(s[i*MATCOLS(m)+j]);
140 if (l[j]>vl)
141 {
142//#ifdef TEST
143// PrintS("pagewidth too small in print(matrix)\n");
144//#endif
145 vl=l[j]; /* make large names fit*/
146 }
147 i=MATROWS(m);
148 }
149 else
150 {
151 if (k>l[j]) l[j]=k;
152 }
153 }
154 }
155 }
156 /*output of the matrix*/
157 for(i=0;i<MATROWS(m);i++)
158 {
159 k=l[0];
160 Print("%-*.*s",l[0],l[0],s[i*MATCOLS(m)]);
161 omFree(s[i*MATCOLS(m)]);
162 for(j=1;j<MATCOLS(m);j++)
163 {
164 if (k+l[j]>colmax)
165 {
166 PrintS("\n ");
167 k=2;
168 }
169 k+=l[j];
170 Print("%-*.*s",l[j],l[j],s[i*MATCOLS(m)+j]);
171 omFree(s[i*MATCOLS(m)+j]);
172 }
173 PrintLn();
174 }
175 /* clean up */
176 omFreeSize((ADDRESS)s,MATCOLS(m)*MATROWS(m)*sizeof(char*));
177 omFreeSize((ADDRESS)l,MATCOLS(m)*sizeof(int));
178 }
179 else Print("%d x %d zero matrix\n",MATROWS(m),MATCOLS(m));
180}
181
182/*2
183* print for: matrix
184*/
186{
187 matrix m=(matrix)u->Data();
188 ipPrint_MA0(m,u->Name());
189 return FALSE;
190}
191
192/*2
193* print for: ring
194*/
195static BOOLEAN ipPrint_RING(ring r)
196{
197 PrintS("polynomial ring, over a ");
198 if (rField_is_Ring(r))
199 {
200 if (rField_is_Domain(r)) PrintS("domain");
201 else PrintS("ring (with zero-divisors)");
202 }
203 else PrintS("field");
204 if (r->OrdSgn==1) PrintS(", global");
205 else if (r->MixedOrder==1) PrintS(", mixed");
206 else PrintS(", local");
207 PrintS(" ordering\n");
208 rWrite(r, TRUE);
209 return FALSE;
210}
211
213{
214 if (nCoeff_is_Ring(r))
215 {
216 if (nCoeff_is_Domain(r)) PrintS("domain: ");
217 else PrintS("ring (with zero-divisors): ");
218 }
219 else PrintS("field: ");
220 PrintS(nCoeffName(r));
221 return FALSE;
222}
223/*2
224* print for: vector
225*/
226static BOOLEAN ipPrint_V(poly u)
227{
228 polyset m=NULL;
229 int l,j;
230 /*convert into an array of the components*/
231 p_Vec2Polys(u, &m, &l, currRing);
232 /*output*/
233 PrintS("[");
234 j=0;
235 loop
236 {
237 PrintS(pString(m[j]));
238 j++;
239 if (j<l) PrintS(",");
240 else
241 {
242 PrintS("]\n");
243 break;
244 }
245 }
246 /* clean up */
247 for(j=l-1;j>=0;j--) pDelete(&m[j]);
248 omFreeSize((ADDRESS)m,l*sizeof(poly));
249 return FALSE;
250}
251
253{
254 SPrintStart();
255 BOOLEAN bo=FALSE;
256 void *d=u->Data();
257 switch(u->Typ())
258 {
259 case INTVEC_CMD:
260 bo=ipPrint_INTVEC((intvec*)d);
261 break;
262
263 case INTMAT_CMD:
264 bo=ipPrint_INTMAT((intvec*)d);
265 break;
266
267 case MATRIX_CMD:
268 bo=ipPrint_MA(u);
269 break;
270
271 case IDEAL_CMD:
272 {
273 char* s = u->String(NULL, FALSE, 2);
274 PrintS(s);
275 PrintLn();
276 omFree(s);
277 break;
278 }
279
280 case MODUL_CMD:
281 {
283 ipPrint_MA0(m, u->Name());
284 id_Delete((ideal *) &m,currRing);
285 break;
286 }
287
288 case VECTOR_CMD:
289 bo=ipPrint_V((poly)d);
290 break;
291
292 case RING_CMD:
293 bo=ipPrint_RING((ring)d);
294 break;
295
296 case CRING_CMD:
297 bo=ipPrint_CRING((coeffs)d);
298 break;
299
300 default:
301 u->Print();
302 break;
303 }
304 char *s=SPrintEnd();
305 if (u->next==NULL)
306 {
307 int l=strlen(s);
308 if (s[l-1]=='\n') s[l-1]='\0';
309 }
310 res->data=(void*)s;
311 return bo;
312}
313
314
315/*2
316* dbprint
317*/
319{
320 BOOLEAN print=(printlevel>myynest);
321 if ((u->next!=NULL)&&(u->Typ()==INT_CMD))
322 {
323 print= (((int)((long)(u->Data()))) > 0);
324 u=u->next;
325 }
326 if (print)
327 {
328 // BOOLEAN r=FALSE;
329 leftv h=u;
330 leftv hh;
331 while (h!=NULL)
332 {
333 hh=h->next;
334 h->next=NULL;
335 if (jjPRINT(res, h)) return TRUE;
336 PrintS((char*)res->data);
337 omFree(res->data);
338 PrintLn();
339 h->next=hh;
340 h=hh;
341 }
342 }
343 return FALSE;
344}
345
346static void ipPrintBetti(leftv u)
347{
348 int i,j;
349 int row_shift=(int)((long)(atGet(u,"rowShift",INT_CMD)));
350 intvec * betti=(intvec *)u->Data();
351 // head line --------------------------------------------------------
352 PrintS(" "); // 6 spaces for no. and :
353 for(j=0;j<betti->cols();j++) Print(" %5d",j); // 6 spaces pro column
354 PrintS("\n------"); // 6 spaces for no. and :
355 for(j=0;j<betti->cols();j++) PrintS("------"); // 6 spaces pro column
356 PrintLn();
357 // the table --------------------------------------------------------
358 for(i=0;i<betti->rows();i++)
359 {
360 Print("%5d:",i+row_shift);
361 for(j=1;j<=betti->cols();j++)
362 {
363 int m=IMATELEM(*betti,i+1,j);
364 if (m==0)
365 PrintS(" -");
366 else
367 Print(" %5d",m);
368 }
369 PrintLn();
370 }
371 // sum --------------------------------------------------------------
372 PrintS("------"); // 6 spaces for no. and :
373 for(j=0;j<betti->cols();j++) PrintS("------"); // 6 spaces pro column
374 PrintS("\ntotal:");
375 for(j=0;j<betti->cols();j++)
376 {
377 int s=0;
378 for(i=0;i<betti->rows();i++)
379 {
380 s+=IMATELEM(*betti,i+1,j+1);
381 }
382 Print(" %5d",s); // 6 spaces pro column
383 }
384 PrintLn();
385}
386
387
388/*2
389* print(...,"format")
390*/
392{
393/* ==================== betti ======================================== */
394 if ((u->Typ()==INTMAT_CMD)&&(strcmp((char *)v->Data(),"betti")==0))
395 {
396 SPrintStart();
397 ipPrintBetti(u);
398 char *s = SPrintEnd();
399 s[strlen(s)]='\0';
400 res->data=s;
401 }
402 else
403/* ======================== end betti ================================= */
404 {
405 char* ns = omStrDup((char*) v->Data());
406 int dim = 1;
407 if (strlen(ns) == 3 && ns[1] == '2')
408 {
409 dim = 2;
410 ns[1] = ns[2];
411 ns[2] = '\0';
412 }
413 if (strcmp(ns,"%l") == 0)
414 {
415 res->data = (char*) u->String(NULL, TRUE, dim);
416 if (dim == 2)
417 {
418 char* ns = (char*) omAlloc(strlen((char*) res->data) + 2);
419 strcpy(ns, (char*) res->data);
420 omFree(res->data);
421 strcat(ns, "\n");
422 res->data = ns;
423 }
424 }
425 else if (strcmp(ns,"%t") == 0)
426 {
427 SPrintStart();
428 type_cmd(u);
429 res->data = SPrintEnd();
430 if (dim != 2)
431 ((char*)res->data)[strlen((char*)res->data) -1] = '\0';
432 }
433 else if (strcmp(ns,"%;") == 0)
434 {
435 SPrintStart();
436 u->Print();
437 if (dim == 2) PrintLn();
438 res->data = SPrintEnd();
439 }
440 else if (strcmp(ns,"%p") == 0)
441 {
443 }
444 else if (strcmp(ns,"%b") == 0 && (u->Typ()==INTMAT_CMD))
445 {
446 SPrintStart();
447 ipPrintBetti(u);
448 if (dim == 2) PrintLn();
449 res->data = SPrintEnd();
450 }
451 else
452 {
453 res->data = u->String(NULL, FALSE, dim);
454 if (dim == 2)
455 {
456 char* ns = (char*) omAlloc(strlen((char*) res->data) + 2);
457 strcpy(ns, (char*) res->data);
458 omFree(res->data);
459 strcat(ns, "\n");
460 res->data = ns;
461 }
462 }
463 omFree(ns);
464 }
465 return FALSE;
466}
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
int l
Definition cfEzgcd.cc:100
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int cols() const
Definition intvec.h:96
int rows() const
Definition intvec.h:97
int Typ()
Definition subexpr.cc:1048
void * Data()
Definition subexpr.cc:1192
leftv next
Definition subexpr.h:86
char * String(void *d=NULL, BOOLEAN typed=FALSE, int dim=1)
Called for conversion to string (used by string(..), write(..),..)
Definition subexpr.cc:765
const char * Name()
Definition subexpr.h:120
void Print(leftv store=NULL, int spaces=0)
Called by type_cmd (e.g. "r;") or as default in jPRINT.
Definition subexpr.cc:63
static FORCE_INLINE BOOLEAN nCoeff_is_Domain(const coeffs r)
returns TRUE, if r is a field or r has no zero divisors (i.e is a domain)
Definition coeffs.h:734
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition coeffs.h:730
static FORCE_INLINE char * nCoeffName(const coeffs cf)
Definition coeffs.h:960
#define Print
Definition emacs.cc:80
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
VAR int printlevel
Definition febase.cc:36
VAR int myynest
Definition febase.cc:41
@ IDEAL_CMD
Definition grammar.cc:285
@ MATRIX_CMD
Definition grammar.cc:287
@ INTMAT_CMD
Definition grammar.cc:280
@ MODUL_CMD
Definition grammar.cc:288
@ VECTOR_CMD
Definition grammar.cc:293
@ RING_CMD
Definition grammar.cc:282
ideal id_Copy(ideal h1, const ring r)
copy an ideal
#define IMATELEM(M, I, J)
Definition intvec.h:86
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition iparith.cc:9330
static BOOLEAN ipPrint_RING(ring r)
Definition ipprint.cc:195
void ipPrint_MA0(matrix m, const char *name)
Definition ipprint.cc:57
BOOLEAN jjPRINT(leftv res, leftv u)
Definition ipprint.cc:252
static BOOLEAN ipPrint_V(poly u)
Definition ipprint.cc:226
static BOOLEAN ipPrint_MA(leftv u)
Definition ipprint.cc:185
static void ipPrintBetti(leftv u)
Definition ipprint.cc:346
static BOOLEAN ipPrint_INTVEC(intvec *v)
Definition ipprint.cc:30
BOOLEAN jjPRINT_FORMAT(leftv res, leftv u, leftv v)
Definition ipprint.cc:391
static BOOLEAN ipPrint_INTMAT(intvec *v)
Definition ipprint.cc:40
static BOOLEAN ipPrint_CRING(coeffs r)
Definition ipprint.cc:212
BOOLEAN jjDBPRINT(leftv res, leftv u)
Definition ipprint.cc:318
void type_cmd(leftv v)
Definition ipshell.cc:255
STATIC_VAR Poly * h
Definition janet.cc:971
ip_smatrix * matrix
Definition matpol.h:43
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omFree(addr)
#define omAlloc0(size)
#define omFreeBinAddr(addr)
#define NULL
Definition omList.c:12
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition p_polys.cc:3705
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
#define pDelete(p_ptr)
Definition polys.h:187
void pString0(poly p)
Definition polys.h:308
char * pString(poly p)
Definition polys.h:307
poly * polyset
Definition polys.h:260
void SPrintStart()
Definition reporter.cc:246
void StringSetS(const char *st)
Definition reporter.cc:128
void StringAppendS(const char *st)
Definition reporter.cc:107
void PrintS(const char *s)
Definition reporter.cc:284
char * StringEndS()
Definition reporter.cc:151
char * SPrintEnd()
Definition reporter.cc:273
void PrintLn()
Definition reporter.cc:310
EXTERN_VAR int colmax
Definition reporter.h:17
void rWrite(ring r, BOOLEAN details)
Definition ring.cc:227
static BOOLEAN rField_is_Domain(const ring r)
Definition ring.h:493
#define rField_is_Ring(R)
Definition ring.h:491
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
matrix id_Module2Matrix(ideal mod, const ring R)
sleftv * leftv
Definition structs.h:53
#define loop
Definition structs.h:71
int name
New type name for int.
@ CRING_CMD
Definition tok.h:56
@ INTVEC_CMD
Definition tok.h:101
@ PRINT_CMD
Definition tok.h:156
@ INT_CMD
Definition tok.h:96
int dim(ideal I, ring r)