how can I return nothing?

R

Richard Tobin

Sign implies order:

a-b < 0 <=> a < b
[/QUOTE]
I don't see a sign there, just a two-argument "-".

Sorry, I was unclear. I should resist posting late at night.

The sign of a-b gives you an ordering of a and b.

So if, for example, we say that the sign of x+iy is the sign of x, we
get an ordering the same as the ordering of the real part.

-- Richard
 
R

Richard Heathfield

Peter J. Holzer said:
No. To be able to say that one element of a set is "less than" another
element of a set, you must have defined an order between the elements.
That's independent of whether these elements have a sign or not.

I didn't claim otherwise. Your "no" is misplaced. I didn't introduce "less
than" into this thread, and neither did I introduce "order". All I did was
object to the claim "there is no such think as nonnegative complex number
(or nonpositive for that matter)".
(For
example, the values representable in an "unsigned int" have an order,
but they have no sign).

So they are wholly inappropriate to this subthread, which is concerned with
sign, not order.
So you agree that there is no such thing as a non-negative complex
number?

Not at all. For example, I would argue that the complex number {0, 0} is
non-negative (and non-positive, for that matter).
 
R

Richard Heathfield

Army1987 said:
Are you suggesting to use the lexicographic order on the complex
numbers?

No. I don't care what order you place the complex numbers in. I'm talking
about sign, not order. It is clear to me that the ordering of complex
numbers is up to the orderer.
 
R

Richard Heathfield

Richard Tobin said:
And two signs?
No.

Indeed.
Fine. Given struct foo { int a; int b; } x = { -2, 2 }, y = { 2, -2 };

which comes first, x or y?

Tell me the (single) sign of {a,b} and I'll tell you the order.[/QUOTE]

It doesn't /have/ a single sign. It has two signs. That doesn't mean it
*can't* be non-negative or non-positive, however, and that's the claim I
was rebutting.
 
R

Richard Heathfield

Tor Rustad said:
Richard Heathfield wrote:

I think you picture a single real axis.

In theoretical physics (e.g. special relativity), we rather use 3 such
axis (x, y and z), as well as an imaginary axis for time.

If you want to talk about that, that's fine, but that's not what I'm
talking about.

Now, please name a mathematician who think that your "sign of z":

Not mine. AFAICR I haven't even mentioned a "sign of z".
sign(z) = Re(z) / |Re(z)|

What happened to the sign of the imaginary component?
 
K

Keith Thompson

Tor Rustad said:
Now, please name a mathematician who think that your "sign of z":

sign(z) = Re(z) / |Re(z)|

is a useful definition.

I can't name one, but it seems that some mathematicians do find it
useful. See <http://en.wikipedia.org/wiki/Sign_function>. No,
Wikipedia is not definitive, but it seems plausible in this case --
and I remember a "signum" function that does just this on my HP 48
calculator.
 
A

Army1987

