acer

32385 Reputation

29 Badges

19 years, 334 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

It sounds as if you might be looking for the functionality provided by subsindets (or evalindets). Those allow you to act on all subexpressions of a particular type.

Notice the similarity between commands indets and subsindets. You could see their respective help-pages.

Here are two made-up examples, since you didn't provide one explicitly. I may have guessed wrong as you your specific goals. It'd be better if you provided actual examples.

There are often several ways to target a flavour of subexpression. (I might have used divide instead of all that member action, in the latter example. The choice between them could depend on whether you want to match exactly `a`  as a multiplicand in the exponent, or `a` as a factor.)

The first example involves exp calls, and the second involves calls to `^`.

restart;

expr := Int(a*b*exp(a*c)*Int(exp(a*b*s)+exp(s+t+b),b),a);

Int(a*b*exp(a*c)*(Int(exp(a*b*s)+exp(s+t+b), b)), a)

# pick off terms like exp(someproduct)
# where someproduct is a product with `a`
# as a factor.

indets(expr, specfunc(And(`*`,satisfies(u->divide(u,a))),exp));

{exp(a*c), exp(a*b*s)}

# The same, but both `a` and `b` must be factors
# in the exponent.

indets(expr, specfunc(And(`*`,satisfies(u->divide(u,a*b))),exp));

{exp(a*b*s)}

# A similar command, but now applying `F` to the term.

subsindets(expr, specfunc(And(`*`,satisfies(u->divide(u,a*b))),exp),
           F);

Int(a*b*exp(a*c)*(Int(F(exp(a*b*s))+exp(s+t+b), b)), a)

# Now applying `G` to the exponent of the term.

subsindets(expr, specfunc(And(`*`,satisfies(u->divide(u,a*b))),exp),
           u->exp(G(op(u))));

Int(a*b*exp(a*c)*(Int(exp(G(a*b*s))+exp(s+t+b), b)), a)

# Now applying a specific substitution to the
# exponent, replacing a*b with AB.

subsindets(expr, specfunc(And(`*`,satisfies(u->divide(u,a*b))),exp),
           u->exp(algsubs(a*b=AB,op(u))));

Int(a*b*exp(a*c)*(Int(exp(s*AB)+exp(s+t+b), b)), a)

Download subsindets_example2.mw

 

restart;

expr := Int(a*b*p^(a*c)*Int(w^(a*b*s)+w^(s*t*b),b),a);

Int(a*b*p^(a*c)*(Int(w^(a*b*s)+w^(s*t*b), b)), a)

# pick off terms like w^someproduct
# where someproduct is a product with `a`
# as a multiplicand.

indets(expr, identical(w)^And(`*`,satisfies(u->member(a,[op(u)]))));

{w^(a*b*s)}

# pick off terms like anything^someproduct
# where someproduct is a product with `a`
# as a multiplicand.

indets(expr, And(`^`,satisfies(u->member(a,[op([2,..],u)]))));

{p^(a*c), w^(a*b*s)}

# The same, but both `a` and `b` must be multiplicands
# in the exponent.

indets(expr, And(`^`,satisfies(u->member(a,[op([2,..],u)])
                                  and member(b,[op([2,..],u)]))));

{w^(a*b*s)}

# A similar command, but now applying `F` to the term.

subsindets(expr, And(`^`,satisfies(u->member(a,[op([2,..],u)])
                                      and member(b,[op([2,..],u)]))),
           F);

Int(a*b*p^(a*c)*(Int(F(w^(a*b*s))+w^(s*t*b), b)), a)

# Now applying `G` to the exponent of the term.

subsindets(expr, And(`^`,satisfies(u->member(a,[op([2,..],u)])
                                      and member(b,[op([2,..],u)]))),
           u->op(1,u)^G(op(2,u)));

Int(a*b*p^(a*c)*(Int(w^G(a*b*s)+w^(s*t*b), b)), a)

# Now applying a specific substitution to the
# exponent, replacing a*b with AB.

subsindets(expr, And(`^`,satisfies(u->member(a,[op([2,..],u)])
                                      and member(b,[op([2,..],u)]))),
           u->op(1,u)^algsubs(a*b=AB,op(2,u)));

Int(a*b*p^(a*c)*(Int(w^(s*AB)+w^(s*t*b), b)), a)

# There are many ways to do that same thing,
# and sometimes there will be a simpler variant.
# In this case `algsubs` acts only on the exponents
# with a*b as a compound multiplicand.

