acer

32333 Reputation

29 Badges

19 years, 321 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

No it is not a different s. It is the same s. That's the problem.

Is you don't need to subsequently substitute for the subscripts the you could use literal subscripts instead. Eg,

   omega__s1    and   omega__s

which prettyprint as subscripted names.

You called it a "user initialization file", ie. your own personal Maple initialization file, unrelated to the location where Linux is installed.

There is not one, by default.

Simply create/edit a file called .mapleinit in your Linux home directory, using your favorite Linux text editor.

It should contain Maple source code.

If you enter initialization into the search bar of Maple's Help system you could see that this is documented. See here, for the online page.

I am taking your description to mean that a can be any algebraic expression not depending on t, and that b can be any algebraic expression depending on t.

If you don't like depends you could change it to has. I don't know how you want to treat the cases where t is used as a dummy variable (of integration, etc).

I'm pretty sure that even if I've overlooked some corner case (or misinterpreted your definition) this could still be fixed up easily.

restart;

F := proc(ee::algebraic, nm::name)
       local s,o;
       if not ee::`*` then return false; end if;
       (s,o) := selectremove(depends,[op(ee)],nm);
       if nops(s)=0 or nops(o)=0 then false;
       else true; end if;
end proc:

F( (a+b)*(t^2+y), t );

true

F( (a+b)*(t^2+y)*t^5, t );

true

F( (t^2+y)*t^5, t );

false

F( (a+b)*c*(t^2+y)*t^5, t );

true

F( 3*t,t );

true

F( a*b*c, t );

false

F( a+b+c, t );

false

 

Download starchk.mw

It would be pretty straightforward to turn that into a type check instead. (I usually go for the easiest or first reasonable predicate I think of, instead of labouring over a slick structured type check that I may not immediately understand when I look at the code again in 3 years.) I don't know how exactly you intend on using it, whether performance is a key concern at huge scale, etc.

[edit] I don't recall seeing patmatch used robustly for a key role in a major project.

Here is another way, without hard-coded writing out of the trig/trigh terms' particular arguments.

You could also add the step to assign the _D names, but it wasn't clear to me that you wanted to.

restart;

sol := W(x) = _C1*(cosh(alpha*x) - sinh(alpha*x))
              + _C2*(cosh(alpha*x) + sinh(alpha*x))
              + _C3*sin(alpha*x) + _C4*cos(alpha*x):

L := [indets(sol,specfunc({sinh,cosh,sin,cos}))[]]:

temp := collect(sol,[sinh,cosh,sin,cos]):

CL := [coeffs(rhs(temp),L)]:

R:=[seq(cat(_D,i)=CL[i], i=1..nops(CL))];

[_D1 = _C1+_C2, _D2 = -_C1+_C2, _D3 = _C3, _D4 = _C4]

subs((rhs=lhs)~(R), temp);

W(x) = _D2*sinh(alpha*x)+_D1*cosh(alpha*x)+_D3*sin(alpha*x)+_D4*cos(alpha*x)

Download subsex.mw

If you don't need R for any other purpose then the last two of those statement could be combined together into this:

    subs(seq(CL[i]=cat(_D,i), i=1..nops(CL)), temp);

[edit] I'll point out that, as I see it, the order of the trig/trigh terms appearing in sol are rather arbitrary since in Maple those are can vary by session and the method of construction. Relying on that particular order of subterms in the sum seems like sloppy programming that might lead to later error, to me. Having said that, I don't see why one could not accept other terse variants such as the following (and it could be made shorter still).

   L := [indets(sol,specfunc({sinh,cosh,sin,cos}))[]]:
   temp := collect(sol,L):
   subs(seq(coeff(rhs(temp),L[i])=cat(_D,i), i=1..nops(L)),temp);

Of course, anyone is free to disagree with my rationale.

The authors of the package have stated steps here:
     https://www-polsys.lip6.fr/~jcf/FGb/FGb/x86_64_linux/index.html

Did you follow those steps?

