您好我想知道是否有任何已知的方式来摆脱在数学公式不必要的括号。我问这个问题的原因是,我要尽量减少这种配方长度
Hi I was wondering if there is any known way to get rid of unnecessary parentheses in mathematical formula. The reason I am asking this question is that I have to minimize such formula length
if((-if(([V].[6432])=0;0;(([V].[6432])-([V].[6445]))*(((([V].[6443]))/1000*([V].[6448])
+(([V].[6443]))*([V].[6449])+([V].[6450]))*(1-([V].[6446])))))=0;([V].[6428])*
((((([V].[6443]))/1000*([V].[6445])*([V].[6448])+(([V].[6443]))*([V].[6445])*
([V].[6449])+([V].[6445])*([V].[6450])))*(1-([V].[6446])));
这是基本的SQL SELECT语句的一部分。它不能超过255个字符,我不能修改产生的这个公式code(基本上是一个黑盒子;)) 正如你看到很多括号是没用的。不提的事实是:
it is basically part of sql select statement. It cannot surpass 255 characters and I cannot modify the code that produces this formula (basically a black box ;) ) As you see many parentheses are useless. Not mentioning the fact that:
((a) * (b)) + (c) = a * b + c
所以我要保持业务括号,乘法/除法的顺序,加/减。
So I want to keep the order of operations Parenthesis, Multiply/Divide, Add/Subtract.
林在VB的工作,但在任何语言解决方案将被罚款。
Im working in VB, but solution in any language will be fine.
我发现了一个相反的问题(括号内添加到前pression)Question.
I found an opposite problem (add parentheses to a expression) Question.
我真的认为,这可能不重解析来实现。但似乎有些解析器将通过EX pression并将其保存在一个EX pression树unevitable。
I really thought that this could be accomplished without heavy parsing. But it seems that some parser that will go through the expression and save it in a expression tree is unevitable.
推荐答案
您可以剥去最简单的例子:
You could strip the simplest cases:
([V].[6432]) and (([V].[6443]))
变为
v.[6432]
您应该不需要[]周围的表名或别名。
You shouldn't need the [] around the table name or its alias.
您可以进一步缩短,如果你可以别名列:
You could shorten it further if you can alias the columns:
select v.[6432] as a, v.[6443] as b, ....
甚至把所有的表被查询到单个子查询 - 那么你就不需要表preFIX:
Or even put all the tables being queried into a single subquery - then you wouldn't need the table prefix:
if((-if(a=0;0;(a-b)*((c/1000*d
+c*e+f)*(1-g))))=0;h*
(((c/1000*b*d+c*b*
e+b*f))*(1-g));
select [V].[6432] as a, [V].[6445] as b, [V].[6443] as c, [V].[6448] as d,
[V].[6449] as e, [V].[6450] as f,[V].[6446] as g, [V].[6428] as h ...
显然,这一切都有点psedo- code,但它应该帮助你简化了声明全文
Obviously this is all a bit psedo-code, but it should help you simplify the full statement
相关推荐
最新文章