Recent

Author Topic: indexind combinations function - math problem  (Read 1941 times)

Laur

  • New Member
  • *
  • Posts: 29
indexind combinations function - math problem
« on: June 24, 2024, 06:33:33 pm »

I have some combinatorics to compute fastly, pairs, triples, etc.

for example: triples and for n = 8 elements:

in a set of 8-elements we have: 8!/3!5! =  56 of triplets:

123, 124, 125, ... 678;

and I need a fast function which give me a one number, so:

fun(i,j,k) -> c; and the c is just an index of triplet: 1..56 in this case.


WooBean

  • Full Member
  • ***
  • Posts: 249
Re: indexind combinations function - math problem
« Reply #1 on: June 24, 2024, 07:18:44 pm »
Out of the question ...

Less writing, more reading?
Platforms: Win7/64, Linux Mint Ulyssa/64

Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #2 on: June 25, 2024, 07:57:21 am »
For the factorals you can use a LUT.
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$R+}
  2.  
  3. const
  4.   MaxFactorial = 20; // Maximum factorial value to compute
  5.   FactorialLut:array[0..MaxFactorial] of qword = (1,1,2,6,24,120,720,5040,40320,362880,3628800,
  6.              39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,
  7.              355687428096000,6402373705728000,121645100408832000,2432902008176640000);
  8. type
  9.   TFactorialRange = 0..MaxFactorial;
  10.  
  11. function ComputeFactorial(const n: TFactorialRange): QWord;inline;
  12. begin
  13.   Result := FactorialLUT[n];
  14. end;
  15.  
  16. begin
  17.   // Example usage:
  18.   writeln('Factorial of 8:', ComputeFactorial(8));
  19.   writeln('Factorial of 3:', ComputeFactorial(3));
  20.   writeln('Factorial of 5:', ComputeFactorial(5));
  21. end.
Be careful with the limits: 20! really is about the limit that fits in a qword.
Then again the code is superfast. above values calculate to 56.
« Last Edit: June 25, 2024, 08:00:08 am by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #3 on: June 25, 2024, 04:43:47 pm »
No. I need a function to compute the index of comination.

say: n = 10 then number of pairs is:

(n over 2) = 10*9 / 2 = 45

pairs: 12, 13,14, ... up to 9X.

and now:

function getIndexOf Pair(i, j, n : integer);
begin
  result := ... // a math formula, which I'm looking for.
end;

for example: i=1 j=2, (n=10) then the func returns: 1, because 12 is just a first pair.

case i =1 j = 3 -> result =2
case i=9 j=10 -> 45 the last pair

And the same for 3: i,j,k... ect.




Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #4 on: June 25, 2024, 05:22:19 pm »
You mean ternary logic? there is a full implementation on this forum and the wiki. (by me)
A three value logic is meant to solve problems like yours.
https://forum.lazarus.freepascal.org/index.php/topic,41144.msg290876.html#msg290876
For some problems you may need the zaheh logic a couple of posts later: that can decide better on the outcome of any underlying math, but is more difficult.
« Last Edit: June 25, 2024, 05:42:40 pm by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #5 on: June 25, 2024, 05:39:39 pm »
You mean ternary logic? there is a full implementation on this forum and the wiki. (by me)
A three value logic is meant to solve problems like yours.

ternaly logics... it's the standard logics of: true, false and nonsense are common in any reality.

my question is quite different:

for n=4 the comb. of 3 looks like this:
(4 over 3) = 4;

123, 124, 134, 234
index = 1 , 2, 3, 4

but for n = 10 it's much  more complicated:  (10 o 3) = 8*9*10 / 6 = 120