I can't name one, but it seems that some mathematicians do find it
useful. See <http://en.wikipedia.org/wiki/Sign_function>. No,
Wikipedia is not definitive, but it seems plausible in this case --
and I remember a "signum" function that does just this on my HP 48
calculator.
It doesn't claim that anybody ever found it useful, only that
it exists. (Often it is useful to know the sign of the real part
of a complex number, but let's call it that way. If we call it the
sign of the complex number, either we admit that -5i, -i, 0, 75i
and 312.34i all have sign 0, or we use the totally useless csgn(z)
convention in the article you cited, which essentially uses the
lexicographic ordering (nothing wrong with it, but it is
essentially useless, though not more so than any other total order
over the complex numbers).
 
R

Richard Bos

[ Please attribute posts the normal way. Corrected. ]
The problem is that I can have two apples whereas I cannot have minus
two apples.

Neither can you have 1/2 apple. You can have 0.501093474... apple, or
0.498376515... apple, but not 1/2 apple. Oh, you can, you just have to
redefine 1/2 to fit sufficiently into the real world? Well, then you can
do the same with minus two: you can be in dept to the amount of two
apples.

In maths, unlike in C (which, hint, hint, is the topic of this
newsgroup), conforming to reality is _not_ an argument.

Richard
 
D

Don

I'm making a function that checks the input integer and returns the
value if it is a prime number.
If the integer is not a prime number, then the function should return
nothing.
Problem is, I don't know how to do that.
Isn't there anything like "return null"in C?

#include <stdio.h>

/* This program implements a blindingly fast O(n^n) algorithm
to find prime numbers, using an elegant recursive method.
If n is prime it returns n. Otherwise it returns nothing (zero).
*/
int _(int n, int m, int d, int t=0)
{
int r;
if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0;
for(r=m!=n; d*(t<n); ++t)
r &= _(n,_(t,m,0,1),d-1)|!_(t,1,t);
return r*n;
}


/*------------------------------------------
Print primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
int n;
for(n = 2; n <= 1000; n++)
printf("Calling with input %d returns %d\n",n, _(n,1,n,0));

return 0;
}
 
T

Tor Rustad

Richard said:
Tor Rustad said:


Indeed. A straightforward real axis <--- thisaway ---> and an imaginary
axis at right angles to it. That's the complex arithmetic I'm discussing.

My intension, was indeed to provide you with an abstraction .. as seen
from the standpoint of theoretical physics, which at least for me, is
far easier to grasp than pure mathematics.

Not mine. AFAICR I haven't even mentioned a "sign of z".

I can *accept*, that your statements in this sub-thread, is rather
confusing at this point.


"No. I don't care what order you place the complex numbers in. I'm
talking about sign, not order."
- R.H.


"I cannot accept that there is no such thing as a non-negative
*complex* number. A complex number has a (possibly zero but usually not)
real number element which is sufficient to displace it off the zero line
in the complex plane. Most numbers in the complex plane are either to
the right of the zero line (positive) or to its left (negative),
regardless of the value of their imaginary co-ordinate."
- R.H.


What happened to the sign of the imaginary component?

"I can accept that there is no such thing as a positive imaginary
number, and no such thing as a negative imaginary number."
- R.H.


I give up.
 
R

Richard Heathfield

Tor Rustad said:

I give up.

Not hard. Fixed-pitch font for best results:


^
|
{ -, + } complex | { +, + } complex
+imaginary
|
|
|
<----------- -real --------------0------- +real ---------------->
|
|
-imaginary
|
|
{ -, - } complex | { +, - } complex
|
V
 
T

Tor Rustad

Richard said:
Tor Rustad said:



Not hard. Fixed-pitch font for best results:

Given

"I can accept that there is no such thing as a positive imaginary
number, and no such thing as a negative imaginary number."
- R.H.

very hard.
^
|
{ -, + } complex | { +, + } complex
+imaginary
|
|
|
<----------- -real --------------0------- +real ---------------->
|
|
-imaginary
|
|
{ -, - } complex | { +, - } complex
|
V


(cos φ + i sin φ) is far more useful.

<gd&r>
 
R

Richard Heathfield

Tor Rustad said:
Given

"I can accept that there is no such thing as a positive imaginary
number, and no such thing as a negative imaginary number."
- R.H.

very hard.

The above paragraph was not supposed to be a claim, but merely a refusal to
get into a disagreement over terminology in a subject in which I am not an
expert. For all I know, mathematicians might call imaginary numbers
plusative and minative rather than positive and negative.
 
C

CBFalconer

Tor said:
Richard Heathfield wrote:
.... snip ...

.... snip ...
I give up.

However any such characteristic is not innate to the complex
number. All you have to do is rotate the coordintes and you can
alter the sign of the real portion. I maintain you can assign
signs (and relative magnitudes) to either the real or imaginary
components, provided you specify the coordinate system. Anything
further is just foolish.
 
C

CBFalconer

Don said:
(e-mail address removed) wrote:
.... snip ...

#include <stdio.h>

/* This program implements a blindingly fast O(n^n) algorithm
to find prime numbers, using an elegant recursive method.
If n is prime it returns n. Otherwise it returns nothing (zero).
*/
int _(int n, int m, int d, int t=0)
{
int r;
if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0;
for(r=m!=n; d*(t<n); ++t)
r &= _(n,_(t,m,0,1),d-1)|!_(t,1,t);
return r*n;
}

/*------------------------------------------
Print primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
int n;
for(n = 2; n <= 1000; n++)
printf("Calling with input %d returns %d\n",n, _(n,1,n,0));

return 0;
}

After slight modification to make it compile (below) I can vouch
that it seems to perform as advertised for all inputs up to 5. 6
may be alright, but I didn't have the patience to wait for it.
Maybe someone will analyze the O() of the routine?

#include <stdio.h>

/* This program implements a blindingly fast O(n^n) algorithm
to find prime numbers, using an elegant recursive method.
If n is prime it returns n. Otherwise it returns nothing
(zero). By Don Dodson.
*/
static int _(int n, int m, int d, int t) {
int r;

if (t) return d ? 1 + _(n, m, d-1, d)
: n ? _(n-1, m, m, n) : 0;
for (r = m != n; d * (t < n); ++t)
r &= _(n, _(t, m, 0, 1), d-1, 0) | !_(t, 1, t, 0);
return r * n;
}

/*------------------------------------------
Print primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
int n;

for(n = 2; n <= 1000; n++)
printf("Calling with input %d returns %d\n",
n, _(n, 1, n, 0));
return 0;
}
 
G

Gordon Burditt

I'm making a function that checks the input integer and returns the
value if it is a prime number.
If the integer is not a prime number, then the function should return
nothing.
Problem is, I don't know how to do that.

If you return whatever it is you call "nothing", how do you tell
that it WAS the nothing you are looking for? How do you test for it?

Yes, you can return a designated value (in your case, integer) that
can't be a valid value, depending on the situation (0 or -1 might
be used here.
Isn't there anything like "return null"in C?

C does not support the SQL notion of null values (except sort-of
for pointers, but you can't do math on those).

C does not support dynamic typing, so something like:

return (void);
won't work either.
 
J

Joachim Schmitz

Don said:
#include <stdio.h>

/* This program implements a blindingly fast O(n^n) algorithm
to find prime numbers, using an elegant recursive method.
If n is prime it returns n. Otherwise it returns nothing (zero).
*/
int _(int n, int m, int d, int t=0)
This isn't C, but C++. But easily fixed.
int _(int n, int m, int d, int t)
{
int r;
if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0;
for(r=m!=n; d*(t<n); ++t)
r &= _(n,_(t,m,0,1),d-1)|!_(t,1,t);
2nd part of the fix
r &= _(n,_(t,m,0,1),d-1,0)|!_(t,1,t,0);
^^ ^^
return r*n;
}


/*------------------------------------------
Print primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
int n;
for(n = 2; n <= 1000; n++)
printf("Calling with input %d returns %d\n",n, _(n,1,n,0));

return 0;
}
On a 6 it chews for ages...

Isn't _ reserverd for the implementation?

Bye, Jojo
 
R

Richard Tobin

CBFalconer said:
However any such characteristic is not innate to the complex
number. All you have to do is rotate the coordintes and you can
alter the sign of the real portion. I maintain you can assign
signs (and relative magnitudes) to either the real or imaginary
components, provided you specify the coordinate system.

No, this is not true. The real and imaginary components of complex
numbers are not arbitrary coordinate axes. The complex numbers are
*numbers*, not just points, and the mathematical operations on complex
number constrain the axes. For example, the real axis has the
property that when you square numbers on it, they stay on it. Axes in
other directions don't have that property. If you swap the signs of
the real axis, you will have -1 x -1 = -1, which is false.

Regarded as a vector space over the reals, what you say is true. You
could choose a basis other than (1, i). But the complex numbers are
more than that.

-- Richard
 

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,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top