indexind combinations function - math problem lazarus / 21-General ---------------------------------------------------------------------- Laur · 2024-06-24 16:33 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 · 2024-06-24 17:18 Out of the question ... Less writing, more reading? ---------------------------------------------------------------------- Thaddy · 2024-06-25 05:57 For the factorals you can use a LUT.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$R+} const  MaxFactorial = 20; // Maximum factorial value to compute  FactorialLut:array[0..MaxFactorial] of qword = (1,1,2,6,24,120,720,5040,40320,362880,3628800,             39916800,47 9001600,6227020800,87178291200,1307674368000,20922789888000,           355687428096000,6402373705728000,121645100408832000,2432902008176640 000);type  TFactorialRange = 0..MaxFactorial; function ComputeFactorial(const n: TFactorialRange): QWord;inline;begin  Result := FactorialLUT[n];end; begin  // Example usage:  writeln('Factorial of 8:', ComputeFactorial(8));  writeln('Factorial of 3:', ComputeFactorial(3));  writeln('Factorial of 5:', ComputeFactorial(5));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. ---------------------------------------------------------------------- Laur · 2024-06-25 14:43 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 · 2024-06-25 15:22 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.h tml#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. ---------------------------------------------------------------------- Laur · 2024-06-25 15:39 Quote from: Thaddy on June 25, 2024, 05:22:19 pmYou 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 · 2024-06-25 15:46 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. ---------------------------------------------------------------------- Laur · 2024-06-25 15:56 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 · 2024-06-25 16:08 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. ---------------------------------------------------------------------- Laur · 2024-06-25 16:35 Quote from: Thaddy on June 25, 2024, 06:08:32 pmlogic 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 · 2024-06-25 16:38 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 ---------------------------------------------------------------------- Laur · 2024-06-25 17:04 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 = ? ---------------------------------------------------------------------- Thaddy · 2024-06-25 17:28 @Laur, try to describe the function content, not its abstraction. Unless similar. ---------------------------------------------------------------------- Laur · 2024-06-25 17:53 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 · 2024-06-25 22:33 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. ---------------------------------------------------------------------- Laur · 2024-06-27 15:44 Quote from: dseligo on June 26, 2024, 12:33:53 amTS 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. OK. It's probably good... anyway, I guessed it myself. iC = i << 1 + j << 1 + ... // where << = shl for any combinations of numbers 01234... ie from 0 not 1. additionaly we don't use N. Thancs.