subsindets(expr, `^`, u->op(1,u)^algsubs(a*b=AB,op(2,u)));

Int(a*b*p^(a*c)*(Int(w^(s*AB)+w^(s*t*b), b)), a)

 

Download subsindets_example.mw

The evalb command is suitable for testing that two equations have the same structure (somewhat akin to being literally the same), but it is not intended for an check of mathematical/algebraic equivalence.

Many examples that arise in practice can be checked by this more suitable test,

   is( eqn1-eqn2 = 0 );

which is slightly more robust than,

   is( eqn1 = eqn2 );

Note also that you can put assumptions on that call, eg,

   is( eqn1-eqn2 = 0 ) assumming x>0, a::real, t::real;

or what have you.

There are a few very rare instance where the extra kick from,

   is( simplify(eqn1-eqn2) = 0 );

is necessary.

Is it the case that you only want assertion-checking on some of your own procedures? If so then you might temporarily turn it off during the key Library calls in your try..catch. For example,

restart;

interface(warnlevel=4):
kernelopts('assertlevel'=2):

try
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;

   old:=kernelopts('assertlevel'=0);
   solve(identity(eq,x),trial_solution_constants);
catch:
   print("error happend ",lastexception);
finally
   kernelopts('assertlevel'=old):
end try;
print(" I am here");

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

2

"error happend ", unknown, "numeric exception: division by zero"

0

" I am here"

Download AL1.mw

