How do we change the five sign functions, in each criteria of the final code, to get what I want?

Suppose, we have the following code (i.e., f[r] and g[r] can be any function, where f[r+c]<V[r]<g[r+d] or g[r+d]<V[r]<f[r+c] and c, d are small constants; e.g., between -10 and 10.)

V[r_]:=V[r]=r!+1
f[r]:=f[r]=
g[r_]:=g[r]=
LengthS[r_] := LengthS[r] = {f[r],g[r]}
LengthS1[r_, x_] := LengthS1[r, x] = LengthS[r][[x]]
LengthS2[j_, y_] := LengthS2[j, y] = LengthS[j][[y]]

We approximate the constants, in the code below, using this equation:

If F:\mathbb{N}\to\mathbb{R} and G:\mathbb{N}\to\mathbb{R} are
arbitrary functions, we want to calculate this equation with
Mathematica:

\begin{equation} c=\inf\left\{|1-\mathbf{c_1}|:\forall(\varepsilon>0)\exists(\mathbf{c_1}>0)\forall(r\in\mathbb{N})\exists(v\in\mathbb{N})\left(\left|\frac{F(r)}{G(v)}-\mathbf{c_1}\right|<\varepsilon\right)\right\} \tag{1} \end{equation}
cV1[r_, 1, 2] := cV1[r, 1, 2] = N[Min[Table[
 RealAbs[1 - V[r]/LengthS1[v, x]], {v, 1, 30000}]]]

cV1[r_, 2, 1 ] := cV1[r, 2, 1] = N[Min[Table[
 RealAbs[1 - LengthS1[r, x]]/V[v], {v, 1, 30000}]]] 

cV2[r_, 1, 2] := cV2[r, 1, 2] = N[Min[Table[
 RealAbs[1 - V[r]/LengthS2[v, y]], {v, 1, 30000}]]] 

cV2[r_, 2, 1] := cV2[r, 2, 1] = N[Min[Table[
 RealAbs[1 - LengthS2[r, y]/V[v]], {v, 1, 30000}]]] 

c[r_, 1, 2] := c[r, 1, 2] = N[Min[Table[
 RealAbs[1 - LengthS1[r, x]/LengthS2[v, y]], {v, 1, 30000}]]] 

c[r_, 2, 1] := c[r, 2, 1] = N[Min[Table[
 RealAbs[1 - LengthS2[r, y]/LengthS1[v, x]], {v, 1, 30000}]]]

In case the outputs are incorrect, use Equation \eqref{eq:1} to solve the exact value.

In addition, w.r.t. the inequality f[r+c]<V[r]<g[r+d], we adjust r+c and r+d into r+c1 and r+d1, using P1 (i.e., c1==c+1||c1==c||c1==c-1 and d1==d+1||d1==d||d1==d-1). If this makes no sense, then analyze the code.

P1 = 3 (*P1 can be any constant positive integer*)

Min11[r_, x_] := 
 Min11[r, x] = 
  Max[r1 /. 
    FindInstance[LengthS1[r1, x] <= V[r] < LengthS1[r1 + 1, x], {r1}, 
     PositiveIntegers]]

Min12[r_, x_] := 
 Min12[r, x] = 
  ArgMin[{RealAbs[LengthS1[r2, x] - V[r]], r - P1 <= r2 <= r + P1}, 
   r2, PositiveIntegers]

Min21[r_, y_] := 
 Min21[r, y] = 
  Max[r3 /. 
    FindInstance[LengthS2[r3, y] <= V[r] < LengthS2[r3 + 1, y], {r3}, 
     PositiveIntegers]]

Min22[r_, y_] := 
 Min22[r, y] = 
  ArgMin[{RealAbs[LengthS1[r4, y] - V[r]], r - P1 <= r4 <= r + P1}, 
   r4, PositiveIntegers]

rMin1[r_, x_] := 
 rMin1[r, x] = 
  Min12[r, x] + Sign[Floor[RealAbs[2 r - Min11[r, x] - Min12[r, x]]/2]]

