Carl Love

Carl Love

25249 Reputation

25 Badges

10 years, 230 days
Himself
Natick, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@sursumCorda According to the definitions and test code in this blog post "Programming Research Laboratory: Lexical and Dynamic Scope" by Ming-Ho Yee, Maple uses dynamic scoping. Yee's test code is

x <- 1
f <- function(a) x + a
g <- function() {
  x <- 2
  f(0)
}
g() # what does this return?

Translated into Maple:

restart:
x:= 1:
f:= a-> x+a;
      f := a-> x + a 
#Note the x in the displayed procedure

g:= proc() :-x:= 2; f(0) end proc:
g();
                               2

It makes no difference whether one uses proc or ->, or whether x is an environment variable or a regular global.

Yee says output 1 means lexical, and 2 dynamic.

If we make x into what Maple calls a lexical variable, the results are the same:

restart:
f:= proc(a) local x:= 1, f1:= a-> x+a, g:= proc(a) x:= 2; f1(a) end proc; g(a) end proc:
f(0);
                               2

This is all good, the way things should be.

If you want to force a global variable in a procedure to assume a certain value for all time, it can be done with subs:

restart:
x:= 1: f:= subs(_x= x, a-> _x+a);
      f := a-> 1 + a 
#Note the absence of _x in the displayed procedure

f(0);
                               1


The subs thing only works when _x is global.

@MaPal93 No, it's not necessary to first create a sequence of plots and then loop through them sending each to a file. And, if you do first create the sequence, it's not necessary to put it in an array (with the angle brackets); putting it into a list (with square brackets) works just as well. If your actual plots use a lot of memory, it might be beneficial to avoid the sequence. 