for n = 30;  30*29*28/6 = ...  4060



Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #6 on: June 25, 2024, 05:46:34 pm »
It is not true false or nonsense, a balanced ternary logic is -1,0,+1 meaning usually false, undecided, true where zero is usually a branch instruction, because that only means that zero values need more information. What you write is a clear expression you do not yet understand it. Maybe the Zadeh logic is easier for you since it is fully in the float domain. In that case, let Zadeh logic decide and use a transfer function to ternary and you have your index. That is what you asked?
Abstract v =f(x,y,z); what is f(x,y,z), I need to know the function for better advice.
« Last Edit: June 25, 2024, 06:06:38 pm by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #7 on: June 25, 2024, 05:56:24 pm »
So, then try to discovery the standard logics over:
true, false, nonsense ==  1,0, nothing.

this is just the real logics, You use it everyday.


And what You are talking is just some arythmetic not logics -
probabllistic theory, ect.

Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #8 on: June 25, 2024, 06:08:32 pm »
logic is logic, in my case Kleene and Priest, which is the standard. You really do not know what you are talking about. Won't answer anymore unless you are a student and want to know the absolute basics or a real student that wants examples of application, which I just did, branching for zero's. If you do not see the importance of balanced, answers would be pointless.
I only asked for the domain in which the function operates, that is key.

Take a simple example: a sine wave and a saw wave: at at least three points they reach -1.0, 0.0 or +1.0. To continue they need to know where to go....(important in analogue syntheziser design) So the wave processing says, dunno, need more information...changing wave form can only be done at limts or center. so the branch looks ahead and makes sure it continues as either sine or saw.
« Last Edit: June 25, 2024, 06:50:32 pm by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #9 on: June 25, 2024, 06:35:36 pm »
logic is logic, in my case Kleene and Priest, which is the standard. You really do not know what you are talking about. Won't answer anymore unless you are a student and want to know the absolute basics or a real student that wants examples of application, which I just did, branching for zero's. If you do not see the importance of balanced, answers would be pointless.
I only asked for the domain in which the function operates, that is key.

Take a simple example: a sine wave and a saw wave: at at least three points they reach -1.0, 0.0 or +1.0. To continue they need to know where to go....(important in analogue syntheziser design) So the wave processing says, dunno, need more information...

I'm an ancient programmer expert - say: from Atlantyda. OK. :)


Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #10 on: June 25, 2024, 06:38:09 pm »
well, you are not an expert. But have fun programming...
Anyway, you namesake Laurent de Soras is an academic expert on the subject.
(not my nephew Lau, he's a chef).
Plz provide some functions in either Pascal or mathematical notation that you want to process.
I need correctness and limits
« Last Edit: June 25, 2024, 06:51:52 pm by Thaddy »
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #11 on: June 25, 2024, 07:04:30 pm »
Indeed.
My son has been just the Laureate - fainmous expert in complex functions analysis, and the creator of Laurent's series, ect.

try this: i^i = ? :D


Thaddy

  • Hero Member
  • *****
  • Posts: 15109
  • Censorship about opinions does not belong here.
Re: indexind combinations function - math problem
« Reply #12 on: June 25, 2024, 07:28:08 pm »
@Laur,

try to describe the function content, not its abstraction. Unless similar.
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

Laur

  • New Member
  • *
  • Posts: 29
Re: indexind combinations function - math problem
« Reply #13 on: June 25, 2024, 07:53:58 pm »
I described the function several times already.

index of pair = fun(i,j,n);

triple index = fun(i,j,k,n);

quatro = fun(i,jk,l, n);

..

the solution is rather easy, but I'm very lazy... today.

8:
1,2,3,4,5,6,7,8 - 8 elements.
a,b,c,d,e,f,g,h - 8 elements too.

pairs: ab, ac, ad, ...
indexes (numbering, sequence): 1, 2, 3, ...

is this comperhandable for... human?




dseligo

  • Hero Member
  • *****
  • Posts: 1282
Re: indexind combinations function - math problem
« Reply #14 on: June 26, 2024, 12:33:53 am »
TS is talking about combinations (https://en.wikipedia.org/wiki/Combination).

And here is some theory how to solve his problem: https://en.wikipedia.org/wiki/Combinatorial_number_system.

 

TinyPortal © 2005-2018