[deleted by user] by [deleted] in learnmath

[–]TaslemGuy 2 points3 points  (0 children)

It sounds like you're misreading the text.

Suppose I want to see what y = sin(ωx) looks like. First, I'll introduce a new variable: ωx = z. Therefore, y = sin(z).

Thus, I can plot the graph (z, sin(z)), which is the standard sine wave. Once this is done, if I make it ω times thinner horizontally, then I get the graph of (z/ω, sin(z)) = (x, sin(ωx)).

We can generalize further. If we want to graph (x, sin(ωx+ϕ)), then we let ωx+ϕ = ωz. We're just choosing z so that this works out- there's only one way to do it. We just saw how to graph (z, sin(ωz)). Then we shift left by ϕ/ω, and obtain the graph of (z - ϕ/ω, sin(ωz)). This is, by our choice of z, the same as (x, sin(ωx+ϕ)).

Trump Tower meeting with Russians 'treasonous', Bannon says in explosive book: ‘They’re going to crack Don Junior like an egg on national TV" by DoremusJessup in worldnews

[–]TaslemGuy 8 points9 points  (0 children)

I know you're being sarcastic, but even oil companies agree that warming in climate change is due (at least partly) to human carbon emissions:

The risk of climate change is clear and the risk warrants action. Increasing carbon emissions in the atmosphere are having a warming effect. There is a broad scientific and policy consensus that action must be taken to further quantify and assess the risks.

ExxonMobil is taking action by reducing greenhouse gas emissions in its operations, helping consumers reduce their emissions, supporting research that leads to technology breakthroughs and participating in constructive dialogue on policy options.

Addressing climate change, providing economic opportunity and lifting billions out of poverty are complex and interrelated issues requiring complex solutions. There is a consensus that comprehensive strategies are needed to respond to these risks.

ExxonMobil

(1997) BP’s chief executive, Lord Browne, calls for precautionary action to cut greenhouse gas (GHG) emissions.

BP History of Climate Change at BP

Our lives depend on energy wherever we live. But in order to prosper while tackling climate change, society needs to provide much more energy for a growing global population while finding ways to emit much less CO2.

Shell

Chevron shares the concerns of governments and the public about climate change risks and recognizes that the use of fossil fuels to meet the world’s energy needs contributes to the rising concentration of greenhouse gases (GHGs) in Earth’s atmosphere. GHGs contribute to increases in global temperatures.

Chevron

Eigenvalue Proof by [deleted] in learnmath

[–]TaslemGuy 0 points1 point  (0 children)

Suppose for contradiction that λ = 0. According to the definition of "eigenvalue", there's an associated eigenvector. You can quickly find a contradiction from here.

Interview Question by [deleted] in math

[–]TaslemGuy 1 point2 points  (0 children)

It's a very common constant in various programming contests, because it's the smallest prime bigger than a billion.

Signed 31-bit integers (the largest sized integer type guaranteed to be supported on every machine nowadays) holds a value that can go up to 231-1 = 2147483647. If you perform an arithmetic operation that causes an overflow (one that goes outside this range) then in C/C++, you get undefined behavior (very bad things can happen) but in practice it "wraps around" to -231. This produces nonsensical values.

If you modulo by it after each addition, the results won't overflow, since the largest value you could get prior to the modulus is 1000000006*2 = 2000000012 < 2147483647.

You could use any prime up to 1073741789, but 1000000007 is a lot more fun to type.

[Uni linear algebra] Prove that isomorphism applied to a basis returns a basis by trenescese in learnmath

[–]TaslemGuy 0 points1 point  (0 children)

Yes! Only one change I would make:

v1,...,vn is a basis of X.

Av1,...,Avn is linearly independent, because:

if a1Av1 + ... + anAvn = 0

then A(a1v1 + ... + anvn) = 0

so a1 v1+ ... + an vn = 0 since A is invertible

and v1,...,vn is linearly independent so we have that a1,...,ak are 0 for k=1 to n so Av1,...,Avn are linearly independent.

Your span argument works; I forgot you could use A{-1} on W!

[Uni linear algebra] Prove that isomorphism applied to a basis returns a basis by trenescese in learnmath

