fosuwxb

25 Reputation

One Badge

1 years, 133 days

MaplePrimes Activity


These are Posts that have been published by fosuwxb

Here are the source codes for the paper  "Gaps Between Integers Having a Common Divisor with an Odd Semi-prime"


 

gg := proc (x, y) return abs(x-y)-1 end proc

proc (x, y) return abs(x-y)-1 end proc

(1)

CopyArrayElem := proc (x, n) local y, i; y := Array(1 .. n); for i to n do y(i) := x(i) end do; return y end proc

proc (x, n) local y, i; y := Array(1 .. n); for i to n do y(i) := x(i) end do; return y end proc

(2)

PrintArray := proc (x, n) local i; for i to n do printf("%d, ", x(i)); if i = (1/2)*n then printf("|,") end if end do; printf("\n") end proc

proc (x, n) local i; for i to n do printf("%d, ", x(i)); if i = (1/2)*n then printf("|,") end if end do; printf("
") end proc

(3)

GapArray := proc (x, n) local i, y; y := Array(1 .. n-1); for i to n-1 do y(i) := gg(x(i), x(i+1)) end do; return y end proc

proc (x, n) local i, y; y := Array(1 .. n-1); for i to n-1 do y(i) := gg(x(i), x(i+1)) end do; return y end proc

(4)

ShiftArrayElem := proc (x, n, d) local i, y; y := Array(1 .. n); for i to n do y(i) := x(i)+d end do; return y end proc

proc (x, n, d) local i, y; y := Array(1 .. n); for i to n do y(i) := x(i)+d end do; return y end proc

(5)

NULL

"chost:=proc(p,q) local i,j,m; local Hpq,hh;   Hpq:=Array(1..p+q-2);  hh:=Array(1..p+q-2);    for i from 1 to q-1 do   Hpq(i):=i*p;   od;      for j from 1 to p-1 do;   Hpq(i++):=j*q;   od;   hh:=sort(Hpq);    return hh;    end proc "

proc (p, q) local i, j, m, Hpq, hh; Hpq := Array(1 .. p+q-2); hh := Array(1 .. p+q-2); for i to q-1 do Hpq(i) := i*p end do; for j to p-1 do Hpq(`++`(i)) := j*q end do; hh := sort(Hpq); return hh end proc

(6)

nGroup := proc (p, m) local j, n, ar; ar := Array(1 .. m); for j from 0 to m-1 do n := ceil((j+1)*p/m)-floor(j*p/m)-1; ar(j+1) := n end do; return ar end proc

proc (p, m) local j, n, ar; ar := Array(1 .. m); for j from 0 to m-1 do n := ceil((j+1)*p/m)-floor(j*p/m)-1; ar(j+1) := n end do; return ar end proc

(7)

Position := proc (ary, k) local i, pos; pos := 0; for i to k-1 do pos := pos+ary(i) end do; pos := pos+1; return pos end proc

proc (ary, k) local i, pos; pos := 0; for i to k-1 do pos := pos+ary(i) end do; pos := pos+1; return pos end proc

(8)

groups := proc (p, q, lm, m) local k, j, x, r, ll, rr, ni, bl, br, i; i := 1; printf("______\n"); for k from 0 to m-2 do ll := floor(k*p/m); rr := floor((k+1)*p/m); ni := rr-ll; for j to ni do r := (j+ll)*m-k*p; printf("(%d: %d),", i, r); if j = ni then printf(" # %d p-hosts after q-host %d\n", lm+1, i*q) end if; i := i+1 end do; printf("\n") end do; ll := floor((m-1)*p/m); rr := p-1; ni := rr-ll; for j to ni do r := (j+ll)*m-k*p; printf("(%d: %d),", i, r); i := i+1 end do; printf("\n______\n") end proc

proc (p, q, lm, m) local k, j, x, r, ll, rr, ni, bl, br, i; i := 1; printf("______
"); for k from 0 to m-2 do ll := floor(k*p/m); rr := floor((k+1)*p/m); ni := rr-ll; for j to ni do r := (j+ll)*m-k*p; printf("(%d: %d),", i, r); if j = ni then printf(" # %d p-hosts after q-host %d
", lm+1, i*q) end if; i := i+1 end do; printf("
") end do; ll := floor((m-1)*p/m); rr := p-1; ni := rr-ll; for j to ni do r := (j+ll)*m-k*p; printf("(%d: %d),", i, r); i := i+1 end do; printf("
______
") end proc

(9)

idx := proc (p, m) local i, r, ri; for i to p-1 do r := i*m-floor(i*m/p)*p; if r = 1 or r = p-1 then ri := i end if; printf("%d, ", r) end do; printf("\n"); return ri end proc

proc (p, m) local i, r, ri; for i to p-1 do r := i*m-floor(i*m/p)*p; if r = 1 or r = p-1 then ri := i end if; printf("%d, ", r) end do; printf("
"); return ri end proc

(10)

DoTest := proc (p, q) local k, i, j, x, y, r, ni, lambda, n, g, xx, ll, rr, w, pos, nj, hh, grp; n := p+q-2; g := Array(1 .. n-1); hh := chost(p, q); printf("Hosts of p and q are:\n"); PrintArray(hh, n); lambda := floor(q/p); r := q-lambda*p; printf("Lambda=%d\nr=%d\n", lambda, r); printf("The %d elements in S(r,p) are:\n", p-1); for i to p-1 do printf("%d,", i*r) end do; printf("\n"); printf("The %d elements in rZ(r,p) are:\n", p-1); for j to p-1 do x := j*r-floor(j*r/p)*p; printf("%d,", x) end do; printf("\n"); printf("The %d subsets are as follows:\n", r); groups(p, q, lambda, r); printf("The maximum gap is: %d \n", p-1); g := q-p-1; printf("Total number of maximum gaps is:%d\n", g); g := GapArray(hh, n); xx := CopyArrayElem(hh, n-1); dataplot(xx, g) end proc

proc (p, q) local k, i, j, x, y, r, ni, lambda, n, g, xx, ll, rr, w, pos, nj, hh, grp; n := p+q-2; g := Array(1 .. n-1); hh := chost(p, q); printf("Hosts of p and q are:
"); PrintArray(hh, n); lambda := floor(q/p); r := q-lambda*p; printf("Lambda=%d
r=%d
", lambda, r); printf("The %d elements in S(r,p) are:
", p-1); for i to p-1 do printf("%d,", i*r) end do; printf("
"); printf("The %d elements in rZ(r,p) are:
", p-1); for j to p-1 do x := j*r-floor(j*r/p)*p; printf("%d,", x) end do; printf("
"); printf("The %d subsets are as follows:
", r); groups(p, q, lambda, r); printf("The maximum gap is: %d 
", p-1); g := q-p-1; printf("Total number of maximum gaps is:%d
", g); g := GapArray(hh, n); xx := CopyArrayElem(hh, n-1); dataplot(xx, g) end proc

(11)

``

DoTest(3, 5)

 

DoTest(5, 7)

 

 

 

 

NULL

DoTest(7, 9)

 

DoTest(11, 13)

 

DoTest(7, 11)

 

NULL

DoTest(5, 23)

 

DoTest(11, 47)

 

DoTest(13, 71)

 

DoTest(17, 29)

 

DoTest(23, 31)

 

DoTest(13, 23)

 

DoTest(11, 17)

 

 

DoTest(11, 29)

 

DoTest(13, 27)

 

DoTest(13, 79)

 

DoTest(11, 45)

 

DoTest(41, 71)

 

DoTest(47, 97)

 

DoTest(53, 103)

 

DoTest(101, 199)

 

DoTest(101, 205)

 

DoTest(23, 45)

 

DoTest(13, 25)

 

DoTest(13, 77)

 

DoTest(23, 93)

 

DoTest(23, 91)

 

DoTest(13, 25)

 

DoTest(13, 77)

 

DoTest(47, 91)

 

DoTest(53, 109)

 

NULL


 

Download Hosts.mw

Source codes (seen in the pdf file) for the paper "Maximal Gap Among Integers Having a Common Divisor with an Odd Semi-prime".

MaxGapTheorem2.pdf

Here are the Maple sources for the paper "Maximum Gap among Integers Having a Common Divisor with an Odd semi-prime" published on Journal of Advances in Mathematics and Computer Science 39 (10):51-61, at :https://doi.org/10.9734/jamcs/2024/v39i101934.

 

gap := proc(a, b) return abs(a - b) - 1; end proc

HostsNdivisors := proc(N)

local i, j, g, d, L, s, t, m, p, q, P, Q, np, nq;

m := floor(1/2*N - 1/2);

L := evalf(sqrt(N));

P := Array();

Q := Array();

s := 1; t := 1;

for i from 3 to m do

   d := gcd(i, N);

    if 1 < d and d < L then P(s) := i; s++;

    elif L < d then Q(t) := i; t++; end if;

end do;

  np := s - 1;

  nq := t - 1;

 for i to np do printf("%3d,", P(i)); end do;

  printf("\n");

  for i to nq do printf("%3d,", Q(i)); end do;

  printf("\n gaps: \n");

  for i to np do

     for j to nq do

      p := P(i); q := Q(j);

      g := gap(p, q);

      printf("%4d,", g);

  end do;

    printf("\n");

end do;

end proc

 

HostOfpq := proc(p, q)

local alpha, s, t, g, r, S, T, i, j;

   S := 1/2*q - 1/2;

   T := 1/2*p - 1/2;

   alpha := floor(q/p);

    r := q - alpha*p;

   for s to S do

     for t to T do

       g := abs((t*alpha - s)*p + t*r) - 1;

        printf("%4d,", g);

      end do;

     printf("\n");

 end do;

end proc

MapleSource.pdf

MapleSource.mw

 

aRandStep2D := proc(X0, Y0, dx, dy)
  local X, Y, P, R;
  P := Array(1 .. 2);
  R := rand(1 .. 8)();
  if R = 1 then X := X0 - dx; Y := Y0 + dy; end if;
  if R = 2 then X := X0; Y := Y0 + dy; end if;
  if R = 3 then X := X0 + dx; Y := Y0 + dy; end if;
  if R = 4 then X := X0 - dx; Y := Y0; end if;
  if R = 5 then X := X0 + dx; Y := Y0; end if;
  if R = 6 then X := X0 - dx; Y := Y0 - dy; end if;
  if R = 7 then X := X0; Y := Y0 - dy; end if;
  if R = 8 then X := X0 + dx; Y := Y0 - dy; end if;
  P[1] := X; P[2] := Y;
  return P;
end proc 

SetStart := proc(b)
  local alpha, R, P;
  P := Array(1 .. 2);
  alpha := rand(1 .. b)();
  P[1] := alpha*b;
  P[2] := alpha*b;
  return P;
end proc 

RandomFactTpq := proc(N, pb, dx, dy)
  local alpha, X, Y, f, P, counter, B, n, T;
  P := Array(1 .. 2);
  counter := 0; f := 1;
  B := floor(evalf(sqrt(N))); #Set maximal searching steps
  T := floor(evalf(sqrt(N))); #For SetStart's use
  P := SetStart(T);
  X := P[1]; Y := P[2];
  while f = 1 and counter < B do  #loop
    n := pb - X - Y;
    f := gcd(N, n);
    if f > 1then break; end if;
    P := aRandStep2D(X, Y, dx, dy); #A random move
    X := P[1]; Y := P[2];
    if X < 1 or Y < 1 or N - pb - 1 < X or X <= Y then
      P := SetStart(T);       # Restart when out of borders
      X := P[1]; Y := P[2];
    end if;
    counter := counter + 1;    #Counting the searched steps
  end do;
  if  f>1  then print(Find at point (X, Y), found divisor = f, searching steps = counter);
  else print(This*time*finds*no*result, test*again!); end if;
end proc


wxbRandWalkTpqNew4.pdf

Page 1 of 1