Minsky: 3.17.0
MathDAG Namespace Reference

Namespaces

 anonymous_namespace{equationDisplayRender.cc}
 
 anonymous_namespace{equations.cc}
 
 anonymous_namespace{node_latex.cc}
 
 anonymous_namespace{node_matlab.cc}
 

Classes

struct  CachedOp
 
struct  ConstantDAG
 
struct  Expr
 
struct  GodleyColumnDAG
 represents a Godley column More...
 
struct  IntegralInputVariableDAG
 represents the input of an integration operation - differs from Variable DAG in that it doesn't refer to the VariableValue More...
 
struct  LaTeXManip
 a manipulator to make iostream expressions easy More...
 
struct  LockDAG
 
struct  MatlabManip
 
struct  Node
 
struct  OperationDAG
 
struct  OperationDAGBase
 
class  SubexpressionCache
 
class  SystemOfEquations
 
class  VariableDAG
 
struct  WeakNodePtr
 weak reference into subexpression cache More...
 

Typedefs

typedef std::shared_ptr< NodeNodePtr
 
typedef shared_ptr< VariableDAGVariableDAGPtr
 

Functions

string differentiateName (const std::string &x)
 creates a new name to represent the derivative of a variable More...
 
string latex (double)
 convert double to a LaTeX string representing that value More...
 
string latexInit (const string &)
 convert an initialisation string into a matlab expression More...
 
string mathrm (const string &nm)
 wraps in if nm has more than one letter - and also takes into account LaTeX subscript/superscripts More...
 
string matlabInit (const string &)
 convert an initialisation string into a matlab expression More...
 
ostream & operator<< (ostream &o, LaTeXManip m)
 
ostream & operator<< (ostream &o, MatlabManip m)
 
Expr operator+ (const NodePtr &x, const Expr &y)
 
Expr operator+ (const Expr &x, const Expr &y)
 
Expr operator+ (double x, const Expr &y)
 
Expr operator- (const NodePtr &x, const Expr &y)
 
Expr operator- (const Expr &x, const Expr &y)
 
Expr operator- (double x, const Expr &y)
 
Expr operator- (const Expr &x, double y)
 
Expr operator* (const NodePtr &x, const Expr &y)
 
Expr operator* (const Expr &x, const Expr &y)
 
Expr operator* (double x, const Expr &y)
 
Expr operator/ (const Expr &x, const Expr &y)
 
Expr operator/ (const NodePtr &x, const Expr &y)
 
Expr operator/ (double x, const Expr &y)
 
Expr log (const Expr &x)
 
Expr exp (const Expr &x)
 
Expr sin (const Expr &x)
 
Expr cos (const Expr &x)
 
Expr sinh (const Expr &x)
 
Expr cosh (const Expr &x)
 
Expr sqrt (const Expr &x)
 
Expr Gamma (const Expr &x)
 
Expr polygamma (const Expr &x, const Expr &y)
 
Expr fact (const Expr &x)
 
Expr operator<= (const Expr &x, const NodePtr &y)
 
Expr operator<= (const Expr &x, double y)
 
Expr operator<= (double x, const Expr &y)
 
Expr operator< (const Expr &x, const NodePtr &y)
 
Expr operator< (const Expr &x, double y)
 
Expr operator< (double x, const Expr &y)
 

Typedef Documentation

◆ NodePtr

typedef std::shared_ptr<Node> MathDAG::NodePtr

Definition at line 131 of file equations.h.

◆ VariableDAGPtr

typedef shared_ptr<VariableDAG> MathDAG::VariableDAGPtr

Definition at line 208 of file equations.h.

Function Documentation

◆ cos()

Expr MathDAG::cos ( const Expr x)
inline

Definition at line 136 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::cos, and MathDAG::Expr::newNode().

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), minsky::VariableBase::draw(), minsky::EvalOp< minsky::OperationType::constant >::evaluate(), minsky::RenderVariable::inImage(), minsky::Group::inIORegion(), minsky::PhillipsDiagram::init(), minsky::VariableBase::onMouseMotion(), and minsky::Group::rotFactor().