Or perhaps it is the case that you want assertion-checking only for enforcing the local or return types of certain procedures (ie, not the ASSERT calls)? In that case perhaps you could temporarily disable just those. For example (and, you don't need to put it all inside the try..catch).

restart;

interface(warnlevel=4):
kernelopts('assertlevel'=2):

try
   unprotect('ASSERT'):ASSERT:=NULL:protect('ASSERT');
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
   solve(identity(eq,x),trial_solution_constants)
catch:
   print("error happend ",lastexception);
finally
   unprotect('ASSERT'):ASSERT:='ASSERT';protect('ASSERT');
end try;
print(" I am here");

"ASSERT := "

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

"error happend ", unknown, "numeric exception: division by zero"

ASSERT

" I am here"

Download AL2.mw

If you have some more complicated scenerio or usage then you really ought to adequately describe it. Your brief statement, "But I need to use kernelopts('assertlevel'=2): in my program" doesn't explain how you need to use it.

As to why that behaviour happened, consider where the assertion-check fails in your example. It happens in line 82 of Maple 2021.2's routine, SolveTools:-Transformers:-Identity:-Apply. And if coeff(dz1,sol) is +-infinity then line 83 gets that raised exception. You write as if the former assertion-failure prevents the ensuing numeric exception is some very special way. But it only prevents it because it fails first.

showstat(((SolveTools::Transformers)::Identity)::Apply,82..83);

Apply := proc(syst::SubSystem)
local SS, news, af, repeat, sys, eqns, ineqs, vars, z, ind, inds, inds1, inds2, z1,
ineqs2, ip, z3, w, i, v, sol, nopush, r2, dz1, newsystem, savesystem, pts, 
  aeqns, beqns, t, onlylin, x, r3, di, e, subsys, recsols;
       ...
  82                   ASSERT(degree(dz1,sol) = 1);
  83                   dz1 := normal(-coeff(dz1,sol,0)/coeff(dz1,sol));
       ...
end proc

There are a few fancier variations on the following idea of temporarily substituting the target term with a dummy (using algsubs, or subs, etc, as appropriate).

restart;

Iso := proc(ee,t) local s;
       subs(s=t,isolate(algsubs(t=s,ee),s));
end proc:

 

eq:=P=A+(z+x/2/z);

P = A+z+(1/2)*x/z

Iso( eq, z+x/2/z );

z+(1/2)*x/z = P-A

Download isolate_alg.mw

The approaches in other Answers (shown so far) involve more ad hoc manipulations involving key subexpressions and their location, ie. more specific to the particular form of the given example. This makes them less general-purpose -- without problem-specific (manual) assistance.

The OP has alluded to a longer, as yet unseen, example. It would be much better to provide that up front, to alleviate hit-and-miss guessing as to technique.

I cannot tell whether you want the exact results better simplified (but still in terms of exact radicals) or as floating-point approximations.

restart;

f := 9*x^3 - 7*x^2*y + 8*x*y^2 - 6*y^3 + 3*x^2 - 3*x*y + 4*y^2 - 3*x + 9*y - 7:
fx:=diff(f,x):
fy:= diff(f,y):

ctpts:= simplify(evala([solve({fx=0,fy=0},{x,y},explicit)])):

length~(ctpts);
                    [3946, 3946, 3916, 3916]

sort(evalf(ctpts));
          [{x = -0.2777746987, y = -0.6265224303}, 

            {x = -0.1196978963, y = -0.5678259685}, {

            x = 0.04295586208 - 0.2689937611 I, 

            y = 0.9924517216 - 0.1221355627 I}, {

            x = 0.04295586208 + 0.2689937611 I, 

            y = 0.9924517216 + 0.1221355627 I}]

There is a Units:-Simple package, which rebinds several commands and allows this kind of comparison to resolve. (Most of Maple doesn't otherwise know much about units.)

restart

with(Units:-Simple)NULL``

NULL

Problem 1 ( If Statement with units)

 

The if statement could not evealuated with the logical operator < or > when a unit is attached to the value

 

tt := 80*Unit('knot'); if tt < 100*Unit('knot') then lprint(got*it) end if

got*it

NULL

Download Problem_IF_ac.mw

By the way, there is no command Restart with a capital "R". The command is restart, all lowercase.

Inside main's catch clause the callstack is no longer what it was when the original exception was thrown.

You can access the procedure name, using lastexception[1]. For example,

restart;

A := module()  
  local B:=module()
     export foo:=proc(n)
         1/n;
     end proc;
  end module;

  export main:=proc()
    try
       B:-foo(0);
    catch:
      print(sprintf("error happened in %a: %s",
            lastexception[1],
            StringTools:-FormatMessage(lastexception[2..-1])));
    end try;
  end proc;

end module:

A:-main()

"error happened in foo: numeric exception: division by zero"

Download try_loc.mw

If your procedures/modules are being accessed from a Library archive into which they were saved (and if the source exists so that line-number information can be used) then you may be able to access that source via lasterrorlocus and showsource. (See the Description of the Help page for topic error.)

For example, I have a file "foo.mpl" with the following plaintext Maple code in it:

A := module()  
  local B:=module()
     export foo:=proc(n)
         1/n;
     end proc;
  end module;
  export main:=proc()
    try
       B:-foo(0);
    catch:
      if lasterrorlocus<>'lasterrorlocus' then
         print(lasterrorlocus);
         showsource();
      end if; 
      print(sprintf("error happened in %a: %s",
            lastexception[1],
            StringTools:-FormatMessage(lastexception[2..-1])));
    end try;
  end proc;
end module:

I can then load that into a .mla Library archive file, and access the relevent souce upon catching an error. For example:

restart;

LB:=cat(currentdir(),"/nm.mla"):
read "foo.mpl";
if FileTools:-Exists(LB) then
  FileTools:-Remove(LB);
end if;
LibraryTools:-Create(LB);
LibraryTools:-Save(A,LB);

restart;

libname := libname,cat(currentdir(),"/nm.mla"):

A:-main()

["foo.mpl", 4, false]

"error happened in A:-main: numeric exception: division by zero"


--- foo.mpl -------------------------------------------------------------------
1  A := module()  
2    local B:=module()
3       export foo:=proc(n)
4!          1/n;
5       end proc;
6    end module;
7  
8    export main:=proc()
9      try

 

Download try_locb.mw

I'll note that the lastexception[1] shows as A:-main in that last example, while more usefully it shows foo in the first example. But the point of the second example is mostly about printing the source snippet with error location indicated.

If you want the result from calling komb to include indexed names then you could form then as such.

Your approach of concatenating produces names that pretty-print with subscripts but are not indexed names.

There are two kinds of name that pretty-print with subscripts:
1) indexed names like a[2,2] for which the subscripts pretty-print in upright Roman characters.
2) special names with double-underscore like say `a__2,2` for which the subscript pretty-prints in italic characters.
These two kinds of name might appear similar, except for the italic aspect and that is easy to overlook. But they are quite distinct from each other (ie. will not cancel upon subtraction).

That approach of concatenation will produce global names. If you want the result from komb to not have escaped local (indexed) names then you can pass in the base-symbol as an additional argument (instead of declaring that base-symbol as local). Below, I do this by having var be an additional parameter of the procedure komb, so that the base-symbol (eg. a) can be passed in. The effect is that the results from komb have the same kind of global name a as are in the Matrix A.

