mmcdara

7891 Reputation

22 Badges

9 years, 54 days

MaplePrimes Activity


These are replies submitted by mmcdara

@Carl Love 

 

Perfect.
I observe that, at the same time, you have corrected your unitial set of procedures to account for bases greater than 4.
I had observed last night (its 8:30 am here) that you first code didn't returnd the correct Matrix for base 7 but it was two late to warn you about that.

On top of that your module uses a lot of technical stuff I didn't know about. It will probably take me some time to understand it correctly, but I think I will learn a lot from it at the end


Bravo!






 

@Carl Love 

If you want to go the polynomial route, use PolynomialTools:-FromCoefficientList rather than series.
No, not necessarily, it was just my initial attempt but your procedures suit me perfectly.

If you have foreknowledge of the overall maximum list length needed
I don't have any prior idea of the this value. I want to study those special matrices of dimansion base^K where K is some "smal" positive number, lets's say 3 or 4, no more.
Then you can consider that the overall maximul list length doesn't exceed 4

 It appears that for your work that there is such foreknowledge.
Right. These matrices probably first appeared in game theory. One can also relate them to some cryptography problems: In this later case I guess one can imagine huge matrices (K large), but I'm still in a prospective stage where I'm looking to these matrices as potentially usefull tolls. 
To investigate this the restriction K<=4 is sufficient. 
You can find a situation where the matrix Matrix(3^2, 3^3, (i,j) -> Nim(i-1, j-1, 3)) appears in 
 http://web.mit.edu/sp.268/www/nim.pdf


I need for you to clarify if a "carry" operation for the addition is needed when the base is greater than 4.
Right again
You raise two points: the one of the carry and, behint it, the value of the base.
Second point first: the base has to be a prime number.
First point: there is effectively an issue when the base is greater or equal to 5... but the additions have to be done withour carry. 
Here is an example with base 7, A=13 and B=27
A = [1, 6] mod 7    (convert(A, base, 7)=[6, 1])
B = [3, 6] mod 7    (convert(A, base, 7)=[6, 3])
A+B = [4, 12]         (bitwise "no carry addition" in base 10)
A+B  mod 7 = [4, 5]
A+B = 33   in base 10

WATCH OUT : I focuse only on bases 2 and 3, then I'm not sure that my procedures return the good matrices for bases greater or equal to 5 !

I hope I have answered to your probing questions.


For information
The alternative ways to generate such matrices start from the "generator" G := Matrix(N, N, (i,j) -> Nim(i-1, j-1, N)) (N being the base, 3 in my initial post) and by using the KroneckerProduct. Their complexities can be easily established.
This product, also termed sometimes "tensor product", makes a (still unformal) connection between these matrices and  tensor product of graphs.

@Carl Love 

