acer

32470 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Do you just want something that works? Or do you want something efficient for really large numbers of intervals?

If you know that a < c <... and b < d < ... then you could do a discrete binary search (over, say, the lower interval values).

What do you know about a,b,c,d,...?

Suppose the intervals are distinct and not overlapping, which makes it easier. Sort them by interval lower value. Then take the middle of those (ie. 5th of 9, not closest to numeric midpoint of upper and lower range bounds). Is x larger or smaller than the lower interval endpoint of the middle interval? The answer tells you which half of the set of intervals x belongs to. (Maybe check also whether x is inside that middle interval.) Repeat this whole process, on just that half of the set of intervals. And repeat...

acer

What are the dimensions of data?

[edited] I wrote something not right here. But I see that you figured it out, that something was being accessed with an index out of bounds.

acer

We already did.

acer

Let's call the encrypted string S and the decrypted original Q. There is a double e (ee) in the S. So that's probably not blank in Q, because the phrase wouldn't have a double blank.

What letter falls enough times at a pretty regular frequency in S, that might be the blank in Q? From the above, it isn't e. Assume that it's a.

Now, what does the e in S become in Q? What letters can occur in doubles? Perhaps o, or l, or s. But e occurs often in S. So it is probably a letter in Q that usually occurs often. Suppose that e in S is o in Q.

You said that the alphabet to use is " abcdefghijklmnopqrstuvwxyz".

Consider the guess a -> blank and o -> e. That means that you need a function finv (x) such that finv(1)=0 and finv(15)=5. In modular terms,  you would have,

finv(x):: x -> (a*x + b) mod 27

15 = (a*5 + b) mod 27
0 = (a + b) mod 27

If you solve that, you should get a=24 and b=3. But a has to be coprime to 27 for an affine cipher! Oops. So the guess is wrong.

