Find Constraint network - arc-consistency - math

I have a question about an arc consistency network example. its nothing with code.
i have a network R with Variables X = {x1, x2, x3, x4, x5, x6, x7, x8} and Domains D = {1,2,3,4}.
This are my constraints:
I have the solution fromy my professor. But i dont understand what happend with C24 / why nothing happend with C24.
I think D2 is 2,3,4 and D4 is default 1,2,3,4. If x2 is not equal x4 (C24), x4 should be 1. I hope someone could help me.

A constraint c(xi,xj) is arc-consistent iff for every value a∈Di there exists a value b∈Dj such that c(a,b) is true (and vice versa with i and j swapped).
If your constraint is xi < xj, then the situation Di={1,2,3}, Dj={1,2,3,4} is not arc-consistent because there is no xi∈{1,2,3} that makes xi < 1 true. To get arc-consistency, you must eliminate 1 from Dj.
However, with the constraint xi ≠ xj and Di={1,2,3}, Dj={1,2,3,4} you already have arc-consistency, because for every xj∈{1,2,3,4} there exists an xi∈{1,2,3} that makes xi ≠ xj true (and for every xi∈{1,2,3} there exists an xj∈{1,2,3,4} that makes xi ≠ xj true).

Related

arctangent implementation in TMS320C55X

I'm learning arctangent implementation in TMS320C55x
this is the source code:
;* AR0 assigned to _x
;* AR1 assigned to _r
;* T0 assigned to _nx
PSH T3
|| BSET FRCT ;fractional mode
SUB #1, T0 ;nx-1
MOV T0, BRC0 ;repeat nx times
MOV #2596 << #16, AC3 ; AC3.Hi = C5
MOV #-9464 << #16, AC1 ; AC1.Hi = C3
MOV #32617 << #16, AC2 ; AC2.Hi = C1
*
* Note: loading T3 on the instruction before a multiply that uses it will
* cause a 1-cycle delay.
*
MPYMR T3=*AR0+, AC3, AC0 ; (Prime the Pump)
|| RPTBLOCAL loop1-1
MACR AC0, T3, AC1, AC0
MPYR T3, AC0
||MOV *AR0+, T1 ; (for next iteration)
MACR AC0, T3, AC2, AC0
MPYR T3, AC0
||MOV T1, T3
MOV HI(AC0), *AR1+ ;save result
||MPYR T1, AC3, AC0 ; (for next iteration)
loop1:
POP T3
|| BCLR FRCT ;return to standard C
MOV #0, T0 ;return OK value (no possible error)
|| RET
where _x is vector of input and _r is output. nx is the number of elements.
The question is about constants that assigns to AC3, AC1, AC2. I guess it is coefficients for polynomial approximation but i don't understand how to calculate them
I do not follow the assembly code, but I could guess where those magic coefficients come from.
The code comments suggest C1, C3, C5 are coefficients of a polynomial approximation, and arctan is an odd function, so its Taylor expansion around 0 has indeed only odd powers of x. Comparing C1 = 32617 to 1 in the Taylor expansion y = x - 1/3 x^3 + 1/5 x^5 - 1/7 x^7 + ..., and given the computational context, this further suggests that the result of the calculation is scaled by 2^15 = 32768.
It turns out that y = (32617 x - 9464 x^3 + 2596 x^5) / 32768 is in fact a pretty good approximation of arctan(x) over the interval [-1, 1]. As shown below (verified in wolfram alpha) the largest absolute error of the approximation is less than 1/1000, and is negligible at the endpoints x = ±1 corresponding to y = ±π/4, which is probably desirable in graphics calculations.
As to how the coefficients were actually derived, a crude polynomial best-fit using just 9 control points gives a polynomial y = 32613 x - 9443 x^3 + 2573 x^5 with coefficients already close to the ones used in the posted code. More control points and/or additional conditions to minimize the error at the end points would result in slightly different coefficients, but it's hard to guess how to exactly match the ones in the code without any documentation or clues about the optimization criteria being actually used there.

Constraint propagation using Projection rule

I've found this example of constraint propagation using projection rule
We have
C = { x1 ≠ x2, x1 ≥ x2 }
< C; x1 ∈ {1,2,3}, x2 ∈ {1,2,3} >
They say that applying propagation rule, does not give any simplification.
I'm not sure why this is the case. Shouldn't we get?
< C; x1 ∈ {2,3}, x2 ∈ {1,2} >
Other steps in the example, make sense that to me, e.g.
< C; x1 ∈ {2}, x2 ∈ {1,2,3} >
produces
< C; x1 ∈ {2}, x2 ∈ {1} >
Note that the constraint in your example is x1 >= x2, and not x1 > x2.
Given that the iniital domains are {1,2,3} for both variables, neither x1 >= x2 nor x1 != x2 can be used to draw any conclusions.

