Can I splice Symbols into Symbols? Returning None

47 views
Skip to first unread message

Nick

unread,
Jul 23, 2023, 4:41:19 AM7/23/23
to sympy
I am trying to expand my program that accelerates my ability to solve math and logical problems by hand by generating not too complicated problems to practice on. The use case of my program is demonstrated on my twitter and the working code is my github.

I think my issue lies at line like 40 and 43. 


As you can see, I can generate and display logical equations in LaTeX using binary literals. The trouble is expanding these simple generations into more complex expressions. I am trying to rewrite a new Symbol using previously generated Symbols by string slicing. 

-Nick 


Reference: 

Chang and Lee . Computer Science and Applied Mathematics. "Symbolic Logic and       
 
     Mechanical Theorem Proving." Academic Press, Inc. 1973. Page 13-15.

Tirthankar Mazumder

unread,
Jul 23, 2023, 5:20:12 AM7/23/23
to sy...@googlegroups.com
Not sure if it's relevant, but in line 41, you are returning the variable forumula whereas you assigned to formula in the line before. The same error is also on lines 44, 47, and 50.

Regards,
Tirthankar Mazumder

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/ca70ada2-e57e-4ed9-bf89-ddba72cf38b7n%40googlegroups.com.

Nick

unread,
Jul 23, 2023, 9:03:04 PM7/23/23
to sympy

Aaron Meurer

unread,
Jul 24, 2023, 2:26:56 PM7/24/23
to sy...@googlegroups.com
Your code kind of defeats the whole purpose of using SymPy. You are
creating one single Symbol that represents your entire expression.
Symbol is supposed to represent variables, and expressions should be
made with the various expression classes, like sympy.And, sympy.Or,
sympy.Implies, and sympy.Equivalent, or the equivalent logical
operators like & and |. If you have a single symbol named "x⟷y" then
you can't do anything with it, but if you have Equivalent(Symbol('x'),
Symbol('y')) then you can perform logical operations on it. See
https://docs.sympy.org/latest/modules/logic.html

As a general rule of thumb, if you find yourself doing mathematical
operations using string manipulation, that means you are using SymPy
wrong. SymPy is designed to do mathematical operations directly, and
doesn't work by operating on strings.

Aaron Meurer
Reply all
Reply to author
Forward
0 new messages