Simplifying given boolean expression - boolean

I've been trying to simplify this boolean expression
'((B'+C(A+D))(A'+B(C+D))(D'+B))
(the first negation is over the whole expression)
I'm getting BC'+A'D'B+AB'+AC'D'+DB' but the answer does not have the term AC'D'. Is there a way I can remove this term using absorption law or something ?
Thank you

Both expressions are equivalent.
Expression 1 : B&!C + A&!B + !A&B&!D + !B&D
Expression 2 : B&!C + A&!B + !A&B&!D + !B&D + A&!C&!D
A&!C&!D is true when and only when A=1, C=0 and D=0
If we inject these conditions in expression 1, we have
B&1 + 1&!B + 0&B&1 + !B&0 = B+!B =1 for all B
Hence when A&!C&!D=1 the rest of the expression is also asserted and A&!C&!D
is redundant and can be suppressed.
It can be also proofed by algebraic methods, but is is longer.
We use the consensus theorem that states that x&y+!x&z=x&y+!x&z+y&z
Applying the theorem on expression 1 we get
B&!C + A&!B == B&!C + A&!B + A&!C
== B&!C + A&!B + A&!C&D + A&!C&!D
B&!C + !B&D == B&!C + !B&D + !C&D
If we inject these redundant extra terms in expression 1 (between parenthesis for readbility)
(B&!C + A&!B + !A&B&!D + !B&D) + A&!C&D + A&!C&!D + !C&D
= (B&!C + A&!B + !A&B&!D + !B&D) + A&!C&!D + (A&!C&D + !C&D)
= (B&!C + A&!B + !A&B&!D + !B&D) + A&!C&!D + !C&D
But as B&!C + !B&D + !C&D = B&!C + !B&D thanks to the consensus theorem
We can suppress !C&D and we find that
B&!C + A&!B + !A&B&!D + !B&D = B&!C + A&!B + !A&B&!D + !B&D + A&!C&!D
qed

For such questions, Karnaugh maps come in handy:
By visual inspection, it becomes clear that AB'C' is fully covered by AB'.
A nice online map generator is provided by the University of Marburg (Prof. Dr. Thorsten Thormählen).

Related

Find fit with custom equation in Matlab

I'm trying to find a fit with a custom equation, but I keep getting errors and don't know why. The custom equation is really big. I'm using what I found here.
This is the code (sorry about the length of the custom equation):
myfittype = fittype('a + (b*2*y) + (c*2*x+dsqrt(6)(2*xy)) + (esqrt(3)*(2*x^2+2*y^2-1)) + (fsqrt(6)(x^2-y^2)) + (gsqrt(8)(3*x^2*y-y^3)) + (hsqrt(8)(3*x^2*y+3*y^3-2*y)) + (ipsqrt(8)(x^3+3*x*y^2-2*x)) + (jpsqrt(8)(x^3-3*xy^2)) + (ksqrt(10)*(4*x^3*y-4*xy^3)+lsqrt(10)*(8*x^3*y+8*x*y^3-6*xy)) + (msqrt(5)*(6*x^4+12*x^2*y^2+6*y^4-6*x^2-6*y^2+1)) + (nsqrt(10)(4*x^4+4*x^2*y^2-3*x^2-4*x^2*y^2-4*y^4+3*y^2)) + (osqrt(10)(x^4-6*x^2*y^2+y^4)) + (psqrt(12)(5*x^4*y-10*x^2*y^3+y^5)) + (qsqrt(12)(15*x^4*y-12*x^2*y-5*y^5+4*y^3+10*x^2*y^3)) + (rsqrt(12)(10*x^4*y+20*x^2*y^3+10*y^5-12*x^2*y-12*y^3+3*y)) + (ssqrt(12)(10*x^5+20*x^3*y^2+10*x*y^4-12*x^3-12*x*y^2+3*x)) + (tsqrt(12)(5*x^5-10*x^3*y^2-4*x^3-15*x*y^4+12*xy^2)) + (usqrt(12)*(x^5-10*x^3*y^2+5*x*y^4))',... 'independent',{'x'},'dependent',{'y'},...
'coefficients',{'a','b','c','d','e','f','g','h','ip','jp','k','l','m','n','o','p','q','r','s','t','u'})
Here is the code formatted with line breaks (...) so that you can read it:
myfittype = fittype('a + (b*2*y) + (c*2*x+d*sqrt(6)*(2*x*y)) + ...
(e*sqrt(3)*(2*x^2+2*y^2-1)) + (f*sqrt(6)*(x^2-y^2)) + ...
(g*sqrt(8)*(3*x^2*y-y^3)) + (h*sqrt(8)*(3*x^2*y+3*y^3-2*y)) + ...
(ip*sqrt(8)*(x^3+3*x*y^2-2*x)) + (jp*sqrt(8)*(x^3-3*x*y^2)) + ...
(k*sqrt(10)*(4*x^3*y-4*x*y^3)+l*sqrt(10)*(8*x^3*y+8*x*y^3-6*x*y)) + ...
(m*sqrt(5)*(6*x^4+12*x^2*y^2+6*y^4-6*x^2-6*y^2+1)) + ...
(n*sqrt(10)*(4*x^4+4*x^2*y^2-3*x^2-4*x^2*y^2-4*y^4+3*y^2)) + ...
(o*sqrt(10)*(x^4-6*x^2*y^2+y^4)) + (p*sqrt(12)*(5*x^4*y-10*x^2*y^3+y^5)) + ...
(q*sqrt(12)*(15*x^4*y-12*x^2*y-5*y^5+4*y^3+10*x^2*y^3)) + ...
(r*sqrt(12)*(10*x^4*y+20*x^2*y^3+10*y^5-12*x^2*y-12*y^3+3*y)) + ...
(s*sqrt(12)*(10*x^5+20*x^3*y^2+10*x*y^4-12*x^3-12*x*y^2+3*x)) + ...
(t*sqrt(12)*(5*x^5-10*x^3*y^2-4*x^3-15*x*y^4+12*x*y^2)) + ...
(u*sqrt(12)*(x^5-10*x^3*y^2+5*x*y^4))', ...
'independent',{'x'},'dependent',{'y'}, ...
'coefficients', ...
{'a','b','c','d','e','f','g','h','ip','jp','k','l','m','n','o','p','q','r','s','t','u'})
The error says this expression is not a valid matlab expression
Hope you can help me, thanks.
I run your code :
The problem of your code is that
Coefficient d does not appear in the equation expression.