136  {
137  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::cos));
138  r->arguments[0].push_back(x);
139  return Expr(x.cache,r);
140  }
Expr cos(const Expr &x)
Definition: expr.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cosh()

Expr MathDAG::cosh ( const Expr x)
inline

Definition at line 147 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::cosh, and MathDAG::Expr::newNode().

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), and minsky::EvalOp< minsky::OperationType::constant >::evaluate().

147  {
148  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::cosh));
149  r->arguments[0].push_back(x);
150  return Expr(x.cache,r);
151  }
Expr cosh(const Expr &x)
Definition: expr.h:147
Here is the call graph for this function:
Here is the caller graph for this function:

◆ differentiateName()

std::string MathDAG::differentiateName ( const string &  x)

creates a new name to represent the derivative of a variable

Definition at line 39 of file derivative.cc.

References minsky::str().

Referenced by MathDAG::SystemOfEquations::derivative().

40  {
41  int order=0; // current derivative order
42  string varName=x; // base variable name
43  const regex singleDeriv(R"(d(.*)/dt)"),
44  higherOrderDeriv(R"(d\^\{(\d*)\}(.*)/dt\^\{(\d*)\})");
45  smatch m;
46  if (regex_match(x,m,singleDeriv))
47  {
48  order=1;
49  varName=m[1];
50  }
51  else if(regex_match(x,m,higherOrderDeriv) && m[1]==m[3])
52  {
53  // for some reason, stoi is missing on MXE, so fake it
54  order=atoi(m[3].str().c_str());
55  varName=m[2];
56  }
57  order++;
58  ostringstream r;
59  if (order==1)
60  r<<"d"<<varName<<"/dt";
61  else
62  r<<"d^{"<<order<<"}"<<varName<<"/dt^{"<<order<<"}";
63  return r.str();
64  }
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exp()

Expr MathDAG::exp ( const Expr x)
inline

Definition at line 125 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::exp, and MathDAG::Expr::newNode().

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), minsky::EvalOp< minsky::OperationType::constant >::evaluate(), and minsky::expMultiplier().

125  {
126  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::exp));
127  r->arguments[0].push_back(x);
128  return Expr(x.cache,r);
129  }
Expr exp(const Expr &x)
Definition: expr.h:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fact()

Expr MathDAG::fact ( const Expr x)
inline

Definition at line 172 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::fact, and MathDAG::Expr::newNode().

172  {
173  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::fact));
174  r->arguments[0].push_back(x);
175  return Expr(x.cache,r);
176  }
Expr fact(const Expr &x)
Definition: expr.h:172
Here is the call graph for this function:

◆ Gamma()

Expr MathDAG::Gamma ( const Expr x)
inline

Definition at line 159 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::Gamma, and MathDAG::Expr::newNode().

Referenced by MathDAG::SystemOfEquations::derivative().

159  {
160  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::Gamma));
161  r->arguments[0].push_back(x);
162  return Expr(x.cache,r);
163  }
Expr Gamma(const Expr &x)
Definition: expr.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ latex()

string MathDAG::latex ( double  x)

convert double to a LaTeX string representing that value

Definition at line 28 of file node_latex.cc.

References minsky::pow(), and minsky::str().

Referenced by MathDAG::OperationDAG< OperationType::subtract >::latex(), and MathDAG::Node::latexStr().

29  {
30  if (abs(x)>0 && (abs(x)>=1e5 || abs(x)<=1e-4))
31  {
32  int exponent=static_cast<int>(log10(abs(x)));
33  if (exponent<0) exponent++;
34  return str(x/pow(10.0,exponent))+"\\times10^{"+str(exponent)+"}";
35  }
36  return str(x);
37  }
UnitsExpressionWalker pow(const UnitsExpressionWalker &x, const UnitsExpressionWalker &y)
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ latexInit()

string MathDAG::latexInit ( const string &  init)

convert an initialisation string into a matlab expression

Definition at line 73 of file node_latex.cc.

References minsky::cminsky(), minsky::VariableValue::init(), minsky::VariableValues::initValue(), minsky::str(), and minsky::Minsky::variableValues.

