Hello Aaron,

I tried both your suggestions but it stil doesn't work.

I even simplified the code and the data to look for the problem. But still, 
I get the attributeerror: 'str' object has no attribute 'atoms'

Any idea?

I would appreciate any help.

Anália

-----------------------------------------------------------------------------------------------------------------------------------------------------

import sympy
from sympy.core import Symbol
from sympy.logic.inference import satisfiable
import re

a = Symbol('a')
b = Symbol('b')
c = sympy.Symbol('c')
d = sympy.Symbol('d')
e = sympy.Symbol('e')
f = sympy.Symbol('f')
g = sympy.Symbol('g')
h = sympy.Symbol('h')
i = sympy.Symbol('i')
j = sympy.Symbol('j')
k = sympy.Symbol('k')


# open file
file=open ("b.txt","r")

for line in file:
    myrules.append([str(n) for n in line.strip().split('\t')])
            
for pair in myrules:
    try:
        x,y = pair[0],pair[1]        
        print(y)        
        print(satisfiable(y))          
    except IndexError:
        print("A line in the file doesn't have enough entries.")

# Close the file
file.close()

--------------------------------------------------------------------------------------------------------------------
b.txt

x    (a) & b
y    ((a & b) | c | d) & e
z    (a) & b



On Thursday, November 15, 2012 10:47:52 AM UTC, Aaron Meurer wrote:
>
> Your dictionary m needs to contain the actual symbols themselves, not 
> their string names.  So you need to do m = {0: a, 1:b, ...} (not {0: 'a', 
> 1:'b', ...}).  Alternately, when you call m, wrap the string in Symbol, 
> like Symbol(m[i]) (instead of just a bare m[i]).
>
> Aaron Meurer
>
>
> On Thu, Nov 15, 2012 at 3:44 AM, faia <[email protected] 
> <javascript:>>wrote:
>
>> Hello all,
>>
>> I'm trying to use sympy.logic.inference, specifically the satisfiable 
>> function, to evaluate a large number of boolean expressions automatically.
>>
>> My rules look something like (b2314 AND b0089) AND (NOT b0089)
>> I substituted AND, OR and NOT by standard python operators &, | and ~
>>
>> I also mapped the names of the expression's variables into 'a', 'b', etc 
>> for simplicity
>>
>> a = Symbol('a')
>> b = Symbol('b')
>> c = sympy.Symbol('c')
>> d = sympy.Symbol('d')
>> e = sympy.Symbol('e')
>> f = sympy.Symbol('f')
>> g = sympy.Symbol('g')
>> h = sympy.Symbol('h')
>> i = sympy.Symbol('i')
>> j = sympy.Symbol('j')
>> k = sympy.Symbol('k')
>>
>> myrules = []
>>
>> m={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j',10:'k'}
>>
>> ...
>>
>> bnumber_pattern = re.compile(r"b\d{4}", re.IGNORECASE)
>>         
>>         if bnumber_pattern.search(y):
>>             bnumber_list=bnumber_pattern.findall(y)
>>             i=0
>>             for bnumber in bnumber_list:  
>>                 
>>                 print(bnumber)                
>>                 rpl_str=m[i]
>>                 print(rpl_str)
>>                 
>>                 y=y.replace(bnumber,rpl_str)                 
>>                 print(y)
>>                 
>>                 i+=1                          
>>             print(y)    
>>             print(satisfiable(y))   
>>
>>
>> So the above rule looks like (a & b) & (~b)
>>
>> But when running  print(satisfiable(y)) 
>> I get an exception: AttributeError: 'str' object has no attribute 'atoms'
>>
>> I don't know that much of sympy or python to understand what I am doing 
>> wrong here.
>>
>> Could someone help me with this please?
>>
>> Regards,
>> Anália
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sympy" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/sympy/-/yJydX9zSLOEJ.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> [email protected] <javascript:>.
>> For more options, visit this group at 
>> http://groups.google.com/group/sympy?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sympy/-/d-L9csWgsPYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to