Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are replies submitted by Doug Meade

I think you want to be using unapply:

F := unapply( OVM(3,7,2), [alpha,gamma,beta] );

One difference between unapply and -> is that -> does not evaluate its arguments. So, when you wrote (alpha,gamma,beta)->OVM(3,7,2), Maple never saw the output to OVM. But, unapply does evaluate its arguments.

Is this like what you have in mind?

OVM := (i,j,k) -> alpha^i*gamma^j*beta^k;
                  i      j     k
(i, j, k) -> alpha  gamma  beta 
OVM(3,7,2);
                                  3      7     2
                             alpha  gamma  beta 
f := unapply( OVM(3,7,2), [alpha,gamma,beta] );
                             3      7     2
(alpha, gamma, beta) -> alpha  gamma  beta 
f(1,2,3);
                                    1152
F := (alpha,beta,gamma) -> OVM(3,7,2);
(alpha, beta, gamma) -> OVM(3, 7, 2)
F(1,2,3);
                                  3      7     2
                             alpha  gamma  beta 

This does not produce the error message you indicated, but you do see that the alpha, beta, and gamma in OVM and the variables with the same name at the top level are not the same variables. (Those in OVM are local only to OVM.)

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Interesting, but explainable.

Here is what I see in Maple 12:

restart;
f := unapply( n+m, m );
                                 m -> n + m
f(1);
                                    n + 1
g := unapply( f(m), m );
                                 m -> n + m
g(1) := f(1)+a;
                                  n + 1 + a
f(1);
                                  n + 1 + a

Your first line  defines the function f. When this function is evaluated with argument 1, the output is n+1.

You are correct, the definition of g is, effectively, assigning g to f. The way unapply works, it fully evaluates the first argument f(m) so Maple is really executing g := unapply( n+m, m ); . If you make any subsequent changes to the definition of f, these will not be seen by g. (If you give a value to n, that will be seen by both f and g.)

