sursumCorda

1109 Reputation

13 Badges

2 years, 8 days

MaplePrimes Activity


These are questions asked by sursumCorda

I would like to simulate the evolution of the so-called B, C, K, W system and SKI combinator calculus in Maple.
The rewrite rules of them are simple: 

S(x)(y)(z)=x(z)(y(z))
K(x)(y)=x, and 
I(x)=x. (Note that since  is protected, I shall use  hereafter.)

However, if I try to evaluate the following example given in the  article, 

Maple will only return an unchanged result: 

restart;
applyrule([cS(x::anything)(y::anything)(z::anything) = x(z)(y(z)), 
   cK(x::anything)(y::anything) = x, cI(x::anything) = x], 
  cS(cK(cS(cI)))(cS(cK(cK))(cI))(x)(y)); # Unable to reduce??? 
 = 
              cS(cK(cS(cI)))(cS(cK(cK))(cI))(x)(y)

I believe that this is not an outlier.
Here are two additional instances: 

> rls := [cS(x::anything)(y::anything)(z::anything) = x(z)(y(z)), cK(x::anything)(y::anything) = x]:
> map2(applyrule, rls, [cS(cS(cS)(cS))(cS)(cS(cS))(cK), cS(cS(cS))(cS)(cS)(cS)(cS(cS)(cK(cK)))]);
                       [cS(cS(cS)(cS))(cS)(cS(cS))(cK), cS(cS(cS))(cS)(cS)(cS)(cS(cS)(cK(cK)))]

>

So why can't `applyrule` apply rules as desired? Meanwhile, how to automatically and thoroughly (like :-eval['recurse'] or MmaTranslator:-Mma:-ReplaceRepeated) apply those transformation rules to 

  1. , and

I have read something like How to apply a recursive rule in an expression? - MaplePrimes, but they are not the same issue.

According to the documentation of MmaTranslator:-Mma:-PolynomialReduce, this command yields . However, 

restart;
MmaTranslator:-Mma:-PolynomialReduce(x**2+y**2,{x-y,y+a});
 = 
                       [         2    2]
                       [[0, 0], x  + y ]

In[1]:= PolynomialReduce[x^2+y^2,{x-y,y+a}](*Mathematica*)

Out[1]= {{x + y, -2 a + 2 y}, 2 a^2}

In SymPy and in MuPAD: 

The output of both is the same as that of Mma; only the result given by Maple is inconsistent with Mathematica's. 

The example above is so simple that the desired result can be found simply by hand. Here is a larger example: 
Given two polynomials .txt and .txt, as well as a list of polynomials .txt, I would like to evaluate 

# Suppose that one has downloaded these three files. 
poly1, poly2 := fscanf("poly1.txt", "%a")[], fscanf("poly2.txt", "%a")[]:
pList := MmaTranslator:-Mma:-ReadList("pList.txt"):
MmaTranslator:-Mma:-PolynomialReduce((a - poly1)*(a - poly2), pList);

 But its result is just “[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]”, while when a=0 it should be “[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 0, 0, 0, 1, 2, 1, 0, 2, 2, 3, 1, 1, 1, 2, 1, 0, 0, 0, 1, 1, 2, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0], 0]”.
So why does  return a distinct value?

In an old question, @mbras asked for a "partial" `convert/elsymfun`. However, SymPy's sympy.polys.rings.PolyElement.symmetrize seems to provide more examples that cannot be handled by the program that appeared in that question.
For instance, 

>>> from sympy import var
>>> var('x:z,p:r')
(x, y, z, p, q, r)
>>> from sympy.polys.polyfuncs import symmetrize
>>> symmetrize(x**2-(y**2+2**z),[y,x],formal=True,symbols=[p+p,q*q])[0]
-2**z - 4*p**2 + 2*q**2
>>> symmetrize(x*x*y+y*y*z+z*z*x,[y,x,z],formal=True,symbols=[p,q,r])
(0, x**2*y + x*z**2 + y**2*z, [(p, x + y + z), (q, x*y + x*z + y*z), (r, x*y*z)])

