Example #1
0
TString MillePedeTrees::DelPhi(const TString &tree1, const TString &tree2) const
{
  return Fun("TVector2::Phi_mpi_pi", Phi(tree1) += Min() += Phi(tree2));
}
Example #2
0
 proto_child1 child1() const
 {
     static expr<tag::terminal, term<Fun> > const that = {Fun()};
     return that;
 }
Example #3
0
TString MillePedeTrees::Phi(const TString &tree) const
{
  return Fun("TMath::ATan2", tree + YPos() += "," + tree + XPos());
}
Example #4
0
 indirect_fun() : fun(Fun())
 { }
Example #5
0
 void_ptr_indirect_fun() : fun(Fun())
 { }
/** \brief Create a "choice" constraint that postpones the resolution of a calc proof step.

    By delaying it, we can perform quick fixes such as:
      - adding symmetry
      - adding !
      - adding subst
*/
constraint mk_calc_proof_cnstr(environment const & env, options const & opts,
                               old_local_context const & _ctx, expr const & m, expr const & _e,
                               constraint_seq const & cs, unifier_config const & cfg,
                               info_manager * im, update_type_info_fn const & fn) {
    justification j         = mk_failed_to_synthesize_jst(env, m);
    auto choice_fn = [=](expr const & meta, expr const & _meta_type, substitution const & _s) {
        old_local_context ctx = _ctx;
        expr e            = _e;
        substitution s    = _s;
        expr meta_type    = _meta_type;
        type_checker_ptr tc = mk_type_checker(env);
        constraint_seq new_cs = cs;
        expr e_type = tc->infer(e, new_cs);
        e_type      = s.instantiate(e_type);
        tag g       = e.get_tag();
        bool calc_assistant = get_elaborator_calc_assistant(opts);

        if (calc_assistant) {
            // add '!' is needed
            while (is_norm_pi(*tc, e_type, new_cs)) {
                binder_info bi = binding_info(e_type);
                if (!bi.is_implicit() && !bi.is_inst_implicit()) {
                    if (!has_free_var(binding_body(e_type), 0)) {
                        // if the rest of the type does not reference argument,
                        // then we also stop consuming arguments
                        break;
                    }
                }
                expr imp_arg = ctx.mk_meta(some_expr(binding_domain(e_type)), g);
                e            = mk_app(e, imp_arg, g);
                e_type       = instantiate(binding_body(e_type), imp_arg);
            }
            if (im)
                fn(e);
        }
        e_type = head_beta_reduce(e_type);

        expr const & meta_type_fn = get_app_fn(meta_type);
        expr const & e_type_fn    = get_app_fn(e_type);
        if (is_constant(meta_type_fn) && (!is_constant(e_type_fn) || const_name(e_type_fn) != const_name(meta_type_fn))) {
            // try to make sure meta_type and e_type have the same head symbol
            if (!try_normalize_to_head(env, const_name(meta_type_fn), e_type, new_cs) &&
                is_constant(e_type_fn)) {
                try_normalize_to_head(env, const_name(e_type_fn), meta_type, new_cs);
            }
        }

        auto try_alternative = [&](expr const & e, expr const & e_type, constraint_seq fcs, bool conservative) {
            justification new_j = mk_type_mismatch_jst(e, e_type, meta_type);
            if (!tc->is_def_eq(e_type, meta_type, new_j, fcs))
                throw unifier_exception(new_j, s);
            buffer<constraint> cs_buffer;
            fcs.linearize(cs_buffer);
            metavar_closure cls(meta);
            cls.add(meta_type);
            cls.mk_constraints(s, j, cs_buffer);

            unifier_config new_cfg(cfg);
            new_cfg.m_discard      = false;
            new_cfg.m_kind         = conservative ? unifier_kind::Conservative : unifier_kind::Liberal;
            unify_result_seq seq   = unify(env, cs_buffer.size(), cs_buffer.data(), substitution(), new_cfg);
            auto p = seq.pull();
            lean_assert(p);
            substitution new_s     = p->first.first;
            constraints  postponed = map(p->first.second,
                                         [&](constraint const & c) {
                                             // we erase internal justifications
                                             return update_justification(c, j);
                                         });
            expr new_e = new_s.instantiate(e);
            if (conservative && has_expr_metavar_relaxed(new_s.instantiate_all(e)))
                throw_elaborator_exception("solution contains metavariables", e);
            if (im)
                im->instantiate(new_s);
            constraints r = cls.mk_constraints(new_s, j);
            buffer<expr> locals;
            expr mvar  = get_app_args(meta, locals);
            expr val   = Fun(locals, new_e);
            r = cons(mk_eq_cnstr(mvar, val, j), r);
            return append(r, postponed);
        };

        if (!get_elaborator_calc_assistant(opts)) {
            bool conservative = false;
            return try_alternative(e, e_type, new_cs, conservative);
        } else {
            // TODO(Leo): after we have the simplifier and rewriter tactic, we should revise
            // this code. It is "abusing" the higher-order unifier.

            {
                // Try the following possible intrepretations using a "conservative" unification procedure.
                // That is, we only unfold definitions marked as reducible.
                // Assume pr is the proof provided.

                // 1. pr
                bool conservative = true;
                try { return try_alternative(e, e_type, new_cs, conservative); } catch (exception & ex) {}

                // 2. eq.symm pr
                constraint_seq symm_cs = new_cs;
                auto symm  = apply_symmetry(env, ctx, tc, e, e_type, symm_cs, g);
                if (symm) {
                    try { return try_alternative(symm->first, symm->second, symm_cs, conservative); } catch (exception &) {}
                }

                // 3. subst pr (eq.refl lhs)
                constraint_seq subst_cs = new_cs;
                if (auto subst = apply_subst(env, ctx, tc, e, e_type, meta_type, subst_cs, g)) {
                    try { return try_alternative(subst->first, subst->second, subst_cs, conservative); } catch (exception&) {}
                }

                // 4. subst (eq.symm pr) (eq.refl lhs)
                if (symm) {
                    constraint_seq subst_cs = symm_cs;
                    if (auto subst = apply_subst(env, ctx, tc, symm->first, symm->second,
                                                 meta_type, subst_cs, g)) {
                        try { return try_alternative(subst->first, subst->second, subst_cs, conservative); }
                        catch (exception&) {}
                    }
                }
            }

            {
                // Try the following possible insterpretations using the default unification procedure.

                // 1. pr
                bool conservative = false;
                std::unique_ptr<throwable> saved_ex;
                try {
                    return try_alternative(e, e_type, new_cs, conservative);
                } catch (exception & ex) {
                    saved_ex.reset(ex.clone());
                }

                // 2. eq.symm pr
                constraint_seq symm_cs = new_cs;
                auto symm  = apply_symmetry(env, ctx, tc, e, e_type, symm_cs, g);
                if (symm) {
                    try { return try_alternative(symm->first, symm->second, symm_cs, conservative); }
                    catch (exception &) {}
                }

                // We use the exception for the first alternative as the error message
                saved_ex->rethrow();
                lean_unreachable();
            }
        }
    };
    bool owner = false;
    return mk_choice_cnstr(m, choice_fn, to_delay_factor(cnstr_group::Epilogue), owner, j);
}
Example #7
0
void Binding(){
//creating variables
TVectorD v(3);
std::vector<Double_t> sv(3);
std::array<Int_t,3>  a{ {1,2,3} };
TString str("ROOTR");
TMatrixD m(2,2);
Int_t i=9;
Double_t d=2.013;
Float_t f=0.013;

//assinging values
v[0]=0.01;
v[1]=1.01;
v[2]=2.01;

sv[0]=0.101;
sv[1]=0.202;
sv[2]=0.303;

m[0][0]=0.01;
m[0][1]=1.01;
m[1][0]=2.01;
m[1][1]=3.01;

ROOT::R::TRInterface &r=ROOT::R::TRInterface::Instance();
// r.SetVerbose(kTRUE);

//testing operators binding
r["a"]<<1;
r["v"]<<v;
r["sv"]<<sv;
r["m"]<<m;
r["b"]<<123.456;
r["i"]<<i;
r["d"]<<d;
r["f"]<<f;
r["array"]<<a;
r["s"]<<"ROOT";


//printting results
std::cout<<"-----------Printing Results---------\n";
r<<"print(a)";
std::cout<<"--------------------\n";
r<<"print(v)";
std::cout<<"--------------------\n";
r<<"print(sv)";
std::cout<<"--------------------\n";
r<<"print(m)";
std::cout<<"--------------------\n";
r<<"print(b)";
std::cout<<"--------------------\n";
r<<"print(i)";
std::cout<<"--------------------\n";
r<<"print(d)";
std::cout<<"--------------------\n";
r<<"print(f)";
std::cout<<"--------------------\n";
r<<"print(s)";
std::cout<<"--------------------\n";
r<<"print(array)";
std::cout<<"--------------------\n";

//reassigning the variable s
r["s"]<<str;//string with string
r<<"print(s)";

// std::cout<<"--------------------\n";
// r["d"]<<str;//double with string
// r<<"print(d)";

r["Function"]<<ROOT::R::TRFunction(Function);
r<<"print(Function(-1))";

r<<"print(Function(1))";//division by zero producess Inf.

r<<"print('hello ')"<<std::string("print('world ')");
r["x"]=123;
r["y"]=321;

Int_t x;
x=r["x"];
std::cout<<x<<std::endl;

r["y"]>>x;
std::cout<<x<<std::endl;

r<<"mat<-matrix(c(1,2,3,4),nrow=2)";

TMatrixD mat(2,2);
r["mat"]>>mat;

r["m"]<<mat;

Double_t b;
Int_t aa;
TString str2;
r["a"]>>aa;
r["v"]>>v;
r["sv"]>>sv;
r["m"]>>m;
r["b"]>>b;
r["i"]>>i;
r["d"]>>d;
r["f"]>>f;
r["array"]>>a;
r["s"]>>str2;

mat.Print();
std::cout<<" array={"<<a[0]<<","<<a[1]<<","<<a[2]<<"}";
r["func"]<<Function;
r<<"print(func(2))";
std::cout<<"func="<<Function(2);

//passing overloaded functions
r["funi"]<<(Int_t (*)(Int_t))Fun;
r<<"print(funi(2))";
std::cout<<"funi="<<Fun(2)<<std::endl;

r["fund"]<<(Double_t (*)(Double_t))Fun;
r<<"print(fund(2.01))";
std::cout<<"fund="<<Fun(2.01)<<std::endl;

//if you uncomment the next line you get a big
//traceback because the template can not reslve the overloaded
//function.
//r["fun"]<<Fun;
}