Carl Love

Carl Love

28020 Reputation

25 Badges

12 years, 302 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@vs140580 You didn't answer my second question: Does trunc~(A) do what you want?? If that doesn't help, how about

trunc~(rtable(A, datatype= anything));

@AmirHosein Sadeghimanesh You wrote:

  • Recently a colleague showed me that it is better to use `__i` instead of `[i]` for indexed variable names.

I wouldn't categorically say that one is better than the other: They each have their uses. One thing that you can never do is make independent assignments to both and x[i], but you can do it with x and x__i.

Your cat(j, '__', i) can be replaced by cat(j__, i). One drawback to using cat is that the variables so constructed are always global. This is true of all programmatically constructed names, regardless of whether the construction is done with catnprintf||, or parse.

@lcz I certainly expected some comments on this procedure.

@dharr You wrote:

  • Code Edit Regions are similar regions embedded in the worksheet, with full error messages (but not error location).

Embedded Code Edit Regions also use the red wiggly underlines, although they may be small and difficult to see.

Perhaps you need to specify where on your computer "networkx" is stored.

1. Could you show in a Maple worksheet an example of the type of Python output you're referring to?

2. Does trunc~(A) do what you want?

Did you mean for x to be k? In that case the product is n!. If not, the product is x^n, but is undefined. 

@Earl 

&under is documented in the last paragraph of the "Description" section of help page ?type,structure. You can also get a full understanding of it by expanding its trivial one-line code:

showstat(`type/&under`);

Please post your code as plaintext, not as an image! I don't feel like re-typing it!

@Carl Love [The code of this Reply requires Maple 2019 or later and 1D input.]

The 2nd differences (or 2nd discrete derivative) of the sequence 2*k^2 is 4. This is obvious by some small hand calculation, and it can also be verified by any of these three methods:

DiscreteDiff:= (f::{list(algebraic), algebraic}, n::seq(name))->
local r:= `if`(f::list, f[2..]-~f[..-2], eval(f, [n][1]= [n][1]+1) - f);
    `if`(nops([n])=1, r, thisproc(r, n[2..]))    
:
A:= [seq](2*k^2, k= 0..9);
          A := [0, 2, 8, 18, 32, 50, 72, 98, 128, 162]

DiscreteDiff(A, k$2);
                    [4, 4, 4, 4, 4, 4, 4, 4]

simplify(rsolve({DiscreteDiff(S(k), k$2) = 4, S(0)=0, S(1)=2}, S(k)));
                                 2
                              2 k 

simplify(DiscreteDiff(2*k^2, k$2));
                               4

This knowledge can be used in the Verify procedure thus:

Verify:= proc(N::And(odd, positive, Not(1)))
local n:= N, k:= -2;
    do if isprime(n) then return true fi until (n-= (k+= 4)) < 0;
    false
end proc
:

 

@student1EE You're welcome. It's a very easy mistake to make. Like I said, there are situations where it is appropriate to redefine a symbol. Whether it's appropriate almost always depends on how you want to affect the human readability of the code. Controlling the order of evaluation is the usually the more-appropriate way to affect how Maple interprets the code.

There's a lot of subtle and likely new-to-you information in the Answer above. I'd be happy to answer any follow-up questions that you have about it.

@dharr I suspect that that strange vector substitution was merely the OP's futile attempt to work around the bug.

A workaround that I think will work in almost any Maple version that has this bug is

subs(Pr= P[convert(r, `local`)], H)

if you want the subscript r and the naked r to be considered as completely independent entities.

 

@Anthrazit Assuming that you have a set a containing only strings that you want to sort into standard order (with respect to the ASCII collating sequence), all that you need to do is

sort([a[]]) 

Note that that collating sequence places all lowercase letters after all uppercase letters.

Option lexorder is superfluous for this purpose. 

A set a can be converted to a list simply by [a[]].

If you want to put the strings into alphabetical order with respect to an alphabet that contains non-ASCII characters, such as may be used in your native language, you'll need to pass a collating procedure to sort. Of course, once this procedure is written, it can be used for all your string sorting.

There's no point in using sort with a first argument that is a set since, by design, you cannot change the order of the items in a set. IMO, it should be an error, or at least a warnable condition, to even try it; unfortunately, it is not an error.

There's no point in the average user (who's not delving deeply into Maple's internal structures) trying to understand the specifics of set order. The important things to know are just that there is a set set order that's more-or-less session independent[*1] and that having a specific order greatly improves the efficiency of set operations (=, insubsetunionintersectminus).

Like Tom and the help page say, it's a poor programming practice to assume a certain set order; however, in my personal opinion (only), it's safe (and very often useful) to assume that single-word-sized integers will appear in numeric order in a set. I don't think that it's safe to extend that idea to other numeric types, and it's certainly not safe to extend it across different numeric types (e.g., integer[*2]fractionfloathfloat).

Warning: In my opinion, the only safe and legitimate purpose of the information in this paragraph is to make a robustness test of a program against the possibility that it has implicitly made an inappropriate assumption about set order: It is possible to change the set order to either address-based or to one of eight session-independent[*1] orders. The order can only be changed from a shell command line used to initiate Maple. See section setsort on help page ?maple.

[*1] Regarding session independence: As noted on help page ?set, it is sometimes necessary, as a last resort, to make an address-based collating decision. In those cases, the set order may not be fully session independent.

[*2] For historical reasons, negative and nonnegative integers are actually stored as distinct fundamental types (INTNEG and INTPOS). I think that this distinction makes no difference to the set order, and I'm almost certain that it makes no difference for single-word-sized integers.

@vv Yes, I like it! It's definitely better than mine  I had forgotten about the possibility of using single quotes as an ephemeral grouping operator. 

 

@impostersyndrome 

I came up with a shorter formula for your permutation. It's conceptually and algebraically simpler, although it may appear a bit more complex to you due to your (perhaps) unfamiliarity with Maple's elementwise syntax (applying an operation to all elements of a container with ~).and arrow operator syntax (x-> e is equivalent to proc(x) e end proc for expressions whose only dependencies on x appear explicitly. The left side of the arrow can contain multiple symbol variables with or without typespecs such as (x::posint, y::realcons)-> ...):

eq_arrangement:= (k::posint)-> k +~ (i-> (-1)^i*iquo(i,2))~([$1..2*k-1]):

Note that this formula doesn't require special treatment of the 1st element, k. The iquo is fast integer division with discarded remainder. To me, it's conceptually simply than the "shuffling" of your procedure, although opinions may vary on that. 

I'm still guessing that you'd like to find the relationship between and the order of the permutation. Let me know. I've written some tools to explore that, but they're difficult to post from my phone.

First 128 129 130 131 132 133 134 Last Page 130 of 708