9static bool zt_is_exp_seq(
const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
10 std::shared_ptr<SymbolicExpr>& base_out) {
14 auto power = std::dynamic_pointer_cast<const PowerNode>(
detail::node(f));
18 auto exponent = std::dynamic_pointer_cast<const VariableNode>(power->exponent());
32 std::shared_ptr<SymbolicExpr>& base) {
33 auto product = std::dynamic_pointer_cast<const MultiplyNode>(
detail::node(f));
34 if (!product || product->operands().size() != 2) {
37 for (std::size_t i = 0; i < 2; ++i) {
38 auto variable = std::dynamic_pointer_cast<const VariableNode>(product->operands()[i]);
51 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n) {
56 auto power = std::dynamic_pointer_cast<const PowerNode>(
detail::node(f));
60 variable = std::dynamic_pointer_cast<const VariableNode>(power->base());
64 auto exponent = std::dynamic_pointer_cast<const NumberNode>(power->exponent());
74static std::shared_ptr<SymbolicExpr>
zt_abs_expr(
const std::shared_ptr<SymbolicExpr>& expr) {
82static std::vector<std::shared_ptr<SymbolicExpr>>
zt_unit_roc(
const std::string& z) {
84 SymbolicExpr::number(1));
85 return condition ? std::vector<std::shared_ptr<SymbolicExpr>>{condition}
86 : std::vector<std::shared_ptr<SymbolicExpr>>{};
90 const std::shared_ptr<SymbolicExpr>& base,
91 const std::string& z) {
94 return condition ? std::vector<std::shared_ptr<SymbolicExpr>>{condition}
95 : std::vector<std::shared_ptr<SymbolicExpr>>{};
99 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
const std::string& z) {
101 std::shared_ptr<SymbolicExpr> base;
104 std::shared_ptr<SymbolicExpr> frequency;
109static std::vector<std::shared_ptr<SymbolicExpr>>
zt_roc(
110 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
const std::string& z) {
112 auto addition = std::dynamic_pointer_cast<const AddNode>(
detail::node(f));
114 std::vector<std::shared_ptr<SymbolicExpr>> combined;
115 for (
const auto& operand : addition->operands()) {
117 combined.insert(combined.end(), conditions.begin(), conditions.end());
123 if (!coefficient->is_one())
return zt_roc(body, n, z);
128 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
132 (
context).limits().max_ast_nodes,
"transform");
136 auto square = SymbolicExpr::power(SymbolicExpr::variable(n), SymbolicExpr::number(2));
139 SymbolicExpr::multiply(SymbolicExpr::number(-1), z),
142 auto denominator = SymbolicExpr::power(SymbolicExpr::add(z, SymbolicExpr::number(-1)),
145 SymbolicExpr::add(z, SymbolicExpr::number(1)));
150 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
154 (
context).limits().max_ast_nodes,
"transform");
155 std::shared_ptr<SymbolicExpr> base;
158 auto difference = SymbolicExpr::add(z, SymbolicExpr::multiply(SymbolicExpr::number(-1), base));
160 auto denominator = SymbolicExpr::power(difference, SymbolicExpr::number(2));
165 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
169 (
context).limits().max_ast_nodes,
"transform");
171 std::shared_ptr<SymbolicExpr> frequency;
172 if (!
te_is_trig(f, n, is_sin, frequency))
return nullptr;
173 auto cosine = SymbolicExpr::cos(frequency);
174 auto cross = SymbolicExpr::multiply(SymbolicExpr::multiply(SymbolicExpr::number(-2), z), cosine);
175 auto denominator = SymbolicExpr::add(SymbolicExpr::add(
176 SymbolicExpr::power(z, SymbolicExpr::number(2)), cross), SymbolicExpr::number(1));
177 auto factor = is_sin ? SymbolicExpr::sin(frequency) : SymbolicExpr::add(z,
178 SymbolicExpr::multiply(SymbolicExpr::number(-1), cosine));
183 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
const std::string& z) {
190 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
191 const std::string& z, ComputationContext&
context);
193static std::shared_ptr<SymbolicExpr>
zt_sum(
194 const std::shared_ptr<SymbolicExpr>& f,
const AddNode& addition,
196 std::shared_ptr<SymbolicExpr> result;
197 for (
const auto& operand : addition.
operands()) {
200 result = result ? SymbolicExpr::add(result, transformed) : transformed;
206 const std::shared_ptr<SymbolicExpr>& f,
const std::string& n,
209 (
context).limits().max_ast_nodes,
"transform");
210 auto step =
context.consume_steps(1,
"z_transform.recursive");
217 auto zv = SymbolicExpr::variable(z);
218 auto addition = std::dynamic_pointer_cast<const AddNode>(
detail::node(f));
223 if (!coefficient->is_one()) {
230 auto denominator = SymbolicExpr::add(zv, SymbolicExpr::number(-1));
246 const std::shared_ptr<SymbolicExpr>& f_n,
247 const std::string& n,
248 const std::string& z,
250 const std::string operation =
"z_transform";
253 auto step =
context.consume_steps(8, operation);
257 auto final_access =
context.consume_steps(0, operation);
263 result.value().value.roc =
zt_roc(f_n, n, z);
266 }
catch (
const std::bad_alloc&) {
268 "transform allocation failed",
270 }
catch (
const std::exception&
e) {
272 e.what(), operation);
277 const std::shared_ptr<SymbolicExpr>& f_n,
278 const std::string& n,
279 const std::string& z) {
const std::vector< std::shared_ptr< const SymbolicNode > > & operands() const noexcept
static Result failure(CasErrc code, std::string message, std::string operation={})
static std::shared_ptr< const SymbolicNode > create_variable(const std::string &name)
SymbolicNodePtr differentiate_node(const SymbolicNodePtr &node, const std::string &variable, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
std::shared_ptr< const Node > make_node(Args &&... args)
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
static bool zt_is_weighted_exp(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, std::shared_ptr< SymbolicExpr > &base)
const std::string & variable
static std::vector< std::shared_ptr< SymbolicExpr > > zt_lookup_roc(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::string &z)
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
ExprResult integer(Integer)=delete
static std::shared_ptr< SymbolicExpr > zt_abs_expr(const std::shared_ptr< SymbolicExpr > &expr)
bool try_get_integer_value(const std::shared_ptr< const NumberNode > &node, BigInt &value)
static std::shared_ptr< SymbolicExpr > z_transform_core(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::string &z, ComputationContext &context)
static std::shared_ptr< SymbolicExpr > zt_polynomial(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::shared_ptr< SymbolicExpr > &z, const std::string &z_var, ComputationContext &context)
static std::shared_ptr< SymbolicExpr > zt_unevaluated(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::string &z)
static std::shared_ptr< SymbolicExpr > zt_sum(const std::shared_ptr< SymbolicExpr > &f, const AddNode &addition, const std::string &n, const std::string &z, ComputationContext &context)
static std::vector< std::shared_ptr< SymbolicExpr > > zt_base_roc(const std::shared_ptr< SymbolicExpr > &base, const std::string &z)
static std::vector< std::shared_ptr< SymbolicExpr > > zt_unit_roc(const std::string &z)
static ZPolynomialPattern zt_polynomial_pattern(const std::shared_ptr< SymbolicExpr > &f, const std::string &n)
static bool zt_is_exp_seq(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, std::shared_ptr< SymbolicExpr > &base_out)
Result< Verified< EvaluatedTransform > > TransformEngineResult
static std::shared_ptr< SymbolicExpr > zt_exponential(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::shared_ptr< SymbolicExpr > &z, ComputationContext &context)
TransformEngineResult z_transform_checked(const std::shared_ptr< SymbolicExpr > &f_n, const std::string &n, const std::string &z, ComputationContext &context)
const ExprPtr & denominator
static std::vector< std::shared_ptr< SymbolicExpr > > zt_roc(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::string &z)
__attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std std::shared_ptr< SymbolicExpr > const std::string & z_var
static std::shared_ptr< SymbolicExpr > zt_trigonometric(const std::shared_ptr< SymbolicExpr > &f, const std::string &n, const std::shared_ptr< SymbolicExpr > &z, ComputationContext &context)