By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

[noob] Questions about mathematical signs...

P: n/a
Hi! I'm programming maths programs.
And I got some questions about mathematical signs.

1. Inputing suqare like a * a, It's too long when I do time-consuming
things. Can it be simplified?

2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?

3. How can i input root?

thx 4 reading :)
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote:
Hi! I'm programming maths programs.
And I got some questions about mathematical signs.

1. Inputing suqare like a * a, It's too long when I do time-consuming
things. Can it be simplified?
You can write powers with the "**" operator. In this case,
a ** 2
2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?
Because of the rules of operator precedence,
a / b + c / d
has the same meaning as the expression you gave.
3. How can i input root?


Assuming that you've already executed
import math
Here are some ways to find the square root of a number:
math.sqrt(4)
4 ** .5
math.pow(4, .5)

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCBoFaJd01MZaTXX0RAn7rAJwOcK9AjS6/LRgV8iTFxJTvI1tcnQCgl1N2
LwASOyZQxrYZ5dyHqrvkqH8=
=wzmg
-----END PGP SIGNATURE-----

Jul 18 '05 #2

P: n/a
administrata wrote:
Hi! I'm programming maths programs.
And I got some questions about mathematical signs.

1. Inputing suqare like a * a, It's too long when I do time-consuming
things. Can it be simplified?
You mean you have to write a*a*a*a when you want the fourth power? You
need the exponentiation operator ** :
for i in range(6): ... print 2 ** i
...
1
2
4
8
16
32
2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?
Surely you jest. Can you suggest a simplification, or have you come
across one in some other language?
3. How can i input root?
Fractional exponents give you roots (sorry about the tiring division):
for i in range(1,7):

... print i, 64 ** (1.0/i)
...
1 64.0
2 8.0
3 4.0
4 2.82842712475
5 2.29739670999
6 2.0
thx 4 reading :)


regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
Jul 18 '05 #3

P: n/a
Jeff Epler wrote:
On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote:
Hi! I'm programming maths programs.
And I got some questions about mathematical signs. .... 2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?


Because of the rules of operator precedence,
a / b + c / d
has the same meaning as the expression you gave.


And it's important to note that that meaning will change in version
3.0. Until then, it's best to start every module with "from __future__
import division".

Jul 18 '05 #4

P: n/a
"Dan Bishop" <da*****@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Jeff Epler wrote:
On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote:
Hi! I'm programming maths programs.
And I got some questions about mathematical signs. ... 2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?


Because of the rules of operator precedence,
a / b + c / d
has the same meaning as the expression you gave.


And it's important to note that that meaning will change in version
3.0. Until then, it's best to start every module with "from __future__
import division".


You're right, of course, but that's like offering advice about how to shift
gears on a bicycle to someone who hasn't even figured out where the pedals
are yet! ;-)
--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.

Jul 18 '05 #5

P: n/a
In article <v0wNd.104851$Jk5.6276@lakeread01>,
Steve Holden <st***@holdenweb.com> wrote:
2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?


Can't this just be written as a/b+c/d ? How much simpler can it get?
I would think you need at least one symbol per operation (ignoring
possible algebraic simplifications and transformations for some
expressions).

-- Lou Pecora (my views are my own)
Jul 18 '05 #6

P: n/a
Steve Holden <st***@holdenweb.com> wrote in message news:<v0wNd.104851$Jk5.6276@lakeread01>...
administrata wrote:
Hi! I'm programming maths programs.
And I got some questions about mathematical signs.

1. Inputing suqare like a * a, It's too long when I do time-consuming
things. Can it be simplified?

You mean you have to write a*a*a*a when you want the fourth power? You
need the exponentiation operator ** :
>>> for i in range(6): ... print 2 ** i
...
1
2
4
8
16
32
2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
Can it be simplified?

Surely you jest. Can you suggest a simplification, or have you come
across one in some other language?
3. How can i input root?

Fractional exponents give you roots (sorry about the tiring division):
>>> for i in range(1,7):

... print i, 64 ** (1.0/i)
...
1 64.0
2 8.0
3 4.0
4 2.82842712475
5 2.29739670999
6 2.0
thx 4 reading :)


regards
Steve


Helpful! :)
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.