Skip to content

Commit 0610e36

Browse files
committed
change encoding from gb2312 to utf-8
1 parent 52feb8e commit 0610e36

File tree

15 files changed

+141
-137
lines changed

15 files changed

+141
-137
lines changed

mathS/include/Compute.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include <Rule.h>
44

55
/*
6-
使用某些策略运用一系列Rule并返回一个MathObject,我们把这称为Compute。Compute的参数和返回类型与Rule相同,但作用不一样
6+
使用某些策略运用一系列Rule并返回一个MathObject,我们把这称为Compute。Compute的参数和返回类型与Rule相同,但作用不一样
77
8-
对于每种MathObject,都有默认的Compute操作
8+
对于每种MathObject,都有默认的Compute操作
99
10-
Power:(a*b)^e=a^e*b^e展开,(a^e1)^e2=a^(e1*e2),常数自动计算,多项式常整数幂展开,化简
11-
Item: Vec分配率展开(a+b)*c=a*c+b*c,化简:倒数相消a/a=1,常数自动计算
12-
Polynomial:常数自动计算,合并同类项
10+
Power:(a*b)^e=a^e*b^e展开,(a^e1)^e2=a^(e1*e2),常数自动计算,多项式常整数幂展开,化简
11+
Item: Vec分配率展开(a+b)*c=a*c+b*c,化简:倒数相消a/a=1,常数自动计算
12+
Polynomial:常数自动计算,合并同类项
1313
14-
Function FunctionalOperator根据函数名称的不同,做不同的计算。未知的函数不做计算。
14+
Function FunctionalOperator根据函数名称的不同,做不同的计算。未知的函数不做计算。
1515
16-
Compare 做简单的化简处理,如果全是常数,直接算出结果
16+
Compare 做简单的化简处理,如果全是常数,直接算出结果
1717
1818
1919
@@ -22,7 +22,7 @@
2222
namespace mathS{
2323

2424
/// <summary>
25-
/// 总 Compute, 在这里分类型
25+
/// 总 Compute, 在这里分类型
2626
/// </summary>
2727
/// <param name="input"></param>
2828
/// <returns></returns>

mathS/include/LBAssembler.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ namespace mathS
1919

2020
public:
2121
Assembler() { InitializeSTDLIB(); }
22-
// 根据表达式expr,组装一个以expr中的出现的变量为参数的函数。参数的顺序是param_str所给出的。
23-
// 如 expr = sin(u)*v, params={u, v},那么返回的函数就是f(x1,x2)=sin(x1)*x2.
22+
// 根据表达式expr,组装一个以expr中的出现的变量为参数的函数。参数的顺序是param_str所给出的。
23+
// 如 expr = sin(u)*v, params={u, v},那么返回的函数就是f(x1,x2)=sin(x1)*x2.
2424
NMath::NFunction Assemble(Ptr<MathObject> expr, std::vector<std::string>& params);
2525

2626
private:
2727

28-
// 考虑到将来可能要在一个脚本运行时组装函数,也许,不是从function_table, constant_table中来查找,
29-
// 而是从运行时的环境中查找所需要的函数、常量、变量等,会更合适,因为运行脚本时,用户可能自定义了的数值函数。
30-
// 但是由于这样的脚本执行器还没有搭建起来, 就先在Assembler里存储function_table和constant_table。
28+
// 考虑到将来可能要在一个脚本运行时组装函数,也许,不是从function_table, constant_table中来查找,
29+
// 而是从运行时的环境中查找所需要的函数、常量、变量等,会更合适,因为运行脚本时,用户可能自定义了的数值函数。
30+
// 但是由于这样的脚本执行器还没有搭建起来, 就先在Assembler里存储function_table和constant_table。
3131

32-
// 函数表。组装时需要的标准函数直接根据函数名称从函数表里取
32+
// 函数表。组装时需要的标准函数直接根据函数名称从函数表里取
3333
std::map<std::string, NMath::NFunction> function_table;
34-
// 常量表。组装时遇到常量符号,会从常量表里取。
34+
// 常量表。组装时遇到常量符号,会从常量表里取。
3535
std::map<std::string, NMath::NFunction> constant_table;
3636

3737
std::map<std::string, NMath::NFuncOperator> fop_table;

mathS/include/MathFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace mathS {
77

88
// MathFunction : MathObject -> MathObject
9-
// MathFunction 是对数学对象,运用一些规则来得到结果的
9+
// MathFunction 是对数学对象,运用一些规则来得到结果的
1010
using MathFunction = std::function<Ptr<MathObject>(std::vector<Ptr<MathObject>>)>;
1111

1212
}

mathS/include/MathObject.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace mathS
107107

108108
virtual Type GetType() const = 0;
109109
virtual std::string GetString() const = 0;
110+
virtual std::string GetLaTeXString() const = 0;
110111
virtual int Level() const = 0;
111112

112113

@@ -134,16 +135,17 @@ namespace mathS
134135
};
135136
*/
136137
std::string ListGetString(const std::vector<Ptr<MathObject>>& lst);
138+
std::string ListGetLaTeXString(const std::vector<Ptr<MathObject>>& lst);
137139
std::vector<Ptr<MathObject>> ListDeepCopy(const std::vector<Ptr<MathObject>>& lst);
138140

