Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

However, no elementwise operators are going to work in Maple 12 because they were introduced in Maple 13. Constructions such as T +~ 1 can be replaced with map(`+`, T, 1).

@Ramakrishnan 

Almost everything that is done with a module could be done with a procedure. Here is an example:

Counters:= proc()::table(procedure);
local Counters::table(integer):= table();
   table([
      ':-Inc'= proc(C::name, inc::integer:= 1)
         if assigned(Counters[C]) then Counters[C]:= Counters[C]+inc
         else error "Unknown counter %1. Use New to create counters.", C
         fi
      end proc,
      ':-Reset'= proc(C::name, Init::integer:= 0)
         if assigned(Counters[C]) then Counters[C]:= Init
         else error "Unknown counter %1. Use New to create counters.", C
         fi
      end proc,
      ':-New'= proc(C::name, Init::integer:= 0)
         if assigned(Counters[C]) then
            error "Counter %1 already exists. Use GC to discard counters."
         else Counters[C]:= Init
         fi
      end proc,
      ':-GC'= proc(C::name)
      local r:= Counters[C];
         unassign('Counters[C]');
         r
      end proc,
      ':-Query'= ((C::name)-> Counters[C])
   ])
end proc:
   
CTS:= Counters():
CTS[New](Sammy, 7);
                               7
CTS[Inc](Sammy);
                               8
CTS[Query](Sammy);
                               8
CTS[Reset](Jane);
Error, (in CTS[Reset]) Unknown counter Jane. Use New to create counters.
CTS[GC](Sammy);
                               8
CTS[Query](Sammy);
                        Counters[Sammy]

Here is the same thing done as a module:

CTS:= module()
local Counters::table(integer):= table();
export
   Inc:= proc(C::name, inc::integer:= 1)
      if assigned(Counters[C]) then Counters[C]:= Counters[C]+inc
      else error "Unknown counter %1. Use New to create counters.", C
      fi
   end proc,
   Reset:= proc(C::name, Init::integer:= 0)
      if assigned(Counters[C]) then Counters[C]:= Init
      else error "Unknown counter %1. Use New to create counters.", C
      fi
   end proc,
   New:= proc(C::name, Init::integer:= 0)
      if assigned(Counters[C]) then
      error "Counter %1 already exists. Use GC to discard counters."
      else Counters[C]:= Init
      fi
   end proc,
   GC:= proc(C::name) local r:= Counters[C]; unassign('Counters[C]'); r end proc, 
   Query:= (C::name)-> Counters[C] 
; 
end module:

CTS[New](Sammy, 7);
                               7
CTS[Inc](Sammy);
                               8
CTS[Query](Sammy);
                               8
CTS[Reset](Jane);
Error, (in Reset) Unknown counter Jane. Use New to create counters.
CTS[GC](Sammy);
                               8
CTS[Query](Sammy);
                        Counters[Sammy]

Note that this module has no statements, only declarations. The vast majority of modules that I write either have no statements, or they have the single statement ModuleLoad().

The above module could be (and most likely would be) implemented as a module with option object. Then the local would be a single integer variable rather than a table of them, and the New would create a new copy of the module (with a fresh, independent local variable). The syntax required for this is a bit elaborate, so I think that it's best to get comfortable with regular modules before learning object modules. Anyway, it can all ultimately be done with regular modules or even procedures, as shown above.

In addition to what Joe said, if the resulting expression has exponents, then your professor's instruction to "Use your identities ... to eliminate all exponents" can be done by simple application of the combine command (no extra options needed). I don't have Maple open right now (grocery shopping) to check whether there's some snag in this case, but that's usually what combine does.

Note that the "Fourier sine transform" and "Fourier cosine transform" are themselves transforms and they are not the same thing as the Fourier transform of sine or cosine. From your wording it's not clear that you're aware of the distinction. 

@vv Vote up. But your procedure will benefit greatly by using option remember, as is usually the case with a branched recursion.

@Alger Declare the matrix with storage= sparse:

m2:= Matrix((150000, 150000), storage= sparse);

@vv Threads:-Seq can get bogged down when the sequence is short. The tasksize option helps with this (example below). But, still, it seems to work best for long sequences rather than short sequences containing long tasks.

When using CodeTools:-Usage for measuring times and memory for GrId operations, the numbers only apply to the master process, so only "real time" is realistic. For finer measurement, you need to do the measuring within the individual processes (example below). 

I changed your example to use evalhf and I increased each add by a factor of 100.