(I'm sand15, now out of the office and at home) 

Yes, it's ok.
Here is the matrix I want to construct :

N := 3: # base
K := 3:
interface(rtablesize=N^K):
M := Matrix(N^K, N^K, (i,j) -> Nim(i-1, j-1, N))


Even if the "plus" operation is the standard way to constructthis matrix M (for different values of K), I was able to derive different alernate ways to build M.
For instance the procedures A and B below 

A := proc(n,k)
  local G, B, un, i:
  uses LinearAlgebra:
  G := Matrix(n, n, (i,j) -> (i-1)+(j-1) mod n):
  B := copy(G):
  un := m -> Matrix(m, m, 1):
  for i from 1 to k do
    B := KroneckerProduct(un(n^i), G) +~ KroneckerProduct(n *~ B, un(n))
  end do:
  B;
end proc;


Or again, after having resolved the recurrence relation 
B := proc(n, k)
  local G, un :
  uses LinearAlgebra:
  G  := Matrix(n, n, (i,j) -> (i-1)+(j-1) mod n):
  un := m -> Matrix(m, m, 1):
  add(n^p *~ KroneckerProduct(KroneckerProduct(un(n^(k-p)), G), un(n^p)), p=0..k)
end proc;


A(N,K) = B(N, K) = Matrix(N^K, N^K, (i,j) -> Nim(i-1, j-1, N))


For information, my coding for the direct building of the matrix  was 
C := proc(n, k)
  local a, b, sa, sb, pa, pb, pc, c:
  M := n^k:
  U := Matrix(M, M);
  for p from 0 to M-1 do
    for q from 0 to M-1 do
      a   := convert(p, base, n);
      b   := convert(q, base, n);
      sa  := gfun[listtoseries](a, x, 'ogf');
      sb  := gfun[listtoseries](b, x, 'ogf');
      pa := convert(sa, polynom):
      pb := convert(sb, polynom):
      pc  := pa + pb mod n;
      c   := subs(x=n, pc);
      U[p+1,q+1] := c;
      U[q+1,p+1] := c;
    end do:
  end do:
  U
end proc;


And here again C(N, K) is equal to M

I wasn't happy of the procedure C which seems to make a moutain of a molehill ...  
Your solution seems clever. Nevertheless I'm not sure we can answer the question without making a detour via polynoms (your B10 procedure seems rather close to my "pc := ...; and c:= ...; above).

I will finally adopt your solution.

Thank you for your time

 

 

@Markiyan Hirnyk 

Probably nothing with Maple.
But Adam Ledger's post was about induction and acer's answer stressed the difference between inductive reasoning and mathematical induction. Then maybe my comment could have something to do with the post.

Everyone reading a post or a question can adopt different attitudes, from the active support to the "I'll pass, this-question-is-not-for-me stance". 
This is all the more easy than the post refers directly to Maple, which is not the cas here.
But the duty to everyone who engage in a discussion is to be respectful of the others. 

What is the purpose to write "I understood nothing from your post. I find the post useless for me. Who is it aimed at?"
To be clear, ii is not because the post is useless for you that you have to write it this way.
A far more intelligent attitute is to remain silent.

I engage you ro read Wittgenstein and to meditate this ctation of his "Whereof one cannot speak, thereof one must be silent."

With kind regards

@acer 

BTW: I would have like to thumb-up but for some unknown reason it doesn't work.
I'll try later

@acer 

I've just read again the help page about "assume(is)"
In the "Calling Sequence" section it is written  is(x1, prop1);
When you write

is(sin(x)^2+cos(x)^2, 1);

it seems that this must be interpreted as "does sin(x)^2+cos(x)^2 (=x1) has the the property 1 (prop1) ?".
If it is so then
1/ I understand why 

is(1, sin(x)^2+cos(x)^2)

returns an error (in fact the question is stupid)

2/ I understand why is~(A,B) returns a matrix full of "true".

Generally I use "is" only with sthe syntax is(x1::prop1).
Here again (i'm not looking to be right), but  is(x1::prop1) seems a more "rigourous" syntax than is(x1, prop1) is.


I keep finding the  `.` operator is sneaky.
On one side it classicaly denotes  the "dot product" and could confuse people. On the other side, to have been introduced, how much, 25 years ago (?) doesn't mean it has to be maintained. I remember that when Maple 8 appeared a lot of syntaxes became obsolete (I believe to remember that the concatenation operator went from '.' to '||') and there was even an assistant to help updating worksheets.

The last point concerns  overload, the help page of which I've just read.
Probably powerfull but it reminds me those "commmon" an "equivalence" declarations of the past versions of FORTRAN. Very powerfull indeed because they enabled to share the same memory location between different variables.
At least as long as you do not want to use a debugger


As a Maple's specialist you know perfectly how to use correctly all those "borderline" commands. But for many users they look more like booby-traps than safe commands.
More generally, I dream sometimes of a Maple's version where there would be only one syntax to do an operation and not several variants, some obscure. And of course of a version which stops  to keep proposing "small" plot and "capital" PLOT ... a real mess.

But do not take this as a declaration of war.
Despite what I personally consider as defaults, I don't think I could do without Maple.

Thanks for all the time you wasted to deliver me such lenghty answers
 

 

 

@acer 

Thank you acer for this quick and detailed answer.

A few points nevertheless :

1/ "That's what the tilde specifies -- an element-wise application of the is command." ok, I agree, but why is~(A,B) understand that I want to realize  "is A = B element-wise?"
Why is~(A,B) would not mean "is A <> B element-wise?" or  " is A > B element-wise?" ot anything else?
The fact is that "=" is never specifiedat the help pages for "is" don't seem to mention this syntax.
I understand why is~( `=`~(A,B)) works correctly, but I stil don't understand why is~(A,B) does.

2/ I just take a look to coercion. I already heard about the word but never focused on it. I'm not going to pretend I correctly understood the help page but I will do some examples to clarify all of this.

3/ You made me discover the element wise "A . A" for arrays.
I would have written A *~ A for my own (and I think I will keep doing it).
Don't you think that these kind of shortcuts are detrimental to the consistency of Maple ?

4/  What  does "overload" mean in the tdeclaration of the procedure ?

Thanks again

Not the clash of the civilizations nor the one of the ancients and of the moderns, but definitely a dialogue of the deaf.

In 1976 Imrè Lakatos published "Proofs and Refutations" (Cambride Univ. Press), with this subtitle (at least in the french version) 
"An essay about the logic of mathematical discovery".
This is a very fascinating book that a lot of researchers in mathematics teaching have read (but probably not enough).
The distinction between induction and proof is clearly made by Lakatos, but he doesn't reject the the power of the former and its role to move toward the later.

In this book Induction has a sense which, I believe is closer to what I understand from your post, than to the sense Acer is referring to (which is closer to the proof)


Not sure that this comment contributes to increase the mutual comprehension ? 
 

@Carl Love 

Hi Carl, 

to end this discussion, here is a reference book:

The Elements of Statistical Learning, DAra Mining, Inference and Prediction
T. Hastie, R. Tibshirani, J. Friedman
2009, Springer Series in Statistics
2nd edition
https://web.stanford.edu/~hastie/Papers/ESLII.pdf



Paragraph 8.2.2 "Maximum Likelihood Inference"
p 265 : (middle of the page) "Maximum likelihood is based on the likelihood function, given by L(theta; Z) = " (formula 8.11)
The line below "The likelihood [here the term "function" is ommited is defined only up to a positive constant" (which answer your interrogation about 1/sqrt(2*Pi) )
Below "... the logarithm of L(theta; Z) [the likelihood function] .... is called the log-likelihood [not the "log-likelihood function"].
Top of page 266 : "Assuming that the likelihood takes its maximum in the interior ...": strictly speakig the authors should have say "Assuming thet the likelihood function takes ..."

In Statistics, even among its most prominent representatives, "likelihood" is very common shortcut for 'likelihood function".
Which doesn't mean there are right and, I agree that "Upto my understanding of this subject, which is admittedly weak, the likelihood function is only properly defined for distributions with at least one symbolic parameter."

Have a good weekend

@vv 

 

I eventually found a loophole which works with Maple 2016
(not very happy of the colors ...)

 

p := proc(k)
  local M, F:
  M := Matrix(8, 8, (i,j) -> i+j+k mod 3):
  F :=  (i,j) -> `if`(M[i,j]=0, 0.999, 0.25);
  plots[matrixplot](M, heights=histogram, axes=frame, gap=0.25, color=F, orientation=[0, 0, 0], lightmodel=light4)
end proc;

plots[animate](p, [ceil(k)], k=0..3);

 

@vv 

PS : it doesn't work in Maple 16 

Error, invalid input: too many and/or wrong type of arguments passed to Explore; first unused argument is k = 0 .. 8

No problem, I'm going to palm my spouse's Mac (it uses Maple 2017 :-) )

 

@vv 
(yes, I'm sand15, now at home for a long weekend)

Thanks for your answer.
I have unsuccessfully tried to use Explore. But looking to your answer shows me I didn't do the things correctly anyway.

I will try your solution during my rest time.
Have a good weekend too

The attached file contains a short comparison of the performances between different ways to do the same operation.
It uses the package CodeTools, a package I often uses to (try to) do efficient coding 

Could_help_adds.mw

@Carl Love 

Maybe.

Concerning the error the OP gets 

Error, (in pr) unable to evaluate 5-A[2] to floating-point

it comes from the fact that each A[i] is a random variable, thus N-n-add(A[j], j=1..i-1) has no sense (note the OP has written A[i] which, I guess, is a typo error).

I don't understand the meaning of r[1] := convert(BinomialRandomVariable(N-n,P),`+`);
If the OP wants to declare r[1] as a Binomial RV, r[1] := BinomialRandomVariable(N-n,P); is sufficient.

Following your idea, maybe the line  A[i-1] := convert(r[i-1], `+`)  should be replaced by A[i-1] := Sample(r[i-1], 1)[1] ???

Then I wonder if the OP wouldn't want to generate a random walk ?

But for sure, some clarification is required.

 

 

 

@vv 

Very astute indeed!

First 143 144 145 146 147 148 149 Last Page 145 of 154