Compare commits

...

3 commits

Author SHA1 Message Date
Louis Burke 0caedcc0df Added 2022 SI prefices 2025-01-13 00:00:35 -05:00
Louis Burke e1660d42de Good progress made 2024-09-23 19:57:32 -04:00
Louis Burke 8394c83e40 Making progress, trying something 2024-04-07 20:45:12 -04:00
6 changed files with 260 additions and 81 deletions

5
README.md Normal file
View file

@ -0,0 +1,5 @@
To play around with IIPAU, run `julia --project=.` and start with:
using Revise
using Unitful
using IIPAU

29
src/Constants.jl Normal file
View file

@ -0,0 +1,29 @@
# Useful information:
#
# https://en.wikipedia.org/wiki/List_of_physical_quantities
# https://en.wikipedia.org/wiki/List_of_physical_constants
module Constants
import Unitful
using Unitful: @unit
export item
function __init__()
Unitful.register(Constants)
end
c = 1 * Unitful.c
h = Unitful.h
ħ = Unitful.ħ
μ₀= Unitful.μ0
Z₀= Unitful.Z0
kₑ = 1 / (4 * π * Unitful.ϵ0) # Coulomb constant
mₑ = Unitful.me
mₚ = Unitful.mp
mₙ = Unitful.mn
kb = Unitful.k
ϵ₀ = Unitful.ϵ0

View file