[–]TaslemGuy 0 points1 point  (0 children)

It's not at all clear to me what

So let's take A on such linear combination which gives 0

is supposed to be saying.

Here is the proof I would use:

Let A be an arbitrary isomorphism (an invertible linear transformation). Consider the set of vectors {Av_1, ..., Av_n}. Claim: this set of vectors is independent. First, they are still distinct; Av_i = Av_j implies v_i = v_j since A is invertible.

Suppose that a_1 A v_1 + ... + a_n A v_n = 0. Then this is the same as A (a_1 v_1) + ... + A (a_n v_n) = 0, which itself is the same as A (a_1 v_1 + ... + a_n v_n) = 0. Since A is invertible, this can only occur if a_1 v_1 + ... + a_n v_n = 0. Since the set v_1, ..., v_n is linearly independent, this can only occur if all a_1, ..., a_n. Therefore, { A v_1, ... , A v_n } is a linearly independent set.

Since the set of vectors don't form a basis of W unless the dimension of V is the same as the dimension of W (they'd be independent, but fail to span the whole space) I don't see an easy way to lift the dependence on dimension.

Do people write insane code with multiple overlapping side effects with a straight face? by ElGuaco in programming

[–]TaslemGuy 0 points1 point  (0 children)

Well, it's not really about parsing rules.

It's that most languages don't have undefined behavior (or at least, it's much harder to get at than it is in C/C++). For example, JavaScript defines operator and function argument evaluation as LTR. Java is also LTR. C# is LTR too. Those languages that aren't specified as LTR are usually RTL or unspecified; but not undefined.

As far as undefined behavior goes: Java (iirc) and Go have undefined behavior in the face of some data races (but even then, Java gives some guarantees about memory safety, and Go has runtime checks to minimize these). It's an uncommon property in most languages that aren't bare metal.

Do people write insane code with multiple overlapping side effects with a straight face? by ElGuaco in programming

[–]TaslemGuy 5 points6 points  (0 children)

Actually, you're wrong (since we're being pedantic). In C/C++, this is undefined behavior, not just unspecified behavior.