Project taking too long to build and run after adding complex query

I have integrated SQLite.swift framework in one of my swift project and everything was working fine until i added the below query. After adding the below query project is taking too long to build. I waited for 30 mins but still project is n't complied.
do
{
let stmt = try DB!.prepare ("SELECT e." + ENDPOINT_ID + " as _id, lk." + HUB_ID + ", e." + X_ENDPOINT_ID + ", e." + ENDPOINT_DESC + ", e." + ENDPOINT_TYPE_ID +", et." + ENDPOINT_STATUS_MIN + ", et." + ENDPOINT_STATUS_MAX + ", e." + ENDPOINT_STATUS + " FROM " + TABLE_ENDPOINT + " as e INNER JOIN " + TABLE_ENDPOINT_TYPE + " as et " +
" ON e." + ENDPOINT_TYPE_ID + " = et." + ENDPOINT_TYPE_ID +
" INNER JOIN " + TABLE_LINKING + " as lk " +
" ON e." + ENDPOINT_ID + " = lk." + ENDPOINT_ID +
" INNER JOIN " + TABLE_NODE + " as n " +
" ON lk." + NODE_ID + " = n." + NODE_ID +
" INNER JOIN " + TABLE_NODE_TYPE + " as nt " +
" ON n." + NODE_TYPE_ID + " = nt." + NODE_TYPE_ID +
" WHERE lk." + SECTION_ID + "=" + section_Id +
" AND nt." + NODE_CATEGORY + " = "S" " +
" ORDER BY e." + ENDPOINT_ID + " ASC")
let arr = Array(try stmt.run)
print("\(arr)")
return arr
} catch {
print("failed: \(error)")
return []
}
If i comment the above code and try to run the project it takes hardly a minute to run the project but after adding this code, it's taking hell lot of time. I have waited for almost 30 mins but still the project is not compiled nor it's throwing any error.
Thanks in advance for help
The Swift compiler has difficulties to deal with big string literals. See also this question for further hints.
I would recommend to split up the sql and to build a string variable in small steps:
var sql = "SELECT e." + ENDPOINT_ID
sql = sql + HUB_ID + ", e."
sql = sql + X_ENDPOINT_ID + ", e."
...
let stmt = try DB!.prepare(sql)
let query = (TABLE_ENDPOINT.select(TABLE_ENDPOINT[ENDPOINT_ID], TABLE_LINKING[HUB_ID], TABLE_ENDPOINT[ETCT_ENDPOINT_ID], TABLE_ENDPOINT[ENDPOINT_DESC], TABLE_ENDPOINT[ENDPOINT_TYPE_ID], TABLE_ENDPOINT_TYPE[ENDPOINT_STATUS_MIN], TABLE_ENDPOINT_TYPE[ENDPOINT_STATUS_MAX], TABLE_ENDPOINT[ENDPOINT_STATUS]).join(TABLE_ENDPOINT_TYPE, on: TABLE_ENDPOINT[ENDPOINT_TYPE_ID] == TABLE_ENDPOINT_TYPE[ENDPOINT_TYPE_ID]).join(TABLE_LINKING, on: TABLE_ENDPOINT[ENDPOINT_ID] == TABLE_LINKING[ENDPOINT_ID]).join(TABLE_NODE, on: TABLE_LINKING[NODE_ID] == TABLE_NODE[NODE_ID]).join(TABLE_NODE_TYPE, on: TABLE_NODE[NODE_TYPE_ID] == TABLE_NODE_TYPE[NODE_TYPE_ID])
.filter(TABLE_LINKING[SECTION_ID] == section_Id && TABLE_NODE_TYPE[NODE_CATEGORY] == "S")
.order(TABLE_ENDPOINT[ENDPOINT_ID].asc))
let arr = Array(try DB!.prepare(query))

