Showing posts with label teach. Show all posts
Showing posts with label teach. Show all posts

Wednesday, August 05, 2026

[hgulalrr] subtracting times of day with units

time elapsed between:
4th day of the month 11:59:59 PM
6th day of the month 6:06:06 AM

$ units
You have: (6 day + 6 hr + 6 min + 6 s) - (4 day + 23 hr + 59 min + 59 s)
You want: day;hr;min;s
1 day + 6 hr + 6 min + 7 s

the semicolon syntax is documented in the units man page in the section entitled "UNIT LISTS: CONVERSION TO SUMS OF UNITS".

computing elapsed time requires more effort if endpoints are in different months, e.g., January 31, February 1 = January 32, February n = January (31 + n),... March 1 = February ( {28 or 29} + 1) = January (31 + {28 or 29} + 1).

incorrect if Daylight Saving Time changes within the interval; incorrect if endpoints are in different time zones; incorrect if a leap second occurs; incorrect if crossing the boundary between Gregorian and Julian calendars.

for such complicated cases, first convert each endpoint into a format which increases continuously and uniformly, then subtract, then convert with units to "day;hour;minute;second".

note well that Unix time does NOT increase uniformly: it stops at a leap second (or more precisely, it discontinuously decreases by one second).  subtracting two Unix times yields an elapsed time value that is incorrect by the number of leap seconds which occurred during the interval.

use the "right" counter instead of POSIX Unix time.  note that, as of Debian Trixie, you need to install the tzdata-legacy package to get the "right" counter value of a given date and time.

Tuesday, August 04, 2026

[pglmhtip] how to exit visual mode in ex

everyone wants to know the opposite direction, how to exit line-editing "ex mode" and return to visual mode in vi, so it is tough to find information for this direction.

the correct answer is "Q", but vim 8.2 (package vim-runtime) in Ubuntu 22.04 has remapped Q to something completely unrelated ("formatting") so Q is inaccessible.  (because everyone who hates line-editing also wants to configure vi never to accidentally enter "ex mode").  unlike emacs using M-x, there is no way to call a function by its long name if you just want to use it once.  to make Q exit visual mode for the rest of the session: ":unmap Q".  but of course that changes state, so you are not returning exactly to the same "ex" state that you started with: what if you then want to enter a visual mode with Q again having its remapped "formatting" behavior?  I do not know of a way to restore Q to whatever it was before (without knowing what it was before) (unlike emacs, there is no local-set-key, local-unset-key).  this is a mess.

to start "ex" (or "vi") with Q being available again: "ex -u NONE".  or maybe "ex -u NONE -N".  but "-u NONE" disables all initialization files, not just the Q remapping.  (-u NONE also makes vim behave more like original vi, a large set of differences in behavior.  -N modifies -u NONE to keep vim behaving like vim, which is good if you are used to vim not vi.)  I could not find any way to disable just the Q remapping from the command line.  this is a mess.

(if you want Q permanently available, you can create a user initialization file to override the system initialization file.)

the almost correct answer, even with "Q" remapped and inaccessible, is "gQ".  but "Q" and "gQ" are subtly different (in a way I do not understand).  when vim is invoked as "ex", it starts in "Q" mode, not "gQ" (according :h Q), and, as described above, there is no easy way to go back to Q after entering visual the first time.  this is a mess.

Q mode (but not gQ mode) has been removed from neovim (nvim).  if invoked as "ex", neovim presumably starts in gQ mode, but this is not documented anywhere I could find.

Sunday, April 19, 2026

[pfbjvubj] environment variables modifying Makefile variables

consider the following GNU Makefile and invocations in the bash shell:

C = c
Q ?= q
.PHONY:default
default:
        @echo C=$(C)
        @echo Q=$(Q)

$ make
C=c
Q=q

$ make C=notc
C=notc
Q=q

$ make Q=notq
C=c
Q=notq

$ C=notc make
C=c
Q=q

$ Q=notq make
C=c
Q=notq

either type of assignment can be overridden by specifying a new value after "make" on the command line, but only variables assigned with ?= can also be overridden by the environment.  I've deliberately done both: makefiles in which make communicates with its caller via environment variables, and makefiles in which make should ignore any identically named environment variables.

Next, experimenting with += :

P += p
.PHONY:default
default:
        @echo P=$(P)

$ make
P=p

$ make P=prefix
P=prefix

$ P=prefix make
P=prefix p

like with ?= , only user-specified values in the environment can be appended to with += .  this is especially useful is the following idiom: if a Makefile specifies "CFLAGS += necessary flags", then the user can add additional flags to CFLAGS just for one build without editing the Makefile.  for += to work keeping the necessary CFLAGS specified in the Makefile, the user must specify CFLAGS in the environment as demonstrated in the last example above, not in a command-line argument to make.

an attacker could surreptitiously set CFLAGS="something evil" in your environment, thereby affecting all builds that use exclusively CFLAGS += , but if you are worried about an attacker who can set and export arbitrary variables in your environment, you probably have bigger problems.

future work: the "override" makefile directive.

Wednesday, March 04, 2026

[fieutgtv] sum of the reciprocals of known primes

at the time of writing, the largest known prime number is the Mersenne prime 2^136279841 - 1, a 41-million-digit number.

the sum of the reciprocals of all primes up to the largest known prime can be estimated to be approximately

log(log(2^136279841 - 1)) + 0.261497 ~= 18.6252

, where the offset 0.261497 is the Meissel-Mertens constant (known to many more digits).  (how many more?)

(previously, on log(2^n +1).)

however, the sum of the reciprocals of all primes up to infinity is infinity, i.e., the infinite sum diverges (proven by Euler).  despite our finite sum being up to a huge prime, 18.6 is still a long way from infinity.

the reciprocal of the next prime after the largest known prime ("the first unknown prime") will add approximately 10^-41000000 to our partial sum 18.6252 , a tiny step.  and each additional step will be yet smaller, because reciprocals keep getting smaller.  yet infinity will still eventually be "reached": the sum will exceed any finite number you can think of: Graham's number, Rayo's number, Loader's number, etc., (and all finite numbers you can't think of).

previously, computing the sum one button press at a time.

Sunday, March 01, 2026

[efggjrfp] infinity breaking groups

consider adding one infinite element to the integers or reals under addition and seeing if it remains a group.