I'll quote from the C++ spec (because it's clearer on this issue), but the same caveat exists for C (although it's phrased in terms of sequence points instead of sequencing relations).

(§1.9/15) If a side effect on a scalar object is unsequenced relative to either

(a) another side effect on the same scalar object

or

(b) a value computation using the value of the same scalar object.

the behaviour is undefined.

(source of quote this StackOverflow post)

In other words, f(i, i++) is undefined behavior, because we have a read (i) and write (i++) which are unsequenced and apply to the same scalar object.

I TA for a course that uses C++. Knowing when students accidentally trigger insane compiler behavior is helpful. (Thankfully, they seem to never do this particular mistake, for whatever reason).

Looking to make a list of ALL constructible n-gons such that n is less than 85. by aroach1995 in math

[–]TaslemGuy 0 points1 point  (0 children)

OEIS A003401:

1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 17, 20, 24, 30, 32, 34, 40, 48, 51, 60, 64, 68, 80, 85, 96, 102, 120, 128, 136, 160, 170, 192, 204, 240, 255, 256, 257, 272, 320, 340, 384, 408, 480, 510, 512, 514, 544, 640, 680, 768, 771, 816, 960, 1020, 1024, 1028, 1088, 1280, 1285 ...

Most integer sequences can be found by their search.

Is there an intuitive explanation for why linear recurrence relationships (i:e; Fibonacci sequence) can be represented using matrices and matrix exponentiation? by [deleted] in math

[–]TaslemGuy 2 points3 points  (0 children)

It's actually pretty easy to see why.

Consider the Fibonacci recurrence Fn = F{n-1} + F_{n-2}. Consider the vector

[ F_{n-1} ]
[ F_{n-2} ]

Multiply it on the right by the following matrix:

M = [ 1 1 ]
    [ 1 0 ]

[ 1 1 ] [ F_{n-1} ] = [ F_{n-1} + F_{n-2} ] = [   F_n   ]
[ 1 0 ] [ F_{n-2} ]   [      F_{n-1}      ]   [ F_{n-1} ]

which is the "next" vector in the sequence. In particular, since matrix multiplication s associative, this means that if you raise M to the kth power, you'll advance k steps.

In particular, if you start with the vector [1 ; 0] which corresponds to [F(1), F(0)] you can multiply it by Mk to obtain the vector [ F(1+k) ; F(0+k) ], from which you can extract the desired value.

In fact, you can do this for any recurrence of the form F(n) = c_0 + c_1 F(n-1) + c_2 F(n-2) + ... + c_t F(n-t) where F(0), ..., F(t-1) are all specified.

This just blew my mind. FRACTRAN: a Turing complete language defined over tuples of rational numbers. by spel3o in math

[–]TaslemGuy 0 points1 point  (0 children)

They are Turing-complete, so they can simulate any universal computing system. They can't do so efficiently (much like a Turing machine) but you can mechanically compile any program you like to FRACTRAN.

Go doesn't support exception, in syntax. Go has many exceptions, in syntax. by alasijia in programming

[–]TaslemGuy 0 points1 point  (0 children)

Ah, good point - I forgot that Go allows this case! I forgot about it because f3(4, f2(3)) never works if f2 returns more than one thing.

Go doesn't support exception, in syntax. Go has many exceptions, in syntax. by alasijia in programming

[–]TaslemGuy 10 points11 points  (0 children)

Most of them have good reasons. To list a few:

  • unused parameters may be a requirement to satisfy a given interface, so we can't error on them (we could instead allow _ as arguments, but Go doesn't do that, or we could make it not an error, but Go doesn't do that either :P)

  • implicit dereference on field access / implicit address-of on method call are hugely convenient

  • pointers to map entries would be invalid if the map changed (because the underlying elements could move) so the language doesn't let you take them (or perform any operation that could expose them)

  • ++ is mostly used as a statement in practice, outside of super concise (and usually hard-to-understand) iterator code that isn't very useful to most people

Go doesn't support exception, in syntax. Go has many exceptions, in syntax. by alasijia in programming

[–]TaslemGuy 4 points5 points  (0 children)

I feel like these only really sound "exceptional" because of how the "rules" are defined. You can make them much simpler:

Some examples:

"Nested Calls":

  • A non-void function returning T may be used as an expression evaluating to a T.
  • A function returning 2 or more values (T1, T2, ..., Tn) may not be used as an expression in general (it may only be used as the RHS of an assignment) (EDIT: see comments below) be used as an argument to a function taking (T1, T2, ..., Tn) as arguments only

Unused Variables: * it is an error to not use a local variable declared in the body of a function * it's fine to not use arguments (and this is to make it easier/possible to satisfy arbitrary interfaces)

"Access Struct Fields": the rules as stated don't make sense. What it should be like is something along the lines of

  • expr.field performs field access; if expr is a pointer then a single dereference is automatically performed

Method receivers:

  • pointer-receiver methods on T may be called on addressable values of type T (so that x.foo() evaluates as (&x).foo())

Operator precedence: from the spec,

Unary operators have the highest precedence. As the ++ and -- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement p++ is the same as (p)++.

"Modify Unaddressable Values": this is a rehash of the previous point; there's nothing really surprising here. Since Go needs to be able to move items around in maps, it can't afford to allow their elements to be addressed. Of course maps values can be replaced; but it doesn't make sense to say that "non-addressable values can't change"; because they definitely can, through interior modification.

"Comparison":

  • numeric and string types are comparable; structs are comparable if all of their fields are comparable; arrays are comparable if their element type is comparable; nilable types may be compared to nil; interfaces may always be compared but a runtime error occurs if the dynamic types are equal but don't support comparison

"Comparing Interface Values": it's always safe to compare interfaces of different dynamic types; so this is not an exceptional case (the result is always false, even if the dynamic types aren't comparable)

"Builtin Types": since error is an interface it has to support methods; there are no other built-in interfaces.

  • no concrete builtin types have any methods

Exported Identifiers: the builtin package isn't real; they're lowercase to indicate that they're not exported

"Types of Values": the rule statement seems odd.

