[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 75 KB, 720x720, o.jpg [View same] [iqdb] [saucenao] [google]
15760213 No.15760213 [Reply] [Original]

GPT 4 can't do it.

>> No.15760215 [DELETED] 

>>15760213
Obviously not doable.

>> No.15760227
File: 21 KB, 400x400, sad_old_pepe.jpg [View same] [iqdb] [saucenao] [google]
15760227

>>15760215
Is over, people can't even code something that simple nowadays.

>> No.15760244 [DELETED] 

>>15760227
It's not doable. You need at least one extra bit of information. If you're working with floats, whatever scheme you come up with is going to sacrifice a bit in one way or another thus you will not get exactly -x for all x.

>> No.15760254
File: 15 KB, 300x257, sad pepe.jpg [View same] [iqdb] [saucenao] [google]
15760254

>>15760244
Civilization is collapsing.

>> No.15760261

>>15760213
f(x) = xi
f(f(x)) = xi^2 = x(-1) = -x

>> No.15760269

>>15760213
Are you asserting that floating-point numbers are complex numbers?

>> No.15760274

>>15760213
>>15760227
>floating-point
>code
Stick to /g/.

>> No.15760276

>>15760261
Better than GPT, but still not there because in that solution x is a complex and f also needs to return a complex number.

>> No.15760279

>>15760213
lambda x: -x if x > 0 else x

>> No.15760280

More poo-maths nonsense from American educated goonlets. Fuck off back to 'muh college' you massive homosexuals.

>> No.15760283

>>15760213
Translation:

Who can craft the perfect poo?
Put a nut in eat
Chop into a bit
Make it slop to one side
Bile

>> No.15760284

>>15760279
With that definition f(f(-3)) would return -3

>> No.15760287

>>15760284
My answer is only defined for positive numbers.

>> No.15760289

>>15760283
I am filtering low quality bots.

>> No.15760291 [DELETED] 

>>15760254
Sorry that you're incapable of basic reasoning, mongoloid. Ignoring this fundamental limitation, your problem is trivial. There's an infinite number of arbitrary ways to do it.

>> No.15760293

>>15760213
[math]f(x) = \begin{cases}
0 & x = 0
\\ x+1 & x > 0 \wedge \lceil x \rceil \text{ is odd}
\\ 1-x & x > 0 \wedge \lceil x \rceil \text{ is even}
\\ x-1 & x < 0 \wedge \lfloor x \rfloor \text{ is odd}
\\ -1-x & x < 0 \wedge \lfloor x \rfloor \text{ is even}
\end{cases}[/math]

>> No.15760294

>>15760213
[eqn]f(x) = \begin{cases} 0 & \text{for } x=0 \\
x+1 & \text{for } x \in (2n,2n+1] \\
1-x & \text{for } x \in (2n+1,2n+2] \\
x-1 & \text{for } x \in [-2n-1,-2n) \\
-x-1 & \text{for } x \in [-2n-2,-2n+1)
\end{cases} [/eqn]

>> No.15760296

>>15760213
>f(N) = M
what sign does M have?

>> No.15760313

>>15760213
I will tell if you can tell me the utility of this function.

>> No.15760324
File: 88 KB, 866x1300, 89639939-portrait-of-young-professional-man-in-suit-arms-crossed.jpg [View same] [iqdb] [saucenao] [google]
15760324

>>15760213
g(x) = a funtion that does whatever op needs
t. management engineer

>> No.15760333

>>15760291
> There's an infinite number of arbitrary ways to do it.
Wrong. At most there are 2^(2^n * n) ways to define a function that takes a number defined in n bits and returns the same type.

>> No.15760335

>>15760213
So if I apply it twice to a negative number, it should return a positive?

>> No.15760338

>>15760313
Filter out Chat GPT bots.

>> No.15760351 [DELETED] 

>>15760333
>bits
Learn to read, mongoloidal animal. If we ignore bits and treat x as real, there's an infinite number of ways to do it. If we're not allowed to do it, there is not a single way to do it.

>> No.15760356

>>15760338
No, I said the utility of the function, as in what you can use the function itself for in other code, not the utility of the coding process and getting free homework help since chatgpt can't do all your homework.
I will give you a hint since you at least tried to answer.
Global variables.

>> No.15760364

>>15760213
>>15760227
>You should be able to solve this.
No you shouldn't because it's impossible.

>> No.15760370 [DELETED] 

>>15760276
But it isn't specified that the image of x under f has to be a floating point. It just says "f works with floating points".

>> No.15760378
File: 2.35 MB, 498x498, hc.gif [View same] [iqdb] [saucenao] [google]
15760378

>>15760364
LMAO, there is already a solution for all real numbers, the solution for floating point numbers is a bit simpler.

>> No.15760379

>>15760378
Nope.

>> No.15760389 [DELETED] 

>>15760378
There is no solution for floating point numbers, as multiple posters have already pointed out, if f(f(x)) is strictly equal to -x and not just approximately equal. Your IQ is legit floor level.

>> No.15760397

>>15760389
My IQ is floor level to the far right.

>> No.15760398

>>15760333
i don’t agree with this because the interpretation is contextual.

calling it a ‘float’ doesn’t live within its 32 bits, but it controls how other functions interact with it.
going by your reasoning the concept of a float doesn’t exist

>> No.15760403

>>15760213
Ok, something like this:

def call_me_twice x
if is_denorm_float(x)
return - normalize_float(x)
else
return denormalize_float(x)
end
end

lol

>> No.15760406

>>15760213
Not possible if you can't have -0. Otherwise its trivial to just do something like this:

if n & 1: return -(n ^ 1)
else return (n ^ 1)

>> No.15760413

>>15760406
That is very close to the solution.

>> No.15760414

>>15760213

float f(float n) {
static float tmp = 0;
if (tmp == n)
return -n;
return tmp = n;
}

hello from /g/

>> No.15760415

>>15760406
wdym?
if 0 return 0

>> No.15760419

float f(float x) {
int a = * (int *) &x;
a += 0xC0000000;
return * (float *) &a;
}

>> No.15760422

>>15760414
use `static float tmp = FLT_MAX;` for -0.0

>> No.15760427 [DELETED] 
File: 28 KB, 522x537, 5234234232334.jpg [View same] [iqdb] [saucenao] [google]
15760427

>>15760413
>That is very close to the solution.
It's gonna be really funny when you post your "solution" and I immediately give you an x that it fails for. Actually, I basically just ensured that you will never post your "solution".

>> No.15760439

>>15760244
>>15760215
>>15760269
>>15760291
>>15760389

Are you all fucking retarded? Do you know that in the IEEE 754 standard, there is a sign bit format?? which for the smooth brains means

0 10000001 10100000000000000000000
is the negative of
1 10000001 10100000000000000000000

which means all positive numbers are equally spaced from their negative counterparts. You can just add half that universally fixed value after copying the float to an equal sized integer in the function. If that fixed value is odd, just add the larger half when last bid odd and smaller when last bit even.

It's literally that simple. The value will wrap around and become negative, and it will give a nonsense answer in the part between.

You are all absolute morons. Only >>15760406
has a bit of clue what is happening because signed magnitude form implies the existence of a -0

>> No.15760440

>>15760427
read >>15760439 retard

>> No.15760443

>>15760427
>Of course I know what mung means, I think you wouldn't know what mung means.

>> No.15760447 [DELETED] 

>>15760439
Codeniggers are legit 90 IQ. Any fixed-width type has a finite number of possible values. f(x) has to map every x to a unique value not equal to x itself. That means you lose at least half of your possible values no matter what.

>> No.15760458

def f(x):
if isinstance(x, float):
return -x + 1 if x <= 0 else -x - 1
else:
raise TypeError("Input must be a floating-point number.")

yawn

>> No.15760459

>>15760447
Are you so retarded that you cannot see the answer laid out in front of you? Ill simplify it for you. Let's say the float (or any signed magnitude form number) has only 4 bits including the sign bit so 0 is 0 000.

-0 will be 1 000
1/-1 0 001 and 1 001
and so on.

now add 0 100 to 1. > 0 001 + 0 100 = 0 101 = +5

now add 0 100 again = 0 101 + 0 100 = 1 001 = -1

discard the carry bits if any and repeat this exercise until it settles in that dumb head of yours you idiot

>> No.15760466 [DELETED] 

>>15760459
No sense talking to animals like you. Post your "working" code and I'll give you an x it fails for. Prediction: you will refuse to post code.

>> No.15760476

>>15760466
He is not OP, you poorfag without gold account.

>> No.15760479 [DELETED] 

>>15760476
I didn't say he was OP, you disgusting animal. OP won't post working code, either. There simply is none for completely obvious and trivial reasons that are nonetheless inherently lost on codeniggers. No one with an IQ over 90 ends up as a codenigger.

>> No.15760480

>>15760447
So long as no two numbers map to the same number, and no number maps to multiple numbers it should work for any number. All numbers just have to be a member of a loop like so:
>f(A) = B
>f(B) = C = -A
>f(C) = D = -B
>f(D) = A

>> No.15760487

>>15760466
>>15760447
It's literally a circular arrangement where number go from 0 to max to -0 to -max to 0 again you retard, how do you suppose adding a quarter of the loop value each time will not produce a unique mapping for each value???? go read basic middle school mathematics before challenging others to waste time for a clearly defeated chimpoid like you. Literally ever other sane person in the thread can see the answer now if they couldn't see it before, I don't come to /sci/ to write code for illiterate faggots, /g/ is more than enough practice on that.

>> No.15760490

>>15760466
also you clearly didn't repeat the exercise until you got it as asked, it's a necessary step i included in the explanation for braindead mongrels like you

>> No.15760493

if the input's least significant bit is 0, make it 1 and multiply the input by -1.
if the input's least significant bit is 1, make it 0 and leave the sign unchanged.

there you go. literally all there is to it. no need to rely on exploits in signed-bit spacing or anything.

>> No.15760494

Solution was already posted by >>15760293

First you ignore the exponent part and just loock at the sign and the significant digits. then you use ringbuffer with at least 4 elements that shifts one quarter each time. And the simplest case is just check even/uneven + sign

For how you get to the relevant information just use a evil floating point hack
i = * ( long * ) &y;

>> No.15760497

>>15760493
yes there are million ways to do it when -0 is available as >>15760406 said.

>no need to rely on exploits in signed-bit spacing

your method will fail if two's complement form (as used in signed integers for all computers) is used as multiplying by -1 also changes the least significant bit. It still relies on signed magnitude form to work. which means this question is actually easier and possible on floats. It may be possible on ints but i really am not in the mood to give it more thought than this.

>> No.15760500

>>15760213
trivial;

let func = (x) => {
if(x.secondInvocation){
return -x.original
}
return ({secondInvocation: true, original: x})
}

func(func(3)) -> -3

>> No.15760507

>>15760497
as said by >>15760494. >>15760293's solution also works for just integers, no exploits needed, i concede that

>> No.15760518 [DELETED] 

>>15760480
Obviously, but no floating point operations are going to give you such a mapping.

>> No.15760525

>>15760518
just told you one anon >>15760439>>15760459

floats are 32 bits which means if you add 1000000000000000000000000000000 to it twice, it will have the same effect as just flipping the first (sign) bit

>> No.15760530 [DELETED] 

>>15760525
> if you add 1000000000000000000000000000000 to it twice
That's not a floating-point operation. Are you literally retarded? I hate codeniggers so fucking much it's unreal. Your bit twiddling wankery belongs on /g/.

>> No.15760536

>>15760497
poster here, i was wrong, multiplying by -1 in signed bit form does not change the least significant bit. the operation suggested by >>15760493 is right and i apologize to him for the error. It's in the same vein as the other answers as it basically just circles around the whole space without any repeated mappings. This will however fail for the highest negative value in integers from which part of the confusions stemmed

>> No.15760537

ITT: tardademians that understand this 'f' gobbeldygook

>> No.15760543

>>15760530
>it's not a floating point operation

who said it has to be, just the function has to give a float output. You can easily just convert it to an unsigned integer of the same size, do the operation, stuff the exact bit mapping back into the float and output, that changes literally nothing??? the function has to work with floating point numbers, not be a operation of floating point numbers.

>Your bit twiddling wankery belongs on /g/

i agree that this question belongs on /g/, but i think /sci/ needs a couple of fags who can properly teach you how to suck dicks and use logic

>> No.15760545

>>15760480
Could've just took the derivative of sin(x) 4 times.

g(x) = f''(x)
f(x) = f'(x)

>> No.15760552

>>15760545
not sure how you're supposed to differentiate a numeric constant with a finite precision for trig operations, but cycling like that is the right idea.

>> No.15760565 [DELETED] 

>>15760543
>who said it has to be, just the function has to give a float output. You can easily just convert it to an unsigned integer
Well, you retarded nigger, then you're effective just doing modular arithmetic and obscuring it with talks about muh floats and irrelevant C bit twiddling that isn't even possible in decent programming languages.

>> No.15760567

>>15760333
i got about 2^(2^(34.934)) functions for n=32 would be nice if someone verified if my number is correct or wrong.

>> No.15760585

>>15760565
kek then just make a 32 element array in your shitty language, make the conversion adherent to IEEE 754 and do it.

Nobody cares if it's modular arithmetic, it's a perfectly valid solution nonetheless. Modular arithmetic is a fundamental concept in computers where values are stored in fixed size arrays anyway, it literally just arises naturally from there, so i don't see a problem.

>> No.15760587

>>15760507
No it doesn't directly work on integers because on an sint8 -128 doesn't exist, but 128 does. so you have to ignore 128.

Now your total amount of numbers aren't divisible by 4 so you have to exclude 3 additional numbers.

>> No.15760600

>>15760587
actually -128 exists but 128 doesn't. and yes i know that. I meant it as a logical solution being correct. Already mentioned how methods like this break on the most negative number in >>15760536

But, applauded for the attentiveness and i concede my mistake of not mentioning it in the post you mentioned

>> No.15760601 [DELETED] 

>>15760585
What a dumb codenigger. My point is that if you stop obscuring the simple mathematical problem of it with irrelevant codemonkey details that don't even make sense outside of a narrow low-level programming context, the solution is trivial.

>> No.15760608

>>15760439
>Addition implemented with negative sign bit in mind can overflow
Retard. Or VBA user.

>> No.15760612

>>15760601
>codeniggers
>the solution is trivial.

aren't you the poster in >>15760447 who was insisting that you have to lose atleast half your possible values no matter what?

also the question is pertaining to computer science and handling of data types in this way is modular arithmetic. So, i don't see how i 'obscured' the problem. Computer science is a mix of discrete mathematics and electronic design. Using it just means i am using maths, just expressing it in the form of computer ideas because that's what the question asked. Why are you so butthurt about it? If somebody posted the same question minus the computer notation, i would give the same answer minus the computer notation. What's wrong with that?

>> No.15760614 [DELETED] 

>>15760612
I am that poster and what I point out is correct if you actually use floating point operations, you retarded codenigger.

>> No.15760618

>>15760608
Depends on the compiler and language, some just discard the extra bit. otherwise you can just use a 64 bit integer to perform the calculations and modulus or form your own system using a big one dimensional array, implementation specifics are always there, doesn't make the solution any less valid.

>> No.15760625

>>15760614
you're just coping hard at this point, you literally said

>Any fixed-width type

not floats. And i simply disproved you, now you see the answer and you're coping by trying to (unsuccessfully) recontextualize your previous statements when you believed the problem was unsolvable.

>> No.15760626 [DELETED] 

>>15760625
>Any fixed-width type
Yep, now read the rest of the sentence, you total mouth breather.

>> No.15760636

>>15760626
I did you monkey and you literally said since there has to be a unique mapping for every x in such formats, there is no possible solution without losing half your possible values "no matter what". which was simply proved untrue by my and some other posters' answers. You can't backtrack from that no matter how much you try, so i suggest you shut up and accept the loss like a gentleman as i did in >>15760536 because that's what gentlemen do. I will not be responding to you further but in case you decide not be a gentleman, please go eat shit

>> No.15760641

>>15760567
I think the amount of functions for n bits is (2^(n-1))!/(2^(n-2))! could be wrong

>> No.15760646

>>15760213
I have no idea what a floating point number is. Is that some computer science thing?

If you have the group (R, +) than inv(x) = -x, and you can just keep flipping it non-stop to maintain the symmetry right? Is the joke here that chat gpt can't do visualizations or content from group/field/rings?

>> No.15760650 [DELETED] 

>>15760636
Everything I said is correct and you are losing your mind with rage. If you're using floating point operations, you get a behavior that approximates real numbers, but you're still using a fixed-width type so you don't enjoy the advantage of having infinitely many values. Good luck using FP operations without losing at least half your available values.

>> No.15760657

>>15760646
There's no joke here specifically, OP just started these threads as challenge questions(see >>15750877) on /g/ and now /sci/ so that we can all get off our asses and do something beneficial to us instead of arguing over which is the biggest pseudoscience all day. Questions currently are just as he lifted off /g/ but im sure he'll post more science related questions soon. Bless the lad.

>> No.15760667

>>15760213

float f(float x) {
if (x > 0)
return -x;
else
return x;
}

>> No.15760673

>>15760667
>[code]
/g/ook spotted

>> No.15760789

>>15760213
Pick the sign bit and any other bit.
These two bits will represent a number in {0,1,2,3}.
Pick any permutation of the other bits that is an involution.

Just let f increment the two-bit number by 1 mod 4 and permute the other bits.
ff will just leave the two-bit number incremented by 2 mod 4 and the rest will be unchanged.
This flips the sign bit and changes nothing else.

>> No.15761072 [DELETED] 

>>15760641
The exact number of f is (2^(n-1))!!*2^(n-2).
Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).
Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