first, consider defining 1 + infinity = infinity in the style of Cantor's cardinal numbers.

(1 + infinity) + (-infinity)
= infinity + (-infinity)
= 0

1 + (infinity + (-infinity))
= 1 + 0
= 1

associativity violated, so not a group.  note that, by group axioms, -infinity must exist, and -infinity + infinity = 0.

ordinal numbers are not a group because omega + (-1) is not defined.

the Riemann sphere (complex numbers extended with infinity) is not a group because infinity + (-infinity) is not defined.  (-infinity) itself might not be defined.

some ways to extend reals with infinity to get a group: Levi-Civita field (not too difficult to understand), surreal numbers (rather difficult to understand).  yet more exist, typically also difficult to understand.

the above successful ways get you not just a group but a field (with multiplication and division).  is that necessary?

unstated: why do you even want a group of numbers with infinity?

Saturday, November 01, 2025

[efyfabmr] map coloring the Voronoi diagram of equally spaced points on a sphere

pick one of the many methods for placing N "equally spaced" points on a sphere (e.g., Thomson problem, Tammes problem), compute the Voronoi partition, then map color, i.e., avoid adjacent regions of the same color.  (Lloyd's algorithm conveniently uses Voronoi to produce equally spaced points.)

4 colors suffice.  such a coloring might be pretty.  I suspect there will not be adjacent Voronoi regions with very short borders.  (maximizing the minimum Voronoi border segment could be another "equally spaced" metric.)

or, equally spaced points on the surface of any shape.  (the surface needs to have a definition for distance between any two points, a metric.  this might be related to a geodesic.)  if the shape is not topologically a sphere, then more than 4 colors might be required.  amazingly, the sufficient number is known for any number of holes in the donut (Heawood conjecture, no longer a conjecture, according to Wikipedia); the case of zero holes (the sphere or equivalently the plane) was the last to be proven.

colors = floor((7 + sqrt(1 + (48 * holes)))/2)

(there is a generalization of the formula that works if the surface has cross caps (real projective planes), e.g., Klein bottle.  such surfaces always self intersect in 3D space.  the classification theorem of surfaces then says that donut holes and cross caps are enough to topologically define any closed surface.)

is there a polynomial time algorithm that colors with the sufficient number of colors any map on a surface of any genus?

are random such coloring problems, the Voronoi diagrams of roughly equally spaced points, relatively easy to color?

how often can such maps on a sphere be 3-colored?  the regular hexagon tiling can be 3-colored.

there may be many ways to color the Voronoi partition, many more than just the 24 = 4! ways from permuting 4 colors.  how often does this happen?  if it does happen, how can we pick one of the colorings uniformly randomly?

Sunday, October 26, 2025

[hgtrowvn] reciprocals of odd numbers mod 2^n

odd numbers have multiplicative inverses modulo 2^n (even numbers do not).

? for(n=1, 8, print1(2^n,":"); for(j=1, 2^(n-1), i=2*j-1; print1(" ",lift(Mod(i,2^n)^-1))); print())

for example, in 4th line below, the reciprocals of 1 3 5 7 9 11 13 15 modulo 16 are 1 11 13 7 9 3 5 15 respectively.  the product of each number multiplied by its reciprocal is a number of the form 16N+1.

2: 1

4: 1 3

8: 1 3 5 7

16: 1 11 13 7 9 3 5 15

32: 1 11 13 23 25 3 5 15 17 27 29 7 9 19 21 31

64: 1 43 13 55 57 35 5 47 49 27 61 39 41 19 53 31 33 11 45 23 25 3 37 15 17 59 29 7 9 51 21 63

128: 1 43 77 55 57 35 69 111 113 27 61 39 41 19 53 95 97 11 45 23 25 3 37 79 81 123 29 7 9 115 21 63 65 107 13 119 121 99 5 47 49 91 125 103 105 83 117 31 33 75 109 87 89 67 101 15 17 59 93 71 73 51 85 127

256: 1 171 205 183 57 163 197 239 241 27 61 167 41 19 53 223 225 139 173 151 25 131 165 207 209 251 29 135 9 243 21 191 193 107 141 119 249 99 133 175 177 219 253 103 233 211 245 159 161 75 109 87 217 67 101 143 145 187 221 71 201 179 213 127 129 43 77 55 185 35 69 111 113 155 189 39 169 147 181 95 97 11 45 23 153 3 37 79 81 123 157 7 137 115 149 63 65 235 13 247 121 227 5 47 49 91 125 231 105 83 117 31 33 203 237 215 89 195 229 15 17 59 93 199 73 51 85 255

they look quite random, but there are some patterns, like some early (e.g., 11, 13, 57) and late numbers (e.g., 51, 85) persisting through several exponents.

the randomness is reminiscent of multiplicative inverse modulo a prime number.  however, prime numbers and powers of 2 are about as different as numbers can be.

the reciprocal of a reciprocal is itself, so most numbers pair with another (two-cycle).  however, 1, (2^(n-1) - 1), (2^(n-1) + 1), and (2^n - 1) (the last one equivalent to -1) are always their own inverses (one-cycle).

previously: it is possible to set up a Galois field of order 2^n so that all nonzero elements (not just the odd elements) have reciprocals.  the reduction operation becomes more complicated than integer modulo 2^n.

[lavnkjop] easy 21cm radio astronomy

is the 21 cm (1420 MHz) hydrogen line the easiest radio astronomy "target"?  not really a target if observing the hydrogen radiation from "everywhere" with an omnidirectional (dipole) antenna.  I have seen such a simple antenna and software-defined radio successfully detect 21 cm radiation.  it was fun to see a peak right at 1420 MHz.  does 21 cm signal strength vary significantly by antenna orientation and what part of the sky (probably the center of the Milky Way) is overhead?  such space and time variance could make observing 21 cm with simple antenna more interesting than just a peak.

an even easier astronomical target to observe in radio frequencies might be the sun.  I think the sun emits broadband noise, not a clear peak.  by measuring intensity, how easy is it to detect active regions rotating into view, or track the sunspot cycle through radio?  for the former, you need to keep your radio calibrated through months; for the latter, through decades.

is 21 cm the easiest astronomical radio thing to observe not also observable in visible light?  it is fun to see the invisible.  (previously: easiest visible-light astronomy with binoculars.)

while not astronomical, lightning can be detected with radio, even from great distance.  the necessary equipment to triangulate lighting strikes is more complicated than a simple dipole antenna but seems gettable by amateurs.

is 21 cm the longest astronomically interesting intrinsic wavelength of electromagnetic radiation?

(the extrinsic effect of cosmological redshift stretches wavelength.  at cosmological distance z=9, 21 cm radiation becomes 21 * (1 + z) = 210 cm.)

the 21 cm line is the hyperfine electron transition of ground-state hydrogen.  I think hyperfine transitions in other elements have shorter wavelengths.  previously, cesium, 3 cm.

electron energy levels become closely spaced near ionization, so transitions between adjacent high energy levels correspond to longer wavelengths.  but do we care about radiation from transitions near but not quite at ionization?  do they happen often enough to observe?  what about hyperfine transitions of excited hydrogen?  the electron probably unexcites much faster (more frequently) than it spin-flips.

Tuesday, June 17, 2025

[ihehqrko] supergun space fountain

at first glance, a giant gun seems not a very practical method for space launch, because very few payloads, certainly not humans, can survive that kind of acceleration.

in contrast, a space elevator, if we could build one, would be a very practical method of getting humans and other fragile cargo to outer space.  (a space elevator is not so great for putting satellites into low earth orbit because it only provides vertical height not horizontal speed.)  one of the most promising designs for a space elevator, promising because it does not require materials with currently unachievable amounts of strength, is a space fountain.  and one of the ways to build a space fountain is a giant gun launching pellets up a tall evacuated tube to space.  the tube does not need to be made of an impossibly strong material because it is actively held up by skimming momentum (somehow) from the pellets shooting upward inside it.  humans then leisurely climb up the outside of the tube to space and beyond.

(at the top of the space fountain, the pellets fall back down to earth.  for energy efficiency, their falling energy at the bottom should be recovered or reflected to launch pellets up again.)

space elevators seem the only realistic way to migrate all humans off the planet before the gradually warming sun boils all water on earth.  alternatively, maybe we can get nuclear pulse propulsion to work, but rockets with radioactive exhaust will be extremely messy near the earth's surface.

(maybe we can increase albedo or play cosmic pinball to survive the warming then red giant sun, but we would still need to get off planet to survive white dwarf sun.)

therefore, the executions of both the world's leading scientist on giant guns and his patron, with the chilling effect those assassinations have on anyone considering continuing such work in the future, may have tremendous consequences on the long-term outcome of our species and survival of intelligent life in the universe.  perhaps that was precisely the moment when humanity went extinct: "Israel, you fool!  you've doomed us all!"

Saturday, May 17, 2025

[esruqntc] fun with the beginning of the primes

{0, 1, 2} are special.  find or create (interesting) theorems that are true precisely for each of the 8 possible subsets of those numbers unioned with the odd primes starting from 3.  then, claim each such theorem defines the primes.

inspired by someone uneducated attempting to troll mathematicians by asking whether 1 is a prime.  in reality, when the relevant set of numbers at beginning of the primes matters (say, for a theorem), mathematicians will uncontroversially state that assumption as part the theorem.  most often, things that are true about primes are interesting because they are true about the larger primes.  {0, 1, 2} are boring.

"prime", when classifying the numbers {0, 1, 2}, is a social construct, not ground truth.  it is a convenience.  the most commonly convenient classification is to exclude 0 and 1 and include 2, but if in some application it is convenient to use a different subset, just state that subset and move on.

[bfganmsg] balanced ternary

first, here are integers from -20 to 100.  to negate a balanced ternary number, swap + and -, leave 0 unchanged.

-+-+-20
-+0--19
-+00-18
-+0+-17
-++--16
-++0-15
-+++-14
----13
--0-12
--+-11
-0--10
-00-9
-0+-8
-+--7
-+0-6
-++-5
---4
-0-3
-+-2
--1
00
+1
+-2
+03
++4
+--5
+-06
+-+7
+0-8
+009
+0+10
++-11
++012
+++13
+---14
+--015
+--+16
+-0-17
+-0018
+-0+19
+-+-20
+-+021
+-++22
+0--23
+0-024
+0-+25
+00-26
+00027
+00+28
+0+-29
+0+030
+0++31
++--32
++-033
++-+34
++0-35
++0036
++0+37
+++-38
+++039
++++40
+----41
+---042
+---+43
+--0-44
+--0045
+--0+46
+--+-47
+--+048
+--++49
+-0--50
+-0-051
+-0-+52
+-00-53
+-00054
+-00+55
+-0+-56
+-0+057
+-0++58
+-+--59
+-+-060
+-+-+61
+-+0-62
+-+0063
+-+0+64
+-++-65
+-++066
+-+++67
+0---68
+0--069
+0--+70
+0-0-71
+0-0072
+0-0+73
+0-+-74
+0-+075
+0-++76
+00--77
+00-078
+00-+79
+000-80
+000081
+000+82
+00+-83
+00+084
+00++85
+0+--86
+0+-087
+0+-+88
+0+0-89
+0+0090
+0+0+91
+0++-92
+0++093
+0+++94
++---95
++--096
++--+97
++-0-98
++-0099
++-0+100

binary and balanced ternary vie to be the most elegant base.  the following list of the powers of 2 is an artistic rendition of an irrational impedance mismatch between base 2 and base 3.  previously, on log(3)/log(2): [1],[2],[3].

+2^01
+-2^12
++2^24
+0-2^38
+--+2^416
++--2^532
+-+0+2^664
+---+-2^7128
+00+++2^8256
+-0+00-2^9512
+++-0-+2^101024
+0-++0--2^112048
+-0-0--0+2^124096
++-+-0++-2^138192
+-+++++-++2^1416384
+--0000--0-2^1532768
+0+000-0+-+2^1665536
+-+-00-++---2^17131072
++++00--+00+2^18262144
+000-0-+--0+-2^19524288
+-00-+-++0+0++2^201048576
++00---0-+-+0-2^212097152
+0-0-00+0-----+2^224194304
+--+-+0+--000+--2^238388608
++----0+0+000+0+2^2416777216
+-+000++-+-00+-+-2^2533554432
+---00+-++++00++++2^2667108864
+00+0+--000-0+000-2^27134217728
+-0+-0+0+00-++-00-+2^28268435456
++0+++-+-00--++00--2^29536870912
+0-+0-++++0-+-0-0-0+2^301073741824
+-0--0-000--+++-+-++-2^312147483648
++-0+-+00-+-00-----++2^324294967296
+-+++---0-+++0-000+-0-2^338589934592
+--0-+00+0-00--+000++-+2^3417179869184
+0+0--0+--+0-+--00+0---2^3534359738368
+-+--0+0++---++0+0+--00+2^3668719476736
+++0++-+-+0+-0-+-0+0+0+-2^37137438953472
+00-+0-----0++-++++-+-0++2^38274877906944
+-00---0000++0--00-+++++0-2^39549755813888
++0-00+000+0--0+00-0000--+2^401099511627776
+0--+0+-00+--0++-0-+000-+--2^412199023255552
+--+--0++00+0++-++0--00-++0+2^424398046511104
+0++0++0-0+-+0--0--0+00-0-+-2^438796093022208
+-+0-+0--++----0+-0++-0-+-+++2^4417592186044416
+---0---+--+000+0+++-++0---00-2^4535184372088832
+00+-00+++--00+-+00--0--00+0-+2^4670368744177664
+-00++0+0-+0+0+---0-0+-0+0+-0--2^47140737488355328
++0+0-+-0--+-0+00+-+0+++-0++-0+2^48281474976710656
+0-+--+++-0++++-0+---+0-+++-+++-2^49562949953421312
+--+++-0-+++00-++0+0+--0-00--0-++2^501125899906842624
++-0-++0-00-00-0-+-0+0+-+0-0+0-0-2^512251799813685248
+-++0-0--+0-+0-+-++++-+----++--+-+2^524503599627370496
+--0--+-+--0--0---00-+++00+--++----2^539007199254740992
+0+-0++++0+-0+-00+00-00-00++--+000+2^5418014398509481984
+-0+++000-0++0++0+-0-+0-+0+-++--00+-2^5536028797018963968
+++00-00-++0-+0-0++0--0--+---+0+00++2^5672057594037927936
+00-0-+00-0-0---++0--0+-0++0+--+-0+0-2^57144115188075855872
+-0-+0--0-+-+-0+-0--0+0+++0-0+0++++--+2^58288230376151711744
++0---0+-+++++0++-0++-+00--++-+00-++--2^59576460752303423488
+0--00++--0000-+-+++0---0-+-0---00--+0+2^601152921504606846976
+--0+0+-+0+0000---00--00+-+++-00+0-+--+-2^612305843009213693952
+0++-+---+-000-00+0-0+0+--0-++0+--++0+++2^624611686018427387904
+-+-+++00+++00-+0+--++-0+0+0-0-0++-0-+00-2^639223372036854775808
+----00-0+00-00--0++--+++-+--+-++-++0--0-+2^6418446744073709551616

Monday, March 03, 2025

[ohtmqaez] distance 70 in 24 dimensions

the point at coordinates (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) in 24-dimensional space is exactly 70 units from the origin, because the sum of the first 24 squares is 4900.  (this amazing relation is somehow related to the 24-dimensional Leech lattice, a different lattice than our hypercube lattice of all points with integer coordinates.)  the point is one of 905754973269671819419476064818886581168 lattice points 70 units from the origin.  that large number divided by 24 factorial is approximately 1459839320625890.4 : there are many more lattice points on a hypersphere of radius 70 than just the permutations of the coordinates of our special point.

our special point is one of 370123270431636382177726611489013547080401 lattice points inside or on the boundary of a 24-dimensional ball of radius 70.  this volume is approximately 408.6 times larger than the above surface "area" of lattice points.  in other words, this outermost layer of lattice points does not dominate the total lattice points.  this matches lower dimensional intuition, which is rare when considering volumes in high dimensions.

future work: actual volume, surface area, and ratio of a 24-dimensional sphere of radius 70.  this should be easy.

the above results are derived from the b-file of OEIS A000156.  I confirmed the list up to entry 1000 (with 48 hours of computing).  I do not know how its larger entries (up to entry 10000) were calculated; there must be some algorithmic tricks beyond what I implemented.

I discovered A000156 by calculating its first few terms (future post kiqanzug), then searching OEIS for the continuation.  this a standard way to use the database.

Thursday, February 06, 2025

[iwuqpzmp] Max Oy Vey

is not the most right way to pronounce world chess champion "Max Euwe", but neither is it the most wrong: "Max You".

Wednesday, January 22, 2025

[xoukpkha] global curvature of square fundamental polygons

a square (or rectangle) fundamental polygon is good for 2D games.

previously on the various spaces (manifolds) that a fundamental polygon can represent, depending on how its edges are defined to behave.

do weird things happen at the corners of the square fundamental polygon for an objects larger than a point (e.g., a sprite) moving around the space?

sphere: Y
torus: N
real projective plane: Y
Klein bottle: N
cylinder: N
Moebius strip: N
hemisphere: Y
square: N

things are not weird if the neighborhood around corners behaves like flat (Euclidean) space.  investigate by tracing a small circle around each corner.  in flat space, we expect a 360-degree circle.  in the answers above, Y = (weird things happen at corners; there is global or total curvature; small circles are less than 360 degrees); N = (corners behave like flat space; circles are 360 degrees).

if you have a fundamental polygon with more edges than a square, e.g., hexagon, you can probably get small circles larger than 360 degrees, some sort of hyperbolic space.  you might be able to get some corners with positive curvature that cancel out other corners with negative curvature for zero global curvature.  but it would still be awkward for games, because local curvature is what we care about for rendering sprites.

even though weird things happen at corners of sphere, projective plane, and hemisphere when drawn as a square fundamental polygon, they are all manifolds (locally Euclidean), so there are other ways of depicting them so that small circles remain approximately small circles throughout, smearing the curvature or weirdness throughout the surface.

or, just put an obstacle over the weird points.

Sunday, December 29, 2024

[ahlvcwcw] factoring while you wait

on a modern computer, Pari/GP can usually factor RSA-style numbers (the worst case for factoring) of 60 digits (199 bits) in 30 seconds or less, subjectively the limit for human interactive patience.  factoring algorithms are probabilistic (randomized), so there is no hard upper bound to "usually".

74 digits (246 bits) usually takes under 5 minutes (300 seconds).  with improvements in software and parallel processing (SMP) (Pari/GP's ECM and MPQS are single-threaded), one could imagine getting getting 74-digits down to under 30 seconds.

previously, standard deviation.

Wednesday, December 25, 2024

[kduuqcjf] ring modulo i^3 + i^2 + i + 1

previously, a commutative ring with reduction polynomial i^3+1.  this time, the polynomial (i^4-1)/(i-1) = i^3 + i^2 + i + 1 because of its distinctive form.  note that the polynomial has root i = -1, so it is not a field. (dividing through further by (i+1) would result in i^2 + 1, the cyclotomic polynomial of order 4, which yields the field of complex numbers.  in general, dividing through by "all" factors yields a cyclotomic field, where "all" requires clarification.)

denote a ring element a + b*i + c*i^2 as (a,b,c).  here is how to do multiplication and division:

(a,b,c) * (d,e,f) = (a*d - b*f - c*e + c*f , a*e + b*d - b*f - c*e , a*f + b*e - b*f + c*d - c*e)

1/(a,b,c) = ( (a^2 - a*b - a*c + b^2)/denominator , -b/(a^2 + b^2 + c^2 - 2*a*c) , (b^2 + c^2 - a*c - b*c)/denominator )
where denominator = (a - b + c) * (a^2 + b^2 + c^2 - 2*a*c) = a^3 - a^2*b - a^2*c + a*b^2 + 2*a*b*c - a*c^2 - b^3 + c*b^2 - c^2*b + c^3

the middle component of reciprocal does not have the same denominator because of fortuitous cancellation by (a - b + c).  if a - b + c = 0, equivalently b = a + c, then the other terms become division by zero, making the whole thing undefined.  because there are numbers not equal to zero which do not have reciprocals, this is not a field.

the numbers that do not have reciprocals are the multiples of the factors of the reduction polynomial.  multiples of (i+1) = (1, 1, 0) yield the family (a, a+c, c) seen above.  multiples of (i^2+1) yield the family (a, 0, a) which also does not have reciprocals.

how to get the multiplication formula with Pari/GP:

? mm=(i^4-1)/(i-1)
? multiplication = Mod(a+b*i+c*i^2, mm) * Mod(d+e*i+f*i^2, mm)
? polcoeff(lift(multiplication), 0, i)
? polcoeff(lift(multiplication), 1, i)
? polcoeff(lift(multiplication), 2, i)

can multiplication in this ring be computed with fewer scalar multiplications like the way the Karatsuba algorithm speeds up complex multiplication?

Saturday, November 09, 2024

[fiijydon] Bernoulli numbers

Bernoulli numbers are mysterious, showing up in lots of places, e.g., the zeta function, the gamma function, sums of powers (Faulhaber's formula), and the Taylor expansion of the tangent function.

Bernoulli numbers of odd index are all zero except for bernoulli[1] which is +1/2 or -1/2 depending on convention.  odd index are omitted below so as not to take sides on this Holy War.

the values below were computed using the bernfrac function in Pari/GP.  the bernvec function can speed up computation but was not needed.  we give both the traditional improper fraction form and each number broken into an integer part and a proper fraction.

bernoulli[0] = 1

bernoulli[2] = 1 / 6

bernoulli[4] = -1 / 30

bernoulli[6] = 1 / 42

bernoulli[8] = -1 / 30

bernoulli[10] = 5 / 66

bernoulli[12] = -691 / 2730

bernoulli[14] = 7 / 6 = 1 + 1/6

bernoulli[16] = -3617 / 510 = -7 - 47/510

bernoulli[18] = 43867 / 798 = 54 + 775/798

bernoulli[20] = -174611 / 330 = -529 - 41/330

bernoulli[22] = 854513 / 138 = 6192 + 17/138

bernoulli[24] = -236364091 / 2730 = -86580 - 691/2730

bernoulli[26] = 8553103 / 6 = 1425517 + 1/6

bernoulli[28] = -23749461029 / 870 = -27298231 - 59/870

bernoulli[30] = 8615841276005 / 14322 = 601580873 + 12899/14322

bernoulli[32] = -7709321041217 / 510 = -15116315767 - 47/510

bernoulli[34] = 2577687858367 / 6 = 429614643061 + 1/6

bernoulli[36] = -26315271553053477373 / 1919190 = -13711655205088 - 638653/1919190

bernoulli[38] = 2929993913841559 / 6 = 488332318973593 + 1/6

bernoulli[40] = -261082718496449122051 / 13530 = -19296579341940068 - 2011/13530

bernoulli[42] = 1520097643918070802691 / 1806 = 841693047573682615 + 1/1806

bernoulli[44] = -27833269579301024235023 / 690 = -40338071854059455413 - 53/690

bernoulli[46] = 596451111593912163277961 / 282 = 2115074863808199160560 + 41/282

bernoulli[48] = -5609403368997817686249127547 / 46410 = -120866265222965259346027 - 14477/46410

bernoulli[50] = 495057205241079648212477525 / 66 = 7500866746076964366855720 + 5/66

bernoulli[52] = -801165718135489957347924991853 / 1590 = -503877810148106891413789303 - 83/1590

bernoulli[54] = 29149963634884862421418123812691 / 798 = 36528776484818123335110430842 + 775/798

bernoulli[56] = -2479392929313226753685415739663229 / 870 = -2849876930245088222626914643291 - 59/870

bernoulli[58] = 84483613348880041862046775994036021 / 354 = 238654274996836276446459819192192 + 53/354

bernoulli[60] = -1215233140483755572040304994079820246041491 / 56786730 = -21399949257225333665810744765191097 - 22298681/56786730

bernoulli[62] = 12300585434086858541953039857403386151 / 6 = 2050097572347809756992173309567231025 + 1/6

bernoulli[64] = -106783830147866529886385444979142647942017 / 510 = -209380059113463784090951852900279701847 - 47/510

bernoulli[66] = 1472600022126335654051619428551932342241899101 / 64722 = 22752696488463515559649260352769264581469 + 62483/64722

bernoulli[68] = -78773130858718728141909149208474606244347001 / 30 = -2625771028623957604730304973615820208144900 - 1/30

bernoulli[70] = 1505381347333367003803076567377857208511438160235 / 4686 = 321250821027180325182047923042649852435219411 + 289/4686

bernoulli[72] = -5827954961669944110438277244641067365282488301844260429 / 140100870 = -41598278166794710913917074495262358936689603011 - 48540859/140100870

bernoulli[74] = 34152417289221168014330073731472635186688307783087 / 6 = 5692069548203528002388345621912105864448051297181 + 1/6

bernoulli[76] = -24655088825935372707687196040585199904365267828865801 / 30 = -821836294197845756922906534686173330145508927628860 - 1/30

bernoulli[78] = 414846365575400828295179035549542073492199375372400483487 / 3318 = 125029043271669930167323398297028955241771963644484775 + 37/3318

bernoulli[80] = -4603784299479457646935574969019046849794257872751288919656867 / 230010 = -20015583233248370274925329198813298768724220132825915915 - 47717/230010

bernoulli[82] = 1677014149185145836823154509786269900207736027570253414881613 / 498 = 3367498291536437423339667690333875301621959894719384367232 + 77/498

bernoulli[84] = -2024576195935290360231131160111731009989917391198090877281083932477 / 3404310 = -594709705031354477186604968440515408405790715651069049904704 - 1058237/3404310

bernoulli[86] = 660714619417678653573847847426261496277830686653388931761996983 / 6 = 110119103236279775595641307904376916046305114442231488626999497 + 1/6

bernoulli[88] = -1311426488674017507995511424019311843345750275572028644296919890574047 / 61410 = -21355259545253501188658385019041065678973298739163469211804590304 - 5407/61410

bernoulli[90] = 1179057279021082799884123351249215083775254949669647116231545215727922535 / 272118 = 4332889698664119241961661305937920621845136851180910914498655788032 + 230759/272118

bernoulli[92] = -1295585948207537527989427828538576749659341483719435143023316326829946247 / 1410 = -918855282416693282262005552155018971389603889162719959591004487113437 - 77/1410

bernoulli[94] = 1220813806579744469607301679413201203958508415202696621436215105284649447 / 6 = 203468967763290744934550279902200200659751402533782770239369184214108241 + 1/6

bernoulli[96] = -211600449597266513097597728109824233673043954389060234150638733420050668349987259 / 4501770 = -47003833958035731078575255535006060654596737369759057915139763564120483354 - 1450679/4501770

bernoulli[98] = 67908260672905495624051117546403605607342195728504487509073961249992947058239 / 6 = 11318043445484249270675186257733934267890365954750747918178993541665491176373 + 1/6

bernoulli[100] = -94598037819122125295227433069493721872702841533066936133385696204311395415197247711 / 33330 = -2838224957069370695926415633648176473828468092801288212822853171446486511107028 - 4471/33330

bernoulli[102] = 3204019410860907078243020782116241775491817197152717450679002501086861530836678158791 / 4326 = 740642489796788506297508271409209841768797317880887066731161003487485328441210855 + 61/4326

bernoulli[104] = -319533631363830011287103352796174274671189606078272738327103470162849568365549721224053 / 1590 = -200964548027566044834656196727153631868672708225328766243461301989213565009779698883 - 83/1590

bernoulli[106] = 36373903172617414408151820151593427169231298640581690038930816378281879873386202346572901 / 642 = 56657170050805941445719346030519356961419468287510420621387564452152460861972277798400 + 101/642

bernoulli[108] = -3469342247847828789552088659323852541399766785760491146870005891371501266319724897592306597338057 / 209191710 = -16584511154136216915823713374319912301494962614725464727402466815589878137712650743149939 - 71532367/209191710

bernoulli[110] = 7645992940484742892248134246724347500528752413412307906683593870759797606269585779977930217515 / 1518 = 5036885995049237741928942191518015481244237426490321414152565132252831097674298932791785387 + 49/1518

bernoulli[112] = -2650879602155099713352597214685162014443151499192509896451788427680966756514875515366781203552600109 / 1671270 = -1586146823765818636936340157296643878274097841277896388047286451429731136509885006831200945121 - 226439/1671270

bernoulli[114] = 21737832319369163333310761086652991475721156679090831360806110114933605484234593650904188618562649 / 42 = 517567436175456269840732406825071225612408492359305508590621669403181082957966515497718776632444 + 1/42

bernoulli[116] = -309553916571842976912513458033841416869004128064329844245504045721008957524571968271388199595754752259 / 1770 = -174889218402171173396900258776181591451414761618265448726273472158762122895238400153326666438279521 - 89/1770

bernoulli[118] = 366963119969713111534947151585585006684606361080699204301059440676414485045806461889371776354517095799 / 6 = 61160519994952185255824525264264167780767726846783200716843240112735747507634410314895296059086182633 + 1/6

bernoulli[120] = -51507486535079109061843996857849983274095170353262675213092869167199297474922985358811329367077682677803282070131 / 2328255930 = -22122776912707834942288323456712932445573185054987780150566552693027736635002572659102528031391154956836 - 971032651/2328255930

bernoulli[122] = 49633666079262581912532637475990757438722790311060139770309311793150683214100431329033113678098037968564431 / 6 = 8272277679877096985422106245998459573120465051843356628384885298858447202350071888172185613016339661427405 + 1/6

bernoulli[124] = -95876775334247128750774903107542444620578830013297336819553512729358593354435944413631943610268472689094609001 / 30 = -3195892511141570958359163436918081487352627667109911227318450424311953111814531480454398120342282422969820300 - 1/30

bernoulli[126] = 5556330281949274850616324408918951380525567307126747246796782304333594286400508981287241419934529638692081513802696639 / 4357878 = 1275008222338779298231002430292667986695719179638977329516058573538220731833362242193847881912832263475958141508 + 4096615/4357878

bernoulli[128] = -267754707742548082886954405585282394779291459592551740629978686063357792734863530145362663093519862048495908453718017 / 510 = -525009230867741338994028246245651754469198940377552432607801345222270181833065745383064045281411494212737075399447 - 47/510

bernoulli[130] = 1928215175136130915645299522271596435307611010164728458783733020528548622403504078595174411693893882739334735142562418015 / 8646 = 223018178942416252098692981988387281437382721508758785424905507810380363451712245962893177387681457638137258286208931 + 589/8646

bernoulli[132] = -410951945846993378209020486523571938123258077870477502433469747962650070754704863812646392801863686694106805747335370312946831 / 4206930 = -97684521930955204438633513398980239301166902674985678971000170661895983711329844759158434488299944780185742512315481910 - 1310531/4206930

bernoulli[134] = 264590171870717725633635737248879015151254525593168688411918554840667765591690540727987316391252434348664694639349484190167 / 6 = 44098361978452954272272622874813169191875754265528114735319759140111294265281756787997886065208739058110782439891580698361 + 1/6

bernoulli[136] = -84290226343367405131287578060366193649336612397547435767189206912230442242628212786558235455817749737691517685781164837036649737 / 4110 = -20508570886464088839729337727583015486456596690400835953087398275481859426430222089186918602388746894815454424764273682977287 - 167/4110

bernoulli[138] = 2694866548990880936043851683724113040849078494664282483862150893060478501559546243423633375693325757795709438325907154973590288136429 / 274386 = 9821443327979127710757296960209752104149185799072410705583196274811683181939115856580267855114057414721266530821204999429964677 + 273107/274386

bernoulli[140] = -3289490986435898803930699548851884006880537476931130981307467085162504802973618096693859598125274741604181467826651144393874696601946049 / 679470 = -4841260079820888050878919670996341276113054994232462038511585625800263150652152555217830953721687111431235327279572526224667309229 - 117419/679470

bernoulli[142] = 14731853280888589565870080442453214239804217023990642676194878997407546061581643106569966189211748270209483494554402556608073385149191 / 6 = 2455308880148098260978346740408869039967369503998440446032479832901257676930273851094994364868624711701580582425733759434678897524865 + 1/6

bernoulli[144] = -3050244698373607565035155836901726357405007104256566761884191852434851033744761276392695669329626855965183503295793517411526056244431024612640493 / 2381714790 = -1280692680408474754878251327860178572181183417119632011809521429908427882645327686944705780380037383050883058628440358894326745245777738 - 965295473/2381714790

bernoulli[146] = 4120570026280114871526113315907864026165545608808541153973817680034790262683524284855810008621905238290240143481403022987037271683989824863 / 6 = 686761671046685811921018885984644004360924268134756858995636280005798377113920714142635001436984206381706690580233837164506211947331637477 + 1/6

bernoulli[148] = -1691737145614018979865561095112166189607682852147301400816480675916957871178648433284821493606361235973346584667336181793937950344828557898347149 / 4470 = -378464685819691046949789954163795568144895492650402997945521404008267980129451551070429864341467838025357177777927557448308266296382227717751 - 179/4470

bernoulli[150] = 463365579389162741443284425811806264982233725425295799852299807325379315501572305760030594769688296308375193913787703707693010224101613904227979066275 / 2162622 = 214261012506652915508713231351482720966601526029650951415596348934478293248460575061213006604801160955717270014726431021090606783849241293313384 + 1933427/2162622

bernoulli[152] = -3737018141155108502105892888491282165837489531488932951768507127182409731328472084456653639812530140212355374618917309552824925858430886313795805601 / 30 = -124567271371836950070196429616376072194582984382964431725616904239413657710949069481888454660417671340411845820630576985094164195281029543793193520 - 1/30

bernoulli[154] = 10259718682038021051027794238379184461025738652460569233992776489750881337506863808448685054322627708245455888249006715516690124228801409697850408284121 / 138 = 74345787551000152543679668394052061311780714872902675608643307896745516938455534843831051118279910929314897740934831271860073363976821809404713103508 + 17/138

bernoulli[156] = -81718086083262628510756459753673452313595710396116467582152090596092548699138346942995509488284650803976836337164670494733866559829768848363506624334818961419869 / 1794590070 = -45535795304641704894063333223321274876772114534277160901794185563554661092679704253013898315109171870084423423319549792635298912486331125393726615424111 - 522242099/1794590070

bernoulli[158] = 171672676901153210072183083506103395137513922274029564150500135265308148197358551999205867870374013289728260984269623579880772408522396975250682773558018919 / 6 = 28612112816858868345363847251017232522918987045671594025083355877551358032893091999867644645062335548288043497378270596646795401420399495875113795593003153 + 1/6

bernoulli[160] = -4240860794203310376065563492361156949989398087086373214710625778458441940477839981850928830420029285687066701804645453159767402961229305942765784122421197736180867 / 230010 = -18437723552033869727688202653628785487541402926335260270034458408149393245849484726102903484283419354319667413610910191555877583414761557944288440165302368315 - 47717/230010

bernoulli[162] = 1584451495144416428390934243279426140836596476080786316960222380784239380974799880364363647978168634590418215854419793716549388865905348534375629928732008786233507729 / 130074 = 12181154536221046699501316506599521355817430663167015060351971806696491081805740427482538001277493077712826666777525052789561241031300248584464458144840696728273 + 125527/130074

bernoulli[164] = -20538064609143216265571979586692646837805331023148645068133372383930344948316600591203926388540940814833173322793804325084945094828524860626092013547281335356200073083 / 2490 = -8248218718531412154848184572968934473014189165923150629772438708405761023420321522571857987365839684671957157748515793206805258967279060492406431143486480062730953 - 113/2490

bernoulli[166] = 5734032969370860921631095311392645731505222358555208498573088911303001784652122964703205752709194193095246308611264121678834250704468082648313788124754168671815815821441 / 1002 = 5722587793783294332965164981429786159186848661232743012547992925452097589473176611480245262184824544007231844921421279120593064575317447752808171781191785101612590640 + 161/1002

bernoulli[168] = -13844828515176396081238346585063517228531109156984345249260453934317772754836791258987516540324983611569758649525983347408589045734176589270143058509026392246407576578281097477 / 3404310 = -4066853052505910472676796938311586556021957212176430833050002477541050243613769386156817839833911603693482276739187485102293576593840334537731011132660184368170811876204 - 1058237/3404310

bernoulli[170] = 195334207626637530414976779238462234481410337350988427215139995707346979124686918267688171536352650572535330369818176979951931477427594872783018749894699157917782460035894085 / 66 = 2959609206464205006287526958158518704263792990166491321441515086474954229161923004055881386914434099583868641966942075453817143597387801102773011362040896332087613030846880 + 5/66

bernoulli[172] = -11443702211333328447187179942991846613008046506032421731755258148665287832264931024781365962633301701773088470841621804328201008020129996955549467573217659587609679405537739509973 / 5190 = -2204952256518945750903117522734459848363785453956150622688874402440325208528888444081188046750154470476510302666979153049749712527963390550202209551679703196071229172550624183 - 203/5190

Sunday, November 03, 2024

[crdxmcet] angular defect of regular polyhedra

degrees missing from being flat at vertex:

tetrahedron 180
octahedron 120
cube 90
icosahedron 60
dodecahedron 36

(angle defect)*(number of vertices) = 720 degree = 4*pi radian, a theorem of Descartes.

by this metric, dodecahedron is the most flat, the least confusing (at corners) for a map of a sphere.  (does that mean it has a lot of distortion inside each face?)  create a tool to display the earth on a dodecahedral net.  drag any point to anywhere on the net and reproject.  also need rotation.  move pentagons to choose among many possible nets.  what countries fit neatly inside adjacent pentagons?  I don't have a good feel of what is the area and extent of 1/12 or 2/12 of a sphere (1 or 2 pentagons).

move portions of pentagons?  the dissection of a pentagon by a pentagram (star) might be useful, as well as the dissection from the center into pie pieces.

vertex-transitive polyhedra have the same angle defect at every vertex.  the Archimedean solids are another (the other?) family of vertex-transitive polyhedra.  by the theorem of Descartes, the most flat therefore is the polyhedron with the most vertices.  excluding the prisms and antiprisms, the truncated icosidodecahedron has the most vertices with 120.  decagon, hexagon, and square meet at each of its vertices; angle defect is 6 degrees.  how much map distortion is in its 12 relatively large decagons?  (30 squares and 20 hexagons are its other faces.  62 faces total.)

previously, pillars of inaccessibility: the tile diagonally opposite you is blank, perhaps annotated with curved arrows indicating edges connect.  moving your immersed character locally induces a different net.  the faces of a net could discretely change adjacency, or walking around a vertex could cause the net to continuously reproject itself, keeping the inaccessible gap diagonally across from you.  not sure if the latter works.

future work: solid angular defect of 4D regular polytopes.

Wednesday, October 02, 2024

[jshrjuga] direct Fibonacci formula without division

golden ratio:

phi = (1 + sqrt(5)) / 2

the version of Binet's formula for the nth Fibonacci number which uses the round-to-the-nearest-integer function is

F[n] = round( phi^n / sqrt(5) )

if that division by sqrt(5) is annoying, another way to write it is

F[n] = round( phi^(n-z) )

where

z = log( Base phi, sqrt(5) ) = log(5) / (2*log(phi)) ~= 1.6722759381845547461703191263944365539

.

not sure what this would be useful for.  you need exp and log to compute exponentiation by the non-integer exponent, in contrast to simpler exponentiation by squaring for the integer exponent in the original formula.

Thursday, September 26, 2024

[aqyyoppn] relativistic bullet

let

(relativistic kinetic energy) = (relativistic mass-energy) - (rest mass-energy)

(rest mass-energy) = m * c^2

let resq = "remaining speed squared" = c^2 - v^2, having units of speed^2.

aside: lorentz = sqrt(c^2/resq) is unitless.  we prefer to work with resq rather than lorentz because with resq, some mistakes can be caught by dimensional analysis.

aside: for very small v, resq has problems with numerical precision.  for very high v, lorentz has problems with numerical precision.

(relativistic mass-energy) = sqrt(c^2/resq) * m * c^2

(relativistic kinetic energy) = (sqrt(c^2/resq)-1) * m * c^2

assume a bullet has mass 100 grain = 6.49 gram.  (aside: the fact that "in" in grain looks like "m" in gram in some fonts is unfortunate.) (another aside: dram is another unit of mass used in firearms, 1/256 lb.  dram sounds similar to gram.  1 dram = 1.77 gram.  "if you are facing a charging rhino, be sure your shotgun shell is loaded with at least ___ [unintelligible]rams of black powder in order to stop it.  but not too much or the gun will explode in your face.")

(rest mass-energy of 100 grain bullet) = 5.82e14 J

at typical bullet speed 0.0000031622777 c = sqrt(1e-11) c = 3110 ft/s = 2121 mph = 948 m/s : (relativistic kinetic energy) = 2911.9 J

0.01 c : (relativistic kinetic energy) = 2.9121e10 J (3162x speed ~= 10,000,000x energy, matching non-relativistic approximation)

0.1 c : 2.93e12 J (10x speed ~= 100x energy, matching non-relativistic approximation)

0.5 c : 9.01e13 J (50x speed ~= 3094x energy, not 2500x by non-relativistic approximation)

0.866 c = sqrt(0.75) c : 5.82e14 J (kinetic energy equals rest mass-energy)

0.9 c : 7.54e14 J

0.99 c : 3.546e15 J

expressing energy in terms of tons of TNT:

(rest mass-energy) = 5.82e14 J = 139 kiloton tnt

typical bullet speed 0.0000031622777 c : (relativistic kinetic energy) = 696 nanoton tnt = 9.74 grain tnt (which unsurprisingly is in the same order of magnitude as typical amounts of black powder in gun rounds)

0.01 c : 6.96 ton tnt

0.1 c : 701 ton tnt

0.5 c : 21.53 kiloton tnt

0.866 c : 139 kiloton tnt

0.9 c : 180 kiloton tnt

0.99 c : 848 kiloton tnt

inspiration: if a SpaceX Starship (approximately 10 kiloton tnt) were to explode on the launchpad, and a significant fraction of its chemical energy were freakishly transferred into a single bullet-sized piece of debris, how far would be safe distance to view the launch and not get hurt by debris?

answer, assuming no air resistance: there is no safe distance.  inverting the equations above, a bullet with relativistic kinetic energy 10 kiloton tnt has speed 0.36 c.  5 kiloton tnt is 0.26 c, because maybe we care about conservation of momentum.  in comparison, speed of low earth orbit is 0.000026 c, and earth escape velocity is 0.000037 c.  a bullet in orbit can hit anywhere on earth; a bullet escaping earth can hit anywhere in the universe.

the SpaceX Starship is of course trying to deliver payloads much more massive than a bullet into orbit or to infinity.  this fact alone is enough to conclude there is no safe distance.