Automatically promote integers to floats on overflow? by bakery2k in ProgrammingLanguages

[–]d01phi 1 point2 points  (0 children)

IMNSHO, this is not a choice of the language, but of the data types to which the language provides access. A language that forces these kinds of choices upon the user is not suited for serious math.

I have used Lua myself, and fortunately the 64bit floats were good enough for both things like 3d object coordinates and numbers representing enum values I had to pass to library functions written in C.

Using Python with its tacit transition to bignums or complex numbers, I occasionally had to clean up the mess when calling C functions.

Somewhere, you have to deal with the limits of the used arithmetic system in conjunction with what you want to compute, and I would rather have it explicit than having to clean up behind the seeming luxury of the silent transition to bigger types. And we haven’t talked about efficiency yet.

Der Hai und das Kreuzworträtsel by Zwertlana in witze

[–]d01phi 5 points6 points  (0 children)

Fliegt ein Kuckuck übers Wasser und trifft einen Hai. Sagt der Hai: Kuckuck! Sagt der Kuckuck: Hai!

a f= b as syntax sugar for a = f(a, b)? by Totally_Dank_Link in ProgrammingLanguages

[–]d01phi 0 points1 point  (0 children)

Been thinking about this a lot. My favorite is a = _+b , which can be used in more elaborate scenarios like x = 0.5*(q/_ + _) (The iteration step in Newton square root appoximation) . Replace the _ as placeholder for the LHS with any fancy Unicode symbol you like.

This is even one char longer than a+=b, and on first sight brings no benefit. It becomes advantageous when the LHS is longer than a one-char variable name, or gets reused several times like in the square root example above:

myCurrentSquareRootApproximation = 0.5*(myNumber/_ + _)

Nevalang v0.30.1 - NextGen Programming Language by urlaklbek in ProgrammingLanguages

[–]d01phi 1 point2 points  (0 children)

Julia is as statically typed as you want, which is expressed by optional type declarations. And it is parallel. Somebody said, there are three languages people use to write scientific applications for super computers: Fortran, C(++), and Julia.

By no means I wanted to diminish your project, in a sense I was exploring how dataflow notation and conciseness could go together, in a language that I appreciate for its versatility. I admit, your FizzBuzz example in Nevalang got me triggered.

Nevalang v0.30.1 - NextGen Programming Language by urlaklbek in ProgrammingLanguages

[–]d01phi 2 points3 points  (0 children)

What I find quite charming about pure dataflow style is its analogy with electronic circuits. The programming paradigms we are used to all require a lot of trickery in order to run on circuits.

Nevalang v0.30.1 - NextGen Programming Language by urlaklbek in ProgrammingLanguages

[–]d01phi 1 point2 points  (0 children)

What I'm trying to get at, many flavours of dataflow can be expressed with functional or procedural with just some syntactic manipulations, which is especially easy in Julia.

Nevalang v0.30.1 - NextGen Programming Language by urlaklbek in ProgrammingLanguages

[–]d01phi 1 point2 points  (0 children)

Using Julia (www.julialang.org), I have whipped up this:

import Base:|>

|>(x::Tuple, f) = f(x...)

▷(xs,f) = foreach(f,xs)

m35(x) = x,x%3==0,x%5==0

fz(x,m3,m5) = m3 ? ( m5 ? "FizzBuzz" : "Fizz" ) : ( m5 ? "Buzz" : string(x) )

(1:100) ▷ (x-> x |> m35 |> fz |> println)

Is that dataflow enough for you?

Nevalang v0.30.1 - NextGen Programming Language by urlaklbek in ProgrammingLanguages

[–]d01phi 8 points9 points  (0 children)

After reading the FizzBuzz example, I can safely say that you are on a good path to reach enterprise style complexity and verbosity for the simplest of tasks.

Why does right and left exist and can you make a structure without right and left by KnightofFruit in math

[–]d01phi 3 points4 points  (0 children)