Datatype equality in higher order logic

Having the following theory:
theory BitVector
imports Main
begin
datatype bitvector = BTM | BITV bool bitvector
lemma "∀ x1 x2 y1 y2. (BITV x1 x2 = BITV y1 y2) = (x1=y1) ∧ (x2=y2)"
I get the following proof state:
proof (prove): step 0
goal (1 subgoal):
1. ∀x1 x2 y1 y2. (BITV x1 x2 = BITV y1 y2) = (x1 = y1) ∧ x2 = y2
Auto Quickcheck found a counterexample:
x1 = False
x2 = BITV True BTM
y1 = False
y2 = BTM
What kind of equality is this here? It is obvious that it is not the structural equality that is of Standard ML. Or, is there a bug in this formalisation?
Be careful with equality of boolean-type expressions. Due to operator precedence, the proposition of your lemma is actually the following:
lemma "∀ x1 x2 y1 y2. ((BITV x1 x2 = BITV y1 y2) = (x1=y1)) ∧ (x2=y2)"
This is obviously false. What you should write is:
lemma "∀ x1 x2 y1 y2. (BITV x1 x2 = BITV y1 y2) = ((x1=y1) ∧ (x2=y2))"
In fact, due to these operator precedence issues, I prefer using ⟷ for equality of boolean expressions:
lemma "∀ x1 x2 y1 y2. BITV x1 x2 = BITV y1 y2 ⟷ x1 = y1 ∧ x2 = y2"
Moreover, one would normally write a lemma such as this without the HOL universal quantifiers and instead use the following, which is equivalent:
lemma "BITV x1 x2 = BITV y1 y2 ⟷ x1 = y1 ∧ x2 = y2"
All of these lemmas are easily proven by the simplifier, as they are direct consequences of the injectivity lemmas that are automatically provided by the datatype command.
I should also mention that instead of defining bit vectors yourself, you may want to use the predefined formalisation of bit vectors in src/HOL/Word. Some examples exist in src/HOL/Word/Examples.

IFFT using FFT by taking conjugate of the FFT result

I am doing fixed point FFT on 8bit pic microcontrller using C language, i am able to get the FFT result from the sample i have taken but i am getting wrong output when i do the IFFT for the FFT result.
The flow of program i am doing is as follows
Doing FFT for 8 samples say example: Real value are (1,0,0,0,0,0,0,0) and Imaginary values are (0,0,0,0,0,0,0,0)
The output of the FFT is (1,1,1,1,1,1,1,1) and imaginary values are (0,0,0,0,0,0,0,0)
Then taking the conjugate of FFT output
Doing FFT for the conjugated result
Again taking the conjugate of the second time FFT result
Finally dividing by 8 to get the original samples in time domain
The output is Real value are (1,0,0,0,0,0,0,0) and Imaginary values are (0,-0,-0,-0,-0,-0,-0,-0);
But if i apply the same for Real values (1,2,3,4,5,6,7,8) and imaginary values (0,0,0,0,0,0,0,0) i am getting wrong result such as real value after IFFT are (1,2,4,7,4,5,4,5) and Imaginary values are(-0,-3,-1,-0,1,0,0,2)
please help me what i am doing wrong...
The FFT solves an interpolation problem, the IFFT the corresponding multi-point evaluation problem
The result of the FFT are coefficients of a polynomial p(z) where p(wk)=xk, w is the unit root associated with the dimension D of the FFT.
Denote with ps,k(z) the polynomial formed from the subsequence of coefficients of p(z) starting in k and spaced with index distance s.
If D=2N is even, the general idea to get from the values to the coefficients is to use wN=-1 and the decomposition
p(z) = p2,0(z²) + z * p2,1(z²)
in the relations
xk = p(wk)=p2,0(w2k) + wk * p2,1(wk)
xN+k = p(wN+k) = p(-wk)
= p2,0(w2k) - wk * p2,1(w2k)
to reduce the big interpolation problem into two subproblems of half the size,
2*p2,0(w2k) = xk + xN+k
2*p2,1(w2k) = w-k * (xk - xN+k)
In the next step,
p2,0 is reduced to p4,0 and p4,2, and
p2,1 is reduced to p4,1 and p4,3
etc.
For the sequence of 8 inputs, one gets in the first step w=(1+i)/sqrt(2) and w2=i
x1,0 = 2*p2,0( 1) = x0 + x4
x1,2 = 2*p2,0( i) = x1 + x5
x1,4 = 2*p2,0(-1) = x2 + x6
x1,6 = 2*p2,0(-i) = x3 + x7
..
x1,1 = 2*p2,1( 1) = (x0 - x4)*1
x1,3 = 2*p2,1( i) = (x1 - x5)*(1-i)/sqrt(2)
x1,5 = 2*p2,1(-1) = (x2 - x6)*(-i)
x1,7 = 2*p2,1(-i) = (x3 - x7)*(-1-i)/sqrt(2)
In the next step, one gets w=i and w2=-1
x2,0 = 4*p4,0( 1) = x1,0 + x1,4
x2,4 = 4*p4,0(-1) = x1,2 + x1,6
..
x2,2 = 4*p4,2( 1)= (x1,0 - x1,4)*1
x2,6 = 4*p4,2(-1)= (x1,2 - x1,6) * (-i)
--
x2,1 = 4*p4,1( 1) = x1,1 + x1,5
x2,5 = 4*p4,1(-1) = x1,3 + x1,7
..
x2,3 = 4*p4,3( 1)= (x1,1 - x1,5)*1
x2,7 = 4*p4,3(-1)= (x1,3 - x1,7) * (-i)
and finally the FFT coefficients Xk=x3,k using w=-1 and w²=1
X0 = 8*p8,0( 1) = x2,0 + x2,4
X4 = 8*p8,4( 1) = (x2,0 - x2,4)*(-1)
--
X2 = 8*p8,2( 1) = x2,2 + x2,6
X6 = 8*p8,6( 1) = (x2,2 - x2,6)*(-1)
--
X1 = 8*p8,1( 1) = x2,1 + x2,5
X5 = 8*p8,5( 1) = (x2,1 - x2,5)*(-1)
--
X3 = 8*p8,3( 1) = x2,3 + x2,7
X7 = 8*p8,7( 1) = (x2,3 - x2,7)*(-1)
Please check that these steps are reflected in your code, especially, that the square root of 2 occurs at the necessary places. It is highly unlikely that the output of random integer inputs is again strictly integer.
In your description there, at no point do you take an inverse DFT.
Think about what is going on, lets say you have the the DFT result as X, taking X*X is going to give you the power spectrum, not an inverse DFT. Then preforming an DFT on this will not give you a time domain, it will give you nonsense.
you need to find the inverse DFT function in the library you are using.

