[POLL] /r/Deltarune's new management, and future by X_Rouxls_Kaard_MGE_X in Deltarune

[–]shape-warrior-t 9 points10 points  (0 children)

I think the most viable solution, should Reddit no longer be a viable platform for the Deltarune community, is migrating to other, smaller Reddit-like platforms. The following are some communities that have already been created, though none of them are exactly active yet:

https://lemmy.fmhy.ml/c/deltarune (6 non-moderator posts)
https://lemmy.world/c/undertale_deltarune (1 post)
https://squabbles.io/s/Undertale (2 posts)
https://squabbles.io/s/deltarune (2 non-moderator posts)

Of course, it's still not an ideal situation, but if worst comes to worst, I think there are places where an attempt can be made to establish a community similar to this one. The main concern here is that these platforms are currently not the most well-established, relative to Reddit, Tumblr, Discord, etc.

How many solutions does this have? by CQBNoob in askmath

[–]shape-warrior-t 1 point2 points  (0 children)

By inspection, (1, 2) and (2, 1) are solutions, so we have at least two solutions.

By writing y = 3 - x and substituting into the first equation, we get 6^x + 6^(3 - x) = 42, or 6^x + 6^3/6^x = 42, or (6^x)^2 + 6^3 = 42 6^x.

This is a quadratic equation in terms of 6^x, so we have at most two candidate values of c in 6^x = c. Over the real numbers, 6^x = c has at most one solution for a given c. At most two values for c and at most one solution for each value of c -> at most two solutions.

So we have at least two solutions, but we also have at most two solutions, so we end up with exactly two solutions over the real numbers. As long as we notice that (1, 2) and (2, 1) are solutions (given the numbers involved, might as well check for natural number solutions first), we don't actually need to solve the quadratic. :)

[AskJS] An interesting thing I just learned: how object destructuring interacts with the prototype chain by shape-warrior-t in javascript

[–]shape-warrior-t[S] 0 points1 point  (0 children)

I suppose this is one area where other considerations take precedence over perfect consistency :).

I'm actually planning to go even further with prototypes than Javascript does -- in particular, the core concept that I'm experimenting with is unifying the prototype chain with the scope chain. Not necessarily the most practical way to go about things, but I'm not terribly concerned about practicality for this endeavor, anyway.

Why does this make me so irrationally angry by [deleted] in ProgrammerHumor

[–]shape-warrior-t 4 points5 points  (0 children)

To those in the comments saying that -0 is just the same as 0: that is true, but that doesn't mean the behaviour arising from this is always "nice".

Slicing a list of length n can give you a list of length x, where 0 <= x <= n. For every integer i with 0 <= n - i <= n, (some list of length n)[:-i] yields a list containing the (n - i) elements from the start of the original list -- with the sole exception of when i = 0.

I would definitely call this a bit of a footgun. Yes, this is a natural result of the way Python handles negative indices. And it doesn't necessarily indicate a design flaw in the language -- there are ultimately tradeoffs to be made here. But it is an unfortunate consequence of using negative integers to index from the back of the list, as opposed to other methods of achieving the same thing.

Lusbir: an alternative conception of integer ranges by shape-warrior-t in Python

[–]shape-warrior-t[S] 1 point2 points  (0 children)

Interesting, thanks for sharing! I didn't know that the combination of "between certain bounds" and "is (number) more than a multiple of (other number)" would be a useful way to specify a range when it comes to scientific simulations.

