Carl Love

Carl Love

28050 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

It's a great algorithm.  I've made some modifications to the code in addition to Joe's, keeping the basic algorithm the same. You may notice another factor-of-two time improvement on some large factorings such as all 92,213 factorings of our friend 711*100^3.

  1. I eliminated the repetitive deep indexing by letting j become a factoring itself rather than an index into the list L[i-1] of factorings.
  2. I rolled the factorings of length two case into the main loop.
  3. I eliminated all divisions by always sorting the list of divisors. That is, if D:= sort([divisors(N)[]]), then for all k, we have n = D[k]*D[-k].
  4. Because of (3), I only scan the first half of each list of divisors, plus one more in case of a perfect square (we know it's a square if the number of divisors is odd, so I don't need to check).

Factorings:= proc(n::posint, m::posint:= 0)
   uses NT= numtheory;
   local
      L, T, Div, i, j, k, Nsq, idx
     ,Omega:= NT:-bigomega(n)
   ;   
   if m > Omega then  return []  elif m > 0 then  Omega:= m  fi;  
 
   L[1]:= [[n]];

   for i from 2 to Omega do  # i is number of factors.
      idx:= 0;
      # j is one factoring for previous i, so j is a list.
      for j in L[i-1] do
         # Split last, and greatest, member of list, if not prime.
         Div:= sort([(NT:-divisors(j[-1]) minus {1,j[-1]})[]]);
         Nsq:= iquo(nops(Div)+1, 2);  # Extra 1 is for square root.
         # Only use splits that maintain the list in order.
         if i=2 then  k:= 1  else  for k to Nsq while Div[k] < j[-2] do od  fi;
         idx:= idx+1;
         # j[-1] = Div[k]*Div[-k] for any k, since Div is sorted.
         T[idx]:= seq([j[1..-2][], Div[k], Div[-k]], k= k..Nsq)
      end do;
      # Convert table T to list L[i].
      L[i]:= [seq](T[j], j= 1..idx)
   end do;

   # Convert table L to list for final output.
   `if`(m = 0, [seq](L[i][], i= 1..Omega), L[m])
end proc:

 

Kitonum: The reason to use ``(...) rather than convert(..., symbol) is that expand will remove the ``.

Kitonum: The reason to use ``(...) rather than convert(..., symbol) is that expand will remove the ``.

Yes, it would be nice and would make sense if simplify were idempotent.

Please post an example worksheet.

@williamov 

Let's correct the original formula to a proper PDF before getting carried away with enthusiasm.

restart;
with(Statistics):
Density := t-> exp(-t^2)/sqrt(Pi):
Check that it's a PDF:
int(Density(t), t= -infinity..infinity);
                               1
Horizontal shift won't change the integral. But we shift the PDF, not the CDF.
Z:= Distribution(PDF= unapply(Density(t-1), t)):
Now the other aspects can be computed from this automatically by the Statistics package.
CDF(Z,t);
                        1   1           
                        - + - erf(t - 1)
                        2   2           
Mean(Z);
                               1

@williamov 

Let's correct the original formula to a proper PDF before getting carried away with enthusiasm.

restart;
with(Statistics):
Density := t-> exp(-t^2)/sqrt(Pi):
Check that it's a PDF:
int(Density(t), t= -infinity..infinity);
                               1
Horizontal shift won't change the integral. But we shift the PDF, not the CDF.
Z:= Distribution(PDF= unapply(Density(t-1), t)):
Now the other aspects can be computed from this automatically by the Statistics package.
CDF(Z,t);
                        1   1           
                        - + - erf(t - 1)
                        2   2           
Mean(Z);
                               1

@williamov 

Use unapply, not Unapply. It is meaningless with a capital U. Change the line

RealDist := Distribution(Dist(t-1));

to

RealDist := Distribution(CDF= unapply(Dist(t-1), t));


Of course, Markiyan's objection about the original not being a PDF applies here also. I am just trying to offer basic corrections to syntax, not claiming that the above is mathematically valid.

@williamov 

Use unapply, not Unapply. It is meaningless with a capital U. Change the line

RealDist := Distribution(Dist(t-1));

to

RealDist := Distribution(CDF= unapply(Dist(t-1), t));


Of course, Markiyan's objection about the original not being a PDF applies here also. I am just trying to offer basic corrections to syntax, not claiming that the above is mathematically valid.

Preben,

I am having some trouble reading your answer. I wonder if the editor dropped some angle brackets.

I see

SecTer:= CrossProduct(,)

____________________^

and

ProjX := diff(x(t), t, t) = -q*DotProduct(SecTer,,conjugate=false)/m;

_______________________________________^^

and the same problem in the line after that (I tried to used uparrows to indicate the problematic commas.)

Preben,

I am having some trouble reading your answer. I wonder if the editor dropped some angle brackets.

I see

SecTer:= CrossProduct(,)

____________________^

and

ProjX := diff(x(t), t, t) = -q*DotProduct(SecTer,,conjugate=false)/m;

_______________________________________^^

and the same problem in the line after that (I tried to used uparrows to indicate the problematic commas.)

@Markiyan Hirnyk

It is easier to define independence precisely. Assume that the equations have all been put in the form where the right sides are 0. They are independent if there exists an assignment of numerical values to all of the unknowns such that

  1. none of the evaluated left sides are 0
  2. none of the evaluated left sides are equal to any other evaluated left side.

PS: Upon sleeping on it, I woke up realizing the above definition is not adequate. I withdraw it, I'll need to think about it some more.

@Markiyan Hirnyk

It is easier to define independence precisely. Assume that the equations have all been put in the form where the right sides are 0. They are independent if there exists an assignment of numerical values to all of the unknowns such that

  1. none of the evaluated left sides are 0
  2. none of the evaluated left sides are equal to any other evaluated left side.

PS: Upon sleeping on it, I woke up realizing the above definition is not adequate. I withdraw it, I'll need to think about it some more.

Maple chose two of the five unknowns to eliminate. In this case, it is almost obvious that it will pick d and s, but we can't rely on that in general.

Maple chose two of the five unknowns to eliminate. In this case, it is almost obvious that it will pick d and s, but we can't rely on that in general.

@Markiyan Hirnyk 

A set of equations is independent if none of the equations can be derived from the others. I'm just extending the concept of "linear independence" to arbitrary equations.

The reason that I'm asking is that so far (in this thread) it seems that solve simply refuses to give any solution when the number of independent equations is greater than the number of variables for which solutions are requested. If that is the case, then solve should just give an error message telling the user to use eliminate instead. Returning NULL is not very helpful.

First 697 698 699 700 701 702 703 Last Page 699 of 709