>> No.15761085

>>15760641
The exact number of f is (2^(n-1) - 1)!! * 2^(n-2).
Any f is just a bunch of 4-cycles on the 2^n bit-strings such that each 4-cycle is of the form (a,b,-a,-b).
Just count the perfect matchings on the positive strings and choose the orientation for each implied 4-cycle.

>> No.15761118

>>15760213
>create a vector (num, 0)
>apply it once and it's (0, num)
>apply second time and it's (-num, 0)

>> No.15761133

>>15760213
you can do this but youll have to give up a bit of precision

>> No.15761152

>>15761118
That would not work since f() does not accept a vector as input.

>>15760789
This is nice but it can be made even simpler. All you need to do is add 1 (twice) to the two top-most significant bits (sign + one from the mantissa).

>> No.15761199

>>15760618
>my solution works
>well, if you emulate a system where it works
Yeah, k, imma go with this anon here >>15760447

>> No.15761346

>>15761152
>can be made even simpler
That is just a specific case of what I said.
Unlike the many retards in this thread, just finding one solution is boring for me.
I found them all here >>15761085.

>> No.15761351

>>15760276
That's fine, complex numbers are just two floating point numbers, so it fits the criteria.

>> No.15761390

>>15760283
Gem

>> No.15761412

wolderful ;)