Referenced by MathDAG::SystemOfEquations::latex(), MathDAG::SystemOfEquations::latexWrapped(), MathDAG::SystemOfEquations::renderEquations(), and MathDAG::anonymous_namespace{equationDisplayRender.cc}::variableRender().

74  {
75  if (init.empty()) return "0";
76  VariableValue v;
77  v.init(init);
78  auto t=cminsky().variableValues.initValue(v);
79  string r;
80  switch (t.rank())
81  {
82  case 0: return str(t[0]);
83  case 1: r="(";
84  for (size_t i=0; i<5 && i<t.size(); ++i)
85  {
86  if (i>0) r+=' ';
87  r+=str(t[i]);
88  }
89  if (t.size()>5)
90  r+="\\ldots";
91  return r+")";
92  default:
93  return "\\ldots"; //TODO can we represent this stuff reasonably?
94  }
95  }
TensorVal initValue(const VariableValue &, std::set< std::string > &visited) const
evaluates the initial value of a given variableValue in the context given by this. visited is used to check for circular definitions
VariableValues variableValues
Definition: minsky.h:188
const std::string & init() const
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log()

Expr MathDAG::log ( const Expr x)
inline

Definition at line 119 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::ln, and MathDAG::Expr::newNode().

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), minsky::EvalOp< minsky::OperationType::constant >::d2(), MathDAG::SystemOfEquations::derivative(), minsky::engExp(), minsky::EvalOp< minsky::OperationType::constant >::evaluate(), minsky::loadValueFromCSVFileT(), and minsky::OperationBase::unitsBinOpCase().

119  {
120  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::ln));
121  r->arguments[0].push_back(x);
122  return Expr(x.cache,r);
123  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mathrm()

string MathDAG::mathrm ( const string &  nm)

wraps in if nm has more than one letter - and also takes into account LaTeX subscript/superscripts

Definition at line 41 of file node_latex.cc.

Referenced by MathDAG::OperationDAG< OperationType::subtract >::latex(), MathDAG::VariableDAG::latex(), MathDAG::SystemOfEquations::latex(), MathDAG::SystemOfEquations::latexWrapped(), MathDAG::VariableDAG::render(), MathDAG::OperationDAG< OperationType::subtract >::render(), and MathDAG::SystemOfEquations::renderEquations().

42  {
43  // process super/sub scripts
44  string::size_type ss;
45  if ((ss=nm.find_first_of("_^"))!=string::npos)
46  return mathrm(nm.substr(0, ss)) + nm[ss] + "{"+mathrm(nm.substr(ss+1))+"}";
47 
48  // process % chars
49  string::size_type pc;
50  if ((pc=nm.find_first_of('%'))!=string::npos)
51  if (pc>0 && nm[pc-1]!='\\')
52  return mathrm(nm.substr(0, pc)) + "\\" + nm[pc] + mathrm(nm.substr(pc+1));
53 
54  // if its a single letter variable, or contains LaTeX codes, process as is
55  if (nm.length()==1 || nm.find('\\')!=string::npos)
56  return nm;
57  return "\\mathrm{"+nm+"}";
58  }
string mathrm(const string &nm)
wraps in if nm has more than one letter - and also takes into account LaTeX subscript/superscripts ...
Definition: node_latex.cc:41
Here is the caller graph for this function:

◆ matlabInit()

string MathDAG::matlabInit ( const string &  init)

convert an initialisation string into a matlab expression

Definition at line 45 of file node_matlab.cc.

References minsky::cminsky(), minsky::VariableValue::init(), minsky::VariableValues::initValue(), minsky::str(), and minsky::Minsky::variableValues.

Referenced by MathDAG::SystemOfEquations::matlab().

