Simplify boolean equation from truth table - math

I need help simplifying the following to the simplest terms. Boolean algebra just doesn't quite click with me yet, any help is appreciated.
(!A!B!C)+(!AB!C)+(!ABC)+(A!B!C)+(A!BC)+(AB!C)
I got it to the following, but I don't know where to go from here:
!A(!B!C + B!C + BC) + A(!B!C + B(XOR)C)
If you are curious and want to check my previous work, I got the original equation from the truth table:

Initially we have A(~B~C + ~BC + ~CB) + ~A(~B~C + B~C + BC)
First Term: A(~B~C + ~BC + ~CB)
= A(~B(~C + C) + ~CB)
= A(~B(True) + ~CB)
= A(~B + ~CB)
= A((~B + ~C)(~B + B))
= A((~B + ~C)(True))
= A(~B + ~C)
Second Term: ~A(~B~C + B~C + BC)
= ~A(~C(~B + B) + BC)
= ~A(~C(True) + BC)
= ~A(~C + BC)
= ~A((~C + C) (~C + B))
= ~A((True) (~C + B))
= ~A(~C + B)
So First Term + Second Term becomes: ~A(~C + B) + A(~B + ~C)
= ~A~C + ~AB + A~B + A~C
= AxorB + ~A~C + A~C
= AxorB + ~C(~A + A)
= AxorB + ~C(True)
= AxorB + ~C
Hence we end up with AxorB + ~C

Related

The leading minor of order 4 is not positive definite in npplreg

I am running the following code:
mydata1 = data.frame(dataset)
mydata1 <- na.omit(mydata1)
bw <- npplregbw(mydata1$X1 ~ mydata1$X2 + mydata1$X3 + mydata1$X4 + mydata1$effect_1993 + mydata1$effect_1994 + mydata1$effect_1995 + mydata1$effect_1996 + mydata1$effect_1997 + mydata1$country_2 + mydata1$country_3 + mydata1$country_4 + mydata1$country_5 + mydata1$country_6 + mydata1$effect_1998 + mydata1$effect_1999 + mydata1$effect_2000 + mydata1$effect_2001 + mydata1$effect_2002 + mydata1$effect_2003 + mydata1$effect_2004 + mydata1$effect_2005 + mydata1$effect_2006 + mydata1$effect_2007 + mydata1$effect_2008 + mydata1$effect_2009 + mydata1$effect_2010 + mydata1$effect_2011 + mydata1$effect_2012 + mydata1$effect_2013 + mydata1$effect_2014 + mydata1$effect_2015 + mydata1$effect_2016 + mydata1$effect_2017 + mydata1$effect_2018 + mydata1$effect_2019 + mydata1$effect_2020 + mydata1$effect_2021|mydata1$X5 + mydata1$X6 + mydata1$X7 + mydata1$X8, data = mydata1, na.action = na.omit)
summary(bw)
reg_np <- npplreg(bw)
The code is running fine except the last command which gives the following error:
Error in chol.default(t(model.matrix(model)) %*% model.matrix(model)) :
the leading minor of order 4 is not positive definite
My data do not have 0 (except the fixed effects data) or NA values.
Is there any way I can proceed with the npplreg regression without getting that error?
Thanks a lot in advance

Recurrence relation with not constant coefficients