(By the way, how do you think that relates to the version that is bundled in Maple 2020? Are you look for that site's specific version because of instructions for compatibility with another 3rd party package? It might help more if you described the full background of the query.)

The following can process 10^5 entries (sub-sets of set A) in about 1 second on my machine.

On my machine this was about 20% faster than mapping convert,string for 10^5 entries.

But for 100 entries I don't think that you'd be able to distinguish the difference.

restart;
A:={{"1","8"},{"1","4"},{"1","10"}};
           A := {{"1", "10"}, {"1", "4"}, {"1", "8"}}

map[2](sprintf,"%a",A);
          {"{"1", "10"}", "{"1", "4"}", "{"1", "8"}"}

An alternative but shorter syntax is,

sprintf~("%a",A);

You have made a common mistake in 2D Input syntax. Your two bracketed terms inside the sqrt are not being multiplied together. They are parsed together as a compound function call.

To get what you intended you can either insert an explicit multiplication sign or (in 2D Input mode) insert a space to denote mutiplication implicitly.

NULLassume(0 < k, k < 1)

int(x^2/sqrt((-x^2+1)*(-k^2*x^2+1)), x = 0 .. k)

EllipticF(k, k)/k^2-EllipticE(k, k)/k^2

``

Download ellipticIntegralTest_ac.mw

 

Could you make big_car itself an object, and pass that to the method procedure, etc?

[edited] I didn't really understand why you want big_car:-set_name declared as static, btw, given the rest of your example's structure and the original description you gave. But you could also change this code below so that big_car_name was instead declared as static(string).

restart;

module car_class()
      option object;
      local name::string :="UNKNOWN";

      export set_name::static:=proc(o::car_class,_name::string)
        o:-name := _name;
        o:-big_car:-set_name(o:-big_car,_name);
      end proc;

      #this is module, that I want to be private to this class only
      #eventually, I'd like this module be in separate mpl file also.
      local big_car::static :=module()  #module does not take arguments!
            option object;
            #this below should be private only to the this module
            #and not seen by the enclosing object.
            local big_car_name::string:="UNKNOWN";  

            #this export to allow parent object to call it
            export set_name::static:=proc(o::big_car,_name::string)
                   o:-big_car_name:=_name;
            end proc;

      end module;

end module:

o:=Object(car_class);

module car_class () local name::string; option object; end module

o:-set_name(o,"GM");

"GM"

# As desired, car_class does not export big_car .
#
o:-big_car:-set_name(o,"Ford");

Error, module `car_class` does not export `big_car`

 

Download object_submodule.mw

It's unclear what you mean by stating that you want big_car defined in its own .mpl file, if you want it declared as a (static) local of the car_class object. Do you just mean that the source of the car_class will $include the source of big_car?

Your first example contained the code snippet,
    big_car:-set_name("toyota")
which you claimed did set the name for your first variant. Is that incomplete and a typo, or actually what you meant? (I have guessed at the intended meaning to be that the car_class object would not export from submodule big_car literally/directly.)

One thing you should know is that the product 14*(7 - 2*sqrt(7)) will automatically simplify to 98-28*sqrt(7), and that cannot be prevented merely by delaying evaluation.

There are a few ways to represent that product so that it prettyprints nicely, and so that you can recover the actual value for further computation.

Here, I'll use the inert `&*` operator instead of the usual active `*`. By default that will prettyprint with a gray multiplication symbol. You can also use the InertForm:-Display command to make it prettyprint in the more usual way.

restart;

'14*(7 - 2*sqrt(7))';

98-28*sqrt(7)

ee := 98-28*sqrt(7);

98-28*7^(1/2)

new := `%*`(content(98-28*sqrt(7), sqrt(7)),
            primpart(98-28*sqrt(7), sqrt(7)));

`%*`(14, 7-2*7^(1/2))

value(new);

98-28*7^(1/2)

InertForm:-Display(new, inert=false);

0, "%1 is not a command in the %2 package", _Hold, Typesetting

 

Download auto_simp.mw

I will also mention that the alternative mechanism (to prevent actual multiplication) of using the ``(...) call will make the result prettyprint with round brackets even if that part is not a sum of terms.

You might also consider the following, though we do not know what other kinds of examples you might have.

content(98/3-28/3*sqrt(7), sqrt(7));
                               14
                               --
                               3 

icontent(98/3-28/3*sqrt(7));
                               14
                               --
                               3 

Also, if you are going to use these mechanisms programmatically then you might want to have a special case that primpart returns 1 or -1 (so that it doesn't print with unnecessary clutter). Again, we don't know what other kinds of examples you might have.

You can construct the plot in several ways.

You can also construct the list D1 in several ways. Your could express the difference of the products using special function GAMMA (or binomial or factorial, which I have not done, though there is the 1/2 present). You could also compute it with explicit multiplication, and by storing prior results to avoid recomputation (which I have not done as efficiency doesn't seem to be a central concern for your range of n).

restart

delta := 1/2

1/2

expr := simplify(product(1-1/(1+k)+3*delta/(1+k), k = 1 .. n)-product(1-(1-delta)/(1+k), k = 1 .. n))

(4/3)*n*GAMMA(3/2+n)/(Pi^(1/2)*GAMMA(2+n))

plot([1/(1+n), expr, n = 1 .. 10], adaptive = false, numpoints = 10, style = pointline, symbolsize = 15)

A := [seq(1/(1+n), n = 1 .. 10)]

[1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11]

D1 := [seq(product(3*delta*A[k]-A[k]+1, k = 1 .. n)-product(1-A[k]*(1-delta), k = 1 .. n), n = 1 .. 10)]

[1/2, 5/6, 35/32, 21/16, 385/256, 429/256, 15015/8192, 12155/6144, 138567/65536, 146965/65536]

D1 := [seq(expr, n = 1 .. 10)]

[1/2, 5/6, 35/32, 21/16, 385/256, 429/256, 15015/8192, 12155/6144, 138567/65536, 146965/65536]

P1 := plot(A, D1, style = point, color = blue, symbol = solidcircle, symbolsize = 15)

P2 := plot([1/(1+n), expr, n = 1 .. 10])

plots:-display(P2, P1)

 

Download Help_exclam_ac.mw

You wrote, "But now I am starting to worry that each maple command/function/name used inside the Object needs  :- added to it, just in case of a current or future name conflict with local object variables names."

But that is already true for programming with procedures and modules, so why suggest that it makes Object programming too onerous?

If there is a procedure or module local or the same name within scope then (within a procedure) one needs to qualify the name with colon-minus in order to force the interpretation to be the global instance of the name. (Your Questions first sentences incorrectly suggest the opposite, IMO.)

You might find it more convenient (or even proper) to exclude the non-static Object local (within scope) from being a candidate for the scoping resolution of the name reference. But it does not follow from your incorrect suggestion that the scoping rules are wholly different from that in general.

Use the Maple read command to read in a .m file that has been stored by Maple.

Pass the read command a string that points to the filename. It can be either the name/location relative to the current directory (see currentdir), or the full path to the file.

You can use the nextperm command from the combinat package to obtain the permutations one at a time. You don't need to construct your own procedure that walks the permutations.

You could also use the Iterator package to generate the permutations one at a time.

Having said that, here are three variants.

The first is like your original, but looks very awkward in Maple since I deliberately made almost as few alterations as possible to suit the language. You should not program like this in Maple, as there are much better techniques and syntax, even if you really feel the need to program the whole permutation process. But it is an answer to what you actually requested, about passing by reference (like a pointer). I use the evaln modifier of the procedure parameters so that they get passed by reference, and I use the eval command to access their values for the re-assignment.

The second is similar, but uses direct Array reference and multiple-assignment to swap entries.

And the third uses combinat:-nextperm.  I deliberately made the do-loop clumsy and obvious. It could be slicker (since Maple's do-loops also allow for useful while and until clauses, etc) but I hoped to confusion and it's not clear how you want to utilize the individual permutations.

restart;

swap := proc(a::evaln, b::evaln)
  local temp;
  temp := eval(a);
  a := eval(b);
  b := temp;
  return NULL;
end proc:

permutation := proc(arr, start::integer, End::integer)
  local i::integer;
  if start = End then
    print(arr);
    return NULL;
  end if;
  for i from start to End do
    swap(arr[i], arr[start]);
    procname(arr, start+1, End);
    swap(arr[i], arr[start]);
  end do;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = e, (6) = d})

Array(%id = 18446883908681703422)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

restart;

permutation := proc(arr, start::integer, End::integer)
  local i::integer;
  if start = End then
    print(arr);
    return NULL;
  end if;
  for i from start to End do
    arr[i],arr[start] := arr[start],arr[i];
    procname(arr, start+1, End);
    arr[i],arr[start] := arr[start],arr[i];
  end do;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = e, (6) = d})

