Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / Maple / October 2008



Tip: Looking for answers? Try searching our database.

how to generate a number serie with starting conditions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul - 27 Sep 2008 16:39 GMT
Hello

My name is Sara Ferrari, i'm an italian student and i'm starting to use
maple.
The problem to solve is to generate a serie of numbers that must respect the
follow condition:

the numbers are 9 from 1 to 9
The random serie is long 9^11
every subserie (of 9 numbers)can't have the follow disposition:

1
2
3
4
5
6
7
8
9

and all the 9x8x7x6x5x4x3x2x1 dispositions where all the 9 numbers exit in a
serie of 9 long.
The same condition must be respect every  2-3-4-x- selection ,where the
selection between the 9 numbers has the same distance.

1_2_3_4_5_6_7_8_9     (  _  ) = numbers     (DISTANCE 1)
1_ _ 2_ _ 3_ _ 4_ _ 5_ _ 6_ _ 7_ _ 8_ _ 9    (DISTANCE 2)

and so on.

Which is the code that i must to insert in maple for generate the serie
above indicate ?

Thanks

Sorry for my bad english...

a kiss for who can help me

Bye
Martin Eisenberg - 28 Sep 2008 11:46 GMT
> My name is Sara Ferrari, i'm an italian student and i'm starting
> to use maple.

Enjoy!

> the numbers are 9 from 1 to 9
> The random serie is long 9^11
> every subserie (of 9 numbers)can't have the follow disposition:
 1, 2, 3,... 9
> and all the 9x8x7x6x5x4x3x2x1 dispositions where all the 9
> numbers exit in a serie of 9 long.

Do you mean that you reject a sequence when it contains any
permutation of {1,... 9} and accept it otherwise? If so, here's a
monitor that, when fed a sequence, tracks its recent history and
deduces the values prohibited in the next position:

Monitor := proc() module()
 export taboos, update;
 local history_, taboos_;
 history_,taboos_ := [],{};

 taboos := ()-> taboos_;
 update := proc(n)
   min(nops(history_) + 1, 8);
   history_ := [history_[], n][-%..-1];
   {history_[]};
   if nops(%) = 8 then  {$ 1..9} minus %;  else  {};  fi;
   taboos_ := %;
 end;
end; end:

Demo of the first taboo appearing:

m:= Monitor():
map(m:-update, [2,4,3,5,6,8]):
m:-update(9), m:-update(1);
                             {}, {7}

> The same condition must be respect every  2-3-4-x- selection
> ,where the selection between the 9 numbers has the same
[quoted text clipped - 4 lines]
>
> and so on.

Set up one monitor for each selection. To generate the next symbol:
- select those monitors appropriate to the current sequence index
- join all those monitors' taboos
- randomly pick a symbol from that set's complement
- feed the symbol to the monitors and return it.
I don't know if the next symbol can ever actually fail to exist. The
code below also keeps the sequence index bounded by wrapping.

Sequence := proc(MaxStride) module()
 export emit;
 local i_, monitors_, currentStrides, pick;
 i_,monitors_ := 0, [Monitor $ MaxStride]();

 currentStrides := proc()
   select(a-> evalb(irem(i_,a) = 0), [$ 1..MaxStride]);
   if nops(%) = MaxStride then  i_ := 1;  else  i_ := i_ + 1;  fi;
   return %%;
 end;
 pick := a-> a[rand(1..nops(a))()];
 emit := proc()
   local mon, result;
   mon := [seq](monitors_[s], s=currentStrides());
   (`union`@op@map)(m-> m:-taboos(), mon);
   if nops(%) = 9 then  error "No feasible symbol";  fi;
   result := pick({$ 1..9} minus %);
   map(m-> m:-update(result), mon);
   return result;
 end;
end; end:

Now we can look at a sequence and its selections:

s:= Sequence(3):
[s:-emit $ 30]();
     [2, 6, 6, 6, 9, 9, 5, 1, 2, 4, 6, 5, 5, 3,
      7, 7, 2, 7, 1, 6, 2, 8, 8, 2, 4, 4, 9, 2, 4, 9]

seq([seq](%[1+a*i], i=0..floor((30-1)/3)), a=1..3);
     [2, 6, 6, 6, 9, 9, 5, 1, 2, 4],
     [2, 6, 9, 5, 2, 6, 5, 7, 2, 1],
     [2, 6, 5, 4, 5, 7, 1, 8, 4, 2]

The results have a fair amount of repetition by nature of the
constraint. You might try biasing the random choice away from
recently-emitted symbols to increase variation.
Let's see with a timing function if this naive method is practical
for your desired length of 9^11 elements:

Time:= proc(p)
 local t, r;
 t := time();
 r := p(args[2 .. -1]);
 t := time() - t;
 if procname :: indexed and op(procname) = 'silent'
   then  return r, t;  fi;
 print(`s elapsed` = t);
 return r;
end:

s:= Sequence(30):
Time([s:-emit $ 1000]):
                        s elapsed = 1.687

s:= Sequence(1000):
Time[silent]([s:-emit $ 100]) [-1]:
9^11/100 * %/60^2/24/365. * 'years';
                        19.30468532 years

About 19 years for 9^11 elements ;/  The culprit is the first line of
currentMonitors() in Sequence, which finds the divisors of sequence
index i_ up to MaxStride. If there is a way to do that in less than
O(MaxStride) time then you could substitute it for the first line of
currentMonitors().

Martin

Signature

Thinking, analyzing, inventing [...] are not anomalous acts;
they are the normal respiration of the intelligence.
--Jorge Luis Borges

paul - 01 Oct 2008 08:46 GMT
Dear Martin,

Thank you for help..
but do you mean that for develop the 9^11 elements is necessary to wait 19
years of elaboration time?
Do you know if is possible to use another more fast procedure or software?
So if the elements for example are only 6. For 6^8 the time necessary is
about some hours only.

Thanks

Sara Ferrari

>> My name is Sara Ferrari, i'm an italian student and i'm starting
>> to use maple.
[quoted text clipped - 119 lines]
>
> Martin
Martin Eisenberg - 01 Oct 2008 12:46 GMT
> but do you mean that for develop the 9^11 elements is necessary
> to wait 19 years of elaboration time?

For 1000 monitored subsequences, on my machine anyway, which is old.
But to enforce the constraint on all possible selections, you'd need
to use Sequence(9^10) which would eat a *lot* of memory (after
changing the code to use Arrays instead of lists).

> Do you know if is possible to use another more fast procedure or
> software?

If I did I'd have used it ;)

Martin

Signature

Quidquid latine scriptum est, altum videtur.

Martin Eisenberg - 02 Oct 2008 12:31 GMT
>> but do you mean that for develop the 9^11 elements is necessary
>> to wait 19 years of elaboration time?
[quoted text clipped - 3 lines]
> you'd need to use Sequence(9^10) which would eat a *lot* of
> memory (after changing the code to use Arrays instead of lists).

Come to think about it I wouldn't actually trust Maple to handle such
load, but an equivalent program in a compiled language can be both
feasible RAM-wise and much faster.

>> Do you know if is possible to use another more fast procedure
>> or software?
>
> If I did I'd have used it ;)

Besides, my real contribution is not the code as such but the
reduction of your task, stated in its own terms, onto a more generic
mathematical problem (generating divisor sets of successive integers)
that you can investigate.

Martin

Signature

Quidquid latine scriptum est, altum videtur.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.