I have this recurrence relation
L^2 G[p]= 2(p-1)(2p-1)G[p-1] + ((p-1)(p-2)+a^2) G[p-2], where L and a are parameters.
Does anyone could help me to find the solution? Thanks
This looks like quite a complicated calculation, especially when no start values are given.
To get some more insight, one could use sympy, Python's symbolic math library to print the formulas for small values of p:
from sympy import symbols
def func_G(p):
if p == 0:
return G0
elif p == 1:
return G1
else:
return (2 * (p - 1) * (2 * p - 1) * func_G(p - 1) + ((p - 1) * (p - 2) + a ** 2) * func_G(p - 2)) / L ** 2
a, L, G0, G1 = symbols('a L G0 G1')
for p in range(8):
print(p, ':', func_G(p).simplify())
Prints out:
0 : G0
1 : G1
2 : (G0*a**2 + 6*G1)/L**2
3 : (20*G0*a**2 + G1*L**2*(a**2 + 2) + 120*G1)/L**4
4 : (840*G0*a**2 + 42*G1*L**2*(a**2 + 2) + 5040*G1 + L**2*(a**2 + 6)*(G0*a**2 + 6*G1))/L**6
5 : (60480*G0*a**2 + 3024*G1*L**2*(a**2 + 2) + 362880*G1 + 72*L**2*(a**2 + 6)*(G0*a**2 + 6*G1) + L**2*(a**2 + 12)*(20*G0*a**2 + G1*L**2*(a**2 + 2) + 120*G1))/L**8
6 : (G0*L**4*a**6 + 26*G0*L**4*a**4 + 120*G0*L**4*a**2 + 10960*G0*L**2*a**4 + 90720*G0*L**2*a**2 + 6652800*G0*a**2 + 158*G1*L**4*a**4 + 2620*G1*L**4*a**2 + 5040*G1*L**4 + 398400*G1*L**2*a**2 + 1209600*G1*L**2 + 39916800*G1)/L**10
7 : (248*G0*L**4*a**6 + 7488*G0*L**4*a**4 + 38880*G0*L**4*a**2 + 1770240*G0*L**2*a**4 + 15966720*G0*L**2*a**2 + 1037836800*G0*a**2 + G1*L**6*a**6 + 44*G1*L**6*a**4 + 444*G1*L**6*a**2 + 720*G1*L**6 + 28224*G1*L**4*a**4 + 526080*G1*L**4*a**2 + 1088640*G1*L**4 + 62513280*G1*L**2*a**2 + 199584000*G1*L**2 + 6227020800*G1)/L**12

Strange behavior of `mutate` when applied to a dataframe