@ -1,105 +1,74 @@
# Useful information:
#
# https://en.wikipedia.org/wiki/List_of_physical_quantities
# https://en.wikipedia.org/wiki/List_of_physical_constants
# https://www.themeasureofthings.com/
# https://cs.uwaterloo.ca/~dtompkin/music/bpm/118.html
# https://physics.stackexchange.com/questions/167720/what-is-the-correct-theoretical-formula-for-the-hyperfine-splitting-of-neutral-h
#
# "free" Unitful units: efijno r v xzDEIOQUXZ |
# "free" Unitful units: f jno r v xzDEIOQUXZ |
# "used" Unitful units: e i p t w |
module IIPAU
include("Seximal.jl")
include("Quantum.jl")
include("Natural.jl")
using .Seximal
using .Quantum
using .Natural
import Unitful
using Unitful: @unit, @affineunit, @u_str
export item
export @b6_str
export yocte, zepte, atte, femte, pice, nane, micre, mille, cente, dice
export yotte, zette, exe, pete, tere, gige, mege, kile, hecte, dece
export to₆
export pace, tick, egg, jolt, brr, °c
export wave_number
export span, tick, egg, spark, lotta, alotta, brr
export ball, touch, jolt
function __init__()
Unitful.register(IIPAU)
end
#Unitful.register(IIPAU)
# Additional Constants
kₑ = 8987551792u"N*m^2/C^2"
mₑ = 9.109e-31u"kg"
mᵤ = 1.6605390666e-27u"kg"
mₙ = 1.674927498e-27u"kg"
kb = 1.380649e-23u"J/K"
ϵ₀ = 8.854e-12u"F/m"
# Natural Units
@unit lₛ "lₛ" StoneyLength (sqrt(Unitful.G * kₑ * Unitful.q^2 / Unitful.c^4) |> Unitful.upreferred) false
@unit mₛ "mₛ" StoneyMass (sqrt(kₑ * Unitful.q^2 / Unitful.G) |> Unitful.upreferred) false
@unit tₛ "tₛ" StoneyTime (sqrt(Unitful.G * kₑ * Unitful.q^2 / Unitful.c^6) |> Unitful.upreferred) false
@unit lₚ "lₚ" PlanckLength sqrt(Unitful.ħ * Unitful.G / Unitful.c^3) false
@unit mₚ "mₚ" PlanckMass sqrt(Unitful.ħ * Unitful.c / Unitful.G) false
@unit tₚ "tₚ" PlanckTime sqrt(Unitful.ħ * Unitful.G / Unitful.c^5) false
@unit Tₚ "Tₚ" PlanckTemperature sqrt(Unitful.ħ * Unitful.c ^ 5 / (Unitful.G * Unitful.k ^ 2)) false
@unit qₚ "qₚ" Planckcharge sqrt(4π * Unitful.ϵ0 * Unitful.ħ * Unitful.c) false
@unit Qₚ "Qₚ" PlanckCharge sqrt(Unitful.ϵ0 * Unitful.ħ * Unitful.c) false
item = @unit count "count" Count (1 / Unitful.Na) false
# Senary prefixes
function base6(number::AbstractString)
if occursin('e', number)
(digits, exponent) = split(number, 'e')
else
(digits, exponent) = (number, "0")
end
if occursin('.', digits)
value = parse(BigFloat, digits, base=6)
else
value = parse(BigInt, digits, base=6)
end
expval = parse(Int, exponent, base=6)
if expval < 0
return 1 // (value * BigInt(6) ^ (-expval))
else
return value * BigInt(6) ^ expval
end
end
macro b6_str(digits)
value = base6(digits)
return :( $value )
end
yocte = b6"1e-52" # y |
zepte = b6"1e-44" # z |
atte = b6"1e-40" # a |
femte = b6"1e-32" # f |
pice = b6"1e-24" # p |
nane = b6"1e-20" # n |
micre = b6"1e-12" # μ |
mille = b6"1e-4" # m |
cente = b6"1e-2" # c |
dice = b6"1e-1" # d |
dece = b6"1e1" # de |
hecte = b6"1e2" # h |
kile = b6"1e4" # k |
mege = b6"1e12" # M |
gige = b6"1e20" # G |
tere = b6"1e24" # T |
pete = b6"1e32" # P |
exe = b6"1e40" # E |
zette = b6"1e44" # Z |
yotte = b6"1e52" # Y |
# Base Units
pace = 1@unit p "p" Pace (lₛ * b6"1e114") false # ~86cm
tick = 1@unit t "t" Tick (tₛ * b6"3e132") false # ~0.52s = 300₆ instants (1/tick ~115bpm)
egg = 1@unit e "e" Egg (mₛ * b6"1e14") false # ~112g
jolt = 1@unit j "j" Jolt (b6"1e34" * Unitful.q / tick) false # ~40mA painful jolt (https://electronics.stackexchange.com/questions/19103/how-much-voltage-current-is-dangerous)
brr = 1@unit "" Brr (Tₚ * b6"1e-110") false # ~0.3K
@affineunit °c "°c" (Int(b6"4400") * brr) # ~13°C -> 0°c
span = 1@unit "" Span (Unitful.c / Natural.HHz) false # ~21cm
tick = 1@unit t "t" Tick (b6"2e15" / Natural.HHz) false # ~0.51s (1/tick is ~118 bpm)
egg = 1@unit e "e" Egg (-b6"4e44" * Natural.ΔEₕ * tick^2 / span^2) false # ~136g
spark = 1@unit ş "ş" Spark (b6"1e34" * Unitful.q) false # ~0.02C
lotta = 1@unit ļ "ļ" Lotta (1u"mol" * egg / u"g") false # ~135mol
alotta = (lotta |> item).val # ~81 septillion (81e24)
brr = 1@unit "" Brr (Natural.ΔEₕ / Natural.hexit) false # ~0.04K
@affineunit °c "°c" (Int(b6"-100000") * brr) # ~23°C -> 0°c, human's can't really survive past about -2000₆°c (too hot)
# Derived Units
ball = 1@unit "" Ball ((π/6)*span^3) false # ~5L (sphere of diameter 1ṡ)
touch = 1@unit "" Touch (egg * span / tick ^2) false # ~0.1N (10grams of weight)
jolt = 1@unit j "j" Jolt (spark / tick) false # ~0.04A
cell = 1@unit ċ "ċ" Cell (span * touch / spark) false # ~1.1V (just shy of zinc/copper electrode)
# TODO: resistance is at about 26.6Ω
# Convenience Units
instant = 1@unit i "i" Instant (b6"3e-2" * tick) false # ~5ms (300₆ instants to a tick)
pause = 1@unit "" Pause (b6"300" * tick) false # ~55 seconds
wait = 1@unit "" Wait (b6"300" * pause) false # ~100 minutes
# Useful references
resistance_of_wire(ρ, L, d) = ρ * L / (π * (d/2)^2)
# Note: 1 kile span of 1 mille span diameter silver wire has a resistance of about 210Ω
#egg = 1@unit e "e" Egg (b6"1e53" * (Unitful.mp + Unitful.me)) false # ~80g
#=
# pace = 1@unit p "p" Pace (lₛ * b6"1e114") false # ~86cm
# tick = 1@unit t "t" Tick (tₛ * b6"3e132") false # ~0.52s = 300₆ instants (1/tick ~115bpm)
# egg = 1@unit e "e" Egg (mₛ * b6"1e14") false # ~112g
# jolt = 1@unit j "j" Jolt (b6"1e34" * Unitful.q / tick) false # ~40mA painful jolt (https://electronics.stackexchange.com/questions/19103/how-much-voltage-current-is-dangerous)
# brr = 1@unit ḃ "ḃ" Brr (Tₚ * b6"1e-110") false # ~0.3K
# @affineunit °c "°c" (Int(b6"4400") * brr) # ~13°C -> 0°c
# Convenience Units
instant = 1@unit i "i" Instant (tₛ * b6"1e130") false # ~5ms (1000₆ instants is about a second)
@ -109,7 +78,7 @@ wait = 1@unit ẇ "ẇ" Wait (pause * b6"100") false # ~34 minutes
# Derived Units
walk = 1@unit w "w" Walk (1 * pace / tick) false # ~6km/h (pretty quick walk)
touch = 1@unit "" Touch (1 * egg * pace / tick ^ 2) false # ~0.36N (half what it takes to press a key on a keyboard)
# touch = 1@unit ṫ "ṫ" Touch (1 * egg * pace / tick ^ 2) false # ~0.36N (half what it takes to press a key on a keyboard)
nosh = 1@unit n "n" Nosh (b6"1e11" * pace * touch) false # ~20.5 kcal
#= Useful Constants ============================================================
@ -117,6 +86,8 @@ nosh = 1@unit n "n" Nosh (b6"1e11" * pace * touch) false # ~20.5 kcal
Speed of light: c 3e14₆p/t
===============================================================================#
=#
#=
export stride, skip, bed, gulp
export moment, instant, wait