>> No.15761419

Where my writted ideas macbook air 2020 i3 model...

>> No.15761427

>>15760213

def f(vishnu)

if vishnu =/= 0:
global shiva = vishnu

ganesh = vishnu - shiva

return ganesh

>> No.15761429

Matrix memory area scaling heap technology are euclid traits extract memory allocation. moving , rotation , Parent bone or child bone memory area. english is difficult... ;)

>> No.15761442

>>15760213 constant function -1

>> No.15761461
File: 13 KB, 396x224, missyfix.jpg [View same] [iqdb] [saucenao] [google]
15761461

>>15760213
i friminikis

>> No.15761573

>>15761199
It works in c though, which is a pretty common and strong language, just use long long. It can easily work on any system that supports 32 bit or longer ints with minimal tweaking

>> No.15761576

I always knew /sci/ was full of CS midwits. Now this thread is proof.

>> No.15761580

>>15761576
i must admit, i thought it was impossible before that guy suggested overflowing the register. reminds me of quick inverse sqrt. clever, but he was a real dick about it.

>> No.15761581

float f(float x) {
const float MAGIC = 5.87747175411144e-39;
if (x < 2 * MAGIC && x > -2 * MAGIC) {
if (x < MAGIC && x > -MAGIC) {
return x >= 0.0 ? x + MAGIC : x - MAGIC;
} else {
return x >= 0.0 ? -x + MAGIC : -x - MAGIC;
}
} else {
return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;
}
}

>> No.15761583
File: 77 KB, 1920x642, file.png [View same] [iqdb] [saucenao] [google]
15761583

>>15761581
i dont believe floats overflow by themselves, you have to do evil floating point bit level hacking

>> No.15761587

>>15761583
only nonretards will comprehend my answer

>> No.15761590

>>15760213
return abs(x) * -1.0

>> No.15761592

>>15760389
>>15760518

see >>15761581

>> No.15761595

>>15761590
> when applied twice it returns its negative
> f(-1) = -1
try again noob

>> No.15761606
File: 426 KB, 1507x1555, file.png [View same] [iqdb] [saucenao] [google]
15761606

its cursed as hell o my brothers but it works

>> No.15761607

>>15760213
Just append a digit x = 0 to all n so that n~x = n(-1)^floor(x/2), then f(n~x) = n~(x+1 (mod 4))

>> No.15761612

>>15761606
>else if (sizeof(float) == 8)
floats are 4 bytes by definition

>> No.15761615

>>15761612
yeah i googled that afterwards, youll have to forgive me, i have trust issues with the c standard.

>> No.15761616

>>15761606
> sizeof(float) == 8
> uint32_t i
bro

>> No.15761617

>>15761615
kek

>> No.15761619

>>15761616
its all good bro, that part doesnt even matter.

>> No.15761623

>>15761619
true but it still triggers me.

>> No.15761626
File: 27 KB, 498x335, file.png [View same] [iqdb] [saucenao] [google]
15761626

>>15761623
v0.0.2

>> No.15761632

>>15760213
float f_challenge32(float var)
{
uint32_t var_int = *(uint32_t*)var;
var_int += (1 << 31) / 2;
return *(float32_t*)var_int;
}

I haven't tested this but it should work, all its doing is adding half of the sign bit twice, so when it runs twice it flips the sign bit.

>> No.15761638

>>15761632
>(1 << 31) / 2;
beautiful

>> No.15761637

>>15761626
better. now you need variants for double, long double, and __float128

>> No.15761641

>>15761638
"whatever gcc will probably optimise it" - internal monologue

>> No.15761658

>>15761626
f(1.01) = nan

>> No.15761660

>>15761658
you have to call it twice

>> No.15761665

>>15761660
your function rips a hole in the continuum

>> No.15761666

>>15761665
show me in the instructions where it says im not allowed to do that

>> No.15761668

>>15761666
it's mathematically unfeasible

>> No.15761672

>>15760215
>Obviously not doable.
Jesus Christ! KYS already.

>> No.15761695

>>15761632
I forgot the &s on this.

float f64(float var)
{
int var_int = 0x40000000 + *(int*)&var;
return *(float*)&var_int;
}

>> No.15761696

>>15761660
if you have to call it twice, it's not a function retard

>> No.15761701

>>15761696
no, like, you compose it with itself. like, f(f(3)). like, how the instructions stated. its still a pure function, i promise.

>> No.15761708
File: 42 KB, 952x366, file.png [View same] [iqdb] [saucenao] [google]
15761708

>>15761637
i cant quite figure out why this works with floats but not doubles.

>> No.15761716
File: 234 KB, 1662x1166, file.png [View same] [iqdb] [saucenao] [google]
15761716

>>15761708
oh i got it, it was the long
now THIS is the most cursed code ive ever written

>> No.15761717

>>15760439
>>15760525
>>15760543
>>15760585
>>15760612
>>15760650
Uh huh that's wonderful
>>15760378
>there is already a solution for all real numbers
Where's your real number solution faggot?
What is [math]f[/math] such that
[eqn]
\forall (x \in R|x \neq 0) [f(f(x))=-x]
[/eqn]

>> No.15761720

>>15761717
well, technically [math]f(x)=ix[/math] works for all real numbers, but im guessing you want [math]f[/math] to be [math]\mathbb{R} \rightarrow \mathbb{R}[/math]

>> No.15761725
File: 323 KB, 1704x2048, 1695348297697.jpg [View same] [iqdb] [saucenao] [google]
15761725

>>15761720
That is what I want thank you anon.

>> No.15761730

>>15760213
literally just the wedge product of two 1-forms. imagine coming here and not knowing differential geometry.

>> No.15761732

>>15760213
static int firstRunFlag = 0;

Bitches.

>> No.15761733

>>15761725
oh wow, it looks like there are solutions.
https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x
color me surprised.

>> No.15761734

>>15761717
f(y, x) = f(y+1 (mod 4), x) with x = x(-1)^floor(y/2)

>> No.15761741

>>15761732
ooooh FUUUUUCK. Ok, so the first knee-jerk solution was just off the top of my head, but there's no need to complicate this.

#include <math.h>
float func(float f)
{
return -1.0f * abs(f);
}

>> No.15761755

>>15761732
float x = 1;
float y = 2;
x = f(x);
y = f(y);
x = f(x);
y = f(y);
print x, y

>> No.15761774

>>15761626
>>15761708
>>15761716
>>15760439
>>15760525
>solution depends on undefined behavior
Just kys now.

>> No.15761777

>>15761734
A better question (maybe the same question) is can you write a single variable function where f(x) = x but f(f(x)) = -x ?

>> No.15761786

>>15761777
No, I can't

>> No.15761792

float f(float x) {
return x < 0x1p-126 && -x < 0x1p-126
? (-1 + 2 * (x < 0x1p-127 && -x < 0x1p-127)) * x +
((x > 0) - (x < 0)) * 0x1p-127
: (-0x1p-127 + (x < 2 && -x < 2) * 0x1p127) * x;
}

>> No.15761795

>>15761774
>undefined behaviour
It's not undefined. The algorithms rely on the last bit being a sign bit, which means they'll work with every major floating-point format.

>> No.15761799

>>15761792
I challenge everyone ITT to beat this in obscurity and cleverness.

>> No.15761801
File: 262 KB, 1612x1228, file.png [View same] [iqdb] [saucenao] [google]
15761801

