Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78752 > unrolled thread

Representing mathematical equations

Started byvarun7rs@gmail.com
First post2014-10-06 04:13 -0700
Last post2014-10-06 11:06 -0700
Articles 11 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Representing mathematical equations varun7rs@gmail.com - 2014-10-06 04:13 -0700
    Re:Representing mathematical equations Dave Angel <davea@davea.name> - 2014-10-06 08:50 -0400
    Re: Representing mathematical equations varun7rs@gmail.com - 2014-10-06 06:03 -0700
      Re: Representing mathematical equations varun7rs@gmail.com - 2014-10-06 06:07 -0700
        Re: Representing mathematical equations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-06 15:10 +0100
        Re: Representing mathematical equations Michael Torrie <torriem@gmail.com> - 2014-10-06 08:42 -0600
          Re: Representing mathematical equations Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-06 16:45 +0000
            Re: Representing mathematical equations Michael Torrie <torriem@gmail.com> - 2014-10-06 20:07 -0600
        Re: Representing mathematical equations Dave Angel <davea@davea.name> - 2014-10-06 13:24 -0400
          Re: Representing mathematical equations Rustom Mody <rustompmody@gmail.com> - 2014-10-06 10:48 -0700
            Re: Representing mathematical equations Rustom Mody <rustompmody@gmail.com> - 2014-10-06 11:06 -0700

#78752 — Representing mathematical equations

Fromvarun7rs@gmail.com
Date2014-10-06 04:13 -0700
SubjectRepresenting mathematical equations
Message-ID<9ea5c61c-9f06-4bcb-982e-2be0a910b817@googlegroups.com>
Hello,

I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out?

The equation looks like this

b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]]  / Σ(l∈L) l

I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x)

i,x,l are sets with different numbers

Thank You
I'm sorry if the equation is not expressed in a standard form. I don't have LateX

[toc] | [next] | [standalone]


#78753

FromDave Angel <davea@davea.name>
Date2014-10-06 08:50 -0400
Message-ID<mailman.14634.1412599694.18130.python-list@python.org>
In reply to#78752
varun7rs@gmail.com Wrote in message:
> Hello,
> 
> I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out?
> 
> The equation looks like this
> 
> b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]]  / Σ(l∈L) l
> 
> I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x)
> 
> i,x,l are sets with different numbers
> 

Perhaps you meant  L is a set of numbers,  none repeated.  If you
 really meant l, I have no clue.

As for i and x, they don't appear on the right side so they're a
 red herring. 

I also don't know what bd, dist, and hc are. Are they each a
 function of a single number? Or are they vectors,  indexed by
 int? If so, then presumably L is a set of ints.

How about you express some sample data that you'd like to
 evaluate. For example,  start with
   L = set (1, 4, 3)
   bd = [4.3, 12.11, 93, -0.9, 42]
.....



> I'm sorry if the equation is not expressed in a standard form. I don't have LateX

No problem,  you did a good job expressing it in unicode in a text
 message. 

Ii Ll  1

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#78754

Fromvarun7rs@gmail.com
Date2014-10-06 06:03 -0700
Message-ID<09669ac4-1aeb-48fa-8cc9-7f741f7fe6b3@googlegroups.com>
In reply to#78752
On Monday, 6 October 2014 13:14:04 UTC+2, varu...@gmail.com  wrote:
> Hello,
> 
> 
> 
> I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out?
> 
> 
> 
> The equation looks like this
> 
> 
> 
> b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]]  / Σ(l∈L) l
> 
> 
> 
> I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x)
> 
> 
> 
> i,x,l are sets with different numbers
> 
> 
> 
> Thank You
> 
> I'm sorry if the equation is not expressed in a standard form. I don't have LateX

Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links...
b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i

Thank You

[toc] | [prev] | [next] | [standalone]


#78756

Fromvarun7rs@gmail.com
Date2014-10-06 06:07 -0700
Message-ID<28aeb1c6-2a2f-4452-862d-c98b204eab34@googlegroups.com>
In reply to#78754
On Monday, 6 October 2014 15:03:44 UTC+2, varu...@gmail.com  wrote:
> On Monday, 6 October 2014 13:14:04 UTC+2, varu...@gmail.com  wrote:
> 
> > Hello,
> 
> > 
> 
> > 
> 
> > 
> 
> > I am working on a mathematical equation which I'm finding really hard to express in python. Could any of you spare some time to help me out?
> 
> > 
> 
> > 
> 
> > 
> 
> > The equation looks like this
> 
> > 
> 
> > 
> 
> > 
> 
> > b(i,x) = [Σ(l∈L) [bd(l) * dist(l) * hc(l)]]  / Σ(l∈L) l
> 
> > 
> 
> > 
> 
> > 
> 
> > I have a problem in representing the above equation. I don't know how to use teh loops over here to express b(i,x)
> 
> > 
> 
> > 
> 
> > 
> 
> > i,x,l are sets with different numbers
> 
> > 
> 
> > 
> 
> > 
> 
> > Thank You
> 
> > 
> 
> > I'm sorry if the equation is not expressed in a standard form. I don't have LateX
> 
> 
> 
> Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links...
> 
> b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i
> 
> 
> 
> Thank You

