如何摆脱数学表达式中的不必要的括号 [英] How to get rid of unnecessary parentheses in mathematical expression
问题描述
if(( - if((V) [6432])= 0; 0;(([V] [6432]) - ([V] [6445])。)*(((([V] [6443]))/ 1000 *([ V]。
/ pre>
+(([V]。[6443]))*([V]。[6449])+([V]。[6450]))*(1 - ([ (V(V)])))= 0;([V])*
(((((V [... 64]))/ 1000 *([V] [6445])*([V]。[6448])+(([V]。[6443]))*([V] [6445])*
([V] +([V]。[6445])*([V]。[6450])))*(1 - ([V] [6446])));
它基本上是sql select语句的一部分,不能超过255个字符,我不能修改生成此公式的代码(基本上是一个黑盒子))
如你所见,许多括号是无用的。没有提到这个事实:((a)*(b))+(c)= a * b + c
所以我想保留操作顺序括号,乘/除,加/减。 >
我在VB工作,但任何语言的解决方案都会很好。
编辑
我发现了一个相反的问题(向表达式添加括号)问题。
我真的以为这可以在没有大量解析的情况下实现。但是似乎一些解析器将会通过表达式并将其保存在表达式树中是不可避免的。
解决方案最简单的情况:
([V]。[6432])和(([V]。[6443]))
成为
诉[6432]
您不应该在表名或其别名周围需要[]。
如果您可以将列别名,可以进一步缩短:
select v。[ 6432]作为,v。[6443]作为b,....
甚至将查询的所有表都放入一个子查询中 - 您不需要表前缀:
if(( - if(a = 0; 0;(ab)* ((c / 1000 * d
+ c * e + f)*(1-g))))= 0; h *
(((c / 1000 * b * d + c *作为a,[V] [6445],将[V]。[6445]选择为[V]。[6445]作为b,[V [6443]如c,[V] [6448]如d,
[V]。[6449]如e,[V] [6450]如f,[V] [6446] g,[V]。[6428] as h ...
显然这是一个psedo -code,但它应该可以帮助您简化完整语句
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])));
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.
Im working in VB, but solution in any language will be fine.
Edit
I found an opposite problem (add parentheses to a expression) Question.
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]))
Becomes
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, ....
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 ...
Obviously this is all a bit psedo-code, but it should help you simplify the full statement
这篇关于如何摆脱数学表达式中的不必要的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!