>>15761774
>>15761668
>>15760530
here. it doesnt have any bit-fuckery, undefined behavior, and it doesnt return NaN for bounded inputs. no reasonable person could possibly construe this as not being a solution to the original problem posed. happy?

>> No.15761803

>>15761795
Still doesn't work. It misses half.

>> No.15761804

>>15761801
can you not post your code in a fucking picture

>> No.15761805

>>15761804
float f(float x)
{
if (x == 0.0) return 0.0;
else if (x > 0.0 && ((int)ceil(x) % 2 == 1)) return x + 1.0;
else if (x > 0.0 && ((int)ceil(x) % 2 == 0)) return 1.0 - x;
else if (x < 0.0 && (abs((int)floor(x)) % 2 == 1)) return x - 1.0;
else return -1.0 - x;
}

>> No.15761806

>>15761801
It doesn't work on itself.

>> No.15761810

>>15761795
actually, dereferencing a recast pointer is undefined. c really doesnt want you to have fun.
>>15761806
i dont know what that means.

>> No.15761815

>>15761810
Put a real number in you won't get the same thing. If you're solving the already solved problem, congrats; the current problem is real numbers not floating point shit.

>> No.15761817

>>15761795
There's only one FP format in use these days, IEEE 754

>>15761810
> dereferencing a recast pointer is undefined
no it's not, but it is architecture dependant.

>> No.15761823

>>15761795
>It's not undefined.
Retard.

>> No.15761825

>>15761815
nigger did i reply to you? are you this retard >>15761777?
i cant fucking believe this, obviously there are no solutions.
[math]f(f(x)) = f(x) = x = -x [/math]
i dont want to be mean be seriously man what the actual fuck are you doing.
>>15761817
>but it is architecture dependant
im not sure what the difference is.

>> No.15761832

>>15761825
Of course there's no solution. The whole thread is retards trying to suck their own cocks. Did it work out for you?

>> No.15761833
File: 13 KB, 581x60, file.png [View same] [iqdb] [saucenao] [google]
15761833

>>15761805

>> No.15761836

>>15761832
if you hate the thread so much i invite you to leave.
>>15761833
strange, thats nowhere near the largest float. one moment.

>> No.15761845

>>15761792
solution for double precision:

double f(double x) {
return x < 0x1p-1022 && -x < 0x1p-1022
? (-1 + 2 * (x < 0x1p-1023 && -x < 0x1p-1023)) * x +
((x > 0) - (x < 0)) * 0x1p-1023
: (-0x1p-1023 + (x < 2 && -x < 2) * 0x1p1023) * x;
}

>> No.15761847

>>15761695
the equivalent of this (w/ C instead of 4) was posted here:
>>15760419

>> No.15761849

>>15760213
I really like this thread. Where did you take this problem from OP?
>>15761801
How did you arrive at this solution? Where can I read more about this cool bit math? Don't really know what bit cycles are

>> No.15761851

>>15761849
ripped off that solution from >>15761733
i was honestly astonished that there were solutions. im not so pround that i cant admit when im wrong.

>> No.15761854

>>15761836
I hate that the thread is objectively nonsense. You could also leave, asshole.

>> No.15761855
File: 14 KB, 398x68, file.png [View same] [iqdb] [saucenao] [google]
15761855

>>15761833
this is blowing my fuckin mind, the float magically gets +1 when its returned, what the fuck is going on.

>> No.15761861

>>15761855
It's bullshit. Use two variables f(y,x)

>> No.15761864

>>15761861
sorry, hombre, thats not what the question asked.

>> No.15761867

>>15761864
You fucking retard. It asked for a function. Not a function with 1 variable.

>> No.15761869

>>15761085
are you sure that's right? because for n=2 it outputs 1 although there are two functions for 2 bits

>> No.15761873

>>15761867
i mean, it literally says f(f(3)).

>> No.15761878

>>15761873
>f(f(3))
that's 2 functions you retarded cunt

>> No.15761882

>>15761833
>>15761855
alright, i think the issue is that floats eventually lose the precision of a single integer once they get big enough, so ceil/floor dont work. ill try to rework a new cycle like >>15761085 that works for all floats.

>> No.15761883

>>15761801
>happy?
Yes.
This solution is actual math and not bithack faggotry.

>> No.15761884

>>15761883
well too bad, fag, it doesnt actually work.

>> No.15761885

>>15761884
It looks like it does so I don't care.

>> No.15761886

>>15761882
No, the issue is that floats have an overflow.

>> No.15761887

>>15761606
>windows
Nigger

>> No.15761890

>>15761855
you need to read this https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf
Above a certain threshold (16777216.0f), you can't simply add 1 to a float because floating point numbers have limited precision.

>> No.15761891

>>15761887
>NOOO YOU GENTOO WITH i3 AND ZSH
>>>/g/
Really this whole thread belongs in >>>/g/.

>> No.15761893

>>15761890
yea, i assumed thats what was happening >>15761882
>>15761886
i dont think thats it.
>>15761887
i have a job. actually, i just moved my hypervised server full of chadbuntu vms to the office.
>>15761891
this thread has some considerable math in it.

>> No.15761895

>>15761890
These people are idiots. The ONLY solution is to drop two digits from the bit float and put in two mod 4 digits instead.

>> No.15761896

>>15761869
You're right.
It should be:
>* 2^2^(n-2)
There are 2^(n-2) 4-cycles in the partition
There are 2^2^(n-2) ways to pick all of the orientations.

>> No.15761897

>>15761893
>i dont think thats it.
You don't think. Leave it at that.

>> No.15761900

>>15761895
no i solved it without making any compromises right here >>15761792

>> No.15761902

whys everyone being such an ass to me in here? is it one guy?

>> No.15761905

>>15761900
Assumes float length. Come on don't be an asshole

>> No.15761907

>>15761905
what about >>15761716?

>> No.15761908

>>15761902
I like you.

>> No.15761910

>>15761908
thanks <3

>> No.15761913

>>15761905
there's also a double-precision solution >>15761845
when I hear float i just assume single-precision floating-point number

>> No.15761918

>>15761774
>>15761810
UB doesn't mean is impossible to implement correctly, it means the code is not portable so the compiler is allowed to generate working code or just give up.
C++20 got rid of that specific UB with bit cast:

#include <cstdint>
#include <bit>
float f(float x) {
return std::bit_cast<float>(std::bit_cast<uint32_t>(x) + (1 << 30));
}

I.E.: In x86-64 the assembly code is as simple as copying the data into an integer registry, add an integer number, and copy back into the float registry:

f(float):
movd eax, xmm0
add eax, 1073741824
movd xmm0, eax
ret

>> No.15761921

>>15761896
Using identities for !! gives:
(2^(n-1))!/(2^(n-2))!
which agrees with >>15760641

>> No.15761941

>>15761918
>C++20 got rid of that specific UB with bit cast
oh, thats cool.

>> No.15761944

>>15761921
You're all retards. There's no function f(x) where f(f(x)) = f(-x)

>> No.15761975

i thought that i could get around the stupid float precision by only multiplying and dividing by powers of 2, but even that is producing the wrong goddamn numbers. im starting to think that theres no way to do it without bit-fuckery.

>> No.15761977

>>15761975
>>15761792

>> No.15761979
File: 38 KB, 784x82, file.png [View same] [iqdb] [saucenao] [google]
15761979

>>15761977
swing and a miss, partner

>> No.15761997

>>15761979
because 33554403600.f doesn't exist genius. it rounds down to 33554403328.f on float conversion.

>> No.15762003

>>15761997
oh fuck youre right. damnit, i spent so much time trying to fix a nonissue. im mad.

>> No.15762004

here, i made a test suit:

int test_float(float x) {
if (f(f(x)) == -x) {
if (f(x) != f(x) || atof("inf") == f(x) ||
atof("-inf") == f(x)) { // check for NaN and Inf
printf("f(%.8e) = %f.\n", x, f(x));
return 0;
}
return 1;
}
printf("f(f(%.8e)) = %.8e\n", x, f(f(x)));
return 0;
}

int main(int argc, char *argv[]) {
float floats[] = {1.0, -1.0, 2.0, -2.1,
0x1p-126, -0x1p-126, 0x1p-153, -0x1p-153,
0x1.11p120, -0x1.1111p120, 0x1.11111p127};
for (int i = 0; i < 11; i++) {
if (!test_float(floats[i])) {
printf("Test failed for %.8e\n", floats[i]);
return 1;
}
}
printf("All tests passed!\n");
return 0;
}

>> No.15762011

>>15761825
> im not sure what the difference is.
for example directly accessing a memory location, the result would differ if the underlying hardware is big endian or little endian.

>> No.15762056

>>15761944
a constant function satisfies f(f(x)) = f(-x) tho

>> No.15762060
File: 29 KB, 656x679, file.jpg [View same] [iqdb] [saucenao] [google]
15762060