Unbelievable. I again forgot to express them

L  = [(1,3), (5,7), .....]
bd = [23, 34,43.44.....]
dist = [3,7,5,7, ....]
hc = [2,3,4,1,2,2,...]
for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7

[toc] | [prev] | [next] | [standalone]


#78759

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-06 15:10 +0100
Message-ID<mailman.14638.1412604906.18130.python-list@python.org>
In reply to#78756
On 06/10/2014 14:07, varun7rs@gmail.com wrote:

[snip 69 lines]

> L  = [(1,3), (5,7), .....]
> bd = [23, 34,43.44.....]
> dist = [3,7,5,7, ....]
> hc = [2,3,4,1,2,2,...]
> for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7
>

Would you please access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing the double line spacing and single line paragraphs that I've 
snipped above, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#78766

FromMichael Torrie <torriem@gmail.com>
Date2014-10-06 08:42 -0600
Message-ID<mailman.14645.1412607549.18130.python-list@python.org>
In reply to#78756
On 10/06/2014 07:07 AM, varun7rs@gmail.com wrote:
>> Okay, I forgot to explain them. L is a set of links, dist is a
>> number (distance), bd is the bandwidth and hc is a number as well
>> (hopcount)...different bandwidths, hopcounts and distances for different
>> links... b(i,x) is what i intend to calculate out of these details...here
>> 'i'could be the head or tail of the link l and x is a node that hosts i
>> Thank You
> 
> Unbelievable. I again forgot to express them
> L  = [(1,3), (5,7), .....]
> bd = [23, 34,43.44.....]
> dist = [3,7,5,7, ....]
> hc = [2,3,4,1,2,2,...]
> for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7

You might want to ask on the scipy mailing list[1].  I'm sure the folks
over there deal with complex sums and math all the time.  Numpy
(standalone, or as part of scipy) has some facilities for working with
vectors, products, and summations in an efficient manner.

[1] http://mail.scipy.org/mailman/listinfo/scipy-user

[toc] | [prev] | [next] | [standalone]


#78771

FromPeter Pearson <pkpearson@nowhere.invalid>
Date2014-10-06 16:45 +0000
Message-ID<c9fv8jF4j2tU1@mid.individual.net>
In reply to#78766
On Mon, 06 Oct 2014 08:42:01 -0600, Michael Torrie <torriem@gmail.com> wrote:
> On 10/06/2014 07:07 AM, varun7rs@gmail.com wrote:
>>> Okay, I forgot to explain them. L is a set of links, dist is a
>>> number (distance), bd is the bandwidth and hc is a number as well
>>> (hopcount)...different bandwidths, hopcounts and distances for different
>>> links... b(i,x) is what i intend to calculate out of these details...here
>>> 'i'could be the head or tail of the link l and x is a node that hosts i
>>> Thank You
>> 
>> Unbelievable. I again forgot to express them
>> L  = [(1,3), (5,7), .....]
>> bd = [23, 34,43.44.....]
>> dist = [3,7,5,7, ....]
>> hc = [2,3,4,1,2,2,...]
>> for every l belonging to L, i could be either 1 or 3 for L[0], similarly 
>> for L[1] it could be 5 or 7
>
> You might want to ask on the scipy mailing list[1].  I'm sure the folks
> over there deal with complex sums and math all the time.  Numpy
> (standalone, or as part of scipy) has some facilities for working with
> vectors, products, and summations in an efficient manner.

I don't think the OP is interested in complex numbers.  I think this
is a question about organizing loops.  But I can't tell for sure.

My guess is that l is one of the pairs in L, and that i is one of the
elements in l, or perhaps both in succession.  OP hints that "x is a
node that hosts i", but how that affects the right-hand side of the
equation defining the quantity to be computed, which is lost in the
history of this thread, is unclear.

There's a lesson here for the OP, varun7rs: If your initial query
had been clear and complete, you would have your answer by now.

-- 
To email me, substitute nowhere->runbox, invalid->com.

[toc] | [prev] | [next] | [standalone]


#78787

