I am a beginner at Coq and I'm stuck at a problem in Coq, I am not able to simplify this further. It would be great if anyone had any tips on how to break the problem down into smaller steps. The lemma is this:
forall (n : N) (n0 : N),
((1 + 2 * n + (2 * N.pos (2 ^ 32) - 1 - (0 + 2 * n0)))
mod (2 * N.pos (2 ^ 32)) / (2 * 1)) mod N.pos (2 ^ 32) =
(((n + (N.pos (2 ^ 32) - 1 - n0)) mod N.pos (2 ^ 32) + 1 mod N.pos (2 ^ 32))
mod N.pos (2 ^ 32) / 1) mod N.pos (2 ^ 32)
As such, your goal is not provable, you can try:
Goal exists (n : N) (n0 : N),
((1 + 2 * n + (2 * N.pos (2 ^ 32) - 1 - (0 + 2 * n0)))
mod (2 * N.pos (2 ^ 32)) / (2 * 1)) mod N.pos (2 ^ 32) <>
(((n + (N.pos (2 ^ 32) - 1 - n0)) mod N.pos (2 ^ 32) + 1 mod N.pos (2 ^ 32))
mod N.pos (2 ^ 32) / 1) mod N.pos (2 ^ 32).
Proof.
now exists 0, (N.pos 2^33).
Qed.
The issue comes from subtraction between positive numbers, which returns 0 when its second argument is larger, so that it is not injective.
Related
I am in big problem in solving a code essential for me, and I need the solution as soon as possible
in fact, I have little knowledge of programming in basic
I have a problem with this code.
I have an equation, and I use this code to solve this equation
when I run the program
this error appears
subscript out of range
is there any solution to this problem
0 Print "******** impact *******"
20 Print "____________"
30 Print "this programs is used to solve impact integral"
40 Print "equation of simply supported slab to "
50 Print "optain the following"
60 Print " (1) force _time history"
70 Print " (2) central deflection - time history"
80 Print "-----------------"
90 Print "input data:"
100 Print " (1) FUNDAMENTAL NATURAL FREQUANCY (RAD/SEC)--- W1"
110 Print " (2) STRIKER MASS (KG.) ----- Mst"
120 Print " (3) MASS OF SLAB (KG)---- Ms"
130 Print " (4) hertz constant (n/m^1.5)----k"
140 Print " (5) STRICKER VELOCITY (M/S)----Vo"
150 Print " (6) NUMBER OF MODES----N"
160 Print "_________"
170 Input " W11, MST, MS, K, VO, N", W11, MST, MS, K, VO, N
180 Print "W1="; W11; "RAD/SEC"
190 Print "MST="; MST; "KG"
200 Print "MS="; MS; "KG"
210
220 Print " K = "; K; "N/M^1.5"
230 Print STANDARD
240 Print "VO="; VO; "M/S"
241 Print " N = "; N
250 Print
260 Print
270 K1 = K
280 V = VO
290 W1 = W11 / 2
300 TINF = 2.94 * (MST / (.8 * K1 * V ^ .5)) ^ .4 * 1000
310 DT = TINF / 10
320 M = 20
330 DT = PROUND(DT, 0)
340 DT = DT / 1000
350 M = 20
360 Option Base 1
370 Dim W(11, 11), Z(11, 11), F(30), D(30), BM(30), SH(30), A(30), T(30), DF(30), S(11, 11, 30), C(11, 11, 30)
380 ReDim W(N, N), Z(N, N)
390 For I = 1 To N Step 2
400 For K = 1 To N Step 2
410 W(K, I) = W1 * (I ^ 2 + K ^ 2)
420 Z(K, I) = W(K, I) * DT
430 Next K
440 Next I
450 ReDim F(M), D(M), A(M), T(M), DF(M), BM(M), SH(M), S(N, N, M), C(N, N, M)
460 F(1) = D(1) = A(1) = T(1) = 0
470 For I = 1 To N Step 2
480 For K = 1 To N Step 2
490 S(K, I, 1) = C(K, I, 1) = 0
500 Next K
510 Next I
520 B1 = 0
530 For I = 1 To N Step 2
540 For K = 1 To N Step 2
550 B1 = B1 + (1 - Sin(Z(K, I)) / Z(K, I)) / W(K, I) ^ 2
560 Next K
570 Next I
580 B = -DT ^ 2 / (6 * MST) - 4 * B1 / MS
590 VE = 0
600 For I = 2 To M
610 T(I) = (I - 1) * DT
620 GM = 0
630 If VE = 1 Then 970
640 For J = 2 To I
650 GM = GM + F(J - 1)
660 Next J
670 AA = 0
680 For J = 1 To N Step 2
690 For K = 1 To N Step 2
700 FF = F(I - 1) * (Sin(Z(K, J)) / Z(K, J) - Cos(Z(K, J))) / W(K, J)
710 AA = AA + 4 * (Cos(Z(K, J)) * S(K, J, I - 1) + Sin(Z(K, J)) * C(K, J, I - 1) + FF) / (MS * W(K, J))
720 Next K
730 Next J
740 A(I - 1) = V * (I - 1) * DT - (D(I - 1) + DT ^ 2 * (GM - F(I - 1) / 6)) / MST - AA
750 F = F(I - 1)
760 If A(I - 1) + B * F < 0 Then 840
770 F1 = (A(I - 1) + B * F) ^ 1.5 * K1
780 X = Abs(F1 - F)
790 If X < 10 Then 820
800 F = F1
810 GoTo 770
820 F(I) = F1
830 GoTo 850
840 F(I) = 0
850 D(I) = D(I - 1) + DT ^ 2 * (GM + (F(I) - F(I - 1)) / 6)
860 For J = 1 To N Step 2
870 For K = 1 To N Step 2
880 S(K, J, I) = Cos(Z(K, J)) * S(K, J, I - 1) + Sin(Z(K, J)) * C(K, J, I - 1) + (1 - Sin(Z(K, J)) / Z(K, J)) * (F(I) - F(I - 1)) / W(K, J) + (1 - Cos(Z(K, J))) * F(I - 1) / W(K, J)
890 C(K, J, I) = Cos(Z(K, J)) * C(K, J, I - 1) - Sin(Z(K, J)) * S(K, J, I - 1) + (1 - Cos(Z(K, J))) / Z(K, J) * (F(I) - F(I - 1)) / W(K, J) + Sin(Z(K, J)) * F(I - 1) / W(K, J)
900 Next K
910 Next J
920 DF = 0
930 For J = 1 To N Step 2
940 For K = 1 To N Step 2
950 DF = DF + 4 * S(K, J, I) / W(K, J) / MS
960 Next K
970 Next J
980 DF(I) = DF
990 If F(I) = 0 Then 1010
1000 Next I
1010 Print "----------------------------------------------------------"
1020 Print "{TIME (MS)},{FORCE (KN)},{DEFLECTION(MM)}"
1030 Print "----------------------------------------------------------"
1040 II = I
1050 For O = 1 To II
1060
1070 Print Tab(1); ":"; Tab(5); T(0) * 1000; Tab(18); ":"; Tab(22); F(O) / 1000; Tab(34); ":"; Tab(42); DF(O) * 1000; Tab(56); ":"
1080 Print "-----------------------------------------------------------"
1090 Next O
1100 End
Can anybody tell me why the tactic "field" does not work when I try to prove the following goal involving rationals?
nat_to_Q 3 * nat_to_Q n * nat_to_Q n + nat_to_Q 3 * nat_to_Q n +
nat_to_Q 3 * nat_to_Q n + nat_to_Q 3 + nat_to_Q 3 * nat_to_Q n +
nat_to_Q 3 + nat_to_Q n * nat_to_Q n * nat_to_Q n + nat_to_Q n * nat_to_Q n +
nat_to_Q n * nat_to_Q n * nat_to_Q 2 + nat_to_Q n * nat_to_Q 2 ==
nat_to_Q 3 * nat_to_Q n * nat_to_Q n * nat_to_Q n +
nat_to_Q 6 * nat_to_Q n * nat_to_Q n + nat_to_Q 11 * nat_to_Q n +
nat_to_Q 6
Note: n is nat and nat_to_Q is (Z.of_nat n # Pos.of_nat 1).
Thanks a lot,
Marcus.
Let's remove the coercions to make this easier to read:
3 * n * n + 3 * n +
3 * n + 3 * n +
3 + n * n * n + n * n +
n * n * 2 + n * 2 ==
3 * n * n * n +
6 * n * n + 11 * n + 6
Now we can see the issue: the goal does not hold. The 3rd order coefficient on the left-hand side is 1, but on the right-hand side it is 3.
In the Netlogo dictionary for "reduce" they show an example with one "+" operator
reduce [?1 + ?2] [1 2 3 4]
which they expand as equivalent to (((1 + 2) + 3) + 4).
Later they give this example:
;; evaluate the polynomial, with given coefficients, at x
to-report evaluate-polynomial [coefficients x]
report reduce [(x * ?1) + ?2] coefficients
end
;; evaluate 3x^2 + 2x + 1 at x = 4
show evaluate-polynomial [3 2 1] 4
=> 57
What is the equivalent expansion (using parentheses) for that evaluation?
observer> show (4 * ((4 * 3) + 2)) + 1
observer: 57
The key to understand it is to do it step by step. reduce starts by taking the first two elements of the list and plugging them into ?1 and ?2, so
(x * ?1) + ?2
becomes
(x * 3) + 2
That whole expression then becomes ?1, and the last element of the list, 1, becomes ?2. Replacing ?1 and ?2 in the initial expression again, we get:
(x * ((x * 3) + 2)) + 1
All that's left is to replace x with 4:
(4 * ((4 * 3) + 2)) + 1
I'm trying to run the code below in which I used a zero trick for my log-likelihood expression(phi is my log-likelihood):
model{
for (l in 1:k) {
d.1[l] ~ dbern(p.1)
d.2[l] ~ dbern(p.2)
d.3[l] ~ dbern(p.3)
d.4[l] ~ dbern(p.4)
}
for (l in 1:k) {
zeros[l] <- 0
zeros[l] ~ dpois(phi[l])
u.1[l] <- pow((1 - p.1), (1 - d.1[l]))
u.2[l] <- pow((1 - p.2), (1 - d.2[l]))
u.3[l] <- pow((1 - p.3), (1 - d.3[l]))
u.4[l] <- pow((1 - p.4), (1 - d.4[l]))
f.1[l] <- pow(p.1, d.1[l]) * pow((1 - p.1), (1 - d.1[l]))
f.2[l] <- pow(p.2, d.2[l]) * pow((1 - p.2), (1 - d.2[l]))
f.3[l] <- pow(p.3, d.3[l]) * pow((1 - p.3), (1 - d.3[l]))
f.4[l] <- pow(p.4, d.4[l]) * pow((1 - p.4), (1 - d.4[l]))
a[l] <- pow((pow(u.3[l], -theta.1) + pow(u.4[l], -theta.1) -
1), (theta.0/theta.1 - 2)) * (-1) * ((theta.0/theta.1) *
(-1) + pow((theta.0/theta.1), 2))
b[l] <- pow((pow(u.1[l], -theta.2) + pow(u.2[l], -theta.2) -
1), (theta.0/theta.2 - 2)) * (-1) * ((theta.0/theta.2) *
(-1) + pow((theta.0/theta.2), 2))
c[l] <- pow(pow((pow(u.3[l], -theta.1) + pow(u.4[l],
-theta.1) - 1), -(1/theta.1)), -theta.0) + pow(pow((pow(u.2[l],
-theta.2) + pow(u.1[l], -theta.2) - 1), -(1/theta.2)),
-theta.0) - 1
d[l] <- pow((pow(u.3[l], -theta.1) + pow(u.4[l], -theta.1) -
1), (theta.0/theta.1 * 2 - 2)) * pow(theta.0/theta.1,
2)
e[l] <- pow((pow(u.1[l], -theta.2) + pow(u.2[l], -theta.2) -
1), (theta.0/theta.2 * 2 - 2)) * pow(theta.0/theta.2,
2)
phi[l] <- log((a[l] * b[l]) * (1 + theta.0)/pow(c[l],
-(2 + 1/theta.0)) + (d[l] * b[l] + a[l] * e[l]) *
((1 + theta.0) * (1 + 2 * theta.0))/pow(theta.0,
3) * pow(c[l], -(3 + 1/theta.0)) + (d[l] * e[l]) *
((1 + theta.0) * (1 + 2 * theta.0) * (1 + 3 * theta.0))/pow(theta.0,
4) * pow(c[l], -(4 + 1/theta.0))) + log(pow(theta.1,
2) * pow((u.3[l] * u.4[l]), -(1 + theta.1)) * pow(theta.2,
2) * pow((u.1[l] * u.2[l]), -(1 + theta.2)))
}
p.1 ~ dunif(0 , 1)
p.2 ~ dunif(0 , 1)
p.3 ~ dunif(0 , 1)
p.4 ~ dunif(0 , 1)
theta.0 ~ dunif(0 , 2)
theta.1 ~ dunif(0 , 2)
theta.2 ~ dunif(0 , 2)
}
with data:
k <- 16
d.1 <- c(0 , 0, 0 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 0)
d.2 <- c(0 , 1, 0 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 0)
d.3 <- c(1 , 0, 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0)
d.4 <- c(0 , 1, 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0)
The model is syntactically correct and the data is loaded but I got the following error:
logical expression contains too many constants
Can anyone please help me solve that problem?
BUGS does not like expressions with too many constants. You need to introduce a sub-step to break them up. See point (c) under 'Some Error Messages' in this page:
http://mathstat.helsinki.fi/openbugs/Manuals/TipsTroubleshooting.html
Below recursive method sums the integer values between a range
def sumInts(a: Int, b: Int): Int = {
if(a > b) 0
else {
println(a +"," + b)
a + sumInts(a + 1 , b)
}
}
So sumInts(2 , 5) returns 14
I'm confused about how the recursive call to sumInts sums the integer range. Can explain textually how this method works ?
How does sumInts return the incremented value ?? Perhaps I am missing something fundamental to recursion here
It calculates the sum of values in the range [a, b] by first calculating the sum of the range [a+1, b] (by recursively calling sumInts(a + 1 , b)) then adding a to it.
[Update] In Scala, the return statement is optional; functions return the value of the last expression evaluated. Thus the above function body is equivalent to
if(a > b) return 0
else {
println(a +"," + b)
return a + sumInts(a + 1 , b)
}
[/Update]
Which for the range [2, 5] it would do the following (I removed the println call for the sake of simplicity, and added brackets to mark recursive calls):
if(2 > 5) 0 else 2 + sumInts(2 + 1, 5) which, the condition being false, evaluates to
2 + sumInts(3, 5)
2 + (if(3 > 5) 0 else 3 + sumInts(3 + 1, 5)) which evaluates to
2 + (3 + sumInts(4, 5))
2 + (3 + (if(4 > 5) 0 else 4 + sumInts(4 + 1, 5))) which evaluates to
2 + (3 + (4 + sumInts(5, 5)))
2 + (3 + (4 + (if(5 > 5) 0 else 5 + sumInts(5 + 1, 5)))) which evaluates to
2 + (3 + (4 + (5 + sumInts(6, 5))))
2 + (3 + (4 + (5 + (if(6 > 5) 0 else 6 + sumInts(6 + 1, 5))))) which, the condition being true, evaluates to
2 + (3 + (4 + (5 + (0))))