NULL

restart

komb := proc (n::integer, m::integer, var::symbol) local L, j; L := [seq(var[j, j], j = 1 .. n)]; add(mul(k), `in`(k, combinat:-choose(L, m))); return % end proc

komb(5, 5, a)

a[1, 1]*a[2, 2]*a[3, 3]*a[4, 4]*a[5, 5]

lprint(komb(5, 5, a))

a[1,1]*a[2,2]*a[3,3]*a[4,4]*a[5,5]

A := Matrix(5, 5, shape = diagonal, symbol = a)

Matrix(%id = 36893628247904552828)

abs(A)

a[1, 1]*a[2, 2]*a[3, 3]*a[4, 4]*a[5, 5]

lprint(abs(A))

a[1,1]*a[2,2]*a[3,3]*a[4,4]*a[5,5]

simplify(komb(5, 5, a)-abs(A))

0

NULL

Download indexed_ac.mw

The colored portions shown by sparsematrixplot are filled polygons, not symbols, ie. it's not a point-plot, which is why passing the symbol option doesn't work for you.

Here's another approach:

restart;

plots:-setoptions(size=[500,500]):

kernelopts(version);

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

H := proc(M::Matrix) local i,m,n,L,V;
  uses LA=LinearAlgebra, IT=ImageTools, P=plots;
  (m,n):=LA:-Dimensions(M):
  (L,V):=((u->[lhs(u)[2],m-lhs(u)[1]+1])~,rhs~)([rtable_elems(M)[]]):
  P:-pointplot(L, style=point, symbol=cross, symbolsize=50,
               color=COLOR(HUE,0.75*IT:-FitIntensity(Array(1..nops(V),1..1,V,
                                                           datatype=float[8]))),
               axis[1]=[tickmarks=[seq(floor(i)=floor(i), i=1..n, (n-1)/4)]],
               axis[2]=[tickmarks=[seq(floor(i)=floor(m-i+1), i=1..m, (m-1)/4)]],
               axes=box, view=[0.5..n+0.5,0.5..m+0.5],
               labels=["column","row"], labeldirections=[horizontal,vertical],
               scaling=constrained, _rest);
end proc:

 

A := Matrix([[2, 1, 0, 0, 3],[0, 2, 1, 0, 0],
             [0, 0, 2, 1, 0],[0, 0, 0, 2, 1],[0, 0, 0, 0, 2]]);

A := Matrix(5, 5, {(1, 1) = 2, (1, 2) = 1, (1, 3) = 0, (1, 4) = 0, (1, 5) = 3, (2, 1) = 0, (2, 2) = 2, (2, 3) = 1, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 2, (3, 4) = 1, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 2, (4, 5) = 1, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 2})

plots:-sparsematrixplot(A, matrixview, color = "Red", scaling=constrained);

H(A);

B := LinearAlgebra:-RandomMatrix(40,80,generator=0..10,density=0.2):

plots:-sparsematrixplot(B, matrixview, color = "Red", scaling=constrained);

H(B, symbolsize=8);

H(B, symbolsize=8, symbol=solidbox);

 

Download sparse_mat_plot3.mw

Another example:

A := Matrix(100,(i,j)->sin(Pi*(i+j)/20)) *~
     LinearAlgebra:-RandomMatrix(100, generator=1..1,
                                 density=0.1):

H(A, symbolsize=6, symbol=soliddiamond,
  background="#777777", size=[500,500]);

If you do decide that you want just filled polygons rather than symbols -- but colored according to value -- then another approach would be to use the Statistics:-HeatMap command, optionally with a colorscheme option.

It wasn't clear whether you were going to deal with other, larger, Matrices. Once the size gets moderately large (more than 200, say) then switching to a density-style plot using surfdata might be better in terms of GUI performance. And if the size got large (more than 400, say) then switching from a plot to an image might be better.

Here's a way, that has reasonably decent speed to get 500x500 resolution.

It also uses the iteration count to adjust the intensity of the color, retaining a little more information. I like the extra pop it provides. Some alternates approaches are commented out.

The timing is not bad: in total about 4.2 sec for the whole computation on my machine.

