sursumCorda

922 Reputation

13 Badges

2 years, 208 days

MaplePrimes Activity


These are questions asked by sursumCorda

That is to say, a generalized map
E.g., here is a nested list: 

nl := [[[[s, t]], [u, [v, w]]], [[x, [y, z]]]]:

We can use map to apply the mapped function F to "each operand" (i.e., the first‐level parts) of : 

:-map(F, nl);
 = 
         [F([[[s, t]], [u, [v, w]]]), F([[x, [y, z]]])]

But in Mathematica, we can make further explorations: 

In[1]:= nl = {{{{s, t}}, {u, {v, w}}}, {{x, {y, z}}}}; 

In[2]:= Map[F, nl, {1}] (*Maple's result*)

Out[2]= {F[{{{s, t}}, {u, {v, w}}}], F[{{x, {y, z}}}]}

In[3]:= Map[F, nl, {2, -2}]

Out[3]= {{F[{F[{s, t}]}], F[{u, F[{v, w}]}]}, {F[{x, F[{y, z}]}]}}

In[4]:= Map[F, nl, {-3, 3}]

Out[4]= {{F[{F[{s, t}]}], F[{F[u], F[{v, w}]}]}, {F[{F[x], F[{y, z}]}]}}

In[5]:= Map[F, nl, {0, \[Infinity]}, Heads -> \[Not] True]

Out[5]= F[{F[{F[{F[{F[s], F[t]}]}], F[{F[u], F[{F[v], F[w]}]}]}], F[{F[{F[x], F[{F[y], F[z]}]}]}]}]

Note that the last case has been implemented in Maple as MmaTranslator[Mma][MapAll]:  

MmaTranslator:-Mma:-MapAll(F,nl);
 = 
   F([F([F([F([F(s), F(t)])]), F([F(u), F([F(v), F(w)])])]), 

     F([F([F(x), F([F(y), F(z)])])])])

Naturally, how to reproduce the other two results in Maple programmatically? (The output may not be easy to read or understand; I have added an addendum below.)

Addendum. It is also possible to display in "tree" structure (like dismantle) manually: 

`[]`
(
    `[]`
    (
        `[]`
        (
            `[]`
            (
                s
            ,
                t
            )
        )
    ,
        `[]`
        (
            u
        ,
            `[]`
            (
                v
            ,
                w
            )
        )
    )
,
    `[]`
    (
        `[]`
        (
            x
        ,
            `[]`
            (
                y
            ,
                z
            )
        )
    )
)

As you can see, the "depth" of  is five (0, 1, 2, 3, and 4), while the classical map just maps at the first "level". (Moreover, such descriptions may lead to a confusion.)

Supplement. Unfortunately, there remains a bug in the MmaTranslator[Mma][Level]. Compare: 

MmaTranslator:-Mma:-Level(nl, [4]); (*Maple*)
                             [v, w]

MmaTranslator:-Mma:-Level(nl, [-1]); (*Maple*)
          [s, t, u, v, w, x, y, z, -1, x, c, r, y, 2]

In[6]:= Level[nl, {4}] (*Mathematica*)

Out[6]= {s, t, v, w, y, z}

In[7]:= Level[nl, {-1}] (*Mathematica*)

Out[7]= {s, t, u, v, w, x, y, z}

For instance, here is a list of valid "rules" (given as equations): 

(* restart; *)
rules := [g = d, e = a, a = b, f = d, c = g, b = b, d = c, c = f, a = e]:

But these rules can be represented more compactly as a list of "cycles": 

cycles := [[g, d, c], [e, a], [f, d, c], [b]]:

Is there a efficient way to convert into ? 

Let a, b be arbitrary real parameters. I intend to compute something like: (with exact piecewise output) 

Optimization:-Maximize(8*x + 7*y, {5*y <= 6 - 9*b, -6*x - 4*y <= 8 - 5*a - 7*b, -4*x + 7*y <= -1 - 2*a - 7*b, -x + y <= 6 + 4*a - 5*b, 7*x + 5*y <= a + 4*b}, variables = {x, y}): # Error
Optimization:-Minimize((x - 1)^2 + (2*y - 1)^2, {x - 2*y <= 2*a - b + 1, x + 2*y <= a + b, 2*x - y <= a - b + 1}, variables = {x, y}): # Error

Unfortunately, these Maple codes are virtually invalid, and the relevant commands minimize, maximize, extrema, and Student[MultivariateCalculus][LagrangeMultipliers] do not support general inequality constraints. Is it possible to tackle these small-scale constrained parametric problems in Maple?

For instance, I'd like to find the integer solutions of the following system (unknowns: k[1], k[2], k[3], k[4], k[5], and k[6]): 

eqs:=eval~(k[1]*x^3+k[2]*x^2*y+k[5]*x^2*z+k[3]*x*y^2+k[6]*x*y*z+k[8]*x*z^2+k[4]*y^3+k[7]*y^2*z+k[9]*y*z^2+k[10]*z^3,{{x=1,y=1,z=1},{x=RootOf(_Z^3-4*_Z^2+_Z+1,index=1),y=RootOf(_Z^3-4*_Z^2+_Z+1,index=2),z=RootOf(_Z^3-4*_Z^2+_Z+1,index=3)},{x=RootOf(_Z^3-4*_Z^2+_Z+1,index=2),y=RootOf(_Z^3-4*_Z^2+_Z+1,index=3),z=RootOf(_Z^3-4*_Z^2+_Z+1,index=1)},{x=RootOf(_Z^3-4*_Z^2+_Z+1,index=3),y=RootOf(_Z^3-4*_Z^2+_Z+1,index=1),z=RootOf(_Z^3-4*_Z^2+_Z+1,index=2)}}):
{isolve}(eqs=~0);

It seems that the isolve command cannot solve such a system of linear equations, but its integer solutions do exist: 

sol := [k[1] = _Z1, k[2] = _Z2, k[3] = _Z3, k[4] = _Z4, k[5] = _Z5, k[6] = _Z1 + 2*_Z3 + 2*_Z4 + _Z5 + 3*_Z6, k[7] = 2*_Z1 + _Z3 + 8*_Z4 - _Z6, k[8] = -21*_Z1 + 2*_Z2 - _Z4 - 4*_Z5 + _Z6, k[9] = 24*_Z1 - 4*_Z2 - 5*_Z3 - 12*_Z4 + 3*_Z5 - 4*_Z6, k[10] = -7*_Z1 + _Z2 + _Z3 + 2*_Z4 - _Z5 + _Z6]: (*results from Mathematica*)
evala(subs(sol, eqs));
 = 
                              {0}

Here _Z1, _Z2, _Z3, _Z4, _Z5, and _Z6 are integer parameters. However, how do I get this result in Maple?

[I split this off from here into a separate question. dharr]

@dharr Thanks. For the second one, an output is . Is it possible to compel Maple to attempt to simplify the second algebraic number to a less complicated expression automatically? 
Its minimal polynomial can be computed. However, this is not so convenient for the specific purpose. Actually, I want something like this: 

evalA(-4*RootOf(_Z^3 - 3*_Z^2 - 10*_Z - 1)^2 + 19*RootOf(_Z^3 - 3*_Z^2 - 10*_Z - 1) + 3);
 = 
                       /  3        2           \
               5 RootOf\_Z  + 10 _Z  + 3 _Z - 1/

Mathematica has an additional function RootReduce to do so directly, but I cannot find such functionality in Maple.

Remark. A fairly complicated one: 

evalA(-45658*RootOf(37*_Z^6 - 382*_Z^5 + 1388*_Z^4 - 2188*_Z^3 + 1475*_Z^2 - 406*_Z + 37, index = 6)^5 + 417257*RootOf(37*_Z^6 - 382*_Z^5 + 1388*_Z^4 - 2188*_Z^3 + 1475*_Z^2 - 406*_Z + 37, index = 6)^4 - 1252087*RootOf(37*_Z^6 - 382*_Z^5 + 1388*_Z^4 - 2188*_Z^3 + 1475*_Z^2 - 406*_Z + 37, index = 6)^3 + 1463384*RootOf(37*_Z^6 - 382*_Z^5 + 1388*_Z^4 - 2188*_Z^3 + 1475*_Z^2 - 406*_Z + 37, index = 6)^2 - 558475*RootOf(37*_Z^6 - 382*_Z^5 + 1388*_Z^4 - 2188*_Z^3 + 1475*_Z^2 - 406*_Z + 37, index = 6) + 69230);
 = 
            /
17991 RootOf\

       6         5          4          3          2                
  37 _Z  - 406 _Z  + 1475 _Z  - 2188 _Z  + 1388 _Z  - 382 _Z + 37, 

           \
  index = 4/


 

First 14 15 16 17 18 19 Page 16 of 19