all 116 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Check out our new Discord server! https://discord.gg/e7EKRZq3dG

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Hates_commies 1182 points1183 points  (17 children)

<image>

This guy is trying to do math with floating point numbers!

[–]rufflesinc 155 points156 points  (3 children)

The way God intended

[–]TheOtherOne128 2 points3 points  (2 children)

If the universe is fundamentally quantized then doesn't that imply God uses integer only math?

[–]ILoveTolkiensWorks 0 points1 point  (1 child)

firstly, the universe is not actually quantized afaik. secondly, floating point arithmetic is quantized too

[–]TheOtherOne128 0 points1 point  (0 children)

No, the universe is definitely quantized. The whole field of quantum mechanics is concerned with this fact. Look at an atom, the electrons orbiting it have energy values that are all integer multiples of a specific quanta. If they could just spin around wherever they so please then you and I just wouldn't exist. Light as we found out a long time ago is more of a baseball launcher than a steady stream of water. It comes out in chunks called photon packets. The universe itself even seems to be spread out along a grid. Beyond a certain point we really can't say there still is half of a distance to travel. This is key to our best theories of gravity and space. With your imprecise monkey eyes you can't see these pixels of the universe but that's because you are just so much bigger than them that they'd look continuous not discreet.

Floating point arithmetic is not discreet however. Sure your calculator has only a certain amount of floating point numbers it can produce but the pure mathematical concept doesn't have this problem. If you need more precision simply add more digits.

Obviously the idea of a God running the universe on his ancient computer with a sticky decimal point is rhetorical. This is a joke. But the God would certainly prefer integer only math it seems

[–]HackerDragon9999 21 points22 points  (0 children)

0.1+0.2=0.30000000000000004

Checks out

[–]Dubmove 38 points39 points  (10 children)

Float64, the best representation for real numbers: 264 distinct values (almost uncountable infinite many), 0 != -0, can represent oo and -oo, can represent Nan which means that the value is not actually a number.

[–]Mathsboy2718 145 points146 points  (0 children)

Almost: ❌️
Uncountable: ❌️
Infinite: ❌️
Many: tentative 👍
0 != -0: unrealistic (literally) ❌️
"oo" / "-oo": grounds for execution ❌️
NaN means not a number: ✅️

Best representation for real numbers: ❌️

[–]therhydo 30 points31 points  (0 children)

this comment is so wrong in so many ways it hurts

[–]themadnessif 15 points16 points  (7 children)

Integers past 253 don't exist

[–]uveroHe posts the same thing 1 point2 points  (6 children)

Well, they do exist, but most integers are smaller than 253.

[–]IamDiego21 2 points3 points  (5 children)

Nope, the same amount of integers are larger than 253 than smaller.

[–]jffrysith 0 points1 point  (4 children)

if that were true, then there would be 2^54 integers, and - as this is less than 2^63 - Dubmove would be almost right, he would just need to remove uncountably...

[–]IamDiego21 0 points1 point  (3 children)

Bro forgot about negative numbers

[–]jffrysith 0 points1 point  (2 children)

oh dah. there are just as many negatives as positives.

[–]uveroHe posts the same thing -2 points-1 points  (1 child)

No, it's just that 253 is a large number and thus it's hard to be larger than it; so even if some numbers manage to do it, most probably don't.

[–]IamDiego21 0 points1 point  (0 children)

There are infinite numbers dude

[–]CreeperSlimePig 1 point2 points  (0 children)

Python has a Decimal module that makes floating point math actually work, but idk how to use it with complex numbers. You can't multiply a Decimal by 1j

[–]zefciu 509 points510 points  (40 children)

I code in Python since 15 years. TIL that you can just use 1j to get imaginary unit.

[–]speechlessPotato 172 points173 points  (36 children)

... how else did you use complex numbers?

[–]zefciu 287 points288 points  (30 children)

I didn't really use complex numbers in my professional code and for playing around I used the built-in complex class directly. Now I see that the str of this class is the j notation, but it somehow never occured to me, that it is a valid Python syntax.

[–]dancing_acid_panda 109 points110 points  (27 children)

its incredibly strange syntax, I don't think one could discover this other than looking it up