But the classifier that matches points to closest root of the polynomial is not optimized, and that step alone takes a 2.2 sec portion of that total! (I couldn't find my old code that did that step better, sorry...)

restart:

kernelopts(version);

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

with(IterativeMaps): with(ImageTools):

#ee := (z^6-1)/(5*z^2+1)^(1/5);
ee := z^3-1:

st := time[real]():

rts:=Vector[row]( sort( [ fsolve(numer(ee),z,complex) ] ),
                  datatype=complex[8]):
evalf[8](%);

Vector[row]([1.+0.*I, -.500000000000000-.866025400000000*I, -.500000000000000+.866025400000000*I])

(minr,maxr) := -2,2:
(mini,maxi) := -2,2:

dee := diff(ee, z):
Z := eval( z - ee/dee, z=zr+zi*I):

fzi := evalc( Im( Z ) ):
fzi := simplify(combine(fzi)) assuming real:

fzr := evalc( Re( subs(zi=zit, Z) ) ):
fzr := simplify(combine(fzr)) assuming real:

N := 500;
maxiter := 20; # increasing this will reduce nonconvergence
h,w := N, floor(N*(maxr-minr)/(maxi-mini));

500

20

500, 500

newt := Escape( height=h, width=w,
                       [zi, zr, zit],
                       [fzi, fzr, zi],
                       [y, x, y], abs(eval(ee,[z=zr+zit*I]))^2<1e-10,
                       minr, maxr, mini, maxi,
                       iterations = maxiter,
                       redexpression = zr, greenexpression = zit, blueexpression=i ):

 

## Use full saturation and full intensity
img:=Array(1..h,1..w,1..3,(i,j,k)->1.0,datatype=float[8]):

temp:=copy(newt[..,..,3]):

 

## Uncomment either scheme 1 or scheme 2.
## Optional, set intensity to zero for non-convergence.
## scheme 1
#temp:=Threshold(temp,1,low=maxiter+1):
#img[..,..,3]:=Threshold(temp,maxiter-1,high=0,low=1):

 

## Optional, set intensity by count (to converge).
## scheme 2
temp:=ln~(map[evalhf](max,temp,1.0)):
temp2:=Threshold(temp,0.01,low=1):
temp:=zip(`*`,temp,temp2):
temp:=FitIntensity(temp):
img[..,..,3]:=temp:

 

## Optional, scale the saturation by count (to converge).
## This works as a possible addition to scheme 2.
#img[..,..,2]:=1-~img[..,..,3]:

 

## Done inefficiently, set the hue by position in the list of
## all roots.
G:=Array(zip((a,b)->min[index](map[evalhf](abs,rts-~(a+b*I))),
             newt[..,..,1],newt[..,..,2]),
         datatype=float[8],order=C_order):
img[..,..,1]:=240*FitIntensity(G):

 

final := HSVtoRGB(Flip(img,'vertical')):

(time[real]() - st) * 'seconds';

4.208*seconds

Embed(final);

NULL

newtbasin2.mw

The above shows an image, in the ImageTools sense. You could turn that into a kind of density-style plot with axes as follows. And you could optionally display this along with a pointplot of the roots, etc. (But note that rendering such high-resolution density-style plots uses a great deal of GUI resources. Embedding images is much gentler on the GUI.)

PLOT(GRID(-2..2,-2..2,Matrix(N,N,datatype=float[8]),
     COLOR(RGB,Rotate(final,-90,degrees))),
     STYLE(PATCHNOGRID),AXESSTYLE(BOX));

Of course one could optionally scale the intensity (brightness) in reverse, so that points which took longer to converge were darker. (That might jibe better with the non-converged points showing as black.)

And here is the same thing, with the option of using the escape-count to adjust the color saturation as well as its intensity.

And here is the other option, using a simpler "scheme 1" for the coloring.

It looks as if you might be trying to compute the following kind of thing.

(But you might be unclear on the differences between definite and indefinite integration).

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

Digits := 15;

15

yyExact := 1/(m*c)*sqrt((m*c)^2+p^2+q^2);

(c^2*m^2+p^2+q^2)^(1/2)/(m*c)

ff11 := cos(k*(p+q+x+t));

cos(k*(p+q+x+t))

JJx11 := simplify(combine( QQ/m * Int(p/yyExact * ff11, [p=0..1, q=0..1]) ));

Int(cos(k*p+k*q+k*t+k*x)*QQ*p*c/(c^2*m^2+p^2+q^2)^(1/2), [p = 0 .. 1, q = 0 .. 1])

eval(JJx11, [t=0, m=9.11e-31, c=3e8, QQ=1.6e-19, k=0.5, x=0]);

Int(0.48e-10*cos(.5*p+.5*q)*p/(p^2+q^2+0.7469289e-43)^(1/2), [p = 0 .. 1, q = 0 .. 1])

evalf(%);

0.265894013394288e-10

# I'm not sure why you were raising Digits as high as 30.
Digits := 30;
eval(Int(op(JJx11), epsilon=1e-7, method=_CubaCuhre),
     [t=0, m=9.11e-31, c=3e8, QQ=1.6e-19, k=0.5, x=0]);
evalf[7](evalf[30](%));
Digits := 15;

30

Int(0.48e-10*cos(.5*p+.5*q)*p/(p^2+q^2+0.7469289e-43)^(1/2), [p = 0 .. 1, q = 0 .. 1], epsilon = 0.1e-6, method = _CubaCuhre)

0.2658940e-10

15

simplify(combine( Int(p/yyExact * ff11, [p=0..1, q=0..1]) ));

Int(cos(k*p+k*q+k*t+k*x)*p*m*c/(c^2*m^2+p^2+q^2)^(1/2), [p = 0 .. 1, q = 0 .. 1])

eval(%, [t=0, m=9.11e-31, c=3e8, QQ=1.6e-19, k=0.5, x=0]);

Int(0.2733e-21*cos(.5*p+.5*q)*p/(p^2+q^2+0.7469289e-43)^(1/2), [p = 0 .. 1, q = 0 .. 1])

evalf(%);

0.151473858761892e-21

 

Download question11_ac.mw

If you can figure out what kind of integration you really intend then perhaps it's worth investigating why you were raising Digits so high.

Perhaps you're after this kind of functionality,

solve( Or(And(x + y = 2,y = 1,x > 0),And(x^2 = 4, x < 0, y = 0)) );
 
         {x = 1, y = 1}, {x = -2, y = 0}

restart;

eq := A=P*(1+r/n)^(n*t);

A = P*(1+r/n)^(n*t)

ans:=combine(simplify(evalindets(solve(eq,n,allsolutions),suffixed(_Z),u->0)));

-r*ln(A/P)/(r*t*LambertW(-ln(A/P)*(A/P)^(-1/(r*t))/(r*t))+ln(A/P))

evalf(eval(eval(eq, n=ans), [P=5,A=10,r=1/10,t=2]));

10. = 10.00000001

Download solve_ex2.mw

This is the same kind of mistake as your other example, and is not a bug.

A successful way is to use map[2], to map applyrule over B using the entire list half_angle_rule as the first argument (ie. passed to applyrule, for each entry in B).

What your orignal code instructs the elementwise operator applyrule~ to do is more like an interleaved zip action.

restart;

half_angle_rule := [
        sin(x::name) = 2*sin(x/2)*cos(x/2),
        cos(x::name) = 1 - 2*sin(x/2)^2
]:

A := < sin(u), sin(u) >;

A := Vector(2, {(1) = sin(u), (2) = sin(u)})

map[2](applyrule, half_angle_rule, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [2*sin((1/2)*u)*cos((1/2)*u)]])

