std::string simplify(std::string code) { std::string out; // If code is empty, do nothing if (code.length() == 0) return code; //! Helper macro used to check if we simplify two characters #define simp(a, b) \ if (code[i] == b) \ if (out.length() && out.back() == a) \ { \ out.pop_back(); \ continue; \ } \ // Simplify with previous chars for (int i = 0; i < code.length(); i++) { simp('+', '-'); simp('-', '+'); simp('[', ']'); simp('<', '>'); simp('>', '<'); out.push_back(code[i]); } return out; }
/* if foo; bar; else baz;; * => cjmp (foo) :bar :baz */ static void simpif(Simp *s, Node *n, Node *exit) { Node *l1, *l2, *l3; Node *iftrue, *iffalse; l1 = genlbl(); l2 = genlbl(); if (exit) l3 = exit; else l3 = genlbl(); iftrue = n->ifstmt.iftrue; iffalse = n->ifstmt.iffalse; simpcond(s, n->ifstmt.cond, l1, l2); simp(s, l1); simp(s, iftrue); jmp(s, l3); simp(s, l2); /* because lots of bunched up end labels are ugly, * coalesce them by handling 'elif'-like constructs * separately */ if (iffalse && iffalse->type == Nifstmt) { simpif(s, iffalse, exit); } else { simp(s, iffalse); jmp(s, l3); } if (!exit) simp(s, l3); }
inline double rsimp(double l,double r) // call here { double mid = (l+r)/2.0; if(fabs((simp(l,r)-simp(l,mid)-simp(mid,r)))/15 < eps) return simp(l,r); else return rsimp(l,mid)+rsimp(mid,r); }
struct decl *copy_decls(struct param *p,struct decl *d) { if(d) { struct decl *nd=malloc(sizeof(struct decl)); nd->name=d->name; nd->top=simp(p,d->top); nd->bot=simp(p,d->bot); nd->next=copy_decls(p,d->next); return nd; } else return 0; }
Expression Analitza::evaluate() { if(m_exp.isCorrect()) { Expression e(m_exp); //FIXME: That's a strange trick, wouldn't have to copy e.m_tree=removeDependencies(e.m_tree); e.m_tree=simp(e.m_tree); e.m_tree=eval(e.m_tree); e.m_tree=simp(e.m_tree); return e; } else { m_err << i18n("Must specify an operation"); return Expression(); } }
static void simpmatch(Simp *s, Node *n) { Node *end, *cur, *next; /* labels */ Node *val, *tmp; Node *m; size_t i; end = genlbl(); val = temp(s, n->matchstmt.val); tmp = rval(s, n->matchstmt.val, val); if (val != tmp) append(s, assign(s, val, tmp)); for (i = 0; i < n->matchstmt.nmatches; i++) { m = n->matchstmt.matches[i]; /* check pattern */ cur = genlbl(); next = genlbl(); umatch(s, m->match.pat, val, val->expr.type, cur, next); /* do the action if it matches */ append(s, cur); simp(s, m->match.block); jmp(s, end); append(s, next); } append(s, end); }
bool SMTStore::empty() { try { static bool simplify = Config.is_set("--q3bsimplify"); if (path_condition.size() == 0) return false; z3::context c; z3::expr pc = c.bool_val(true); z3::solver s(c); for (const Definition &def : definitions) pc = pc && toz3(def.to_formula(), 'a', c); for (const Formula &p : path_condition) pc = pc && toz3(p, 'a', c); if (simplify) { ExprSimplifier simp(c, true); pc = simp.Simplify(pc); } z3::check_result ret = solve_query_qf(s, pc); assert(ret != z3::unknown); return ret == z3::unsat; } catch (const z3::exception& e) { std::cerr << "Cannot perform empty operation: " << e.msg() << "\n"; throw e; } }
/*public static*/ std::auto_ptr<geom::CoordinateSequence> BufferInputLineSimplifier::simplify(const geom::CoordinateSequence& inputLine, double distanceTol) { BufferInputLineSimplifier simp(inputLine); return simp.simplify(distanceTol); }
void simp_params(struct param *p) { while(p) { p->expr=simp(p->context,p->expr); p=p->next; } }
/* init; while cond; body;; * => init * jmp :cond * :body * ...body... * ...step... * :cond * ...cond... * cjmp (cond) :body :end * :end */ static void simploop(Simp *s, Node *n) { Node *lbody; Node *lend; Node *lcond; Node *lstep; lbody = genlbl(); lcond = genlbl(); lstep = genlbl(); lend = genlbl(); lappend(&s->loopstep, &s->nloopstep, lstep); lappend(&s->loopexit, &s->nloopexit, lend); simp(s, n->loopstmt.init); /* init */ jmp(s, lcond); /* goto test */ simp(s, lbody); /* body lbl */ simp(s, n->loopstmt.body); /* body */ simp(s, lstep); /* test lbl */ simp(s, n->loopstmt.step); /* step */ simp(s, lcond); /* test lbl */ simpcond(s, n->loopstmt.cond, lbody, lend); /* repeat? */ simp(s, lend); /* exit */ s->nloopstep--; s->nloopexit--; }
/*public static*/ DouglasPeuckerLineSimplifier::CoordsVectAutoPtr DouglasPeuckerLineSimplifier::simplify( const DouglasPeuckerLineSimplifier::CoordsVect& nPts, double distanceTolerance) { DouglasPeuckerLineSimplifier simp(nPts); simp.setDistanceTolerance(distanceTolerance); return simp.simplify(); }
build_model() { int i,j,k; nodeptr p, p1, root1, root_sw, simp(); char f_name[MAX_NAME]; char v_name[MAX_NAME]; for (i=1; i<=n_gen+m_pv+s_pq; i++) { j=n_gen+m_pv+s_pq; root1=f1_term(i,j,'1'); for (k=1; k<=5+n_gen+m_pv+s_pq; k++) root1=simp(root1); p=new_node(); p->node_id='b'; p->node_data.bi_term.oprt='-'; p->node_data.bi_term.left=root1; sprintf(v_name,"p[%d]",i); p->node_data.bi_term.right=find_node(name_header,v_name,'c'); sprintf(f_name,"f1[%d]=", i); store_func(func_header, f_name, p); if (i>n_gen+m_pv) { j=n_gen+m_pv+s_pq; root1=f1_term(i,j,'2'); for (k=1; k<=5+n_gen+m_pv+s_pq; k++) root1=simp(root1); p=new_node(); p->node_id='b'; p->node_data.bi_term.oprt='-'; p->node_data.bi_term.left=root1; sprintf(v_name,"q[%d]",i); p->node_data.bi_term.right=find_node(name_header,v_name,'c'); sprintf(f_name,"f2[%d]=", i-n_gen-m_pv); store_func(func_header, f_name, p); } } }
double func(double epsilon, int n) // Sets new integrated function { double val, xin, xout; xin = (rmin/a) - log(1.+sqrt(fabs((epsilon/V0) +1.))); xout = (rmin/a) - log(1.-sqrt(fabs((epsilon/V0) +1.))); val = lama*a*simp(xin,xout,epsilon) - ((n+(1.0/2.0))*M_PI); // integrates from xin to xout and then -(n+0.5)*pi from the equation return val; }
static void simpblk(Simp *s, Node *n) { size_t i; pushstab(n->block.scope); for (i = 0; i < n->block.nstmts; i++) { n->block.stmts[i] = fold(n->block.stmts[i], 0); simp(s, n->block.stmts[i]); } popstab(); }
main() { double a, b, eps, t, simpf(double); a = 0.0; b = 1.0; eps = 0.000001; t = simp(a, b, eps, simpf); printf("\n"); printf("t=%13.5e\n", t); printf("\n"); }
static void to_subpaving(cmd_context & ctx, expr * t) { ast_manager & m = ctx.m(); unsynch_mpq_manager qm; scoped_ptr<subpaving::context> s; s = subpaving::mk_mpq_context(ctx.m().limit(), qm); expr2var e2v(m); expr2subpaving e2s(m, *s, &e2v); params_ref p; p.set_bool("mul_to_power", true); th_rewriter simp(m, p); expr_ref t_s(m); simp(t, t_s); scoped_mpz n(qm), d(qm); ctx.regular_stream() << mk_ismt2_pp(t_s, m) << "\n=======>" << std::endl; subpaving::var x = e2s.internalize_term(t_s, n, d); expr2var::iterator it = e2v.begin(); expr2var::iterator end = e2v.end(); for (; it != end; ++it) { ctx.regular_stream() << "x" << it->m_value << " := " << mk_ismt2_pp(it->m_key, m) << "\n"; } s->display_constraints(ctx.regular_stream()); ctx.regular_stream() << n << "/" << d << " x" << x << "\n"; }
void print_table(double a, double b, double (*func)(double) , double precision){ printf("n \t h value: \t Integral value: \t Relative error:\n"); double old_I = 0.0; for (double i = 1; i <= 10; ++i){ // do not exceed 10 double h = ((b-a)/pow(2,i)); double I = simp(a,b,*func, pow(2,i),h); double rel_err = (I - old_I)/pow(h,4) ; printf("%d \t %1.2e \t %1.2e \t \t %1.2e\n", (int)pow(2,i) , h , I, rel_err ); if( fabs(I - old_I) < precision){ printf("precision reached \n"); break; } old_I = I; } }
/* pat; seq; * body;; * * => * .pseudo = seqinit * jmp :cond * :body * ...body... * :step * ...step... * :cond * ...cond... * cjmp (cond) :match :end * :match * ...match... * cjmp (match) :body :step * :end */ static void simpiter(Simp *s, Node *n) { Node *lbody, *lstep, *lcond, *lmatch, *lend; Node *idx, *len, *dcl, *seq, *val, *done; Node *zero; lbody = genlbl(); lstep = genlbl(); lcond = genlbl(); lmatch = genlbl(); lend = genlbl(); lappend(&s->loopstep, &s->nloopstep, lstep); lappend(&s->loopexit, &s->nloopexit, lend); zero = mkintlit(n->line, 0); zero->expr.type = tyintptr; seq = rval(s, n->iterstmt.seq, NULL); idx = gentemp(s, n, tyintptr, &dcl); declarelocal(s, dcl); /* setup */ append(s, assign(s, idx, zero)); jmp(s, lcond); simp(s, lbody); /* body */ simp(s, n->iterstmt.body); /* step */ simp(s, lstep); simp(s, assign(s, idx, addk(idx, 1))); /* condition */ simp(s, lcond); len = seqlen(s, seq, tyintptr); done = mkexpr(n->line, Olt, idx, len, NULL); cjmp(s, done, lmatch, lend); simp(s, lmatch); val = load(idxaddr(s, seq, idx)); umatch(s, n->iterstmt.elt, val, val->expr.type, lbody, lstep); simp(s, lend); s->nloopstep--; s->nloopexit--; }
static void test_qe(ast_manager& m, lbool expected_outcome, expr* fml, char const* option) { // enable_trace("bit2int"); //enable_trace("gomory_cut"); enable_trace("final_check_arith"); enable_trace("arith_final_check"); //enable_trace("arith_branching"); enable_trace("theory_arith_int"); enable_trace("presburger"); enable_trace("quant_elim"); // enable_trace("arith_simplifier_plugin"); // enable_trace("non_linear"); // enable_trace("gomory_cut_detail"); // enable_trace("arith"); // enable_trace("bv"); // enable_trace("after_search"); // enable_trace("bv_bit_prop"); simplifier simp(m); front_end_params params; params.m_quant_elim = true; std::cout << mk_pp(fml, m) << "\n"; qe::expr_quant_elim qe(m, params); expr_ref result(m); qe(m.mk_true(), fml, result); std::cout << " -> " << mk_pp(result, m) << " " << expected_outcome << "\n"; if (expected_outcome == l_true && !m.is_true(result)) { std::cout << "ERROR: expected true, instead got " << ast_pp(result, m).c_str() << "\n"; //exit(-1); } if (expected_outcome == l_false && !m.is_false(result)) { std::cout << "ERROR: expected false, instead got " << ast_pp(result, m).c_str() << "\n"; //exit(-1); } }
Object* Analitza::simp(Object* root) { Q_ASSERT(root && root->type()!=Object::none); Object* aux=0; if(!hasVars(root)) { if(root->type()!=Object::value && root->type() !=Object::oper) { aux = root; root = new Cn(calc(root)); delete aux; } } else if(root->isContainer()) { Container *c= (Container*) root; QList<Object*>::iterator it; bool d; switch(c->firstOperator().operatorType()) { case Object::times: simpScalar(c); simpPolynomials(c); for(it=c->m_params.begin(); it!=c->m_params.end();) { *it = simp(*it); d=false; if((*it)->type() == Object::value) { Cn* n = (Cn*) (*it); if(n->value()==1.) { //1*exp=exp delete n; d=true; } else if(n->value()==0.) { //0*exp=0 delete root; root = new Cn(0.); break; } } if(!d) ++it; else it = c->m_params.erase(it); } break; case Object::minus: case Object::plus: simpScalar(c); simpPolynomials(c); for(it=c->m_params.begin(); it!=c->m_params.end();) { *it = simp(*it); d=false; if((*it)->type() == Object::value) { Cn* n = (Cn*) (*it); if(n->value()==0.) { //0+-exp=exp delete n; d=true; } } if(!d) ++it; else it = c->m_params.erase(it); } break; case Object::power: { c->m_params[1] = simp(c->m_params[1]); c->m_params[2] = simp(c->m_params[2]); if(c->m_params[2]->type()==Object::value) { Cn *n = (Cn*) c->m_params[2]; if(n->value()==0.) { //0*exp=0 delete root; root = new Cn(1.); break; } else if(n->value()==1.) { root = c->m_params[1]; delete c->m_params[2]; c->m_params.clear(); delete c; } } } break; default: it = c->m_params.begin(); for(; it!=c->m_params.end(); it++) *it = simp(*it); break; } } return root; }
int main (int argc, char ** argv) { int changed, golden, res, rounds, interval, fixed, sign, overwritten; int i, j, argstart, len; Exp * e; argstart = argc; for (i = 1; i < argc; i++) { if (run_name) { argstart = i; break; } else if (!strcmp (argv[i], "-h")) { printf ("usage: deltabtor " "[-h][-v][--no-simp][--no-sort] <in> <out> " "<run> [<opt> ...]\n"); exit (0); } else if (!strcmp (argv[i], "-v")) verbose++; else if (!strcmp (argv[i], "--no-simp")) nosimp = 1; else if (!strcmp (argv[i], "--no-sort")) nosort = 1; else if (output_name) run_name = argv[i]; else if (input_name) output_name = argv[i]; else input_name = argv[i]; } if (!input_name) die ("<input> missing"); if (!output_name) die ("<output> missing"); if (!run_name) die ("<run> missing"); if (!strcmp (input_name, output_name)) die ("<input> and <output> are the same"); if (!strcmp (input_name, run_name)) die ("<input> and <run> are the same"); if (!strcmp (output_name, run_name)) die ("<output> and <run> are the same"); nexps = sexps = 1; exps = calloc (sexps, sizeof *exps); if (!(input = fopen (input_name, "r"))) die ("can not read '%s'", input_name); parse (); fclose (input); tmp = malloc (100); sprintf (tmp, "/tmp/deltabtor%u", (unsigned) getpid ()); len = strlen (tmp); for (i = argstart; i < argc; i++) len += 1 + strlen (argv[i]); cmd = malloc (strlen (run_name) + len + 100); sprintf (cmd, "%s %s", run_name, tmp); for (i = argstart; i < argc; i++) sprintf (cmd + strlen (cmd), " %s", argv[i]); sprintf (cmd + strlen (cmd), " >/dev/null 2>/dev/null"); expand (); save (); simp (); cone (); print (); clean (); reset (); golden = run (); msg (1, "golden exit code %d", golden); rename (tmp, output_name); rounds = 0; fixed = 0; interval = nexps - maxwidth; oexps = rexps; do { do { rounds++; msg (1, "interval %d size %d round %d", interval, oexps, rounds); changed = 0; for (i = maxwidth + 1; i < nexps; i += interval) { for (sign = 1; sign >= -3; sign -= 2) { overwritten = 0; for (j = i; j < i + interval && j < nexps; j++) { e = exps + j; if (!e->ref) continue; if (e->ref != j) continue; if (e->cut) continue; if (!strcmp (e->op, "root")) continue; if (!strcmp (e->op, "array")) continue; overwritten++; } if (!overwritten) continue; save (); for (j = i; j < i + interval && j < nexps; j++) { e = exps + j; if (!e->ref) continue; if (e->ref != j) continue; if (e->cut) continue; if (!strcmp (e->op, "root")) continue; if (!strcmp (e->op, "array")) continue; if (sign >= -1) e->ref = sign * e->width; else e->cut = 1; } msg (3, "trying to set %d expressions %d .. %d to %s", overwritten, i, min (i + interval, nexps) - 1, (sign < -1) ? "new variables" : (sign < 0) ? "all one" : "zero"); simp (); cone (); print (); clean (); res = run (); if (res == golden) { changed = 1; fixed += overwritten; msg (2, "fixed %d expressions", overwritten); rename (tmp, output_name); oexps = rexps; msg (2, "saved %d expressions in '%s'", rexps, output_name); } else { msg (3, "restored %d expressions", overwritten); reset (); } } } } while (changed); if (3 < interval && interval < 8) interval = 3; else if (interval == 3) interval = 2; else if (interval == 2) interval = 1; else if (interval == 1) interval = 0; else interval = (interval + 1) / 2; } while (interval); unlink (tmp); msg (2, "%d rounds", rounds); msg (2, "%d runs", runs); free (tmp); free (cmd); for (i = 1; i < nexps; i++) { if (!exps[i].ref) continue; free (exps[i].op); free (exps[i].name); } free (exps); free (buf); msg (1, "fixed %d expressions out of %d", fixed, iexps); msg (1, "wrote %d expressions to '%s'", oexps, output_name); return 0; }
void m5249audio_init(void) { printk("M5249AUDIO: (C) Copyright 2002, " "Greg Ungerer ([email protected])\n"); if (register_chrdev(SOUND_MAJOR, "sound", &m5249audio_fops) < 0) { printk(KERN_WARNING "SOUND: failed to register major %d\n", SOUND_MAJOR); return; } m5249audio_buf = kmalloc(BUFSIZE, GFP_KERNEL); if (m5249audio_buf == NULL) { printk("M5249AUDIO: failed to allocate DMA[%d] buffer\n", BUFSIZE); } #ifdef CONFIG_AUDIOIRQ #ifdef CONFIG_AUDIOIRQASM /* Install fast interrupt handler */ printk("M5249AUDIO: fast interrupt handler irq=%d\n", M5249AUDIO_TXIRQ); *((unsigned long *) (M5249AUDIO_TXIRQ * 4)) = (unsigned long) m5249audio_isr; #else /* Re-direct TX empty FIFO audio interrupt. */ printk("M5249AUDIO: standard interrupt handler, irq=%d\n", M5249AUDIO_TXIRQ); if (request_irq(M5249AUDIO_TXIRQ, m5249audio_isr, (SA_INTERRUPT | IRQ_FLG_FAST), "audio", NULL)) { printk("M5249AUDIO: IRQ %d already in use?\n", M5249AUDIO_TXIRQ); } #endif *reg32p(0x140) = 0x00007000; #endif #ifdef CONFIG_AUDIODMA { volatile unsigned char *dmap; unsigned int icr; printk("M5249AUDIO: DMA channel=%d, irq=%d\n", M5249AUDIO_DMA, M5249AUDIO_DMAIRQ); if (request_irq(M5249AUDIO_DMAIRQ, m5249audio_dmaisr, (SA_INTERRUPT | IRQ_FLG_FAST), "audio(DMA)", NULL)) { printk("M5249AUDIO: DMA IRQ %d already in use?\n", M5249AUDIO_DMAIRQ); } dmap = (volatile unsigned char *) dma_base_addr[M5249AUDIO_DMA]; dmap[MCFDMA_DIVR] = M5249AUDIO_DMAIRQ; /* Set interrupt level and priority */ switch (M5249AUDIO_DMA) { case 1: icr=MCFSIM_DMA1ICR; m5249audio_imrbit=MCFSIM_IMR_DMA1; break; case 2: icr=MCFSIM_DMA2ICR; m5249audio_imrbit=MCFSIM_IMR_DMA2; break; case 3: icr=MCFSIM_DMA3ICR; m5249audio_imrbit=MCFSIM_IMR_DMA3; break; default: icr=MCFSIM_DMA0ICR; m5249audio_imrbit=MCFSIM_IMR_DMA0; break; } *simp(icr) = MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3; mcf_setimr(mcf_getimr() & ~m5249audio_imrbit); /* Set DMA to use channel 0 for audio */ *reg8p(MCFA_DMACONF) = MCFA_DMA_0REQ; *reg32p(MCFSIM2_DMAROUTE) = 0x00000080; if (request_dma(M5249AUDIO_DMA, "audio")) { printk("M5249AUDIO: DMA channel %d already in use?\n", M5249AUDIO_DMA); } } #endif /* Unmute the DAC, set GPIO49 */ *reg32p(MCFSIM2_GPIO1FUNC) |= 0x00020000; *reg32p(MCFSIM2_GPIO1ENABLE) |= 0x00020000; m5249audio_unmute(); /* Power up the DAC, set GPIO39 */ *reg32p(MCFSIM2_GPIO1FUNC) |= 0x00000080; *reg32p(MCFSIM2_GPIO1ENABLE) |= 0x00000080; *reg32p(MCFSIM2_GPIO1WRITE) |= 0x00000080; m5249audio_chipinit(); /* Dummy write to start outputing */ *reg32p(MCFA_PDOR3) = 0; }
bool SMTStore::subseteq(const SMTStore &b, const SMTStore &a, bool timeout, bool is_caching_enabled) { static bool simplify = Config.is_set("--q3bsimplify"); ++Statistics::getCounter(SUBSETEQ_CALLS); if (a.definitions == b.definitions) { bool equal_syntax = a.path_condition.size() == b.path_condition.size(); for (size_t i = 0; equal_syntax && i < a.path_condition.size(); ++i) { if (a.path_condition[i]._rpn != b.path_condition[i]._rpn) equal_syntax = false; } if (equal_syntax) { ++Statistics::getCounter(SUBSETEQ_SYNTAX_EQUAL); return true; } } std::map< Formula::Ident, Formula::Ident > to_compare; for (unsigned s = 0; s < a.generations.size(); ++s) { assert(a.generations[s].size() == b.generations[s].size()); for (unsigned offset = 0; offset < a.generations[s].size(); ++offset) { Value var; var.type = Value::Type::Variable; var.variable.segmentId = s; var.variable.offset = offset; Formula::Ident a_atom = a.build_item(var); Formula::Ident b_atom = b.build_item(var); if (!a.depends_on(var) && !b.depends_on(var)) continue; to_compare.insert(std::make_pair(a_atom, b_atom)); } } if (to_compare.empty()) return true; // pc_b && foreach(a).(!pc_a || a!=b) // (sat iff not _b_ subseteq _a_) z3::context c; z3::solver s(c); z3::params p(c); p.set(":mbqi", true); if (timeout) p.set(":timeout", 1000u); s.set(p); Z3SubsetCall formula; // Structure for caching bool cached_result = false; bool retrieved_from_cache = false; // Try if the formula is in cache if (is_caching_enabled) { StopWatch s; s.start(); std::copy(a.path_condition.begin(), a.path_condition.end(), std::back_inserter(formula.pc_a)); std::copy(b.path_condition.begin(), b.path_condition.end(), std::back_inserter(formula.pc_b)); for (const Definition &def : a.definitions) formula.pc_a.push_back(def.to_formula()); for (const Definition &def : b.definitions) formula.pc_b.push_back(def.to_formula()); std::copy(to_compare.begin(), to_compare.end(), std::back_inserter(formula.distinct)); s.stop(); if (Config.is_set("--verbose") || Config.is_set("--vverbose")) std::cout << "Building formula took " << s.getUs() << " us\n"; // Test if this formula is in cache or not if (Z3cache.is_cached(formula)) { ++Statistics::getCounter(SMT_CACHED); cached_result = Z3cache.result() == z3::unsat; retrieved_from_cache = true; if (!Config.is_set("--testvalidity")) return cached_result; } } StopWatch solving_time; solving_time.start(); z3::expr pc_a = c.bool_val(true); for (const auto &pc : a.path_condition) pc_a = pc_a && toz3(pc, 'a', c); z3::expr pc_b = c.bool_val(true); for (const auto &pc : b.path_condition) pc_b = pc_b && toz3(pc, 'b', c); for (const Definition &def : a.definitions) pc_a = pc_a && toz3(def.to_formula(), 'a', c); for (const Definition &def : b.definitions) pc_b = pc_b && toz3(def.to_formula(), 'b', c); z3::expr distinct = c.bool_val(false); for (const auto &vars : to_compare) { z3::expr a_expr = toz3(Formula::buildIdentifier(vars.first), 'a', c); z3::expr b_expr = toz3(Formula::buildIdentifier(vars.second), 'b', c); distinct = distinct || (a_expr != b_expr); } std::vector< z3::expr > a_all_vars; for (const auto &var : a.collect_variables()) { a_all_vars.push_back(toz3(Formula::buildIdentifier(var), 'a', c)); } z3::expr not_witness = !pc_a || distinct; z3::expr query = pc_b && forall(a_all_vars, not_witness); if (simplify) { ExprSimplifier simp(c, true); query = simp.Simplify(query); } z3::check_result ret = solve_query_q(s, query); if (ret == z3::unknown) { ++unknown_instances; ++Statistics::getCounter(SOLVER_UNKNOWN); if (Config.is_set("--verbose") || Config.is_set("--vverbose")) { if (Config.is_set("--vverbose")) std::cerr << "while checking:\n" << s; std::cerr << "\ngot 'unknown', reason: " << s.reason_unknown() << std::endl; } } //FormulaeCapture::insert(s.to_smt2(), ret); solving_time.stop(); if (is_caching_enabled) Z3cache.place(formula, ret, solving_time.getUs()); bool real_result = ret == z3::unsat; if (is_caching_enabled && Config.is_set("--testvalidity") && retrieved_from_cache && real_result != cached_result) { std::cout << "Got different result from cache!\n"; abort(); } return real_result; }
void Analitza::simplify() { if(m_exp.isCorrect()) m_exp.m_tree = simp(m_exp.m_tree); }
/* This routine calculates fourier components of Kleiman-Beylander non-local psuedopotentials */ void kbpp(REAL zv, int lmax, int nrho, REAL drho, REAL *rho, REAL *vp, REAL *wp, int nfft3d, REAL *G, REAL *vl, REAL *vnl, REAL *vnlnrm) { int i,l,k,lmmax; REAL pi,twopi,fourpi; REAL p0,p1,p2,p,d,gx,gy,gz,a,q; REAL *f, *cs, *sn; f = (REAL *) malloc(nrho*sizeof(REAL)); cs = (REAL *) malloc(nrho*sizeof(REAL)); sn = (REAL *) malloc(nrho*sizeof(REAL)); pi = 4.0*atan(1.0); twopi = 2.0*pi; fourpi = 4.0*pi; lmmax = lmax*lmax; p0=sqrt(fourpi); p1=sqrt(3.0*fourpi); p2=sqrt(15.0*fourpi); /* Define non-local pseudopotential */ for (l=0; l<lmax; ++l) for (i=0; i<nrho; ++i) vp[i + l*nrho] -= vp[i+lmax*nrho]; /* Normarization constants */ for (l=0; l<lmax; ++l) { for (i=0; i<nrho; ++i) f[i] = vp[i+l*nrho]*wp[i+l*nrho]*wp[i+l*nrho]; a = simp(nrho,f,drho); for (i=(l*l); i < ((l+1)*(l+1)); ++i) vnlnrm[i] = a; } /* Fourier transformation - G != 0 terms */ for (k=1; k<nfft3d; ++k) { gx = G[k]; gy = G[k+nfft3d]; gz = G[k+2*nfft3d]; q = sqrt(gx*gx + gy*gy + gz*gz); gx /= q; gy /= q; gz /= q; for (i=0; i<nrho; ++i) { cs[i] = cos(q*rho[i]); sn[i] = cos(q*rho[i]); } /* d-wave */ if (lmax>2) { f[0]=0.0; for (i=1; i<nrho; ++i) { a=3.0*(sn[i]/(q*rho[i])-cs[i])/(q*rho[i])-sn[i]; f[i]=a*wp[i+2*nrho]*vp[i+2*nrho]; } d = p2*simp(nrho,f,drho)/q; vnl[k+4*nfft3d] = d*(3.0*gz*gz-1.0)/(2.0*sqrt(3.0)); vnl[k+5*nfft3d] = d*gx*gy; vnl[k+6*nfft3d] = d*gy*gz; vnl[k+7*nfft3d] = d*gz*gx; vnl[k+8*nfft3d] = d*(gx*gx-gy*gy)/2.0; } /* p-wave */ if (lmax>1) { f[0]=0.0; for (i=1; i<nrho; ++i) f[i] = (sn[i]/(q*rho[i])-cs[i])*wp[i+1*nrho]*vp[i+1*nrho]; p = p1*simp(nrho,f,drho)/q; vnl[k+1*nfft3d] = p*gx; vnl[k+2*nfft3d] = p*gy; vnl[k+3*nfft3d] = p*gz; } /* s-wave */ if (lmax>0) { for (i=0; i<nrho; ++i) f[i] = sn[i]*wp[i]*vp[i]; vnl[k] = p0*simp(nrho,f,drho)/q; } /* local psp */ for (i=0; i<nrho; ++i) f[i]=rho[i]*vp[i+lmax*nrho]*sn[i]; vl[k] = simp(nrho,f,drho)*fourpi/q - zv*fourpi*cs[nrho-1]/(q*q); } /* G==0 terms */ for (i=0; i<nrho; ++i) { f[i] = vp[i + lmax*nrho] * (rho[i]*rho[i]); } a = simp(nrho,f,drho); vl[0]=fourpi*a + twopi*zv*rho[nrho-1]*rho[nrho-1]; for (i=0; i<nrho; ++i) f[i] = rho[i]*wp[i]*vp[i]; vnl[0] = p0*simp(nrho,f,drho); for (l=1; l<lmmax; ++l) vnl[0 + l*nfft3d] = 0.0; free(sn); free(cs); free(f); }
/* line integral of quantities (such as nh) along a ray, * for column densities, etc. (just a basic simpsons rule integration, * i.e. linearly interpolating between each point) */ void integrate_ray(Ray_struct *R) { float nh,z,neutral_frac,temp,nh_gadget_units,nh_hot; float vrad; int i; float *vec_to_integrate, *dr; dr = (float *)malloc(R->N_steps * sizeof(float)); vec_to_integrate = (float *)malloc(R->N_steps * sizeof(float)); for (i=0; i<R->N_steps; i++) dr[i] = FRACTIONAL_STEPSIZE * R->local[i].h ; /* First, column density */ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].rho ; nh_gadget_units = simp(dr, vec_to_integrate, R->N_steps); nh = nh_gadget_units; R->nh = nh; /* Column density of the hot-phase ISM along the ray*/ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].rho_hot * R->local[i].rho ; nh_hot = simp(dr, vec_to_integrate, R->N_steps); R->nh_hot = nh_hot; /* Mass-weighted metallicity (so R->Z = total metal fraction) */ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].Z * R->local[i].rho ; z = simp(dr, vec_to_integrate, R->N_steps); R->Z = z; /* Mass-weighted neutral fraction (so R->neutral_frac = total neutral fraction) */ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].neutral_frac * R->local[i].rho ; neutral_frac = simp(dr, vec_to_integrate, R->N_steps); R->neutral_frac = neutral_frac; /* Mass-weighted temperature (so R->temp = temp fraction) */ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].T * R->local[i].rho ; temp = simp(dr, vec_to_integrate, R->N_steps); R->Temp = temp; /* Thermal SZ: n_e * temperature */ /* ------------------------------------ */ /* for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].rho * R->local[i].T; temp = simp(dr, vec_to_integrate, R->N_steps); */ R->thermalSZ= temp; /* same as above */ /* Kinetic SZ: n_e * radial velocity */ /* ------------------------------------ */ vrad= R->n_hat[0]*R->local[i].vel[0] + R->n_hat[1]*R->local[i].vel[1] + R->n_hat[2]*R->local[i].vel[2]; for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].rho * vrad; temp = simp(dr, vec_to_integrate, R->N_steps); R->kineticSZ= temp; /* X-ray Luminosity (so R->temp = temp fraction) */ /* ------------------------------------ */ for (i=0; i<R->N_steps; i++) vec_to_integrate[i] = R->local[i].xrayL * R->local[i].rho ; temp = simp(dr, vec_to_integrate, R->N_steps); R->xrayL = temp; /* need to free vectors created in this subroutine */ free(dr); free(vec_to_integrate); }