Ticket #16997: infinity.patch

File infinity.patch, 4.9 KB (added by jdemeyer, 7 years ago)

Removed patch

  • doc/usersch4.tex

    commit 56a75c6789284da3a1e0cbaca1254ffcb7c43423
    Author: Jeroen Demeyer <jdemeyer@cage.ugent.be>
    Date:   Mon Sep 22 17:20:12 2014 +0200
    
        Enable basic arithmetic with t_INFINITY
    
    diff --git a/doc/usersch4.tex b/doc/usersch4.tex
    index dde26b6..1592650 100644
    a b variadic, $0$ else. 
    15011501This type has a single \typ{INT} component, which is either $1$ or $-1$,
    15021502corresponding to $+\infty$ and $-\infty$ respectively.
    15031503
    1504 \fun{GEN}{mkmoo}{} returns $-\infty$
     1504\fun{GEN}{mkmoo}{} returns $-\infty$.
    15051505
    1506 \fun{GEN}{mkoo}{} returns $\infty$
     1506\fun{GEN}{mkoo}{} returns $\infty$.
     1507
     1508\fun{GEN}{mksoo}{long s} returns $\infty$ if $s \geq 0$ and $-\infty$ otherwise.
    15071509
    15081510\fun{long}{inf_get_sign}{GEN x} returns $1$ if $x$ is $+\infty$, and $-1$
    15091511if $x$ is $-\infty$.
  • src/basemath/gen1.c

    diff --git a/src/basemath/gen1.c b/src/basemath/gen1.c
    index e272eb5..1464e3c 100644
    a b add_rfrac_scal(GEN y, GEN x) 
    782782static GEN
    783783add_scal(GEN y, GEN x, long ty)
    784784{
     785  long tx;
    785786  switch(ty)
    786787  {
    787788    case t_POL: return RgX_Rg_add(y, x);
    788789    case t_SER: return add_ser_scal(y, x);
    789790    case t_RFRAC: return add_rfrac_scal(y, x);
     791    case t_INFINITY:
     792      tx = typ(x);
     793      if (tx == t_INT || tx == t_REAL || tx == t_FRAC) return mksoo(inf_get_sign(y));
     794      break;
    790795    case t_COL: return RgC_Rg_add(y, x);
    791796    case t_VEC:
    792797      if (isintzero(x)) return gcopy(y);
    gadd(GEN x, GEN y) 
    10151020      if (lx == 1) return cgetg(1, t_MAT);
    10161021      if (lgcols(y) != lgcols(x)) pari_err_OP("+",x,y);
    10171022      return RgM_add(x,y);
     1023    case t_INFINITY:
     1024      if (inf_get_sign(x) == inf_get_sign(y)) return mksoo(inf_get_sign(x));
     1025      pari_err_OP("+",x,y);
    10181026
    10191027    default: pari_err_TYPE2("+",x,y);
    10201028  }
    gsub(GEN x, GEN y) 
    13061314      return RgM_sub(x,y);
    13071315    }
    13081316    case t_RFRAC: case t_SER: break;
     1317    case t_INFINITY:
     1318      if (inf_get_sign(x) != inf_get_sign(y)) return mksoo(inf_get_sign(x));
     1319      pari_err_OP("+",x,y);
    13091320
    13101321    default: pari_err_TYPE2("+",x,y);
    13111322  }
    mul_rfrac_scal(GEN n, GEN d, GEN x) 
    13701381static GEN
    13711382mul_scal(GEN y, GEN x, long ty)
    13721383{
     1384  int s;
    13731385  switch(ty)
    13741386  {
    13751387    case t_POL:
    mul_scal(GEN y, GEN x, long ty) 
    13771389      return RgX_Rg_mul(y, x);
    13781390    case t_SER: return mul_ser_scal(y, x);
    13791391    case t_RFRAC: return mul_rfrac_scal(gel(y,1),gel(y,2), x);
     1392    case t_INFINITY:
     1393      s = gsigne(x) * inf_get_sign(y);
     1394      if (!s) pari_err_OP("*",x,y);
     1395      return mksoo(s);
    13801396    case t_QFI: case t_QFR:
    13811397      if (typ(x) == t_INT && gequal1(x)) return gcopy(y); /* fall through */
    13821398  }
    gmul(GEN x, GEN y) 
    19141930      }
    19151931      return z;
    19161932
     1933    case t_INFINITY: return mksoo(inf_get_sign(x) * inf_get_sign(y));
    19171934
    19181935    default:
    19191936      pari_err_TYPE2("*",x,y);
    GEN 
    25032520gdiv(GEN x, GEN y)
    25042521{
    25052522  long tx = typ(x), ty = typ(y), lx, ly, vx, vy, i;
     2523  int s;
    25062524  pari_sp av, tetpil;
    25072525  GEN z, p1, p2;
    25082526
    gdiv(GEN x, GEN y) 
    28362854      return z;
    28372855    case t_LIST: case t_STR: case t_VECSMALL: case t_CLOSURE:
    28382856      pari_err_TYPE2("/",x,y);
     2857    case t_INFINITY:
     2858      s = inf_get_sign(x) * gsigne(y);
     2859      if (!s) pari_err_INV("/", y);
     2860      return mksoo(s);
    28392861  }
    28402862
    28412863  vy = gvar(y);
  • src/basemath/gen2.c

    diff --git a/src/basemath/gen2.c b/src/basemath/gen2.c
    index 0a94fc4..d85cfda 100644
    a b gneg(GEN x) 
    17311731    case t_VEC: return RgV_neg(x);
    17321732    case t_COL: return RgC_neg(x);
    17331733    case t_MAT: return RgM_neg(x);
    1734     case t_INFINITY: return inf_get_sign(x) == 1? mkmoo(): mkoo();
     1734    case t_INFINITY: return mksoo(-inf_get_sign(x));
    17351735    default:
    17361736      pari_err_TYPE("gneg",x);
    17371737      return NULL; /* not reached */
    gneg_i(GEN x) 
    17991799      gel(y,1) = gneg_i(gel(x,1));
    18001800      gel(y,2) = gel(x,2); break;
    18011801
     1802    case t_INFINITY: return mksoo(-inf_get_sign(x));
     1803
    18021804    default:
    18031805      pari_err_TYPE("gneg_i",x);
    18041806      return NULL; /* not reached */
  • src/headers/paridecl.h

    diff --git a/src/headers/paridecl.h b/src/headers/paridecl.h
    index 7e02467..b4ac1c2 100644
    a b INLINE GEN mkcomplex(GEN x, GEN y); 
    41634163INLINE GEN    mkerr(long n);
    41644164INLINE GEN    mkmoo();
    41654165INLINE GEN    mkoo();
     4166INLINE GEN    mksoo(long s);
    41664167INLINE GEN    mkfrac(GEN x, GEN y);
    41674168INLINE GEN    mkfraccopy(GEN x, GEN y);
    41684169INLINE GEN    mkintmod(GEN x, GEN y);
  • src/headers/pariinl.h

    diff --git a/src/headers/pariinl.h b/src/headers/pariinl.h
    index 9a67a02..6912ae1 100644
    a b INLINE GEN 
    235235mkoo() { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
    236236INLINE GEN
    237237mkmoo() { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     238INLINE GEN
     239mksoo(long s) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = (s >= 0) ? gen_1 : gen_m1; return v; }
    238240INLINE long
    239241inf_get_sign(GEN x) { return signe(gel(x,1)); }
    240242/* pol */