applyrule~(half_angle_rule, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [sin(u)]])

zip(applyrule, <half_angle_rule>, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [sin(u)]])

Download map2_ex2.mw

The error message states the problem. It is not a bug.

You goal appears to be to map applyrule over each of the entries of C, with all of double_angle_rule as the first argument.

The elementwise operator applyrule~ is not correct for doing that. As you wrote it Maple is trying something more like an interleaved zip operation, but the dimensions of C and double_angle_rule do not match.

One way to accomplish the presumed goal is to utilize map[2].

restart;

double_angle_rule := [
        sin(x::name/2)*cos(x::name/2) = 1/2*sin(x),
        sin(x::name/2)^2 = 1/2*(1-cos(x)),
        cos(x::name/2)^2 = 1/2*(1+cos(x))
]:

C := < cos(1/2*u)*sin(1/2*u), cos(1/2*u)^2 >;

C := Vector(2, {(1) = cos((1/2)*u)*sin((1/2)*u), (2) = cos((1/2)*u)^2})

map[2](applyrule, double_angle_rule, C);

Vector[column]([[(1/2)*sin(u)], [1/2+(1/2)*cos(u)]])

applyrule(double_angle_rule, C[1]);

(1/2)*sin(u)

applyrule(double_angle_rule, C[2]);

1/2+(1/2)*cos(u)

Download map2_ex.mw

First 73 74 75 76 77 78 79 Last Page 75 of 336