#include "py_algorithms.hh" #include #include "../Algorithm.hh" #include "../NEvaluator.hh" #include "../algorithms/canonicalise.hh" #include "../algorithms/collect_components.hh" #include "../algorithms/collect_factors.hh" #include "../algorithms/collect_terms.hh" #include "../algorithms/combine.hh" #include "../algorithms/complete.hh" #include "../algorithms/decompose.hh" #include "../algorithms/decompose_product.hh" #include "../algorithms/distribute.hh" #include "../algorithms/drop_weight.hh" #include "../algorithms/einsteinify.hh" #include "../algorithms/eliminate_kronecker.hh" #include "../algorithms/eliminate_metric.hh" #include "../algorithms/eliminate_vielbein.hh" #include "../algorithms/epsilon_to_delta.hh" #include "../algorithms/evaluate.hh" #include "../algorithms/expand.hh" #include "../algorithms/expand_delta.hh" #include "../algorithms/expand_diracbar.hh" #include "../algorithms/expand_dummies.hh" #include "../algorithms/expand_power.hh" #include "../algorithms/explicit_indices.hh" #include "../algorithms/factor_in.hh" #include "../algorithms/factor_out.hh" #include "../algorithms/fierz.hh" #include "../algorithms/flatten_sum.hh" #include "../algorithms/indexsort.hh" #include "../algorithms/integrate_by_parts.hh" #include "../algorithms/join_gamma.hh" #include "../algorithms/keep_terms.hh" #include "../algorithms/lower_free_indices.hh" #include "../algorithms/lr_tensor.hh" #ifdef MATHEMATICA_FOUND #include "../algorithms/map_mma.hh" #endif #include "../algorithms/map_sympy.hh" #include "../algorithms/meld.hh" #include "../algorithms/nevaluate.hh" #include "../algorithms/order.hh" #include "../algorithms/product_rule.hh" #include "../algorithms/reduce_delta.hh" #include "../algorithms/rename_dummies.hh" #include "../algorithms/replace_match.hh" #include "../algorithms/rewrite_indices.hh" #include "../algorithms/simplify.hh" #include "../algorithms/sort_product.hh" #include "../algorithms/sort_spinors.hh" #include "../algorithms/sort_sum.hh" #include "../algorithms/split_gamma.hh" #include "../algorithms/split_index.hh" #include "../algorithms/substitute.hh" #include "../algorithms/sym.hh" #include "../algorithms/tab_dimension.hh" #include "../algorithms/take_match.hh" #include "../algorithms/unwrap.hh" #include "../algorithms/unzoom.hh" #include "../algorithms/untrace.hh" #include "../algorithms/vary.hh" #include "../algorithms/young_project.hh" #include "../algorithms/young_project_product.hh" #include "../algorithms/young_project_tensor.hh" #include "../algorithms/zoom.hh" namespace cadabra { namespace py = pybind11; void init_algorithms(py::module& m) { pybind11::enum_(m, "result_t") .value("checkpointed", Algorithm::result_t::l_checkpointed) .value("changed", Algorithm::result_t::l_applied) .value("unchanged", Algorithm::result_t::l_no_action) .value("error", Algorithm::result_t::l_error) .export_values(); def_algo(m, "canonicalise", true, false, 0); def_algo(m, "collect_components", true, false, 0); def_algo(m, "collect_factors", true, false, 0); def_algo(m, "collect_terms", true, false, 0); def_algo(m, "decompose_product", true, false, 0); def_algo(m, "distribute", true, false, 0); def_algo(m, "eliminate_kronecker", true, false, 0); def_algo(m, "expand", true, false, 0); def_algo(m, "expand_delta", true, false, 0); def_algo(m, "expand_diracbar", true, false, 0); def_algo(m, "expand_dummies", true, false, 0, py::arg("components") = nullptr, py::arg("zero_missing_components") = true); def_algo(m, "expand_power", true, false, 0); def_algo(m, "explicit_indices", true, false, 0); def_algo(m, "flatten_sum", true, false, 0); def_algo(m, "indexsort", true, false, 0); def_algo(m, "lr_tensor", true, false, 0); def_algo(m, "product_rule", true, false, 0); def_algo(m, "reduce_delta", true, false, 0); def_algo(m, "sort_product", true, false, 0); def_algo(m, "sort_spinors", true, false, 0); def_algo(m, "sort_sum", true, false, 0); def_algo(m, "tab_dimension", true, false, 0); def_algo(m, "young_project_product", true, false, 0); def_algo(m, "combine", true, false, 0, py::arg("trace_op") = Ex{}); def_algo(m, "complete", false, false, 0, py::arg("add")); def_algo(m, "decompose", false, false, 0, py::arg("basis")); def_algo(m, "drop_weight", false, false, 0, py::arg("condition") = Ex{}); def_algo(m, "eliminate_metric", true, false, 0, py::arg("preferred") = Ex{}, py::arg("redundant") = false); def_algo(m, "eliminate_vielbein", true, false, 0, py::arg("preferred") = Ex{},py::arg("redundant")= false); def_algo(m, "keep_weight", false, false, 0, py::arg("condition")); def_algo(m, "lower_free_indices", true, false, 0, py::arg("lower") = true); def_algo(m, "raise_free_indices", true, false, 0, py::arg("lower") = false); def_algo(m, "integrate_by_parts", true, false, 0, py::arg("away_from")); def_algo(m, "young_project_tensor", true, false, 0, py::arg("modulo_monoterm") = false); def_algo(m, "join_gamma", true, false, 0, py::arg("expand") = true, py::arg("use_gendelta") = false); def_algo(m, "einsteinify", true, false, 0, py::arg("metric") = Ex{}); def_algo(m, "evaluate", false, false, 0, py::arg("components") = Ex{}, py::arg("rhsonly") = false, py::arg("simplify") = true); def_algo>(m, "keep_terms", true, false, 0, py::arg("terms")); def_algo, std::vector>(m, "young_project", true, false, 0, py::arg("shape"), py::arg("indices")); def_algo(m, "simplify", false, false, 0); def_algo(m, "order", true, false, 0, py::arg("factors"), py::arg("anticommuting") = false); def_algo(m, "epsilon_to_delta", true, false, 0, py::arg("reduce") = true); def_algo(m, "rename_dummies", true, false, 0, py::arg("set") = "", py::arg("to") = ""); def_algo(m, "sym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = false); def_algo(m, "asym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = true); def_algo, bool>(m, "slot_sym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = false); def_algo, bool>(m, "slot_asym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = true); def_algo(m, "factor_in", true, false, 0, py::arg("factors")); def_algo(m, "factor_out", true, false, 0, py::arg("factors"), py::arg("right") = false); def_algo(m, "fierz", true, false, 0, py::arg("spinors")); def_algo(m, "substitute", true, false, 0, py::arg("rules"), py::arg("partial") = true); def_algo(m, "take_match", true, false, 0, py::arg("rules")); def_algo(m, "replace_match", false, false, 0); def_algo(m, "zoom", true, false, 0, py::arg("rules")); def_algo_preorder(m, "unzoom", true, false, 0); def_algo(m, "untrace", true, false, 0); def_algo(m, "rewrite_indices", true, false, 0, py::arg("preferred"), py::arg("converters")); def_algo_preorder(m, "vary", false, false, 0, py::arg("rules")); def_algo(m, "split_gamma", true, false, 0, py::arg("on_back")); def_algo(m, "split_index", true, false, 0, py::arg("rules")); def_algo(m, "unwrap", true, false, 0, py::arg("wrapper") = Ex{}); // def_algo_preorder(m, "young_reduce", true, false, 0, py::arg("pattern") = nullptr); // def_algo_preorder(m, "young_reduce_trace", true, false, 0); def_algo_preorder(m, "meld", true, false, 0, py::arg("project_as_sum") = false); // def_algo(m, "nevaluate", true, false, 0); m.def("nevaluate", [](Ex_ptr ex, py::dict d) { std::vector> values; NEvaluator ev(*ex); for(const auto& dv: d) { // std::cerr << dv.first << std::endl; // values.push_back(std::make_pair(py::cast(dv.first), py::cast>(dv.second))); ev.set_variable(py::cast(dv.first), py::cast>(dv.second)); } auto res = ev.evaluate(); return res; // nevaluate algo(*get_kernel_from_scope(), *ex, values); // algo.apply } ); } }