arithmtype Pow(void) { arithmtype Q,Res = Term(); while(*Expr=='^') { if ( ErrorDesc ) break; Expr++; Q = Pow(); Res = pow_int(Res,Q); } return Res; }
inline typename Base<F>::type SchattenNorm( const Matrix<F>& A, typename Base<F>::type p ) { #ifndef RELEASE PushCallStack("SchattenNorm"); #endif typedef typename Base<F>::type R; Matrix<F> B( A ); Matrix<R> s; SVD( B, s ); // TODO: Think of how to make this more stable const int k = s.Height(); R sum = 0; for( int j=k-1; j>=0; --j ) sum += Pow( s.Get(j,0), p ); const R norm = Pow( sum, 1/p ); #ifndef RELEASE PopCallStack(); #endif return norm; }
virtual int PlanMore() { iterationCount++; if(anytime) { int d=qStart.n; Real scaleFactor = Pow(0.5,1.0/Real(d)); planner.resolution *= scaleFactor; planner.SolveFMM(); } else planner.SolveFMM(); return -1; }
static NOINLINE int UpdateParam(equalizer* p) { if (p->Codec.In.Format.Type == PACKET_AUDIO) { int n; const eqfilter *src; eqfilter *dst; src = Band44100; dst = p->Filter; for (n=0;n<MAXFILTER;++n,++src,++dst) { dst->alpha0 = fix_mul(src->alpha,Pow(p->Eq[n])-FIXC(1.)); dst->beta = ACCFAST_BSHIFT(src->beta); dst->gamma = ACCFAST_BSHIFT(src->gamma); } p->ScalePreamp = Pow(p->Amplify); UpdateScale(p); } return ERR_NONE; }
FdmZabrOp::FdmZabrOp(const boost::shared_ptr<FdmMesher>& mesher, const Real beta, const Real nu, const Real rho, const Real gamma) : forwardValues_(mesher->locations(0)), volatilityValues_(mesher->locations(1)), dxyMap_(SecondOrderMixedDerivativeOp(0, 1, mesher).mult(nu*rho*Pow(Abs(volatilityValues_),gamma+1.0)*Pow(Abs(forwardValues_),beta))), dxMap_(FdmZabrUnderlyingPart(mesher,beta,nu,rho,gamma)), dyMap_(FdmZabrVolatilityPart(mesher,beta,nu,rho,gamma)) { }
arithmtype MulDivMod(void) { int Val=0; arithmtype Res = Pow(); while(1) { if ( ErrorDesc ) break; //if (UnderVerify) //printf("MulDivMod_Expr=%s\n",Expr); if (*Expr=='*') { Expr++; Res = Res * Pow(); } else if (*Expr=='/') { Expr++; Val = Pow(); if ( ErrorDesc==NULL ) Res = Res / Val; } else if (*Expr=='%') { Expr++; Val = Pow(); if ( ErrorDesc==NULL ) Res = Res % Val; } else { break; } } return Res; }
void Complex::setPow (const Complex& z, const Complex& w) { Real mag = z.norm(); Real theta = z.arg(); Real powm = Pow(mag,w.x); Real expt = Exp(-w.y*theta); Real phi = w.x*theta; if(w.y != 0) { Assert(mag != Zero); phi += w.y*Log(mag); } x = powm*expt*Cos(phi); y = powm*expt*Sin(phi); }
my::LongInt my::operator /(my::LongInt const &_a, unsigned char const b) { unsigned int digit = Pow(2, CHAR_BIT); LongInt retVal; unsigned int r = 0; unsigned int help; for (int i = _a.number.GetSize() - 1; i >= 0; i--){ help = _a.number[i] + r * digit; retVal.number[i] = help / b; r = help % b; } retVal.DelZero(); return retVal; }
inline double HVL_da2_internal(const HVL_Context *ctx, const hvl_float &a0, const hvl_float &a2, const hvl_float &a3, const hvl_float &gauss_base, const hvl_float &b1pb2, const hvl_float &reca3, const hvl_float &nmr, const hvl_float &xmu) { const hvl_float gauss_der = a0 * (xmu * xmu * gauss_base / Pow(a2, 3) - gauss_base / a2); if (a3 == ctx->HVL_ZERO) return ToDouble(gauss_der); const hvl_float rnmr = nmr * xmu / a2; const hvl_float result = reca3 * ((gauss_der / b1pb2) + rnmr / (b1pb2 * b1pb2)); return ToDouble(result); }
float calculateCurrentPressureAtSeaLevel(float currentAltitude) { float t = getTemperature()/10; float p = getCurrentPressure()/100; float temp = 1-((0.0065*currentAltitude)/(t+(0.0065*currentAltitude)+273.15)); temp = Pow(temp,-5.257); temp = p*temp; CoEnterMutexSection(PressureAtSeaLevelMutex); pressureAtSeaLevel = temp; CoLeaveMutexSection(PressureAtSeaLevelMutex); return temp; }
char * TFT_ScaleFonts::ftos(float data, byte W, byte D, char * buf) { byte shf = 0; if (data < 0) { data *= -1; shf = 1; buf[0] = '-'; } long Wdata = data, tmp; float dec = data - long(data); // get the first whole number and convert it buf[0 + shf] = Wdata / Pow(10, W - 1) + '0'; tmp = Wdata % Pow(10, W - 1); //now get the rest of the whole numbers for (byte i = 1; i < W; i++) { long factor = Pow(10, W - 1 - i); buf[i + shf] = (tmp / factor) + '0'; tmp %= factor; } buf[W + shf] = '.'; // add the decimal point // now do the decimal numbers for (byte i = 0; i < D; i++) { dec *= 10; buf[W + i + 1 + shf] = (long(dec) % 10) + '0'; } // don't forget the NULL terminator buf[W + D + 1 + shf] = NULL; return buf; }
inline typename Base<F>::type SchattenNorm( const DistMatrix<F,U,V>& A, typename Base<F>::type p ) { #ifndef RELEASE PushCallStack("SchattenNorm"); #endif typedef typename Base<F>::type R; DistMatrix<F> B( A ); DistMatrix<R,VR,STAR> s( A.Grid() ); SVD( B, s ); // TODO: Think of how to make this more stable const int kLocal = s.LocalHeight(); R localSum = 0; for( int j=kLocal-1; j>=0; --j ) localSum += Pow( s.GetLocal(j,0), p ); R sum; mpi::AllReduce( &localSum, &sum, 1, mpi::SUM, A.Grid().VRComm() ); const R norm = Pow( sum, 1/p ); #ifndef RELEASE PopCallStack(); #endif return norm; }
my::LongInt my::operator *(my::LongInt const &_a, unsigned char const b) { unsigned int digit = Pow(2, CHAR_BIT); LongInt retVal; unsigned int help; unsigned char r = 0; for (unsigned int i = 0; i < _a.number.GetSize(); i++){ help = _a.number[i] * b + r; r = help / digit; retVal.number[i] = help % digit; } if (r != 0) retVal.number.PushBack(r); return retVal; }
inline typename Base<F>::type SymmetricSchattenNorm ( UpperOrLower uplo, const Matrix<F>& A, typename Base<F>::type p ) { #ifndef RELEASE PushCallStack("SymmetricSchattenNorm"); #endif typedef typename Base<F>::type R; Matrix<F> B( A ); Matrix<R> s; MakeSymmetric( uplo, B ); SVD( B, s ); // TODO: Think of how to make this more stable const int k = s.Height(); R sum = 0; for( int j=0; j<k; ++j ) sum += Pow( s.Get(j,0), p ); const R norm = Pow( sum, 1/p ); #ifndef RELEASE PopCallStack(); #endif return norm; }
inline VII BabyStep(int a, int b, int c) { VII ret; int m = (int)sqrt(c) + 1, tmp = 1; a %= c; if (a == 0) return ret; insert(1, 0); for (int i = 1; i <= m; i++) tmp = (Int65) tmp * a % c, insert(tmp, i); int gss = b, opp = Pow(tmp, c - 2, c); for (int i = 0, d; i <= m; i++) { int index = gss % MOD; for (Edge *p = e[index]; p; p = p->next) if (p->index == gss) ret.push_back(i * m + p->value); gss = (Int65) gss * opp % c; } return ret; }
inline bool Check(Int64 n) { if (n == 1) return false; if (n == 2) return true; for (int i = 0; i < 4; i++) { int a = fim[i]; Int64 d = n - 1; while (!(d&1)) d >>= 1; Int64 t = Pow(a, d, n); while (d != n - 1 && t != 1 && t != n - 1) { d <<= 1; t = Mult(t, t, n); } if (t != n - 1 && ((d & 1) != 1)) return false; } return true; }
void Nori(int rs,int rt,int C){ int RS; if(for_ex == 1)RS = wbrsd; else if(for_id == 1)RS = wbrs; else RS = registers[rs]; unsigned int A1 = C; unsigned int A2 = RS; int i; wbad = rt; wbrs = 0; for(i = 0;i < 32;i++){ wbrs = wbrs + (!((A1%2)||(A2%2)))*(int)(Pow(2,i)+0.01); A1 = A1/2; A2 = A2/2; } }
int main() { scanf("%I64d%I64d",&n,&m); find_factor(m); ans=Pow(m,n); temp=1; for(i=1;i<=top;i++) { sum=0; find(1,0,i); temp*=-1; ans+=temp*sum; } printf("%I64d\n",ans); return 0; }
void MakeExtendedKahan ( ElementalMatrix<F>& A, Base<F> phi, Base<F> mu ) { EL_DEBUG_CSE typedef Base<F> Real; if( A.Height() != A.Width() ) LogicError("Extended Kahan matrices must be square"); const Int n = A.Height(); if( n % 3 != 0 ) LogicError("Dimension must be an integer multiple of 3"); const Int l = n / 3; if( !l || (l & (l-1)) ) LogicError("n/3 is not a power of two"); Int k=0; while( Int(1u<<k) < l ) ++k; if( phi <= Real(0) || phi >= Real(1) ) LogicError("phi must be in (0,1)"); if( mu <= Real(0) || mu >= Real(1) ) LogicError("mu must be in (0,1)"); // Start by setting A to the identity, and then modify the necessary // l x l blocks of its 3 x 3 partitioning. MakeIdentity( A ); unique_ptr<ElementalMatrix<F>> ABlock( A.Construct(A.Grid(),A.Root()) ); View( *ABlock, A, IR(2*l,3*l), IR(2*l,3*l) ); *ABlock *= mu; View( *ABlock, A, IR(0,l), IR(l,2*l) ); Walsh( *ABlock, k ); *ABlock *= -phi; View( *ABlock, A, IR(l,2*l), IR(2*l,3*l) ); Walsh( *ABlock, k ); *ABlock *= phi; // Now scale A by S const Real zeta = Sqrt(Real(1)-phi*phi); auto& ALoc = A.Matrix(); for( Int iLoc=0; iLoc<A.LocalHeight(); ++iLoc ) { const Int i = A.GlobalRow(iLoc); const Real gamma = Pow(zeta,Real(i)); for( Int jLoc=0; jLoc<A.LocalWidth(); ++jLoc ) ALoc(iLoc,jLoc) *= gamma; } }
int main(int argc, char** argv){ unsigned int max = atoi( argv[1] ); BigInteger n(n_digits,1); for(unsigned int i=2; i<=max; i++){ BigInteger *add = Pow(i,i); n.Add(*add); delete add; add = NULL; } n.Print(); return 0; }
void Quaternion::setPow(const Quaternion& q, Real n) { Real mag = q.norm(); Real immag = q.imNorm(); Real immaginv; if(immag == Zero) immaginv = Zero; //it's a real number, zero out the imaginary part else immaginv = One / immag; Real theta = Atan2(immag, q.w); Real cntheta = Cos(n*theta); Real sntheta = Sin(n*theta); Real powm = Pow(mag, n); w = powm * cntheta; x = powm * sntheta * immaginv * q.x; y = powm * sntheta * immaginv * q.y; z = powm * sntheta * immaginv * q.z; }
void MakeExtendedKahan ( Matrix<F>& A, Base<F> phi, Base<F> mu ) { EL_DEBUG_CSE typedef Base<F> Real; if( A.Height() != A.Width() ) LogicError("Extended Kahan matrices must be square"); const Int n = A.Height(); if( n % 3 != 0 ) LogicError("Dimension must be an integer multiple of 3"); const Int l = n / 3; if( !l || (l & (l-1)) ) LogicError("n/3 is not a power of two"); Int k=0; while( Int(1u<<k) < l ) ++k; if( phi <= Real(0) || phi >= Real(1) ) LogicError("phi must be in (0,1)"); if( mu <= Real(0) || mu >= Real(1) ) LogicError("mu must be in (0,1)"); // Start by setting A to the identity, and then modify the necessary // l x l blocks of its 3 x 3 partitioning. MakeIdentity( A ); auto ABlock = A( IR(2*l,3*l), IR(2*l,3*l) ); ABlock *= mu; ABlock = A( IR(0,l), IR(l,2*l) ); Walsh( ABlock, k ); ABlock *= -phi; ABlock = A( IR(l,2*l), IR(2*l,3*l) ); Walsh( ABlock, k ); ABlock *= phi; // Now scale A by S const Real zeta = Sqrt(Real(1)-phi*phi); for( Int i=0; i<n; ++i ) { const Real gamma = Pow(zeta,Real(i)); for( Int j=0; j<n; ++j ) A(i,j) *= gamma; } }
ll Comb(int n, int m, int k) { set(dp, 0); v.clear(); int tmp = k; for (int i = 2; i * i <= tmp; i++) { if (tmp % i == 0) { int num = 0; while (tmp % i == 0) { tmp /= i; num++; } v.pb(i); } } if (tmp != 1) v.pb(tmp); ll ans = Cal(n - m + 1, n, k, 1); for (int j = 0; j < v.size(); j++) { ans = ans * Pow(v[j], dp[j], k) % k; } ans = ans * inv(Cal(2, m, k, -1), k) % k; return ans; }
inline void MakeLegendre( Matrix<F>& A ) { #ifndef RELEASE CallStackEntry entry("MakeLegendre"); #endif if( A.Height() != A.Width() ) LogicError("Cannot make a non-square matrix Legendre"); MakeZeros( A ); const Int n = A.Width(); for( Int j=0; j<n-1; ++j ) { const F gamma = F(1) / Pow( F(2)*(j+1), F(2) ); const F beta = F(1) / (2*Sqrt(F(1)-gamma)); A.Set( j+1, j, beta ); A.Set( j, j+1, beta ); } }
inline void MakeKahan( F phi, DistMatrix<F,U,V>& A ) { #ifndef RELEASE PushCallStack("MakeKahan"); #endif typedef typename Base<F>::type R; const int m = A.Height(); const int n = A.Width(); if( m != n ) throw std::logic_error("Cannot make a non-square matrix Kahan"); if( Abs(phi) >= R(1) ) throw std::logic_error("Phi must be in (0,1)"); const F zeta = Sqrt(1-phi*Conj(phi)); const int localHeight = A.LocalHeight(); const int localWidth = A.LocalWidth(); const int colShift = A.ColShift(); const int rowShift = A.RowShift(); const int colStride = A.ColStride(); const int rowStride = A.RowStride(); for( int iLocal=0; iLocal<localHeight; ++iLocal ) { const int i = colShift + iLocal*colStride; const F zetaPow = Pow( zeta, R(i) ); for( int jLocal=0; jLocal<localWidth; ++jLocal ) { const int j = rowShift + jLocal*rowStride; if( i > j ) A.SetLocal( iLocal, jLocal, F(0) ); else if( i == j ) A.SetLocal( iLocal, jLocal, zetaPow ); else A.SetLocal( iLocal, jLocal, -phi*zetaPow ); } } #ifndef RELEASE PopCallStack(); #endif }
Real Matrix::Determinant(MType eType) const { Real result = 0.0; switch(eType) { case MI_IDENTITY: result = 1.0; break; case MI_UNIT_SCALE: case MI_UNIT_SCALE_TRANSLATE: result = Pow(this->m00,3); break; case MI_SCALE_TRANSLATE: case MI_SCALE: result = this->m00 * this->m11 * this->m22; break; case MI_ROTATE: case MI_TRANSLATE: case MI_ROTATE_TRANSLATE: result = 1.0; break; case MI_3X3DMATRIX: case MI_AFFINE: result = Determinant3X3(m00,m01,m02,m10,m11,m12,m20,m21,m22); // result = this->m00 * (this->m11 * this->m22 - this->m21 * this->m12) // - this->m01 * (this->m10 * this->m22 - this->m20 * this->m12) // + this->m02 * (this->m10 * this->m21 - this->m20 * this->m11); break; case MI_GENERIC: result = m00 * (m11 * (m22 * m33 - m23 * m32) - m12 * (m21 * m33 - m23 * m31) + m13 * (m21 * m32 - m22 * m31)) - m01 * (m10 * (m22 * m33 - m23 * m32) - m12 * (m20 * m33 - m23 * m30) + m13 * (m20 * m32 - m22 * m30)) + m02 * (m10 * (m21 * m33 - m23 * m31) - m11 * (m20 * m33 - m23 * m30) + m13 * (m20 * m31 - m21 * m30)) - m03 * (m10 * (m21 * m32 - m22 * m31) - m11 * (m20 * m32 - m22 * m30) + m12 * (m20 * m31 - m21 * m30)); break; } return result; }
void Work(void) { int Ans = 0, uplast = 1, downlast = 1; T.Set(max); T.Insert(a[n], 1); number[a[n]]++; for (int i = n - 1; i >= 1; i--) { int Sk = ++number[a[i]], Now = 1; T.Insert(a[i], 1); int count = T.Cal(a[i] - 1); uplast = (Int64) uplast * Divid(n - i, up) % Mod; downlast = (Int64) downlast * Divid(Sk, down) % Mod; if (count) count = Divid(count, yy); else continue; int tmp1 = 1; for (int j = 1; j <= cnt; j++) { tmp1 = (Int64) tmp1 * Pow(factory[j], yy[j] + up[j] - down[j]) % Mod; yy[j] = 0; } int tmp2 = (Int64) uplast * _E(downlast) % Mod; count = (Int64) count * tmp1 % Mod; count = (Int64) count * tmp2 % Mod; Ans = (Int64) ((count + Ans) % Mod); } printf("%d\n", (Ans + 1) % Mod); }
void SplineInterpolate(const vector<Vector>& pts, GeneralizedCubicBezierSpline& path, CSpace* space,GeodesicManifold* manifold, Real coxDeBoorParameter) { if(coxDeBoorParameter == 0) { //uniform SplineInterpolate(pts,path.segments,space,manifold); path.durations.resize(path.segments.size()); fill(path.durations.begin(),path.durations.end(),1); } else { vector<Real> times(pts.size()); times[0] = 0; path.durations.resize(pts.size()-1); for(size_t i=0;i+1<pts.size();i++) { path.durations[i] = Pow(pts[i].distance(pts[i+1]),coxDeBoorParameter); times[i+1] = times[i] + path.durations[i]; } SplineInterpolate(pts,times,path.segments,space,manifold); } }
Base<Field> SparseToNormLowerBound ( const Matrix<Base<Field>>& d, const Matrix<Field>& y ) { EL_DEBUG_CSE typedef Base<Field> Real; const Int n = d.Height(); const Real* dBuf = d.LockedBuffer(); const Field* yBuf = y.LockedBuffer(); const Real oneHalf = Real(1)/Real(2); Real lowerBoundSquared = 0; for( Int j=0; j<n; ++j ) { if( yBuf[j] != Field(0) ) { const Real arg = (Abs(yBuf[j])-oneHalf)*dBuf[j]; lowerBoundSquared += Pow(arg,Real(2)); } } return Sqrt(lowerBoundSquared); }
Int Newton( DistMatrix<Field>& A, const SignCtrl<Base<Field>>& ctrl ) { EL_DEBUG_CSE typedef Base<Field> Real; Real tol = ctrl.tol; if( tol == Real(0) ) tol = A.Height()*limits::Epsilon<Real>(); Int numIts=0; DistMatrix<Field> B( A.Grid() ); DistMatrix<Field> *X=&A, *XNew=&B; while( numIts < ctrl.maxIts ) { // Overwrite XNew with the new iterate NewtonStep( *X, *XNew, ctrl.scaling ); // Use the difference in the iterates to test for convergence Axpy( Real(-1), *XNew, *X ); const Real oneDiff = OneNorm( *X ); const Real oneNew = OneNorm( *XNew ); // Ensure that X holds the current iterate and break if possible ++numIts; std::swap( X, XNew ); if( ctrl.progress && A.Grid().Rank() == 0 ) cout << "after " << numIts << " Newton iter's: " << "oneDiff=" << oneDiff << ", oneNew=" << oneNew << ", oneDiff/oneNew=" << oneDiff/oneNew << ", tol=" << tol << endl; if( oneDiff/oneNew <= Pow(oneNew,ctrl.power)*tol ) break; } if( X != &A ) A = *X; return numIts; }