标志符号代数EX pression代数、符号、标志、pression

2023-09-11 00:09:01 作者:★`關于今昔

有没有什么算法,可以找到一个任意符号代数EX pression在树 - 表所设的预兆?

Is there any algorithm that can find the sign of an arbitrary symbolic algebraic expression given in a "Tree - Form"?

我知道,一般的算法不存在,因为零recognizion问题是不可判定对于任意前pression,但是我应该如何处理发现的前pression标志的问题? (这是怎么在计算机代数做了什么?)

I know that a general algorithm doesn't exist because the zero recognizion problem is undecidable for an arbitrary expression, but how should I approach the problem of finding the sign of an expression? (how is this done in computer algebra?)

例如:号(的sqrt(2)-1)=

推荐答案

评估函数值

在需要的功能评估引擎的(它不是很难code)... 有没办法,以评估只签署如果你想为支持+, - 操作! need function evaluator engine for that (it is not that hard to code) ... there is no way to evaluate sign only if you want to support +,- operations !!!

我所有的功能评估的工作原理是这样的:

All my function evaluators works like this:

编译功能的源文本

compile the source text of the function 创建支持的功能表(ID,操作数NUM,名称,函数指针) +, - ,*,/,正弦,余弦,... 请不要忘了code在code太所有功能 在单独的括号'(',')'的任何功能,也推功能,流行 +, - 与1和2的操作数(两个不同的功能各自!!!) create supported functions table (id,num of operands,name,pointer to function) +,-,*,/,sin,cos,.... do not forget to code all functions in your code too separate brackets '(',')' from any function are also functions push,pop +,- are with 1 and 2 operands (two different functions each !!!)

例如:

sign(sqrt(2)-1)

类型:

types:

id type
0  function
1  number
2  constant
3  variable

功能:

关系代数的自然连接符号 2 2 关系代数

functions:

id name   pointer
0  '('    ???
1  ')'    ???
2  '+'    ???
3  '-'    ???
4  '*'    ???
5  '/'    ???
6  'sqrt' ???
7  'sign' ???

不变量

no variables

编号:

id value
0  2  
1  1

编译字符串:

compiled string:

type id
0    7   // sign(1 operand)
0    6   // sqrt(1 operand)
1    0   // 2
0    3   // - (2 operands)
1    1   // 1

编译之后,您需要跨preT字符串,并评估它的价值。

After compilation you need to interpret the string and evaluate it's value.

初始化变量

init variables OP1 = 0,OP2 = 0,...设置为零的所有操作数(数量取决于支持的功能通常为2) 在OPN = 0 ...实际操作数号 在FX =无...实际功能(例如无= -1) FXN = 0 ...实际功能的操作数号

读取第一个字符串记录

如果是值(数字,常量,变量)相应的运算?价值有了它,​​OPN ++ 如果它的功能设置FX,FXN code与它

如果OPN == FXN

if opn == fxn

执行功能FX OP1 = fxtab [FX] .pointer(OP1,OP2,...) 设置FX =无,FXN = 1 设置OPN = 1(部分规格功能可以返回更多的操作数,然后设置OP1,OP2,... OPN = ...)

如果不能结束的字符串转到2,但与下一个字符串记录

if not end of string goto 2 but with next string record

在年底OP1应该握住你的产值

at the end op1 should hold your output value

一些示例功能:

double sign(double op1) 
 { 
 if (op1>0.0) return +1.0; 
 if (op1<0.0) return -1.0; 
 return 0.0; 
 }
double sqrt1(double op1) { return sqrt(op1); }
double plus1(double op1) { return op1; }
double minus1(double op1) { return -op1; }
double plus2(double op1,double op2) { return op1+op2; }
double minus2(double op1,double op2) { return op1-op2; }

注:

您必须处理特殊情况之类的函数=; 提防间隔,区分大小写 在编译的任何错误的结果无效 的速度是不是一个大问题,这是除preting评价不数值解 在所有的操作都​​称为相同倍,你会做的纸 您也应该处理数学错误(溢出,无效的操作数,NaN的...) 在我通常组功能与操作数相同数量的自己的类型,以简化的东西 you have to handle special cases like function = ""; beware spacing, case sensitivity any error in compilation invalidates the result speed is not a big issue this is interpreting-evaluation not numerical solution all operations are called the same times as you would do on the paper you should also handle mathematic errors (overflows,invalid operands,NaNs ...) I usually group functions with the same number of operands to own type to simplify things