Is there notation for actual 100% probability in a continuous case?

If I threw a dart at the real number line along the interval between 0 and 1,

P(dart ≠ 0.5) = 1

However, it *could* be 1/2. A probability of 1 doesn't necessarily mean it's impossible for the situation not to occur. That being said, is there a standard way to denote a probability of 1 means it *has* to happen? For example,

P(dart ≠ 2) = 1

This time, it's actually impossible, yet the notation is identical.

reddit.com
u/playsthebongcloud — 1 day ago

Basic question, but does initializing a pointer always initialize it to null?

Are these two lines any different in practice? (Especially if you want to later check if x has been given a specific address, or if it's still null.)

int* x {};

int* x { nullptr };

reddit.com
u/playsthebongcloud — 5 days ago

Really struggling with finding all conditions where two-variable inequalities hold.

I have ten seperate inequalities relating two variables, N and n, and want to describe all pairs of the two that satisfy each of them individually. Inequalities are a huge mathematical blindspot for me, so I'm really not sure how to ensure I've found all relations between N and n that satisfy it. The fact everything is wrapped in an absolute value is also throwing me off.

In all of these an additional condition also applies, |N| >= |n|.

1: |-n / N| < |N|

2: |n / (N + n)| < |N|

3: |2 - n/(N + n)| < |N|

4: |2 - n/N| < |N|

5 & 6: |1 ± N(N + n)| < |N|

7 & 8: |1 ± 1/(N + n)| < |N|

9 & 10: |1 ± 1/(N(N+n))| < |N|

I'm just not even really sure where to start. I don't expect you guys to do all 10 for me, I just want to understand a strategy for this kind of problem.

reddit.com
u/playsthebongcloud — 22 days ago
▲ 1 r/vscode

Is there a tool to determine what identifiers would be undefined in a C++ file if you didn't include any other file's includes?

Imagine you have a header file, fileA.hpp

#include &lt;iostream&gt;

int func();

...

and another header file that needs func, fileB.hpp

#include "fileA.hpp"

...

But now imagine you needed to use something from iostream in fileB. If you didn't explicitly include it in fileB, neither the compiler nor VSCode will care, because it's already being included in fileA. But, if fileA is updated and no longer needs to include iostream to run, fileB will suddenly not have it anymore either.

Is there an extension or something that will say either "You need to include iostream in fileB" or "Identifier 'cout' may become undefined" (preferably the latter)? It's very annoying to have to manage by hand.

reddit.com
u/playsthebongcloud — 23 days ago

How can I use a makefile to properly link both SDL2 and my own precompiled files?

I'm getting multiple errors, of the forms:

undefined reference to cmp::EventHandler::isEvent(unsigned int, SDL_Event*) const',

multiple definition of err::msgAccessNullptr, and

multiple definition of utl::drawFilledCircle

My program's structure is as follows:

project
&gt; comp
  &gt; events.cpp
  &gt; events.hpp
  &gt; ...
&gt; sdl2
  &gt; include
  &gt; lib
&gt; Makefile
&gt; main.cpp
&gt; err.hpp
&gt; util.hpp
&gt; entity.hpp
&gt; ...

C/C++'s building and linking system is very confusing to me, and I'm not even sure whether the problem is in my code or in the makefile, so I'm just going to paste the contents of all the possibly offending files. Sorry for the text dump.

Makefile:

CC = g++
CFLAGS = -std=c++23 -I sdl2/include -L sdl2/lib -Wall -Wextra -pedantic -Wno-unused -l SDL2 -l SDL2main -l SDL2_ttf -l SDL2_image -l mingw32

OBJS = main.o events.o


all: main


main: $(OBJS)
	$(CC) $(OBJS) -o $@ $(CFLAGS)

main.o: main.cpp
	$(CC) $&lt; -c $(CFLAGS)

events.o: comp/events.cpp comp/events.hpp
	$(CC) $&lt; -c $(CFLAGS)

The makefile seems to make main.o and events.o just fine, the main: label seems to be the problem.

events.hpp:

#pragma once

#include &lt;SDL.h&gt;
#include "../entity.hpp"

namespace cmp
{
    class EventHandler : public Component
    {
    public:
        EventHandler() = default;

        [[nodiscard]] constexpr const std::vector&lt;SDL_Event&gt;&amp; events() const;

        // Returns true if there is an event with a specified type in the events vector.
        [[nodiscard]] constexpr bool isEvent(std::uint32_t eventType, SDL_Event* eventOut = nullptr) const;

        static void tick(const Environment&amp; environment);
    private:
        std::vector&lt;SDL_Event&gt; m_events {};
    };
}

events.cpp:

#include "events.hpp"
using namespace cmp;

constexpr const std::vector&lt;SDL_Event&gt;&amp; EventHandler::events() const
{
    return m_events;
}

constexpr bool EventHandler::isEvent(std::uint32_t eventType, SDL_Event* eventOut) const
{
    for (const SDL_Event&amp; event : m_events)
        if (event.type == eventType)
        {
            if (eventOut)
                *eventOut = event;
            return true;
        }
    return false;
}

void EventHandler::tick(const Environment&amp; environment)
{
    auto* eventHandlers { environment.getAllComponents&lt;EventHandler&gt;() };
    if (eventHandlers)
    {
        std::vector&lt;SDL_Event&gt; evs {};

        SDL_Event event {};
        while (SDL_PollEvent(&amp;event))
            evs.push_back(event);

        for (auto* eventHandler : *eventHandlers) if (eventHandler-&gt;active)
            eventHandler-&gt;m_events = evs;
    }
}

For reference, before I tried to start using makefile to to pre-compile, and everything was header-only, a batch file that worked to build the project was:

g++ main.cpp ^
-std=c++23 ^
-I sdl2/include -L sdl2/lib ^
-l SDL2 -l SDL2main -l SDL2_ttf -l SDL2_image -l mingw32 ^
-Wall -Wextra -pedantic -Wno-unused ^
-o main.exe
reddit.com
u/playsthebongcloud — 29 days ago

How can I get the difference between a rational number and its corrosponding double?

The difference between the rational number "1/3" and the double-precision floating point number "1/3" is about 1.8 * 10^(-17). How would I find this number in python?

reddit.com
u/playsthebongcloud — 2 months ago

Is there a way to define Re and Im non-circularly?

There is no practical purpose to this whatsoever, I'm just curious. The typical definition of (z + conj(z))/2 is clearly circular, since the complex conjugate is Re(z) - i*Im(z).

reddit.com
u/playsthebongcloud — 2 months ago

How can I find when an inequality of two variables holds?

In all of these, |N| >= |n|.

I want to know what combination of N and n make this statement true or false:

|1 - N(N + n)| < |N|

I don't just want this one specific problem solved though, I want a general method. I have many others I want to evaluate, such as:

|1 + N(N + n)| < |N|

|(N + n) / n| < |N|

|2 - n/(N + n)| < |N|.

These are just a few of them.

reddit.com
u/playsthebongcloud — 2 months ago

Pi is an uncomputable number

R4: This guy has no idea what a computable function is. In computability theory, a computable function is a function which a universal turing machine can compute to any arbitrary accuracy in a finite amount of steps with a finite instruction set. This guy is right that it would take an infinitely long time to compute pi exactly, but the definition states it only needs to be "to any arbitrary accuracy". This guy simply will not let himself understand the meaning of that phrase. I think he's thinking of algebraic functions?

reddit.com
u/playsthebongcloud — 3 months ago

What are some uncomputable functions that aren't derivative of the halting problem?

I find the existence of uncomputable functions really cool, but all the examples I've seen are essentially just new ways of trying to predict whether a turing machine is going to halt. What are some examples of uncomputable functions that aren't essentially entirely based on the halting problem?

reddit.com
u/playsthebongcloud — 3 months ago

Is there an explicit formula to obtain the numerator and/or denominator of a rational number?

I'm looking for two functions Q -> Z such that gcd(num(x), den(x)) = 1 and num(x)/den(x) = x. So, num(0.5) = 1, and den(0.5) = 2. I assume it will be an infinite series, but can't find anything online because it all just brings up elementary "what is a fraction" articles.

Edit: Here is the solution: https://www.reddit.com/r/learnmath/s/nkH0H0eaBv

reddit.com
u/playsthebongcloud — 3 months ago

What is the exact formula to convert the components of an IEEE754 float of arbitrary precision a real number?

*to a real number

(For all of this, I'm ignoring the existence of special values such as nan or infinity.) A popular video on the quake 3 inverse square root algorithm claims the formula, given the mantissa, exponent, and sign of a 32 bit float is as follows:

(-1)^s * (2^(e - 127)) * (1 + m/(2^23))

However, plugging in zero for all variables does not result in zero, but rather 2^-127. Floats are capable of exactly representing zero, but this formula seems to suggest otherwise. Looking at the actual bits of the zero float in C confirms that floats do store it using the integer zero, so what's up here? Is zero a special value with an exception carved out for it?

I want to do the exact same math on these numbers that the computer is doing, so two's complement is needed in the exponent to denote sign; it is not allowed to be a negative number. I'm looking for a general result for all possible numbers of bits in the mantissa and exponent, so I would expect this formula to work identically for doubles as well (given that you swap E=8 for E=11 and M=23 for M=52).

So, to fully state my problem:

Given the components of a floating point number: E (the number of exponent bits), M (the number of mantissa bits), s (the sign, 0 or 1), e (the exponent, non-negative, less than 2^E), and m (the mantissa, non-negative, less than 2^M), what is the formula to convert the float to its corrosponding real?

reddit.com
u/playsthebongcloud — 3 months ago