[noob] Questions about mathematical signs...

A

administrata

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 :)
 
J

Jeff Epler

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-----
 
S

Steve Holden

administrata said:
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 ** :
... 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):
... 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
 
D

Dan Bishop

Jeff said:
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".
 
R

Russell Blau

Dan Bishop said:
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! ;-)
 
L

Lou Pecora

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

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)
 
A

administrata

Steve Holden said:
You mean you have to write a*a*a*a when you want the fourth power? You
need the exponentiation operator ** :

... print 2 ** i
...
1
2
4
8
16
32

Surely you jest. Can you suggest a simplification, or have you come
across one in some other language?

Fractional exponents give you roots (sorry about the tiring division):

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


regards
Steve

Helpful! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top