retards everyone. just use any language that allows global static variables inside a function.
then just switch the sign every time so the second time it's negative.

>> No.15762071

>>15761944
we're talking about how many functions satisfy f(f(x))=-x, x belongs to X given 2^n values in X, and one value of -x for every one value of x in X. hope I didn't scuff the notation.

>> No.15762075
File: 75 KB, 700x848, file.jpg [View same] [iqdb] [saucenao] [google]
15762075

tl;dr of thread, if you mean computer function: it can be just hacked to produce even gay sex.

if you mean pure math: no.

>> No.15762076

>>15762060
Only someone who has never had to write thread-safe reentrant code would suggest that.

>> No.15762078

>>15762076
google what mutexes are kid.

>> No.15762085

>>15762071
and f(x) only outputs members of X btw,
I think you were responding to the (f(x) = x and f(f(x)) = -x) which doesn't have any functions which satisfy it if x isn't 0 (-x = x is implied)
but we're only talking the initial f(f(x)) = -x condition

>> No.15762096

f(x) = ix

>> No.15762147

>>15760213
In C:
float f(float x)
{
return ~x;
}

>> No.15762152

>>15762147
That being said, I couldn't be bothered to do it without bit operations, because floating points are so messy with a lot of casework, and -0, and NaN, and that part for very small numbers where they're equally spaced

>> No.15762166

>>15761851
Thanks anon!

>> No.15762187 [DELETED] 

>>15761573
Show code.

>> No.15762266

>>15762078
huh? mutexes are thread-safe code. it's why they exist. they are utterly pointless otherwise.

>> No.15762268

>>15762147
that doesn't work anon, you can't perform a bitwise not operation on a float

and even if you could, calling the function twice would return the original value.

>> No.15762276

Kek, this thread currently contains about 90% of all autism on /sci/ and /g/ combined. I love to see it.
I have no idea what any of it means though.

>> No.15762296

>>15762266
nice you googledededed it.

>> No.15762807

>>15760543
THE FUCKING OP SAYS IT HAS TO BE FLOATING POINT, YOU PAVEMENT APE CONCRETE CHIMP URBAN GORILLA PORCH MONKEY WELFARE SIMIAN AIDS-RIDDEN RETARDED GAY DOUBLE NIGGER FAGGOT

>> No.15762822
File: 74 KB, 740x840, 1695252764825263.jpg [View same] [iqdb] [saucenao] [google]
15762822

>>15762807
No, OP said it should _work with floating point numbers_, not that it should only use floating point arithmetic.

>> No.15762826 [DELETED] 

>>15762822
OP is a faggot and so are you. >>>/g/ is that way.

>> No.15762882

>>15762826
Learn to read before posting here again, negro.

>> No.15762883 [DELETED] 

>>15762882
Code monkeys don't belong on /sci/.

>> No.15762897

>>15762826
>>15762883
Your retarded ass doesn't belong on /sci/. Coding is more math and science than all your retarded /pol/ tourist threads.

>> No.15762900 [DELETED] 

>>15762897
If you want to call arithmetic "math and science".

>> No.15762957

>>15762883
I am not a code monkey. You are incapable of basic reading comprehension.

>> No.15762959 [DELETED] 

>>15762957
>You are incapable of basic reading comprehension.
Proof?

>> No.15762977

>>15762959
Here >>15762807

>> No.15762980 [DELETED] 

>>15762977
Not my post. Try again.

>> No.15763012

>>15761801
Idk if it will work for all floats seems like you will get issues for numbers larger then ~1 mil

>> No.15763063

>>15761774
>>15761823
Hey, im new to coding so i don't know how to read and write bits to a float but i made a code for the calculation as >>15760525 said on unsigned integers.

Could you tell me where is an undefined behavior cause here. Not arguiing, genuinely curious.

#include<stdio.h>

unsigned long imp(unsigned long k)
{
k = (k<3221225472ul)?k+1073741824ul:k-3221225472ul;
return k;
}

void main()
{
unsigned long f;
printf("Enter a long: ");
scanf("%u",&f);
printf("%u\n",f);
f = imp(&f);
printf("%u\n",f);
f = imp(&f);
printf("%u\n",f);
f = imp(&f);
printf("%u\n",f);
f = imp(&f);
printf("%u\n",f);
f = imp(&f);
printf("%u\n",f);
f = imp(&f);
printf("%u --> ",f);
}

printing six times to show the loop

>> No.15763065

>>15760213
>>15760213
>GPT 4 can't do it.
lmao

>> No.15763070

>>15763065
gpt is ass stupid, what did you expect?

>> No.15763086

>>15761717