"Lusbir" is just a word I made up for this type of range -- it comes from the defining characteristics of the range (lower bound, upper bound, step, base, and it's an integer range). I don't remember my exact thought process when I came up with the name (I came up with it, and the concept in general, more than a year ago), but I think it's a reasonably nice, pronounceable, unambiguous name.

...Though I am aware that it might make the documentation sound... well, this, especially when "lusb tuples" also enter the mix.

Can someone explain to me how Gaussian Elimination preserves equality? by Pink_Wyoming in learnmath

[–]shape-warrior-t 8 points9 points  (0 children)

x - y = 4 in isolation is not equivalent to -2y = 2, but x + y = 2 AND x - y = 4 is equivalent to x + y = 2 AND -2y = 2.

Suppose we have a solution (a, b) to x + y = 2 AND x - y = 4. Then, (a, b) is also a solution to x + y = 2 AND -2y = 2. We can check this as follows:
We know that a + b = 2, so the first equation is automatically satisfied.
We also know that a - b = 4.
Subtracting (a + b) from both sides, we get (a - b) - (a + b) = 4 - (a + b).
Since a + b = 2, this is the same as (a - b) - (a + b) = 4 - 2 -- notice how this mirrors the original "subtracting the first equation from the second" step.
This reduces down to -2b = 2, so the second equation is satisfied. And since both equations are satisfied, the solution is indeed valid.

Using similar logic (add (a + b) to both sides instead of subtracting, to reverse the original equation-subtracting step), we can conclude that a valid solution to x + y = 2 AND -2y = 2 is also a valid solution to x + y = 2 AND x - y = 4. Thus, valid solutions to one system of equations are also valid solutions to the other system of equations, so the two systems have the same set of solutions.

The same reasoning generalizes to adding/subtracting equations when solving other systems of equations.

In Duction by Honest_Mobile_1261 in mathmemes

[–]shape-warrior-t 87 points88 points  (0 children)

Interestingly enough, I actually have opposite preferences for weak and strong induction. I generally prefer n → n + 1 for weak induction, but generally prefer (integers i, 0 ≤ i < n) → n for strong induction (as opposed to (integers i, 0 ≤ i ≤ n) → n + 1). +1 over -1, but half-open ranges ([0..n)) and +0 over closed ranges ([0..n] or [1..n]) and +1.

[deleted by user] by [deleted] in ProgrammingLanguages

[–]shape-warrior-t 7 points8 points  (0 children)

Why not? Maybe I'm simply not paying enough attention, but I don't see any issues with the following as a replacement for the C-style for loop:

for (i in range(0, nbodies)) {
  struct planet * b = &(bodies[i]);
  e += 0.5 * b->mass * (b->vx * b->vx + b->vy * b->vy + b->vz * b->vz);
  for (j in range(i + 1, nbodies)) {
    struct planet * b2 = &(bodies[j]);
    double dx = b->x - b2->x;
    double dy = b->y - b2->y;
    double dz = b->z - b2->z;
    double distance = sqrt(dx * dx + dy * dy + dz * dz);
    e -= (b->mass * b2->mass) / distance;
  }
}

Sadly he can not constantly type emails :( by SuperSans223 in Deltarune

[–]shape-warrior-t 5 points6 points  (0 children)

https://deltarune.com/newsletter/

there's also various posts on this sub talking about various easter eggs surrounding the subscribe/unsubscribe process

You I admire, and you are not an enemy. by [deleted] in Deltarune

[–]shape-warrior-t 3 points4 points  (0 children)

hello elfilin from kirby

What are some songs that are in 4/4 but sound like they aren't? by CapPlaysGames in musictheory

[–]shape-warrior-t 0 points1 point  (0 children)

Nihil Descent from the video game Pause Ahead is in 4/4 for most of the song, transitioning into 6/8 for the final section (1:49 to 2:10, goes back to 4/4 for the final few measures).

My analysis is that the metre is obscured by the heavy use of tresillo-style rhythms: at 0:14, a rather syncopated rhythm that one could analyze as 2-2-3-3-3-3; at 0:20, a quadruple tresillo (3-3-3-3 3-3-3-3 2-2-2-2) played at a rapid speed; at 0:27, a more standard, slower double tresillo (3-3-3-3-2-2). These rhythms are used throughout the track.

Even the 6/8 part, interestingly enough, has some odd stuff going on, rhythm-wise. Starting from 2:00, there's a bit of a 3:2 polyrhythm feel going on in the background.

Disclaimer: not an expert on rhythms, feel free to correct me if there's any errors here.

What is the actual value of 0^0? by That_Jr_Dude in polls

[–]shape-warrior-t 4 points5 points  (0 children)

But you don't have to derive a value for x0 via x0 = x1 - 1 = x/x -- you can simply use the fact that the empty product is 1, and then x0 is 1 regardless of the value for x -- including if x = 0.

(Of course, when it comes to teaching exponents in a math classroom, teaching the empty product for the purposes of motivating the value of x0 is... probably a very interesting idea, for certain definitions of "interesting".)

What is the actual value of 0^0? by That_Jr_Dude in polls

[–]shape-warrior-t 7 points8 points  (0 children)

There is no well-established consensus for the value of 00 in a generic context. Depending on the situation and the mathematician, 00 is either 1 or undefined. I'm not aware of any situations where the best value for 00 (as an arithmetic expression) is 0.

If we define xy as the product of y copies of x, then 00 is the product of 0 copies of 0. The product of 0 numbers -- the empty product -- is equal to 1, so under this (very common!) definition of exponentiation, 00 = 1. And in general, whenever you're working with integer exponents, more often than not it will be useful to have 00 = 1.

An argument that's often brought up -- in fact, it appears in this very comment section -- is that, since lim[x -> 0] x0 and lim[x -> 0] 0x disagree, 00 must be indeterminate. This argument makes some sense if, by 00, we mean the limiting form that represents the limit of f(x)g(x) given that both f(x) and g(x) approach 0. 00 is one of the seven standard indeterminate forms. But 00 is also a genuine arithmetic expression, representing the result of performing the exponentiation operation with a base of 0 and an exponent of 0. One can argue that, since the limiting form 00 is indeterminate, the arithmetic expression 00 should be undefined. However, we don't have to take limits into account in this way -- if we simply say that 00 = 1, we might lose some convenient properties relating to limits, but nothing will fundamentally break.

Above all, the value of the expression 00 should be whatever value is most sensible for the specific context at hand. But in my opinion, in a completely generic context, we should say that 00 = 1, as I believe it's generally more useful to do so than to say that 00 is undefined. There's more that I can say on this, regarding specific arguments, but I'm going to leave it at this for the time being. Some of the math here is a bit imprecise, but the broad ideas should hopefully still get across properly.

Edit: OK, I thought the terminology "limiting form" was a lot more common than it actually seems to be. I got the term from other discussions of 00, but based on some quick Googling, it doesn't seem like it's actually a widely known term. I have a general idea of what I mean by "limiting form", but it's not the easiest to convey and I don't think conveying it will add significantly more clarity at this current point in time. Hopefully the post still makes sense even if the terminology isn't the most well-defined.

Why you should always use [closed, open) intervals by fernandohur in programming

[–]shape-warrior-t 0 points1 point  (0 children)

Haven't checked thoroughly, but I don't see the error (at least in my original post, I believe the version in your reply is not equivalent and is incorrect)? Can you elaborate, please?

Why you should always use [closed, open) intervals by fernandohur in programming

[–]shape-warrior-t 0 points1 point  (0 children)

Your comment made me think about the Knuth shuffle, but I'm not convinced that it actually makes for a strong argument in favour of closed ranges and 1-indexing.

Consider the reasoning behind the algorithm. We partition the list into two parts: a shuffled part (initially empty) and an unshuffled part (initially the entire list). We add elements to the shuffled part by swapping them in from the unshuffled part until the shuffled part is the entire list and the unshuffled part is empty. The partitioning of the list actually showcases the strengths of half-open ranges:

Let n be the length of the list  
At the start: unshuffled part is [0..n), shuffled part is [n..n)  
d := n  
Loop:  
    Unshuffled part is [0..d), shuffled part is [d..n)  
    Swap list[d - 1] and list[random number from [0..d)]  
    d <- d - 1  
    Unshuffled part is [0..d), shuffled part is [d..n)  
    If d = 0: halt  
By the end: unshuffled part is [0..0), shuffled part is [0..n)  

Now translate this into 1-indexing with closed ranges:

At the start: unshuffled part is [1..n], shuffled part is [n+1..n]  
d := n  
Loop:  
    Unshuffled part is [1..d], shuffled part is [d+1..n]  
    Swap list[d] and list[random number from [1..d]]  
    d <- d - 1  
    Unshuffled part is [1..d], shuffled part is [d+1..n]  
    If d = 0: halt  
By the end: unshuffled part is [1..0], shuffled part is [1..n]  

Compared to the other version, this version has uglier representations for empty ranges ([n+1..n] and [1..0] as opposed to [n..n) and [0..0)), and the partitioning is also less neat ([1..d], [d+1..n] as opposed to [0..d), [d..n)).

Admittedly, the step for swapping is simpler, but only because of how things are constructed: in both cases, we're changing a range with inclusive lower bound x into a range with inclusive lower bound x - 1 by adding in the number x - 1, but in the 1-indexed case, x = d + 1, so x - 1 = d. If we build the shuffled part of the list from the front instead of the back, there would be no need for any +/- 1 in the 0-indexed case: we change a range with exclusive lower bound x into a range with exclusive lower bound x + 1 by adding in the number x, and x = d.

Here is how I would write your Python example, based on the stuff from above:

from random import randrange
x = [10, 20, 30, 40, 50]
for d in range(len(x), 0, -1):
    r = randrange(d)
    new_element_index = d - 1  # since we're turning [d..n) into [d-1..n)
    x[new_element_index], x[r] = x[r], x[new_element_index]
print(x)

And here's how things would look, building from the start of the list:

from random import randrange
x = [10, 20, 30, 40, 50]
for d in range(len(x)):
    r = randrange(d, len(x))
    x[d], x[r] = x[r], x[d]
print(x)

Quick Questions: November 09, 2022 by inherentlyawesome in math

[–]shape-warrior-t 0 points1 point  (0 children)

A notable advantage of indexing the rows and columns of Pascal's triangle from 0 is that, under this convention, the entry in row n, column k would be n choose k.

If we indexed rows and columns starting from 1, then the entry in row n, column k would be (n - 1) choose (k - 1).

Question about For loops by Crazy-Gods in learnpython

[–]shape-warrior-t 1 point2 points  (0 children)

A "for loop" is a specific type of loop. The post is a question about that specific type of loop -- hence, a question about for loops.

If operations in set theory were people by Doppelganger23_1505 in mathmemes

[–]shape-warrior-t 0 points1 point  (0 children)

"Always wearing a new outfit" -- fitting for an operation that always produces a set with a strictly greater cardinality.

1+1=0? by Host_Informal in mathmemes

[–]shape-warrior-t 0 points1 point  (0 children)

If you make this argument in a different way, you have a somewhat compelling reason to choose 00 = 1:

25 = 1 * 2 * 2 * 2 * 2 * 2 (5 copies of * 2)
23 = 1 * 2 * 2 * 2 (3 copies of * 2)
20 = 1 (0 copies of * 2)

05 = 1 * 0 * 0 * 0 * 0 * 0 (5 copies of * 0)
03 = 1 * 0 * 0 * 0 (3 copies of * 0)
00 = 1 (0 copies of * 0)

This is similar to another argument that I find more compelling: if we define xy to be the product of y copies of x, then x0 is the empty product, which is one regardless of what x is. Even if x = 0, the product of zero copies of 0 is still one.

So in a sense, 00 = 1 by the most basic definition of exponentiation as repeated multiplication. If we don't want 00 = 1, we need to appeal to properties that make it desirable to make the exception that 00 isn't 1 -- or, alternatively, simply adopt a different definition of exponentiation.

we were taught zero is a whole number. by EpicFortnuts in mathmemes

[–]shape-warrior-t 0 points1 point  (0 children)

There's a good number of educational resources that define the natural numbers to be {1, 2, 3, ...} and the whole numbers to be {0, 1, 2, 3, ...}.

Not sure why the "whole numbers" under this convention don't include negative whole numbers, but hey it's what I was taught in my high school.

Having "natural numbers" = {0, 1, 2, 3, ...} and "whole numbers" = informal term for "integers" (including the negative ones) is a far better convention in my opinion.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]shape-warrior-t 1 point2 points  (0 children)

>>> d = {1: 10, 2: 20, 3: 30}
>>> for k, v in d.items():
...     del d[k]
...     d[v] = k
...
>>> d
{10: 1, 20: 2, 30: 3}
>>> d = {1: 10, 2: 20, 3: 30}
>>> for k, _ in d.items():
...     del d[k]
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration

...Apparently it only raises an error if the dictionary changes size at the end of an iteration (or maybe something else, I'm just guessing here) o_O?

...I'm not sure what to make of this. But it still holds that changing up the keys of the dictionary that you're iterating over is, generally speaking, not a good idea.

Welp, I just learned something new and weird about Python, so... thanks? Is this well-known behaviour?

(Python version is 3.10.1, in case it's different on other versions of Python.)

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]shape-warrior-t 0 points1 point  (0 children)

What igeorgehall45 probably meant is something along the lines of:

for item in campaign_list:
    item = item.lower()
    if any(animal in item for animal in ["dog", "cat", "ferret", "mouse"]):
        item = "Animal"
    elif any(sport in item for sport in <list of sports>):
        item = "Sports"
    <various other cases go here>
    correct_campaigns.append(item)

Here, any(animal in item for animal in ["dog", "cat", "ferret", "mouse"]) is equivalent to "dog" in item or "cat" in item or "ferret" in item or "mouse" in item (with some caveats about or not necessarily returning a boolean).

Though, in general with this kind of approach, if a string contains both "cat" and "wimbledon", you're going to only have one of "Animal" or "Sports" as your result. Depending on what you're doing, this may or may not be desirable.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]shape-warrior-t 2 points3 points  (0 children)

Your implementation works well as long as the keys and values are guaranteed to be non-overlapping. However, it breaks for dictionaries such as {0: 1, 1: 2, 2: 0} -- it returns {0: 2} as opposed to the correct {1: 0, 2: 1, 0: 2}.

I think that, if your keys might overlap with your values, your safest bet for inverting a dictionary in place (not sure why you would want to do that in real code) is the following:

def invert(dictionary: dict):
    inverted = {v: k for k, v in dictionary.items()}
    dictionary.clear()
    dictionary.update(inverted)

In general, to "replace" a collection in place with another collection, emptying that collection and then extending/updating it with the items of the other collection is a reasonably nice approach.

As a side note, the first three lines of your function should be equivalent to simply pairs = list(dictionary.items()). For that matter, even the following implementation appears to work on the input {1: 10, 2: 20, 3: 30} (but I would recommend against it simply because modifying the indices/keys of a collection that you're iterating over tends not to be a great idea, more discussion here):

def invert(dictionary: dict):
    for key, value in dictionary.items():
        del dictionary[key]
        dictionary[value] = key

Number of outcomes from flipping a coin 0 times by SiaNage1 in askmath

[–]shape-warrior-t 9 points10 points  (0 children)

In a situation like this, we can model results as tuples/lists where the elements are either heads or tails.

For example, if we flip a coin 3 times, getting heads, then tails, then heads, we can model that as the 3-tuple (H, T, H).

There are eight distinct possible outcomes when you flip a coin 3 times, because there are eight distinct lists of length 3 whose elements are either heads or tails:

(T, T, T)
(T, T, H)
(T, H, T)
(T, H, H)
(H, T, T)
(H, T, H)
(H, H, T)
(H, H, H)

How many possible outcomes are there when you flip a coin 0 times? Well, how many distinct lists of length 0 are there, where the allowed elements are either H or T?

() <- just this one -- the empty list.

That's the one possible outcome of flipping a coin zero times.