Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:57:04+00:00 2026-05-15T20:57:04+00:00

suppose i a have a multiplicative expression with lots of multiplicands (small expressions) expression

  • 0

suppose i a have a multiplicative expression with lots of multiplicands (small expressions)

expression = a*b*c*d*....*w   

where for example c is (x-1), d is (y**2-16), k is (xy-60)….. x,y are numbers
and i know that c,d,k,j maybe zero
Does the order i write the expression matters for faster evaluation?
Is it better to write c
dkj….*w or python will evaluate all expression no matter the order i write?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:57:05+00:00Added an answer on May 15, 2026 at 8:57 pm

    Python v2.6.5 does not check for zero values.

    def foo():
        a = 1
        b = 2
        c = 0
        return a * b * c
    
    >>> import dis
    >>> dis.dis(foo)
      2           0 LOAD_CONST               1 (1)
                  3 STORE_FAST               0 (a)
    
      3           6 LOAD_CONST               2 (2)
                  9 STORE_FAST               1 (b)
    
      4          12 LOAD_CONST               3 (3)
                 15 STORE_FAST               2 (c)
    
      5          18 LOAD_FAST                0 (a)
                 21 LOAD_FAST                1 (b)
                 24 BINARY_MULTIPLY     
                 25 LOAD_FAST                2 (c)
                 28 BINARY_MULTIPLY     
                 29 RETURN_VALUE        
    

    Update: I tested Baldur‘s expressions, and Python can and will optimize code that involve constant expressions. The weird is that test6 isn’t optimized.

    def test1():
        return 0 * 1
    
    def test2():
        a = 1
        return 0 * a * 1
    
    def test3():
        return 243*(5539**35)*0
    
    def test4():
        return 0*243*(5539**35)
    
    def test5():
        return (256**256)*0
    
    def test6():
        return 0*(256**256)
    
    >>> dis.dis(test1) # 0 * 1
      2           0 LOAD_CONST               3 (0)
                  3 RETURN_VALUE       
    
    >>> dis.dis(test2) # 0 * a * 1
      5           0 LOAD_CONST               1 (1)
                  3 STORE_FAST               0 (a)
    
      6           6 LOAD_CONST               2 (0)
                  9 LOAD_FAST                0 (a)
                 12 BINARY_MULTIPLY     
                 13 LOAD_CONST               1 (1)
                 16 BINARY_MULTIPLY     
                 17 RETURN_VALUE        
    
    >>> dis.dis(test3) # 243*(5539**35)*0
      9           0 LOAD_CONST               1 (243)
                  3 LOAD_CONST               5 (104736434394484...681759461305771899L)
                  6 BINARY_MULTIPLY     
                  7 LOAD_CONST               4 (0)
                 10 BINARY_MULTIPLY     
                 11 RETURN_VALUE        
    
    >>> dis.dis(test4) # 0*243*(5539**35)
     12           0 LOAD_CONST               5 (0)
                  3 LOAD_CONST               6 (104736433252667...001759461305771899L)
                  6 BINARY_MULTIPLY     
                  7 RETURN_VALUE        
    
    >>> dis.dis(test5) # (256**256)*0
     15           0 LOAD_CONST               4 (0L)
                  3 RETURN_VALUE        
    
    >>> dis.dis(test6) # 0*(256**256)
     18           0 LOAD_CONST               1 (0)
                  3 LOAD_CONST               3 (323170060713110...853611059596230656L)
                  6 BINARY_MULTIPLY     
                  7 RETURN_VALUE        
    

    In brief, if the expression includes variables, the order doesn’t matter. Everything will be evaluated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a process that is updating a record and encounters a record
Suppose I have a class that represents a product to be priced using one
Suppose I have an executable JAR that launches a Swing GUI. If it is
For example, suppose I have: x = array([1, 2, 3]) y = array([4, 5,
Suppose I have this animation that start at some point : myElement.animate({ top: -currentTempImageX,
Suppose I have a table like the following: tblNumbers Numbers 4 5 3 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.