Joe Riel

8833 Reputation

23 Badges

16 years, 295 days

MaplePrimes Activity

These are answers submitted by Joe Riel

You specified the vertical range as 0..0.1, but the points are higher than that.  Try view = [0..1,0..1].

You could write a procedure to do this.  Say

keep_type := proc(x, typ :: type)
   if type(x, typ) then x;
   else select(type, x, typ);
   end if;
end proc:

More general would be a keep procedure that applies a predicate as select does,

keep := proc(fcn, x)
   if fcn(x, _rest) then x;
   else select(fcn, x, _rest);
   end if;
end proc:

You could then use this with, say

keep(type, expr, mytype_3);


Acer's response addresses an issue about which I had begun to reply but canceled. I assume that the primary motivation for testing the entire expression against the type is to handle the case when the general sum of terms is, in fact, a single term.  Using select in that case will generally produce something undesired as it will select factors from a product. Using your method (or the keep I provided) may work, but only if the predicate is properly constructed.  Constructing structured types that exactly match a desired form is challenging. An ad hoc solution is to use has or hastype as the predicate, however, if it matches a single term in a sum, it will also match the entire sum, so is useless in the keep algorithm.  The better approach, as Acer suggests, is to first explicitly test for a sum; if it is a sum select the desired terms, otherwise test a single term.

As Acer mentions, it isn't clear precisely what you want.  Further confusing the issue is your description of an expression of the form something*piecewise as a function. I'll assume you mean expression and that you want selection rather than extraction. However, one typically doesn't select from a sum because the result is another sum. I'll further assume you want the terms of the given sum that have the desired form. For the particular example, a not robust but easy way is with

mytype := 'And(piecewise,patfunc(identical(t)<numeric,anything))':
select(hastype, convert(MyExpr,'set'), mytype); 


Not quite sure what you want. Consider

P := module()
export A := module() ... end module:
export B := module() ... end module:
export C := module() ... end module:
end module:

If that's the structure, just rename B to Btmp and C to B.  If C is independent and in a library, then you should be able to just rename your B and, in P, do 

export B := C;


If you remove the square brackets from subs command the output is an algebraic expression rather than a list.

An alternative way to handle this is with the Syrup package, available on the Maple Cloud. With it you can do

ckt := [V3(1), R3(200),R49(1.3e3),1,C5(68e-12),L(3.3e-6),C4(100e-12),1,C6(8.2e-12),C2(10e-12),R8(10e3)]:
sol := Solve(ckt,ac):
subs(sol, v[2]); # I'm not sure which node voltage you are interested in.


Note that n is charge carrier density, not charge density. So

(**) B := 0.5*Unit('T'):
(**) q := Unit('e'):
(**) n := 0.15*100000./Unit('L'):
(**) d := 1*Unit('micron'):
(**) Ih := 0.1*10^(-5)*Unit('A'):
(**) Vh := Ih*B/q/n/d:
(**) combine(Vh, units);

Seems a tad large.  Better check those values.

A slight clarification; the package will be loaded, regardless; what you don't want is binding its exports into the global namespace, which is what with does.

Those two procedures, alias and macro, have different purposes.  Alias causes a global name to be displayed as its defined alias, though it also allows entering the short name.  Macro is only for simplified input.  Because macro is builtin (alias is a library procedure) I'd probably use it rather than alias if your purpose is to simplify the input. Note that using alias will change the display of a printed procedure.  For example

alias(ST = StringTools):
foo := proc(s) ST:-UpperCase(s); end proc;

         foo := proc(s) ST:-UpperCase(s); end proc


macro(ST = StringTools):
foo := proc(s) ST:-UpperCase(s); end proc;
        foo := proc(s) StringTools:-UpperCase(s); end proc



In the Type menu, select Custom and then enter Modelica.Thermal.FluidHeatFlow.Interfaces.FlowPort in the text area and click Apply Custom.  You can also enter FlowPort_a to get a filled port or FlowPort_b to get an open port.

Something seems wrong.  I build a package with many includes. The number of source lines is over 100K.  It takes 2 seconds for Maple to process it. 

Are you sure you have write permission to the directory which is being used (execute currentdir() to determine that)?

The short answer is that unless you can just combine the modules into one, you'll probably have to edit code.  If it's a lot, you might consider how to automate it.  For example, use the exports Maple command to get the exports of a module, then use StringTools commands to update source files.  If a unix user, consider generating a sed script to do the update. Backup stuff so you can recover from the inevitable errors.

This is one of a few reasons to alway use the equation binding form in a uses statement.  For example

uses ST = StringTools;
end proc:

Another is that if you use the name form, an addition to the package being used could break code if you had used an identifier that matches an export. 

Because you have the source, an alternative is to hard-code a call to DEBUG() inside the procedure.  For example,

foo := proc()
local k,y;
    y := 0;
    for k to 10 do
        if k > 3 then
         end if;
        y := y + k;
    end do;
end proc:
foo();  # the debugger will be invoked when k reaches 4.


I've added an option to the Iterator:-Partition procedure that specifies the maximum value of a partition.  For example

P := Iterator:-Partition(100,'maxvalue'=35):
add(1, p=P);

That took a bit under 8 minutes. The cardinality differs significantly from what you show.  Will investigate.

Later The cardinality from the Sage math output is different because it is returning partitions with distinct values.   Iterator:-Partition generates all partitions.  For example

(**) P := Iterator:-Partition(7,maxvalue=4):
(**) Print(P,showrank);
 1: 4 3 
 2: 4 2 1 
 3: 4 1 1 1 
 4: 3 3 1 
 5: 3 2 2 
 6: 3 2 1 1 
 7: 3 1 1 1 1 
 8: 2 2 2 1 
 9: 2 2 1 1 1 
10: 2 1 1 1 1 1 
11: 1 1 1 1 1 1 1 


A practical method is to create a Maple archive (mla file) from the source, then access it from Maple.  To access it from Maple you can either modify libname, or (better), install the mla into a custom toolbox where it will be automatically found.  On my linux box that means installing it in, say, /home/joe/maple/toolbox/foo/lib/foo.mla, where the package name is foo

Depends on what you want to do with the data structure.  Maple tables and MultiSets behave quite differently. 

2 3 4 5 6 7 8 Last Page 4 of 110