AngouriMath
AngouriMath.h
1 #pragma once
2 
3 #include "TypeAliases.h"
4 #include "ErrorCode.h"
5 #include "FieldCache.h"
6 
7 #include <memory>
8 #include <string>
9 #include <ostream>
10 #include <vector>
11 #include <complex>
12 
13 namespace AngouriMath
14 {
15  class Entity;
16 }
17 
18 namespace AngouriMath::Internal
19 {
21  {
22  private:
25  FieldCache<std::vector<Entity>> varsAndConstants;
26  FieldCache<std::vector<Entity>> directChildren;
28  FieldCache<std::shared_ptr<Entity>> innerSimplified;
30  EntityRef reference;
31  public:
32  EntityInstance(EntityRef reference) : reference(reference) { }
33 
34  const std::vector<Entity>& CachedNodes();
35  const std::vector<Entity>& CachedVars();
36  const std::vector<Entity>& CachedVarsAndConstants();
37  const std::vector<Entity>& CachedDirectChildren();
38  EntityRef GetReference() const { return reference; }
39  const Entity& CachedEvaled();
40  const Entity& CachedInnerSimplified();
41  const std::string& CachedString();
42  };
43 }
44 
45 namespace AngouriMath
46 {
47  enum class ApproachFrom : std::int32_t
48  {
49  BothSides = 0,
50  Left = 1,
51  Right = 2
52  };
53 
54  class Entity
55  {
56  explicit Entity(Internal::EntityRef handle);
57 
58  std::shared_ptr<Internal::EntityInstance> innerEntityInstance;
59  public:
60  // Constructors
61  Entity();
62  Entity(const std::string& expr);
63  Entity(const char* expr);
64 
65  // Methods
66  std::string ToString() const;
67  std::string Latexise() const;
68  Entity Differentiate(const Entity& var) const;
69  Entity Integrate(const Entity& var) const;
70  Entity Solve(const Entity& var) const;
71  Entity SolveEquation(const Entity& var) const;
72  Entity Limit(const Entity& var, const Entity& dest) const;
73  Entity Limit(const Entity& var, const Entity& dest, ApproachFrom from) const;
74  Entity Simplify() const;
75  std::vector<Entity> Alternate() const;
76 
77 
78  // Casts
79  std::int64_t AsInteger() const;
80  std::pair<std::int64_t, std::int64_t> AsRational() const;
81  double AsReal() const;
82  std::complex<double> AsComplex() const;
83 
84  // Properties
85  const std::vector<Entity>& Nodes() const { return innerEntityInstance.get()->CachedNodes(); }
86  const std::vector<Entity>& Vars() const { return innerEntityInstance.get()->CachedVars(); }
87  const std::vector<Entity>& VarsAndConsts() const { return innerEntityInstance.get()->CachedVarsAndConstants(); }
88  const std::vector<Entity>& DirectChildren() const { return innerEntityInstance.get()->CachedDirectChildren(); }
89  const Entity InnerSimplified() const { return innerEntityInstance.get()->CachedInnerSimplified(); }
90  const Entity Evaled() const { return innerEntityInstance.get()->CachedEvaled(); }
91 
92  friend Internal::EntityRef GetHandle(const Entity& e);
93  friend Entity CreateByHandle(Internal::EntityRef handle);
94  };
95 
96  inline std::ostream& operator<<(std::ostream& out, const AngouriMath::Entity& e)
97  {
98  out << e.ToString();
99  return out;
100  }
101 }
102 
103 namespace std
104 {
105  inline std::string to_string(const AngouriMath::Entity& e)
106  {
107  return e.ToString();
108  }
109 }
ApproachFrom
Where to tend to the given number in limits
Definition: Limit.Definition.cs:13
IReadOnlyCollection< Variable > VarsAndConsts
Set of unique variables, for example it extracts x, goose, pi from (x + 2 * goose) - pi * x ...
Definition: Entity.Definition.cs:549
Definition: AngouriMath.h:103
Definition: AngouriMath.cpp:20
IReadOnlyList< Variable > Vars
Set of unique variables, for example it extracts x, goose from (x + 2 * goose) - pi * x ...
Definition: Entity.Definition.cs:504
Means that the limit is considered valid if and only if Left-sided limit exists and Right-sided limit...
IEnumerable< Entity > Nodes
The list of all subnodes of the given expression, including its own.
Definition: Entity.Definition.cs:162
If x tends from the right, i.
partial record Entity
This is the main class in AngouriMath.
Definition: StringToEachClass.Classes.cs:14
If x tends from the left, i.
Definition: AngouriMath.h:54
Definition: AngouriMath.h:20
IReadOnlyList< Entity > DirectChildren
Represents all direct children of a node
Definition: Entity.Definition.cs:132
Definition: FieldCache.h:9