autocheck of rule.test ====================== In[1]:= (* TEST RULE FORMATION *) In[2]:= Clear[a, b, c, d, e, f, g, h, i, x, xx, yy, x1, x2, x3, x4, s, t] In[3]:= (x // listOfVariables) === {x} Out[3]= True In[4]:= (f[x] // listOfVariables) === {x} Out[4]= True In[5]:= (f[x, x] // listOfVariables) === {x} Out[5]= True In[6]:= (1 // listOfVariables) === {} Out[6]= True In[7]:= (f[1/2] // listOfVariables) === {} Out[7]= True In[8]:= (f[g[h[a, b], c], d] // listOfVariables) === {a, b, c, d} Out[8]= True In[9]:= (f[g[h[d, c], b], a] // listOfVariables) === {a, b, c, d} Out[9]= True In[10]:= s = a + b c + f[0, w, a] + 3 pi g[2] + h[i][c + d]; In[11]:= Unprotect[pi]; In[12]:= (s // listOfVariables) === {a, b, c, d, i, pi, w} Out[12]= True In[13]:= Protect[pi]; In[14]:= (s // listOfVariables) === {a, b, c, d, i, w} Out[14]= True In[15]:= (s // restrictedListOfVariables) === {a, b, c, d, w} Out[15]= True In[16]:= (s // extendedListOfVariables) === {a, b, c, d, f, g, h, i, w} Out[16]= True In[17]:= Clear[s] In[18]:= e1 = f[x, y, z] == a[x, y] + b[z] x^2/y + xx yy; In[19]:= ClearAttributes[RuleDelayed, HoldRest] In[20]:= bruleFor[e1] === (f[x, y, z] :> xx yy + a[x, y] + (x^2 b[z])/y) Out[20]= True In[21]:= gruleFor[e1] === (f[x_, y_, z_] :> xx yy + a[x, y] + (x^2 b[z])/y) Out[21]= True In[22]:= listOfVariables[e1] === {x, xx, y, yy, z} Out[22]= True In[23]:= cruleFor[e1][w] === (f[w, y, z] :> xx yy + a[w, y] + (w^2 b[z])/y) Out[23]= True In[24]:= cruleFor[e1][u, v] === (f[u, y, z] :> v yy + a[u, y] + (u^2 b[z])/y) Out[24]= True In[25]:= cruleFor[e1][x1, x2, x3] === (f[x1, x3, z] :> x2 yy + a[x1, x3] + (x1^2 b[z])/x3) Out[25]= True In[26]:= cruleFor[e1][x1, x2, x3, x4, x5] === (f[x1, x3, x5] :> x2 x4 + a[x1, x3] + (x1^2 b[x5])/x3) Out[26]= True In[27]:= cruleFor[e1][x1, , x3, , x5] === (f[x1, x3, x5] :> xx yy + a[x1, x3] + (x1^2 b[x5])/x3) Out[27]= True In[28]:= localRule = hruleFor[Equal @@ (#[(a + b) x]& /@ {Expand, Identity})][x]; In[29]:= Off[Syntax::bktwrn] In[30]:= localRule[y] === (y (a_) + y (b_) :> (a + b) y) Out[30]= True In[31]:= localRule[s-t] === ((s - t) (a_) + (s - t) (b_) :> (a + b) (s -" t)) Out[31]= True In[32]:= On[Syntax::bktwrn] In[33]:= eqnList = {y == b x, f[x] == x + c}; In[34]:= bruleFor[eqnList] === {y :> b x, f[x] :> c + x} Out[34]= True In[35]:= gruleFor[eqnList] === {y_ :> b x, f[x_] :> c + x} Out[35]= True In[36]:= cruleFor[eqnList][z] === {y :> z x, f[x] :> z + x} Out[36]= True In[37]:= hruleFor[eqnList][x][z] === {y_ :> b z, f[z] :> c + z} Out[37]= True In[38]:= bruleReverseFor[x == y] === (y :> x) Out[38]= True In[39]:= bruleReverseFor[eqnList] === {b x :> y, c + x :> f[x]} Out[39]= True In[40]:= eqn[1] = a x + b y == c z; In[41]:= brule[1] === (a x + b y :> c z) Out[41]= True In[42]:= grule[1] === ((a_) (x_) + (b_) (y_) :> c z) Out[42]= True In[43]:= crule[1][w] === (w x + b y :> c z) Out[43]= True In[44]:= crule[1][u, v] === (u x + v y :> c z) Out[44]= True In[45]:= crule[1][, s] === (a x + s y :> c z) Out[45]= True In[46]:= crule[1][,,s] === (a x + b y :> s z) Out[46]= True In[47]:= Clear[x, y, z, xx, yy, u, v, w, s, x1, x2, x3, x4, x5] In[48]:= e2 = (f[x, y, z] == If[xx == yy, a[x, y] + (x^2*b[z])/y]); In[49]:= bruleFor[e2] === (f[x, y, z] :> If[xx == yy, a[x, y] + (x^2*b[z])/y]) Out[49]= True In[50]:= gruleFor[e2] === (f[x_, y_, z_] :> If[xx == yy, a[x, y] + (x^2*b[z])/y]) Out[50]= True In[51]:= cruleFor[e2][w] === (f[w, y, z] :> If[xx == yy, a[w, y] + (w^2*b[z])/y]) Out[51]= True In[52]:= cruleFor[e2][u, v] === (f[u, y, z] :> If[v == yy, a[u, y] + (u^2*b[z])/y]) Out[52]= True In[53]:= cruleFor[e2][, s] === (f[x, y, z] :> If[s == yy, a[x, y] + (x^2*b[z])/y]) Out[53]= True In[54]:= cruleFor[e2][x1, x2, x3] === (f[x1, x3, z] :> If[x2 == yy, a[x1, x3] + (x1^2*b[z])/x3]) Out[54]= True In[55]:= cruleFor[e2][x1, x2, x3, x4, x5] === (f[x1, x3, x5] :> If[x2 == x4, a[x1, x3] + (x1^2*b[x5])/x3]) Out[55]= True In[56]:= eqn[legendre, all] = P[n, x] == Which[n == 0, 1, n == 1, x, n >= 2, (2n-1)/n x P[n-1, x] - (n-1)/n P[n-2, x]]; In[57]:= known[P[5, x]] = (15*x - 70*x^3 + 63*x^5)/8; In[58]:= (P[5, x] // FixedPoint[Composition[Together, # /. grule[legendre, all]&], #]&) === known[P[5, x]] Out[58]= True In[59]:= (P[5, x] // inSuccession[ inSuccession[grule[legendre, all], Together]^totally]) === known[P[5, x]] Out[59]= True In[60]:= Clear[a, b, c]; In[61]:= e3 = a == If[b, c]; In[62]:= (a^2 /. bruleFor[e3]) === If[b, c]^2 Out[62]= True In[63]:= b = True; In[64]:= (a^2 /. bruleFor[e3]) === c^2 Out[64]= True In[65]:= b =. In[66]:= (a^2 /. bruleFor[e3]) === If[b, c]^2 Out[66]= True In[67]:= (* grule just with True clause *) In[68]:= Clear[e4, f, b, x, z] In[69]:= e4 = f[x] == If[b, x^2]; In[70]:= (f[z] /. gruleFor[e4]) === If[b, z^2] Out[70]= True In[71]:= b = True; In[72]:= (f[z] /. gruleFor[e4]) === z^2 Out[72]= True In[73]:= b =. In[74]:= (f[z] /. gruleFor[e4]) === If[b, z^2] Out[74]= True In[75]:= (* grule with True and False clauses *) In[76]:= Clear[e5, f, b, x, z] In[77]:= e5 = f[x] == If[b, x^2, x^3]; In[78]:= b = True; In[79]:= (f[z] /. gruleFor[e5]) === z^2 Out[79]= True In[80]:= b = False; In[81]:= (f[z] /. gruleFor[e5]) === z^3 Out[81]= True In[82]:= b = . In[83]:= (f[z] /. gruleFor[e5]) === If[b, z^2, z^3] Out[83]= True In[84]:= (* HOWEVER, when maybe clause included doesn't work *) In[85]:= Clear[e6, f, b, x, z] In[86]:= e6 = f[x] == If[b, x^2, x^3, x^4]; In[87]:= b = True; In[88]:= (f[z] /. gruleFor[e6]) === z^4 (* WHICH IS BAD *) Out[88]= True In[89]:= (* condition as variable *) In[90]:= Clear[e7, f, b, x] In[91]:= e7 = f[b, x] == If[b, x^2, x^3]; In[92]:= (f[True, z] /. gruleFor[e7]) === z^2 Out[92]= True In[93]:= (f[False, z] /. gruleFor[e7]) === z^3 Out[93]= True In[94]:= (f[, z] /. gruleFor[e7]) === If[Null, z^2, z^3] Out[94]= True In[95]:= (* HOWEVER, when maybe clause included doesn't work *) In[96]:= Clear[e8, f, b, x, z] In[97]:= e8 = f[b, x] == If[b, x^2, x^3, x^4]; In[98]:= (f[True, z] /. gruleFor[e8]) === z^4 (* WHICH IS BAD *) Out[98]= True In[99]:= (* using Which works *) In[100]:= eqn[legendre] = P[n, x] == Which[n==0, 1, n==1, x, n>1, -(((-1 + n)*P[-2 + n, x])/n) + ((-1 + 2*n)*x*P[-1 + n, x])/n]; In[101]:= ((P[4, z] //. grule[legendre]) ~ Collect ~ z) === 3/8 - (15*z^2)/4 + (35*z^4)/8 Out[101]= True In[102]:= (* using Switch does not *) In[103]:= eqn[legendre, bad] = P[n, x] == Switch[n, 0, 1, 1, x, _, -(((-1 + n)*P[-2 + n, x])/n) + ((-1 + 2*n)*x*P[-1 + n, x])/n]; In[104]:= Off[Power::infy, Infinity::indet] In[105]:= (P[0, z] /. grule[legendre, bad]) === Indeterminate Out[105]= True In[106]:= On[Power::infy, Infinity::indet] In[107]:= (h[i][c + d] // restrictedListOfVariables) === {c, d} Out[107]= True In[108]:= (h[i][c + d] // extendedListOfVariables) === {c, d, h, i} Out[108]= True In[109]:= (* ========================================================= *) In[110]:= (* *) In[111]:= opc = Identity; In[112]:= {Length[checkList], Union[checkList], Plus @@ checkList} Out[112]= {110, {Null, True}, 50*Null + 60*True} In[113]:= Complement[Range[Length[checkList]], Position[checkList, #, 1]& /@ {True, Null, shown} // Flatten] Out[113]= {} In[114]:= localList[localName] = checkList;