void value_sett::get_value_set( const exprt &expr, object_mapt &dest, const namespacet &ns, bool is_simplified) const { exprt tmp(expr); if(!is_simplified) simplify(tmp, ns); get_value_set_rec(tmp, dest, "", tmp.type(), ns); }
void addPortDescr(int type, const char* label, int hint, float min=0.0, float max=0.0) { string fullname = simplify(fPrefix.top() + "-" + label); char * str = strdup(fullname.c_str()); fPortDescs[fInsCount + fOutsCount + fCtrlCount] = type; fPortNames[fInsCount + fOutsCount + fCtrlCount] = str; fPortHints[fInsCount + fOutsCount + fCtrlCount].HintDescriptor = hint; fPortHints[fInsCount + fOutsCount + fCtrlCount].LowerBound = min; fPortHints[fInsCount + fOutsCount + fCtrlCount].UpperBound = max; fCtrlCount++; }
bool QgsAbstractFeatureIterator::nextFeature( QgsFeature& f ) { bool dataOk = false; if ( mRequest.limit() >= 0 && mFetchedCount >= mRequest.limit() ) { return false; } if ( mUseCachedFeatures ) { if ( mFeatureIterator != mCachedFeatures.constEnd() ) { f = mFeatureIterator->mFeature; ++mFeatureIterator; dataOk = true; } else { dataOk = false; // even the zombie dies at this point... mZombie = false; } } else { switch ( mRequest.filterType() ) { case QgsFeatureRequest::FilterExpression: dataOk = nextFeatureFilterExpression( f ); break; case QgsFeatureRequest::FilterFids: dataOk = nextFeatureFilterFids( f ); break; default: dataOk = fetchFeature( f ); break; } } // simplify the geometry using the simplifier configured if ( dataOk && mLocalSimplification ) { if ( f.constGeometry() ) simplify( f ); } if ( dataOk ) mFetchedCount++; return dataOk; }
bool ranking_synthesis_satt::generate_functions(void) { exprt templ = instantiate(); if(body.variable_map.size()==0 || templ.is_false()) return false; // some coefficient values c_valuest c_values; debug("Template:" + from_expr(ns, "", templ)); satcheckt::resultt result=satcheckt::P_SATISFIABLE; while(result==satcheckt::P_SATISFIABLE) { if(c_values.size()==0) initialize_coefficients(c_values); else { if(increase_coefficients(c_values)) break; } result=check_for_counterexample(templ, c_values, conversion_time, solver_time); } if(result==satcheckt::P_ERROR) throw ("Solver error."); else if(result==satcheckt::P_UNSATISFIABLE) // no counter-example { debug("Found ranking functions"); // put the coefficient values in the rank relation replace_mapt replace_map; for(c_valuest::const_iterator it=c_values.begin(); it!=c_values.end(); it++) { replace_map[it->first] = from_integer(it->second, it->first.type()); } replace_expr(replace_map, rank_relation); simplify(rank_relation, ns); return true; } else return false; }
/** * \return Representation of the given number as fraction (number numerator/denominator). * Rounding occurs to satisfy the use of maxDenominator as maximum value for denominator. */ void RMath::toFraction(double v, int maxDenominator, int& number, int& numerator, int& denominator) { int in = (int)v; number = in; if (in==v) { number = in; numerator = 0; denominator = 1; return; } simplify(abs(mround((v-in)*maxDenominator)), maxDenominator, numerator, denominator); }
int main(void) { struct Fraction f; printf("Fraction Simplifier\n"); printf("===================\n"); enter(&f); simplify(&f); display(&f); return 0; }
void solve(unsigned short* sudoku, int recursionLevel) { do { boolean couldSimplify = simplify(sudoku, recursionLevel); // if(recursionLevel > 0 && !couldSimplify) // return; if(isSolved(sudoku)) return; } while( guess(sudoku, recursionLevel+1) ); }
void BezierCurve::simplify(double tol, QList<QPointF> &inputList, int j, int k, QList<bool> &markList) { // -- Douglas-Peucker simplification algorithm // from http://geometryalgorithms.com/Archive/algorithm_0205/ if (k <= j+1) { //there is nothing to simplify // return immediately } else { // test distance of intermediate vertices from segment Vj to Vk double maxd = 0.0; //is the distance of farthest vertex from segment jk int maxi = j; //is the index of the vertex farthest from segement jk for(int i=j+1; i<k-1;i++) { // each intermediate vertex Vi QPointF Vij = inputList.at(i)-inputList.at(j); QPointF Vjk = inputList.at(j)-inputList.at(k); double Vijx = Vij.x(); double Vijy = Vij.y(); double Vjkx = Vjk.x(); double Vjky = Vjk.y(); double dv = (Vjkx*Vjkx+Vjky*Vjky); if( dv != 0.0) { dv = sqrt( Vijx*Vijx+Vijy*Vijy - pow(Vijx*Vjkx+Vijy*Vjky,2)/dv ); } //qDebug() << "distance = "+QString::number(dv); if (dv < maxd) { //Vi is not farther away, so continue to the next vertex } else { //Vi is a new max vertex maxd = dv; maxi = i; //to remember the farthest vertex } } if (maxd >= tol) { //a vertex is farther than tol from Sjk // split the polyline at the farthest vertex //Mark Vmaxi as part of the simplified polyline markList.replace(maxi, true); //and recursively simplify the two subpolylines simplify(tol, inputList, j, maxi, markList); simplify(tol, inputList, maxi, k, markList); } } }
int runInterpreter(void) { AST M = getTree("main"); if(M != NULL) { AST R = simplify(M); if((R->kind == ACTION_NK) || ((R->kind == BASIC_FUNC_NK) && ((R->extra == PRILST_FK) || (R->extra == PRINT_FK) || (R->extra == PROD_FK) || (R->extra == READI_FK) || (R->extra == READC_FK)))) { AST ret = performAction(R); if(ret->kind != EMPTYLIST) { if(ret->kind == CONS_NK) displayList(ret); else displayAST(ret); } } else { AST S = simplify(R); if(S->kind != EMPTYLIST) { if(S->kind == CONS_NK) displayList(S); else displayAST(R); } } printf("\n"); } return 0; }
static void testSimplifySkinnyTriangle3() { SkPath path, out; path.moveTo(591, 627.534851f); path.lineTo(541, 560.707642f); path.lineTo(491, 493.880310f); path.lineTo(441, 427.053101f); path.close(); path.moveTo(317, 592.013306f); path.lineTo(366, 542.986572f); path.lineTo(416, 486.978577f); path.lineTo(465, 430.970581f); path.close(); simplify(__FUNCTION__, path, true, out); }
void absval_tensor(void) { if (p1->u.tensor->ndim != 1) stop("abs(tensor) with tensor rank > 1"); push(p1); push(p1); conjugate(); inner(); push_rational(1, 2); power(); simplify(); eval(); }
END_TEST START_TEST(test_issue200) { input_from_file(TESTDIR "/bounds/issue200.vhd"); tree_t a = parse_and_check(T_ENTITY, T_ARCH); fail_unless(sem_errors() == 0); simplify(a); bounds_check(a); fail_unless(bounds_errors() == 0); }
END_TEST START_TEST(test_issue36) { input_from_file(TESTDIR "/bounds/issue36.vhd"); tree_t e = parse_and_check(T_ENTITY); fail_unless(sem_errors() == 0); simplify(e); bounds_check(e); fail_unless(bounds_errors() == 0); }
Integer prs_resultant_ufd< Integer >(Poly_1 A, Poly_1 B) { #ifdef CGAL_ACK_BENCHMARK_RES res_tm.start(); #endif // implemented using the subresultant algorithm for resultant computation // see [Cohen, 1993], algorithm 3.3.7 typedef Integer NT; if (A.is_zero() || B.is_zero()) return NT(0); int signflip; if (A.degree() <123 B.degree()) { Polynomial<NT> T = A; A = B; B = T; signflip = (A.degree() & B.degree() & 1); } else { signflip = 0; } NT a = A.content(), b = B.content(); NT g(1), h(1), t = CGAL::ipower(a, B.degree()) * CGAL::ipower(b, A.degree()); Polynomial<NT> Q, R; NT d; int delta; A /= a; B /= b; do { signflip ^= (A.degree() & B.degree() & 1); Polynomial<NT>::pseudo_division(A, B, Q, R, d); delta = A.degree() - B.degree(); typedef CGAL::Algebraic_structure_traits<NT>::Is_exact Is_exact; A = B; B = R / (g * CGAL::ipower(h, delta)); g = A.lcoeff(); // h = h^(1-delta) * g^delta CGALi::hgdelta_update(h, g, delta); } while (B.degree() > 0); // h = h^(1-deg(A)) * lcoeff(B)^deg(A) delta = A.degree(); g = B.lcoeff(); CGALi::hgdelta_update(h, g, delta); h = signflip ? -(t*h) : t*h; Algebraic_structure_traits<NT>::Simplify simplify; simplify(h); return h; }
QgsSimplifyDialog::QgsSimplifyDialog( QWidget* parent ) : QDialog( parent ) { setupUi( this ); connect( horizontalSlider, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) ); connect( horizontalSlider, SIGNAL( valueChanged( int ) ), spinBox, SLOT( setValue( int ) ) ); connect( spinBox, SIGNAL( valueChanged( int ) ), horizontalSlider, SLOT( setValue( int ) ) ); connect( okButton, SIGNAL( clicked() ), this, SLOT( simplify() ) ); }
Exponent::Exponent(string str) { baseIsFrac = false; baseIsInt = false; powerIsFrac = false; powerIsInt = false; separate(str); findPowerType(); findBaseType(); simplify(); canSimplifyToFrac(); canSimplifyToInt(); }
/** * Eval a block diagram to an int. * * Eval a block diagram that represent an integer constant. This function first eval * a block diagram to its normal form, then check it represent a numerical value (a * block diagram of type : 0->1) then do a symbolic propagation and try to convert the * resulting signal to an int. * @param exp the expression to evaluate * @param globalDefEnv the global environment * @param visited list of visited definition to detect recursive definitions * @param localValEnv the local environment * @return a block diagram in normal form */ static int eval2int (Tree exp, Tree visited, Tree localValEnv) { Tree diagram = a2sb(eval(exp, visited, localValEnv)); // pour getBoxType() int numInputs, numOutputs; getBoxType(diagram, &numInputs, &numOutputs); if ( (numInputs > 0) || (numOutputs != 1) ) { evalerror(yyfilename, yylineno, "not a constant expression of type : (0->1)", exp); return 1; } else { Tree lsignals = boxPropagateSig(gGlobal->nil, diagram , makeSigInputList(numInputs) ); Tree val = simplify(hd(lsignals)); return tree2int(val); } }
static int show_auths(char *username, int print_name) { int status = EXIT_OK; struct passwd *pw; int i; cbs_t cbs = { 0, 0, NULL }; if (username == NULL) { if ((pw = getpwuid(getuid())) == NULL) { status = EXIT_NON_FATAL; (void) fprintf(stderr, "%s: ", progname); (void) fprintf(stderr, gettext("No passwd entry\n")); return (status); } username = pw->pw_name; } else if (getpwnam(username) == NULL) { status = EXIT_NON_FATAL; (void) fprintf(stderr, "%s: %s : ", progname, username); (void) fprintf(stderr, gettext("No such user\n")); return (status); } (void) _enum_auths(username, add_auth, NULL, &cbs); if (cbs.auth_cnt == 0) status = EXIT_NON_FATAL; if (status == EXIT_NON_FATAL) { (void) fprintf(stderr, "%s: %s: ", progname, username); (void) fprintf(stderr, gettext("No authorizations\n")); } else { simplify(&cbs); if (print_name) (void) printf("%s: ", username); /* print out the auths */ for (i = 0; i < cbs.auth_cnt - 1; i++) (void) printf("%s,", cbs.auths[i]); /* print out the last entry, without the comma */ (void) printf("%s\n", cbs.auths[cbs.auth_cnt - 1]); /* free memory allocated for authorizations */ free_auths(&cbs); } return (status); }
static int read_data_locale(void) { int r; free_data_locale(); r = parse_env_file("/etc/locale.conf", NEWLINE, "LANG", &data[PROP_LANG], "LANGUAGE", &data[PROP_LANGUAGE], "LC_CTYPE", &data[PROP_LC_CTYPE], "LC_NUMERIC", &data[PROP_LC_NUMERIC], "LC_TIME", &data[PROP_LC_TIME], "LC_COLLATE", &data[PROP_LC_COLLATE], "LC_MONETARY", &data[PROP_LC_MONETARY], "LC_MESSAGES", &data[PROP_LC_MESSAGES], "LC_PAPER", &data[PROP_LC_PAPER], "LC_NAME", &data[PROP_LC_NAME], "LC_ADDRESS", &data[PROP_LC_ADDRESS], "LC_TELEPHONE", &data[PROP_LC_TELEPHONE], "LC_MEASUREMENT", &data[PROP_LC_MEASUREMENT], "LC_IDENTIFICATION", &data[PROP_LC_IDENTIFICATION], NULL); if (r == -ENOENT) { int p; /* Fill in what we got passed from systemd. */ for (p = 0; p < _PROP_MAX; p++) { char *e, *d; assert(names[p]); e = getenv(names[p]); if (e) { d = strdup(e); if (!d) return -ENOMEM; } else d = NULL; free(data[p]); data[p] = d; } r = 0; } simplify(); return r; }
void RangeSet::setRange (std::uint32_t minV, std::uint32_t maxV) { while (hasValue (minV)) { ++minV; if (minV >= maxV) return; } mRanges[minV] = maxV; simplify (); }
bool file_specification::make_absolute(const file_specification& rootspec) { if (absolute()) return true; DEBUG_ASSERT(rootspec.absolute()); // now append this's relative path and filename to the root's absolute path file_specification result = rootspec; for (unsigned i = 0; i < subpath_size(); i++) result.add_subpath(subpath_element(i)); result.set_file(file()); // now the rootspec is the absolute path, so transfer it to this *this = result; // and simplify to get rid of any unwanted .. or . elements simplify(); return true; }
TEST(Simplifier, LdObjClass) { IRUnit unit{test_context}; auto const dummy = BCMarker::Dummy(); auto const cls = SystemLib::s_IteratorClass; // LdObjClass t1:Obj<=C doesn't simplify { auto sub = Type::Obj.specialize(cls); auto obj = unit.gen(Conjure, dummy, sub); auto load = unit.gen(LdObjClass, dummy, obj->dst()); auto result = simplify(unit, load, false); EXPECT_NO_CHANGE(result); } // LdObjClass t1:Obj=C --> Cls(C) { auto exact = Type::Obj.specializeExact(cls); auto obj = unit.gen(Conjure, dummy, exact); auto load = unit.gen(LdObjClass, dummy, obj->dst()); auto result = simplify(unit, load, false); EXPECT_EQ(result.dst->clsVal(), cls); EXPECT_EQ(result.instrs.size(), 0); } }
TEST(Simplifier, LdObjInvoke) { IRUnit unit{test_context}; auto const dummy = BCMarker::Dummy(); auto const taken = unit.defBlock(); // LdObjInvoke t1:Cls doesn't simplify { auto type = Type::Cls; auto cls = unit.gen(Conjure, dummy, type); auto load = unit.gen(LdObjInvoke, dummy, taken, cls->dst()); auto result = simplify(unit, load, false); EXPECT_NO_CHANGE(result); } // LdObjInvoke t1:Cls(C), where C is persistent but has no __invoke // doesn't simplify. { auto type = Type::cns(SystemLib::s_IteratorClass); auto cls = unit.gen(Conjure, dummy, type); auto load = unit.gen(LdObjInvoke, dummy, taken, cls->dst()); auto result = simplify(unit, load, false); EXPECT_NO_CHANGE(result); } }
static SEXP simplify (SEXP fun, SEXP arg1, SEXP arg2) { SEXP ans; if (fun == PlusSymbol) { if (isZero (arg1)) ans = arg2; else if (isUminus (arg1)) ans = simplify (MinusSymbol, arg2, ((((arg1)->u.listsxp.cdrval))->u.listsxp.carval)); else if (isUminus (arg2)) ans = simplify (MinusSymbol, arg1, ((((arg2)->u.listsxp.cdrval))->u.listsxp.carval)); } else if (fun == DivideSymbol) { ans = Rf_lang3 (DivideSymbol, arg1, arg2); } return ans; }
void darctan(void) { push(cadr(p1)); push(p2); derivative(); push_integer(1); push(cadr(p1)); push_integer(2); power(); add(); inverse(); multiply(); simplify(); }
RationalNumber RationalNumber::operator- (RationalNumber num){ RationalNumber temp; if(numerator < num.numerator){ temp.numerator = (num.numerator * denominator) - (num.denominator * numerator); temp.denominator = (num.denominator * denominator); } else{ temp.numerator = (numerator * num.denominator) - (denominator * num.numerator); temp.denominator =(denominator * num.denominator); } return simplify(temp); }
static tree_t run_elab(void) { tree_t t, last_ent = NULL; while ((t = parse())) { sem_check(t); fail_if(sem_errors() > 0); simplify(t); if (tree_kind(t) == T_ENTITY) last_ent = t; } return elab(last_ent); }
ExpressionNode BinaryOperation::simplify(ExpressionNode& left) { if (left.getRight() > 0) { if ((left.getRight())->getRight() != 0) { throw ExpressionNode::WrongArityError("> 2 arguments for BinaryOperation"); } return simplify(left, *left.getRight()); } else { throw ExpressionNode::WrongArityError("only 1 argument for BinaryOperation"); } }
// generates a perfect alignment from the graph Alignment Sampler::alignment(size_t length) { string seq; Alignment aln; Path* path = aln.mutable_path(); pos_t pos = position(); char c = pos_char(pos); // we do something wildly inefficient but conceptually clean // for each position in the mapping we add a mapping // at the end we will simplify the alignment, merging redundant mappings do { // add in the char for the current position seq += c; Mapping* mapping = path->add_mapping(); *mapping->mutable_position() = make_position(pos); Edit* edit = mapping->add_edit(); edit->set_from_length(1); edit->set_to_length(1); // decide the next position auto nextc = next_pos_chars(pos); // no new positions mean we are done; we've reached the end of the graph if (nextc.empty()) break; // what positions do we go to next? vector<pos_t> nextp; for (auto& n : nextc) nextp.push_back(n.first); // pick one at random uniform_int_distribution<int> next_dist(0, nextc.size()-1); // update our position pos = nextp.at(next_dist(rng)); // update our char c = nextc[pos]; } while (seq.size() < length); // save our sequence in the alignment aln.set_sequence(seq); aln = simplify(aln); { // name the alignment string data; aln.SerializeToString(&data); int n; #pragma omp critical(nonce) n = nonce++; data += std::to_string(n); const string hash = sha1head(data, 16); aln.set_name(hash); } // and simplify it aln.set_identity(identity(aln.path())); return aln; }
bool ranking_synthesis_qbf_bitwiset::extract_ranking_relation(boolbvt &converter) { replace_mapt replace_map; for(coefficient_mapt::const_iterator it=coefficient_map.begin(); it!=coefficient_map.end(); it++) { const exprt *sym=&it->second; while(sym->id()==ID_typecast) sym=&sym->op0(); if(bitwise_width<=1) { exprt value; value=converter.get(*sym); // this returns a constant. replace_map[*sym] = value; std::cout << from_expr(ns, "", it->second) << " = " << from_expr(ns, "", value) << std::endl; } else { assert(sym->id()==ID_symbol); exprt nsym(*sym); std::string original_id=sym->get_string(ID_identifier); for(unsigned i=0; i<bitwise_width; i++) { if(i!=0) nsym.set(ID_identifier, original_id + "@" + i2string(i)); exprt value = converter.get(nsym); replace_map[nsym] = value; // bit i std::cout << from_expr(ns, "", nsym) << " = " << from_expr(ns, "", value) << std::endl; } } } if(const_coefficient.id()!=ID_nil) { exprt value=converter.get(const_coefficient); std::cout << from_expr(ns, "", const_coefficient) << " = " << from_expr(ns, "", value) << std::endl; replace_map[const_coefficient]=value; } replace_expr(replace_map, rank_relation); simplify(rank_relation, ns); return false; }