Changeset e8a0aa in git
- Timestamp:
- Aug 6, 2008, 3:55:42 PM (16 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 3832e66fe9e1ccb1939127b0b8335291fee1bf4e
- Parents:
- ad8e1b0d640cd2aaf8929e7568cf730da7d7d683
- Location:
- kernel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/longrat.cc
rad8e1b re8a0aa 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: longrat.cc,v 1.3 7 2008-07-24 13:36:16Singular Exp $ */4 /* $Id: longrat.cc,v 1.38 2008-08-06 13:55:41 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: computation with long rational numbers (Hubert Grassmann) … … 1155 1155 } 1156 1156 1157 number nlShort(number x) 1158 { 1159 if (mpz_cmp_ui(&x->z,(long)0)==0) 1160 { 1161 nlDelete(&x,currRing); 1162 return INT_TO_SR(0); 1163 } 1164 return x; 1165 } 1157 1166 /*2 1158 1167 * simplify x … … 1635 1644 { 1636 1645 MP_INT x; 1637 MP_INT y;1638 1646 mpz_init(&x); 1639 mpz_init(&y); 1647 1640 1648 mpz_mul(&x,&b->z,&a->n); 1641 mpz_mul(& y,&a->z,&b->n);1642 mpz_add(&u->z,& x,&y);1649 mpz_mul(&u->z,&a->z,&b->n); 1650 mpz_add(&u->z,&u->z,&x); 1643 1651 mpz_clear(&x); 1644 mpz_clear(&y); 1652 1645 1653 if (mpz_cmp_ui(&u->z,(long)0)==0) 1646 1654 { … … 1663 1671 case 3: /* a:1 b:3 */ 1664 1672 { 1665 MP_INT x; 1666 mpz_init(&x); 1667 mpz_mul(&x,&b->z,&a->n); 1668 mpz_add(&u->z,&a->z,&x); 1669 mpz_clear(&x); 1673 mpz_mul(&u->z,&b->z,&a->n); 1674 mpz_add(&u->z,&u->z,&a->z); 1670 1675 if (mpz_cmp_ui(&u->z,(long)0)==0) 1671 1676 { … … 1694 1699 case 1:/* a:3, b:1 */ 1695 1700 { 1696 MP_INT x; 1697 mpz_init(&x); 1698 mpz_mul(&x,&a->z,&b->n); 1699 mpz_add(&u->z,&b->z,&x); 1700 mpz_clear(&x); 1701 mpz_mul(&u->z,&a->z,&b->n); 1702 mpz_add(&u->z,&u->z,&b->z); 1701 1703 if (mpz_cmp_ui(&u->z,(long)0)==0) 1702 1704 { … … 2249 2251 { 2250 2252 return (a==INT_TO_SR(0)); 2253 //return (mpz_cmp_si(&a->z,(long)0)==0); 2251 2254 } 2252 2255 … … 2322 2325 } 2323 2326 2327 number nlShort(number x); 2328 2329 LINLINE number nlInpAdd (number a, number b, const ring r) 2330 { 2331 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 2332 { 2333 int r=SR_HDL(a)+SR_HDL(b)-1; 2334 if ( ((r << 1) >> 1) == r ) 2335 return (number)(long)r; 2336 else 2337 return nlRInit(SR_TO_INT(r)); 2338 } 2339 // a=a+b 2340 if (SR_HDL(b) & SR_INT) 2341 { 2342 switch (a->s) 2343 { 2344 case 0: 2345 case 1:/* b:short, a:1 */ 2346 { 2347 MP_INT x; 2348 mpz_init(&x); 2349 mpz_mul_si(&x,&a->n,SR_TO_INT(b)); 2350 mpz_add(&a->z,&a->z,&x); 2351 mpz_clear(&x); 2352 a->s = 0; 2353 nlNormalize(a); 2354 break; 2355 } 2356 case 3: 2357 { 2358 if ((long)b>0L) 2359 mpz_add_ui(&a->z,&a->z,SR_TO_INT(b)); 2360 else 2361 mpz_sub_ui(&a->z,&a->z,-SR_TO_INT(b)); 2362 a->s = 3; 2363 a=nlShort(a); 2364 break; 2365 } 2366 } 2367 return a; 2368 } 2369 if (SR_HDL(a) & SR_INT) 2370 { 2371 number u=(number)omAllocBin(rnumber_bin); 2372 #if defined(LDEBUG) 2373 u->debug=123456; 2374 #endif 2375 mpz_init(&u->z); 2376 switch (b->s) 2377 { 2378 case 0: 2379 case 1:/* a:short, b:1 */ 2380 { 2381 MP_INT x; 2382 mpz_init(&x); 2383 2384 mpz_mul_si(&x,&b->n,SR_TO_INT(a)); 2385 mpz_add(&u->z,&b->z,&x); 2386 mpz_clear(&x); 2387 // result cannot be 0, if coeffs are normalized 2388 mpz_init_set(&u->n,&b->n); 2389 u->s = 0; 2390 nlNormalize(u); 2391 break; 2392 } 2393 case 3: 2394 { 2395 if ((long)a>0L) 2396 mpz_add_ui(&u->z,&b->z,SR_TO_INT(a)); 2397 else 2398 mpz_sub_ui(&u->z,&b->z,-SR_TO_INT(a)); 2399 // result cannot be 0, if coeffs are normalized 2400 u->s = 3; 2401 u=nlShort(u); 2402 break; 2403 } 2404 } 2405 #ifdef LDEBUG 2406 nlTest(u); 2407 #endif 2408 return u; 2409 } 2410 else 2411 { 2412 switch (a->s) 2413 { 2414 case 0: 2415 case 1: 2416 { 2417 switch(b->s) 2418 { 2419 case 0: 2420 case 1: /* a:1 b:1 */ 2421 { 2422 MP_INT x; 2423 MP_INT y; 2424 mpz_init(&x); 2425 mpz_init(&y); 2426 mpz_mul(&x,&b->z,&a->n); 2427 mpz_mul(&y,&a->z,&b->n); 2428 mpz_add(&a->z,&x,&y); 2429 mpz_clear(&x); 2430 mpz_clear(&y); 2431 mpz_mul(&a->n,&a->n,&b->n); 2432 a->s = 0; 2433 break; 2434 } 2435 case 3: /* a:1 b:3 */ 2436 { 2437 MP_INT x; 2438 mpz_init(&x); 2439 mpz_mul(&x,&b->z,&a->n); 2440 mpz_add(&a->z,&a->z,&x); 2441 mpz_clear(&x); 2442 a->s = 0; 2443 break; 2444 } 2445 } /*switch (b->s) */ 2446 nlNormalize(a); 2447 break; 2448 } 2449 case 3: 2450 { 2451 switch(b->s) 2452 { 2453 case 0: 2454 case 1:/* a:3, b:1 */ 2455 { 2456 MP_INT x; 2457 mpz_init(&x); 2458 mpz_mul(&x,&a->z,&b->n); 2459 mpz_add(&a->z,&b->z,&x); 2460 mpz_clear(&x); 2461 mpz_init_set(&a->n,&b->n); 2462 a->s = 0; 2463 nlNormalize(a); 2464 break; 2465 } 2466 case 3: 2467 { 2468 mpz_add(&a->z,&a->z,&b->z); 2469 a->s = 3; 2470 a=nlShort(a); 2471 break; 2472 } 2473 } 2474 break; 2475 } 2476 } 2477 #ifdef LDEBUG 2478 nlTest(a); 2479 #endif 2480 return a; 2481 } 2482 } 2483 2324 2484 LINLINE number nlMult (number a, number b) 2325 2485 { … … 2367 2527 #ifndef P_NUMBERS_H 2368 2528 2369 void nlInpGcd(number &a, number b, ring r)2529 void nlInpGcd(number &a, number b, const ring r) 2370 2530 { 2371 2531 if ((SR_HDL(b)|SR_HDL(a))&SR_INT) … … 2391 2551 } 2392 2552 } 2393 void nlInpIntDiv(number &a, number b, ring r)2553 void nlInpIntDiv(number &a, number b, const ring r) 2394 2554 { 2395 2555 if ((SR_HDL(b)|SR_HDL(a))&SR_INT) … … 2439 2599 } 2440 2600 } 2441 void nlInpAdd (number &a, number b,ring r)2601 void nlInpAdd_(number &a, number b, const ring r) 2442 2602 { 2443 2603 // TODO … … 2464 2624 } 2465 2625 } 2466 void nlInpMult(number &a, number b, ring r)2626 void nlInpMult(number &a, number b, const ring r) 2467 2627 { 2468 2628 if (((SR_HDL(b)|SR_HDL(a))&SR_INT) -
kernel/longrat.h
rad8e1b re8a0aa 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: longrat.h,v 1.1 2 2008-07-16 12:41:33 wienandExp $ */6 /* $Id: longrat.h,v 1.13 2008-08-06 13:55:42 Singular Exp $ */ 7 7 /* 8 8 * ABSTRACT: computation with long rational numbers … … 102 102 103 103 // in-place operations 104 void nlInpGcd(number &a, number b, ring r); 105 void nlInpIntDiv(number &a, number b, ring r); 106 void nlInpAdd(number &a, number b, ring r); 104 void nlInpGcd(number &a, number b, const ring r); 105 void nlInpIntDiv(number &a, number b, const ring r); 106 void nlInpAdd_(number &a, number b, const ring r); 107 LINLINE number nlInpAdd(number la, number li, const ring r); 107 108 void nlInpMult(number &a, number b, ring r); 108 109 -
kernel/numbers.cc
rad8e1b re8a0aa 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: numbers.cc,v 1.1 7 2008-07-07 12:21:43 wienandExp $ */4 /* $Id: numbers.cc,v 1.18 2008-08-06 13:55:42 Singular Exp $ */ 5 5 6 6 /* … … 82 82 n_Delete(&a,r); 83 83 a=n; 84 } 85 number ndInpAdd(number &a, number b, const ring r) 86 { 87 number n=n_Add(a,b,r); 88 n_Delete(&a,r); 89 a=n; 90 return a; 84 91 } 85 92 -
kernel/numbers.h
rad8e1b re8a0aa 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: numbers.h,v 1.1 4 2008-07-07 12:21:43 wienandExp $ */6 /* $Id: numbers.h,v 1.15 2008-08-06 13:55:42 Singular Exp $ */ 7 7 /* 8 8 * ABSTRACT: interface to coefficient aritmetics … … 93 93 number ndCopy(number a); 94 94 void ndInpMult(number &a, number b, const ring r); 95 number ndInpAdd(number &a, number b, const ring r); 95 96 96 97 #ifdef LDEBUG -
kernel/p_Add_q__T.cc
rad8e1b re8a0aa 7 7 * Author: obachman (Olaf Bachmann) 8 8 * Created: 8/00 9 * Version: $Id: p_Add_q__T.cc,v 1. 1.1.1 2003-10-06 12:15:58Singular Exp $9 * Version: $Id: p_Add_q__T.cc,v 1.2 2008-08-06 13:55:42 Singular Exp $ 10 10 *******************************************************************/ 11 11 … … 43 43 n1 = pGetCoeff(p); 44 44 n2 = pGetCoeff(q); 45 t = n_Add(n1,n2, r); 46 n_Delete(&n1, r); 45 //t = n_Add(n1,n2, r); 46 //n_Delete(&n1, r); 47 t=n_InpAdd(n1,n2,r); 47 48 n_Delete(&n2, r); 48 49 q = p_LmFreeAndNext(q, r); -
kernel/p_Numbers.h
rad8e1b re8a0aa 7 7 * Author: obachman (Olaf Bachmann) 8 8 * Created: 8/00 9 * Version: $Id: p_Numbers.h,v 1. 3 2008-01-30 09:01:37 wienandExp $9 * Version: $Id: p_Numbers.h,v 1.4 2008-08-06 13:55:42 Singular Exp $ 10 10 *******************************************************************/ 11 11 #ifndef P_NUMBERS_H … … 23 23 //#define n_InpMult_FieldGeneral(n1, n2, r) (r)->cf->nInpMult(n1, n2, r) 24 24 #define n_InpMult_FieldGeneral(n1, n2, r) ndInpMult(n1, n2, r) 25 #define n_InpAdd_FieldGeneral(n1, n2, r) n1=ndInpAdd(n1, n2, r) 25 26 26 27 #ifdef HAVE_RINGS … … 35 36 //#define n_InpMult_RingGeneral(n1, n2, r) (r)->cf->nInpMult(n1, n2, r) 36 37 #define n_InpMult_RingGeneral(n1, n2, r) ndInpMult(n1, n2, r) 38 #define n_InpAdd_FieldGeneral(n1, n2, r) n1=ndInpAdd(n1, n2, r) 37 39 #endif 38 40 … … 47 49 #define n_Sub_FieldZp(n1, n2, r) npSubM(n1, n2) 48 50 #define n_InpMult_FieldZp(n1, n2, r) n1=npMultM(n1, n2) 51 #define n_InpAdd_FieldZp(n1, n2, r) n1=npAddM(n1, n2) 49 52 50 53 #define DO_LINLINE … … 59 62 #define n_Sub_FieldQ(n1, n2, r) nlSub(n1, n2) 60 63 #define n_InpMult_FieldQ(n1, n2, r) nlInpMult(n1, n2, r) 64 #define n_InpAdd_FieldQ(n1, n2, r) n1=nlInpAdd(n1, n2, r) 61 65 #endif -
kernel/p_Procs_Generate.cc
rad8e1b re8a0aa 8 8 * Author: obachman (Olaf Bachmann) 9 9 * Created: 8/00 10 * Version: $Id: p_Procs_Generate.cc,v 1. 3 2007-05-10 08:12:42 wienandExp $10 * Version: $Id: p_Procs_Generate.cc,v 1.4 2008-08-06 13:55:42 Singular Exp $ 11 11 *******************************************************************/ 12 12 … … 69 69 } 70 70 71 const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", NULL};71 const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", "n_InpMult", "n_InpAdd", NULL}; 72 72 73 73 const char* macros_length[] =
Note: See TracChangeset
for help on using the changeset viewer.