问题描述
我想将逻辑公式转换为数组并使用它们进行计算。 首先,它应该输入情况的数量。然后给出公式的名称。然后是公式的值,例如:
PQ ~PQ P~Q ~P~Q
one circumstance: p = a u a u
two circumstances: p&q= A N N N
...
我希望在给定的情况下像二叉树一样定义数组的形状,因为公式的值在公式的每个n ^ 2位置上可以相同,如p = au- au之前。
我尝试了此操作,但是我不知道如何将数组的值定义为3个(或更多)可能的值('a','u','n',...)。
最好遍历数组以输入值并例如将公式的第二个值设置为相同(p = au-au)。我不知道该怎么做,也不知道是否可能。
我也不知道这是否完全是“正确”的方法。我几乎是编程新手。
此后,程序应计算给定公式的结论。该算法机械简便。但是,我不知道如何对数组进行处理以及如何对计算进行概括。如果您有兴趣,这里是更多信息:
也许我的下一个目标是使用这些公式以及这种计算方式进行计算的主页。
import numpy as np
import pdb; pdb.set_trace()
def array_zero_number_name_fn(number_circumstances_int):
if number_circumstances_int == 1:
a = np.zeros((2),np.dtype=({'names':['a','u','n'],'formats':['S1',np.uint8]}))
b = 1
c = input('Name the logical formula!')
input_gf_fn(a,b)
return(a,b,c)
elif number_circumstances_int == 2:
a = np.zeros((2,2),np.dtype({'names':['a',np.uint8]}))
b = 2
c = input('Name the logical formula!')
input_gf_fn(a,c)
def input_gf_fn(a,c):
if b == 1:
a[0] = input('Please type value of circumstance of logic formula!')
a[1] = input('Please type value of complement-circumstance of logical formula!')
elif b == 2:
a[0,0] = input('Please type value 1 of logic formula!')
a[0,1] = input('Please type value 2 of logic formula!')
a[1,0] = input('Please type value 3 of logic formula!')
a[1,1] = input('Please type value 4 of logic formula!')
print(a)
return(0)
number_circumstances_str = input('How many circumstances should your formula have?')
number_circumstances_int = int(number_circumstances_str)
array_zero_and_number = array_zero_number_name_fn(number_circumstances_int)
array_zero = array_zero_and_number[0]
name = array
print(array_zero)
number = array_zero_and_number[1]
input_gf = input_gf_fn(array_zero,number,name)
print(input_gf)
input('Exit with Enter!')
´´´
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)