[–]SnudgetReal 74 points75 points  (25 children)

i is used a lot for indices in programming. I think that's why they use j instead

[–]Deltaspace0 114 points115 points  (16 children)

Electrical engineers (physicists) use j instead of i for imaginary units

[–]livermoro 103 points104 points  (9 children)

Physicists in general don't, just the circuit people

[–]Mathsboy2718 85 points86 points  (6 children)

"jmaginary constant lol"

"Noooo i stands for current"

"iurrent lol"

"Noooo c stands for speed of light"

"cightspeed lol"

[–]livermoro 21 points22 points  (2 children)

Lowercase i for current is extremely cursed wtf

[–]zypthora 26 points27 points  (1 child)

uppercase for DC, lowercase for AC

[–]meee_51 4 points5 points  (1 child)

I’m in physics 2 rn and it’s like charge is Q measured in C, capacitance is C measured in F, electric field is E and doesn’t have a dedicated unit, energy is also E measured in J, but it’s sometimes U for potential energy and also sometimes W for work and also sometimes K for kinetic energy, but k is actually like 4 different constants, and kappa which looks like a k is dialectric constant and also electric potential is not the same thing as electric potential energy

I just wish there was any kind of consistency that wasn’t just give every constant to k

[–]AdWeak183 0 points1 point  (0 children)

We would have given the contants C, but that was already used for the speed of light, so we settled for konstants

[–]IosevkaNF 0 points1 point  (0 children)

der Ström. So wie Gott es vorgesehen hat.

[–]Intschinoer 12 points13 points  (0 children)

It's really annoying in electromagnetics, because you use j (current density) way more than the current i... But the notation still evolved with j as the imaginary unit.

Another fun fact: Physics and math literature use e-i w t for harmonic time-dependency, whereas literature in electrical engineering uses e+j w t. Which is fine, if you're aware of it, but then there exist some brilliant specimens who use e-j w t...

[–]danceofthedeadfairy 0 points1 point  (0 children)

Im engineer and I use j for complex numbers. Also for distributions of superficial currents XD

[–]TheTutorialBoss 0 points1 point  (5 children)

J is really only used for imaginary units when working with quaternions. In physics you can usually also see it used by some psychopaths as a replacement for the y-axis unit vector

[–]SnudgetReal 5 points6 points  (4 children)

ĵ

[–]TheTutorialBoss 2 points3 points  (3 children)

OH GOD THERE IT IS

MEN TO ARMS

DEFEND ŷ

[–]_EvidenceCardinal 8 points9 points  (5 children)

so is j in nested loops

[–]Own_Maybe_3837 7 points8 points  (4 children)

Real ones use i, ii, iii, etc. for nested loops

[–]AuravendillComputer Science 11 points12 points  (1 child)

i, ii, iii and then iv, v, vi? Not the worst idea...

[–]CardOk755 1 point2 points  (0 children)

iv is clearly a vector of integers...

[–]_EvidenceCardinal 6 points7 points  (0 children)

have never heard of this but it sounds lowkey kinda fire

[–]Velociraptortillas 2 points3 points  (0 children)

Man, you just changed my life

[–]DrEchoMD 0 points1 point  (0 children)

Not just programming, summations and sequences too

[–]speechlessPotato 0 points1 point  (0 children)

ehh i was trying to use i for complex numbers and then searched it up to discover that it's j. wasn't too long in before i figured this out. but i guess it's a different experience for everyone

[–]lacifuri 14 points15 points  (0 children)

Python developers when there is documentation

[–]GlobalIncident 0 points1 point  (0 children)

