Carl Love

Carl Love

28150 Reputation

25 Badges

13 years, 351 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Thomas Dean You (as well as isolve) are interpretting "solution" to mean any 4-tuple (a, m, n, x) of integers that satisfy the equation. It's obvious that given any integers a and x with a <> x we can find a 1-dimensional infinite family of pairs of integers (m, n) such that (a, m, n, x) satisfy the equation. However, that's not what the OP means by "solution". By "solutions" they mean the values of x alone. Given any (a, m, n) with a <> 0, the resulting equation is quartic in x. The OP wants to know if that quartic has 4 integer solutions for x.

@greatpet The behavior of series is exactly the opposite of what you say. The order argument does specify (one more than) the maximum power. It does not specify the number of terms.

@tomleslie Vote up.

If someone wants an alternative with much less typing, at the expense of slightly more-complicated code, do this:

(f, g, h):= (0.5*x, sqrt(0.81-(x-2)^2), sqrt(3.57^2-(x-8)^2));
plots:-display(
    Student:-Calculus1:-SurfaceOfRevolution~([f,g,h], x= 0..10, output= plot),
    transparency= 0.5, scaling= constrained, color= [red, green, blue],
    caption= `` 
);

 

@nm On the help page ?rtable_indexing, in the section "Selecting Elements: Extracting Subblocks", the 4th paragraph is

  • The result of subselection A(i1, i2,  .. , iN) on an N-dimensional array is not the same as the indexing with square brackets.  In this case, the number of dimensions of the result will correspond to the location of the last non-singleton index.  That is, if the ith index is the last non-integer index then the result will have i dimensions.

I think that this completely addresses the Question at hand. However, why this design decision was made is another matter.

@AHSAN In that case you use

for n from 20 to 30

I don't think that you understand what "default" means. It means a value that will be used if and only if no other value is given. If a value is given, it takes precedence over a default. 

@AHSAN 

The from clause of a do loop is optional and defaults to from 1. Indeed, all clauses of a do loop are optional (for, from, by, to, in, while, until).

@tomleslie It's clear from the title that the OP wants to integrate with respect to time, not distance.

@Carl Love 

Here's another way that uses a feature of int that is added by loading the Units:-Standard package:

with(Units:-Standard): 
Int(10*Unit(m/s^2), t*Unit(s));
value(%);

The reason that I didn't mention this before is that the inert Int gets prettyprinted in an inelegant way, which you'll see when you execute the code. This inelegancy only affects the display, not the computation. Despite that, it seems the closest to what you were trying. Still, I'd use the Intat.

@acer 

The reason that I didn't use Typesetting is that the objects it produces are type function, not type symbol or name. Thus there are numerous contexts where they can't be used, such as a variable of integration; and there are other contexts where they silently behave in different and undocumented ways, such as a bound variable in solve.

@Johan159 

Yes:

phi:= `#mo("phi", mathcolor= black)`;

@Gillee Considering the extent of programming involved in this Answer and the degree of efficiency improvement attained, I think that it deserves a Vote up (thumb icon in upper right corner).

I realized that compiled code recognizes parity checks (::odd, ::even), and by using these as a replacement for mod 2, I reduced the total time to 7 seconds. Again, that's the total time using a single processor. It should be possible to parallelize this (e.g., rowwise), but I have yet to get it to work with Threads.

I also added comments that explain the arithmetic.

restart
:
BuildA_M:= proc(
    A::Array(datatype= integer[4]), M::Array(datatype= integer[4]),
    r::integer[4]
)::integer[2];
local 
    i0::integer[2], i::integer[2], j0::integer[2], j::integer[2],
    m::integer[2], t0::integer[2], t::integer[2],
    p::integer[2], #parity (1=even, 0=odd) of 1 bits in a word
    Z::integer[2] #count of 0s
;
    for i0 to r do for j0 to r do
        Z:= 0; 
        for t0 to r do
            p:= 1; i:= i0-1; j:= j0-1; t:= t0-1; m:= M[t0];
            while i*t <> -j*m do #i.e., while they're not both 0
                #The effect on the low-order bit of the operation i*t-j*m is
                #equivalent to that of the operation Xor(And(i,t), And(j,m)).         
                if (i*t - j*m)::odd then #low bit = 1
                    p:= 1-p #Switch parity of count of 1-bits. 
                fi;
                i:= i/2; t:= t/2; m:= m/2; j:= j/2 #integer divisions!
            od;
            if p=1 then Z:= Z+1 fi
        od;
        A[i0,j0]:= Z
    od od;
    0
end proc
:
BuildA:= Compiler:-Compile(BuildA_M):

LArip:= proc(n::posint)
local 
    r:= 2^n, 
    M:= Array(1..r, combinat:-randperm(r) -~ 1, datatype= integer[4]),
    A:= Array((1..r)$2, datatype= integer[4])      
;
    BuildA(A, M, r);
    (A, M)  
end proc 
:
(A,M):= CodeTools:-Usage(LArip(8));
memory used=287.77KiB, alloc change=0 bytes, 
cpu time=7.06s, real time=7.07s, gc time=0ns

 

@Carl Love My code above can handle your longer example just as well:

str:= "A": s1:= " some very long string here":
s2:= " it was%s 10 ": s3:= "another very long string": 
x:= 10:
str:= sprintf(cat(str, s||(1..3)), if x++=10 then "" else x:=9; " not" fi);
x;
  str := "A some very long string here it was 10 another very 
     long string"

                               11

 

@nm Appending [] to a list or set returns the underlying sequence, just like op. Unlike op, this only works for lists and sets. I know that I've seen this in the help somewhere. 

It's sometimes useful to append [] to an rtable. This is a completely different usage, somewhat akin to eval, and the end result is still an rtable.

@mmcdara You've done a good job learning to use evalindets / subsindets in 1-2 days.

First 136 137 138 139 140 141 142 Last Page 138 of 711