{"id":27683,"date":"2022-08-15T23:59:14","date_gmt":"2022-08-15T18:29:14","guid":{"rendered":"https:\/\/python-programs.com\/?p=27683"},"modified":"2022-08-15T23:59:14","modified_gmt":"2022-08-15T18:29:14","slug":"python-sympy-expand_log-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-sympy-expand_log-method\/","title":{"rendered":"Python sympy.expand_log() Method"},"content":{"rendered":"
Python SymPy Module:<\/strong><\/p>\n SymPy is a Python\u00a0symbolic mathematics<\/strong>\u00a0library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library for arbitrary floating-point arithmetic.<\/p>\n Rational and Integer are the numerical types defined by SymPy. A rational number is represented by the Rational class as a pair of two Integers, numerator and denominator, therefore Rational(1, 2) is 1\/2, Rational(3, 2) is 3\/2, and so on. Integer numbers are represented by the Integer class.<\/p>\n SymPy uses mpmath in the background, allowing it to execute arbitrary-precision arithmetic computations. Some special constants, such as exp, pi, and oo (Infinity), are thus considered as symbols and can be evaluated with arbitrary precision.<\/p>\n Installation:<\/strong><\/p>\n Python sympy.expand_log() Method:<\/strong><\/p>\n We can use expand_log() function of the sympy module to simplify the log terms in the mathematical equation by employing the properties stated below:<\/p>\n Syntax:<\/strong><\/p>\n Return Value:<\/strong><\/p>\n The simplified mathematical expression is returned by the expand_log() function.<\/p>\n Example1<\/strong><\/p>\n Here it gives the result based on the log(x*y)=log(x)+log(y)<\/strong> property.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2<\/strong><\/p>\n Here it gives the result based on the log(x**n)=nlog(x)<\/strong>\u00a0property.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Python SymPy Module: SymPy is a Python\u00a0symbolic mathematics\u00a0library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library …<\/p>\npip install sympy<\/pre>\n
\n
sympy.expand_log()<\/pre>\n
sympy.expand_log() Method in Python<\/h2>\n
\n
# Import all the functions from sympy module using the import keyword\r\nfrom sympy import *\r\n# Pass the symbols to be used and set positive as True as arguments to the \r\n# symbols() function and store them in corresponding variables.\r\na, b, c = symbols('a b c', positive = True)\r\n# Give the mathematical expression as static input and store it in a variable.\r\ngvn_expression = log(a * b)\r\n \r\n# Pass the above given expression as an argument to the expand_log() method \r\n# to simplify the log terms in the given expression based on the properties given.\r\n# Store it in another variable.\r\nrslt = expand_log(gvn_expression)\r\n\r\n# Print the result after the simplification of log terms in the given expression.\r\nprint(rslt)<\/pre>\n
log(a) + log(b)<\/pre>\n
\n
# Import all the functions from sympy module using the import keyword\r\nfrom sympy import *\r\n# Pass the symbols to be used and set set positive as True as arguments to the \r\n# symbols() function and store them in corresponding variables.\r\na, b, c = symbols('a b c', positive = True)\r\n# Give the mathematical expression as static input and store it in a variable.\r\ngvn_expression = log(b**2)\r\n \r\n# Pass the above given expression as an argument to the expand_log() method \r\n# to simplify the log terms in the given expression based on the properties given.\r\n# Here it gives the result based on the log(x**n)=nlog(x)\u00a0property.\r\n# Store it in another variable.\r\nrslt = expand_log(gvn_expression)\r\n\r\n# Print the result after the simplification of log terms in the given expression.\r\nprint(rslt)<\/pre>\n
2*log(b)<\/pre>\n","protected":false},"excerpt":{"rendered":"