139141
class Atom : public MathObject
140142
{
141-
// 2020-7-3 架构调整. 原先的Number, Variable, String被全部当做了Atom.
142-
// Atom.str 表示其内容:
143-
// 如果是一个number,那么str就是一个数字对应的字符串;如果是一个variable,就是以字母开头的字符串(或特殊修饰符);如果是string,那一定是""包括的字符串.
144-
// 这个调整的理由是:Number, Variable, String本来就是只用std::string来存储的,其Level(),GetString(),DeepCopy()等方法一模一样
145-
// 并且在一般的表达式变形中,不必对这三者作区分。只需要在化简、求值等涉及到其具体内容时,需要区分。
146-
// 因此采用Atom统一表示,语法分析器会更简单。而涉及到其内容时,再作识别Atom是数字、变量还是字符串.
143+
// 2020-7-3 架构调整. 原先的Number, Variable, String被全部当做了Atom.
144+
// Atom.str 表示其内容:
145+
// 如果是一个number,那么str就是一个数字对应的字符串;如果是一个variable,就是以字母开头的字符串(或特殊修饰符);如果是string,那一定是""包括的字符串.
146+
// 这个调整的理由是:Number, Variable, String本来就是只用std::string来存储的,其Level(),GetString(),DeepCopy()等方法一模一样
147+
// 并且在一般的表达式变形中,不必对这三者作区分。只需要在化简、求值等涉及到其具体内容时,需要区分。
148+
// 因此采用Atom统一表示,语法分析器会更简单。而涉及到其内容时,再作识别Atom是数字、变量还是字符串.
147149
public:
148150
std::string str;
149151

@@ -154,12 +156,12 @@ namespace mathS
154156
Type GetType() const { return Type::ATOM; };
155157

156158
Type AtomType() const;
157-
// 返回数值. 暂时只支持double. 如果以后支持了复数,则需要修改此处.
159+
// 返回数值. 暂时只支持double. 如果以后支持了复数,则需要修改此处.
158160
double NumberValue() const;
159161

160162
int Level() const { return LEVEL_ATOM; };
161163
std::string GetString() const;
162-
164+
std::string GetLaTeXString() const;
163165
Ptr<MathObject> DeepCopy() const;
164166
};
165167

@@ -175,7 +177,7 @@ namespace mathS
175177
Type GetType() const { return Type::VECTOR; };
176178
int Level() const { return LEVEL_VECTOR; };
177179
std::string GetString() const;
178-
180+
std::string GetLaTeXString() const;
179181
Ptr<MathObject> DeepCopy() const;
180182
};
181183

@@ -192,7 +194,7 @@ namespace mathS
192194
Type GetType() const { return Type::FUNCTION; };
193195
int Level() const { return LEVEL_FUNCTION; };
194196
std::string GetString() const;
195-
197+
std::string GetLaTeXString() const;
196198
Ptr<MathObject> DeepCopy() const;
197199
};
198200

@@ -210,7 +212,7 @@ namespace mathS
210212
Type GetType() const { return Type::FUNCOPERATOR; };
211213
int Level() const { return LEVEL_FUNCTION; };
212214
std::string GetString() const;
213-
215+
std::string GetLaTeXString() const;
214216
Ptr<MathObject> DeepCopy() const;
215217
};
216218

@@ -227,7 +229,7 @@ namespace mathS
227229
Type GetType() const { return Type::LOCATE; };
228230
int Level() const { return LEVEL_LOCATE; };
229231
std::string GetString() const;
230-
232+
std::string GetLaTeXString() const;
231233
Ptr<MathObject> DeepCopy() const;
232234
};
233235
class Power : public MathObject
@@ -244,7 +246,7 @@ namespace mathS
244246
Type GetType() const { return Type::POWER; };
245247
int Level() const { return LEVEL_POWER; };
246248
std::string GetString() const;
247-
249+
std::string GetLaTeXString() const;
248250
Ptr<MathObject> DeepCopy() const;
249251
};
250252

@@ -261,7 +263,7 @@ namespace mathS
261263
Type GetType() const { return Type::INVERSE; };
262264
int Level() const { return LEVEL_INVERSE; };
263265
std::string GetString() const;
264-
266+
std::string GetLaTeXString() const;
265267
Ptr<MathObject> DeepCopy() const;
266268
};
267269