46  {
47  if (init.empty()) return "0";
48  VariableValue v;
49  v.init(init);
50  auto t=cminsky().variableValues.initValue(v);
51  string r;
52  switch (t.rank())
53  {
54  case 0: return str(t[0]);
55  case 1: r="[";
56  for (auto i: t) r+=str(i)+",";
57  return r+"]";
58  case 2:
59  r="[";
60  for (size_t i=0; i<t.hypercube().xvectors[1].size(); ++i)
61  {
62  for (size_t j=0; j<t.hypercube().xvectors[0].size(); ++j)
63  r+=str(t[i*t.hypercube().xvectors[0].size()+j])+",";
64  r+=";";
65  }
66  return r+"]";
67  default:
68  throw error("high rank tensors not supported in Matlab");
69  }
70  }
TensorVal initValue(const VariableValue &, std::set< std::string > &visited) const
evaluates the initial value of a given variableValue in the context given by this. visited is used to check for circular definitions
VariableValues variableValues
Definition: minsky.h:188
const std::string & init() const
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*() [1/3]

◆ operator*() [2/3]

Expr MathDAG::operator* ( const Expr x,
const Expr y 
)
inline

Definition at line 102 of file expr.h.

102  {
103  return x*NodePtr(y);
104  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator*() [3/3]

Expr MathDAG::operator* ( double  x,
const Expr y 
)
inline

Definition at line 105 of file expr.h.

105  {
106  return y*NodePtr(new ConstantDAG(x));
107  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator+() [1/3]

Expr MathDAG::operator+ ( const NodePtr x,
const Expr y 
)
inline

Definition at line 76 of file expr.h.

76  {
77  return y+x;
78  }

◆ operator+() [2/3]

Expr MathDAG::operator+ ( const Expr x,
const Expr y 
)
inline

Definition at line 79 of file expr.h.

79  {
80  return x+NodePtr(y);
81  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator+() [3/3]

Expr MathDAG::operator+ ( double  x,
const Expr y 
)
inline

Definition at line 82 of file expr.h.

82  {
83  return y+NodePtr(new ConstantDAG(x));
84  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator-() [1/4]

Expr MathDAG::operator- ( const NodePtr x,
const Expr y 
)
inline

Definition at line 86 of file expr.h.

References MathDAG::Expr::cache.

86  {
87  return Expr(y.cache, x)-NodePtr(y);
88  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator-() [2/4]

Expr MathDAG::operator- ( const Expr x,
const Expr y 
)
inline

Definition at line 89 of file expr.h.

89  {
90  return x-NodePtr(y);
91  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator-() [3/4]

Expr MathDAG::operator- ( double  x,
const Expr y 
)
inline

Definition at line 92 of file expr.h.

92  {
93  return NodePtr(new ConstantDAG(x))-y;
94  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator-() [4/4]

Expr MathDAG::operator- ( const Expr x,
double  y 
)
inline

Definition at line 95 of file expr.h.

95  {
96  return x-NodePtr(new ConstantDAG(y));
97  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator/() [1/3]

Expr MathDAG::operator/ ( const Expr x,
const Expr y 
)
inline

Definition at line 109 of file expr.h.

109  {
110  return x/NodePtr(y);
111  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator/() [2/3]

Expr MathDAG::operator/ ( const NodePtr x,
const Expr y 
)
inline

Definition at line 112 of file expr.h.

References MathDAG::Expr::cache.

112  {
113  return Expr(y.cache, x)/y;
114  }

◆ operator/() [3/3]

Expr MathDAG::operator/ ( double  x,
const Expr y 
)
inline

Definition at line 115 of file expr.h.

115  {
116  return NodePtr(new ConstantDAG(x))/y;
117  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator<() [1/3]

Expr MathDAG::operator< ( const Expr x,
const NodePtr y 
)
inline

Definition at line 192 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::lt, and MathDAG::Expr::newNode().

192  {
193  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::lt));
194  r->arguments[0].push_back(x);
195  r->arguments[1].push_back(y);
196  return Expr(x.cache,r);
197  }
Here is the call graph for this function:

◆ operator<() [2/3]

Expr MathDAG::operator< ( const Expr x,
double  y 
)
inline

Definition at line 199 of file expr.h.

References MathDAG::Expr::cache.

199  {
200  return x < Expr(x.cache, NodePtr(new ConstantDAG(y)));
201  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator<() [3/3]

Expr MathDAG::operator< ( double  x,
const Expr y 
)
inline

Definition at line 202 of file expr.h.

References MathDAG::Expr::cache.

202  {
203  return Expr(y.cache, NodePtr(new ConstantDAG(x))) < y;
204  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator<<() [1/2]

ostream& MathDAG::operator<< ( ostream &  o,
LaTeXManip  m 
)
inline

Definition at line 150 of file equations.h.

References MathDAG::Node::latex(), and MathDAG::LaTeXManip::node.

151  {return m.node.latex(o);}
Here is the call graph for this function:

◆ operator<<() [2/2]

ostream& MathDAG::operator<< ( ostream &  o,
MatlabManip  m 
)
inline

Definition at line 152 of file equations.h.

References MathDAG::Node::matlab(), and MathDAG::MatlabManip::node.

153  {return m.node.matlab(o);}
Here is the call graph for this function:

◆ operator<=() [1/3]

Expr MathDAG::operator<= ( const Expr x,
const NodePtr y 
)
inline

Definition at line 178 of file expr.h.

References MathDAG::Expr::cache, minsky::OperationType::le, and MathDAG::Expr::newNode().

178  {
179  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::le));
180  r->arguments[0].push_back(x);
181  r->arguments[1].push_back(y);
182  return Expr(x.cache,r);
183  }
Here is the call graph for this function:

◆ operator<=() [2/3]

Expr MathDAG::operator<= ( const Expr x,
double  y 
)
inline

Definition at line 185 of file expr.h.

References MathDAG::Expr::cache.

185  {
186  return x <= Expr(x.cache, NodePtr(new ConstantDAG(y)));
187  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ operator<=() [3/3]

Expr MathDAG::operator<= ( double  x,
const Expr y 
)
inline

Definition at line 188 of file expr.h.

References MathDAG::Expr::cache.

188  {
189  return Expr(y.cache, NodePtr(new ConstantDAG(x))) <= y;
190  }
std::shared_ptr< Node > NodePtr
Definition: equations.h:131

◆ polygamma()

Expr MathDAG::polygamma ( const Expr x,
const Expr y 
)
inline

Definition at line 165 of file expr.h.

References MathDAG::Expr::cache, MathDAG::Expr::newNode(), and minsky::OperationType::polygamma.

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), minsky::EvalOp< minsky::OperationType::constant >::evaluate(), and minsky::OperationBase::unitsBinOpCase().

165  {
166  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::polygamma));
167  r->arguments[0].push_back(x);
168  r->arguments[1].push_back(y);
169  return Expr(x.cache,r);
170  }
Expr polygamma(const Expr &x, const Expr &y)
Definition: expr.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sin()

Expr MathDAG::sin ( const Expr x)
inline

Definition at line 130 of file expr.h.

References MathDAG::Expr::cache, MathDAG::Expr::newNode(), and minsky::OperationType::sin.

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), minsky::VariableBase::draw(), minsky::EvalOp< minsky::OperationType::constant >::evaluate(), minsky::RenderVariable::inImage(), minsky::Group::inIORegion(), and minsky::PhillipsDiagram::init().

130  {
131  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::sin));
132  r->arguments[0].push_back(x);
133  return Expr(x.cache,r);
134  }
Expr sin(const Expr &x)
Definition: expr.h:130
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sinh()

Expr MathDAG::sinh ( const Expr x)
inline

Definition at line 141 of file expr.h.

References MathDAG::Expr::cache, MathDAG::Expr::newNode(), and minsky::OperationType::sinh.

Referenced by minsky::EvalOp< minsky::OperationType::constant >::d1(), MathDAG::SystemOfEquations::derivative(), and minsky::EvalOp< minsky::OperationType::constant >::evaluate().

141  {
142  shared_ptr<OperationDAGBase> r(x.newNode(OperationType::sinh));
143  r->arguments[0].push_back(x);
144  return Expr(x.cache,r);
145  }
Expr sinh(const Expr &x)
Definition: expr.h:141
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqrt()