Joe Riel

9660 Reputation

23 Badges

20 years, 4 days

MaplePrimes Activity


These are replies submitted by Joe Riel

I'm not sure I understand all your points. Why is copy not needed for arrays? Consider
v1 := vector([1,2,3]):
v2 := v1:
v2[1] := 100:
v1[1];
           100
Maybe you were thinking that the constructor (vector) could be used to duplicate the vector. Alas, it cannot:
v2 := vector(v1);
Error, (in vector) invalid arguments
Similary with arrays and matrices. One could argue that copy is less needed with rtables, since their constructors can do the duplication, however, as you note, there are subtle differences and frequently it is useful to be able to copy an rtable without knowing its specialization. I'm not sure that adding links from help pages is the best solution; that can lead to a tangled web and there will always be missing links. Maybe better would be to improve the search capabilities of the help browser. Being able to use boolean searches on keywords could be quite powerful. In this particular case, the more fundamental issue might not be the missing links to copy, but missing documentation from the ?assignment page. Understanding how the assignment operator (:=) works with different types is crucial to working with Maple, as with any programming language.
I'm not sure I understand all your points. Why is copy not needed for arrays? Consider
v1 := vector([1,2,3]):
v2 := v1:
v2[1] := 100:
v1[1];
           100
Maybe you were thinking that the constructor (vector) could be used to duplicate the vector. Alas, it cannot:
v2 := vector(v1);
Error, (in vector) invalid arguments
Similary with arrays and matrices. One could argue that copy is less needed with rtables, since their constructors can do the duplication, however, as you note, there are subtle differences and frequently it is useful to be able to copy an rtable without knowing its specialization. I'm not sure that adding links from help pages is the best solution; that can lead to a tangled web and there will always be missing links. Maybe better would be to improve the search capabilities of the help browser. Being able to use boolean searches on keywords could be quite powerful. In this particular case, the more fundamental issue might not be the missing links to copy, but missing documentation from the ?assignment page. Understanding how the assignment operator (:=) works with different types is crucial to working with Maple, as with any programming language.
Finding the appropriate command in Maple can be a daunting task. My usual strategy is to start with the Help Browser. For this case I'd type "Vector" into the search box, select the "Topic" radio button, click "Search" and then, when the search is finished, select the "Table of Contents" tab. In this case that puts me in "Data Structures" subsection of the "LinearAlgebra" section, a seemingly appropriate choice. Alas, a little browsing doesn't reveal any obvious clues on how to copy a Vector. My next attempt might be to type in appropriate keywords and use the "Text search" radio button. The root of the problem, I believe, is that copy is an old command, originally written for the linalg data structure (array, vector, matrix) as well as the table data structure. While it has been updated to work with rtables (Vectors, Arrays, and Matrices) as well as records, no links have been added from these help pages.
Finding the appropriate command in Maple can be a daunting task. My usual strategy is to start with the Help Browser. For this case I'd type "Vector" into the search box, select the "Topic" radio button, click "Search" and then, when the search is finished, select the "Table of Contents" tab. In this case that puts me in "Data Structures" subsection of the "LinearAlgebra" section, a seemingly appropriate choice. Alas, a little browsing doesn't reveal any obvious clues on how to copy a Vector. My next attempt might be to type in appropriate keywords and use the "Text search" radio button. The root of the problem, I believe, is that copy is an old command, originally written for the linalg data structure (array, vector, matrix) as well as the table data structure. While it has been updated to work with rtables (Vectors, Arrays, and Matrices) as well as records, no links have been added from these help pages.
I agree that it is not a good habit to get into, however, I was wrong in stating that it was inefficient. While it uses substantially more memory, at least for "large" lists, it appears to be at worst only half the speed of using a Vector. Here is a table comparing the performance of assigning a single element to a list or Vector of elements with increasing numbers of elements. Note that increasing gcfreq to reduce the number of garbage collections has almost no effect on the time in this case; the actual memory allocated is relatively small, its just be accessed a lot (for the list).
Measure Performance of assigning an element to a List/VectorLoop 10^5 times; gcfreq = 1.0e+06
  Timing (seconds) Memory (MiB)  
Procedure Maple Total Used Alloc GC times
num = 1
list_assign 0.36 0.38 5.72 3.25 1
Vector_assign 0.35 0.35 4.96 3.19 1
num = 2
list_assign 0.36 0.39 6.11 3.31 1
Vector_assign 0.35 0.35 4.96 3.19 1
num = 4
list_assign 0.38 0.46 6.87 3.37 1
Vector_assign 0.34 0.35 4.96 3.19 1
num = 8
list_assign 0.40 0.40 8.40 3.44 2
Vector_assign 0.33 0.35 4.96 3.19 1
num = 16
list_assign 0.45 0.45 11.45 3.56 3
Vector_assign 0.36 0.35 4.96 3.19 1
num = 32
list_assign 0.47 0.50 17.55 3.62 4
Vector_assign 0.34 0.36 4.96 3.19 1
num = 64
list_assign 0.55 0.56 29.76 3.69 7
Vector_assign 0.36 0.36 4.96 3.19 1
num = 100
list_assign 0.66 0.69 43.50 3.75 11
Vector_assign 0.35 0.35 4.96 3.19 1
I agree that it is not a good habit to get into, however, I was wrong in stating that it was inefficient. While it uses substantially more memory, at least for "large" lists, it appears to be at worst only half the speed of using a Vector. Here is a table comparing the performance of assigning a single element to a list or Vector of elements with increasing numbers of elements. Note that increasing gcfreq to reduce the number of garbage collections has almost no effect on the time in this case; the actual memory allocated is relatively small, its just be accessed a lot (for the list).
Measure Performance of assigning an element to a List/VectorLoop 10^5 times; gcfreq = 1.0e+06
  Timing (seconds) Memory (MiB)  
