I may need your help with this quite simple thing:
This -> abc' + ab'c + a'bc + abc
can (I guess) be simplified to this -> ab+ac+bc.
But how in the world is this done with Boolean algebra?
I already reduced it to -> abc'+ab'c+bc by using the absorption rule on the last two terms [a'bc + abc]. But how can I reduce the rest of it to get the end result?
Before simplifying the expression I'll show you one nice trick that will be used later. For any two logical variables A and B the following holds:
A + AB = A(B + 1) = A
With this in mind let's simplify your expression:
abc' + ab'c + a'bc + abc = ac(b + b') + abc' + a'bc = ac + abc' + a'bc
We can expand ac in the following way using that 'trick' I mentioned before:
ac = ac + abc = ac(b + 1) = ac
Using this we get:
ac + abc' + a'bc =
ac + abc + abc' + a'bc =
ac + ab(c + c') + a'bc =
ac + ab + a'bc =
ac + ab + abc + a'bc =
ab + bc(a + a') + ac =
ab + ac + bc
Leading to the final expression you wanted to get in the first place.
Related
Is it possible to write the following code in VBA Excel 2016 more briefly?
Select Case NemberOfProduct(i)
Case 1
CounterPlot(1) = CounterPlot(1) + 1
SumPureRate(1) = SumPureRate(1) + H(i)
Case 2
CounterPlot(2) = CounterPlot(2) + 1
SumPureRate(2) = SumPureRate(2) + H(i)
Case 3
CounterPlot(3) = CounterPlot(3) + 1
SumPureRate(3) = SumPureRate(3) + H(i)
.
.
Case 12
CounterPlot(12) = CounterPlot(12) + 1
SumPureRate(12) = SumPureRate(12) + H(i)
End Select
You could either manualy use NemberOfProduct(i) expresion as value.
So your whole select case could be replaced with
CounterPlot(NemberOfProduct(i)) = CounterPlot(NemberOfProduct(i)) + 1
SumPureRate(NemberOfProduct(i)) = SumPureRate(NemberOfProduct(i)) + H(i)
Or even more simplify it by storing NemberOfProduct(i) inside variable and then use it.
Dim n as Integer
n = NemberOfProduct(i)
CounterPlot(n) = CounterPlot(n) + 1
SumPureRate(n) = SumPureRate(n) + H(i)
I'm having problems in this SQL server code, even using the ISNULL or COALESCE functions it keeps returning NULL, could someone tell me how to solve it?
CASE WHEN TIPO_X = 'F'
AND TIPO_CALCULOX IN ('N','S','D')
AND TRPR_COD_X IN (7,13,15,17) THEN CASE WHEN EVEN_COD_X IN (623,70623,947,70947,1871,71871,2697,72697,2871,72871,30623,30947,31871,22697,22871,20623,20947,21871) THEN CONVERT(int, (SELECT SUM(VLR_X)
FROM GMS_RELATORIO_GERAL
WHERE CHAPA_X = MATRÍCULA_DO_SEGURADO
AND EVEN_COD_X IN (623 + 7062 + 947 + 70947 + 1871 + 71871 + 2697 + 72697 + 2871 + 72871 + 30623 + 30947 + 31871)
AND MONTH(DT_COMP_X) = #MES)) - CONVERT(int,(SELECT SUM(VLR_X)
FROM GMS_RELATORIO_GERAL
WHERE CHAPA_X = MATRÍCULA_DO_SEGURADO
AND EVEN_COD_X IN (22697 + 22871 + 20623 + 20947 + 21871)
AND MONTH(DT_COMP_X) = #MES))
END
ELSE ''
END AS RENUMERAÇÃO_DA_CONTRIBUIÇÃO
Somehow I doubt this part of the code is as intended:
AND EVEN_COD_X IN (623 + 7062 + 947 + 70947 + 1871 + 71871 + 2697 + 72697 + 2871 + 72871 + 30623 + 30947 + 31871)
It's equivalent to this:
AND EVEN_COD_X IN (397898)
You probably want commas there instead.
Among your three EVEN_COD_X IN clauses, the last two are wrong : values should be separated with a comma (,).
CASE WHEN EVEN_COD_X IN (623 + 7062) -- It should be (623, 7062)
A good practice is :
to simplify your code (use CTE or temporary tables instead of doing everything in one query) ;
to use indentation (mistakes like this will become more visible) ;
for debugging, simplify it even more until it works.
I am novice in analysing time complexity.some one can help me with the time complexity of below algorithm?
public void test(int n)
{
for(int i=1;i<=n;i=i+2)
{
for(int j=1;j<=i;j++)
{}
}
}
outer loop will run n/2 times.Inner loop will run (1+3+5+7+9...n) times.
what will be time complexity of inner loop and how can we calculate sum of such arithmitic progression?
Assume n is odd. Then n = 2k + 1 for some k. Now
1 + 3 + … + n
= 1 + 3 + … + 2k+1
= (1 + 3 + … + 2k + 1) + (1 + 1 + … + 1) - (1 + 1 + … + 1)
= (1 + 1) + (3 + 1) + … + (2k + 1 + 1) - (1 + 1 + … + 1)
= 2 + 4 + … + 2k+2 - (1 + 1 + … + 1)
= 2(1 + 2 + … + k+1) - (1 + 1 + … + 1)
= 2(k+1)(k+2)/2 - (k+1)
= k^2 + 3k + 2 - k - 1
= k^2 + 2k + 1
= (k+1)^2
= (n+1)^2/4
We can test a few terms...
n f(n) Series Sum
1 1 1 = 1
3 4 1 + 3 = 4
5 9 1 + 3 + 5 = 9
7 16 1 + 4 + 5 + 7 = 16
Looks like it checks out.
Can someone help me convert grammar to regular expression and explain how to do it on some complex grammars?
S -> aA | bB
A -> aC | bC | a | b
B -> aC | bC | a | b
C -> aA
This grammar of yours:
S -> aA | bB
A -> aC | bC | a | b
B -> aC | bC | a | b
C -> aA
Happens to be a right-regular grammar. As such, it describes a regular language and can easily be converted to a deterministic finite automaton:
q s q'
S a A
S b B
A a (C)
A b (C)
B a (C)
B b (C)
(C) a A
(C) b [D]
[D] a [D]
[D] b [D]
Here, S is the initial state, C is accepting and D is dead. To get a regular expression, treat this automaton as a NFA and start replacing symbol labels with regular expressions eliminating states:
S = aA + bB
A = aC + bC + a + b
B = aC + bC + a + b
C = aA + bD
D = aD + bD
Notice that D = aD + bD = (a + b)D is only true if D = {}. Rewriting:
S = aA + bB
A = aC + bC + a + b
B = aC + bC + a + b
C = aA
Now we can safely eliminate C by substitution:
S = aA + bB
A = aaA + baA + a + b = (aa + ba)A + (a + b)
B = aaA + baA + a + b = (aa + ba)A + (a + b)
Now we can use the rule Z = xZ + y => Z = x*y:
S = aA + bB
A = (aa + ba)*(a + b)
B = aaA + baA + a + b = (aa + ba)A + (a + b)
Now substitute:
S = aA + bB
A = (aa + ba)*(a + b)
B = (aa + ba)(aa + ba)*(a + b) + (a + b)
Now again:
S = a(aa + ba)*(a + b) + b((aa + ba)(aa + ba)*(a + b) + (a + b))
Now we can group like terms:
S = (a(aa + bb)* + b(aa + ba)(aa + ba)* + b)(a + b)
Notice that b(aa + ba)(aa + ba)* + b can be factored b((aa + ba)(aa + ba)* + e) and that (aa + ba)(aa + ba)* + e = (aa + ba)*:
S = (a(aa + bb)* + b(aa + ba)*)(a + b)
We can factor again:
S = (a + b)(aa + ba)*(a + b)
This last expression is a good, concise, correct regular expression for your language. It basically encodes the idea "see one symbol, then see another symbol, but if you see a third symbol it had better not be a b".
I want to update with sum full datatable data row wise but how?
See what want I do:
This code only for shown sum data with row-wise but its not working with NULL value.
select
sum(tc6671 + tf6671 + pc6671 + pf6671 + tc8572 + tf8572 + pc8572 + pf8572 +
tc6672 + tf6672 + tc6673 + tf6673 + pc6673 + pf6673 + pc6674 + pf6674 + tc5852 + tf5852 +
tc5853 + tf5853) as Test
from
cmt_7th;
But I want to update my specific column with all sum data.
I was tried this code but failed:
update cmt_7th
set roll = sum(tc6671+tf6671+pc6671+pf6671+tc8572+tf8572+pc8572+pf8572+
tc6672+tf6672+tc6673+tf6673+pc6673+pf6673+
pc6674+pf6674+tc5852+tf5852+tc5853+tf5853);
And I was tried also by this code:
UPDATE c
SET c.total = c.tc6671+c.tf6671+c.pc6671+c.pf6671+c.tc8572+c.tf8572+c.pc8572+
c.pf8572+c.tc6672+c.tf6672+c.tc6673+c.tf6673+c.pc6673+c.pf6673+
c.pc6674+c.pf6674+c.tc5852+c.tf5852+c.tc5853+c.tf5853
FROM cmt_7th c
Instead of tc6671+tf6671, use coalesce to handle nulls.
Like coalesce(tc6671,0)+coalesce(tf6671,0)+...
So your update statement will be something like
UPDATE c
SET c.total = coalesce(c.tc6671,0) + coalesce(c.tf6671,0) + coalesce(c.pc6671,0)
+ coalesce(c.pf6671,0) + coalesce(c.tc8572,0) + coalesce(c.tf8572,0)
+ coalesce(c.pc8572,0) + coalesce(c.pf8572,0) + coalesce(c.tc6672,0)
+ coalesce(c.tf6672,0) + coalesce(c.tc6673,0) + coalesce(c.tf6673,0)
+ coalesce(c.pc6673,0) + coalesce(c.pf6673,0) + coalesce(c.pc6674,0)
+ coalesce(c.pf6674,0) + coalesce(c.tc5852,0) + coalesce(c.tf5852,0)
+ coalesce(c.tc5853,0) + coalesce(c.tf5853,0)
FROM cmt_7th c
But if you use select sum(coalesce(c.tc6671,0) ... then you will get only 1 row and column with sum of sum of all columns.
See what I mean here
http://rextester.com/LUIPOW59089