@MaPal93 Without delving into the details of your particular case (which I don't feel like persuing at the moment), I'll advise you thus: Any numeric value representing a plot coordinate can be replaced with the keyword 'undefined'. These will simply appear as nothing at all in the plot. Example:

restart:
f:= x-> piecewise(abs(x-3/2) < 1/2, 'undefined', x^2):
plot(f(x), x= 0..3);

@AHSAN Running your most-recent worksheet in Maple 2023 (with no changes!), I get the following plot. 

  1. Is this plot different from what you get (presumably in Maple 2022)?
  2. Is this plot (shown below) what you want to get?
  3. If not, then precisely how do you want the colors changed?

The cutting off of the third digits (the right side) of the legends is a separate issue.

In my worksheet itself, the above plot displays with a very ugly font used for the tickmark labels (but not the legend labels). I don't know why that is corrected by my context-menu Copy-As-Image followed by Ctrl-V paste into MaplePrime. Anyway, that's also a separate issue from the colors.

 

@achreftabet if we let k = i + j, then goes from 0 to n, and j = k - i. Then the sum can be obtained as 

add(add(a[i, k-i]*x^i*y^(k-i), i= 0..k), k= 0..n)

This assumes that n has a definite nonnegative value at the time the command is executed.

I didn't see your presumably deleted follow-up question, although I can see some possible loose ends in my Answer above. So, if you're having any trouble with that Answer, please ask here.

@sursumCorda I wonder what you mean by saying that `$` is a "lower-level command" (as compared to seq). If you mean simply that it has fewer options than seq, then that is true. But I can"t think of any other way that it could be considered lower level. 

I think that `$` is higher level because it allows for the abstract representation of infinite sequences and sequences with an indefinite number of terms. (Admittedly, those are quite easy things to do.) I make the formal analogy "`$` is to seq as sum is to add."

If you'd post a worksheet showing the error, there's a good chance that I could figure out the problem without even needing to unpack my computer, which'd be useful for me at the moment because I'm driving (at a rest stop at the moment).

@Rakshak As I said, you could plot the polar jets with plots:-tubeplot (which'll give you the most flexibility for color, etc.), or plots:-spacecurve, or plot3d with option style= wireframe. Then assemble all those static plots into a single static plot with plots:-display, and then plots:-animate with plottools:-rotate as shown above.

@acer IMO, if one is using 1D-input, then the expression-form for-while-do-until loop offers the greatest flexibility:

  • has a bona fide assignable return value;
  • can be used inside other expressions;
  • allows any extra statements inside without changing the return value and without changing the displayed values (unless that is desired);
  • allows any of the control structures that an ordinary do loop allows: whileuntil, multilevel break and next;
  • no detectable efficiency differences compared with seq or elementwise; in particular, expression sequences are built in linear, not quadratic, time.

Example:

Bools:= (
     for x in [0,1,2] do
         es1:= "extra statement 1";
         #Handle true/false/FAIL trichotomy: 
         if (b:= is(x in RealRange(Open(0), infinity))) then
             es2:= "extra statement 2"; 
             yes 
         elif b = FAIL then  #See 10th and 13th paragraphs of "Description" on the
             undecidable     #help page ?assume
         else
             es3:= "extra 3"; 
             no 
         fi 
     until b = FAIL
);
                     Bools := no, yes, yes

Indeed, this is the finest looping construct that I've ever seen in any language. Bravo, Maple kernel developers!

@Carlos36r printlevel is an all-or-nothing thing pretty much only suitable for debugging. It'll show the results of all statements executed at the given level or lower. Assignments to a for loop index are considered statements for this purpose, and, of course, that's useful information for debugging. 

There are several things that you could do instead:

1. Wrap the for loop in parentheses (only works in 1D-input AFAIK):

(for x in [0,1,2] do if is(x in RealRange(Open(0), infinity)) then yes else no fi od)  
                         
no, yes, yes

2. Use elementwise operators instead of a loop:

`if`~(is~([0,1,2], RealRange(Open(0), infinity)), yes, no)[]
                         no, yes, yes

3. Use seq (prefix-form looping operator):

seq(`if`(is(x in RealRange(Open(0), infinity)), yes, no), x= (0,1,2))  
                         
no, yes, yes

and others.

@vs140580 

[Moderator's comment: This Reply refers to a Reply that has been deleted.]

What you have written immediately above is highly specific to circulant graphs, whereas the rest of this thread is "pure" general combinatorics. Thus, if you'd like for these specific circulant-graph issues to be addressed, you should start a new Question thread. You've used circulant graphs as examples elsewhere is this thread; that's fine. However, in your most-recent Reply, they are not examples but rather the main issue.

Also, like I said before, please put the relevant parts of the text from your PDFs directly in your MaplePrimes's posts. If, in addition to that, you also want to attach the PDFs, that's fine.

@vs140580 You asked:

  • Which copy of C_4 represents with respect to which vertex if that can be told it will be great

If you could describe a method by which that can be known, then I'll include it.

  • Now put a new G and a new H it is taking sometime attached the same code with the new G and H

As I said, the method that I showed in the worksheet immediately above was not meant to be efficient. Its only purpose was for you to verify that its results were correct before I started working on a more-efficient version.

It's utterly impossible to use that worksheet on the problem that you're currently trying. You should kill it as soon as possible. It'll surely run out of memory and crash before finding a single cover. Here's why: |S| = 200 and n=10 (so, I guess that this is the example with which you started this thread). So, the number of n-subsets of S is binomial(200,10) = 22451004309013280 = 2.2 * 10^16 = 22 quadrillion. The worksheet tries to generate all those subsets before checking any of them.

  • Is it possible to print each IC cover set as it comes , as full excecution may take time I dont know if it is possible

In the code in the Answer (where G = K[n]), that's not possible because all the covers are built at the same time (with a loop that goes from 2 to n). In other words, the construction is "breadth first". That was the main thing that I did to improve the efficiency. Any branches that show violations of the singleton-intersection rule are pruned as soon as possible. This leads to a great reduction of the number of n-subsets of S that need to be checked. 

@vs140580 In order to make sure that I understand your requirements, I need you to verify the correctness of the following solution to your example of embedding C[4] in K[2,2,2]. I am not proposing this as an efficient solution technique; I just need to know whether its final result is correct before proceeding. This worksheet runs in under 5 seconds, and the result is 8 isomorphism covers.

restart:

Automorphs:= (G::Graph)->
local A:= op(4,G), n:= numelems(A), V:= [$n], p, E:= {seq}((op@`{}`~)~(V, A));
    {seq}(subs(V=~ p, E), p= combinat:-permute(n))
:

GT:= GraphTheory:  C:= combinat:

n:= 6:

H:= GT:-Graph([$n], {{1,2}, {2,3}, {3,4}, {4,1}}); #C[4]

GRAPHLN(undirected, unweighted, [1, 2, 3, 4, 5, 6], Array(1..6, {(1) = {2, 4}, (2) = {1, 3}, (3) = {2, 4}, (4) = {1, 3}, (5) = {}, (6) = {}}), `GRAPHLN/table/1`, 0)

G:= GT:-CompleteGraph(2,2,2); #K[2,2,2]

GRAPHLN(undirected, unweighted, [1, 2, 3, 4, 5, 6], Array(1..6, {(1) = {3, 4, 5, 6}, (2) = {3, 4, 5, 6}, (3) = {1, 2, 5, 6}, (4) = {1, 2, 5, 6}, (5) = {1, 2, 3, 4}, (6) = {1, 2, 3, 4}}), `GRAPHLN/table/7`, 0)

E:= GT:-Edges(G);

{{1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {3, 5}, {3, 6}, {4, 5}, {4, 6}}

S:= select(s-> s subset E, Automorphs(H)):

E:= `{}`~(E) union {{}}:

IC:= select(s-> (p-> `intersect`(p[]))~(C:-choose(s,2)) = E, C:-choose(S,n));

{{{{1, 3}, {1, 4}, {3, 5}, {4, 5}}, {{1, 3}, {1, 5}, {2, 3}, {2, 5}}, {{1, 4}, {1, 6}, {2, 4}, {2, 6}}, {{1, 5}, {1, 6}, {3, 5}, {3, 6}}, {{2, 3}, {2, 4}, {3, 6}, {4, 6}}, {{2, 5}, {2, 6}, {4, 5}, {4, 6}}}, {{{1, 3}, {1, 4}, {3, 5}, {4, 5}}, {{1, 3}, {1, 5}, {2, 3}, {2, 5}}, {{1, 4}, {1, 6}, {2, 4}, {2, 6}}, {{1, 5}, {1, 6}, {4, 5}, {4, 6}}, {{2, 3}, {2, 4}, {3, 6}, {4, 6}}, {{2, 5}, {2, 6}, {3, 5}, {3, 6}}}, {{{1, 3}, {1, 4}, {3, 5}, {4, 5}}, {{1, 3}, {1, 6}, {2, 3}, {2, 6}}, {{1, 4}, {1, 5}, {2, 4}, {2, 5}}, {{1, 5}, {1, 6}, {3, 5}, {3, 6}}, {{2, 3}, {2, 4}, {3, 6}, {4, 6}}, {{2, 5}, {2, 6}, {4, 5}, {4, 6}}}, {{{1, 3}, {1, 4}, {3, 5}, {4, 5}}, {{1, 3}, {1, 6}, {2, 3}, {2, 6}}, {{1, 4}, {1, 5}, {2, 4}, {2, 5}}, {{1, 5}, {1, 6}, {4, 5}, {4, 6}}, {{2, 3}, {2, 4}, {3, 6}, {4, 6}}, {{2, 5}, {2, 6}, {3, 5}, {3, 6}}}, {{{1, 3}, {1, 4}, {3, 6}, {4, 6}}, {{1, 3}, {1, 5}, {2, 3}, {2, 5}}, {{1, 4}, {1, 6}, {2, 4}, {2, 6}}, {{1, 5}, {1, 6}, {3, 5}, {3, 6}}, {{2, 3}, {2, 4}, {3, 5}, {4, 5}}, {{2, 5}, {2, 6}, {4, 5}, {4, 6}}}, {{{1, 3}, {1, 4}, {3, 6}, {4, 6}}, {{1, 3}, {1, 5}, {2, 3}, {2, 5}}, {{1, 4}, {1, 6}, {2, 4}, {2, 6}}, {{1, 5}, {1, 6}, {4, 5}, {4, 6}}, {{2, 3}, {2, 4}, {3, 5}, {4, 5}}, {{2, 5}, {2, 6}, {3, 5}, {3, 6}}}, {{{1, 3}, {1, 4}, {3, 6}, {4, 6}}, {{1, 3}, {1, 6}, {2, 3}, {2, 6}}, {{1, 4}, {1, 5}, {2, 4}, {2, 5}}, {{1, 5}, {1, 6}, {3, 5}, {3, 6}}, {{2, 3}, {2, 4}, {3, 5}, {4, 5}}, {{2, 5}, {2, 6}, {4, 5}, {4, 6}}}, {{{1, 3}, {1, 4}, {3, 6}, {4, 6}}, {{1, 3}, {1, 6}, {2, 3}, {2, 6}}, {{1, 4}, {1, 5}, {2, 4}, {2, 5}}, {{1, 5}, {1, 6}, {4, 5}, {4, 6}}, {{2, 3}, {2, 4}, {3, 5}, {4, 5}}, {{2, 5}, {2, 6}, {3, 5}, {3, 6}}}}

 

Download IsoCovers.mw

Also, please post the text from your PDFs directly in MaplePrimes. If you want to also attach the PDF, that's okay, but I'll like the text (regardless of its formatting) to be in MaplePrimes.

@Carl Love By implementing a large number of small efficiencies, I've made IsoCovers twice as fast as the version that I posted yesterday. The new code is in the Answer immediately above.

1 2 3 4 5 6 7 Last Page 1 of 656