PermGroup *normalClosure( const PermGroup *const G, const PermGroup *const H) { PermGroup *N = copyOfPermGroup( H); Permutation *a, *b, *newGen; Unsigned i; UnsignedS *img = allocIntArrayBaseSize(); G->base[G->baseSize+1] = 0; changeBase( N, G->base); for ( a = G->generator ; a ; a = a->next ) for ( b = H->generator ; b ; b = b->next ) { for ( i = 1 ; i <= G->baseSize ; ++i ) img[i] = a->image[b->image[a->invImage[G->base[i]]]]; if ( !isBaseImage( N, img) ) { newGen = newIdentityPerm( G->degree); rightMultiplyInv( newGen, a); rightMultiply( newGen, b); rightMultiply( newGen, a); reduceWrtGroup( N, newGen, NULL); addStrongGenerator( N, newGen, TRUE); } } freeIntArrayBaseSize( img); return N; }
PermGroup *commutatorGroup( const PermGroup *const G, const PermGroup *const H) { PermGroup *C = newTrivialPermGroup( G->degree); Permutation *a, *b, *x, *newGen; Unsigned i; UnsignedS *img = allocIntArrayBaseSize(); G->base[G->baseSize+1] = 0; changeBase( C, G->base); for ( a = G->generator ; a ; a = a->next ) for ( b = (H == G ? a->next : H->generator) ; b ; b = b->next ) for ( x = G->generator ; x ; x = x->next ) { for ( i = 1 ; i <= G->baseSize ; ++i ) { img[i] = b->invImage[a->invImage[x->invImage[G->base[i]]]]; img[i] = x->image[b->image[a->image[img[i]]]]; } if ( !isBaseImage( C, img) ) { newGen = newIdentityPerm( G->degree); rightMultiplyInv( newGen, x); rightMultiplyInv( newGen, a); rightMultiplyInv( newGen, b); rightMultiply( newGen, a); rightMultiply( newGen, b); rightMultiply( newGen, x); reduceWrtGroup( C, newGen, NULL); addStrongGenerator( C, newGen, TRUE); } } freeIntArrayBaseSize( img); return C; }
QString RealFormat::fracPart(const RawFloatIO& io) const { if (significandbase == base || precision == 0) return io.fracpart; return changeBase(_digitsz(base), _digitsz(significandbase), getDigits(), io.fracpart, 0, lowerCaseHexDigit); }
int TreeJntToJacSolver::JntToJac(const JntArray& q_in, Jacobian& jac, const std::string& segmentname) { //First we check all the sizes: if (q_in.rows() != tree.getNrOfJoints() || jac.columns() != tree.getNrOfJoints()) return -1; //Lets search the tree-element SegmentMap::value_type const* it = tree.getSegmentPtr(segmentname); //If segmentname is not inside the tree, back out: if (!it) return -2; //Let's make the jacobian zero: SetToZero(jac); SegmentMap::value_type const* root = tree.getSegmentPtr("root"); Frame T_total = Frame::Identity(); Frame T_local, T_joint; Twist t_local; //Lets recursively iterate until we are in the root segment while (it != root) { //get the corresponding q_nr for this TreeElement: unsigned int q_nr = it->second.q_nr; //get the pose of the joint. T_joint = it->second.segment.getJoint().pose(((JntArray&)q_in)(q_nr)); // combine with the tip to have the tip pose T_local = T_joint*it->second.segment.getFrameToTip(); //calculate new T_end: T_total = T_local * T_total; //get the twist of the segment: int ndof = it->second.segment.getJoint().getNDof(); for (int dof=0; dof<ndof; dof++) { // combine joint rotation with tip position to get a reference frame for the joint T_joint.p = T_local.p; // in which the twist can be computed (needed for NDof joint) t_local = it->second.segment.twist(T_joint, 1.0, dof); //transform the endpoint of the local twist to the global endpoint: t_local = t_local.RefPoint(T_total.p - T_local.p); //transform the base of the twist to the endpoint t_local = T_total.M.Inverse(t_local); //store the twist in the jacobian: jac.twists[q_nr+dof] = t_local; } //goto the parent it = it->second.parent; }//endwhile //Change the base of the complete jacobian from the endpoint to the base changeBase(jac, T_total.M, jac); return 0; }//end JntToJac
void RegistersModel::setBase(int frmt) { qDebug()<< "RegistersModel : setBase " << frmt ; changeBase(frmt); if (frmt == 11) { // Unsigned Integer m_base = 10; } else { m_base = frmt; } m_frmt = frmt; }
void BaseStage::begin() { changeBase(); textFunds = form->findControlTyped<Label>("TEXT_FUNDS"); textFunds->setText(state->getPlayerBalance()); int b = 0; for (auto &pair : state->player_bases) { auto &viewBase = pair.second; auto viewName = format("BUTTON_BASE_%d", ++b); auto view = form->findControlTyped<GraphicButton>(viewName); if (!view) { // This screen doesn't have miniviews return; } if (state->current_base == viewBase) { currentView = view; } view->setData(viewBase); auto viewImage = drawMiniBase(viewBase, viewHighlight, viewFacility); view->setImage(viewImage); view->setDepressedImage(viewImage); wp<GraphicButton> weakView(view); view->addCallback(FormEventType::ButtonClick, [this, weakView](FormsEvent *e) { auto base = e->forms().RaisedBy->getData<Base>(); if (this->state->current_base != base) { this->changeBase(base); this->currentView = weakView.lock(); } }); view->addCallback(FormEventType::MouseEnter, [this](FormsEvent *e) { auto base = e->forms().RaisedBy->getData<Base>(); this->textViewBase->setVisible(true); this->textViewBase->setText(base->name); }); view->addCallback(FormEventType::MouseLeave, [this](FormsEvent *) { this->textViewBase->setText(""); this->textViewBase->setVisible(false); }); miniViews.push_back(view); } textViewBase = form->findControlTyped<Label>("TEXT_BUTTON_BASE"); this->textViewBase->setVisible(false); }
int TreeJntToJacSolver::JntToJac(const JntArray& q_in, Jacobian& jac, const std::string& segmentname) { //First we check all the sizes: if (q_in.rows() != tree.getNrOfJoints() || jac.columns() != tree.getNrOfJoints()) return -1; //Lets search the tree-element SegmentMap::const_iterator it = tree.getSegments().find(segmentname); //If segmentname is not inside the tree, back out: if (it == tree.getSegments().end()) return -2; //Let's make the jacobian zero: SetToZero(jac); SegmentMap::const_iterator root = tree.getRootSegment(); Frame T_total = Frame::Identity(); //Lets recursively iterate until we are in the root segment while (it != root) { //get the corresponding q_nr for this TreeElement: unsigned int q_nr = it->second.q_nr; //get the pose of the segment: Frame T_local = it->second.segment.pose(q_in(q_nr)); //calculate new T_end: T_total = T_local * T_total; //get the twist of the segment: if (it->second.segment.getJoint().getType() != Joint::None) { Twist t_local = it->second.segment.twist(q_in(q_nr), 1.0); //transform the endpoint of the local twist to the global endpoint: t_local = t_local.RefPoint(T_total.p - T_local.p); //transform the base of the twist to the endpoint t_local = T_total.M.Inverse(t_local); //store the twist in the jacobian: jac.setColumn(q_nr,t_local); }//endif //goto the parent it = it->second.parent; }//endwhile //Change the base of the complete jacobian from the endpoint to the base changeBase(jac, T_total.M, jac); return 0; }//end JntToJac
QString RealFormat::intPart(const RawFloatIO& io) const { if (significandbase == base) return io.intpart; int idigitsz = _digitsz(base); int ibitlg = (io.intpart.size() << idigitsz); // reduce length by count of leading zero bits in the first digit const char* p = "1248"; QChar c = io.intpart.at(0); while (*p) if (c < *(p++)) --ibitlg; if (ibitlg == 0) return "0"; int odigitsz = _digitsz(significandbase); int osz = ((ibitlg - 1) >> odigitsz) + 1; return changeBase(idigitsz, odigitsz, osz, io.intpart, (osz << odigitsz) - ibitlg, lowerCaseHexDigit); }
StringList* getAlphabetCombinations(char *alphabet, int combinationLength) { if(alphabet == NULL){ return NULL; } char *combination = malloc((combinationLength + 1) * sizeof(char)); int nSymbols = strlen(alphabet); int totalCombinations = pow(nSymbols, combinationLength); int *baseChanged; StringList* combinations = malloc(sizeof(StringList)); initStringList(combinations); for(int i = 0; i < totalCombinations; i++){ baseChanged = changeBase(i, nSymbols, combinationLength); for(int j = 0; j < combinationLength; j++){ combination[j] = alphabet[baseChanged[j]]; } combination[combinationLength] = '\0'; free(baseChanged); addString(combinations, strdup(combination)); } free(combination); return combinations; }
float DexCalc::eval(std::string expr) { int i; std::string result; std::string newExpr, token, prevToken; std::stack<std::string> opStack, elemStack, inStack; int depth; newExpr = "(" + expr + ")"; if (!mTurbo) newExpr = TS_Util::fixExpr(newExpr); newExpr = replaceEx(newExpr, "E", "*10^"); // STEP #1 (GROUP) // group tokens into operators and operands // (check for syntax errors) // // "(1 * 2 + 3)" // // [O]: ( * + ) // [E]: 1 2 3 // [I]: token = ""; depth = 0; i = 0; while (i < newExpr.length()) { prevToken = token; //============================== token = getNextTerm(newExpr, i); //============================== depth += (token == "(") ? 1 : 0; depth -= (token == ")") ? 1 : 0; if (depth < 0) throw Exception("expected end of statement"); #ifndef TURBO_MODE if (TS_Util::rankOp(prevToken[0]) > 0 || prevToken == "(") { if (token == "+") { token = prevToken; continue; } if (token == "-") token = "neg"; if (token == "!") token = "not"; if (token == "~") token = "bnot"; std::string prefix = left(token, 2); std::string value = lcase(right(token, token.length() - 2)); if (prefix == "0x") token = changeBase(value, 16, 10); if (prefix == "0o") token = changeBase(value, 8, 10); if (prefix == "0b") token = changeBase(value, 2, 10); } if ( TS_Util::rankOp(prevToken[0]) && (token[0] == OP_INC || token[0] == OP_DEC) || (prevToken[0] == OP_INC || prevToken[0] == OP_DEC) && TS_Util::rankOp(token[0]) ) elemStack.push("0"); else if (TS_Util::isFunc(prevToken) && token != "@" && token != ")") opStack.push("@"); else TS_Util::checkSyntaxError(prevToken, token); #endif //================================= if (TS_Util::rankOp(token[0])) opStack.push(token); else elemStack.push(token); //================================= } if (depth > 0) throw Exception("expected close paren"); // force operator into inStack // (start chain reaction) // // "(1 * 2 + 3)" // // [O]: ( * + // [E]: 1 2 3 // [I]: ) inStack.push(opStack.top()); opStack.pop(); while (!inStack.empty()) { // STEP #2 (LOAD) // load inStack with opStack, elemStack elements // (stop at appropriate point) // // "(1 * 2 + 3)" // // [O]: ( // [E]: 1 // [I]: ) 3 + 2 * while ( (opStack.top()[0] == OP_SET && TS_Util::rankOp(opStack.top()[0]) > TS_Util::rankOp(inStack.top()[0])) || (opStack.top()[0] != OP_SET && TS_Util::rankOp(opStack.top()[0]) >= TS_Util::rankOp(inStack.top()[0])) || opStack.top() == ")" ) { // transfer close-parens to inStack // (if any) while (opStack.top() == ")") { inStack.push(opStack.top()); opStack.pop(); } // transfer operand to inStack inStack.push(elemStack.top()); elemStack.pop(); // force operator into inStack // (continue chain reaction) if (opStack.top() != "(") { inStack.push(opStack.top()); opStack.pop(); } } // STEP #3 (BIND) // bind elemStack, inStack operands with an opStack operator // (push result into elemStack) // // "(1 * 2 + 3)" // // [O]: ( * // [E]: 1 // [I]: ) 3 + 2 // // [O]: ( + // [E]: 2 // [I]: ) 3 // // [O]: ( // [E]: 5 // [I]: ) // // [O]: // [E]: 5 // [I]: while (TS_Util::rankOp(opStack.top()[0]) <= TS_Util::rankOp(inStack.top()[0])) { if (TS_Util::rankOp(inStack.top()[0])) { //====================================================== opStack.push(inStack.top()); inStack.pop(); float temp = this->bind( elemStack.top(), opStack.top()[0], inStack.top() ); result = (fabs(temp) == HUGE_VAL) ? "0" : cstr(temp); opStack.pop(); elemStack.pop(); //====================================================== } else result = inStack.top(); //============ inStack.pop(); //============ while (!opStack.empty() && opStack.top() == "(" && inStack.top() == ")") { opStack.pop(); inStack.pop(); } if (inStack.empty()) { if (isNumeric(result)) return val(result); else return this->getVar(result); } else elemStack.push(result); } } throw Exception("unknown error"); }
int main(int argc, char** argv) { cout << endl << "Welcome to BigNum! Enter \"help\" for assistance." << endl << endl; settings user(10, false, false); bool commline=false; if (argc>1) commline=true; string entered; PTYPE problemType = ERROR; bool exit = false; bigNumber previous; previous.updateDigits(); while (exit == false) { if (commline==false) { entered.clear(); if (previous.getBase() != user.getBase()) previous.convertBase(user.getBase()); cout << "\n"; displayNumber(previous, user, false, true); cout << "\n\n"; std::getline(cin, entered); cout << "-----------------------" << endl; if (changeBase(entered, user)) { continue; } if (entered == "clear" || entered == "reset") { bigNumber reset(0); reset.setBase(user.getBase()); previous = reset; continue; } if (entered == "settings" || entered == "options" || entered == "preferences") { modifySettings(user); continue; } if (entered == "show stats") { cout << "\nNumber stats are visible\n\n"; user.showDigitsOn(); continue; } if (entered == "hide stats") { cout << "\nNumber stats are hidden\n\n"; user.showDigitsOff(); continue; } if (entered == "help") { printHelp(); continue; } } else { entered.clear(); for (int i=1; i<argc; i++) { entered += argv[i]; } commline=false; } if (entered != "exit" && entered != "EXIT" && entered != "Exit") { solution answer(solve(entered, previous, user)); if (answer.getError()>0) { cout << endl << "Invalid Input (Error " << answer.getError() << ")"; } else { previous = answer.getSolved(); } } else exit = true; cout << endl; } }