Procedure Maple Total Used Alloc GC times
num = 1
list_assign 0.36 0.38 5.72 3.25 1
Vector_assign 0.35 0.35 4.96 3.19 1
num = 2
list_assign 0.36 0.39 6.11 3.31 1
Vector_assign 0.35 0.35 4.96 3.19 1
num = 4
list_assign 0.38 0.46 6.87 3.37 1
Vector_assign 0.34 0.35 4.96 3.19 1
num = 8
list_assign 0.40 0.40 8.40 3.44 2
Vector_assign 0.33 0.35 4.96 3.19 1
num = 16
list_assign 0.45 0.45 11.45 3.56 3
Vector_assign 0.36 0.35 4.96 3.19 1
num = 32
list_assign 0.47 0.50 17.55 3.62 4
Vector_assign 0.34 0.36 4.96 3.19 1
num = 64
list_assign 0.55 0.56 29.76 3.69 7
Vector_assign 0.36 0.36 4.96 3.19 1
num = 100
list_assign 0.66 0.69 43.50 3.75 11
Vector_assign 0.35 0.35 4.96 3.19 1
No problemo, Mariner. I had edited my response after posting, which causes some of the problem. Thanks for suggesting LSSolve. Alas, an initial attempt with it returned the same result as with Statistics[Fit] (not too surprising). So I modified the approach, creating a function in terms of b:
residues := convert(map(unapply(y,x),X) - Y,list):
fit := proc(bval)
   Optimization:-LSSolve(residues, {b=bval})[1];
end proc:
I then plotted that from 0..3 (using discrete points to avoid taking too much time):
plot([seq([b,fit(b)],b=0..3,0.01)]);
The result looks something like an upside down sinc function. It has multiple local mimimums, which explains the problems. From the graph we see (well, I do, you'll have to plot it 8-) that the desired b is between 1.8 and 2.2. Adding that constraint gives
Optimization:-LSSolve(residues, {1.8 <= b, b <= 2.2}):
evalf[4](%); # elide digits for appearance
         [        -16                                              ]
         [2.941 10   , [c = 3.000, b = 2.000, d = 4.000, a = 1.000]]
I'll have to try this with the Global Optimization Toolbox (an add-on to Maple).
No problemo, Mariner. I had edited my response after posting, which causes some of the problem. Thanks for suggesting LSSolve. Alas, an initial attempt with it returned the same result as with Statistics[Fit] (not too surprising). So I modified the approach, creating a function in terms of b:
residues := convert(map(unapply(y,x),X) - Y,list):
fit := proc(bval)
   Optimization:-LSSolve(residues, {b=bval})[1];
end proc:
I then plotted that from 0..3 (using discrete points to avoid taking too much time):
plot([seq([b,fit(b)],b=0..3,0.01)]);
The result looks something like an upside down sinc function. It has multiple local mimimums, which explains the problems. From the graph we see (well, I do, you'll have to plot it 8-) that the desired b is between 1.8 and 2.2. Adding that constraint gives
Optimization:-LSSolve(residues, {1.8 <= b, b <= 2.2}):
evalf[4](%); # elide digits for appearance
         [        -16                                              ]
         [2.941 10   , [c = 3.000, b = 2.000, d = 4.000, a = 1.000]]
I'll have to try this with the Global Optimization Toolbox (an add-on to Maple).
The explanation is in the help page. Note the "note" that appears at the end of the Calling Sequence section. This has been expanded in Maple 11 to clarify. Maple 10: (Note: Phrases located between | | are optional.) Maple 11: (Note: Phrases located between | | are optional, and can appear in any order, except that the for clause, if used, must appear first.) What is easily overlooked is that only the the do and end do (or od, for those accustomed to the older syntax) are required. Here's a simple quiz to see how well you know the exit condition. Does the following loop terminate:
  by 0 to 1 do end do;
Can one figure this out be reading the help page? Another factoid that is overlooked is that one can loop over the characters in a string:
for char in "abcde" do 
  lprint(char);
end do;
You're welcome. The assumptions I gave could be slightly relaxed:
expand(-kT*ln(Q^N)) assuming Q::nonnegative, N::real;
                     -kT*N*ln(Q)
Another way to handle this is to use simplify/symbolic:
simplify(kT*ln(Q^N),symbolic);
                     -kT*N*ln(Q)
Expand needs more information:
expand(F) assuming Q::positive, N::positive;
                                   -kT*N*ln(Q)
Where is this post (on Legendre function)?
Where is this post (on Legendre function)?
They (op and selection operation, []) differ when the expression is not an "aggregate". For example, unevaluated functions, ranges, procedures, sums, products, etc.
Use &lt; to print the less-than sign in html. Otherwise your input disappears (as you see, or not). You could also change the Input format (below the window you type in) to "Plain Text".
First 175 176 177 178 179 180 181 Last Page 177 of 195