golitex icon indicating copy to clipboard operation
golitex copied to clipboard

`%` bug

Open kidherofun opened this issue 2 months ago • 3 comments

(1 ^ 2 + 2 ^ 2 + 3 ^ 2 + 4 ^ 2 + 5 ^ 2 + 6 ^ 2 + 7 ^ 2 + 8 ^ 2 + 9 ^ 2) % 10 works well.

But the following code is not:

claim:
    forall n Z:
        sum = 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + 4 ^ 2 + 5 ^ 2 + 6 ^ 2 + 7 ^ 2 + 8 ^ 2 + 9 ^ 2
        digit_sum = sum % 10
        =>:
            digit_sum = 5
    prove:
        sum = 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 = 285
        digit_sum = 285 % 10 = 5

The Error from terminal is:

Error: failed :( line 7:
some atoms in the following fact are undeclared:
forall n Z:
    sum = (((((((((1 ^ 2) + (2 ^ 2)) + (3 ^ 2)) + (4 ^ 2)) + (5 ^ 2)) + (6 ^ 2)) + (7 ^ 2)) + (8 ^ 2)) + (9 ^ 2))
    digit_sum = (sum %!)(MISSING)
    =>:
        digit_sum = 5

kidherofun avatar Oct 14 '25 06:10 kidherofun

I'm not sure but it seems sum and digit_sum is not yet introduced in the context so you should write following:

claim:
    forall n, sum, digit_sum Z:
        sum = 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + 4 ^ 2 + 5 ^ 2 + 6 ^ 2 + 7 ^ 2 + 8 ^ 2 + 9 ^ 2
        digit_sum = sum % 10
        =>:
            digit_sum = 5
    prove:
        sum = 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 = 285
        digit_sum = 285 % 10
        digit_sum = 5

I think litex's forall X: Y means forall X s.t. Y

yuniruyuni avatar Oct 19 '25 11:10 yuniruyuni

claim: forall n, sum, digit_sum Z: sum = 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + 4 ^ 2 + 5 ^ 2 + 6 ^ 2 + 7 ^ 2 + 8 ^ 2 + 9 ^ 2 digit_sum = sum % 10 =>: digit_sum = 5 prove: sum = 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 = 285 digit_sum = 285 % 10 digit_sum = 5

Thank you. That works!

kidherofun avatar Oct 19 '25 11:10 kidherofun

@yuniruyuni THANK YOU! You are the first community participant who isn't known to our core team but has been answering questions under the Litex repository! We would love to get to know you better. Could you please share your email with us? Also, if you could say a few kind words about Litex that we could feature on our website as a community voice, we would greatly appreciate it! Thank you!

malloc-realloc avatar Oct 21 '25 15:10 malloc-realloc