significant bit 有效位
bitwise 按位
基础知识
算法
bit-blastting
incremental bit-blastting
应用
Fermat’s last theorem
基础知识
算法
Array Reduction Algorithm
P1 = eliminate all array write: store(A, i, x);
P2 = replace ?x.P1(x) with P1(y); // y is fresh
P3 = replace ?x.P2(x) with P2(i)/…/\P2(k);
P4 = eliminate array read in P3: A[i];
应用
lambda 函数
语法
lambda 参数列表: 表达式
参数可以有多个,但只能有一个表达式
使用 lambda 函数实现 array 接口
def lambda_array():
def array_new():
return lambda x: 0
# array[index]
def array_select(array, index):
return array(index)
# array[index] = element
def array_store(array, index, element):
# exercise 16: write code to store an "element" into the
# "index" position of "array" by using lambda expression.
return lambda x: element if x == index else array(x)
# a small test case
arr = array_new()
assert(array_select(array_store(array_store(arr, 5, 88), 7, 99), 5) == 88)
assert(array_select(array_store(array_store(arr, 5, 88), 7, 99), 17) == 0)
assert (array_select(array_store(array_store(arr, 5, 88), 5, 99), 5) == 88)
print("\033[32mSUCCESS!\033[0m")