Enforcing a rule in a symbolic expression in Matlab

I have already asked the same question in the Matlab user community.
I have the following symbolic expression:
(3*s11)/2 + (3*s12)/2 + (3*s13)/2 + (3*s14)/2 + (3*s15)/2 + (s11*s12)/2 + (s11*s13)/2 + (s11*s14)/2 + (s12*s13)/2 + (s11*s15)/2 + (s12*s14)/2 + (s12*s15)/2 + (s13*s14)/2 + (s13*s15)/2 + (s14*s15)/2 + s11^2/4 + s12^2/4 + s13^2/4 + s14^2/4 + s15^2/4 + 9/4
It is stored as a symbolic expression variable. I would like to enforce the rule sij^2 = 1 i.e. the variables can be either -1 or +1. If I enforce the rule in the expression mentioned above, the expression will be as follows.
(3*s11)/2 + (3*s12)/2 + (3*s13)/2 + (3*s14)/2 + (3*s15)/2 + (s11*s12)/2 + (s11*s13)/2 + (s11*s14)/2 + (s12*s13)/2 + (s11*s15)/2 + (s12*s14)/2 + (s12*s15)/2 + (s13*s14)/2 + (s13*s15)/2 + (s14*s15)/2 + 1/4 + 1/4 + 1/4 + 1/4 + 1/4 + 9/4
How can I do this in Matlab?
Set assumptions e.g. assume(s14^2==1), then use simplify.

Simplifying Boolean Expression (A'BC) + (A'B'C) + (A'BC) + (AB'C)

please help me with simplifying this one. I am a bit new to these..
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
the book i use shows and answer, which is,
Answer = A'B + B'C
I tried simplifying, but I get stucked with two eXors, my simplification so far goes like this...
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
A (BC' + B'C) + C (A'B + AB')
This doesn't seem to be a write way, Please someone help me simplify this, and please show step by step, as I am sort of new..
Also I don't get how to simplify eXor further..
You have the Rule X' + X = True. SO
(A'BC') + (A'B'C) + (A'BC) + (AB'C) =
(A'BC') + (A'BC) + (A'B'C) + (AB'C) = // just permuting the terms
A'B(C' + C) + (A' + A)B'C = // factoring
A'B + B'C
I'll assume that multiplcation is AND, addition is OR and prime is negation.
Here's what I'd do:
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
A'B(C'+C) + B'C(A'+A)
(C'+C) = 1 and (A'+A) = 1
A'B + B'C
Q.E.D.
for simplifying boolean expressions use karnaugh maps. i think it is very much useful if we less number of variables. but if we have more variables then we can follow methods because this method is not that preferable.
(A'BC') + (A'B'C) + (A'BC) + (AB'C)
answer just arrange the terms like this
step 1:A'BC'+A'BC+AB'C+A'B'C
now get common terms out
step 2 : A'B(C'+C)+B'C(A+A')
step 3 : A'B.1+B'C.1
step 4 : A'B+B'C

jQuery UI DatePicker date convert to RFC 3339 format

Currently working on the Google Calendar API and basically my end will provide Start and End date for user to pick the date and time. But would like anyone to advise how to convert them from (DatePicker/TimePicker/input field) to RFC 3339 format (e.g. 2013-07-24T10:00:00.000-07:00).
var date = new Date();
var timeZone = date.getTimezoneOffset();
alert(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + "T" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "." + date.getMilliseconds() + (timeZone > 0 ? "-" : "+") + Math.floor(Math.abs(timeZone) / 60) + ":" + Math.abs(timeZone) % 60);