35
src/Natural.jl Normal file
View file

@ -0,0 +1,35 @@
module Natural
import Unitful
using Unitful:@unit
export lₛ, mₛ, tₛ
export lₚ, mₚ, tₚ, Tₚ, qₚ, Qₚ, item
# Additional constants (not in Unitful)
kₑ = 1 / (4 * π * Unitful.ϵ0) # Coulomb constant
gₑ = 2.00231930436256 # Electron g-factor
gₚ = 5.5856946893 # Proton g-factor
α = Unitful.q^2 / (4 * π * Unitful.ϵ0 * Unitful.ħ * Unitful.c) # fine structure constant
a₀= Unitful.ħ / (Unitful.me * Unitful.c * α) # bohr radius
ΔEₕ = 2 * gₑ * α^4 * gₚ * Unitful.me^2 * Unitful.c^2 / (3 * Unitful.mp) # hydrogen hyperfine transition energy
HHz = -ΔEₕ / Unitful.h # Hydrogen hyperfine transition frequency
bit = Unitful.k * log(2)
hexit = Unitful.k * log(6)
natit = Unitful.k * log(1/α)
# Natural Units
@unit lₛ "lₛ" StoneyLength (sqrt(Unitful.G * kₑ * Unitful.q^2 / Unitful.c^4) |> Unitful.upreferred) false
@unit mₛ "mₛ" StoneyMass (sqrt(kₑ * Unitful.q^2 / Unitful.G) |> Unitful.upreferred) false
@unit tₛ "tₛ" StoneyTime (sqrt(Unitful.G * kₑ * Unitful.q^2 / Unitful.c^6) |> Unitful.upreferred) false
@unit lₚ "lₚ" PlanckLength sqrt(Unitful.ħ * Unitful.G / Unitful.c^3) false
@unit mₚ "mₚ" PlanckMass sqrt(Unitful.ħ * Unitful.c / Unitful.G) false
@unit tₚ "tₚ" PlanckTime sqrt(Unitful.ħ * Unitful.G / Unitful.c^5) false
@unit Tₚ "Tₚ" PlanckTemperature sqrt(Unitful.ħ * Unitful.c ^ 5 / (Unitful.G * Unitful.k ^ 2)) false
@unit qₚ "qₚ" Planckcharge sqrt(4π * Unitful.ϵ0 * Unitful.ħ * Unitful.c) false
@unit Qₚ "Qₚ" PlanckCharge sqrt(Unitful.ϵ0 * Unitful.ħ * Unitful.c) false
item = @unit ç "ç" Count (1 / Unitful.Na) false
end # module Natural