How about the guess that e in S is actually e in Q as well. There are words that end in double e. (I'll be nice, this leads to the solution, if you solve the pair of modular equations using finv(1)=0 and finv(5)=5.)

In Maple, once you have the a and the b,

S := "fmw segjaweoouanerj a ceyqrype aswaheoaqbrqabeafrua eeaojerf afmjeayperjpu":

with(StringTools):

abet := " abcdefghijklmnopqrstuvwxyz":
L := Explode(abet):

f := x -> 1/a*(x-b) mod 27:

nL:=[seq( L[f(i)+1], i=0..26 )];
nabet:=Implode(nL);

CharacterMap(nabet,abet,S);

nb.  Using Joe's  set-up above, you'd  apply  finv := x -> A*x+B mod 27 with his A and B instead of my f using my a and b. Both solve it.

acer

It depends on how big the number is. I should have scaled n by 1.0 inside the log call.

> restart:
> n:=77^898789:
> f1 := x -> floor(log[10](1.0*x)/3.):
>  time( f1(n) );
                                     0.156

> n:=77^898789:
> f2 := x -> iquo(ilog10(x),3):
> time( f2(n) );
                                     0.066

Once the numbers get into the few millions of digits, the timing difference starts to show.

acer

The problem that you describe can occur if you fail to create a Library archive (.mla) in which to savelib.

See either the ?march or ?LibraryTools:-Create help-page.

When there is no available .mla archive file in which to save, the contents will get written out to a .m file. But that .m file will only contain a "shell" of the module, in your case, and not the whole thing.

acer

> f := n -> map(parse,[StringTools[LengthSplit](convert(n,string),3)]):
 
> f(394737234242);
                             [394, 737, 234, 242]
> g := proc(n::integer)
> local i, r, p;
>     r := n;
>     for i to floor(log[10](n)/3.) + 1 do
>         p[i] := irem(r, 1000, 'r');
>     end do;
>     convert(p,list);
> end proc:

> g(394737234242);
                             [242, 234, 737, 394]

Those are just two of many different fun ways to do this in Maple.

acer

> maximize(x*exp(-x),location);
                         exp(-1), {[{x = 1}, exp(-1)]}

> Optimization:-Maximize(x*exp(-x),x=-10..10);
               [0.367879441171442334, [x = 1.00000001071262612]]
 
> Optimization:-Maximize(x*exp(-x),method=nonlinearsimplex);
                       [0.367879441171442334, [x = 1.]]

acer

> M:=Matrix(3,4);
                                 [0    0    0    0]
                                 [                ]
                            M := [0    0    0    0]
                                 [                ]
                                 [0    0    0    0]
 
> M(4,1..):=<1,2,3,4>:

> M;
                              [0    0    0    0]
                              [                ]
                              [0    0    0    0]
                              [                ]
                              [0    0    0    0]
                              [                ]
                              [1    2    3    4]

acer

Start off with a character mapping that does nothing, and which maps abc...XYZ to itself. Make small changes to this, to get going with it. A single letter following an apostrophe is very likely an "s". The sequences "rWB" and "AWB" are likely "she" and "the", but you have to guess which. Single letter words are likely "a" or "I". Words of just two letters are likely "on", "in", "to", "of", "is", "be" or "at". If you're lucky then some of these easier short word guesses can be considered together. Just keep refining the mapping with guesses, and back out any guess that undoes something you're already confident about. Eventually you can guess whole words and thus deduce the remaining letters.

S := "wA'r aBeD WUeK AP XNaB NM U rALK\
NP USUeAJBMA NM zUM nPrB ZNAW U JUM ZW\
P'r XBUeMNMO AP SXUD AWB aNPXNM. yWUA'\
r ZWUA rWB APXK AWB SPXNCB ZWBM rWB WU\
MKBK AWBJ AWB BJSAD eBaPXaBe. lNCWUeK heULANOUM, yWB zCUeXUAAN yNXA";
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopqrstuvwxyz",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzA","abcdefghijklmnopqsstuvIxyzt",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAU","abcdefghijklmnopqsstuvIxyzta",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUP","abcdefghijklmnopqsstuvIxyztao",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMN","abcdefghijklmnopqsstuvIxyztaono",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMN","abcdefghijklmnopqsstuvIxyztaono",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMN","hbcdefghijklmeopqsstuvIxytttoeb",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMN","hbcdefghijklmeopqsstuvIxytthoeb",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWB","hbcdefghijklmeopqsstuvIxytthoebot",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWB","hbcdefghijklmeopqsstuvIxytthoebhe",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWB","hbcdefghijklmeopqsstuvIxstthoebhe",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWB","tbcdefghijklmeopqsstuvIxstthoebhe",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJ","tbcdefghijklmeopqsstuvIxstthoebhem",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJ","tbcdefghijklmeopqsstuvIxsttaoebhem",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJ","tbcdefghijklmeopqsstuvIxtttaoebhem",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJ","tbcdnfghijklmeopqsstuvIxtttaoebhem",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJ","tbcdefghijklmeopqsstuvIxtttaonohem",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJB","tbcdrfghijklmeopqsstuvIxtttaonoheme",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZ","tbcdrfghijklmeopqsstuvIxtttaonohemeb",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZK","tbcdrfghijklmeopqsstuvIxtttaonohemebd",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKX","tbcdrfghijklmeopqsstuvIxtttaonohemebde",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdrfghijklmeopqsstuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdmfghijklmeopqsstuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdrfghijklmeopqsstuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdmfghijklmeopqsstuvIxbttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdmfghijklmeopqssbuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdrfghijklmeopqssbuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdrfghijklmeopqIsbuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdrfghijklmeopqssbuvIxtttaonohemebdeyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdrfghijklmeopqssbuvIxtttaenohemebdeyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdofghijklmeopqssbuvIxtttaenohemebdeyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdrfghijklmeopqssbuvIxtttaenohemebdeyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXD","vbcdrfghijklmeopqssbuvIxtttaonohemebdey",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdrfghijklmeopqssbuvIxtttaonohemebdeyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDS","vbcdrfghijklmeopqssbuvIxtttaonohemebdlyp",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSO","vbcdrfghijklmeipqssbuvIxtttaonohemebdlypg",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSO","vbcdrfghijklmeopqssbuvIxtttaonghemebdlypg",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSO","vbcdrfghijklmeopqssbuvIxtttaonihemebdlypg",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtttaonihemebdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqsswuvIxtttaonihemebdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtttaonihemebdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtttaonihemewdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtntaonihemewdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtntaonihemewdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmeopqssbuvIxtstaonihemewdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOL","vbcdrfghijklmJopqssbuvIxtStaonihemewdlypgu",S);
StringTools:-CharacterMap("abcdefghijklmnopqrstuvwxyzAUPMNWBJBZKXDSOLC","vbcdrfghijklmJopqssbuvIxtStaonihemewdlypguc",S);

And finally, if you get bored, feed key bits of what you have into google (it's clearly a  quotation),

S := "wA'r aBeD WUeK AP XNaB NM U rALK\
NP USUeAJBMA NM zUM nPrB ZNAW U JUM ZW\
P'r XBUeMNMO AP SXUD AWB aNPXNM. yWUA'\
r ZWUA rWB APXK AWB SPXNCB ZWBM rWB WU\
MKBK AWBJ AWB BJSAD eBaPXaBe. lNCWUeK heULANOUM, yWB zCUeXUAAN yNXA";

StringTools:-CharacterMap("abcdefghijk\
lmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW\
XYZ","vbcdrfgBijkRmJopqssbuvIxTStecyEFGHImdunigoQRpTaVhlYw",S);
"It's very hard to live in a studio apartment in San Jose with a man who's \
    learning to play the violin. That's what she told the police when she h\
    anded them the empty revolver. Richard Brautigan, The Scarlatti Tilt"

acer

Right, there is a "lessthan" structure, but no "greaterthan" structure. You have noticed that Maple only needs one such beast in order to get by.

> x:=a>b;
                                  x := b < a

> dismantle(x);

LESSTHAN(3)
   NAME(4): b
   NAME(4): a

See the ?dismantle and related help-pages for an introduction to Maple structures. The Advanced Programming Guide may also be useful to you for learning about Maple's internal structures.

acer

interface( rtablesize=50 );

p := randpoly(R,dense,degree=15);

Matrix( [Vector(degree(p)+1,i->i-1),
         PolynomialTools:-CoefficientVector(p,R)] );

Matrix(degree(p)+2,2,
       [[Matrix([n,a[n]])],
        [Matrix([Vector(degree(p)+1,i->i-1),
                 PolynomialTools:-CoefficientVector(p,R)])
        ]]);

Or, with more columns,

restart:
interface( rtablesize=50 ):

p := randpoly(R,dense,degree=15):

V1 := Vector(degree(p)+1,i->i-1):
V2 := PolynomialTools:-CoefficientVector(p,R):
V3 := Vector(degree(p)+1,i->93):
<<n|a[n]|"3rd">,<V1|V2|V3>>;

acer

You could apply evalf to the indexed RootOfs, to get floating-point approximations.

acer

The total derivative of h(x,y,z) is usually taken to refer to an independent variable (let's call it t, though it may in fact not represent time). The premise is that the other variables depend upon this t. And then the total derivative is taken to be,

   del h/del t
 + del h/del x * del x/del t
 + del h/del y * del y/del t
 + del h/del z * del z/del t

Now, either you have in mind that there is some variable t upon which each of x,y,z depend, or you consider that two of x,y,z depend upon the third, eg. x(z) and y(z). If it's the latter situation, h(x(z),y(z)) say, then the total derivative may be taken as,

   del h/del z
 + del h/del x * del x/del z
 + del h/del y * del y/del z

Is either of those the case at hand?

ps. It doesn't look like what is commonly termed a vector-valued function, and the Jacobian may not be what you're after.

acer

It should be possible to change Maple's Standard GUI so that it will compress/decompress worksheets on the fly.

It would be preferable if such a change still allowed one to save worksheets as uncompressed XML.

Such files could have an extension such as .mwz. Hopefully that natural choice of filename extension hasn't been exclusively preempted.

acer

First 309 310 311 312 313 314 315 Last Page 311 of 337