The assignment to g(1) overrides the general rule for the function g. More precisely, Maple has a `remember table' where it can keep track of the value of the functions that it evaluates. Before Maple applies the general rule for evaluating a function it looks to see if this value has been computed previously. If so, this value is used instead of the general rule. So, your assignment to g(1) puts this value in the remember table for the function g. You can see Maple's remember table for your function g as follows:

op(4,eval(g));
                                   table([1=n+1+a])
op(4,eval(f));
                                   table([1=n+1+a])

Now, unapply is also a "function" and it has its own sort of a remember table. In this case, because Maple sees that it has evaluated the command unapply( m+n, m ) it returns the remembered result. While f and g are separate objects,as shown by the output from addressof, when disassembled they are exactly the same internally:

addressof(f);
                                  50814608
addressof(g);
                                  50820912
disassemble( addressof(f) );
                         8, 50826360, 50539420, 102
disassemble( addressof(g) );
                         8, 50826360, 50539420, 103
kernelopts( dagtag=(10)[1] );
                                    NAME
pointto( (10)[2] );
                                 m -> n + m
pointto( (11)[2] );
                                 m -> n + m

Consider now the following function:

h := unapply( f(u), u );
                                 u -> n + u
h(2) := f(2)+b;
                                  n + 2 + b
f(2);
                                    n + 2

Because Maple has not seen u->n+u before, this expression gets stored to a different place in memory.

addressof(f);
                                  50814608
addressof(h);
                                  51224368

And, digging deeper we see that the internal representations of f and h are different:

ff := disassemble( addressof(f) );
                         8, 50826360, 50539420, 102
hh := disassemble( addressof(h) );
                         8, 50826448, 50539420, 104
kernelopts( dagtag=ff[1] );
                                    NAME
pointto( ff[2] );
                                 m -> n + m
pointto( hh[2] );
                                 u -> n + u

While we would not make a mathematical distinction between the functions g and h, I hope this explains why Maple does see them as being different functions (and why Maple sees f and g as being the same function). In addition to explaining why this happens, I hope I've given you some ideas about how to avoid any problems that you have encountered as a result of this implementation.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

First, I am not aware of a "list" command. You aren't doing anything (useful) when you refer to list(30).

When you create a data structure by assigning to entries, you are actually creating a table not a list. (Maple's output shows this.) When you use subsop on a table, you do unexpected things. Just because you think of l as a list does not mean that's how Maple sees it.

You really should try to understand the solutions others are posting. You need to break away from traditional programming in terms of loops. Once you do this you will start to see the real power of the tools at your fingertips.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

First, I am not aware of a "list" command. You aren't doing anything (useful) when you refer to list(30).

When you create a data structure by assigning to entries, you are actually creating a table not a list. (Maple's output shows this.) When you use subsop on a table, you do unexpected things. Just because you think of l as a list does not mean that's how Maple sees it.

You really should try to understand the solutions others are posting. You need to break away from traditional programming in terms of loops. Once you do this you will start to see the real power of the tools at your fingertips.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Does this work for you?

NN := {a[]} intersect {b[]};
                                   {2, 3}
[seq( n $ min( map2( ListTools:-Occurrences, n, [a,b] ) ), n=NN )];
                                  [2, 2, 3]
 

I'm sure there are more sophisticated approaches to your problem. This implementation closely follows your description. First, find all elements that are found in both lists. The output is formed by repeating ($) each number the fewest number of times it occurs in both lists.

The same output is obtained if you replace the NN in the seq command by {a[]} or {b[]}. Note that the conversion of a list to a set can also be done with, e.g., convert( a, set ); .

The number of elements in a list (or set) can be found with the nops command. For example, nops( a ); .

You should try to get away from using indices to access elements in a list. Think about operations on the entire list (or set or whatever).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Does this work for you?

NN := {a[]} intersect {b[]};
                                   {2, 3}
[seq( n $ min( map2( ListTools:-Occurrences, n, [a,b] ) ), n=NN )];
                                  [2, 2, 3]
 

I'm sure there are more sophisticated approaches to your problem. This implementation closely follows your description. First, find all elements that are found in both lists. The output is formed by repeating ($) each number the fewest number of times it occurs in both lists.

The same output is obtained if you replace the NN in the seq command by {a[]} or {b[]}. Note that the conversion of a list to a set can also be done with, e.g., convert( a, set ); .

The number of elements in a list (or set) can be found with the nops command. For example, nops( a ); .

You should try to get away from using indices to access elements in a list. Think about operations on the entire list (or set or whatever).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

All of the approaches sugested simply send the result from the base command to evalf for floating-point evaluation. They are not, in general, obtained using a numerical method. (I provide several examples related to this in my earlier post in this topic.)

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

All of the approaches sugested simply send the result from the base command to evalf for floating-point evaluation. They are not, in general, obtained using a numerical method. (I provide several examples related to this in my earlier post in this topic.)

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I have uploaded the worksheet showing my results. I copied your commands. All of my output shows zeros, either integer or float as specified.

View 178_ModularRandom.mw on MapleNet or Download 178_ModularRandom.mw
View file details

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

Alec,

The Create command in LinearAlgebra[Modular] does the same. It's probably the same bug, and you are probably closer to the source. I'll bet Create just calls Random.

Interesting that we both found this today, as we were working on our respnses in the base 5 discussion.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

I have marked in blue differences.

 

Where? I don't see anything in blue?

In an image editor, I deleted the parentisis square maple that comes with the group execution.

I've seen it in worksheet that have been shown in "Application Demostration" from Maplesoft Web.I would like to achieve this configuration in my worksheets. more colorful presentation and printing.

Open the View menu and select Show/Hide Content ...

From the pop-up window that appears, uncheck Execution Group Boundaries and, probably, Section Boundaries. Click OK. Is this what you want? (If not, experiment with other combinations.)

Does this do what you want? If not, please give us some more (visual) information to use to try to find a solution.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

I have marked in blue differences.

 

Where? I don't see anything in blue?

In an image editor, I deleted the parentisis square maple that comes with the group execution.

I've seen it in worksheet that have been shown in "Application Demostration" from Maplesoft Web.I would like to achieve this configuration in my worksheets. more colorful presentation and printing.

Open the View menu and select Show/Hide Content ...

From the pop-up window that appears, uncheck Execution Group Boundaries and, probably, Section Boundaries. Click OK. Is this what you want? (If not, experiment with other combinations.)

Does this do what you want? If not, please give us some more (visual) information to use to try to find a solution.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

You want to take the derivative of I[ds] with respect to L, right?

You should try to find out how to do this from the information in the help system. If you don't know the correct command, you can ask for help on "derivative". Either select Maple Help from the Help (the first entry in this menu) and type "derivative" in the search for box, or type "?derivative" in an input region. Either way you will see the help page for the diff command, which is what you should use to compute most derivatives in Maple. It will also tell you about the D operator and the Diff command, but I doubt these are what you need at this point. Don't bother reading all of the details, just enough to get the general syntax and then look at the examples that are provided with almost every help topic.

The examples in the diff page (almost) all use the 2-D Math Notation for entering the derivatives. This shows the derivative using Leibniz notation instead of the actual Maple command. To play with the examples you can easily Copy Examples and paste them into an active worksheet. If you'd prefer to see the commands using traditional 1D Maple Notation, select what you want to convert (even multiple input regions), right click, select 2D Math -> Convert  To -> 1D Math Input and all inputs will suddenly appear. To convert to the prettier 2D notation, follow the same steps, except choose 2D Math Input in the final step.

In your case, your function depends on L in a very simple way. Maple does not allow you to use it's reserved name of I (without special considerations), so I changed this to II. Then, being sure to use := to make an assignment, I'd use:

II[ds] := conjugate(mu[eff0])*C[ox]*W/L*(V[gb]-V[fb]-conjugate(phi[s])-gamma*sqrt(phi[s])+(1+1/2*gamma/sqrt(conjugate(phi[s])))*V[th])*V[dseff];
       1 /________         /                ______               (1/2)
       - |mu[eff0] C[ox] W |V[gb] - V[fb] - phi[s] - gamma phi[s]     
       L |                 |                                          
         |                 |                                          
         \                 \                                          

            /        gamma    \      \         \
          + |1 + -------------| V[th]| V[dseff]|
            |            (1/2)|      |         |
            |      ______     |      |         |
            \    2 phi[s]     /      /         /
diff( II[ds], L );
       1  /________         /                ______               (1/2)
     - -- |mu[eff0] C[ox] W |V[gb] - V[fb] - phi[s] - gamma phi[s]     
        2 |                 |                                          
       L  |                 |                                          
          \                 \                                          

          /        gamma    \      \         \
        + |1 + -------------| V[th]| V[dseff]|
          |            (1/2)|      |         |
          |      ______     |      |         |
          \    2 phi[s]     /      /         /

I hope this is helpful for you.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

You want to take the derivative of I[ds] with respect to L, right?

You should try to find out how to do this from the information in the help system. If you don't know the correct command, you can ask for help on "derivative". Either select Maple Help from the Help (the first entry in this menu) and type "derivative" in the search for box, or type "?derivative" in an input region. Either way you will see the help page for the diff command, which is what you should use to compute most derivatives in Maple. It will also tell you about the D operator and the Diff command, but I doubt these are what you need at this point. Don't bother reading all of the details, just enough to get the general syntax and then look at the examples that are provided with almost every help topic.

The examples in the diff page (almost) all use the 2-D Math Notation for entering the derivatives. This shows the derivative using Leibniz notation instead of the actual Maple command. To play with the examples you can easily Copy Examples and paste them into an active worksheet. If you'd prefer to see the commands using traditional 1D Maple Notation, select what you want to convert (even multiple input regions), right click, select 2D Math -> Convert  To -> 1D Math Input and all inputs will suddenly appear. To convert to the prettier 2D notation, follow the same steps, except choose 2D Math Input in the final step.

In your case, your function depends on L in a very simple way. Maple does not allow you to use it's reserved name of I (without special considerations), so I changed this to II. Then, being sure to use := to make an assignment, I'd use:

II[ds] := conjugate(mu[eff0])*C[ox]*W/L*(V[gb]-V[fb]-conjugate(phi[s])-gamma*sqrt(phi[s])+(1+1/2*gamma/sqrt(conjugate(phi[s])))*V[th])*V[dseff];
       1 /________         /                ______               (1/2)
       - |mu[eff0] C[ox] W |V[gb] - V[fb] - phi[s] - gamma phi[s]     
       L |                 |                                          
         |                 |                                          
         \                 \                                          

            /        gamma    \      \         \
          + |1 + -------------| V[th]| V[dseff]|
            |            (1/2)|      |         |
            |      ______     |      |         |
            \    2 phi[s]     /      /         /
diff( II[ds], L );
       1  /________         /                ______               (1/2)
     - -- |mu[eff0] C[ox] W |V[gb] - V[fb] - phi[s] - gamma phi[s]     
        2 |                 |                                          
       L  |                 |                                          
          \                 \                                          

          /        gamma    \      \         \
        + |1 + -------------| V[th]| V[dseff]|
          |            (1/2)|      |         |
          |      ______     |      |         |
          \    2 phi[s]     /      /         /

I hope this is helpful for you.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

If you are asking about the Examples section of the help topics, then maybe you are thinking about the triple question mark (???) syntax.

???topic opens the help page for "topic" with only the Examples section expanded. (The Description, See Also, and References sectios, if present, are all collapsed.)

From here the Copy Examples entry in the File menu is an easy way to copy all of the Examples to an active worksheet (or document).

There are a few help topics that do open a worksheet.  Within the help browser, most topics have an icon that contains a question mark (?); these are the typical help pages displayed in the help browser. Those with a D icon are entries in Maple's dictionary. And, those with a WS icon are actual Maple worksheets; click on one of these and a separate worksheet opens in a Maple window. To see all three, look at the help for applications: ?applications

If this is not what you were asking about, please ask again.

Wishing a Merry Christmas to one and all!

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed
First 30 31 32 33 34 35 36 Last Page 32 of 76