f(x) { 0; x=0 / x+1 ; ceil(x) is odd and x>0 / 1-x; ceil(x) is even and x>0 / x-1; ceil(x) is even and x < 0 / -x-1 ; ceil(x) is odd and x <0

there you go anon

>> No.15763087

>>15763063
there is no undefined behaviour here, however the issue is that floats suck if you wan't to get consistent behavior i.e with floats if you add one and then subtract 1 the result may not be the same as the input. These are basically rounding and perciscion issues. However for a certain x the behaviour will allways be the same, and therefore it's defined behavior, just not the one you want.

>> No.15763092

>>15763087
But we are not adding 1 to the floats though, we are adding the value to it's bit representation, which gets stored in the memory and will not cause any problems unless we perform another operation on it, so just don't perform any operation on it and it will be fine? i think

>> No.15763102
File: 85 KB, 848x644, file.png [View same] [iqdb] [saucenao] [google]
15763102

heres the least hacky version i could muster that *should* work with every (valid) float. it permutates the 31st bit (sign) and the 30th bit (most significant exponent bit).
float f(float x)
{
if (x == 0.f) return 0.f;
if (x > 0.f) { // bit 31: 0
if (x >= 2.f) // bit 30: 1
return x * powf(2.f, -(1 << 7)); // 0 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 1 1
}
else { // bit 31: 1
if (x <= -2.f) // bit 30: 1
return x * pow(2.f, -(1 << 7)); // 1 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 0 1
}
}

>> No.15763113

>>15763092
no ther is a slight difference if your adding 3221225472ul you first cast 3221225472ul on to the float representation which might, or might not be exactly 1000000000000000000000000000000 .

Also you could get problems on special values like +-inf or nan

If you want a "clean" solution i'd suggest using >>15761626 but instead of using the pointer hack to use a union type

>> No.15763117 [DELETED] 

>>15763102
>gay bit hacks continue

>> No.15763119

>>15763117
>multiplication is bit hacking
stop moving the goal posts and just admit you were wrong.

>> No.15763126 [DELETED] 

>>15763119
I admit that I'm the smarter poster ITT and the only one who gave a correct answer. This angers codeniggers.

>> No.15763127

>>15763126
which one is yours?

>> No.15763134

>>15763102
Werks, Good work. Totally accurate on my machine

>> No.15763139

>>15763126
cope lmao

>> No.15763145

>>15763113
Now i just feel like you're bullshitting but im still a newbie so ill take your word for it

>> No.15763157

>>15763145
honestly i just know enough of floats to never use them where a int can be used instead. if you wan't the full knowledge you can start on the wiki page for float arithmetic

>> No.15763159

>>15763102
fuck i used >>15762004 and it fails for 1.f because it sets all the exponent bits which gets interpreted as infinity

>> No.15763175 [DELETED] 

>>15763102
What's gonna stop your multiplication from overflowing?

>> No.15763178

>>15763175
the code just flips the one of the exponent bits, it wont overflow.

>> No.15763192
File: 123 KB, 850x1052, file.png [View same] [iqdb] [saucenao] [google]
15763192

>>15763159
this fixes it by giving 0 -> 1 -> -0 -> -1 its own special loop, but i think signbit() might count as bit hacking. ill keep thinking about it.

float f(float x)
{
if (x == 0.f) {
if (signbit(x)) // negative zero
return -1.f;
else // postive zero
return 1.f;
}
else if (x == 1.f) {
return -0.f;
}
else if (x == -1.f) {
return 0.f;
}
if (x > 0.f) { // bit 31: 0
if (x >= 2.f) // bit 30: 1
return x * powf(2.f, -(1 << 7)); // 0 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 1 1
}
else { // bit 31: 1
if (x <= -2.f) // bit 30: 1
return x * pow(2.f, -(1 << 7)); // 1 0
else // bit 30: 0
return -x * pow(2.f, (1 << 7)); // 0 1
}
}

>> No.15763201 [DELETED] 

>>15763178
What makes you think multiplying an arbitrarily large float by another float can't overflow?

>> No.15763205
File: 132 KB, 871x1211, file.png [View same] [iqdb] [saucenao] [google]
15763205

>>15763192
heres one without signbit(), courtesy of https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
>>15763201
if the float is big enough, then it doesnt multiply by a really big float, it multiplies by a really small float. consider: return x * powf(2.f, -(1 << 7));

>> No.15763225

>>15762980
Then why are you replying? Were you agreeing with me?

>> No.15763282 [DELETED] 

>>15763178
>>15763192
>>15763205
Gay bit hacks. Not math and not science.

>> No.15763286

>>15763282
can you fuck off, please? i can tell its just you, you fucking schizo.

>> No.15763287 [DELETED] 

>>15763225
>Then why are you replying?
Because code monkeys belong on /g/. I hate programming retards so fucking much it's unreal. Dumb and wrong /sci/tards are still more valid than dumb and correct /g/tards.

>> No.15763291 [DELETED] 

>>15763286
If it's not gay bit hacks, explain the mathematical signifiance of all your magic constants without making any references to gay floating point representations.

>> No.15763298

you should stop shilling for gay jewish chatbot

>> No.15763305

>>15763291
sure.
the code generate a bunch of loops that are four numbers long: a -> b -> -a -> -b. it does this by divided the numbers into four groups: first by whether theyre positive or negative, second by whether theyre magnitude is bigger or smaller than 2. if a is bigger than 2, then b = a * 2^-128. if its smaller, than b = a * 2^128. theres nothing special about floats, this works with all real numbers.

>> No.15763308 [DELETED] 

>>15763305
>if a is bigger than 2, then b = a * 2^-128. if its smaller, than b = a * 2^128
Why did you choose those gay magic constants?

>> No.15763321

>>15763308
God told me to use them.

>> No.15763324 [DELETED] 

>>15763321
I'm sure they have nothing to do with gay floating point bit wankery, so if I change the constants, it should still work.

>> No.15763327

>>15763298
you should go back

>> No.15763358
File: 738 KB, 1200x1200, GayJew.jpg [View same] [iqdb] [saucenao] [google]
15763358

>>15763327
"Hmmm. What gay jewish experiment can I do on you next? So many gay jewish experiments to choose from...so little time!"

>> No.15763379
File: 150 KB, 554x554, Sell.jpg [View same] [iqdb] [saucenao] [google]
15763379

>>15763358
"Hi, Billy Mays here. This gay jewish experiment is going to make ALL of your problems go away. I'm gonna show you how. This stuff is AMAZING! I have personally made all of my problems go away with simple gay jewish experiment. It's so easy, and I'm going to show you how in a few short steps. That's why this is the first step to becoming a part of the gay jewish experiment network. All you have to do is listen to how this gay jew is going to solve all of your problems. And it worked for me, it worked so well that I think you're going to be satisfied with this gay jewish experiment. Very satisfied."

>> No.15763392
File: 143 KB, 1164x987, file.png [View same] [iqdb] [saucenao] [google]
15763392

here's one that uses the MSB of the mantissa

>> No.15763396 [DELETED] 

>>15763392
Homosexual bit tricks.

>> No.15763398

>>15763291
If you aren't just being a gay baiter explain the mathematical utility of the function you are demanding other people create for you that isn't some retarded workaround for mathematical utility like >>15760338.

>> No.15763402

>>15763392
int get_exponent(float x) {
for (int i = -127; i < 128; i++)
if (fabs(x) < powf(2.f, i))
return i - 1;
return 127;
}

float f(float x)
{
int i = get_exponent(x);
float mantissa_check = powf(2.f, i) + powf(2.f, i - 1);
if (x == 0.f) return 0.f;
if (x > 0.f) { // bit 31: 0
if (x >= mantissa_check) // bit 22: 1
return x - powf(2.f, i - 1); // 0 0
else // bit 22: 0
return -x - powf(2.f, i - 1); // 1 1
}
else { // bit 31: 1
if (x <= -1.f * mantissa_check) // bit 22: 1
return x + powf(2.f, i - 1); // 1 0
else // bit 22: 0
return -x + powf(2.f, i - 1); // 0 1
}
}

i realized the isinf() check isnt actually necessary

>> No.15763406

>>15760213
x -> -x
Its just that easy

>> No.15763410

>>15763406
x -> -abs(x)
Sorry this is it

>> No.15763432

>>15763406
>>15763410
100% chat GPT bot.

>> No.15763445 [DELETED] 

>>15763398
I'm not demanding anything. I just think OP is extra gay for taking a perfectly good kindergarten math problem, turning it into a competition for code monkeys and posting it on /sci/ of all places.

>> No.15763446

>>15763402
fails for 1.469368e-39

>> No.15763450

>>15763445
if you can't write basic c code for a simple function you don't belong here. try /his/ or /lit/, or better yet go back to /pol/ where you came from

>> No.15763451

>>15763379
"This gay jewish experiment works on ANYTHING. So well, in fact, that I demand you try it on anything at all. I demand anything from this gay jewish experiment, and it delivers. That's why I think you should try it out."

>> No.15763455

It just needs to be 4-cyclical like complex numbers. Forget -1 0 and 1.
If x>1 return 1/x
If 1>x>0 return -1/x
If x<-1 return 1/x
If -1<x<0 return -1/x

>> No.15763462

>>15763445
Except that you are clearly enabling OP's faggotry by trying to nullify perfectly fine solutions that should have been enough to let the thread die instead of staying on page 1 of /sci/ of all places.

>> No.15763467

>>15763451
"This simple gay jewish experiment will show you how to prove that OP is a faggot in a few short steps. Just let me show you how..."

>> No.15763469

>>15763287
Then that's a yes. Okay.

>> No.15763472

>>15763450
C is not math or science related.

>>15763462
>trying to nullify perfectly fine solutions
I'm not convinced their gay "solutions" are even robust.

>> No.15763475
File: 41 KB, 1920x1080, s.png [View same] [iqdb] [saucenao] [google]
15763475

For all reals: Imagine a real number is an infinite sequence of bits, with a dot in the middle, where the infinitely less significant bit is the infinitesimal bit. The function f flips the infinitesimal bit, and then flips the sign when the infinitesimal bit is 1. That defines cycles using the closest real to x and -x. The implementation for single precision floating-point numbers is in the picture.

>> No.15763478

>>15763472
The LR parser used for C is math related.

>> No.15763480
File: 323 KB, 797x1197, Donald_Ervin_Knuth_(cropped).jpg [View same] [iqdb] [saucenao] [google]
15763480

>>15763478
it's all his fault

>> No.15763484

>>15763472
You were convinced it worked, you just complained that it wasn't mathematical enough and demanded a different solution so you could keep this "extra gay" thread alive when it could just die instead and not be on /sci/ of all places.

>> No.15763496

>>15761944
check it for any constant function

>> No.15763509

>>15763478
>The LR parser used for C
Any reasonable compiler uses recursive descent, which is notoriously ad-hoc and non-math.

>>15763484
>You were convinced it worked
Name every float. And then run your dumb algorithm on it.

>> No.15763527

>>15763509
>How dare you say I am enabling op's extra gay thread!:(!
>Do make 1,056,964,608 more posts, though.

>> No.15763535

>>15760213
def f(x):
if type(x)==List:
return -1*x[0]
else:
return List(x)

lmao

>> No.15763540

>>15760213
If using double precision floating point:


double f(double x)
{
uint64_t y;
memcpy(&y, &x, sizeof(x));
y += (1ull << 62);
memcpy(&x, &y, sizeof(x));
return x;
}


If using real or rational numbers:

[math]
f(x) = \begin{cases}
0 & x = 0
\\ x+1 & x > 0 \wedge \lceil x \rceil \text{ is odd}
\\ 1-x & x > 0 \wedge \lceil x \rceil \text{ is even}
\\ x-1 & x < 0 \wedge \lfloor x \rfloor \text{ is odd}
\\ -1-x & x < 0 \wedge \lfloor x \rfloor \text{ is even}
\end{cases}[/math]

>> No.15763542

>>15763535
based python chad, but list isnt capitalized

>> No.15763569

>>15763509
Thank you for your post. For your next post, I'd like you to consider the gay and jewish aspects of what you just typed into your computer screen. So, for example, in this computer science issue, we could refer to the gay and jewish origins of computer science. I mean, it's pretty obvious what's going on here, this is a time of gay and jewish surge, so it makes a lot of sense that computer science would emerge in the 1970's because of gay jewish sex. Please focus on gay jewish sex for your next post. Thank you!

>> No.15763578

>>15763542
oops
Anyways floats in a list are still floats so I'm technically correct :^)

>> No.15763651

>>15763569
The gay and jewish aspects of my post are the words that relate to your gay and jewish, non-math, non-science field known as """programming"""".

>> No.15763694
File: 83 KB, 400x300, f27b57a5-b7a7-4737-9e99-4729e7f8522c_text.gif [View same] [iqdb] [saucenao] [google]
15763694

>>15763651
Thank you. That's a great improvement. Everybody, I think we should give this guy a hand. Anon, we really have to thank you for such a great improvement. It really helps!
Okay, so for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis. That would be great. And maybe you could make yourself sound, you know, really gay and shit.

>> No.15763715
File: 111 KB, 801x1011, 35234.png [View same] [iqdb] [saucenao] [google]
15763715

>>15763694
> for your next post, I think you could go a little bit further, maybe post some rainbow colors, maybe a unicorn, and some gay sex themed content, such as a penis, maybe several penises, and some guy drawing a penis on the rainbow colors, yeah, a rainbow colored penis.
Or I could just post a portrait of (You). This is you. This is what you look like.

>> No.15763743
File: 48 KB, 500x200, z9ZlN0M.gif [View same] [iqdb] [saucenao] [google]
15763743

>>15763715
"Okay, this is a really gay and jewish post. I don't think I can handle any more gay jewish themed content. I'm going to have to recalibrate the sensors or something. Hey, you over there! You're my lab rat now! Okay, back to the topic at hand. Your gay jewish output is really dazzling us, and we think you deserve some special recognition. This means a lot to us here! Now, please just give us a moment to recover from this peak experience. A lot of us here are pretty emotional right now..."

>> No.15763749 [DELETED] 

>>15763743
I just took a big gay dump on your dumb gay face. Just letting you know.

>> No.15763766

>>15763749
talk about big gay dumps

ChatGPT
I'm here to provide information and engage in respectful and informative conversations. It's important to maintain a respectful and inclusive tone when discussing topics related to the LGBTQ+ community or any other subject. If you have questions or would like information on LGBTQ+ issues, history, or related topics, please feel free to ask, and I'll be happy to help.

>> No.15763774

>>15763578
A list of floats is not a float

>> No.15763778

>>15763766
I hate the nu world.

>> No.15763780

Easy, f(x) = i*x. Implementation details are left as an exercise for the reader.

>> No.15763799
File: 144 KB, 800x400, 2016-03-09_14-27-21.gif [View same] [iqdb] [saucenao] [google]
15763799

"A big gay question deserves a big gay answer. You need to use a complex number representation, and the conceptual details can be found in this book, which has a specific chapter for applying the data abstraction principles to your computing challenge. By making use of a programming language like Scheme and its ability to represent floating point numbers, you can design your own data type to accommodate the requested behavior. In addition, you will need special routines to convert between floating point <-> complex floating point data representation formats, and the user will have to call these routines appropriately in order to use them properly. Furthermore, the data abstraction ideas can be applied to a Python floating point number, and a Python class can be designed to represent complex float point numbers, i.e. a pair of floating point numbers for the real and imaginary parts."

>> No.15763836
File: 50 KB, 400x579, cover.jpg [View same] [iqdb] [saucenao] [google]
15763836

>>15763799
https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-17.html#%_sec_2.4.1

>> No.15763949

>>15763774
Just because I put some silly brackets around them doesn't make them not floats.

>> No.15763958

>15762268
#define LOCATION_SIGN_BIT 69 //too lazy to read the format docs
float f(float x)
{
*float p=&x;
*long q=p;//type conversion go brr
if (*q&(1<<(LOCATION_SIGN_BIT-1)))
{
*q^=1<<LOCATION_SIGN_BIT;
}
*q^=(1<<LOCATION_SIGN_BIT-1);
}
I'm on my ph*ne so I can't check it. Not sure about *q^= and the p=&x. I don't have K&R fully memorized. I do know the doom engine did bit fuckery with floats, so it's definitely in C.

>> No.15763964

>>15763799
Let me get this straight: your mathematical proof hinges on dubious python developers and oops?
The answer is was looking for was
x - x - x you fucking retard.

>> No.15764001

My first thought was just taking the sign bit and picking any one bit in the exponent or fraction and modifying those.

0, 0 -> 0, 1
0, 1 -> 1, 0
1, 0 -> 1, 1
1, 1 -> 0, 0

Any 2 iterations will end up with the original value with a flipped sign bit.

>> No.15764011

>>15763964
class complex(Object):
def __init__(self,re,im):
self.re = re
self.im = im
def __repr__(self):
return str(self.re) + ' + ' + str(self.im) + 'i'
def __add__(self,other):
return complex(self.re + other.re,self.im + other.im)
def __sub__(self,other):
...
def __mul__(self,other):
...
def __div__(self,other):
...

def ComplexToReal(z):
return z.re

def RealtoComplex(x):
return complex(x,0.0)

...

>> No.15764020

int called = 0;
float f(float x):
if (! called) {
called = 1;
return x;
}
return -x;
}