Though I can , can't the built-in  be generalized to such expressions (in other words, write the polynomial part of input as a symmetric part and a remainder with (named, if need be) elementary symmetric polynomials)?

Besides, since any symmetric polynomial can also be expressed in terms of the complete symmetric polynomials, is there a similar  command in Maple?

Why does _EnvLinalg95 only affect  (and ) and not and ? 
 

restart;

m := <3 , 4 | 4 , 3>;

m := Matrix(2, 2, {(1, 1) = 3, (1, 2) = 4, (2, 1) = 4, (2, 2) = 3})

(1)

LinearAlgebra:-Eigenvalues(m);

Vector(2, {(1) = 7, (2) = -1})

(2)

LinearAlgebra:-Eigenvectors(m);

Vector(2, {(1) = -1, (2) = 7}), Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

(3)

LinearAlgebra:-EigenConditionNumbers(m);

Vector(2, {(1) = 1.00000000000000, (2) = 1.00000000000000}), Vector(2, {(1) = 8., (2) = 8.})

(4)

_EnvLinalg95 := true:

whattype(m);

Matrix

(5)

LinearAlgebra:-Eigenvalues(m);

Vector(2, {(1) = 7, (2) = -1})

(6)

LinearAlgebra:-Eigenvectors(m):

Error, (in Matrix) invalid input: `Matrix/MakeInit` expects its 1st argument, initializer, to be of type list(list), but received [proc (i, j) options operator, arrow; `if`(j = 1 and i <= 2, (Vector(2, {(1) = 1, (2) = 1}))[i], rhs(fill_opt)) end proc]

 

LinearAlgebra:-EigenConditionNumbers(m);

Vector(2, {(1) = 1.00000000000000, (2) = 1.00000000000000}), Vector(2, {(1) = 8., (2) = 8.})

(7)

_EnvLinalg95 := false:

LinearAlgebra:-Eigenvectors(m);

Vector(2, {(1) = -1, (2) = 7}), Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

(8)


 

Download _EnvLinalg95.mw

I have read the help page of Eigenvectors but couldn't find anything related.

There seems to be a consensus about using ListTools:-SearchAll to locate an item in a list. However, this subroutine does not work on other expressions; A simple instance is that “ListTools:-SearchAll(1, [[1], 1]);” only outputs  while what I need is  (because both “op([1, 1], [[1], 1])” and “op([2], [[1], 1])” are ). And actually, I hope that there is a more general version in Maple.
For example, I intend to do something like 

restart;
expr, elem := ToInert(eval(`print/Diff`)), '_Inert_NAME'("_syslib"):
SearchAll(elem, expr);

and 

List:=[[[[cS,[[[cS,cS],cS],[[[cS,cS],[[cK,cK],cS]],cS]]],cS],cS],[[[cS,[[cK,cS],cK]],cK],cS]]: 
items:=Or([[[identical(cS),anything],anything],anything],[[identical(cK),anything],anything]): 
SearchAll(items,List); 

In other words, I need all positions of an operand of an expression (cf. op).

It may be manually checked that the "indices" of  in  include [5,1,1,2,1,1,1,2,1,2,1,2], [5,1,2,2,1,1,1,1,2,1,2], and [5,2,2,1,1,3,1,2], since 

patmatch(op([5, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2], expr), elem);
 = 
                              true

patmatch(op([5, 1, 2, 2, 1, 1, 1, 1, 2, 1, 2], expr), elem);
 = 
                              true

patmatch(op([5, 2, 2, 1, 1, 3, 1, 2], expr), elem);
 = 
                              true

Similarly, after some manual searchs, 

[[1], [1, 1, 1, 2], [1, 1, 1, 2, 2], [1, 1, 1, 2, 2, 1, 2], [2], [2, 1, 1, 2]]:
convert(typematch~(map2(`?[]`, List, `%`), items), `and`);
 = 
                              true

It turns out that all "indices" in  of  are [1][1,1,1,2][1,1,1,2,2][1,1,1,2,2,1,2][2], and [2,1,1,2].
But isn't there such a  command that can eliminate the need to manually retrieve them?

5 6 7 8 9 10 11 Last Page 7 of 22