Boolean Algebra expression with nots - boolean

So at the end of my truth table I got:
NOT NOT ABC.NOT ABD
________
___ ___
ABC.ABD
Does this simplify into ABC+ABD? Also what laws would I use?

For a start I don't like the way they teach binary simplification. To make things much easier for yourself take these rules instead of the ones they taught you:
A AND B = AB
A AND A = A
A OR B = A + B - AB
NOT A = 1 - A
You can work out xor and etc.. yourself using these.
Now then using these rules:
NOT(NOT(A AND B AND C) AND (NOT (A AND B AND D)))
= 1 - ((1 - ABC)*(1 - ABD))
= 1 - (1 - ABC)(1 - ABD)
= 1 - 1 + ABD + ABC - ABCABD
= ABD + ABC - ABCD
= AB(D + C - CD)
= A AND B AND (C OR D)
which is equivalant to ABC + ABD using your system.
Edit:
First 3 equals (but a bit slower):
NOT(NOT(A AND B AND C) AND (NOT (A AND B AND D)))
->
NOT((NOT(ABC)) AND (NOT (ABD)))
->
1 - ((NOT(ABC))(NOT(ABD)))
->
1 - (1 - ABC)(1 - ABC)
-> expanding the brackets
1 - (1 * 1 - ABC * 1 - ABD * 1 + ABC * ABD)
->
1 - (1 - ABC - ABD + ABCABD)
-> multiple out the bracket
1 - 1 + ABD + ABC - ABCABD
glad I could help ^^

Related

matlab:why am i getting this error?nvalid expression. When calling a function or indexing a variable, use parentheses