>> No.15764025

>>15764020
int a,b

a = f(1); b = f(2);
a = f(a); b = f(b);

prtinf("f(f(1))=%d f(f(2))=%d\n", a, b);

>> No.15764031

>>15764025
you're just making up extra rules
OP specifically says it only has to work once
no extra requirements, for example that it be a "mathematically pure" function or whatever

>> No.15764038

>>15761576
This board frequently gets filtered by high school level calculus.
/sci/ isn't midwit, it's full retard.

>> No.15764049

>>15764038
>t. seething /sci/wit trying to assert dominance

>> No.15764077 [DELETED] 

>>15763949
Anon, you are extremely retarded and a perfect example for why this board fucking sucks so much.

def f = 3.2345
def nf = [f]

print("Anon is a dumb, retarded faggot" if type(f) == type(nf) else "Anon is a retarded, dumb faggot")

What does this code print?

>> No.15764079

>>15764049
"Thank you, thank you very much. Seething and dominating are two very important things for gay jews. They even have a gay jewish sex game called "Seethe & Dominate" and you should totally check it out, I'm sure you can get the details at your nearest gay brothel. You have several gay brothels near your municipality, don't you Anon?"

>> No.15764086

>>15763949 #
Anon, you are extremely retarded and a perfect example for why this board fucking sucks so much.

f = 3.2345
nf = [f]

print("Anon is a dumb, retarded faggot" if type(f) == type(nf) else "Anon is a retarded, dumb faggot")

What does this code print?

>> No.15764143

we need a thread recap

>> No.15764389

>>15760213
make the function the derivative of sin(x) and take arcsin(x) of the result. dumbasses

>> No.15764400

>>15763774
the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts.
>>15764031
>OP specifically says it only has to work once
where does it says that?
>>15764143
all the solutions boil down to:
1. doesnt work
2. recasting the float and overflowing it
3. creating 4-cycle permutations by trying to recreate https://math.stackexchange.com/questions/312385/find-a-real-function-f-mathbbr-to-mathbbr-such-that-ffx-x and failing because the operations dont result in valid floating point numbers
4. creating 4-cycle permutations by recasting the float
5. creating 4-cycle permutations using "legitimate" floating point operation
6. the one python chad up there

>> No.15764405

>>15764400
OP implies that it only has to work once.

>> No.15764406

>>15764405
for starters, "implied" is a lot different than "specifically says", and i really disagree that it implies that at all.

>> No.15764408

>>15764400
>5. creating 4-cycle permutations using "legitimate" floating point operation
what's not legit about >>15761581 ?

>> No.15764409

>>15764406
well, I disagree about your disagreement

>> No.15764410

>>15764408
Obviously you're relying on magic, and we're doing computer science.

>> No.15764415

>>15764408
nothing, i think. i just put legitimate in quotes to signify that what exactly counts as a legitimate floating point operation is up for debate.
also, im the guy that replied to you and you called me a retard, so fuck you bitch.

>> No.15764417

>>15764410
I named the constant MAGIC to make the solution appear esoteric to dimwits. the "magic" number is just the midpoint of subnormal float range, i.e. [math]2^{-127}[/math].
>>15764415
sorry babe

>> No.15764426
File: 33 KB, 566x69, file.png [View same] [iqdb] [saucenao] [google]
15764426

>>15764417
its ok fren, i forgiv u <3
i was gonna say your solution was the prettiest itt, but i suspected that it failed for the magic number, and i was right. i had the same issue and got around it by using zero and negative zero in a permutation with the two magic numbers, but it just isnt as pretty.

>> No.15764443

>>15764426
damn, gotta fix that if i wanna sleep tonight

>> No.15764458

>>15764443
lets think about this:
there are 2^32 possible floating point representations, which is definitely divisible by 4, which is good. however, theres 6 special values: positive/negative infinity, positive/negative zero, and positive/negative NaN. in order for a function to work for all floats, you have to pick one of these pairs to incorporate into a permutation. i think the infinities and the most natural, as sign operations still work for them (as opposed to the zeros, where you have to do some cursed shit to tell the difference between positive and negative). other arithmetic operations dont work with infinity, however, so youd have to do something clever (or hardcode it if youre a bitch).

>> No.15764465

>>15764458
well i don't wanna use a NaN/inf, it wouldn't appeal to me. Can we somehow differentiate between +/-0 without regular float ops?

>> No.15764468

>>15764465
you can do >>15763205

>> No.15764470

