1 /* SYMMETRICA rh.c */
2 #include "def.h"
3 #include "macro.h"
4
5 #ifdef REIHETRUE
6
7 /* ++++++++++++ jetzt Variablendeklaration +++++++++++++++ */
8 static INT zuwachs=(INT)5;
9
10 /* +++++++++++ Funktionsdeklaration +++++++++++++++++ */
11
12 #define new_var new_drei
13 #define new_mon new_zwei
14 static INT co_261093();
15 static INT reihevergleich ();
16 static INT Eins_eingabe();
17 static INT co_eingabe();
18 static INT Random_eingabe();
19 static INT co_REIHE();
20 static int debugprint_rh();
21 static int debugprint_rh_var();
22 static int debugprint_rh_mon();
23 static int debugprint_rh_poly();
24 static struct REIHE_variablen *new_drei();
25 static struct REIHE_mon *new_zwei();
26 static struct REIHE_poly *new_eins();
27 static INT JH_add_reihe();
28 static INT JH_mult_reihe();
29 static int pot_reihe();
30 static int transform_reihe();
31 static int subst_reihe();
32 static int ableitung_reihe();
33 static INT initial_reihe();
34 static INT einfuegen_in_reihe();
35 static int del_reihe();
36 static int del_var();
37 static int del_mon();
38 static int del_poly();
39 static int normalisiere_reihe();
40 static int make_skalar_reihe();
41 static INT make_reihe();
42 static INT ergaenze_reihe();
43 static int card_typ_reihe();
44 static int card_reihe();
45 static int variablenvergleich();
46 static int monomvergleich ();
47 static int monomgrad();
48 static INT monommult();
49 static INT monomausgabe();
50 static int trans_reihe_in_monom();
51 static int copyy_monom();
52 static void JH_copy_reihe();
53 static void JH_copy_reihe_co();
54 static INT reihe_zu_sympolynom(), monom_zu_symmonom();
55 static INT poly_zu_sympolynom();
56 static int ausgabe();
57 static void copy_var(), copy_mon();
58 static int free_drei(), free_zwei(), free_eins();
59
del_poly(p)60 static int del_poly(p) struct REIHE_poly **p;
61 /* AK 110393 */
62 {
63 if (*p != NULL)
64 {
65 del_mon(& (*p) ->unten);
66 del_poly(& (*p) ->rechts);
67 free_eins((char*)*p);
68 *p = NULL;
69 }
70 }
71
del_mon(m)72 static int del_mon(m) struct REIHE_mon **m;
73 /* AK 110393 */
74 {
75 if (*m != NULL)
76 {
77 del_var(& (*m)->zeiger);
78 if ((*m)-> coeff != NULL)
79 freeall((*m)->coeff);
80 del_mon(& (*m)->ref);
81 free_zwei((char*)(*m));
82 *m = NULL;
83 }
84 }
85
del_var(v)86 static int del_var(v) struct REIHE_variablen **v;
87 /* AK 110393 */
88 {
89 if (*v != NULL)
90 {
91 del_var(&(*v)->weiter);
92 free_drei((char*)*v);
93 *v = NULL;
94 }
95 }
96
copy_poly(a,b)97 static void copy_poly(a,b) struct REIHE_poly **b,*a;
98 /* AK 150393 */
99 {
100 if (a==NULL) { *b = NULL; return; }
101 *b = (struct REIHE_poly *) SYM_malloc(sizeof(struct REIHE_poly));
102 if (*b == NULL) { no_memory(); return; }
103 (*b)->grad = a->grad;
104
105 copy_mon(a->unten, & (*b)->unten);
106 copy_poly(a->rechts, & (*b)->rechts);
107 }
108
copy_mon(a,b)109 static void copy_mon(a,b) struct REIHE_mon **b,*a;
110 /* AK 150393 */
111 {
112 if (a==NULL) { *b = NULL; return; }
113 *b = (struct REIHE_mon *) SYM_malloc(sizeof(struct REIHE_mon));
114 if (*b == NULL) { no_memory(); return; }
115 (*b)->coeff=callocobject();
116 copy(a->coeff, (*b)->coeff);
117 copy_mon(a->ref, & (*b)->ref);
118 copy_var(a->zeiger, & (*b)->zeiger);
119 }
120
copy_var(a,b)121 static void copy_var(a,b) struct REIHE_variablen **b,*a;
122 /* AK 150393 */
123 {
124 if (a == NULL) { *b = NULL; return; }
125 *b = (struct REIHE_variablen *) SYM_malloc(sizeof(struct REIHE_variablen));
126 if (*b == NULL) { no_memory(); return; }
127 (*b)->index = a->index;
128 (*b)->potenz = a->potenz;
129 copy_var(a->weiter, & (*b)->weiter);
130 }
131
copy_rh(a,b)132 static void copy_rh(a,b) REIHE_zeiger a,*b;
133 {
134 if (a == NULL) { *b = NULL; return; }
135 *b = (struct reihe *) SYM_malloc(sizeof(struct reihe));
136 if (*b == NULL) { no_memory(); return; }
137 (*b)->exist = a->exist;
138 (*b)->reihenart = a->reihenart;
139 (*b)->z = a->z;
140 (*b)->ope = a->ope;
141 (*b)->eingabefkt = a->eingabefkt;
142 copy_rh(a->x, & (*b)->x);
143 copy_rh(a->y, & (*b)->y);
144 copy_rh(a->p, & (*b)->p);
145 copy_poly(a->infozeig, & (*b)->infozeig);
146 }
147
148
max_degree_reihe(a,b)149 INT max_degree_reihe(a,b) OP a,b;
150 /* AK 100393 */
151 {
152 OBJECTSELF d;
153 INT i;
154 INT erg = OK;
155 CTO(REIHE,"max_degree_reihe",a);
156 d = S_O_S(a);
157 if (d.ob_reihe == NULL)
158 {
159 erg += m_i_i((INT)-1,b);
160 goto endr_ende;
161 }
162 i = d.ob_reihe -> exist;
163 erg += m_i_i(i,b);
164 ENDR("max_degree_reihe");
165 }
166
167
new_drei()168 static struct REIHE_variablen *new_drei()
169 {
170 return (struct REIHE_variablen*) SYM_calloc(1,sizeof(struct REIHE_variablen));
171 }
free_drei(a)172 static int free_drei(a) char *a; { SYM_free(a); }
free_zwei(a)173 static int free_zwei(a) char *a; { SYM_free(a); }
free_eins(a)174 static int free_eins(a) char *a; { SYM_free(a); }
free_null_debug(a)175 static int free_null_debug(a) char *a; { printf("free_null:%p\n",a); SYM_free(a); }
free_null(a)176 static int free_null(a) char *a; { SYM_free(a); }
177
new_zwei()178 static struct REIHE_mon *new_zwei()
179 {
180 return (struct REIHE_mon*) SYM_calloc(1,sizeof(struct REIHE_mon));
181 }
182
new_eins()183 static struct REIHE_poly *new_eins()
184 {
185 return
186 (struct REIHE_poly*) SYM_calloc(1,sizeof(struct REIHE_poly));
187 }
188
new_null()189 static struct reihe *new_null() {
190 struct reihe *a;
191 a = (struct reihe*) SYM_calloc(1,sizeof(struct reihe)); return a; }
192
new_null_debug()193 static struct reihe *new_null_debug() {
194 struct reihe *a;
195 a = (struct reihe*) SYM_calloc(1,sizeof(struct reihe));
196 printf("new_null:%p\n",a);
197 return a; }
198
initial_reihe(adress)199 static INT initial_reihe(adress) REIHE_zeiger* adress;
200 /* JH 0293 */
201 {
202 *adress=new_null();
203 if (*adress == NULL)
204 return no_memory();
205 (*adress)->exist=0L;
206 (*adress)->reihenart=1L;
207 (*adress)->x=NULL;
208 (*adress)->y=NULL;
209 (*adress)->z=0L;
210 (*adress)->p=NULL;
211 (*adress)->eingabefkt=NULL;
212 (*adress)->ope='#';
213 (*adress)->infozeig=new_eins();
214 (*adress)->infozeig->unten=NULL;
215 (*adress)->infozeig->rechts=NULL;
216 (*adress)->infozeig->grad=0L;
217 return OK;
218 }
219
callocreihe()220 static struct reihe *callocreihe()
221 /* AK 090393 */
222 {
223 struct reihe *a;
224 initial_reihe(&a);
225 return a;
226 }
227
init_reihe(a)228 INT init_reihe(a) OP a;
229 /* AK 090393 */
230 {
231 OBJECTSELF c;
232 c.ob_reihe = callocreihe();
233 B_KS_O(REIHE,c,a);
234 return OK;
235 }
236
normalisiere_reihe(a)237 static int normalisiere_reihe(a) REIHE_zeiger a;
238 { /* entfernen des absoluten Gliedes wegen pletist. Subst. */
239 a->infozeig->unten=NULL;
240 }
241
card_reihe(a)242 static int card_reihe(a) REIHE_zeiger a;
243 {
244 struct REIHE_poly *zeigpoly;
245 struct REIHE_mon *zeigmon;
246
247 if (a!=NULL)
248 {
249 zeigpoly=a->infozeig;
250 do
251 {
252 if (zeigpoly->unten!=NULL)
253 {
254 zeigmon=zeigpoly->unten;
255 if (((zeigmon->zeiger)==NULL) ||
256 ((zeigmon->zeiger->potenz)==(zeigpoly->grad)))
257 monomausgabe(zeigmon);
258 }
259 zeigpoly=zeigpoly->rechts;
260 } while (zeigpoly!=NULL);
261 }
262 }
263
card_typ_reihe(a)264 static int card_typ_reihe(a) REIHE_zeiger a;
265 {
266 struct REIHE_poly *zeigpoly;
267 struct REIHE_mon *zeigmon;
268 OP e;
269
270 if (a!=NULL)
271 {
272 zeigpoly=a->infozeig;
273 do
274 {
275 if (zeigpoly->unten!=NULL)
276 {
277 e=callocobject();
278 m_i_i(0L,e);
279 zeigmon=zeigpoly->unten;
280 do
281 {
282 add_apply(zeigmon->coeff,e);
283 zeigmon=zeigmon->ref;
284 } while (zeigmon!=NULL);
285 print(e);
286 if (zeigpoly->grad!= (INT)0) printf("X^%i\n",zeigpoly->grad);
287 else printf("\n");
288 freeall(e);
289 }
290 zeigpoly=zeigpoly->rechts;
291 } while (zeigpoly!=NULL);
292 }
293 }
294
295
variablenvergleich(p,q)296 static int variablenvergleich(p,q) struct REIHE_variablen* p, * q;
297 {
298 int hilf;
299 if (q==NULL) hilf=2;
300 else if (p == NULL) hilf = -1; /* AK 040893 */
301 else
302 { /* referenzmonom ist ....... als einzufuegendes monom */
303 hilf=0; /* gleich */
304 if ((p->index)>(q->index)) hilf= -1; /* kleiner */
305 if ((p->index)<(q->index)) hilf=1; /* groesser */
306 }
307 return hilf;
308 }
309
monomvergleich(p,q)310 static int monomvergleich (p,q) struct REIHE_mon* p, * q;
311 { /* p einzufuegendes Monom */
312 struct REIHE_variablen* p1;
313 struct REIHE_variablen* q1;
314 int hilf;
315
316 if (q==NULL) hilf=2; /* q ist NULLREIHE_zeiger */
317 else
318 {
319 p1=p->zeiger; /* koennen NULL sein bei abs. Glied */
320 q1=q->zeiger;
321 if ((p1==NULL) && (q1==NULL)) hilf=0; /* gleich */
322 else if (p1==NULL) hilf= -1; /* AK 030893 */
323 else if (q1==NULL) hilf=1; /* AK 030893 */
324 else
325 {
326 while (((p1->index)==(q1->index))
327 && ((p1->potenz)==(q1->potenz))
328 && ((p1->weiter)!=NULL)) /* nur wenn gleiche Monome, */
329 { /* sonst schon vorher Unterschied */
330 p1=p1->weiter;
331 q1=q1->weiter;
332 }
333
334 if ((p1->weiter==NULL) &&
335 ((p1->index)==(q1->index)) &&
336 ((p1->potenz)==(q1->potenz)))
337 hilf=0; /* gleiche Monome */
338
339 /* falls Unterschied erst beim letzten Monomteil
340 und p->weiter ist also Null */
341
342 else
343 {
344 if ((p1->index<q1->index) ||
345 ((p1->index==q1->index)
346 && (p1->potenz>q1->potenz)))
347 hilf=1; /* Referenzmonom ist groeaer */
348 else
349 hilf= -1;/* Referenzmonom ist kleiner */
350 }
351 }
352 }
353
354 return hilf;
355 }
356
monomgrad(p)357 static int monomgrad(p) struct REIHE_mon* p;
358 {
359 struct REIHE_variablen* p1;
360 int hilf;
361
362 hilf=0;
363 p1=p->zeiger;
364 if (p1!=NULL)
365 {
366 do
367 {
368 /* hilf=hilf+((p1->index))*(p1->potenz); */
369 hilf=hilf+((p1->index)+1)*(p1->potenz);
370 p1=p1->weiter;
371 } while (p1!=NULL);
372 }
373 return hilf;
374 }
375
376
einfuegen_in_reihe(m,in)377 static INT einfuegen_in_reihe(m,in) struct REIHE_mon* m; REIHE_zeiger in;
378 {
379 /* ein neuer Grad ist immer groeaer als Null,
380 es wurde mit Null initialisiert */
381
382 int g,v,gefunden;
383 INT erg = OK;
384
385 struct REIHE_poly *zeigpol,*p;
386 struct REIHE_mon* zeigmon;
387 struct REIHE_mon* hilfmon;
388 struct REIHE_variablen* zeigvar,hilfvar;
389
390 g=monomgrad(m);
391
392 gefunden=0;
393
394 p=in->infozeig;
395
396 if (p==NULL)
397 error("internal error:RH6");
398
399 while ((p->rechts!=NULL) && (gefunden==0))
400 {
401 if ((p->rechts->grad)<=g)
402 p=p->rechts;
403 else gefunden=1;
404 }
405
406 /* Vergleiche von links nach rechts , Abbruch sobald etwas zutrifft */
407 /* also while ((p->rechts!=NULL) && (p->rechts->grad<g)) */
408
409 if (p->grad==g)
410 {
411 switch(v=monomvergleich(m,p->unten)) /* falls ganz oben */
412 { /*eingesetzt werden mua */
413 case 2:
414 p->unten=m;
415 break; /* als erstes Monom bei Grad 0 */
416
417 case 1:
418 hilfmon=p->unten; /* ganz oben einsetzen */
419 p->unten=m;
420 m->ref=hilfmon;
421 break;
422
423 case 0:
424 add_apply(m->coeff,p->unten->coeff);
425 del_mon(& m); /* AK 110393 */
426 break;
427 }
428
429 if (v==-1) /* also noch nicht ganz vorne eingefuegt */
430 {
431 zeigmon=p->unten;
432 while ((v=monomvergleich(m,zeigmon->ref))<=0)
433 zeigmon=zeigmon->ref;
434
435 if (monomvergleich(m,zeigmon)==0) /* passendes Monom gefunden */
436 {
437 erg += add_apply(m->coeff,zeigmon->coeff) ;
438 del_mon(& m); /* AK 110393 */
439 }
440 else
441 switch(v)
442 {
443 case 2 : /* am Ende anfuegen */
444 zeigmon->ref=m;
445 break;
446
447 case 1 : /* naechstes Monom ist groeaer */
448 hilfmon=zeigmon->ref;
449 zeigmon->ref=m;
450 m->ref=hilfmon;
451 break;
452 }
453 }
454 }
455 else
456 if (p->rechts==NULL) /* am Ende neuen Grad erzeugen */
457 {
458 p->rechts=new_eins();
459 p=p->rechts;
460 p->grad=g;
461 p->unten=m;
462 p->rechts=NULL;
463 }
464 else /* neuen Grad dazwischenschieben */
465 {
466 zeigpol=p->rechts;
467 p->rechts=new_eins();
468 p=p->rechts;
469 p->rechts=zeigpol;
470 p->grad=g;
471 p->unten=m;
472 }
473 if (erg != OK)
474 error("internal error:RH7");
475 return erg;
476 }
477
Exp_eingabe(root,anzahl)478 INT Exp_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
479 /* JH 0293 */
480 {
481 OP b,d,f;
482 INT l;
483 struct REIHE_mon *zeigmon;
484
485 b=callocobject();
486 d=callocobject();
487 f=callocobject();
488
489 if (root->exist==0)
490 {
491 zeigmon=new_zwei();
492 zeigmon->coeff=callocobject();
493 zeigmon->zeiger=NULL;
494 zeigmon->ref=NULL;
495 m_i_i(1L,zeigmon->coeff);
496 einfuegen_in_reihe(zeigmon,root);
497 }
498
499 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
500 {
501 m_i_i(l,d);
502 fakul(d,b);
503 zeigmon=new_zwei();
504 zeigmon->coeff=callocobject();
505 zeigmon->zeiger=NULL;
506 zeigmon->ref=NULL;
507 m_i_i(1L,f);
508 m_ou_b(f,b,zeigmon->coeff);
509 kuerzen(zeigmon->coeff);
510 zeigmon->zeiger=new_drei();
511 zeigmon->zeiger->weiter=NULL;
512 zeigmon->zeiger->index=1;
513 zeigmon->zeiger->potenz=l;
514 einfuegen_in_reihe(zeigmon,root);
515 }
516 root->exist+=anzahl; /* erhoehen um anzahl */
517 freeall(b);
518 freeall(d);
519 freeall(f);
520 }
521
522
co_261093(root,anzahl,func)523 static INT co_261093(root,anzahl,func) REIHE_zeiger root; INT anzahl;
524 INT (*func)();
525 /* bei benutzer definierten funktionen
526 f ist vom typ (OP degree, OP koeff) */
527 {
528 OP b,d,f;
529 OP bb;
530 INT i,j,l,k;
531 INT erg=OK;
532 struct REIHE_mon *zeigmon;
533 struct REIHE_variablen *zeigvar,*help_drei;
534
535 b=callocobject();
536 d=callocobject();
537 f=callocobject();
538
539 if (root->exist==0L)
540 {
541 zeigmon=new_zwei();
542 zeigmon->coeff=callocobject();
543 zeigmon->zeiger=NULL;
544 zeigmon->ref=NULL;
545 /* m_i_i(1L,zeigmon->coeff); */
546 (*func)(cons_null,b);
547 if (S_O_K(b) != POLYNOM)
548 EDC("RH11:internal error");
549 copy(S_PO_K(b),zeigmon->coeff);
550 einfuegen_in_reihe(zeigmon,root);
551 }
552 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
553 {
554 m_i_i(l,d);
555 (*func)(d,b);
556 if (S_O_K(b) != POLYNOM)
557 EDC("RH12:internal error");
558 bb = b;
559 while (bb!=NULL)
560 {
561 zeigmon=new_zwei();
562 zeigmon->coeff=callocobject();
563 zeigmon->zeiger=NULL;
564 zeigmon->ref=NULL;
565 /* m_i_i(1L,f); */
566 copy(S_PO_K(bb) ,zeigmon->coeff);
567 /* for (j=1L;j<=l;j++) */
568 for (j=1L;j<=S_PO_SLI(bb);j++)
569 {
570 if ((k=S_PO_SII(bb,j-1))!=0L)
571 {
572 help_drei=new_drei();
573 help_drei->weiter=NULL;
574 if (zeigmon->zeiger==NULL) zeigmon->zeiger=help_drei;
575 else zeigvar->weiter=help_drei;
576 zeigvar=help_drei;
577 /* zeigvar->index=j; */
578 zeigvar->index=j-1;
579 zeigvar->potenz=k;
580 }
581 }
582 einfuegen_in_reihe(zeigmon,root);
583 bb=S_PO_N(bb);
584 }
585 freeall(b);
586 b=callocobject();
587 }
588 root->exist+=anzahl; /* erhoehen um anzahl */
589 freeall(b);
590 freeall(d);
591 freeall(f);
592 }
593
Sinus_eingabe(root,anzahl)594 INT Sinus_eingabe(root,anzahl) REIHE_zeiger root; INT anzahl;
595 {
596 OP a,b,c,d,e,f;
597 INT l;
598 struct REIHE_mon *zeigmon;
599
600 b=callocobject();
601 d=callocobject();
602 f=callocobject();
603 e=callocobject();
604 m_i_i(2L,e);
605
606 for (l=(root->exist)+1;l<=(root->exist)+anzahl;l++)
607 {
608 a=callocobject();
609 c=callocobject();
610 m_i_i(l,a);
611 mod(a,e,c);
612 if (einsp(c))
613 {
614 m_i_i(l,d);
615 fakul(d,b);
616 zeigmon=new_zwei();
617 zeigmon->coeff=callocobject();
618 zeigmon->zeiger=NULL;
619 zeigmon->ref=NULL;
620 freeall(c);
621 c=callocobject();
622 ganzdiv(a,e,c);
623 freeall(a);
624 a=callocobject();
625 mod(c,e,a);
626 if (einsp(a)) m_i_i(-1L,f);
627 else m_i_i(1L,f);
628 m_ou_b(f,b,zeigmon->coeff);
629 kuerzen(zeigmon->coeff);
630 zeigmon->zeiger=new_drei();
631 zeigmon->zeiger->weiter=NULL;
632 zeigmon->zeiger->index=0;
633 zeigmon->zeiger->potenz=l;
634 einfuegen_in_reihe(zeigmon,root);
635 }
636 freeall(a);
637 freeall(c);
638 }
639 root->exist = (root->exist)+anzahl; /* erhoehen um anzahl */
640 freeall(b);
641 freeall(d);
642 freeall(f);
643 freeall(e);
644 return OK;
645 }
646
Cosinus_eingabe(root,anzahl)647 INT Cosinus_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
648 /* JH 0293 */
649 {
650 OP a,b,c,d,e,f;
651 INT l;
652 struct REIHE_mon *zeigmon;
653
654 b=callocobject();
655 d=callocobject();
656 f=callocobject();
657 e=callocobject();
658 m_i_i(2L,e);
659
660 if (root->exist==0L)
661 {
662 zeigmon=new_zwei();
663 zeigmon->coeff=callocobject();
664 zeigmon->zeiger=NULL;
665 zeigmon->ref=NULL;
666 m_i_i(1L,zeigmon->coeff);
667 einfuegen_in_reihe(zeigmon,root);
668 }
669
670 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
671 {
672 a=callocobject();
673 c=callocobject();
674 m_i_i(l,a);
675 mod(a,e,c);
676 if (nullp(c))
677 {
678 m_i_i(l,d);
679 fakul(d,b);
680 zeigmon=new_zwei();
681 zeigmon->coeff=callocobject();
682 zeigmon->zeiger=NULL;
683 zeigmon->ref=NULL;
684 freeall(c);
685 c=callocobject();
686 ganzdiv(a,e,c);
687 freeall(a);
688 a=callocobject();
689 mod(c,e,a);
690 if (einsp(a)) m_i_i(-1L,f);
691 else m_i_i(1L,f);
692 m_ou_b(f,b,zeigmon->coeff);
693 kuerzen(zeigmon->coeff);
694 zeigmon->zeiger=new_drei();
695 zeigmon->zeiger->weiter=NULL;
696 zeigmon->zeiger->index=0;
697 zeigmon->zeiger->potenz=l;
698 einfuegen_in_reihe(zeigmon,root);
699 }
700 freeall(a);
701 freeall(c);
702 }
703 root->exist+=anzahl; /* erhoehen um anzahl */
704 freeall(b);
705 freeall(d);
706 freeall(e);
707 freeall(f);
708 return OK;
709 }
710
711 #ifdef PARTTRUE
712
Perm_eingabe(root,anzahl)713 INT Perm_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
714 {
715 OP b,d,f;
716 OP bb;
717 INT i,j,l,k;
718 struct REIHE_mon *zeigmon;
719 struct REIHE_variablen *zeigvar,*help_drei;
720
721 b=callocobject();
722 d=callocobject();
723 f=callocobject();
724
725 if (root->exist==0)
726 {
727 zeigmon=new_zwei();
728 zeigmon->coeff=callocobject();
729 zeigmon->zeiger=NULL;
730 zeigmon->ref=NULL;
731 m_i_i(1L,zeigmon->coeff);
732 einfuegen_in_reihe(zeigmon,root);
733 }
734 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
735 {
736 m_i_i(l,d);
737 zykelind_Sn(d,b);
738 bb = b;
739 while (bb!=NULL)
740 {
741 zeigmon=new_zwei();
742 zeigmon->coeff=callocobject();
743 zeigmon->zeiger=NULL;
744 zeigmon->ref=NULL;
745 m_i_i(1L,f);
746 copy(f,zeigmon->coeff);
747 for (j=1L;j<=l;j++)
748 {
749 if ((k=S_PO_SII(bb,j-1))!=0)
750 {
751 help_drei=new_drei();
752 help_drei->weiter=NULL;
753 if (zeigmon->zeiger==NULL) zeigmon->zeiger=help_drei;
754 else zeigvar->weiter=help_drei;
755 zeigvar=help_drei;
756 zeigvar->index=j;
757 zeigvar->potenz=k;
758 }
759 }
760 einfuegen_in_reihe(zeigmon,root);
761 bb=s_po_n(bb);
762 }
763 freeall(b);
764 b=callocobject();
765 }
766 root->exist+=anzahl; /* erhoehen um anzahl */
767 freeall(b);
768 freeall(d);
769 freeall(f);
770 return OK;
771 }
772
773
E_eingabe(root,anzahl)774 INT E_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
775 /* JH 0293 */
776 {
777 OP bb;
778 OP b,d,f;
779 INT i,j,l,k;
780 struct REIHE_mon *zeigmon;
781 struct REIHE_variablen *zeigvar,*help_drei;
782
783 b=callocobject();
784 d=callocobject();
785 f=callocobject();
786
787 if (root->exist==0)
788 {
789 zeigmon=new_zwei();
790 zeigmon->coeff=callocobject();
791 zeigmon->zeiger=NULL;
792 zeigmon->ref=NULL;
793 m_i_i(1L,zeigmon->coeff);
794 einfuegen_in_reihe(zeigmon,root);
795 }
796 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
797 {
798 m_i_i(l,d);
799 zykelind_Sn(d,b);
800 bb = b;
801 while (bb!=NULL)
802 {
803 zeigmon=new_zwei();
804 zeigmon->coeff=callocobject();
805 zeigmon->zeiger=NULL;
806 zeigmon->ref=NULL;
807 zeigmon->coeff=s_po_k(bb);
808 for (j=1L;j<=l;j++)
809 {
810 if ((k=S_V_II(s_po_s(bb),j-1))!=0L)
811 {
812 help_drei=new_drei();
813 help_drei->weiter=NULL;
814 if (zeigmon->zeiger==NULL) zeigmon->zeiger=help_drei;
815 else zeigvar->weiter=help_drei;
816 zeigvar=help_drei;
817 zeigvar->index=j;
818 zeigvar->potenz=k;
819 }
820 }
821 einfuegen_in_reihe(zeigmon,root);
822 bb=s_po_n(bb);
823 }
824 freeall(b);
825 b=callocobject();
826 }
827 root->exist+=anzahl; /* erhoehen um anzahl */
828 freeall(b);
829 freeall(d);
830 freeall(f);
831 return OK;
832 }
833
834 #endif /* PARTTRUE */
make_reihe(a,eingabe)835 static INT make_reihe(a,eingabe) REIHE_zeiger* a; INT (*eingabe)();
836 {
837 initial_reihe(a);
838 (*a)->reihenart=1L;
839 (*a)->eingabefkt=eingabe;
840 return OK;
841 }
842
m_function_reihe(f,a)843 INT m_function_reihe(f,a) OP a; INT (*f)();
844 /* AK 261093 */
845 {
846 REIHE_zeiger *b;
847 OBJECTSELF d;
848 INT erg = OK;
849 init(REIHE,a);
850 d = S_O_S(a);
851 b = & d.ob_reihe;
852 ( S_O_S(a).ob_reihe)->reihenart=2L;
853 ( S_O_S(a).ob_reihe)->eingabefkt=f;
854 erg += ergaenze_reihe( & S_O_S(a).ob_reihe,5L);
855 return erg;
856 }
857
858
m_scalar_reihe(c,b)859 INT m_scalar_reihe(c,b) OP c,b;
860 /* AK 100393 */
861 {
862 REIHE_zeiger *a;
863 OBJECTSELF d;
864 init(REIHE,b);
865 d = S_O_S(b);
866 a = & d.ob_reihe;
867 (*a)->reihenart=1L;
868 (*a)->infozeig->unten=new_zwei();
869 (*a)->infozeig->unten->coeff=callocobject();
870 copy(c,(*a)->infozeig->unten->coeff);
871 (*a)->infozeig->unten->zeiger=NULL;
872 (*a)->infozeig->unten->ref=NULL;
873 return OK;
874 }
875
make_skalar_reihe(a)876 static int make_skalar_reihe(a) REIHE_zeiger* a;
877 {
878 initial_reihe(a);
879 (*a)->reihenart=1;
880 (*a)->infozeig->unten=new_zwei();
881 (*a)->infozeig->unten->coeff=callocobject();
882 scan(scanobjectkind(),(*a)->infozeig->unten->coeff);
883 (*a)->infozeig->unten->zeiger=NULL;
884 (*a)->infozeig->unten->ref=NULL;
885 }
886
887
inc_reihe(a)888 INT inc_reihe(a) OP a;
889 /* AK 100393 */
890 {
891 INT erg = OK;
892 erg += ergaenze_reihe( & S_O_S(a).ob_reihe,1L);
893 ENDR("inc_reihe");
894 }
895
ergaenze_reihe(a,zunahme)896 static INT ergaenze_reihe(a,zunahme) REIHE_zeiger* a; INT zunahme;
897 /* JH 0293 */
898 {
899 INT erg = OK;
900 if ((*a)->reihenart==1L)
901 {
902 if (((*a)->eingabefkt)!=NULL)
903 (*((*a)->eingabefkt))((*a),zunahme);
904 }
905 else if ((*a)->reihenart==0L)
906 { /* schon definierte Verknuepfung erweitern */
907 switch((*a)->ope)
908 {
909 case 'a':
910 JH_add_reihe((*a)->x,(*a)->y,*a,zuwachs);
911 break;
912 case 'm':
913 JH_mult_reihe((*a)->x,(*a)->y,*a,zuwachs);
914 break;
915 case 's':
916 subst_reihe((*a)->x,(*a)->y,a,((*a)->exist)+zuwachs);
917 break; /* immer neue Berechnung */
918 case 'p':
919 pot_reihe((*a)->x,(*a)->z,*a,zuwachs);
920 break;
921 case 'l':
922 ableitung_reihe((*a)->x,(*a)->z,*a,zuwachs);
923 break;
924 case 't':
925 transform_reihe((*a)->x,(*a)->z,*a,zuwachs);
926 break;
927 default :
928 erg += error("RH2:internal error");
929 }
930 }
931 else if ((*a)->reihenart == 2L)
932 {
933 co_261093((*a),zunahme,(*a)->eingabefkt);
934 }
935 else if ((*a)->reihenart == -1L)
936 erg += error("RH1:internal error");
937 else
938 erg += error("RH10:internal error");
939 return erg;
940 }
941
comp_reihe(a,b)942 INT comp_reihe(a,b) OP a,b;
943 /* AK 300793 */
944 {
945 OBJECTSELF c,d;
946 INT erg = OK;
947 CTO(REIHE,"comp_reihe",a);
948 CTO(REIHE,"comp_reihe",b);
949 c = S_O_S(a);
950 d = S_O_S(b);
951 return reihevergleich(c.ob_reihe,d.ob_reihe);
952 ENDR("comp_reihe");
953 }
954
fprint_reihe(f,a)955 INT fprint_reihe(f,a) FILE *f; OP a;
956 /* AK 090393 */
957 {
958 OBJECTSELF c;
959 c = S_O_S(a);
960 ausgabe(f,c.ob_reihe);
961 return OK;
962 }
963
964
ausgabe(f,r)965 static int ausgabe(f, r) REIHE_zeiger r; FILE *f;
966 /* JH 0293 */
967 {
968 struct REIHE_poly *zeigpoly;
969 struct REIHE_mon *zeigmon;
970
971 if (r!=NULL)
972 {
973 zeigpoly=r->infozeig;
974 do
975 {
976 if (zeigpoly->unten!=NULL)
977 /* weil p mit Grad 0 initial. wurde, */
978 {
979 /* aber Konst. nicht unbedingt exist. */
980 zeigmon=zeigpoly->unten;
981 do
982 {
983 monomausgabe(f, zeigmon);
984 zeigmon=zeigmon->ref;
985 } while (zeigmon!=NULL);
986 }
987 zeigpoly=zeigpoly->rechts;
988 } while (zeigpoly!=NULL);
989 }
990 }
991
reihevergleich(s,r)992 static INT reihevergleich (s, r) REIHE_zeiger s,r;
993 /* AK 300793 */
994 {
995 struct REIHE_poly *zeigpoly_r;
996 struct REIHE_poly *zeigpoly_s;
997 struct REIHE_mon *zeigmon_r;
998 struct REIHE_mon *zeigmon_s;
999 int erg;
1000
1001 if ((r == NULL) && (s==NULL)) return 0L;
1002 if ((r == NULL) && (s!=NULL)) return 1L;
1003 if ((r != NULL) && (s==NULL)) return -1L;
1004
1005 zeigpoly_r=r->infozeig;
1006 zeigpoly_s=s->infozeig;
1007 do
1008 {
1009 if (zeigpoly_s == NULL) return -1L;
1010 if (zeigpoly_r == NULL) return 1L;
1011
1012 if ((zeigpoly_s->unten!=NULL) &&
1013 (zeigpoly_r->unten!=NULL) )
1014 /* weil p mit Grad 0 initial. wurde, */
1015 {
1016 /* aber Konst. nicht unbedingt exist. */
1017 zeigmon_s=zeigpoly_s->unten;
1018 zeigmon_r=zeigpoly_r->unten;
1019 do
1020 {
1021 if (zeigmon_s == NULL) return -1L;
1022 if (zeigmon_r == NULL) return 1L;
1023
1024 erg = monomvergleich(zeigmon_s, zeigmon_r);
1025 if (erg != 0) return (INT) erg;
1026 zeigmon_s=zeigmon_s->ref;
1027 zeigmon_r=zeigmon_r->ref;
1028 } while ((zeigmon_s!=NULL)||(zeigmon_r!=NULL));
1029 }
1030 zeigpoly_s=zeigpoly_s->rechts;
1031 zeigpoly_r=zeigpoly_r->rechts;
1032 } while ( (zeigpoly_s!=NULL) || (zeigpoly_r!=NULL) ) ;
1033 return 0L;
1034 }
1035
ableitung_reihe(a,n,c,anzahl)1036 static int ableitung_reihe(a,n,c,anzahl) REIHE_zeiger a,c; INT n,anzahl;
1037 {
1038 struct REIHE_poly *zeigpoly;
1039 struct REIHE_mon *zeigmon, *hmon;
1040 struct REIHE_variablen *zeigvar,*hvar1,*hvar2;
1041 OP e;
1042 int gefunden;
1043
1044
1045 if (c->ope=='#') c->ope='l';
1046 c->reihenart=0L;
1047 if ((c->x==NULL) && (c->z==0))
1048 {
1049 c->x=a;
1050 c->z=n;
1051 }
1052 else if ((c->x!=a) || (c->z!=n))
1053 {
1054 printf("Falsche Operanden beim Transformieren!");
1055 exit(3);
1056 }
1057
1058 if (a->exist<c->exist+anzahl+1)
1059 ergaenze_reihe(&a,c->exist+anzahl+n-a->exist);
1060
1061 /* Ableitung erniedrigt Grad des Monoms um n */
1062
1063 if (a!=NULL)
1064 {
1065 zeigpoly=a->infozeig;
1066 if (c->exist!=0)
1067 while ((zeigpoly->grad<=c->exist+n)
1068 && (zeigpoly->rechts!=NULL))
1069 zeigpoly=zeigpoly->rechts;
1070
1071
1072 while ((zeigpoly!=NULL) && (zeigpoly->grad<=c->exist+anzahl+n))
1073 {
1074 if (zeigpoly->unten!=NULL) /* weil p mit Grad 0 initial. wurde, */
1075 { /* aber Konst. nicht unbedingt exist. */
1076 zeigmon=zeigpoly->unten;
1077 do
1078 {
1079 gefunden=0;
1080 if (zeigmon->zeiger!=NULL) /* fuer Grad 0 ex. keine Monome */
1081 {
1082 zeigvar=zeigmon->zeiger;
1083 do /* Pruefen, ob Variable im Monom enthalten ist */
1084 {
1085 if ((zeigvar->index*1L==n) && (zeigvar->potenz>0))
1086 gefunden=1;
1087 zeigvar=zeigvar->weiter;
1088 } while ((zeigvar!=NULL) && (gefunden==0));
1089 if (gefunden==1)
1090 {
1091 hmon=new_zwei();
1092 hmon->zeiger=NULL;
1093 hmon->ref=NULL;
1094 hmon->coeff=callocobject();
1095 copy(zeigmon->coeff,hmon->coeff);
1096 zeigvar=zeigmon->zeiger;
1097 do
1098 {
1099 if (((zeigvar->index*1L==n) && (zeigvar->potenz>1)) ||
1100 (zeigvar->index!=n))
1101 {
1102 /* code folded from here */
1103 hvar1=new_drei();
1104 hvar1->weiter=NULL;
1105 if (zeigvar->index==n)
1106 {
1107 e=callocobject();
1108 m_i_i(zeigvar->potenz*1L,e);
1109 mult(hmon->coeff,e,hmon->coeff);
1110 freeall(e);
1111 hvar1->potenz=zeigvar->potenz-1;
1112 hvar1->index=zeigvar->index;
1113 }
1114 else
1115 {
1116 hvar1->index=zeigvar->index;
1117 hvar1->potenz=zeigvar->potenz;
1118 }
1119 if (hmon->zeiger==NULL) hmon->zeiger=hvar1;
1120 else hvar2->weiter=hvar1;
1121 hvar2=hvar1;
1122 /* unfolding */
1123 }
1124 zeigvar=zeigvar->weiter;
1125 } while (zeigvar!=NULL);
1126 einfuegen_in_reihe(hmon,c);
1127 }
1128 }
1129 zeigmon=zeigmon->ref;
1130 }
1131 while (zeigmon!=NULL);
1132 }
1133 zeigpoly=zeigpoly->rechts;
1134 }
1135 }
1136 c->exist+=anzahl;
1137 }
1138
1139
1140
monomausgabe(f,m)1141 static INT monomausgabe(f, m) struct REIHE_mon* m; FILE *f;
1142 {
1143 struct REIHE_variablen *zeigvar;
1144 INT erg = OK;
1145 if (not(nullp(m->coeff)))
1146 {
1147 fprintf(f, " ");
1148 if (f == stdout) zeilenposition++; /* AK 040893 */
1149 erg += fprint(f, m->coeff);
1150 if (m->zeiger!=NULL) /* fuer Grad 0 ex. keine Monome */
1151 {
1152 zeigvar=m->zeiger;
1153 do
1154 {
1155 if (zeigvar->potenz>0L)
1156 fprintf(f, " X%" PRIINT "^%" PRIINT ,zeigvar->index,zeigvar->potenz);
1157 if (f == stdout) zeilenposition+=5L; /* AK 040893 */
1158 zeigvar=zeigvar->weiter;
1159
1160 if ((f == stdout) &&
1161 (zeilenposition > 70L)) /* AK 040893 */
1162 {
1163 zeilenposition = 0L;
1164 fprintf(f,"\n");
1165 }
1166 } while (zeigvar!=NULL);
1167 }
1168 fprintf(f," +");
1169 if (f == stdout)
1170 zeilenposition += 2L;
1171 }
1172 return erg;
1173 }
1174
1175
copyy_monom(m1,m2)1176 static int copyy_monom(m1,m2) struct REIHE_mon* m1, **m2;
1177 {
1178 struct REIHE_variablen *zvar_eins,*zvar2,*help;
1179
1180 *m2=new_zwei();
1181 (*m2)->coeff=callocobject();
1182 (*m2)->ref=NULL;
1183 (*m2)->zeiger=NULL;
1184 copy(m1->coeff,(*m2)->coeff);
1185 if (m1->zeiger!=NULL)
1186 {
1187 zvar_eins=m1->zeiger;
1188 do
1189 {
1190 help=new_drei();
1191 help->weiter=NULL;
1192 help->index=zvar_eins->index;
1193 help->potenz=zvar_eins->potenz;
1194 if ((*m2)->zeiger==NULL) (*m2)->zeiger=help;
1195 else zvar2->weiter=help;
1196 zvar2=help;
1197 zvar_eins=zvar_eins->weiter;
1198 } while (zvar_eins!=NULL);
1199 }
1200 }
1201
1202
monommult(m1,m2,m3)1203 static INT monommult(m1,m2,m3) struct REIHE_mon* m1,*m2, **m3;
1204 {
1205 int i,p,v;
1206 INT erg = OK;
1207 struct REIHE_variablen *help,*zeigvar1, *zeigvar2, *kopie;
1208 struct REIHE_mon *helpmon;
1209
1210 if (monomgrad(m1)<monomgrad(m2)) {
1211 helpmon=m1;
1212 m1=m2;
1213 m2=helpmon;
1214 }
1215 /*Tausch wegen Multiplikationsalgorithmus */
1216
1217 copyy_monom(m1,m3);
1218
1219 erg +=mult(m1->coeff,m2->coeff,(*m3)->coeff);
1220 zeigvar1=m2->zeiger;
1221
1222 if (zeigvar1!=NULL) /* also nicht nur absolutes Glied */
1223 {
1224
1225 while (zeigvar1!=NULL)
1226 {
1227 i=zeigvar1->index;
1228 p=zeigvar1->potenz;
1229 if ((*m3)->zeiger == NULL) /* AK 040893 */
1230 {
1231 zeigvar2=(*m3)->zeiger;
1232 kopie=new_drei();
1233 kopie->index=i;
1234 kopie->potenz=p;
1235 kopie->weiter=NULL;
1236 (*m3)->zeiger=kopie;
1237 (*m3)->zeiger->weiter=zeigvar2;
1238 }
1239
1240 else if (i<(*m3)->zeiger->index) /* ganz vorn als erstes */
1241 {
1242 zeigvar2=(*m3)->zeiger;
1243 kopie=new_drei();
1244 kopie->index=i;
1245 kopie->potenz=p;
1246 kopie->weiter=NULL;
1247 (*m3)->zeiger=kopie;
1248 (*m3)->zeiger->weiter=zeigvar2;
1249 }
1250 else
1251 {
1252 zeigvar2=(*m3)->zeiger;
1253 if (zeigvar2 == NULL)
1254 return error("internal error:RH9");
1255 while ( (v=variablenvergleich(zeigvar1,zeigvar2->weiter)) <=0)
1256 zeigvar2=zeigvar2->weiter;
1257
1258 if (variablenvergleich(zeigvar1,zeigvar2)==0)
1259 zeigvar2->potenz=zeigvar2->potenz+zeigvar1->potenz;
1260 else
1261 {
1262 kopie=new_drei();
1263 kopie->index=i;
1264 kopie->potenz=p;
1265 kopie->weiter=NULL;
1266 switch(v)
1267 {
1268 case 1:
1269 help=zeigvar2->weiter;
1270 zeigvar2->weiter=kopie;
1271 kopie->weiter=help;
1272 break;
1273
1274 case 2:
1275 zeigvar2->weiter=kopie;
1276 break;
1277 }
1278 }
1279 }
1280 zeigvar1=zeigvar1->weiter;
1281 }
1282 }
1283 #ifdef DEBUGRH7
1284 printf("m1:");monomausgabe(stdout,m1);printf("\n");
1285 printf("m2:");monomausgabe(stdout,m2);printf("\n");
1286 printf("m3:");monomausgabe(stdout,*m3);printf("\n");
1287 zeilenposition = 0L;
1288 #endif /* DEBUGRH7 */
1289 #undef DEBUGRH7
1290 return erg;
1291 }
1292
1293
monom_zu_symmonom(m,c)1294 static INT monom_zu_symmonom(m,c) struct REIHE_mon* m; OP c;
1295 {
1296 struct REIHE_variablen *zeigvar;
1297
1298 OP a,b,e,f;
1299 INT g;
1300 INT i;
1301 INT erg = OK;
1302
1303 e=callocobject();
1304 erg += m_iindex_iexponent_monom(0L,0L,e);
1305 if (m->zeiger!=NULL) /* fuer Grad 0 ex. keine Monome */
1306 {
1307 zeigvar=m->zeiger;
1308 do
1309 {
1310 if (zeigvar->potenz>0)
1311 {
1312 a=callocobject();
1313 erg += m_iindex_iexponent_monom(
1314 (zeigvar->index)*1L,(zeigvar->potenz)*1L,a);
1315 erg += mult_apply(a,e);
1316 erg += freeall(a);
1317 }
1318 zeigvar=zeigvar->weiter;
1319 } while (zeigvar!=NULL);
1320 }
1321 /*
1322 erg += mult(m->coeff,e,c);
1323 */
1324 erg += mult_scalar_polynom(m->coeff,e,c);
1325 erg += freeall(e);
1326 return erg;
1327 }
1328
1329
t_REIHE_POLYNOM(a,b)1330 INT t_REIHE_POLYNOM(a,b) OP a,b;
1331 /* AK 150393 */
1332 {
1333 INT erg = OK;
1334
1335 if (check_equal_2(a,b,t_REIHE_POLYNOM,&erg) == EQUAL)
1336 goto tre;
1337
1338 erg += reihe_zu_sympolynom(S_O_S(a).ob_reihe,b);
1339 tre:
1340 if (erg != OK)
1341 EDC("t_REIHE_POLYNOM");
1342 return erg;
1343 }
1344
is_scalar_reihe(c)1345 INT is_scalar_reihe(c) OP c;
1346 {
1347 return co_REIHE(c,is_scalar_polynom);
1348 }
1349
nullp_reihe(a)1350 INT nullp_reihe(a) OP a;
1351 {
1352 return co_REIHE(a,nullp);
1353 }
einsp_reihe(a)1354 INT einsp_reihe(a) OP a;
1355 {
1356 return co_REIHE(a,einsp);
1357 }
1358
co_REIHE(a,f)1359 static INT co_REIHE(a,f) OP a; INT (*f)();
1360 /* AK 280793 */
1361 {
1362 OP b;
1363 INT erg;
1364 b = callocobject();
1365 t_REIHE_POLYNOM(a,b);
1366 erg = (*f)(b);
1367 freeall(b);
1368 return erg;
1369 }
1370
1371
poly_zu_sympolynom(a,c)1372 static INT poly_zu_sympolynom(a,c) struct REIHE_poly *a; OP c;
1373 /* AK 040893 */
1374 {
1375 struct REIHE_poly *zeigpoly;
1376 struct REIHE_mon *zeigmon;
1377 INT erg = OK;
1378 OP h;
1379
1380 init(POLYNOM,c);
1381 h=callocobject();
1382 zeigpoly=a;
1383 if (zeigpoly->unten!=NULL)
1384 {
1385 zeigmon=zeigpoly->unten;
1386 do
1387 {
1388 if (not(nullp(zeigmon->coeff)))
1389 {
1390 erg += monom_zu_symmonom(zeigmon,h);
1391 erg += add_apply(h,c);
1392 }
1393 zeigmon=zeigmon->ref;
1394 }
1395 while (zeigmon!=NULL);
1396 }
1397 erg += freeall(h); /* AK 131093 */
1398 return erg;
1399 }
1400
reihe_zu_sympolynom(a,c)1401 static INT reihe_zu_sympolynom(a,c) REIHE_zeiger a; OP c;
1402 {
1403 INT erg = OK;
1404 struct REIHE_poly *zeigpoly;
1405 struct REIHE_mon *zeigmon;
1406 struct REIHE_variablen *zeigvar;
1407 OP h;
1408
1409 if ((OP)a == c)
1410 return ERROR;
1411 h=callocobject();
1412 erg += init(POLYNOM,c);
1413 if (a!=NULL)
1414 {
1415 zeigpoly=a->infozeig;
1416 do
1417 {
1418 erg += poly_zu_sympolynom(zeigpoly,h);
1419 erg += add_apply(h,c);
1420 zeigpoly=zeigpoly->rechts;
1421 }
1422 while (zeigpoly!=NULL);
1423 }
1424 erg += freeall(h);
1425 return erg;
1426 }
1427
add_apply_reihe(a,b)1428 INT add_apply_reihe(a,b) OP a,b;
1429 /* AK 020893 */
1430 {
1431 OP c;
1432 INT erg = OK;
1433
1434 if (S_O_K(a) != REIHE)
1435 return WTO("add_apply_reihe",a);
1436
1437 c = callocobject();
1438 *c = *b;
1439 C_O_K(b,EMPTY);
1440 erg += add(c,a,b);
1441 erg += freeall(c);
1442 aar_ende:
1443 if (erg != OK)
1444 EDC("add_apply_reihe");
1445 return erg;
1446 }
1447
1448
freeself_reihe(a)1449 INT freeself_reihe(a) OP a;
1450 /* AK 100393 */
1451 {
1452 INT erg = OK;
1453 CTO(REIHE,"freeself_reihe(1)",a);
1454 del_reihe(& (S_O_S(a).ob_reihe) );
1455 C_O_K(a,EMPTY);
1456 ENDR("freeself_reihe");
1457 }
1458
del_reihe(a)1459 static int del_reihe(a) REIHE_zeiger *a;
1460 /* AK 110393 */
1461 {
1462 if (*a != NULL)
1463 {
1464 del_reihe(& (*a)->x);
1465 del_reihe(& (*a)->y);
1466 del_reihe(& (*a)->p);
1467 del_poly( & (*a)->infozeig);
1468 free_null((char*)*a);
1469 *a = NULL;
1470 }
1471 }
1472
copy_reihe(a,b)1473 INT copy_reihe(a,b) OP a,b;
1474 /* AK 100393 */
1475 {
1476 copy_rh( (S_O_S(a)).ob_reihe,& S_O_S(b).ob_reihe);
1477 C_O_K(b,REIHE);
1478 return OK;
1479 }
1480
1481
JH_copy_reihe(a,c)1482 static void JH_copy_reihe(a,c) REIHE_zeiger a; REIHE_zeiger* c;
1483 {
1484 JH_copy_reihe_co(a,c,1);
1485 }
1486
AK_copy_reihe(a,c)1487 static void AK_copy_reihe(a,c) REIHE_zeiger a; REIHE_zeiger* c;
1488 {
1489 JH_copy_reihe_co(a,c,0);
1490 }
1491
JH_copy_reihe_co(a,c,i)1492 static void JH_copy_reihe_co(a,c,i) REIHE_zeiger a; REIHE_zeiger* c; int i;
1493 /* JH 0293 */
1494 {
1495 struct REIHE_mon *zeigmon,*hmon;
1496 struct REIHE_poly *zeigpoly;
1497
1498 del_reihe(c);
1499 initial_reihe(c);
1500 (*c)->exist=a->exist;
1501
1502 if (i==1)
1503 (*c)->x=a->x;
1504 if (i==0)
1505 AK_copy_reihe(a->x, & ((*c)->x) );
1506 if (i==1)
1507 (*c)->y=a->y;
1508 if (i==0)
1509 AK_copy_reihe(a->y, & ((*c)->y) );
1510
1511 (*c)->z=a->z;
1512 (*c)->ope=a->ope;
1513 (*c)->reihenart=a->reihenart;
1514 if (i==1)
1515 (*c)->p=a->p;
1516 if (i==0)
1517 AK_copy_reihe(a->p, & ((*c)->p) );
1518
1519 (*c)->eingabefkt=a->eingabefkt;
1520
1521 if(i==1) {
1522 if (a!=NULL) /* dann ist auch a->infozeig!=NULL wegen initial */
1523 {
1524 zeigpoly=a->infozeig;
1525 do
1526 {
1527 if (zeigpoly->unten!=NULL)
1528 {
1529 zeigmon=zeigpoly->unten;
1530 do
1531 {
1532 copyy_monom(zeigmon,&hmon);
1533 einfuegen_in_reihe(hmon,*c);
1534 zeigmon=zeigmon->ref;
1535 } while (zeigmon!=NULL);
1536 }
1537 zeigpoly=zeigpoly->rechts;
1538 } while (zeigpoly!=NULL);
1539 }
1540 }
1541 if (i==0)
1542 {
1543 if (a == NULL)
1544 if(a->infozeig == NULL)
1545 error("JH_copy_reihe_co:(1)");
1546 copy_poly(a->infozeig, & (*c)->infozeig);
1547 }
1548 }
1549
pot_reihe(a,n,c,anzahl)1550 static int pot_reihe(a,n,c,anzahl) REIHE_zeiger a,c; INT n, anzahl;
1551 {
1552 struct reihe *help;
1553 struct REIHE_poly *zeigpoly;
1554 struct REIHE_mon *hmon,*zeigmon;
1555 int zaehler;
1556
1557 if (c->ope=='#') c->ope='p';
1558 c->reihenart=0L;
1559 if ((c->x==NULL) && (c->z==0)) {
1560 c->x=a;
1561 c->z=n;
1562 } /* fuer 1.Aufruf */
1563 else if ((c->x!=a) || (c->z!=n))
1564 {
1565 printf("Falsche Operanden beim Potenzieren!\n");
1566 exit(3);
1567 }
1568
1569 if (a->exist<c->exist+anzahl) ergaenze_reihe(&a,c->exist+anzahl-a->exist);
1570
1571 help=a; /* help zeigt jetzt auch auf a */
1572
1573 zaehler=1;
1574
1575 while ((help->p!=NULL) && (zaehler!=n))
1576 {
1577 help=help->p;
1578 zaehler=zaehler+1;
1579 }
1580 if (zaehler==n)
1581 {
1582 if (help->exist<c->exist+anzahl)
1583 ergaenze_reihe(&help,c->exist+anzahl-help->exist);
1584 }
1585 else
1586 {
1587 do
1588 {
1589 initial_reihe(&(help->p));
1590 zaehler=zaehler+1;
1591 help->p->reihenart=0L;
1592 help->p->ope='m';
1593 help->p->x=a;
1594 help->p->y=help;
1595 JH_mult_reihe(a,help,help->p,c->exist+anzahl);
1596 help=help->p;
1597 } while (zaehler<n);
1598 }
1599 /* anhaengen an bestehende Reihe */
1600 if (help!=NULL) /* dann ist auch a->infozeig!=NULL wegen initial */
1601 {
1602 zeigpoly=help->infozeig;
1603 if (c->exist!=0)
1604 while ((zeigpoly->grad<=c->exist) && (zeigpoly->rechts!=NULL))
1605 zeigpoly=zeigpoly->rechts;
1606
1607 while ((zeigpoly!=NULL) && (zeigpoly->grad<=c->exist+anzahl))
1608 {
1609 if (zeigpoly->unten!=NULL)
1610 {
1611 zeigmon=zeigpoly->unten;
1612 do
1613 {
1614 copyy_monom(zeigmon,&hmon);
1615 einfuegen_in_reihe(hmon,c);
1616 zeigmon=zeigmon->ref;
1617 } while (zeigmon!=NULL);
1618 }
1619 zeigpoly=zeigpoly->rechts;
1620 }
1621 }
1622 c->exist+=anzahl;
1623 }
1624
1625
mult_reihe(a,b,c)1626 INT mult_reihe(a,b,c) OP a,b,c;
1627 /* AK 100393 */
1628 {
1629 INT erg = OK;
1630 switch(S_O_K(b))
1631 {
1632 case BRUCH:
1633 case INTEGER:
1634 case LONGINT:
1635 {
1636 OP d;
1637 d = callocobject();
1638 erg += m_scalar_reihe(b,d);
1639 erg += mult_reihe(a,d,c);
1640 erg += freeall(d);
1641 break;
1642 }
1643 case REIHE:
1644 {
1645 OBJECTSELF as,bs,cs;
1646 OP d,e,f,g;
1647 d = callocobject();
1648 e = callocobject();
1649 g = callocobject();
1650 f = callocobject();
1651 erg += max_degree_reihe(a,d);
1652 erg += max_degree_reihe(b,e);
1653 if (lt(e,d)) copy(d,e);
1654 erg += copy(a,f);
1655 erg += copy(b,g);
1656
1657 erg += init(REIHE,c);
1658 as = S_O_S(f);
1659 bs = S_O_S(g);
1660 cs = S_O_S(c);
1661 erg += JH_mult_reihe(as.ob_reihe,bs.ob_reihe,cs.ob_reihe,S_I_I(e));
1662 erg += freeall(d);
1663 erg += freeall(e);
1664 C_O_K(f,EMPTY);
1665 C_O_K(g,EMPTY);
1666 erg += freeall(f);
1667 erg += freeall(g);
1668 break;
1669 }
1670 default:
1671 return WTT("mult_reihe",a,b);
1672 }
1673 if (erg != OK)
1674 EDC("mult_reihe");
1675 return erg;
1676 }
1677
JH_mult_reihe(a,b,c,anzahl)1678 static INT JH_mult_reihe(a,b,c,anzahl) REIHE_zeiger a,b,c; INT anzahl;
1679 {
1680 struct REIHE_poly *zeigpoly1,*zeigpoly2;
1681 struct REIHE_mon *zeigmon1, *zeigmon2, *hmon;
1682
1683 if (c->ope=='#') c->ope='m';
1684 c->reihenart=0L;
1685 if ((c->x==NULL) && (c->y==NULL))
1686 {
1687 c->x=a;
1688 c->y=b;
1689 }
1690 else if (((c->x!=a) || (c->y!=b)) && ((c->x!=b) || (c->y!=a)))
1691 {
1692 return error("RH-internal error");
1693 }
1694
1695 if (a->exist<c->exist+anzahl) ergaenze_reihe(&a,c->exist+anzahl-a->exist);
1696 if (b->exist<c->exist+anzahl) ergaenze_reihe(&b,c->exist+anzahl-b->exist);
1697
1698 if (a!=NULL) /* dann ist auch a->infozeig!=NULL wegen initial */
1699 {
1700 zeigpoly1=a->infozeig;
1701 while ((zeigpoly1!=NULL) && (zeigpoly1->grad<=c->exist+anzahl))
1702 {
1703 if (zeigpoly1->unten!=NULL)
1704 {
1705 zeigmon1=zeigpoly1->unten;
1706 do
1707 {
1708 if (b!=NULL)
1709 /* dann ist auch b->infozeig!=NULL wegen initial */
1710 {
1711 zeigpoly2=b->infozeig;
1712 if (c->exist!=0)
1713 while ((zeigpoly2->grad<=c->exist-zeigpoly1->grad) &&
1714 (zeigpoly2->rechts!=NULL))
1715 zeigpoly2=zeigpoly2->rechts;
1716
1717 if (((zeigpoly2->grad+zeigpoly1->grad>c->exist) &&
1718 (zeigpoly2->grad+zeigpoly1->grad<=c->exist+anzahl))
1719 || (c->exist==0))
1720 /* richtiger Grad ist erreicht */
1721 do
1722 {
1723 if (zeigpoly2->unten!=NULL)
1724 {
1725 zeigmon2=zeigpoly2->unten;
1726 do
1727 {
1728 monommult(zeigmon1,zeigmon2,&hmon);
1729 einfuegen_in_reihe(hmon,c);
1730 zeigmon2=zeigmon2->ref;
1731 } while (zeigmon2!=NULL);
1732 }
1733 zeigpoly2=zeigpoly2->rechts;
1734 } /* do */ while ((zeigpoly2!=NULL) &&
1735 (zeigpoly2->grad<=c->exist+anzahl-zeigpoly1->grad));
1736 /* hier endet das if vor dem do */
1737 }
1738 zeigmon1=zeigmon1->ref;
1739 } while (zeigmon1!=NULL);
1740 }
1741 zeigpoly1=zeigpoly1->rechts;
1742 }
1743 }
1744 c->exist+=anzahl;
1745 return OK;
1746 }
1747
1748
trans_reihe_in_monom(a,m,b,anzahl)1749 static int trans_reihe_in_monom(a,m,b,anzahl)
1750 REIHE_zeiger a,*b; struct REIHE_mon *m; INT anzahl;
1751 {
1752 REIHE_zeiger help_eins,help_zwei,help_drei;
1753 struct REIHE_variablen *zeigvar;
1754
1755 del_reihe(b);
1756
1757 initial_reihe(&help_eins);
1758 help_eins->exist=1;
1759 help_eins->reihenart=1L;
1760 help_eins->infozeig->unten=new_zwei();
1761 help_eins->infozeig->unten->ref=NULL;
1762 help_eins->infozeig->unten->zeiger=NULL;
1763 help_eins->infozeig->unten->coeff=callocobject();
1764 m_i_i(1L,help_eins->infozeig->unten->coeff);
1765
1766 if (m->zeiger!=NULL) /* wegen abs. Glied */
1767 {
1768 zeigvar=m->zeiger;
1769 do
1770 {
1771 initial_reihe(&help_zwei);
1772 pot_reihe(a,zeigvar->potenz,help_zwei,anzahl);
1773 help_zwei->reihenart=1L;
1774 initial_reihe(&help_drei);
1775 transform_reihe(help_zwei,zeigvar->index,help_drei,anzahl);
1776 help_drei->reihenart=1L;
1777 del_reihe(&help_zwei);
1778 initial_reihe(&help_zwei);
1779 JH_mult_reihe(help_eins,help_drei,help_zwei,anzahl);
1780 help_zwei->reihenart=1L;
1781 del_reihe(&help_eins);
1782 del_reihe(&help_drei);
1783 help_eins=help_zwei;
1784 help_zwei=NULL;
1785
1786 zeigvar=zeigvar->weiter;
1787 } while (zeigvar!=NULL);
1788 }
1789
1790 initial_reihe(&help_zwei); /* Realisation der Skalarmult. mit coeff */
1791 help_zwei->exist=1;
1792 help_zwei->reihenart=1L;
1793 help_zwei->infozeig->unten=new_zwei();
1794 help_zwei->infozeig->unten->ref=NULL;
1795 help_zwei->infozeig->unten->zeiger=NULL;
1796 help_zwei->infozeig->unten->coeff=callocobject();
1797 copy(m->coeff,help_zwei->infozeig->unten->coeff);
1798
1799 initial_reihe(&help_drei);
1800 JH_mult_reihe(help_eins,help_zwei,help_drei,anzahl);
1801 help_drei->reihenart=1L;
1802 del_reihe(&help_eins);
1803 del_reihe(&help_zwei);
1804
1805 *b=help_drei;
1806 }
1807
1808
subst_reihe(a,b,c,anzahl)1809 static int subst_reihe(a,b,c,anzahl) REIHE_zeiger a,b,* c; INT anzahl ;
1810 {
1811 struct REIHE_poly *zeigpoly;
1812 REIHE_zeiger help_eins,help_zwei,help_drei,help4;
1813 struct REIHE_mon *zeigmon;
1814 int m;
1815
1816 /* a Basisreihe b einzusetzende Reihe c Ergebinsreihe */
1817 if (((*c)->x==NULL) && ((*c)->y==NULL)) {
1818 (*c)->x=a;
1819 (*c)->y=b;
1820 }
1821 else if ((((*c)->x!=a) || ((*c)->y!=b)) && (((*c)->x!=b) || ((*c)->y!=a)))
1822 {
1823 printf("Falsche Operanden bei der Substitution!");
1824 exit(3);
1825 }
1826
1827 normalisiere_reihe(b);
1828 del_reihe(c);
1829 if (a->exist<anzahl) ergaenze_reihe(&a,anzahl-a->exist);
1830 if (b->exist<anzahl) ergaenze_reihe(&b,anzahl-b->exist);
1831
1832 initial_reihe(&help4); /* help4 enthaelt immer das ergebnis */
1833 help4->reihenart=1L; /* wird somit zum Skalar = 0 */
1834
1835 if (a!=NULL)
1836 {
1837 zeigpoly=a->infozeig;
1838 do
1839 {
1840 if (zeigpoly->unten!=NULL)
1841 {
1842 zeigmon=zeigpoly->unten;
1843 do
1844 {
1845 initial_reihe(&help_eins);
1846 trans_reihe_in_monom(b,zeigmon,&help_eins,anzahl);
1847 help_eins->reihenart=1L;
1848 initial_reihe(&help_zwei);
1849 JH_add_reihe(help_eins,help4,help_zwei,anzahl);
1850 help_zwei->reihenart=1L;
1851 del_reihe(&help_eins);
1852 del_reihe(&help4);
1853 help4=help_zwei;
1854 help_zwei=NULL;
1855
1856 zeigmon=zeigmon->ref;
1857 } while (zeigmon!=NULL);
1858 }
1859 zeigpoly=zeigpoly->rechts;
1860 }
1861 while (zeigpoly!=NULL);
1862 }
1863
1864 /* initial_reihe(c); Zeiger nur umhaengen */
1865 *c=help4;
1866 (*c)->x=a;
1867 (*c)->y=b; /* und noch die alten infos uebertragen */
1868 (*c)->reihenart=0L;
1869 (*c)->exist=anzahl;
1870 (*c)->ope='s';
1871 }
1872
1873
add_reihe(a,b,c)1874 INT add_reihe(a,b,c) OP a,b,c;
1875 /* AK 100393 */
1876 {
1877 INT erg = OK;
1878 switch(S_O_K(b))
1879 {
1880 case REIHE:
1881 {
1882 OBJECTSELF as,bs,cs;
1883 OP d,e,f,g;
1884
1885 d = callocobject();
1886 e = callocobject();
1887 f = callocobject();
1888 g = callocobject();
1889 copy(a,f);
1890 copy(b,g);
1891 erg += max_degree_reihe(f,d);
1892 erg += max_degree_reihe(g,e);
1893 if (lt(e,d))
1894 copy(d,e);
1895
1896 erg += init(REIHE,c);
1897 as = S_O_S(f);
1898 bs = S_O_S(g);
1899 cs = S_O_S(c);
1900 erg += JH_add_reihe(as.ob_reihe,bs.ob_reihe,cs.ob_reihe,S_I_I(e));
1901 erg += freeall(d);
1902 erg += freeall(e);
1903 C_O_K(f,EMPTY);
1904 C_O_K(g,EMPTY);
1905 erg += freeall(f);
1906 erg += freeall(g);
1907 break;
1908 }
1909 case INTEGER:
1910 case BRUCH:
1911 case LONGINT: /* AK 020893 */
1912 {
1913 OP d;
1914 d = callocobject();
1915 erg += m_scalar_reihe(b,d);
1916 erg += add_reihe(a,d,c);
1917 erg += freeall(d);
1918 break;
1919 }
1920 default:
1921 return WTT("add_reihe",a,b);
1922 }
1923 ENDR("add_reihe");
1924 }
1925
JH_add_reihe(a,b,c,anzahl)1926 static INT JH_add_reihe(a,b,c,anzahl) REIHE_zeiger a,b,c; INT anzahl;
1927 /* JH 0293 */
1928 {
1929 struct REIHE_mon *zeigmon,*hmon;
1930 struct REIHE_poly *zeigpoly;
1931
1932 if (c->ope=='#') c->ope='a';
1933 c->reihenart=0L;
1934 if ((c->x==NULL) && (c->y==NULL))
1935 {
1936 c->x=a;
1937 c->y=b;
1938 }
1939 else if (((c->x!=a) || (c->y!=b)) && ((c->x!=b) || (c->y!=a)))
1940 {
1941 printf("Falsche Operanden bei der Addition!");
1942 exit(3);
1943 }
1944
1945 if (a->exist<c->exist+anzahl) ergaenze_reihe(&a,c->exist+anzahl-a->exist);
1946 if (b->exist<c->exist+anzahl) ergaenze_reihe(&b,c->exist+anzahl-b->exist);
1947 if (a!=NULL) /* dann ist auch a->infozeig!=NULL wegen initial */
1948 {
1949 zeigpoly=a->infozeig;
1950 if (c->exist!=0)
1951 while ((zeigpoly->grad<=c->exist) && (zeigpoly->rechts!=NULL))
1952 zeigpoly=zeigpoly->rechts;
1953
1954 while ((zeigpoly!=NULL) && (zeigpoly->grad<=c->exist+anzahl))
1955 {
1956 if (zeigpoly->unten!=NULL)
1957 {
1958 zeigmon=zeigpoly->unten;
1959 do
1960 {
1961 copyy_monom(zeigmon,&hmon);
1962 einfuegen_in_reihe(hmon,c);
1963 zeigmon=zeigmon->ref;
1964 } while (zeigmon!=NULL);
1965 }
1966 zeigpoly=zeigpoly->rechts;
1967 }
1968 }
1969
1970 if (b!=NULL)
1971 {
1972 zeigpoly=b->infozeig;
1973 if (c->exist!=0)
1974 while ((zeigpoly->grad<=c->exist) && (zeigpoly->rechts!=NULL))
1975 zeigpoly=zeigpoly->rechts;
1976
1977 while ((zeigpoly!=NULL) && (zeigpoly->grad<=c->exist+anzahl))
1978 {
1979 if (zeigpoly->unten!=NULL)
1980 {
1981 zeigmon=zeigpoly->unten;
1982 do
1983 {
1984 copyy_monom(zeigmon,&hmon);
1985 einfuegen_in_reihe(hmon,c);
1986 zeigmon=zeigmon->ref;
1987 } while (zeigmon!=NULL);
1988 }
1989 zeigpoly=zeigpoly->rechts;
1990 }
1991 }
1992 c->exist+=anzahl;
1993 return OK;
1994 }
1995
transform_reihe(a,n,c,anzahl)1996 static int transform_reihe(a,n,c,anzahl) REIHE_zeiger a,c; INT n,anzahl;
1997 {
1998 struct REIHE_poly *zeigpoly;
1999 struct REIHE_mon* zeigmon, *hmon;
2000 struct REIHE_variablen *zeigvar;
2001
2002 if (c->ope=='#') c->ope='t';
2003 c->reihenart=0L;
2004 if ((c->x==NULL) && (c->z==0))
2005 {
2006 c->x=a;
2007 c->z=n;
2008 }
2009 else if ((c->x!=a) || (c->z!=n))
2010 {
2011 return error("internal error:RH8");
2012 }
2013
2014 if (a->exist<c->exist+anzahl) ergaenze_reihe(&a,c->exist+anzahl-a->exist);
2015 if (a!=NULL) /* dann ist auch a->infozeig!=NULL wegen initial */
2016 {
2017 zeigpoly=a->infozeig;
2018 if (c->exist!=0)
2019 while ((zeigpoly->grad<=c->exist)
2020 && (zeigpoly->rechts!=NULL))
2021 zeigpoly=zeigpoly->rechts;
2022
2023 while ((zeigpoly!=NULL) && (zeigpoly->grad<=c->exist+anzahl))
2024 {
2025 if (zeigpoly->unten!=NULL)
2026 {
2027 zeigmon=zeigpoly->unten;
2028 do
2029 {
2030 copyy_monom(zeigmon,&hmon);
2031 if (hmon->zeiger!=NULL)
2032 {
2033 zeigvar=hmon->zeiger;
2034 do
2035 {
2036 zeigvar->index*=n;
2037 zeigvar=zeigvar->weiter;
2038 } while (zeigvar!=NULL);
2039 }
2040 einfuegen_in_reihe(hmon,c);
2041 zeigmon=zeigmon->ref;
2042 } while (zeigmon!=NULL);
2043 }
2044 zeigpoly=zeigpoly->rechts;
2045 }
2046 }
2047 c->exist+=anzahl;
2048 }
2049
m_perm_reihe(a)2050 INT m_perm_reihe(a) OP a;
2051 /* AK 100393 */
2052 {
2053 INT erg = OK;
2054 erg += freeself(a);
2055 erg += make_reihe(& (S_O_S(a)).ob_reihe,Perm_eingabe);
2056 erg += ergaenze_reihe(& (S_O_S(a)).ob_reihe,5L);
2057 C_O_K(a,REIHE);
2058 ENDR("m_perm_reihe");
2059 }
2060
m_cosinus_reihe(a)2061 INT m_cosinus_reihe(a) OP a;
2062 /* AK 100393 */
2063 {
2064 INT erg = OK;
2065 erg += freeself(a);
2066 erg += make_reihe(& (S_O_S(a)).ob_reihe,Cosinus_eingabe);
2067 erg += ergaenze_reihe(& (S_O_S(a)).ob_reihe,5L);
2068 C_O_K(a,REIHE);
2069 ENDR("m_cosinus_reihe");
2070 }
2071
random_reihe(a)2072 INT random_reihe(a) OP a;
2073 /* AK 030893 */
2074 {
2075 INT erg = OK;
2076 if (not EMPTYP(a))
2077 erg += freeself(a);
2078 erg += make_reihe(& (S_O_S(a)).ob_reihe,Random_eingabe);
2079 erg += ergaenze_reihe(& (S_O_S(a)).ob_reihe,5L);
2080 C_O_K(a,REIHE);
2081 ENDR("random_reihe");
2082 }
2083
m_eins_reihe(a)2084 INT m_eins_reihe(a) OP a;
2085 /* AK 100393 */
2086 {
2087 if (not EMPTYP(a))
2088 freeself(a);
2089 make_reihe(& (S_O_S(a)).ob_reihe,Eins_eingabe);
2090 ergaenze_reihe(& (S_O_S(a)).ob_reihe,5L);
2091 C_O_K(a,REIHE);
2092 return OK;
2093 }
2094
m_sinus_reihe(a)2095 INT m_sinus_reihe(a) OP a;
2096 /* AK 100393 */
2097 {
2098 INT erg = OK;
2099 if (not EMPTYP(a))
2100 erg += freeself(a);
2101 erg += make_reihe(& (S_O_S(a)).ob_reihe,Sinus_eingabe);
2102 erg += ergaenze_reihe(& (S_O_S(a)).ob_reihe,5L);
2103 C_O_K(a,REIHE);
2104 ENDR("m_sinus_reihe");
2105 }
2106
2107
jh_ausgabe_vorbereiten(f,a,r)2108 void jh_ausgabe_vorbereiten(f, a, r) REIHE_zeiger* a; FILE *f;
2109 REIHE_zeiger r[];
2110 /* JH 0293 */
2111 {
2112 int art,x,y,z;
2113 char operat,was;
2114
2115 if (*a==NULL)
2116 {
2117 printf("Es existiert noch keine Reihe.\n");
2118 printf("Permutation.........1\n");
2119 printf("EMenge..............2\n");
2120 printf("Exponentialreihe....3\n");
2121 printf("Skalar..............4\n");
2122 printf("Sinus...............5\n");
2123 printf("Cosinus.............6\n");
2124 printf("Verknuepfungen......0\n");
2125 printf("Uebergehen.........-1\n");
2126 printf("\nAuswahl:");
2127 do
2128 scanf("%i",&art);
2129 while ((art<-2) || (art>6));
2130
2131 if (art!=-1)
2132 {
2133 if (art>0)
2134 {
2135 switch(art)
2136 {
2137 case 1:
2138 make_reihe(a,Perm_eingabe);
2139 break;
2140 case 2:
2141 make_reihe(a,E_eingabe);
2142 break;
2143 case 3:
2144 make_reihe(a,Exp_eingabe);
2145 break;
2146 case 4:
2147 make_skalar_reihe(a);
2148 break;
2149 case 5:
2150 make_reihe(a,Sinus_eingabe);
2151 break;
2152 case 6:
2153 make_reihe(a,Cosinus_eingabe);
2154 break;
2155
2156
2157 }
2158 ergaenze_reihe(a,zuwachs);
2159 }
2160 else /* Verknuepfungen */
2161 {
2162 initial_reihe(a);
2163 printf("\nAddition.............a\n");
2164 printf("Multiplikation.......m\n");
2165 printf("Potenzieren..........p\n");
2166 printf("Ableitung............l\n");
2167 printf("Transformieren.......t\n");
2168 printf("Substitution.........s\n");
2169 printf("\nOperation:");
2170 do
2171 operat=getchar();
2172 while(operat!='a' && operat!='m' &&
2173 operat!='s' && operat!='p' &&
2174 operat!='t' && operat!='l');
2175 switch(operat)
2176 {
2177 case 'a':
2178 printf("\n1.Summand:");
2179 scanf("%i",&x);
2180 printf("\n2.Summand:");
2181 scanf("%i",&y);
2182 JH_add_reihe(r[x],r[y],*a,zuwachs);
2183 break;
2184
2185 case 'm':
2186 printf("\n1.Faktor:");
2187 scanf("%i",&x);
2188 printf("\n2.Faktor:");
2189 scanf("%i",&y);
2190 JH_mult_reihe(r[x],r[y],*a,zuwachs);
2191 break;
2192
2193 case 'p':
2194 printf("\nBasisreihe :");
2195 scanf("%i",&x);
2196 printf("\nPotenz :");
2197 scanf("%i",&z);
2198 pot_reihe(r[x],z,*a,zuwachs);
2199 break;
2200
2201 case 'l':
2202 printf("\nBasisreihe :");
2203 scanf("%i",&x);
2204 printf("\nAbleitung nach Variable:");
2205 scanf("%i",&z);
2206 ableitung_reihe(r[x],z,*a,zuwachs);
2207 break;
2208
2209 case 't':
2210 printf("\nReihe :");
2211 scanf("%i",&x);
2212 printf("\nTransformation:");
2213 scanf("%i",&z);
2214 transform_reihe(r[x],z,*a,zuwachs);
2215 break;
2216
2217 case 's':
2218 printf("\n1.Reihe, in die eingesetzt wird:");
2219 scanf("%i",&x);
2220 printf("\n2.Reihe, die eingesetzt wird :");
2221 scanf("%i",&y);
2222 subst_reihe(r[x],r[y],a,zuwachs);
2223 break;
2224 } /* switch */
2225 } /* else */
2226 } /* if art.. */
2227 ausgabe(f, *a);
2228 } /* if */
2229 else /* Reihe ist schon definiert */
2230 {
2231 if ((*a)->ope!='#')
2232 printf(" Operator:%c, \n",(*a)->ope); /* ursprung angeben */
2233 else printf("\n");
2234
2235 printf("Ausgabe + Zuwachs...a ");
2236 printf("Loeschen............l ");
2237 printf("Ausgabe.............A\n");
2238 printf("Normalisieren.......n ");
2239 printf("Symmetrica-Polynom..s ");
2240 printf("Cardinalitaet.......c\n");
2241 printf("Typ-Cardinalitaet...t\n");
2242
2243 printf("\nAuswahl:");
2244 do
2245 was=getchar();
2246 while(was!='a' && was!='l' &&
2247 was!='s' && was!='A' &&
2248 was!='c' && was!='t' && was!='n');
2249 if (was=='a') {
2250 ergaenze_reihe(a,zuwachs);
2251 ausgabe(f, *a);
2252 }
2253 if (was=='l') del_reihe(a);
2254 if (was=='c') card_reihe(*a);
2255 if (was=='t') card_typ_reihe(*a);
2256 if (was=='n') normalisiere_reihe(*a);
2257 if (was=='A') ausgabe(f, *a);
2258 if (was=='s'){
2259 OP symd;
2260 symd = callocobject();
2261 reihe_zu_sympolynom(*a,symd);
2262 fprintln(f, symd);
2263 freeall(symd);
2264 }
2265 }
2266 }
2267
debugprint_reihe(a)2268 INT debugprint_reihe(a) OP a;
2269 {
2270 debugprint_rh(S_O_S(a).ob_reihe);
2271 return OK;
2272 }
2273
debugprint_rh(a)2274 static int debugprint_rh(a) REIHE_zeiger a;
2275 {
2276 INT i;
2277 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2278 fprintf(stderr,"struct reihe:\n");
2279 if (a==NULL)
2280 {
2281 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2282 return fprintf(stderr,"struct reihe==NULL\n");
2283 }
2284 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2285 fprintf(stderr, "exist = %" PRIINT "\n" ,a->exist);
2286 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2287 fprintf(stderr, "reihenart = %" PRIINT "\n" ,a->reihenart);
2288 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2289 fprintf(stderr, "z = %" PRIINT "\n" ,a->z);
2290 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2291 fprintf(stderr,"x = \n");
2292 doffset += 2L;
2293 debugprint_rh(a->x);
2294 doffset -= 2L;
2295 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2296 fprintf(stderr,"y = \n");
2297 doffset += 2L;
2298 debugprint_rh(a->y);
2299 doffset -= 2L;
2300 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2301 fprintf(stderr,"p = \n");
2302 doffset += 2L;
2303 debugprint_rh(a->p);
2304 doffset -= 2L;
2305 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2306 fprintf(stderr,"ope = %c\n",a->ope);
2307 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2308 fprintf(stderr,"infozeig = \n");
2309 doffset += 2L;
2310 debugprint_rh_poly(a->infozeig);
2311 doffset -= 2L;
2312 }
2313
debugprint_rh_poly(a)2314 static int debugprint_rh_poly(a) struct REIHE_poly *a;
2315 {
2316 INT i;
2317 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2318 fprintf(stderr,"struct reihe_poly:\n");
2319 if (a==NULL)
2320 {
2321 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2322 return fprintf(stderr,"struct reihe_poly==NULL\n");
2323 }
2324 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2325 fprintf(stderr, "grad = %" PRIINT "\n" ,a->grad);
2326 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2327 fprintf(stderr,"unten = \n");
2328 doffset += 2L;
2329 debugprint_rh_mon(a->unten);
2330 doffset -= 2L;
2331 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2332 fprintf(stderr,"rechts = \n");
2333 doffset += 2L;
2334 debugprint_rh_poly(a->rechts);
2335 doffset -= 2L;
2336 }
debugprint_rh_mon(a)2337 static int debugprint_rh_mon(a) struct REIHE_mon *a;
2338 {
2339 INT i;
2340 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2341 fprintf(stderr,"struct reihe_mon:\n");
2342 if (a==NULL)
2343 {
2344 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2345 return fprintf(stderr,"struct reihe_mon==NULL\n");
2346 }
2347 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2348 fprintf(stderr,"coeff = \n");
2349 doffset += 2L;
2350 debugprint(a->coeff);
2351 doffset -= 2L;
2352 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2353 fprintf(stderr,"zeiger = \n");
2354 doffset += 2L;
2355 debugprint_rh_var(a->zeiger);
2356 doffset -= 2L;
2357 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2358 fprintf(stderr,"ref = \n");
2359 doffset += 2L;
2360 debugprint_rh_mon(a->ref);
2361 doffset -= 2L;
2362 }
debugprint_rh_var(a)2363 static int debugprint_rh_var(a) struct REIHE_variablen *a;
2364 {
2365 INT i;
2366 extern INT doffset;
2367
2368 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2369 fprintf(stderr,"struct reihe_var:\n");
2370 if (a==NULL)
2371 {
2372 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2373 return fprintf(stderr,"struct reihe_var==NULL\n");
2374 }
2375 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2376 fprintf(stderr, "index = %" PRIINT "\n" ,a->index);
2377 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2378 fprintf(stderr, "potenz = %" PRIINT "\n" ,a->potenz);
2379 for (i=0L;i<doffset;i++) fputc(' ',stderr);
2380 fprintf(stderr,"weiter = \n");
2381 doffset += 2L;
2382 debugprint_rh_var(a->weiter);
2383 doffset -= 2L;
2384 }
2385
addinvers_reihe(a,b)2386 INT addinvers_reihe(a,b) OP a,b;
2387 /* AK 020893 */
2388 {
2389 OP c;
2390 INT erg = OK;
2391 c = callocobject();
2392 erg += m_scalar_reihe(cons_negeins,c);
2393 erg += mult(a,c,b);
2394 erg += freeall(c);
2395 if (erg != OK)
2396 EDC("addinvers_reihe");
2397 return erg;
2398 }
2399
2400
mult_apply_reihe(a,b)2401 INT mult_apply_reihe(a,b) OP a,b;
2402 /* AK 150393 */
2403 {
2404 OP c;
2405 INT erg = OK;
2406 c = callocobject();
2407 erg += copy(b,c);
2408 erg += mult(a,c,b);
2409 erg += freeall(c);
2410 if (erg != OK)
2411 EDC("mult_apply_reihe");
2412 return erg;
2413 }
2414
2415
Eins_eingabe(root,anzahl)2416 static INT Eins_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
2417 {
2418 return co_eingabe (root, anzahl, 1L);
2419 }
Random_eingabe(root,anzahl)2420 static INT Random_eingabe(root, anzahl) REIHE_zeiger root; INT anzahl;
2421 {
2422 return co_eingabe (root, anzahl, 2L);
2423 }
2424
co_eingabe(root,anzahl,para)2425 static INT co_eingabe(root, anzahl, para ) REIHE_zeiger root; INT anzahl,para;
2426 /* AK 300793 */
2427 {
2428 INT i,j,l,k;
2429 INT erg = OK;
2430 struct REIHE_mon *zeigmon;
2431 struct REIHE_variablen *zeigvar,*help_drei;
2432
2433 /*
2434 b=callocobject();
2435 d=callocobject();
2436 f=callocobject();
2437 */
2438 if (root->exist==0)
2439 {
2440 zeigmon=new_zwei();
2441 zeigmon->coeff=callocobject();
2442 zeigmon->zeiger=NULL;
2443 zeigmon->ref=NULL;
2444 switch(para)
2445 {
2446 case 1:
2447 erg += M_I_I(1L,zeigmon->coeff);
2448 break;
2449 case 2:
2450 erg += random_integer(zeigmon->coeff,NULL,NULL);
2451 break;
2452 default:
2453 error("internal error:RH3");
2454 }
2455 erg += einfuegen_in_reihe(zeigmon,root);
2456 }
2457 for (l=root->exist+1L;l<=root->exist+anzahl;l++)
2458 {
2459 zeigmon=new_zwei();
2460 zeigmon->coeff=callocobject();
2461 zeigmon->ref=NULL;
2462 switch(para)
2463 {
2464 case 1:
2465 erg += M_I_I(1L,zeigmon->coeff);
2466 break;
2467 case 2:
2468 erg += random_integer(zeigmon->coeff,NULL,NULL);
2469 break;
2470 default:
2471 error("internal error:RH4");
2472 }
2473
2474 help_drei=new_drei();
2475 help_drei->weiter=NULL;
2476 zeigmon->zeiger=help_drei;
2477 zeigvar=help_drei;
2478 zeigvar->index=0;
2479 zeigvar->potenz=l;
2480 erg += einfuegen_in_reihe(zeigmon,root);
2481 }
2482 root->exist+=anzahl; /* erhoehen um anzahl */
2483 /*
2484 erg += freeall(b);
2485 erg += freeall(d);
2486 erg += freeall(f);
2487 */
2488 if (erg != OK)
2489 error("internal error:RH5");
2490 return erg;
2491 }
2492
t_MONOM_REIHE_mon(a,b)2493 static INT t_MONOM_REIHE_mon(a,b) OP a;struct REIHE_mon *b;
2494 {
2495 INT i;
2496 struct REIHE_variablen *c;
2497 b->coeff = callocobject();
2498 copy(S_MO_K(a),b->coeff);
2499 c = b->zeiger; /* fuer variablen */
2500 for (i=0L;i<S_MO_SLI(a);i++)
2501 {
2502 if (not nullp(S_MO_SI(a,i)))
2503 {
2504 /* ein exponent ungleich NULL */
2505 if (b->zeiger == NULL)
2506 {
2507 b->zeiger = new_var();
2508 c = b->zeiger;
2509 }
2510 else {
2511 c->weiter = new_var();
2512 c = c->weiter;
2513 }
2514 }
2515 c->index = i;
2516 c->potenz = s_i_i(S_MO_SI(a,i));
2517 }
2518 return OK;
2519 }
2520
2521
select_degree_reihe(a,b,c)2522 INT select_degree_reihe(a,b,c) OP a,b,c;
2523 /* AK 030893 */
2524 {
2525 struct REIHE_poly *info;
2526 REIHE_zeiger z;
2527 OBJECTSELF d;
2528 INT erg = OK;
2529
2530 if (S_O_K(a) != REIHE)
2531 {
2532 erg += WTT("select_degree_reihe",a,b);
2533 goto sdr_ende;
2534 }
2535 if (S_O_K(b) != INTEGER)
2536 {
2537 erg += WTT("select_degree_reihe",a,b);
2538 goto sdr_ende;
2539 }
2540 if (S_I_I(b) < 0L)
2541 {
2542 erg += ERROR;
2543 goto sdr_ende;
2544 }
2545
2546 init(POLYNOM,c);
2547 d = S_O_S(a);
2548 z = d.ob_reihe;
2549
2550 info = z->infozeig;
2551 while (info != NULL)
2552 {
2553 if (S_I_I(b) == info->grad)
2554 {
2555 erg += poly_zu_sympolynom(info,c);
2556 goto sdr_ende;
2557 }
2558 info = info->rechts;
2559 }
2560 sdr_ende:
2561 if (erg != OK)
2562 EDC("select_degree_reihe");
2563 return erg;
2564 }
2565
select_coeff_reihe(a,b,d)2566 INT select_coeff_reihe(a,b,d) OP a,b,d;
2567 /* AK 020893 */
2568 {
2569 OP c;
2570 INT erg = OK;
2571
2572 if (S_O_K(b) != VECTOR)
2573 return ERROR;
2574 if (S_O_K(a) != REIHE)
2575 return ERROR;
2576
2577 c = callocobject();
2578 erg += t_REIHE_POLYNOM(a,c);
2579 erg += select_coeff_polynom(c,b,d);
2580 erg += freeall(c);
2581 return erg;
2582 }
2583
length_reihe(a,b)2584 INT length_reihe(a,b) OP a,b;
2585 /* AK 251093 */
2586 {
2587 OP c;
2588 INT erg = OK;
2589 c = callocobject();
2590 erg += t_REIHE_POLYNOM(a,c);
2591 erg += length(c,b);
2592 erg += freeall(c);
2593 if (erg != OK)
2594 EDC("length_reihe");
2595 return erg;
2596 }
2597
rh_test()2598 INT rh_test()
2599 {
2600 OP a,b,c,d,e,f,g,h,h2,x;
2601 INT i,j,i1,j1,l; FILE *fp1,*fp2;
2602
2603 a=callocobject();
2604 b=callocobject();
2605 c=callocobject(); d=callocobject();
2606 e=callocobject();
2607 f=callocobject();
2608 g=callocobject();
2609 h=callocobject();
2610 h2=callocobject();
2611
2612 m_sinus_reihe(a);
2613 copy(a,b); println(a); println(b);
2614 printf("%d\n",comp(a,b));
2615 inc(a);inc(a); println(a);
2616 printf("%d\n",comp(a,b));
2617 inc(b);inc(b); println(b);
2618 printf("%d\n",comp(a,b));
2619 inc(b);inc(b); println(b);
2620 printf("%d\n",comp(a,b));
2621 inc(a);inc(a); println(a);
2622 printf("%d\n",comp(a,b));
2623
2624 m_iindex_iexponent_monom(0L,3L,c);
2625 println(c);
2626 select_coeff_reihe(b,S_PO_S(c),d);
2627 println(d);
2628
2629 max_degree_reihe(b,c);
2630 println(c);
2631
2632 m_perm_reihe(b);
2633 max_degree_reihe(b,c);
2634 println(c);
2635 inc(b); inc(b); println(b);
2636 max_degree_reihe(b,c);
2637 println(c);
2638
2639 m_eins_reihe(a); println(a);
2640 add(a,cons_eins,b);
2641 println(b);
2642
2643 m_cosinus_reihe(a);
2644 add_apply(a,b);
2645 println(b);
2646
2647 addinvers(b,c);
2648 println(c);
2649 add(b,c,a);
2650 println(a);
2651 if (not nullp(a))
2652 error("not null");
2653 random_reihe(a);
2654 println(a);
2655 random_reihe(b);
2656 println(b);
2657 add(a,b,c);
2658
2659 m_perm_reihe(b);
2660 select_degree_reihe(b,cons_null,d);
2661 println(d); debugprint(d);
2662 select_degree_reihe(b,cons_eins,d);
2663 println(d);
2664 m_i_i(5L,a);
2665 select_degree_reihe(b,a,d);
2666 println(d);
2667
2668 freeall(a); freeall(b); freeall(c); freeall(d); freeall(e);
2669 freeall(f);freeall(g);freeall(h);freeall(h2);
2670
2671 }
2672 #endif /* REIHETRUE */
2673 #ifdef REIHETRUE
scan_reihe(a)2674 INT scan_reihe(a) OP a;
2675 /* AK 221093 */
2676 {
2677 int i;
2678 INT erg = OK;
2679 printeingabe("input of REIHE object");
2680 printeingabe("sinus[1] cosinus[2] identity[3]");
2681 printeingabe("perm [4] random [5] ");
2682 scanf("%d",&i);
2683 switch(i)
2684 {
2685 case 1: erg += m_sinus_reihe(a); break;
2686 case 2: erg += m_cosinus_reihe(a); break;
2687 case 3: erg += m_eins_reihe(a); break;
2688 case 4: erg += m_perm_reihe(a); break;
2689 case 5: erg += random_reihe(a); break;
2690 default: erg += ERROR;
2691 }
2692 if (erg != OK)
2693 EDC("scan_reihe");
2694 return erg;
2695 }
2696 #endif /* REIHETRUE */
2697