Jupyt-nb is designed to study Mathematical and Physical Constants properties of ratios as detailed in http://vixra.org/pdf/1904.0218v4.pdf
It uses 2 Julia packages:
MathPhysicalConstants.SI
PhysicalConstant.CODATA2019
it can be linked to numpy using PyCall
Pkg.clone("https://github.com/laguer/MathPhysicalConstants.jl")
versioninfo()
Julia Version 0.6.4 Commit 9d11f62bcb (2018-07-09 19:09 UTC) Platform Info: OS: Linux (x86_64-pc-linux-gnu) CPU: Intel(R) Xeon(R) CPU @ 2.20GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)
Pkg.init()
INFO: Initializing package repository /srv/julia/pkg/v0.6 INFO: Package directory /srv/julia/pkg/v0.6 is already initialized.
Pkg.add("Unitful")
INFO: Package Unitful is already installed
#import Pkg;
Pkg.status()
Pkg.clone("https://github.com/laguer/PhysicalConstant.jl.git")
Pkg.add("PhysicalConstant")
INFO: Package PhysicalConstant is already installed
Pkg.dir("PhysicalConstant")
using Unitful
using Measurements
using MathPhysicalConstants.SI
Let's experiment MathPhysConstants by looking at the reduced electron Compton wavelength Basic formula is given by ƛ_e ≡ ħ/m_e.c
big(SI.PlanckConstantHbar)/(big(SI.MassElectron)*big(SI.SpeedOfLight))
3.861592046068737688702740558503376825155847784672545991504355454736855198364958e-13
big(SI.SanchezElectrConstant)
1.370359991390000118371972348541021347045898437500000000000000000000000000000000e+02
measurement(SI.PlanckConstantHbar)
big(measurement(SI.PlanckConstantHbar))
using Unitful
using Measurements
using MathPhysicalConstants.SI
a1 = big(e^e^e)
3.814279104760214220732450485229492187500000000000000000000000000000000000000000e+06
a1^e
7.764865179158049315959156489518625436695868996929735868921423813247391069467881e+17
a = SI.SanchezElectrConstant
137.035999139
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport numpy as np
np.log(137)/ np.log(a/137)
18726.168436946326
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport numpy as np
@pyimport sympy as sy
@pyimport decimal
#np.exp(2^e^2.5)
np.exp(2^e)
721.178003510984
exp(2^(e^2.5))
Inf
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport numpy as np
@pyimport sympy as sy
@pyimport decimal
# decimal.Decimal(np.exp(2^e^2.5))
decimal.Decimal(np.exp(e^(2*e)+e^2))
8.820166056085355e102
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport numpy as np
@pyimport sympy as sy
@pyimport scipy as sci
@pyimport matplotlib.pyplot as plt
@pyimport decimal
println(np.e^np.e^np.e)
3.8142791047601975e6
Wien Reduced Constant
ω=hc/kTλWien
NIST tells b=2.897 7729 x 10-3
(SI.PlanckConstantH*SI.SpeedOfLight)/(SI.Boltzmann * 1 * 2.8977729e-3)
4.9651126128756795
f(26)≈6(2π2a3)5, where 2π2a3 is the area of a 4-sphere of radius a
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport math
println(math.pi)
3.141592653589793
This notebook is a preview demo of IJulia: a Julia-language backend combined with the IPython interactive environment. This combination allows you to interact with the Julia language using IPython's powerful graphical notebook, which combines code, formatted text, math, and multimedia in a single document.
Basic mathematical expressions work like you expect:
i = e
exp(i*pi)
5113.984999751927
You can define variables, write loops, and execute arbitrary multiline code blocks. Here is an example of an alternating harmonic series ∑∞n=1(−1)nn from a Julia tutorial by Homer Reid:
Sum=0.0
for n = 1:2:10000
Sum += 1/n - 1/(n+1)
end
Sum # an expression on the last line (if it doesn't end with ";") is printed as "Out"
0.6930971830599458
Previous outputs can be referred to via Out[
n]
, following the IPython, for example Out[2]
for the result above. You can also use the shorthand _2
, or _
for the previous result, as in IPython. Like in Matlab, ans
can also be used to refer to the previous result, even if it was not printed (when the command ended with ;
).
For example, the harmonic series above should be converging (slowly) to ln2, and we can check this:
Out[26] - log(2)
-4.9997499999454575e-5
println(math.e^128-1)
3.8877084059945687e55
using PhysConsts
α.quantity
big((α.value)^-1)
big(log((α.value)^-1))
big(math.exp(699))
import Pkg; Pkg.status()
using PhysConsts.DATA
c.quantity
Speed of light in vacuum (c) Value = 2.99792458e8 m s^-1 Standard uncertainty = (exact) Relative standard uncertainty = (exact) Reference = CODATA 2019
a0.value
Bohr radius (a0) Value = 5.2917721067e-11 m Standard uncertainty = 1.2e-20 m Relative standard uncertainty = 2.3e-10 Reference = CODATA 2019
G.value
Newtonian constant of gravitation (Gg) Value = 6.67408e-11 m^3 kg^-1 s^-2 Standard uncertainty = 3.1e-15 m^3 kg^-1 s^-2 Relative standard uncertainty = 4.6e-5 Reference = CODATA 2019
g.quantity
Proton mass (m_p) Value = 1.672621898e-27 kg Standard uncertainty = 2.1e-35 kg Relative standard uncertainty = 1.3e-8 Reference = CODATA 2019
Like Matlab or Scipy + Numpy, Julia has lots of mathematical functions and linear algebra built in. For example, we can define a 500×500 random matrix R and form the positive-definite matrix R∗R:
R = rand(50,50)
R' * R
50×50 Array{Float64,2}: 14.8401 11.0159 11.0398 12.1371 12.9914 … 10.0666 10.2719 11.5613 11.0159 14.5508 10.6115 12.8797 13.3489 9.09651 11.5845 12.8904 11.0398 10.6115 14.664 12.1591 12.6995 11.3192 11.2392 12.7697 12.1371 12.8797 12.1591 18.0848 15.3832 10.9588 12.952 12.7643 12.9914 13.3489 12.6995 15.3832 18.8978 11.3417 13.766 13.7376 10.3582 12.1922 10.8784 12.5355 14.0756 … 9.75837 11.2291 12.7569 11.403 11.4861 12.1963 12.413 13.4622 11.4271 12.3969 12.9923 11.9348 11.3753 11.5956 13.6172 13.1759 10.7935 11.2115 12.2721 12.2734 12.3439 11.7942 14.8864 14.2113 11.7685 12.4404 12.9881 12.611 12.6692 12.6645 14.3057 15.212 12.4616 12.4764 13.661 12.46 10.9597 11.9727 12.0599 12.9428 … 11.0595 11.6294 13.2982 10.7607 12.462 11.4551 12.9311 14.3571 10.629 12.2371 14.6529 11.5589 12.314 12.3473 12.9978 13.8131 10.5067 12.1406 13.694 ⋮ ⋱ 11.3496 11.8048 11.2844 13.7931 13.7687 11.7626 12.937 12.6045 11.0356 12.8355 11.1324 13.4014 13.5355 9.83385 11.9688 12.6278 12.3802 14.0015 12.4311 13.7834 14.4353 … 12.0277 12.6047 14.6398 11.4193 12.8167 12.8603 12.5936 14.013 10.8855 12.3162 14.082 11.9126 11.3802 10.747 12.2219 12.3567 10.434 10.8304 12.1167 11.8378 12.2769 11.7172 14.8255 14.3169 11.4519 13.129 13.469 12.6271 12.8352 12.74 13.0265 15.1861 12.46 13.2996 15.0121 12.1822 13.1224 11.2227 13.8452 14.8181 … 9.94071 12.3738 13.4795 11.6848 10.9105 10.2393 11.041 12.3348 9.44363 9.89868 10.8772 10.0666 9.09651 11.3192 10.9588 11.3417 14.6154 10.5976 10.1157 10.2719 11.5845 11.2392 12.952 13.766 10.5976 16.6939 12.2948 11.5613 12.8904 12.7697 12.7643 13.7376 10.1157 12.2948 18.5953
(Notice that, by default, only a portion of a large matrix is shown. You didn't really want to read 5002=250,000 numbers, did you?)
Standard output from Julia is also captured and sent to the IJulia notebook as you'd expect:
println("Hello world!\n")
println(STDERR, "Testing, some unicode output on stderr...\n")
Hello world!
Testing, some unicode output on stderr...
IJulia even captures output from external C libraries (and notice how easy it is using Julia's ccall
intrinsic):
ccall(:printf, Cint, (Ptr{UInt8},), "Hello from C!!\n");
Hello from C!!
We can define functions, of course, and use them in later input cells:
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport math
@pyimport numpy as np
f(x) = np.power(np.log(2), (x / 4 ))
f (generic function with 1 method)
using Unitful
using Measurements
using Cosmology
using PyCall
@pyimport math
@pyimport numpy as np
println(f(2))
f([1.1,1.2,2,3,5,8])
0.8325546111576977
6-element Array{Float64,1}: 0.904122 0.895875 0.832555 0.75966 0.632458 0.480453
Notice that the input above both printed an scalar to STDOUT
and also returned a vector, the latter using Julia's ability to write polymorphic functions and built-in array operations.
On the other hand adding a string to a number is not defined (there is no +
method defined for those types, although we could easily add one), and attempting to do so will throw an exception:
Below we'll show off some plotting using the excellent Gadfly package. The plots are heavily inspired by this blog post.
✨✨✨✨✨
✨✨✨✨✨
using RDatasets
sleep = dataset("lme4","sleepstudy")
using Gadfly
plot(sleep, x = "Days", y = "Reaction", Geom.point)
plot(sleep, x = "Reaction", Geom.density, color = "Subject", Scale.x_continuous(minvalue= 0, maxvalue= 500))
plot(x = sleep[:Reaction], Geom.histogram(bincount = 30), Scale.x_continuous(minvalue = 200), color = sleep[:Days])
Like most programming languages, Julia has a built-in print(x)
function for outputting an object x
as text, and you can override the resulting text representation of a user-defined type by overloading Julia's show
function. The next version of Julia, however, will extend this to a more general mechanism to display arbitrary multimedia representations of objects, as defined by standard MIME types. More specifically, the Julia multimedia I/O API provides:
display(x)
function requests the richest available multimedia display of a Julia object x (with a text/plain
fallback).writemime
allows one to indicate arbitrary multimedia representations (keyed by standard MIME types) of user-defined types.Display
type. IJulia provides one such backend which, thanks to the IPython notebook, is capable of displaying HTML, LaTeX, SVG, PNG, and JPEG media formats.The last two points are critical, because they separate multimedia export (which is defined by functions associated with the originating Julia data) from multimedia display (defined by backends which know nothing about the source of the data).
Precisely these mechanism were used to create the inline PyPlot plots above. To start with, the simplest thing is to provide the MIME type of the data when you call display
, which allows you to pass "raw" data in the corresponding format:
display("text/html", """Hello <b>world</b> in <font color="red">HTML</font>!""")
However, it will be more common to attach this information to types, so that they display correctly automatically. For example, let's define a simple HTML
type in Julia that contains a string and automatically displays as HTML (given an HTML-capable backend such as IJulia):
type HTML
s::String
end
import Base.show
show(io::IO, MIME, x::HTML) = print(io, x.s)
show (generic function with 428 methods)
Here, show
is just a function that writes x
in the corresponding format (text/html
) to the I/O stream io
. The @MIME
is a bit of magic to allow Julia's multiple dispatch to automatically select the correct writemime
function for a given MIME type (here "text/html"
) and object type (here HTML
). We also needed an import
statement in order to add new methods to an existing function from another module.
This show
definition is all that we need to make any object of type HTML
display automatically as HTML text in IJulia:
x = HTML("<ul> <li> Hello from a bulleted list! </ul>")
display(x)
#println(x)