0
$\begingroup$

one example:

How many ways we can do possible value-preserving parenthesis the following expression in such a way that value not changed after parenthesis with one constraint that parenthesis among one variable is not correct (i.e: $(i)+j+k$ is not acceptable) ?

as an example for expression $i+j+k$, parenthesis like $i+(j+k)$, $((i+j)+k)$ are correct parenthesis but $(i)+j+k$ is not. I take a complete short example as follows.

$\endgroup$
12
  • 2
    $\begingroup$ I think your definition of "correct parenthesis" needs to be made more precise. Why, for example, is $(i)$ excluded and not $((i+j))$? Also, are $i+j+k$ and $(i+j)+k$ different, even though the second one just shows the consequence of the conventional rules for parsing? Similarly, do the redundant outer parentheses in $((i+j)+k)$ really create a different expression than $(i+j)+k$? $\endgroup$ – rici Dec 27 '20 at 17:06
  • $\begingroup$ $i+j-k$ has only two complete parenthesizations, corresponding to the two possible parse trees. The number of evaluations of an unparenthedized binary expression with $k$ operators, or equivalently the number of balanced parenthesis strings with $k$ pairs of parentheses, is given by $C_k$, the $k_{th}$ Catalan number. (The linked wikipedia article has lots of info and useful links). Your (rather unclear) definition double-counts, so its less combinatorically useful. $\endgroup$ – rici Dec 27 '20 at 20:15
  • $\begingroup$ And your statement that "each operator can have parentheses or not" undercounts the possible arrangements, since parentheses do not have a single possible location for an operator. The Catalan numbers griw more rapidly than powers of two; $C_5 = 42$ and $C_6 = 132$. $\endgroup$ – rici Dec 27 '20 at 20:18
  • 1
    $\begingroup$ You still don't define "correct parentheses". Also this is disorganized. Also it's not clear what question you are trying to ask. PS Please clarify via edits, not comments. Please delete & flag unneeded comments. $\endgroup$ – philipxy Dec 28 '20 at 1:42
  • 1
    $\begingroup$ Do not edit your question to remove its content. That is considered "vandalism" on Stack Exchange. $\endgroup$ – D.W. Jan 24 at 16:32
1
$\begingroup$
  1. What's wrong with (i) + j + k ?

  2. I live in a world where floating-point arithmetic has rounding errors, and where integer arithmetic has overflow checks, so (i + j) + k and i + (j + k) are most definitely not the same, for example if i is a large positive integer, and j, k are two large negative integers then the second one can produce an overflow (crash) while the first one doesn't.

$\endgroup$
3
  • $\begingroup$ @EmmaNic., if this does not meet your requirements, please edit your question to make it clearer what you are asking and state your requirements clearly, so that others don't have a similar reaction. $\endgroup$ – D.W. Dec 28 '20 at 19:32
  • 2
    $\begingroup$ Emma Nic: Very, very rude. I have not the slightest intent to remove my answer. $\endgroup$ – gnasher729 Jan 24 at 12:38
  • $\begingroup$ You think me telling you that (a + b) + c and a + (b + c) usually don't give the same result is "a strange answer"? That's how it is. $\endgroup$ – gnasher729 Jan 29 at 22:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.