codecogs equations
torsdag 11 februari 2021
SAT for developers 1: What is SAT?
måndag 8 februari 2021
SAT: Some Constraints
In this post, I present four constraints that I have implemented for my satisfiability package SugarRush. It is based on PySAT [1].
Parity
This constraint is much much better to use than the method used in sat: disjunction operator.
Naive / general way, with disjunction (for 10 elements):
Special purpose encoding of parity constraint (for 10 elements):
Less / Leq
A natural question is: why is the t returned separately from the rest of the constraint? The reason is that this way, one can easily encode such constraints as "a is either less than b, or less than c", or "a is less than either b or c, but not both". An example usage here is to constrain two intervals to be non-overlapping:
Plus
Element
[1] Ignatiev, Alexey, Antonio Morgado, and Joao Marques-Silva. "PySAT: A Python toolkit for prototyping with SAT oracles." International Conference on Theory and Applications of Satisfiability Testing. Springer, Cham, 2018.
måndag 9 mars 2020
COVID19: How many unconfirmed cases are there?
We use this to estimate a best case scenario for the number of unconfirmed cases.
Answer: best case in Europe and US is the total number of cases is 2 times the confirmed cases. So double the official figure. The situation is better in Asia: Japan and South Korea have a best case bound of about 10% extra.
More in depth info about the method below the graphs.
![]() |
| Belgium |
![]() |
| France |
![]() |
| Germany |
![]() |
| Iran |
![]() |
| Italy |
![]() |
| Japan |
![]() |
| China |
![]() |
| Netherlands |
![]() |
| Norway |
![]() |
| Singapore |
![]() |
| South Korea |
![]() |
| Spain |
![]() |
| Sweden |
![]() |
| Switzerland |
![]() |
| United Kingdom |
![]() |
| United States |
Method
References
COVID19: what is the growth rate?
Method
tisdag 3 mars 2020
Political intolerance and dating pt. 2: Chemistry
![]() |
| Women lean left. Men lean right. Will this be a problem for future marriages in Sweden? |
The Idea
The reaction goes both ways: in equilibrium new products are formed as fast as old ones are breaking up. The key variable in this process is the equilibrium constant*. The equilibrium constant is:
The brackets mean concentrations. What value does K have in real life if A=single women, B=single men and AB=couple? Let's be fairly optimistic and say that with all other variables that affect this except politics, 80% of people will be in a long term relationship at equilibrium. About 80% of all women become mothers at some point during their life, so that's where I get that from. Then A=0.1, B=0.1, and AB=0.4 (since a couple counts as one in chemistry). Therefore, K=40.
*The speed by which the solution converges to the equilibrium is reached is also very important, but here we will just assume that all processes are in equilibrium (though of course life happens before the asymptote, quote Taleb).
The Model
Another motivation for using a binary tolerance model rather than something more granular is the assumption that value questions come up quite early during dating, and if the values do not match then chances of going forward are not good. If the values do approximately match however, then it should be possible to reconcile political difference in good faith, and other variables are more important to whether the relationship will hold.
For each politically feasible couple, we get a reaction formula, such as:
for Center women and Social democrat men. This gives us the equilibrium equation:
Where K is the equilibrium constant, assuming no political troubles.
The variables in this model are the concentrations at equilibrium. So there will be one variable for each "single" type, such as Cw, and one for each "couple" type, such as CwSm. We need to preserve the total number of people of course, which gives us the equations like:
Where P is the total concentration of that group, out of both men and women. In the case of Center women, P(Cw) = 16.8% / 2 = 8.4%.
Now we have one equation per single type, and one per couple type, which means one per variable, so the model should be fully constrained. Might exist some satisfying solutions involving negative concentrations, but we can easily constrain concentrations to be in the interval [0, 1].
The model solves beautifully with Couenne [1][2] in about 100 ms.
Results
![]() |
| Equilibrium matching pattern using the "chemical" model. Line width in the middle is proportional to the commonness of that couple. Singles are not shown. |
V, women 57.1%
MP, women 41.8%
S, women 26.4%
C, women 26.0%
L, women 26.0%
M, women 14.8%
KD, women 15.4%
SD, women 17.0%
V, men 19.3%
MP, men 15.9%
S, men 14.8%
C, men 24.7%
L, men 24.7%
M, men 24.7%
KD, men 32.5%
SD, men 50.8%
Discussion
Alternative Parameter Values
V, women 80.8%
MP, women 72.0%
S, women 58.6%
C, women 59.6%
L, women 59.6%
M, women 47.7%
KD, women 49.8%
SD, women 53.8%
V, men 59.4%
MP, men 51.6%
S, men 48.0%
C, men 58.1%
L, men 58.1%
M, men 56.2%
KD, men 63.9%
SD, men 76.4%
This scenario has a total of 62.4% equilibrium singles.
What about a much more optimistic moral and economic scenario? (morally favourable, in the sense that it incentivises marriages). Let's consider a world like 1950's American suburbia, with only 2% equilibrium singles:
V, women 24.7%
MP, women 8.1%
S, women 2.8%
C, women 2.3%
L, women 2.3%
M, women 0.5%
KD, women 0.5%
SD, women 0.6%
V, men 0.6%
MP, men 0.5%
S, men 0.5%
C, men 2.6%
L, men 2.6%
M, men 3.3%
KD, men 5.8%
SD, men 19.4%
References
[2] I use Couenne by wrapping Pyomo http://www.pyomo.org/
Political intolerance and dating
![]() |
| Political polls Sweden February 2020. Females 18-29 (left), and males 18-29 (right) |
Key to the parties (links are to the corresponding party groups in the EU parliament)
Political intolerance model
Matching model
Results
![]() |
| Assignment of couples that maximize the number of matches. The total match rate is almost 98%. The width of the lines in the middle is proportional to the number of couples of that kind. |
V, women: 8.8%
V, men: 0.0%
MP, women: 0.0%
MP, men: 0.0%
S, women: 0.0%
S, men: 0.0%
C, women: 0.0%
C, men: 28.0%
L, women: 0.0%
L, men: 0.0%
M, women: 0.0%
M, men: 0.0%
KD, women: 0.0%
KD, men: 0.0%
SD, women: 0.0%
SD, men: 0.6%
Except for that odd result, the only groups that have unmatched members are indeed women to the far left and men to the far right, as would be expected.
Model uncertainties
Of course, an final important implicit assumption is that the number of women and men is the same! This may be imbalanced by either gender being more likely to emigrate.







































