(x XOR a) + (x XOR b) + (x XOR c)
Can we simplify this further?
Here '+' is addition not a logical disjunction.
x, a, b, c are numbers.
Example :
x = 10 , a = 5 , b = 4 , c = 6
(10 XOR 5) + (10 XOR 4) + (10 XOR 6) = 41.
Related
can you use the Nat solver in agda-stdlib for proof by contradiction? In particular I have a gnarly bit of algebra I'd rather not do by hand, but I'm not sure how to use a solver to make my life easier. For reference this is the result I want to prove:
{n m : ℕ} → 3 + (n + (3 + (n + (3 + (n + n * (3 + n)))))) ≡ 1 + m + (1 + m + (1 + m + 0)) + 2 → ⊥
I have data representation of complex numbers, but I don't know how to multiply two complex numbers. Maybe, someone can help me?
(define (complex-num a b)
(cons a b))
(define (real x)
(car x))
(define (imag x)
(cdr x))
Let's try to multiply two complex numbers
(a + bi) * (c + di) = (a + bi) * c + (a + bi) * di
= ac + bci + adi + bdii
= ac + bci + adi - bd (here we use that i*i = -1)
= ac-bd + (bc+ad)i
If we put z1=a+bi and z2=c+di then we can translate this to Scheme:
(define (multiply z1 z2)
(let ([a (real z1)]
[b (imag z1)]
[c (real z2)]
[d (imag z2)])
(complex-num ..compute ac-bd.. ..compute bc+ad.. )))
(define (complex-mult a b)
(make-rectangular (- (* (real-part a) (real-part b)) (* (imag-part a) (imag-part b)))
(+ (*(real-part a) (imag-part b)) (*(real-part b) (imag-part a)))))
e,g:
]=> (complex-mult 2+3i 5+2i)
;Value: 4+19i
]=> (complex-mult -i +i)
;Value: 1
I want to make a definition in Isabelle which returns all the pairs of a map function.
I have the following definition in Z
\begin{schema}[X, Y, Z]
allPairs: (X \pfun (Y \rel Z)) \fun (Y \rel Z)
where
\<forall f: (X \<pfun (Y \rel Z)) #
allPairs f == \<bigcup{x:X | x \in \dom f # fx}
\end{schema}
Therefore I want to make a definition which takes an element of type
(X \<rightharpoonup> ((Y * Z) set))) or (X \<rightharpoonup> (Y \<rightharpoonup> Z)) in isabelle and return ((Y * Z) set) for both.
I have the following so far
definition allPairs ::
"('X \<rightharpoonup ('Y * 'Z) set) => ('Y * 'Z) set"
where
"allPairs f == ⋃{yz. yz ∈ ran f}"
I am trying to find the modulo of an expression. All I know is that
(a+b) mod N = ((a mod N) + (b mod N)) mod N
How do I use it to simplify the following modulo operation?
(a - 2*b + 1) mod N
There must be some way to simplify it by considering it as
(a - b - b + 1) mod N ?
EDIT:
I have stumbled upon the following property too:
ab mod N = ((a mod N) (b mod N)) mod N
Will this be helpful somehow?
If: (a+b) mod N = ((a mod N) + (b mod N)) mod N
then:
(a - 2*b + 1) mod N = ((a mod N) - (b mod N) - (b mod N) + (1 mod N)) mod N
It is simpler with large values of a and b and a small value for N.
For example: a=85773, b = 77733340, N=5:
which would you rather solve
(85773 - 77733340 - 77733340 + 1) mod 5
or
((85773 mod 5) - (77733340 mod 5) - (77733340 mod 5) + (1 mod 5)) mod 5
for the second one i get (3 - 0 - 0 + 1) % 5 = 4
There is no way to simplify (b*-2 + a + 1) % n unfortunately.
I am taking a course on the formal foundations of programming, one of things we have covered is proving certain properties of languages, i have done most of the work, but I am stuck on these two questions, as I have no idea how to prove them.
they are as follows:
A ^ (B ^ C) = (A ^ B) ^ C (which I believe is the associative rule)
A ^ (B U C) = (A ^ B) U ( A ^ C) (Distribution rule)
In these examples i have used the ^ to mean concatenation
First
A^B is all the words x such that there is v in A and w in B such that x = vw
let's prove A^(B^C) is included into (A^B)^C
The A^(B^C) is all the words x such that there is v in A and w in B^C
such that x=vw
and w = lm where l is in B and m is in C then x=vlm
x=(vl)m =v(lm) since vl is in A^B qnd m is in C then x is in (A^B)^C.
then A^(B^C) is included into (A^B)^C.
Same proof for inverse inclusion
then A^(B^C) =(A^B)^C
Second:
x in B U C if and only if x is in B or x is in C.
first inclusion:
if x in A ^ (B U C)
then x = vw where v in A and w in B or C
Then x is in A^B or A^C
then x is in (A ^ B) U ( A ^ C)
second inclusion
if x is in (A ^ B) U ( A ^ C)
then x = vw with v in A and w in B or x =vw with with v in A and w in
C
then since v is always is A
then x = vw where v in A and w in B or C
x in A ^ (B U C)
Therefore A ^ (B U C) = (A ^ B) U ( A ^ C)