Array(%id = 18446883908681703422)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

restart;

permutation:=proc(arr, start::integer, End::integer)
  local i,L,oldL,orig;
  uses combinat;
  L := [seq(i, i=start..End)];
  orig := arr[L];
  print(arr);
  do
    oldL,L := L,nextperm(L);
    if L = FAIL then break;
    else
      arr[L] := arr[oldL];
      print(arr);
    end if;
  end do;
  arr[[seq(i, i=start..End)]] := orig;
  return NULL;
end proc:

A := Array(1..6, [a,b,c,d,e,f,g]);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

permutation(A, 4, 6);

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = f, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = d, (6) = f})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = f, (5) = d, (6) = e})

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = e, (5) = f, (6) = d})

Array(%id = 18446883908681703662)

A;

Vector[row](6, {(1) = a, (2) = b, (3) = c, (4) = d, (5) = e, (6) = f})

 

Download perm.mw

If I have pasted in the plaintext theta__xy while in 2D Input mode then I can immediately convert it to the typeset form by simplify pressing the Escape key.

And I can do the same thing after the fact (ie. later) by first placing the mouse focus on that literal input, and then pressing Escape.

I don't know of any mechanism to change all such paste-ins with just one action, after the fact.

Is this adequate for your purpose?

Applying the expand command will turn the composition into nested calls, on which value does what you wanted.

restart;

with(Physics[Vectors]):

(%Nabla)(f(x,y,z));

%Nabla(f(x, y, z))

value(%);

(diff(f(x, y, z), x))*_i+(diff(f(x, y, z), y))*_j+(diff(f(x, y, z), z))*_k

(%Nabla@@4)(f(x,y,z));

(%Nabla@@4)(f(x, y, z))

value(expand(%));

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

(Nabla@@4)(f(x,y,z));

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

 

expand( (%Nabla@@4)(f(x,y,z)) );

%Nabla(%Nabla(%Nabla(%Nabla(f(x, y, z)))))

value(%);

diff(diff(diff(diff(f(x, y, z), x), x), x), x)+2*(diff(diff(diff(diff(f(x, y, z), x), x), y), y))+2*(diff(diff(diff(diff(f(x, y, z), x), x), z), z))+diff(diff(diff(diff(f(x, y, z), y), y), y), y)+2*(diff(diff(diff(diff(f(x, y, z), y), y), z), z))+diff(diff(diff(diff(f(x, y, z), z), z), z), z)

 

Download nested_comp.mw

First 119 120 121 122 123 124 125 Last Page 121 of 336