@@ -278,7 +280,7 @@ namespace mathS
278280
Type GetType() const { return Type::ITEM; };
279281
int Level() const { return LEVEL_ITEM; };
280282
std::string GetString() const;
281-
283+
std::string GetLaTeXString() const;
282284
Ptr<MathObject> DeepCopy() const;
283285
};
284286

@@ -295,7 +297,7 @@ namespace mathS
295297
Type GetType() const { return Type::OPPOSITE; };
296298
int Level() const { return LEVEL_OPPOSITE; };
297299
std::string GetString() const;
298-
300+
std::string GetLaTeXString() const;
299301
Ptr<MathObject> DeepCopy() const;
300302
};
301303
class Polynomial : public MathObject
@@ -310,7 +312,7 @@ namespace mathS
310312
Type GetType() const { return Type::POLYNOMIAL; };
311313
int Level() const { return LEVEL_POLYNOMIAL; };
312314
std::string GetString() const;
313-
315+
std::string GetLaTeXString() const;
314316
Ptr<MathObject> DeepCopy() const;
315317

316318
void push_back(Ptr<MathObject> const itm);
@@ -330,7 +332,7 @@ namespace mathS
330332
Type GetType() const { return Type::MAP; };
331333
int Level() const { return LEVEL_MAP; };
332334
std::string GetString() const ;
333-
335+
std::string GetLaTeXString() const;
334336
Ptr<MathObject> DeepCopy() const;
335337
};
336338

@@ -349,7 +351,7 @@ namespace mathS
349351
Type GetType() const { return Type::COMPARE; };
350352
int Level() const { return LEVEL_COMPARE; };
351353
std::string GetString() const ;
352-
354+
std::string GetLaTeXString() const;
353355
Ptr<MathObject> DeepCopy() const;
354356
};
355357

@@ -365,7 +367,7 @@ namespace mathS
365367
Type GetType() const { return Type::ERROR; };
366368
int Level() const { return LEVEL_ERROR; };
367369
std::string GetString() const { return info; };
368-
370+
std::string GetLaTeXString() const { return info; };
369371
Ptr<MathObject> DeepCopy() const;
370372
};
371373

@@ -380,7 +382,7 @@ namespace mathS
380382
Type GetType() const { return Type::EMPTY; };
381383
int Level() const { return LEVEL_EMPTY; };
382384
std::string GetString() const { return std::string(); };
383-
385+
std::string GetLaTeXString() const { return std::string(); };
384386
Ptr<MathObject> DeepCopy() const;
385387
};
386388
/*

mathS/include/MathParser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ namespace mathS
1616
{
1717

1818
public:
19-
// 从字符串初始化
19+
// 从字符串初始化
2020
Parser(const std::string& c) : lexer(c) { }
2121

22-
// 获得解析的 MathObject 符号表达式对象
22+
// 获得解析的 MathObject 符号表达式对象
2323
Ptr<MathObject> Parse();
2424
private:
2525
Lexer lexer;
2626

2727
short level(const std::string& c);
2828
/// <summary>
29-
/// 从 start 位置开始解析一个对象,直到到达右括号或末尾. 若没有对象则返回 EmptyObject. 若检测到语法错误则返回ErrorObject
29+
/// 从 start 位置开始解析一个对象,直到到达右括号或末尾. 若没有对象则返回 EmptyObject. 若检测到语法错误则返回ErrorObject
3030
/// </summary>
3131
/// <param name="tokens"></param>
3232
/// <param name="start"></param>
33-
/// <param name="i">引用变量,解析结束时,i在被解析的对象对应token的后一位索引(即往后继续解析开始的位置)</param>
33+
/// <param name="i">引用变量,解析结束时,i在被解析的对象对应token的后一位索引(即往后继续解析开始的位置)</param>
3434
/// <returns></returns>
3535
Ptr<MathObject> parseObject(const std::vector<Token>& tokens, const int start, int& i);
3636

mathS/include/NFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include <NMathObject.h>
33
/*
4-
NFunction.h 中,定义了常用的NFunction. 称作标准NFunction库.
4+
NFunction.h 中,定义了常用的NFunction. 称作标准NFunction库.
55
*/
66

77
namespace mathS
@@ -11,9 +11,9 @@ namespace mathS
1111
using NParamsList = std::vector<Ptr<NMathObject>>;
1212
using NFunction = std::function<Ptr<NMathObject>(const NParamsList&)>;
1313

14-
// NFunction的Error类型.
14+
// NFunction的Error类型.
1515
NFunction NFunctionError(const std::string info);
16-
// NFunction的Atom类型。直接返回值 v 的函数。
16+
// NFunction的Atom类型。直接返回值 v 的函数。
1717
NFunction NFunctionAtom(const NValueType v);
1818