rMin2[r_, y_] := 
 rMin2[r, y] = 
  Min22[r, y] + Sign[Floor[RealAbs[2 r - Min21[r, y] - Min22[r, y]]/2]]

Putting it together, here is what I want:

For any LengthS1[r,x]=f[r+c1] and LengthS2[r,y]==g[r+d1] such that for any function f and g, where f[r+c1]<V[r]<g[r+d1] or g[r+d1]<V[r]<f[r+c1], consider four out of sixteen cases. (I figured out the other cases, so I will not include them):

  1. Case 11:

     LengthS1[rMin1[r, x], x] > V[r] && V[r] > LengthS2[rMin2[r, y], y] && 
     RealAbs[LengthS1[rMin1[r, x], x] - V[r]] >
      RealAbs[LengthS2[rMin2[r, y], y] - V[r]]
    

and extra criteria including cV1, cV2, and c (see Equation \ref{eq:1}).

  1. Case 12:

     LengthS1[rMin1[r, y], y] > V[r] && V[r] > LengthS2[rMin2[r, x], x] && 
     RealAbs[LengthS1[rMin1[r, y], y] - V[r]] > 
     RealAbs[LengthS2[rMin2[r, x], x] - V[r]]
    

and extra criteria including cV1, cV2 and c (see Equation \ref{eq:1})

  1. Case 15:

     LengthS2[rMin2[r, y], y] > V[r] && V[r] > LengthS1[rMin1[r, x], x] &&
      RealAbs[LengthS2[rMin2[r, y], y] - V[r]] >
      RealAbs[LengthS1[rMin1[r, x], x] - V[r]]
    

and extra criteria including cV1, cV2 and c (see Equation \ref{eq:1})

  1. Case 16:

     LengthS2[rMin2[r, x], x] > V[r] && V[r] > LengthS1[rMin1[r, y], y] &&
      RealAbs[LengthS2[rMin1[r, x], x] - V[r]] >
      RealAbs[LengthS1[rMin2[r, y], y] - V[r]]
    

and extra criteria including cV1, cV2 and c (see Equation \ref{eq:1}).

In the code below (I assume) there should be five sign functions involved with cV1, cV2, and c in Equation \eqref{eq:1} that are multiplied by c[r,x,y] (in Q11), c[r,y,x] (in Q12), c[r,y,x] (in Q15), and c[r,x,y] (in Q16).

Note: In my research paper, I want the sign functions in (Q11 and Q12) and (Q15 and Q16) to be the same, except that the x and y are swapped. (See the code, for an example of such functions.)

Question: How do I change the five sign functions (in each criteria) to match any example that satisfies the former criteria? (Keep reading for specific examples.)


Here is what I got:

Q11[r_, x_, y_] := 
 Q11[r, x, y] =
       Sign[cV2[r, y, x] - cV1[r, y, x]] Sign[cV1[r, y, x] - cV2[r, x, y]] 
       Sign[cV2[r, x, y] - cV1[r, x, y]] Sign[c[r, x, y] - c[r, y, x]] 
       Sign[cV2[r, x, y] - cV2[r, y, x]] c[r, x, y] 
       >= c[r, y, x] && c[r, y, x] >= cV2[r, y, x] && LengthS1[rMin1[r, x], x] > 
       V[r] && V[r] > LengthS2[rMin2[r, y], y] && RealAbs[LengthS1[rMin1[r, x], x] - V[r]] 
       > RealAbs[LengthS2[rMin2[r, y], y] - V[r]]

Q12[r_, x_, y_] := 
 Q12[r, x, y] =
        Sign[cV2[r, x, y] - cV1[r, x, y]] Sign[cV1[r, x, y] - cV2[r, y, x]] 
        Sign[cV2[r, y, x] - cV1[r, y, x]] Sign[c[r, y, x] - c[r, x, y]] 
        Sign[cV2[r, y, x] - cV2[r, x, y]] c[r, y, x]
         >= c[r, x, y] && c[r, x, y] >= cV2[r, x, y] && LengthS1[rMin1[r, y], y] >
        V[r] && V[r] > LengthS2[rMin2[r, x], x] && RealAbs[LengthS1[rMin1[r, y], y] -V[r]] 
        > RealAbs[LengthS2[rMin2[r, x], x] - V[r]]

