inverse_simplicial fix

This commit is contained in:
Jiri Pittner 2024-04-08 16:02:46 +02:00
parent c6a0fc9814
commit e09171467b
2 changed files with 13 additions and 6 deletions

View File

@ -811,7 +811,7 @@ return stored[d-2][n];
}
//find largest n such that simplicial(d,n)<=s
int inverse_simplicial(int d, unsigned long long s)
{
if(s==0) return 0;
@ -841,7 +841,9 @@ do
x -= dx;
}
while(std::fabs(dx)>.5); //so usually 2 iterations are enough
return std::floor(x);
int n= std::floor(x);
while(simplicial(d,n)>s) --n;
return n;
}
#undef SIMPLICIAL_MAXD

13
t.cc
View File

@ -3180,10 +3180,15 @@ if(1)
{
int d,n;
cin>>d>>n;
unsigned long long s;
s=simplicial(d,n);
cout <<s<<" "<<binom(n+d-1,d)<<endl;
cout <<inverse_simplicial(d,s)<<endl;
unsigned long long s1;
s1=simplicial(d,n);
cout <<s1<<" "<<binom(n+d-1,d)<<endl;
unsigned long long s2 = simplicial(d,n+1);
for(unsigned long long s=s1; s<s2; ++s)
{
int i=inverse_simplicial(d,s);
if(i!=n) cout <<"Error "<<s<<" " <<i<<endl;
}
}
if(0)