1919

mathS/include/NMathObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace mathS
1818
|=>//NMatrix
1919
|=>//NSparseMatrix
2020
21-
NList 和 NAtom 构成广义表,通过类的继承实现。
22-
与之相对的做法是使用 NNode,但这样的话会浪费一些空间。
21+
NList 和 NAtom 构成广义表,通过类的继承实现。
22+
与之相对的做法是使用 NNode,但这样的话会浪费一些空间。
2323
2424
*/
2525

@@ -72,7 +72,7 @@ namespace mathS
7272
class NList : public NMathObject
7373
{
7474
public:
75-
// 匹配
75+
// 匹配
7676
/*
7777
f(_x)
7878
f(1,2)

mathS/include/Ptr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <memory>
33

44
namespace mathS {
5-
// 使用智能指针,防止内存泄漏
5+
// 使用智能指针,防止内存泄漏
66
template<class T>
77
using Ptr = std::shared_ptr<T>;
88

99
#define New std::make_shared
10-
// 强制内存转换,基类与派生类之间相互转换
10+
// 强制内存转换,基类与派生类之间相互转换
1111
#define Dynamic_cast std::dynamic_pointer_cast
1212
}

mathS/include/Rule.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
#pragma once
22
#include <MathObject.h>
33
#include <map>
4+
#include <list>
45

56
namespace mathS {
67

78
using Rule = std::function<bool(Ptr<MathObject>, Ptr<MathObject>&)>;
89
using Match = std::function<bool(Ptr<MathObject>)>;
910

1011
/// <summary>
11-
/// 对于给定的Pattern,生成一个匹配
12+
/// 对于给定的Pattern,生成一个匹配
1213
/// </summary>
1314
/// <param name="pattern"></param>
1415
/// <returns></returns>
1516
Match MakeMatch(Ptr<MathObject> pattern);
1617
/// <summary>
17-
/// 对于给定的source pattern, target pattern,生成一个匹配-替换规则
18+
/// 对于给定的source pattern, target pattern,生成一个匹配-替换规则
1819
/// </summary>
1920
/// <param name="src_pattern"></param>
2021
/// <param name="tar_pattern"></param>
2122
/// <returns></returns>
2223
Rule MakeRule(Ptr<MathObject> src_pattern, Ptr<MathObject> tar_pattern);
2324

2425
/// <summary>
25-
/// 匹配。对给定的pattern和obj的形式,并返回匹配表
26+
/// 匹配。对给定的pattern和obj的形式,并返回匹配表
2627
/// </summary>
2728
/// <param name="pattern"></param>
2829
/// <param name="obj"></param>
@@ -31,23 +32,23 @@ namespace mathS {
3132
bool DoMatch(Ptr<MathObject> pattern, Ptr<MathObject> obj, std::map<std::string, Ptr<MathObject>>& table, std::list<std::string>& table_list);
3233

3334
/// <summary>
34-
/// 替换。对于给定的table,返回将pattern中对应地替换的结果(是拷贝,不影响pattern)
35+
/// 替换。对于给定的table,返回将pattern中对应地替换的结果(是拷贝,不影响pattern)
3536
/// </summary>
3637
/// <param name="pattern"></param>
3738
/// <param name="table"></param>
3839
/// <returns></returns>
3940
Ptr<MathObject> DoReplace(Ptr<MathObject> pattern, std::map<std::string, Ptr<MathObject>>& table);
4041

4142
/// <summary>
42-
/// 全匹配,当两个两个表达式完全相同返回true。(为什么不比较GetString()?因为GetString()一定会遍历整个表达式,效率很低。)
43+
/// 全匹配,当两个两个表达式完全相同返回true。(为什么不比较GetString()?因为GetString()一定会遍历整个表达式,效率很低。)
4344
/// </summary>
4445
/// <param name="a"></param>
4546
/// <param name="b"></param>
4647
/// <returns></returns>
4748
bool FullCompare(Ptr<MathObject> a, Ptr<MathObject> b);
4849

4950

50-
// 规则库,在这里可以写包括直接生成的规则,或是必须要程序进行的规则
51+
// 规则库,在这里可以写包括直接生成的规则,或是必须要程序进行的规则
5152
namespace RuleLib {
5253

5354

mathS/src/Compute.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using namespace mathS;
44

55
Ptr<MathObject> mathS::Compute(const Ptr<Item>& input)
66
{
7-
// ÏÈ¿½±´Ò»·Ý
7+
// 先拷贝一份
88
Ptr<Item> rst = Dynamic_cast<Item>(input->DeepCopy());
9+
return Ptr<MathObject>();
910
}

0 commit comments

Comments
 (0)