Q15[r_, x_, y_] := 
 Q15[r, x, y] = 
       Sign[cV2[r, x, y] - cV1[r, x, y]] Sign[cV1[r, x, y] - cV2[r, y, x]] 
       Sign[cV1[r, y, x] - cV2[r, y, x]] Sign[c[r, y, x] - c[r, x, y]] 
       Sign[cV1[r, x, y] - cV1[r, y, x]] c[r, y, x] 
       >= c[r, x, y] && c[r, x, y] >= cV1[r, y, x] && LengthS2[rMin2[r, y], y] > V[r] && V[r] > 
       LengthS1[rMin1[r, x], x] && RealAbs[LengthS2[rMin2[r, y], y] - V[r]]
       > RealAbs[LengthS1[rMin1[r, x], x] - V[r]]

Q16[r_, x_, y_] := 
 Q16[r, x, y] = 
       Sign[cV2[r, y, x] - cV1[r, y, x]] Sign[cV2[r, y, x] - cV1[r, x, y]] 
       Sign[cV1[r, x, y] - cV2[r, x, y]] Sign[c[r, x, y] - c[r, y, x]] 
       Sign[cV1[r, x, y] - cV1[r, y, x]] c[r,x, y] 
       >= c[r, y, x] && c[r, y, x] >= cV1[r, x, y] && LengthS2[rMin2[r, x], x] > V[r] && V[r] > 
       LengthS1[rMin1[r, y], y] && RealAbs[LengthS2[rMin2[r, x], x] - V[r]] > 
       RealAbs[LengthS1[rMin1[r, y], y] - V[r]]

Examples:

Here are the cases I worked with (they should satisfy the known criteria in the post). Note that r can be any natural number (e.g., r==10). I have not gotten the output I wanted for all the specific cases.

  1. LengthS[r_]:=LengthS[r]={11r!/8+1, 2r!/3+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={True,False,False,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,True,False,False})

  2. LengthS[r_]:=LengthS[r]={2r!/3+1, 11r!/8+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={False,False,True,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,False,False,True})

  3. LengthS[r_]:=LengthS[r]={4r!/3+1, 7r!/8+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={True,False,False,False} and {Q11[r,2,1],Q12[r,2,1],Q13[r,2,1],Q14[r,2,1]}=={False,True,False,False})

  4. LengthS[r_]:=LengthS[r]={7r!/8+1, 4r!/3+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={False,False,True,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,False,False,True})

  5. LengthS[r_]:=LengthS[r]={11r!/8+1, 33r!/50+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={True,False,False,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,True,False,False})

  6. LengthS[r_]:=LengthS[r]={33r!/50+1, 11r!/8+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={False,False,True,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,False,False,True})

  7. LengthS[r_]:=LengthS[r]={7r!/9+1, 11r!/8+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={True,False,False,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,True,False,False})

  8. LengthS[r_]:=LengthS[r]={11r!/8+1, 7r!/9+1} (it should return {Q11[r,1,2],Q12[r,1,2],Q15[r,1,2],Q16[r,1,2]}=={False,False,True,False} and {Q11[r,2,1],Q12[r,2,1],Q15[r,2,1],Q16[r,2,1]}=={False,False,False,True})

Reading your first block of code, it seems that the functions LengthS1 and LengthS2 are exactly the same function, with just different names for the variables.

Yes, that is true, but the variables x or y can be 1 or 2. As long as the numbers in the variables are different, the functions are different.

I define LengthS1 and LengthS2 this way for a special reason. (This would take a long time to explain.)

Cross-posted: https://mathematica.stackexchange.com/questions/319150/how-do-we-change-the-five-sign-functions-in-each-criteria-of-the-final-code-to