Error:Line: 23 Column: 376 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
clc;
Ti=300;
Mi=input('please enter Mi>1 : ');
thetas=input('please enter mach angle<thetas<90 : ');
dtheta=(1/10)*(thetas);
gama=1.4;
Ts=(Ti)*(1+(((gama*2)/(gama+1))*(((Mi)^2)*((sin(thetas))^2)-1))*(((gama+1)*(((Mi)^2)*((sin(thetas))^2)))/(2+((gama-1)*(((Mi)^2)*((sin(thetas))^2))))));
delta=atan(2*cot(thetas)*(((((Mi)^2)*((sin(thetas))^2))-1)/((((Mi)^2)*(gama+cos(thetas)))+2)));
Ms=(((sin(thetas-delta))^2)*((1+((gama-1)/2)*((Mi)^2)*((sin(thetas))^2)))/((gama)*((Mi)^2)*((sin(thetas))^2)-((gama-1)/2)))^(1/2);
vp=0:dtheta:thetas;
vpr=0:dtheta:thetas;
vpt=0:dtheta:thetas;
vp(1,1)=(2/((gama-1)*((Ms)^2)));
vpr(1,1)=vp(1,1)*cos(thetas-delta);
vpt(1,1)=vp(1,1)*sin(thetas-delta);
vpr(1,2)=(vpt(1,1)*dtheta)+vpr(1,1);
M=0:dtheta:thetas;
i=2;
while vpt(1,i)>0.001
i=i+1;
eq = (((gama-1)/2)*(1-(vpr(1,i)^2)-(((vpr(1,i)-vpr(1,i-1))/(dtheta))^2))*((2*vpr(1,i))+(((vpr(1,i)-vpr(1,i-1))/(dtheta))*cot(thetas+(i-2)*dtheta))+((vpr(1,i)-(2*vpr(1,i-1))+vpr(1,i-2))/((dtheta)^2))))-(((vpr(1,i)-vpr(1,i-1))/(dtheta))*(((vpr(1,i))*((vpr(1,i)-vpr(1,i-1))/(dtheta)))+(((vpr(1,i)-vpr(1,i-1))/(dtheta))*((vpr(1,i)-(2*vpr(1,i-1))+vpr(1,i-2))/((dtheta)^2)))== 0;
M(1,i-2)=solve(eq , vpr(1,i));
vpt(1,i)=((vpr(1,i)-vpr(1,i-1))/(dtheta));
end
If you have such long equations it's better to divide a few parts in variables. I have no idea, what you want to calculate but it's better to leave a space at least between each operand. If your line becomes too long just do a line break with three dots .... I'm also sure, you can eliminate a few unnecessary brackets. Your code works if you just add 2 closing brackets before == 0
eq = (((gama - 1)/2) * (1 - (vpr(1,i) ^ 2) - ...
(((vpr(1,i) - vpr(1,i - 1))/(dtheta)) ^ 2)) * ...
((2 * vpr(1,i)) + (((vpr(1,i) - vpr(1,i - 1)) / ...
(dtheta)) * cot(thetas + (i - 2)*dtheta)) + ...
((vpr(1,i) - (2 * vpr(1,i - 1)) + vpr(1,i - 2)) / ...
((dtheta) ^ 2)))) - (((vpr(1,i) - vpr(1,i - 1)) / ...
(dtheta)) * (((vpr(1,i)) * ((vpr(1,i) - vpr(1,i - 1)) / ...
(dtheta))) + (((vpr(1,i) - vpr(1,i - 1))/(dtheta)) * ...
((vpr(1,i) - (2*vpr(1,i - 1)) + vpr(1,i-2)) / ((dtheta)^2))))) == 0;
Still not sure, if your result is correct. At least there's no occuring array about missing parenthesis

Simplifying boolean algebra (XOR)

I know how to convert first and second term to the first term of the simplified expression, but I don't know how to convert the rest.
By simplifying, I can get rid of A_Bar in the third term and A in the fifth term and get =B*C_bar
How is it that B*C_bar + the fourth term = becomes XOR(B,C) ?
The two expressions are clearly the same. This can be easily proven by truth tables.
The first one is:
And the second one:
However, this does not fully answer your question.
B*C_bar + the fourth term = becomes XOR(B,C)
This is clearly true if A is true, since per definitionem, B XOR C = B_bar and C OR B and C_bar.
If A is false, these terms are always false and you cannot simplify these two to B XOR C! They are not equal!
Note: Tables generated with http://web.stanford.edu/class/cs103/tools/truth-table-tool/
Note2: ^= OR, ¬ = NOT, ∨ = AND
let play a game.
Let a=not(A), b=not(B) and c=not(C) and *=xor
Y = ab + (B*C)
Y = ab + Bc + bC
Y = ab(1) + Bc(1) + bC(1)
Y = ab(c+C) + Bc(a+A) + bC(a+A)
Y = abc + abC + Bca + BcA + bCa + bCA
Y = abc + abC + aBc + ABc + abC + AbC
Y = abc + abC + aBc + ABc + AbC
That is the first equ.

Solve constrained equation with 2 variables

EDIT:
I think what I need is to apply fmincon, but I don't know how. I want to do this:
Use fmincon to solve:
Minimize a, subject to the equality constraint
f(q,z) = 0
by varying the unknowns (q,z).
How do I use fmincon to implement this? Thanks!
Here is the entire function:
f(q,z) = 60*q^9*z^4 + 120*q^7*z^3 + 80*q^(17/2)*z^3 - 60*q^8*z^3 - 60*q^6*z^3 + 40*q^(15/2)*z^3 + 20*q^(11/2)*z^3 - 20*q^9*z^3 + 175*q^(13/2)*z^2 - 90*q^(15/2)*z^2 + 75*q^5*z^2 - 60*q^6*z^2 - 45*q^(11/2)*z^2 + 40*q^2*z^2 + 30*q^8*z^2 - 30*q^(3/2)*z^2 - 10*q^(17/2)*z^2 + 15*q^(9/2)*z^2 - 20*q^4*z^2 - 10*q^(7/2)*z^2 - 90*q^(11/2)*z + 86*q^(9/2)*z + 75*q^6*z - 45*q^(7/2)*z + 40*q^(3/2)*z - 30*q^7*z - 20*q^(13/2)*z - 24*q^(1/2)*z + 15*q^4*z + 15*q^3*z - 9*q^(5/2)*z - 9*q^5*z + 45*q^4 - 30*q^5 + 30*q^(1/2) - 29*q^3 + 21*q^(5/2) - 10*q^(9/2) - 9*q^2 - 24.
----- original post -------
I have a function of 2 variables q and z like
f(q,z) = 60*q^9*z^4 + 120*q^7*z^3 + 80*q^(17/2)*z^3 - 60*q^8*z^3 - 60*q^6*z^3 + ...
I need to find
f(q,z) = 0
with respect to z, but this is not possible analytically (resulting in RootOf). So instead of finding all points, I want to numerically find the smallest number z such that the value pair (q,z) fulfills f(q,z) = 0. Any ideas how to do this?
I'm afraid there is no minimum z, as f(q,z) = 0: q↓0 ⇒ z↓-∞.
Your original equation can be written as:
Writing all the terms following like powers of z as A, B, C, D and E, you basically have
This is a quartic equation in z, which can definitely be solved analytically. Granted, it's a bit awkward, but possible nonetheless.
Note that the fact that A = f(q), B = g(q), C = h(q), D = k(q) and E = m(q) does not matter, as your goal is to express z = F(q).
Here's one way to find the minimum z for which f(q,z)=0 holds:
function find_minimum_z
solution = fminsearch(#F, 3)
end
function R = F(q)
R = roots([
60.*q.^9
120.*q.^7 + 80.*q.^(17/2) - 60.*q.^8 - 60.*q.^6 + 40.*q.^(15/2) + 20.*q.^(11/2) - 20.*q.^9
175.*q.^(13/2) - 90.*q.^(15/2) + 75.*q.^5 - 60.*q.^6 - 45.*q.^(11/2) + 40.*q.^2 + 30.*q.^8 - 30.*q.^(3/2) - 10.*q.^(17/2) + 15.*q.^(9/2) - 20.*q.^4 - 10.*q.^(7/2)
-90.*q.^(11/2) + 86.*q.^(9/2) + 75.*q.^6 - 45.*q.^(7/2) + 40.*q.^(3/2) - 30.*q.^7 - 20.*q.^(13/2) - 24.*q.^(1/2) + 15.*q.^4 + 15.*q.^3 - 9.*q.^(5/2) - 9.*q.^5
45.*q.^4 - 30.*q.^5 + 30.*q.^(1/2) - 29.*q.^3 + 21.*q.^(5/2) - 10.*q.^(9/2) - 9.*q.^2 - 24
]);
R = min(R(imag(R)==0));
if isempty(R)
R = NaN; end
end
My trials indicate there is an asymptote at q=0 for which the minimum, real z that solves the quartic tends to -∞.
Indeed this is what you can see when you make a plot of F(q):
If all terms after the first term have a z³, then it's really quite simple:
f(q,z) = 60q⁹z⁴ + 120q⁷z³ + 80q¹⁷/²z³ - 60q⁸z³ - 60q⁶z³ + ...
= z⁴·(60q⁹) + z³·(120q⁷ + 80q¹⁷/² - 60q⁸ - 60q⁶ + ... )
f(q,z) = 0
⇒ z⁴ · (60q⁹) = -z³ · (120q⁷ + 80q¹⁷/² - 60q⁸ - 60q⁶ + ...)
⇒ -z · (60q⁹) = 120q⁷ + 80q¹⁷/² - 60q⁸ - 60q⁶ + ...
⇒ z = -(120q⁷ + 80q¹⁷/² - 60q⁸ - 60q⁶ + ...) / 60q⁹
= -(2q⁷ + 1⅓q¹⁷/² - q⁸ - q⁶ + ...) / q⁹

Coffeescript - Improve algorithm for increasing grouping

The code below works but I am wondering if there is a better way that maybe uses some of the features of coffeescript that I am unfamiliar with.
The problem is this, I need to page items but the paging increases each time.
If I take the number 20 for example, it would create the following pages:
1 - 3
4 - 7
8 - 15
16 - 20
I have the following test and code which does pass:
module 'Remainder',
setup: ->
#remainder = 20
test 'splits remainder incrementally', ->
parts = #remainder.increasingSplit()
equal parts[0], '1 - 3', ''
equal parts[1], '4 - 7', ''
equal parts[2], '8 - 15', ''
equal parts[3], '16 - 20', ''
Number.prototype.increasingSplit = ->
start = 1
nextSplit = 3
parts = []
finished = false
while !finished
if nextSplit > #
parts.push "#{start} - #{#}"
break
parts.push "#{start} - #{nextSplit}"
start = nextSplit + 1
nextSplit = nextSplit * 2 + 1
parts
Without changing the algorithm too much, you can try this:
Number::increasingSplit = ->
start = 1
nextSplit = 3
parts = []
while start <= #
parts.push "#{start} - #{Math.min nextSplit, #}"
start = nextSplit + 1
nextSplit = nextSplit * 2 + 1
parts
The changes were:
replacing .prototype with ::,
removing of the finished variable (which was not being used effectively because the break anyway) and the break altogether and changing the condition to start <= #,
using only one parts.push <part>, with the minimum between nextSplit and # as the top.
Also, i'd advice against extending the Number prototype in this case. Extending the prototype of primitive types can sometimes cause weird problems, like:
Number::isFour = -> # is 4
console.log 4.isFour() # -> false
That happens because inside that function # will be a Number object instead of a primitive number, thus making the === 4 comparison always fail. That would not happen if you define isFour as a standalone function:
isFour = (n) -> n is 4
console.log isFour 4 # -> true
So, i'd prefer this version of incrasingSplit:
increasingSplit = (n) ->
start = 1
nextSplit = 3
parts = []
while start <= n
parts.push "#{start} - #{Math.min nextSplit, n}"
start = nextSplit + 1
nextSplit = nextSplit * 2 + 1
parts
Finally, if you don't mind recursion, you can go with a more FP-style algorithm :)
increasingSplit = (n, start = 1, nextSplit = 3) ->
if start > n
[]
else
part = "#{start} - #{Math.min nextSplit, n}"
rest = increasingSplit n, nextSplit + 1, nextSplit * 2 + 1
[part, rest...]

Crystal Reports Cross-tab with mix of Sum, Percentages and Computed values

Being new to crystal, I am unable to figure out how to compute rows 3 and 4 below.
Rows 1 and 2 are simple percentages of the sum of the data.
Row 3 is a computed value (see below.)
Row 4 is a sum of the data points (NOT a percentage as in row 1 and row 2)
Can someone give me some pointers on how to generate the display as below.
My data:
2010/01/01 A 10
2010/01/01 B 20
2010/01/01 C 30
2010/02/01 A 40
2010/02/01 B 50
2010/02/01 C 60
2010/03/01 A 70
2010/03/01 B 80
2010/03/01 C 90
I want to display
2010/01/01 2010/02/01 2010/03/01
========== ========== ==========
[ B/(A + B + C) ] 20/60 50/150 80/240 <=== percentage of sum
[ C/(A + B + C) ] 30/60 60/150 90/240 <=== percentage of sum
[ 1 - A/(A + B + C) ] 1 - 10/60 1 - 40/150 1 - 70/240 <=== computed
[ (A + B + C) ] 60 150 250 <=== sum
Assuming you are using a SQL data source, I suggest deriving each of the output rows' values (ie. [B/(A + B + C)], [C/(A + B + C)], [1 - A/(A + B + C)] and [(A + B + C)]) per date in the SQL query, then using Crystal's crosstab feature to pivot them into the output format desired.
Crystal's crosstabs aren't particularly suited to deriving different calculations on different rows of output.