FromMichael Torrie <torriem@gmail.com>
Date2014-10-06 20:07 -0600
Message-ID<mailman.14654.1412647637.18130.python-list@python.org>
In reply to#78771
On 10/06/2014 10:45 AM, Peter Pearson wrote:
> I don't think the OP is interested in complex numbers.  I think this
> is a question about organizing loops.  But I can't tell for sure.

Poor choice of words on my part. I meant complicated.  This is exactly
the kind of thing that people use numpy and other libraries to assist
with.  Right up scipy's alley.

[toc] | [prev] | [next] | [standalone]


#78776

FromDave Angel <davea@davea.name>
Date2014-10-06 13:24 -0400
Message-ID<mailman.14650.1412616149.18130.python-list@python.org>
In reply to#78756
varun7rs@gmail.com Wrote in message:
> On Monday, 6 October 2014 15:03:44 UTC+2, varu...@gmail.com  wrote:
>

(Deleted all the 8-space quoting. Either use a better email client
 or remove the extra 7 lines between every line you
 quote.)

>> 
>> Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links...
>> 
>> b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i

> 
> Unbelievable. I again forgot to express them
> 
> L  = [(1,3), (5,7), .....]
> bd = [23, 34,43.44.....]
> dist = [3,7,5,7, ....]
> hc = [2,3,4,1,2,2,...]
> for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7

Now it's clear I don't have a clue. L is either a set or a list.
 Little l is an element of that set, and is either a tuple or is
 mysteriously subscripted by a boolean at the other end of the
 expression. ..

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#78779

FromRustom Mody <rustompmody@gmail.com>
Date2014-10-06 10:48 -0700
Message-ID<381deb51-46e8-480c-9c9b-cf63ebe303c5@googlegroups.com>
In reply to#78776
On Monday, October 6, 2014 10:52:40 PM UTC+5:30, Dave Angel wrote:
> varun7rs Wrote in message:
> > On Monday, 6 October 2014 15:03:44 UTC+2, Varun  wrote:

> (Deleted all the 8-space quoting. Either use a better email client
>  or remove the extra 7 lines between every line you
>  quote.)

> >> Okay, I forgot to explain them. L is a set of links, dist is a number (distance), bd is the bandwidth and hc is a number as well (hopcount)...different bandwidths, hopcounts and distances for different links...
> >> b(i,x) is what i intend to calculate out of these details...here 'i' could be the head or tail of the link l and x is a node that hosts i

> > Unbelievable. I again forgot to express them
> > L  = [(1,3), (5,7), .....]
> > bd = [23, 34,43.44.....]
> > dist = [3,7,5,7, ....]
> > hc = [2,3,4,1,2,2,...]
> > for every l belonging to L, i could be either 1 or 3 for L[0], similarly for L[1] it could be 5 or 7

> Now it's clear I don't have a clue. L is either a set or a list.
>  Little l is an element of that set, and is either a tuple or is
>  mysteriously subscripted by a boolean at the other end of the
>  expression. ..

As Dave says there are too many loose ends in your spec to make much sense.

Anyway heres a small start to help you start off --
both for cleaning up your spec as well as moving towards an implementation

Take your denominator term: Σ(l∈L) l

You also say "i could be head or tail of l"
Dunno what to make of that 'or'... Toss a coin and choose??

So here are two version that will calculate the denominator for head and for tail

>>> L  = [(1,3), (5,7)]

>>> sum(x for (x,y) in L)
6
>>> sum(y for (x,y) in L)
10

If you need to examine the sub-expressions (always a good idea!), use

>>> (x for (x,y) in L)
<generator object <genexpr> at 0x7fe04025c730>

Whazzat?

>>> list(x for (x,y) in L)
[1, 5]

Or just simply
>>> [x for (x,y) in L]
[1, 5]

You can use that literally in the sum

>>> sum([x for (x,y) in L])
6


>>> sum([(x,y) for (x,y) in L])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

Python just expressing that you are goofing off by trying to add tuples
rather than numbers

>>> sum([l for l in L])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

Same as above

[toc] | [prev] | [next] | [standalone]


#78781

FromRustom Mody <rustompmody@gmail.com>
Date2014-10-06 11:06 -0700
Message-ID<ed6684c3-5094-4ef5-8e6d-4f2fd0ef6953@googlegroups.com>
In reply to#78779
On Monday, October 6, 2014 11:18:55 PM UTC+5:30, Rustom Mody wrote:

> >>> sum([(x,y) for (x,y) in L])
> Traceback (most recent call last):
> TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

> Python just expressing that you are goofing off by trying to add tuples
> rather than numbers

I forgot to mention that this comes from just taking your
denominator
term  "Σ(l∈L) l" literally.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web