Formulating Linear Programming Problem

This may be quite a basic question for someone who knows linear programming.
In most of the problems that I saw on LP has somewhat similar to following format
max 3x+4y
subject to 4x-5y = -34
3x-5y = 10 (and similar other constraints)
So in other words, we have same number of unknown in objective and constraint functions.
My problem is that I have one unknown variable in objective function and 3 unknowns in constraint functions.
The problem is like this
Objective function: min w1
subject to:
w1 + 0.1676x + 0.1692y >= 0.1666
w1 - 0.1676x - 0.1692y >= -0.1666
w1 + 0.3039x + 0.3058y >= 0.3
w1 - 0.3039x - 0.3058y >= -0.3
x + y = 1
x >= 0
y >= 0
As can be seen, the objective function has only one unknown i.e. w1 and constraint functions have 3 (or lets say 2) unknown i.e w1, x and y.
Can somebody please guide me how to solve this problem, especially using R or MATLAB linear programming toolbox.
Your objective only involves w1 but you can still view it as a function of w1,x,y, where the coefficient of w1 is 1, and the coeffs of x,y are zero:
min w1*1 + x*0 + y*0
Once you see this you can formulate it in the usual way as a "standard" LP.
Prasad is correct. The number of unknowns in the objective function does not matter. You can view unknowns that are not present as having a zero coefficient.
This LP is easily solved using Matlab's linprog function. For more
details on linprog see the documentation here.
% We lay out the variables as X = [w1; x; y]
c = [1; 0; 0]; % The objective is w1 = c'*X
% Construct the constraint matrix
% Inequality constraints will be written as Ain*X <= bin
% w1 x y
Ain = [ -1 -0.1676 -0.1692;
-1 0.1676 0.1692;
-1 -0.3039 -0.3058;
-1 0.3039 0.3058;
];
bin = [ -0.166; 0.166; -0.3; 0.3];
% Construct equality constraints Aeq*X == beq
Aeq = [ 0 1 1];
beq = 1;
%Construct lower and upper bounds l <= X <= u
l = [ -inf; 0; 0];
u = inf(3,1);
% Solve the LP using linprog
[X, optval] = linprog(c,Ain,bin,Aeq,beq,l,u);
% Extract the solution
w1 = X(1);
x = X(2);
y = X(3);

Resources