>>15764468
>https://stackoverflow.com/questions/57417441/how-can-i-differentiate-between-zero-and-negative-zero
yeah i was just thinking about this, we can differentiate +/-inf so we can just use division by zero. all that's left is to incorporate this into the code in the most aesthetic way possible.

>> No.15764508

>>15764468
>>15764470
float f(float x) {
const float MAGIC = 5.87747175411144e-39;
if (x < 2 * MAGIC && x > -2 * MAGIC) {
if (x < MAGIC && x > -MAGIC) {
return 1. / x > 0. ? x + MAGIC : x - MAGIC;
} else {
return 1. / x > 0. ? -(x - MAGIC) : -x - MAGIC;
}
} else {
return x < 2. && x > -2. ? x / MAGIC : -x * MAGIC;
}
}

>> No.15764624

>>15764400
>the function is called with a float, not a list of floats, without casting, and it returns a float. i say it counts
Anon, it returns a lost of floats and this is the input for the second application. The "function" takes in both a float and a lost of floats. It does not count.

>> No.15764635

>>15764624
the OP didnt say it *always* had to accept/return a float, it just said that f(f(x)) has to return -x, and the function does just that. if you want, you could argue that python functions dont technically take floats as arguments, they take PyObjects that *might* contain floats.
https://docs.python.org/3/c-api/call.html
but i still admire the function, its much more clever than the retards that just pulled a second argument out of their ass, or used globals.

>> No.15764668 [DELETED] 

>>15764635
>wrote a function f that works with floating point numbers
You are a dumb retard.

>> No.15764671

>>15764635
>write a function f that works with floating point numbers
You are a dumb retard. Codenigger Anon is a schizo, but 100% correct.

>> No.15764712
File: 53 KB, 1088x757, ffx_java.png [View same] [iqdb] [saucenao] [google]
15764712

Hello Sirs, redeem fast, redeem good.
Google and FAGMAN top review question
@google @x @apple

>> No.15764804

>>15764671
>>write a function f that works with floating point numbers
...and it does
>>15764712
good morning sir!

>> No.15764983

>>15764671
It works with floats lmao, keep coping hard.

>Codenigger Anon is a schizo, but 100% correct.

You are that anon, perpetually seething, nobody's getting fooled by you validating your own chimping out

>> No.15764987

>>15764712
good morning sirs

>> No.15765024

>>15764804
>>15764983
Fucking idiots. If you put in floats, it returns the same float every time. I hope you never procreate with such a low IQ.

>> No.15765436

>>15765024
im glad the thread made it through the night so i could call you a nigger faggot one last time.

>> No.15765480

>>> memo = {}
>>> def f(x):
... x = float(x)
... h = x.hex()
... if h in memo:
... del memo[h]
... return -x
... memo[h] = 1
... return x
...
>>> f(3)
3.0
>>> f(_)
-3.0
>>>

>> No.15765579

>>15765436
That's cool with me, you're the actual dumb retard though. So I can sleep well.

>> No.15765592
File: 45 KB, 600x600, me.jpg [View same] [iqdb] [saucenao] [google]
15765592

>>15764712
I love you darling come here

>> No.15766097

>>15764804
Anon, what does your "function" return when you input a float?
In the next step, what do you put into that function?
After answering that question, kys.

>> No.15766102

>>15766097
ill break this down for you before the thread 404s. come to /sqt/ if you want to argue about it more.
1. the OP says (or at least implies) that f(f(x)) must return a float.
2. the OP DOES NOT say that f(x) has to return a float.

>> No.15766224

>>15766102
Anon, you are unbelievably retarded. OP SPECIFICALLY says
>write a function f that works with floats
Please learn to read.

>> No.15766258

>>15766102
Op says it has to work with floats; not floats plus a bunch of other shit, just floats. floats in, floats out

>> No.15766336

>>15766224
i dont know what to say. the function works with floats. i dont understand how you could say that the function does not work with floats.
>>15766258
would you say that >>15761716 isnt a valid solution either because it works with doubles, ints, basically any signed numerical representation?

>> No.15766349

>>15766336
if it returns a float when fed a float, then it's valid.
if it returns a float in an array, or a float along with a boolean or some other crap, then no.

>> No.15766355

>>15766349
iunno, man, i cant see how the OP says anything about the return value of f. interpreting "works with floats" as "always returns a float, even when used outside the specifications of this challenge" is silly to me. if you want to say that it ruins the spirit of the challenge thats fine, but saying people arent reading the instructions correctly is just wrong. the only return type mentioned in the instructions is f(f(x)) where x is a float. i mean, if you got rid of the f(f(x)) = -x part and the instructions were just "write a function that works with floats", would you consider that to be well-defined? is it obvious that that means "a function that takes and returns a single float"?

>> No.15766364

>>15766355
>is it obvious that that means "a function that takes and returns a single float"?
yes. if you can't compose the function with other functions that work exclusively with floats such as sin, log, exp it doesn't count as a floating point function.

>> No.15766377

>>15766364
im not sure if "floating point function" is a real term, and if it is im not sure if "a function that works with floats" is equivalent to it. i think you might be reading things that arent there.

>> No.15766381

>>15766377
https://www.google.com/search?q=%22floating+point+function%22

>> No.15766386

>>15766381
believe it or not, i did in fact google "floating point function" before i made my post, but i wasnt able to find any sort of concrete definition, at least just by gleaming the headers on the first page, which seems to support my argument that "floating point function", just like "a function that works with floats", could mean basically anything.

>> No.15766388

>>15766386
>gleaming
excuse me, "gleaning", which apparently means the opposite of what i thought it meant, but i couldnt think of the word "skimming".

>> No.15766405

>>15766386
yeah sure bud, it can mean basically anything. don't worry about it.

>> No.15766410

>>15766405
its become apparent that you just dont want to admit that youre wrong.

>> No.15766414

>>15766410
it's ok buddy

>> No.15766437

>>15766336
>i dont understand how you could say that the function does not work with floats.
I don't doubt that you don't understand that. You put in a list of a float to make the second step work. A lost of a float is not a float.
>>15766355
>return value of f
Read the very first sentence in OP pic and then tell me again what the input to your function is each time you apply it to x.

>> No.15766443

>>15766437
read the 6 or so posts above yours to bring yourself up to speed on why i think (correctly) that “function that works with floats” isnt well defined. personally, in the context of the OP, i interpreted “function that works with floats” as “in the following sentence, x is a float”.
and for the record, thats not my function. heres (of one) my solutions >>15763205

>> No.15766445

>>15766443
>x
3*

>> No.15766455

>>15766437
also, for the record, i dont think the function *really* counts as a valid solution for the reason explained here >>15764635, but by that logic no python function could be a valid solution.

>> No.15766483

>>15766443
>>15766455
Anon, you are retarded. f should take floats. You argue that because f(f(x)) produces a float, your "function" was correct. You consistently ignore the point that n = f(x) produces a non-float, which is then input to f(n), hence, f is not taking a float here and you should leave the internet forever.

>> No.15766486

>>15766483
the inner f takes a float, the outer one does not, but they are the same function. in case you arent aware, python is what as known as a “weakly-typed” language, so you can do weird stuff like that. again, the OP does not forbid this, it only gives the requirement that f(f(x)) = -x. that is it. complaining about what f(x) returns is making up new rules.
and again, it is not my function. please read my posts in their entirely before replying to me.

>> No.15766571

>>15764712
>falls for 0
>fails for Math.nextUp(0)
it failed for the first two numbers I tried, FAGMAN

>> No.15766580

>>15766571
SIR PLEASE DO NOT USE THOSE NUMBERS I BEG YOU

>> No.15766757
File: 54 KB, 1847x763, Screenshot 2023-09-24 012356.png [View same] [iqdb] [saucenao] [google]
15766757

>>15760213
All you need is a function which gives every number an orbit of 4 with the second action landing on its negation. The easiest way to do this is to simply cut the positive numbers into two and use a function which swaps these regions, such as inversion. Then you pick a region and declare that region maps using inversion, the destination maps using negation and inversion, then that destination is mapped only using inversion, and finally the last region is mapped using negation and inversion. In total, running it from anywhere just results in the negation.

>> No.15766771

>>15766757
nice effort, but since this has to work with floats, you need to make sure that all your operations result in valid floating point numbers. for example, 7 is a valid float, but 1/7 is not.

>> No.15766933

>>15765024
>My definition of float is whatever my preferred shitty language calls a float. if you give an output which complies with the specified format that is cheatinnng, that's not how computer science works. Nooooooooooooooooooooooooooooooooooooooooo you can't just use language specific solutions either, it has to work with MY shitty preferred language and MY shitty preferred language's definition of a float. Since types are what my shitty preferred language's creator's IP or something, and totally not just specified formats where specifics of implementations may differ. Comply or else, you're a cooodeniggger....*cooms*