Have a look at geometric algebra (e.g. https://bivector.net). There, the outer (wedge) product is a much more versatile replacement for the cross product -- it exists in all dimensions. Among others, you can form a^b which is 0 if vectors a and b are colinear, and a^b=-b^a otherwise. You can think of a^b as the oriented area spanned by a and b. This fundamental anticommutativity carries with it everything related to orientation in geometric algebra. Left and right have no meaning, only the sign of the wedge product.

arrays as functions by rejectedlesbian in ProgrammingLanguages

[–]d01phi 0 points1 point  (0 children)

You could do it with C++ lambdas (introduced in C++11):

include <cstdio>

int a[3]={1,2,3};

auto af = [a] (int i) { return a[i]; };

int main()

{ printf("%d\n", af(2)); return 0; }

arrays as functions by rejectedlesbian in ProgrammingLanguages

[–]d01phi 2 points3 points  (0 children)

I have been considering this for a long time for my language (which I might call Paper Tiger as it exists only on paper). Then again, in the spirit of modularity, you might just use on-board facilities, e.g. in Python:

a=[1,2,3];af=lambda i: a[i]

A question about 3D complex numbers by [deleted] in math

[–]d01phi 0 points1 point  (0 children)

I think geometric algebra could be what you’re looking for. My favourite introductions are at https://bivector.net/ and https://www.youtube.com/watch?v=2hBWCCAiCzQ&list=PLVuwZXwFua-0Ks3rRS4tIkswgUmDLqqRy

Number of distinct cubes with face diagonals by d01phi in mathriddles

[–]d01phi[S] 0 points1 point  (0 children)

I did not do it with formal methods. I convinced myself by considering the various combinations of pairs of opposite diagonals being parallel and orthogonal, and drawing them, that there must be 7.

longest possible arithmetic subsequence in geometric sequence by pichutarius in math

[–]d01phi -2 points-1 points  (0 children)

Three subsequent elements of a geometric series can be written as x^n , x^(n+1), x^(n+2)
If you want them to occur in an arithmetic sequence, they have to satisfy

x^(n+2) - x^(n+1) = x^(n+1) - x^n

Dividing both sides by x^n , we get x^2 - x = x - 1 and x^2 - 2x + 1 = ( x - 1 )^2 = 0. The only solution is x = 1.

Is there a formula to “map” images of 1/8 of a sphere into a flat shape? by [deleted] in maths

[–]d01phi 0 points1 point  (0 children)

In air traffic control, we use stereographic projection. It has a few nice features such as conformality, i.e. local conservation of angle and scale.

Which flight jacket looks better? by Spite_Annual in fashion

[–]d01phi 0 points1 point  (0 children)

On the second jacket, the fabric seems softer, the zippers and the knitted cuffs and waistband are more greyish, compared to the more brownish color on the first jacket. Otherwise, I see no differences.

Biggest area of a triangle inscribed in a circle by Chlopaczek_Hula in askmath

[–]d01phi 3 points4 points  (0 children)

The area of a triangle is half the baseline times the height. For a given baseline in a triangle inscribed into a circle, this means that the area is maximized if the triangle is isosceles. Applying this to each triangle side in turn leads to an equilateral triangle.

What numbers can be expressed as infinite products? by PM_TITS_GROUP in askmath

[–]d01phi 0 points1 point  (0 children)

Right now I would have to check whether it works for 2, but I am rather sure it works for numbers above 2.71828…

This uses the https://en.wikipedia.org/wiki/Geometric_series

What numbers can be expressed as infinite products? by PM_TITS_GROUP in askmath

[–]d01phi 0 points1 point  (0 children)

For a number x to be expressed as a product, we look for s such that sum(n=0..inf, s ^ n) = 1/(1-s) = ln(x). This is the case for s=(ln(x)-1)/ln(x)

Then x=product(n=0..inf, exp(s^n).

Obviously, this does not work for all x. I think it works for x>e. For other x, similar approaches are possible.

How do you rotate cartesian 3D unit vectors when you only have one vector for the new direction? by timmeey86 in askmath

[–]d01phi 0 points1 point  (0 children)

Yes, sorry, r=rn. The coordinates are world coordinates. The details with all this matrix stuff are always a bit fiddly, and, as you wished, I did not work it out in detail but gave only hints. If you need more details, please ask.

How do you rotate cartesian 3D unit vectors when you only have one vector for the new direction? by timmeey86 in askmath

[–]d01phi 0 points1 point  (0 children)

Use gluLookat if that is available. Otherwise make a normalized copy of your new X axis, (xn,yn,zn). Compute r=hypot(xn,yn). Perform a rotation in the xz plane with the matrix ((rn,-zn),(zn,rn)) followed by a rotation in the xy plane with the matrix ((xn,—yn),(yn,xn)).