Sunday, June 28, 2020

connective derivations

There are multiple derivations associated with waveguides. However, I don't see derivations focused on waveguides as being connective to any other topic.

Similarly the Navier-Stokes equation for fluids doesn't seem to relate any topics (though I have less experience with this compared to waveguides).
  • There is probably a "connective derivation" that relates Quantum Mechanics to Statistical mechanics, probably involving the definition of entropy. 
  • Another connection is that Statistical mechanics is related to thermodynamics (again, not clear what derivation would show this). 
  • classical mechanics and astrophysics are based on the same concepts
  • There should be a relation between (classical motion) and (relativity) since the difference is the assumptions about slow versus fast objects.
  • Wave-particle duality present in optics relates to atomic theory
  • the orbit of Mercury relates astrophysics to relativity
  • thermodynamics connects to quantum mechanics in the black-body radiation experiment
  • quantum field theory relates relativity to quantum

I don't have insight on how electrodynamics relates to quantum mechanics or how electrodynamics relates to classical mechanics. 

Wednesday, June 24, 2020

parsing latex using Sympy - what works and what does not


# python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
>>> from sympy.parsing.latex import parse_latex
>>> parse_latex('a = b')
Eq(a, b)
>>> parse_latex('\\frac{\\partial}{\\partial t} \\psi( r,t)')
Derivative(\psi(r, t), t)
>>> parse_latex('\\int_{a}^{b} f(x) dx')
Integral(f(x), (x, a, b))

To can check that the Sympy expression gets converted to Latex correctly:
>>> from sympy import *
>>> sympy.latex(parse_latex('\\int_{a}^{b} f(x) dx'))


vectors do not get parsed correctly
>>> parse_latex('\\vec{a} = \\vec{g} t')
see https://docs.sympy.org/latest/modules/vector/index.html
Similarly,
>>> parse_latex('\\hat{x} + \\hat{y}')
The "hat" is typically used for unit vectors. These are referenced in
https://docs.sympy.org/latest/modules/physics/vector/vectors.html
but I don't see a Sympy-specific notation for unit vectors.

bra-ket notation does not raise an exception but is not interpreted correctly
>>> parse_latex('\\langle \\alpha | = 1')
see https://docs.sympy.org/latest/modules/physics/quantum/state.html

The following triggers an exception
>>> parse_latex('\\mathcal{H} = 5')
For a discussion of that symbol in Latex, see https://tex.stackexchange.com/questions/429749/two-different-mathcalh
https://docs.sympy.org/latest/modules/physics/quantum/hilbert.html

Complex conjugation notation is not interpreted correctly:
>>> parse_latex('Z Z^* = 5')

Saturday, June 20, 2020

latex to sympy and sympy to latex


From Latex to Sympy:
$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy
>>> from sympy.parsing.latex import parse_latex
>>> sympy.srepr(parse_latex('\\frac{p}{\\hbar} = k'))
"Equality(Mul(Pow(Symbol('hbar'), Integer(-1)), Symbol('p')), Symbol('k'))"

A more complicated example

>>> sympy.srepr(parse_latex('\\frac{\\partial}{\\partial t} \\psi( r,t)'))
"Derivative(Function('psi')(Symbol('r'), Symbol('t')), Tuple(Symbol('t'), Integer(1)))"


Check that Sympy-to-Latex produces the same:
>>> sympy.latex(sympy.Derivative(sympy.Function('psi')(sympy.Symbol('r'), sympy.Symbol('t')), sympy.Tuple(sympy.Symbol('t'), sympy.Integer(1))))
'\\frac{\\partial}{\\partial t} \\psi{\\left(r,t \\right)}'

docker - no space left on device

When Docker runs out of space, the error messages can be misleading.

docker images | grep "<none>                              <none>" | tr -s " " | cut -d' ' -f3 | xargs docker rmi -f

docker image prune -f

docker rm $(docker ps -q -f 'status=exited')

docker rmi $(docker images -q -f "dangling=true")

docker system prune


https://domm.plix.at/perl/2020_06_docker_prune_volumes_by_label.html
https://news.ycombinator.com/item?id=23571953

Saturday, June 6, 2020

the role of a lexer and parser

A lexer detects patterns in a sequence of characters (the input string). The patterns are specified as regex in a grammar file (e.g., ANTLR's .g4 file).

The lexer produces a stream of tokens consumed by the parser.

A parser assembles an AST
The nodes of the AST are tokens.
The parser then has a set of rules which are used to apply actions.
For example (in the context of the Physics Derivation Graph), the rules produce Sympy expressions.



For the Physics Derivation Graph, the lexer will be consuming math latex.

The math latex strings are expected to be agnostic to which Physics domain the .tex file is from.
In contrast, the parser rules may be domain-specific.

a grand vision for bulk .tex analysis

Current plan for bulk .tex analysis and math extraction
  1. characterization and counting of .tex in arxiv
  2. anomaly detection, trie data structures of .tex in arxiv
  3. clean up latex to remove formatting indications (this can be handled in the grammar)
  4. The minimal regex is based on a threshold from the trie data structure.
    Work is in progress to automate regex generation.
  5. use the regex to lex latex character stream into ASTs.
  6. parse ASTs for math syntax (e.g., into Sympy)
  7. check dimensionality of expressions using Sympy
  8. use inference rules to create steps that relate math expressions
  9. use Sympy to validate inference rule application