Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

There are two characters appearing in the statement of Problem B1 that have been transcribed incorrectly. The first looks like numeral "2", and I'm sure that it's supposed to be the "is an element of" symbol. The second looks like "y", but I can't figure out what it's supposed to be.

Here is an example of the same thing done as what Mac Dude called a "module factory", i.e., a procedure that returns a module that implements some object (meant in the sense of Object-Oriented Programming or OOP):

CTS:= proc(Init::integer:= 0)
   module()
   local Counter::integer;
   export
      Inc:= proc(inc::integer:= 1) Counter:= Counter+inc end proc,
      Reset:= proc(init::integer:= Init) Counter:= init end proc,
      Query:= ()-> Counter
   ;
      Counter:= Init
   end module
end proc:

Sammy:= CTS(7):
Sammy:-Inc();
Sammy:-Query();
Sammy:-Reset();
                               8
                               8
                               7

Note that the code in significantly shorter, mostly because the module no longer needs to manage the names of the individual counters. The New has been replaced by the outer procedure itself. Note that the module contains one statement.

In terms of its behavior, this is very close to an object module, like I mentioned earlier. However, the syntax of an object module is significantly different.

@Rohith fsolve is a command that returns a purely numeric complex float solution to a system of equations that has the same number of equations as variables. The system of equations (or single equation) may be specified symbolically (as is the case here), or may be specified by a numeric procedure. When I referred to symbolic computation systems, I was referring to the ability to take a symbolic equation and use a one-line template to construct a procedure that numerically solves the equation. That process is symbolic, even though the final product is numeric.

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.

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