From d75409aae5b512bfd17c091a383c31294f31169e Mon Sep 17 00:00:00 2001 From: deseilligny Date: Fri, 15 Mar 2024 15:34:08 +0100 Subject: [PATCH] Hand merge mpd/SatSession --- MMVII/include/MMVII_Ptxd.h | 24 ++++++++++--- MMVII/include/SymbDer/SymbDer_BinaryOp.h | 2 ++ MMVII/include/SymbDer/SymbDer_UnaryOp.h | 1 + MMVII/include/SymbDer/SymbolicDerivatives.h | 39 +++++++++++++++++++-- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/MMVII/include/MMVII_Ptxd.h b/MMVII/include/MMVII_Ptxd.h index 3c86982663..079eff4c61 100755 --- a/MMVII/include/MMVII_Ptxd.h +++ b/MMVII/include/MMVII_Ptxd.h @@ -146,15 +146,19 @@ template class cPtxd inline Type & x() {static_assert(Dim>=1,"bad dim in cPtxd initializer");return mCoords[0];} inline const Type & x() const {static_assert(Dim>=1,"bad dim in cPtxd initializer");return mCoords[0];} + inline tBigNum BigX2() const {return Square(tBigNum(x()));} inline Type & y() {static_assert(Dim>=2,"bad dim in cPtxd initializer");return mCoords[1];} inline const Type & y() const {static_assert(Dim>=2,"bad dim in cPtxd initializer");return mCoords[1];} + inline tBigNum BigY2() const {return Square(tBigNum(y()));} inline Type & z() {static_assert(Dim>=3,"bad dim in cPtxd initializer");return mCoords[2];} inline const Type & z() const {static_assert(Dim>=3,"bad dim in cPtxd initializer");return mCoords[2];} + inline tBigNum BigZ2() const {return Square(tBigNum(z()));} inline Type & t() {static_assert(Dim>=4,"bad dim in cPtxd initializer");return mCoords[3];} inline const Type & t() const {static_assert(Dim>=4,"bad dim in cPtxd initializer");return mCoords[3];} + inline tBigNum BigT2() const {return Square(tBigNum(t()));} cDenseVect ToVect() const; ///< conversion std::vector ToStdVector() const; ///< conversion @@ -395,10 +399,22 @@ template inline T NormInf(const cPtxd & aP) {return std::max(std: // template inline T SqN2(const cPtxd & aP) {return Square(aP.x());} */ /// Currently, the L2 norm is used for comparaison, no need to extract square root -template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) {return Square(aP.x());} -template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) {return Square(aP.x())+Square(aP.y());} -template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) {return Square(aP.x())+Square(aP.y())+Square(aP.z());} -template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) {return Square(aP.x())+Square(aP.y())+Square(aP.z()) + Square(aP.t()) ;} +template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) +{ + return aP.BigX2(); +} +template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) +{ + return aP.BigX2() + aP.BigY2(); +} +template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) +{ + return aP.BigX2() + aP.BigY2() + aP.BigZ2(); +} +template inline typename tNumTrait::tBig SqN2(const cPtxd & aP) +{ + return aP.BigX2() + aP.BigY2() + aP.BigZ2() + aP.BigT2() ; +} /// Sort vector by norm, typically dont need to compute square root template bool CmpN2(const cPtxd &aP1,const cPtxd & aP2) { diff --git a/MMVII/include/SymbDer/SymbDer_BinaryOp.h b/MMVII/include/SymbDer/SymbDer_BinaryOp.h index 2fdaf5c959..f195e2a588 100755 --- a/MMVII/include/SymbDer/SymbDer_BinaryOp.h +++ b/MMVII/include/SymbDer/SymbDer_BinaryOp.h @@ -50,6 +50,8 @@ template class cBinaryF : public cImplemF InternalError("No operation defined",aV1->CoordF()->Name()); return aV1; } + + std::string Name4Print() const override {return this->NameOperator();} protected : void AssocSortedVect(std::vector & aV); void EmpileAssoc (const cFormula & aF, std::vector & aV); diff --git a/MMVII/include/SymbDer/SymbDer_UnaryOp.h b/MMVII/include/SymbDer/SymbDer_UnaryOp.h index 3e7b9f577d..53cafe388b 100755 --- a/MMVII/include/SymbDer/SymbDer_UnaryOp.h +++ b/MMVII/include/SymbDer/SymbDer_UnaryOp.h @@ -37,6 +37,7 @@ template class cUnaryF : public cImplemF { return this->NameOperator() + " "+ mF->InfixPPrint() + PostName() ; } + std::string Name4Print() const override {return this->NameOperator();} protected : virtual std::string GenCodeExpr() const override diff --git a/MMVII/include/SymbDer/SymbolicDerivatives.h b/MMVII/include/SymbDer/SymbolicDerivatives.h index 03b207eb11..2336ba48fd 100755 --- a/MMVII/include/SymbDer/SymbolicDerivatives.h +++ b/MMVII/include/SymbDer/SymbolicDerivatives.h @@ -552,6 +552,8 @@ template class cImplemF : public SYMBDER_cMemCheck /// Access at global level is 4 reducing, also it is used 4 implemant in Unary & Binary virtual const std::string & NameOperator() const = 0; + /// Name for pretty print + virtual std::string Name4Print() const = 0; // -------------------- Destructor / Constructor -------------------------- @@ -655,7 +657,8 @@ template class cAtomicF : public cImplemF typedef typename tCoordF::tFormula tFormula; /// Should work always - std::string InfixPPrint() const override {return tImplemF::Name();} + // std::string InfixPPrint() const override {return tImplemF::Name();} + std::string InfixPPrint() const override {return this->Name4Print();} /// Rule deriv=0 , work by default (constant and observations) tFormula Derivate(int aK) const override {return tImplemF::mCoordF->Cste0();} @@ -682,8 +685,9 @@ template class cUnknownF : public cAtomicF typedef typename tCoordF::tFormula tFormula; const std::string & NameOperator() const override {static std::string s("UK"); return s;} + std::string Name4Print() const override {return tImplemF::Name() +"_UK";} - std::string InfixPPrint() const override {return tImplemF::Name();} + // std::string InfixPPrint() const override {return tImplemF::Name();} All ready overided /// rule : dXi/dXj = delta(i,j) tFormula Derivate(int aK) const override { @@ -712,6 +716,8 @@ template class cObservationF : public cAtomicF friend tCoordF; const std::string & NameOperator() const override {static std::string s("Obs"); return s;} + std::string Name4Print() const override {return tImplemF::Name() +"_Obs";} + // const std::string & NameOperator() const override {return tImplemF::Name() +"-Obs";} private : inline cObservationF(tCoordF * aCoordF,const std::string & aName,int aNum) : tAtom (aCoordF,aName), @@ -735,6 +741,7 @@ template class cConstantF : public cAtomicF bool IsCste(const TypeElem &K) const override {return mVal==K;} ///< Here we know if we are a constant of value K const TypeElem * ValCste() const override {return &mVal;} const std::string & NameOperator() const override {static std::string s("Cste"); return s;} + std::string Name4Print() const override {return std::to_string(mVal) +"_Cste";} protected : inline cConstantF(tCoordF * aCoordF,const std::string & aName,int aNum,const TypeElem& aVal) : tAtom (aCoordF,aName), @@ -1271,6 +1278,34 @@ inline const cFormula SymbCommentDer(const cFormula & aF, in } + +template void StdShowTreeFormulaRec(const cFormula& aF,int aMaxPerL,int aLevel) +{ + + // StdOut() << aF->GenCodeFormName() << std::endl; + // StdOut() << aF->GenCodeExpr() << std::endl; + for (int aK=0 ; aK < aLevel ; aK++) + { + std::cout << " "; + } + if (aF->RecursiveRec() < aMaxPerL) + { + std::cout << aF->InfixPPrint() << std::endl; + } + else + { + std::cout << aF->Name4Print() << std::endl; + for (auto aChild : aF->Ref()) + StdShowTreeFormulaRec(aChild,aMaxPerL,aLevel+1); + } +} +template void StdShowTreeFormula(const cFormula& aF,int aMaxPerL=7) +{ + StdShowTreeFormulaRec(aF,aMaxPerL,0); +} + + + } // namespace NS_SymbolicDerivative