f := proc(i) local k; 
if   i=1 then    add(1/(k+sin(k))^(k/(k+1)),k=1..5*10^6)
elif i=2 then    add(1/(k+sin(k))^(k/(k+2)),k=1..6*10^6)
elif i=3 then    add(1/(k+sin(k))^(k/(k+3)),k=1..6*10^6)
elif i=4 then    add(1/(k+sin(k))^(k/(k+4)),k=1..3*10^6)
fi
end:

CodeTools:-Usage([Threads:-Seq[tasksize=1](evalhf(f(i)), i=1..4)]);
CodeTools:-Usage([Grid:-Seq(CodeTools:-Usage(evalhf(f(i))), i= 1..4)]);
CodeTools:-Usage([seq(evalhf(f(i)), i=1..4)]);  

memory used=3.60KiB, alloc change=0 bytes, cpu time=13.66s, real time=3.93s, gc time=0ns
[16.5582269340421213, 17.6172669486901476, 18.3916368704668471, 18.4091417194700675]

memory used=0.91KiB, alloc change=0 bytes, cpu time=797.00ms, real time=813.00ms, gc time=0ns
memory used=0.91KiB, alloc change=0 bytes, cpu time=1.33s, real time=1.34s, gc time=0ns
memory used=1.05KiB, alloc change=0 bytes, cpu time=1.62s, real time=1.63s, gc time=0ns
memory used=0.91KiB, alloc change=0 bytes, cpu time=1.62s, real time=1.63s, gc time=0ns
memory used=177.05KiB, alloc change=2.19MiB, cpu time=156.00ms, real time=1.68s, gc time=125.00ms
[16.5582269340421213, 17.6172669486901476, 18.3916368704668471, 18.4091417194700675]

memory used=1.44KiB, alloc change=0 bytes, cpu time=5.05s, real time=5.07s, gc time=0ns
[16.5582269340421213, 17.6172669486901476, 18.3916368704668471, 18.4091417194700675]

 

Do you mean separate solutions to each of those equations or solutions that satisfy all the equations simultaneously?

Is b considered fixed and a1 and a2 the variables to solve for?  

@vv wrote:

  • As I understand, you have to find m,e  knowing N = m^e.
    That's not very complicated. Using ifactor(N, squfof)   it will be easy to guess/find them.

If it's possible the find m knowing N = m^e, then what's the point of using RSA?

@vazzz No result yet. It's used about 4 hours of CPU time so far. The computer went to sleep due to lack of keyboard activity, but I just resumed it.

@kristavaldes Your worksheet does correctly recover the value of X = m^e from its three remainders. But I don't see how that can be used to get simply m even if you knew e.

@AliGH I can't test if you don't post your code.

@Kitonum In cases where you can easily identify a unique representative of each equivalence class, it is far more efficient to use that fact and ListTools:-Classify rather than ListTools:-Categorize. In this case, sorting a composition gives a unique representative of the equivalence classes that we want:

ListTools:-Classify(sort, combinat:-composition(7,3));

But, in this case, we only need the representative; we can discard the rest of each class:

[indices(%, 'nolist')];

So, if you have a function ECUR that returns the Equivalence Class Unique Representative, then applying such to a set S can be done with ECUR~(S). Hence, we've arrived at VV's Answer.

Because of such simplifications, there've been very few times where I've actually used Categorize. When dealing with finite sets (as must be the case in a computer program), it's usually easy to come up with a unique representative of each equivalence class.

@kristavaldes Are you sure that you weren't given a value of d (the decryption exponent) earlier, perhaps as part of another assignment? Or perhaps in an earlier assignment, you generated your own random primes p and q and exponents e and d and sent the instructor your public key (n,e) (where n = p*q, but you keep p and q secret)?

@Lottie In the code of a procedure, there are several symbols that can be used to refer generically to various parts of the procedure and its invocation. The symbol procname refers to the name by which the procedure was called. Usually this is the same as the name with which it was declared, i.e., the name to the left of proc. But this is not always the case. For example, it may be called with its declared name with a subscript added. Using procname instead of the explicitly declared name will retain that subscript.

Likewise args and _passed (which mean the same thing) are the arguments with which the procedure was actually called, which may include extra arguments that don't correspond to declared parameters.

It is for these reasons that experienced Maple programmers use constructions such as 'procname(_passed)' rather than 'Q(A)'. Another reason is that the former will never need to be changed, even if you rewrite the procedure with a different name and different names for its parameters.

First 290 291 292 293 294 295 296 Last Page 292 of 709