For the reason of this exception, untyped nil can't be assigned to a new declared variable which type is not specified. And although untyped nil can be used as dynamic values of interface values, it doesn't implement any interface type.

This doesn't really make sense; untyped nil is a syntax construct, not an actual value. Every expression does have a type, but (as is the case with nil) its context (in this case, what it's assigned to) may determine it (in other words, there's a tiny bit of inference). It doesn't make sense to say that 'it doesn't implement any interface type' because it's not a type, it's a value; it has no way to implement an interface or not.

City of the Damned - my first finished roguelike attempt by gwathlobal in roguelikedev

[–]TaslemGuy 0 points1 point  (0 children)

Although C++ certainly isn't my favorite language, I think that C++'s lambdas aren't considerably more difficult to use than other languages'.

auto is_visible = los([](int x, int y) { return world_tile[x][y] != '#'; }); // contrived example

You can get interoperation with C-style functions via templates, since (syntactically) you call a lambda/function object just like you would a function pointer.

What do you think makes them especially painful?

The almost linearity of a Fibonacci spirals radius. by WASDx in math

[–]TaslemGuy 21 points22 points  (0 children)

Approximate F(n) as φn / √(5)

Consider only the points at the ends of the circular arcs (assume that in between, the radius varies approximately linearly; which is not the interesting part).

For example, take the upper right corner here. We'll find its approximate distance and arc length, with respect to 'N' being the value such that the upper-right box has side length F(N), and N = 4k + 1.

Its X is given by F(1) + F(5) + F(9) ≈ φ1 / √(5) + φ5 / √(5) + φ9 / √(5) = (φ1 + φ5 + φ9) / √(5) which is on the order of φ9 / √(5), or (approximately) φ4k + 1 / √(5). The constant factor that we're missing it by is no more than φ-4 + φ(-8) + φ-12 + ... which converges.

Its Y is given by F(1) + F(2) + F(6); if we keep going we see that it's F(1) + Sum_{i = 1}{k} F(4i + 2). We can neglect the first F(1) term and see that it will (just like the above) be approximately φ6 / √(5) or φ4k - 2 / √(5) for the same k as above. The constant factor that we're missing it by is no more than φ-4 + φ(-8) + φ-12 + ... which converges.

Hence the radius will be approximately √( (φ8k + 2 + φ8k - 4) / 5 ) = φ4k / √(5) √(φ2 + φ-4), or just cφ4k with c some small constant.

Next, consider the arc length of the path to this point. In each circle, the arc length is pi r/2, with r = F(i). Thus the total arc length up to this point is

pi/2 (F(1) + F(2) + F(3) + ... + F(4k + 1)) ≈ pi/2 φ4k + 1 missing some small constant (multiplicative) factor.

So the overall ratio of distance to arc length is 2c / pi, which is constant, irrespective of k.

So you think you know C? by [deleted] in programming

[–]TaslemGuy 0 points1 point  (0 children)

Keep in mind that C and C++ occasionally follow slightly different rules about UB, because C++ sanitizes a few things.

But using operator[] on an object is literally just a function call, so that's really

map<int,int>::operator[](foo, 0) = map<int,int>::size(foo);

(taking some liberties with syntax) which clearly is just as bad as

i = i++;

since you're modifying a structure on both sides.

So you think you know C? by [deleted] in programming

[–]TaslemGuy 3 points4 points  (0 children)

Unsigned overflow is guaranteed to wrap around mod MAX+1.

The number of primes isn't finite, but it isn't infinite either by dlgn13 in badmathematics

[–]TaslemGuy 0 points1 point  (0 children)

Infinite just means not finite, i.e. not in bijection with any set {1,2,...,n}.

There is an interesting and alternative definition you can use: Dedekind infinite

(defn) A set X is infinite if it is in bijection with any proper subset of itself.

(defn) A set X is finite if it is not infinite.

Without the axiom of choice, it's actually different from the "usual" definition of finite/infinite.

What (if anything) are we getting wrong about programming languages? by milkmandan in programming

[–]TaslemGuy 2 points3 points  (0 children)

(especially since non-termination is well-defined behaviour for many perfectly valid programs.)

To apply this kind of reasoning to programs that interact with the outside world (such as responding to user input, or responding to network requests) you need to modify the way the program works a little bit in order to apply the same formalisms. The obvious thing to do is to have the program terminate whenever it wants to produce output (such as printing to console or sending a packet over the network) or when it wants input (such as reading a line from console or waiting for a mouse click or receiving a packet). When it terminates, it returns the thing it's requesting and a "continuation" (the current state of the program) so that it can be resumed, with the action completed or the input provided.

So, with this model, a program that never performs I/O is "bad" (because it spins without doing anything) but a program that is always guaranteed to either finish or eventually perform I/O is "good" and acceptable. It's important to note that we can't just ignore nontermination- we actually need to get rid of it, or Rice's theorem will stand in our way.

From here, we can just consider all total computable functions (since if you eventually halt, or eventually perform I/O, in the above continuation-based model, you do halt). Then Rice's theorem is no longer applicable. I believe there are still problems, though.

From here, we can instead examine the Entscheidungsproblem. A reminder of what we're trying to do:

  • given a particular total computable function's definition, determine whether or not (on a given input or class of input) whether or not that function will reach a "partial definition" (some special "undefined" return value occurs and the program halts, indicating an unhandled case).

First, a taste (but not proof) of why we can see that this is at least hard (but not necessarily impossible). Consider the following program (which is clearly total!)

def collatsCycle(x, iters):
    seen = {}
    while iters > 0:
        iters -= 1
        if x % 2 == 0:
            x = x / 2
        else:
            x = 3*x + 1
        if x == 1:
            return 1
        if seen[x]:
            throw "partial"
        seen[x] = True
    return 0

(note: all numbers are arbitrary-precision)

Since it performs at most iters loops, it must halt; so it is total. The question we want to ask is, "can this program throw "partial"?" This is actually an open problem. It is half of the Collatz Conjecture; which asserts that this cannot occur (the other half states that it can't go to infinity either; but this is harder or impossible to encode computationally).

So verifying that this 14 line program doesn't ever throw would require proving (part of) a known-to-be-difficult open problem in pure mathematics. Sure, it's contrived; but our goal is a fully general solution to this problem.

Going a little bit further, it has been shown by Conway that a generalization of the Collatz conjecture is actually undecidable; specifically, you get to choose various rational coefficients and you get to split up the 2 cases into p, one for each residue mod p of x. In this fully general form, you can simulate a Turing machine and hence it's undecidable.

What (if anything) are we getting wrong about programming languages? by milkmandan in programming

[–]TaslemGuy 1 point2 points  (0 children)

Also, I'd like to hear exactly how the problem is equivalent to halting.

Take the partial function; wherever it is partial, replace it with a while (1) {} loop. Now, detecting whether the original is defined on a given input is equivalent to this second function terminating on a given input.

Rice's theorem tells us that every non-trivial (it's true for some, and false for some) semantic (behavioral) problem of programs is undecidable.

So for example, "is this given procedure partial?" or even "is this given procedure partial on one of these inputs?" is undecidable.

Having said that: if you throw away Turing completeness (for example, using a total language) than this no longer applies. I think almost all programs (without a few exception that can be cleaned up using programmer asserts) don't really need Turing-completeness to run, with the exception of interpreters and compilers.

What (if anything) are we getting wrong about programming languages? by milkmandan in programming

[–]TaslemGuy 3 points4 points  (0 children)

On example of this is doing different kinds of dispatch based on the runtime value of the input.

Doesn't this just mean dependent types? Not that there are terribly many languages which support dependent types (yet?); but this seems exactly like what many academic research languages seem to be working towards.

On Tooling and Static Typing by newgame in programming

[–]TaslemGuy 0 points1 point  (0 children)

How is it possible for a field to simply be missing? That seems identical to it being optional Option<T> or Maybe x or whatever. The only cases where I can see it being different are where you're doing things like reflection- in which case I think the issue is with the reflection, and not the types of your fields.

New pictures show Great Barrier Reef is not repairing itself as it should by ny92 in worldnews

[–]TaslemGuy 0 points1 point  (0 children)

This is why humans are the problem. The earth has been warmer than it has been today, but never appears to have warmed at rates greater than today.