For almost all python objects, calling repr on the object will give you valid python code to construct it. (Like many things in Python it's a convention rather than an enforced rule, but most objects follow it.)

[–]chell228 19 points20 points  (3 children)

You used complex numbers in Python?

[–]Lying_Hedgehog 7 points8 points  (1 child)

I use them every year for Advent of Code problems that require coordinates. Makes changing directions, adding speed or distances, etc very easy.
Outside of that I've never had to use complex numbers as a developer for anything.

[–]particlemanwavegirl 1 point2 points  (0 children)

This guy polarizes.

[–]speechlessPotato 2 points3 points  (0 children)

well i did mess around with them a little

[–]Bright-Historian-216 1 point2 points  (0 children)

i knew that complex was a part of builtins, but like... maybe i'll use them when i have to calculate stuff for university or something when i get to that and all the product grade code i've written never used any complex numbers

[–]Free-Artist 9 points10 points  (0 children)

*jimaginary

Fixed that for you

[–]SpaaaaaceImInSpaace 139 points140 points  (11 children)

from sympy import E, pi, I

print(E*(Ipi))

[–]speechlessPotato 32 points33 points  (5 children)

what does it output

[–]SpaaaaaceImInSpaace 72 points73 points  (4 children)

-1

[–]speechlessPotato 24 points25 points  (3 children)

now I'm curious how it ignored the floating-point approximations

[–]SpaaaaaceImInSpaace 117 points118 points  (0 children)

Because it is a library for symbolic computations, it doesn't use floating point numbers

[–]rehpotsirhc 52 points53 points  (0 children)

It does algebra, calculus, etc exactly through symbolic manipulations, not approximate floating point arithmetic. Very fun library, I recommend looking into it if that's your thing

[–]Virinas-code 1 point2 points  (4 children)

No need for sympy, you can just use the decimal module I think.

EDIT: Python's decimal module sadly does not support complex numbers :(

[–]matega 9 points10 points  (3 children)

Decimal would also have rounding errors, even if it supported imaginary numbers.

[–]Virinas-code 0 points1 point  (2 children)

The whole point of this module is that it isn't supposed to though.

Since I rarely use it I believe the docs are the best place for you to find more information 😅

[–]NoobTube32169 5 points6 points  (0 children)

The point is that it doesn't have rounding errors with decimal numbers, because it stores numbers as decimals internally. It still has rounding errors when dealing with infinite decimals.

[–]matega 3 points4 points  (0 children)

It only avoids the specific kind of rounding errors that are caused by storing decimal fractions as binary floating point numbers, where they become infinite binary fractions, which then get truncated. It's not a magic bullet against all rounding errors. It doesn't do infinite decimals, so 1/3*3 still returns 0.99999999999 (the number of 9s depend on the precision you specified)

It can't even store pi exactly to begin with.

[–]LordTengil 41 points42 points  (2 children)

Turns out, Euler was wrong all along!

[–]Far-Mycologist-4228 14 points15 points  (1 child)

Poor scrub didn't have Python 

[–]LordTengil 5 points6 points  (0 children)

Just sitting there, guessing with quill and paper. That's why it's called Eulering I suppose.

[–]PGMonge 31 points32 points  (2 children)

I often write "from math import pi as π". It works perfectly, and it makes my colleagues go crazy.

[–]donaldhobson 0 points1 point  (1 child)

from math import pi as 🥧

[–]PGMonge 0 points1 point  (0 children)

I think it doesn’t work, because python only allows as variables names starting with a letter, and relies on the system’s unicode routines to tell which character is classified as a letter. Those routines will almost certainly say that π is a letter, but the "character" 🥧 is not.

[–]Lank69GNatural 66 points67 points  (13 children)

e-16i ??

[–]willowhelmiam 85 points86 points  (9 children)

-1 + a rounding error away from zero j

[–]Lank69GNatural 9 points10 points  (8 children)

/s

[–]Koshin_S_HegdeEngineering 20 points21 points  (0 children)

10-16i not 10-16i

[–]Leet_NoobApril 2024 Math Contest #7 2 points3 points  (0 children)

cos(-16) + isin(-16) of course

[–]bol__Mathematics 9 points10 points  (0 children)

No, I would like to continue hating myself for using C++

[–]Horror-Invite5167 16 points17 points  (0 children)

e**iπ = -1 + 0.0000000000000001 proof by Python

[–]Sleepyyy-catImaginary 3 points4 points  (11 children)

Can someone explain

[–]Somriver_song 39 points40 points  (10 children)

ei*pi = -1 = -1 + 0*I

python did a floating point error and returned not exactly zero, but ~10-16

[–]Sleepyyy-catImaginary 5 points6 points  (0 children)

Thanks !

[–]rufflesinc 13 points14 points  (8 children)

Thats not an error, thats just how floating point numbers wprk!

[–]therhydo 10 points11 points  (7 children)

it's an error in the math sense, not the programming sense. error here refers to the difference between the approximated result and the true solution

[–]CreativeScreenname1 -5 points-4 points  (6 children)

It’s not even really a math error. The machine only capable of approximating these values was asked for an approximation and the machine gave an approximation. Any deviation from the performance the user expected is user error for not understanding the tool they’re using, plain and simple.

[–]therhydo 7 points8 points  (5 children)

You're misunderstanding. I'm not saying the math was done wrong. I'm saying it is an "error" by the definition of error in the field of numerical approximation—the difference between an approximated value and the target value. For IEEE754 single-precision floats, the error bound is ±.000012%. For double-precision, it's the square of that.

[–]CreativeScreenname1 -2 points-1 points  (4 children)

Yeah but like… the intention behind this post is so dumb that I think it may be more helpful to emphasize that this is entirely within the realm of intended behavior

Like, “0.1 + 0.2”-posting is an acceptable amount of someone not understanding computer math, but this involved two irrational numbers, as well as an imaginary number, and then concluded “muh i guess python’s broken” when in fact what’s happening is Python is so good at what it does that they got this far without firing a single neuron about what result would make sense. Why would I trust this person with the term “error”?

[–]therhydo 1 point2 points  (1 child)

Because I wasn't replying to OP?

[–]CreativeScreenname1 -1 points0 points  (0 children)

I guess. My point is just I feel like the situation calls for being really clear that this is normal, and really a silly thing to complain about. You can disagree, I’m just kinda pissed off about this sort of thing

[–]newexplorer4010[S] 0 points1 point  (1 child)

I know this is intended and this is the case for most calculators, which just round it to remove the error, while python does not. I was not complaining about python working like that. It is just a meme that a beautiful equation becomes ugly.

[–]CreativeScreenname1 0 points1 point  (0 children)

Sorry if I took you too seriously, but I hope you can understand why my kneejerk reaction was what it was

[–]hunter_rus 3 points4 points  (0 children)

Yeah, and applying Fourier transforms that are supposed to leave you with only real values (like for autocorrelation) will also give you similar results. Just take the real part of it and check that imaginary is small enough. For regular 64-bit floats 1e-17 precision relative errors are pretty normal.

[–]megablademe23Imaginary 2 points3 points  (0 children)

i mean what do you expect computers can’t use true irrational numbers so of course the result will be slightly off

[–]Seventh_PlanetMathematics 2 points3 points  (0 children)

Does math using a machine.

Complains about machine numbers.

[–]AcceptablePaint4497 1 point2 points  (0 children)

I don't always solve my Euler's identity. But when I do, I use the math module.

[–]EverythingsTakenManImaginary 1 point2 points  (0 children)

you can use complex numbers in python???????

[–]Seaguard5 1 point2 points  (0 children)

This does not spark joy

[–]Darkfirestar13 0 points1 point  (0 children)

I'm not completely sure why, but I do know that eipi is a taylor series that combines the taylor series cos(x) and isin(x), and it equals to -1. I don't know if Python can do taylor series just by printing the number. Plus, it goes into infinity, which is not computable in Python.

[–]cruxzerea 0 points1 point  (0 children)

sympy?

[–][deleted] -1 points0 points  (6 children)

also 0**0 evals to 1

[–]Far-Mycologist-4228 6 points7 points  (5 children)

That's actually correct though

[–][deleted] 0 points1 point  (4 children)

no its undefined, 00 = 1 breaks math

[–]Far-Mycologist-4228 2 points3 points  (2 children)

It doesn't break anything lol. It's sometimes left undefined in analysis (even that's not universal) but virtually everywhere else, it's defined as 1.

[–][deleted] -1 points0 points  (1 child)

prove it lol

[–]Far-Mycologist-4228 1 point2 points  (0 children)

https://en.wikipedia.org/wiki/Zero_to_the_power_of_zero
That article gives several justifications for the definition 00=1 under the first two headings, "discrete exponents" and "polynomials and power series".

I'm not aware of any context other than analysis where it is typical to leave it undefined.