14
src/Quantum.jl Normal file
View file

@ -0,0 +1,14 @@
module Quantum
import Unitful
export wave_number
RH = Unitful.R∞ * Unitful.mp / (Unitful.mp + Unitful.me)
Rₙ(z::Integer) = (Unitful.R∞ * Unitful.mp * z) / (Unitful.mp * z + Unitful.me)
# Inverse wavelength
wave_number(z::Integer, n1::Integer, n2::Integer) = Rₙ(z) * z^2 * ((1 / n1^2) - (1 / n2^2))
end # module Quantum

125
src/Seximal.jl Normal file
View file

@ -0,0 +1,125 @@
module Seximal
export @b6_str
export yocte, zepte, atte, femte, pice, nane, micre, mille, cente, dice
export yotte, zette, exe, pete, tere, gige, mege, kile, hecte, dece
# Senary prefixes
function base6(number::AbstractString)
if occursin('e', number)
(digits, exponent) = split(number, 'e')
else
(digits, exponent) = (number, "0")
end
if occursin('.', digits)
value = parse(BigFloat, digits, base=6)
else
value = parse(BigInt, digits, base=6)
end
expval = parse(Int, exponent, base=6)
if expval < 0
return 1 // (value * BigInt(6) ^ (-expval))
else
return value * BigInt(6) ^ expval
end
end
macro b6_str(digits)
value = base6(digits)
return :( $value )
end
quecte = b6"1e-64" # q |
ronte = b6"1e-60" # r |
yocte = b6"1e-52" # y |
zepte = b6"1e-44" # z |
atte = b6"1e-40" # a |
femte = b6"1e-32" # f |
pice = b6"1e-24" # p |
nane = b6"1e-20" # n |
micre = b6"1e-12" # μ |
mille = b6"1e-4" # m |
cente = b6"1e-2" # c |
dice = b6"1e-1" # d |
dece = b6"1e1" # de |
hecte = b6"1e2" # h |
kile = b6"1e4" # k |
mege = b6"1e12" # M |
gige = b6"1e20" # G |
tere = b6"1e24" # T |
pete = b6"1e32" # P |
exe = b6"1e40" # E |
zette = b6"1e44" # Z |
yotte = b6"1e52" # Y |
ronne = b6"1e60" # R |
quette = b6"1e64" # Q |
#=
def longdiv(numerator,denominator):
digits = []
remainders = [0]
n = numerator
while n not in remainders: # until repeated remainder or no remainder
remainders.append(n) # add remainder to collection
digits.append(n//denominator) # add integer division to result
n = n%denominator * 10 # remainder*10 for next iteration
# Result
result = list(map(str,digits)) # convert digits to strings
result = ''.join(result) # combine list to string
if not n:
result = result[:1]+'.'+result[1:] # Insert . into string
else:
recurring = remainders.index(n)-1 # first recurring digit
# Insert '.' and then surround recurring part in brackets:
result = result[:1]+'.'+result[1:recurring]+'['+result[recurring:]+']'
return result;
print(longdiv(31,8)) # 3.875
print(longdiv(2,13)) # 0.[153846]
print(longdiv(13,14)) # 0.9[285714]
=#
"Converts x to an exact seximal number. Repeated digits are shown in brackets."
function to₆(x :: Rational{BigInt})
if x < 0
return "-" * to₆(-x)
end
if x > 1
intpart = floor(x)
return string(intpart.num, base=6) * to₆(x - intpart)
end
digits = []
remainders = [BigInt(0)]
remset = Set{BigInt}()
n = x.num
d = x.den
while !(n in remset)
append!(remainders, n)
push!(remset, n)
append!(digits, floor(n // d).num)
n = (n % d) * 6
end
if n == 0
return "." * prod(map(string, digits[2:end]))
end
recur = findfirst(==(n), remainders) - 1
return "." * prod(map(string, digits[2:recur - 1])) * "(" * prod(map(string, digits[recur:end])) * ")"
end
to₆(x) = to₆(Rational{BigInt}(x))
# TODO: custom base6 version of @prefixed_unit_symbol
end # module Seximal