I'm trying to mutate a character column in a dataframe, the result should return another character column, but in reality some of the elements in the column are converted to numeric. How could this happen?
This is the dataframe, both sumspec and rate.express are character vectors
sumspec= c("TA","TCO2")
rate.express = c("(rNC-rPC)*RO2POC[i]*dstopw[i] + (rNC-rPC+4/3)*RNO2POC[i]*dstopw[i] + (rNC-rPC)*RNO3POC[i]*dstopw[i] + (rNC-rPC+4)*RMnO2POC[i]*dstopw[i] + (rNC-rPC+8)*RFeOOHPOC[i]*dstopw[i] + (rNC-rPC+1)*RSO4POC[i]*dstopw[i] + (rNC-rPC)*RCH4POC[i]*dstopw[i] + -2*RO2NH4[i] + -2*RO2Mn[i] + -1*RO2Mn_ads[i] + -2*RO2Fe[i] + -1*RO2Fe_ads[i] + -2*RO2H2S[i] + -2*RO2FeS[i]*dstopw[i] + -8/5*RNO3Mn[i] + -1.8*RNO3Fe[i] + 2*RSO4CH4[i] + -1*RMnO2Fe[i]*dstopw[i] + 2*RMnO2H2S[i]*dstopw[i] + 4*RFeOOHH2S[i]*dstopw[i] + -2*RFeS_pre[i]*dstopw[i] + 2*RFeS_dis[i]*dstopw[i] + 2*RCaCO3_dis[i]*dstopw[i] + -2*RCaCO3_pre[i]*dstopw[i] + 2*RMnCO3_dis[i]*dstopw[i] + -2*RMnCO3_pre[i]*dstopw[i] + 2*RFeCO3_dis[i]*dstopw[i] + -2*RFeCO3_pre[i]*dstopw[i] + 10*RAnnite_dis[i]",
"1*RO2POC[i]*dstopw[i] + 1*RNO2POC[i]*dstopw[i] + 1*RNO3POC[i]*dstopw[i] + 1*RMnO2POC[i]*dstopw[i] + 1*RFeOOHPOC[i]*dstopw[i] + 1*RSO4POC[i]*dstopw[i] + 0.5*RCH4POC[i]*dstopw[i] + 1*RO2CH4[i] + 1*RSO4CH4[i] + 1*RCaCO3_dis[i]*dstopw[i] + -1*RCaCO3_pre[i]*dstopw[i] + 1*RMnCO3_dis[i]*dstopw[i] + -1*RMnCO3_pre[i]*dstopw[i] + 1*RFeCO3_dis[i]*dstopw[i] + -1*RFeCO3_pre[i]*dstopw[i]")
Now mutate the colume rate.express
dH <- data.frame(sumspec,
rate.express) %>%
mutate(RHS = ifelse(
sumspec == "TA", rate.express,
paste0("-1.0*(",rate.express,")*dTA/d",sumspec,"[i]")
))
Which returns
> dH$RHS
[1] "1"
[2] "-1.0*(1*RO2POC[i]*dstopw[i] + 1*RNO2POC[i]*dstopw[i] + 1*RNO3POC[i]*dstopw[i] + 1*RMnO2POC[i]*dstopw[i] + 1*RFeOOHPOC[i]*dstopw[i] + 1*RSO4POC[i]*dstopw[i] + 0.5*RCH4POC[i]*dstopw[i] + 1*RO2CH4[i] + 1*RSO4CH4[i] + 1*RCaCO3_dis[i]*dstopw[i] + -1*RCaCO3_pre[i]*dstopw[i] + 1*RMnCO3_dis[i]*dstopw[i] + -1*RMnCO3_pre[i]*dstopw[i] + 1*RFeCO3_dis[i]*dstopw[i] + -1*RFeCO3_pre[i]*dstopw[i])*dTA/dTCO2[i]"
So the mutate rate.express should just return the original value for the first element but it is converted to numeric. The second element is OK. I think it is converted to numeric because
> as.numeric(dH$rate.express[1])
[1] 1
In stead, if I explicitly use as.character to rate.express
> dH <- data.frame(sumspec,
+ rate.express) %>%
+ mutate(RHS = ifelse(
+ sumspec == "TA", as.character(rate.express), # explicitly state type
+ paste0("-1.0*(",rate.express,")*dTA/d",sumspec,"[i]")
+ ))
Then the result is correct
Why did this type conversion happen?

Simplify the following expression to A'D' + A'B

𝑓 = 𝐴'𝐡'𝐢'𝐷' + 𝐴'𝐡'𝐢𝐷' + 𝐴'𝐡𝐢'𝐷 + 𝐴'𝐡𝐢𝐷 + 𝐴'𝐡𝐢𝐷' + 𝐴'𝐡'𝐢𝐷' + 𝐴𝐡'𝐢D'
I've done the K-Map for the following and got A'D' + A'B but can't figure out how to show the simplification that the K-Map derived.

Error in First Differences Model

I am very new to R and trying to tackle some homework that is giving me trouble. I think I have just about everything worked out, except last glitch.
When I create the following First differences models (using my two panel datasets):
out00 <- plm(logmrate ~ 0 + lawchange + logbeertaxa + y70 + y71 + y72 + y73 + y74 + y75 + y76 + y77 + y78 + y79 + y80 + y81 + y82 + y83 + y84 + y85 + y86 + y87 + y88 + y89 + y90 + y91 + y92 + y93 + y94 + y95 + y96, data = pdt.deaths, model = 'fd')
out01 <- plm(logmrate ~ 0 + lawchange + logbeertaxa + y70 + y71 + y72 + y73 + y74 + y75 + y76 + y77 + y78 + y79 + y80 + y81 + y82 + y83 + y84 + y85 + y86 + y87 + y88 + y89 + y90 + y91 + y92 + y93 + y94 + y95 + y96, data = pdt.deaths1, model = 'fd')
stargazer(out00, type="text")
stargazer(out01, type="text")
I get this error term returned for both models:
Error in crossprod(t(X), beta) : non-conformable arguments
The variable "lawchange" is a 1 or 0 variable, and each of the year variables ("y70"..."y96") are year indicator variables to account for time

Resources