Tuesday, December 29, 2015

increasing flexibility of the Physics Derivation Graph

Currently the Physics Derivation Graph is designed as though there is a single authoritative user/developer (historically me). Having additional contributors is new, and contributors (including me) don't always provide valid content.

The following are ideas for a significant re-design of the Physics Derivation Graph

Independent Graphs per Derivation

Suppose every derivation was an independent graph. This is easier to debug and analyze. A set of these derivations could be then merged to analyze the full graph, but that shouldn't be a requirement. Merging derivation graphs incurs overhead of finding overlaps. The overlap would be identifying common expressions. For example,
A/B = C
is the same as
\frac{A}{B} = C
These should have the same unique index. This index (the Godel number) should be unique across all derivations. Although the graph of the derivation is independent of other derivations, the expression database will need to be shared globally.

Enable arbitrary formats

Currently all expressions are stored as Latex in a single CSV. I don't actually care about the representation (in this case Latex). Instead, I want a single numeric index (the Godel number) associated with arbitrary but equivalent representations. For example,
A/B = C
gets the same unique numeric index as
\frac{A}{B} = C
and a Sage representation is also acceptable:
A,B,C = var('A,B,C')
expr = A/B == C

To enable arbitrary formats, place each in a separate file with the naming convention
<unique numeric id>_<type>_<date>.<extension>
"Type" = {Latex, Mathematica, Sage, etc}
The date is to distinguish versions of the same expression, ie A/B = C versus \frac{A}{B} = C.
A single unique numeric index may have multiple files:
4924829_latex_20151228.tex
4924829_latex_20151229.tex
4924829_mathematica_20151228.nb

The reason to have separate files for each representation and for each expression is to increase flexibility. 
This adds to confusion when building the graph: which of the two equivalent latex representations should be used?
An additional source of work: checking that the various representations are consistent. An abstract syntax tree should be able to determine the equivalence of representations.

Implementing Inference Rules

Similarly for inference rule representations, there are Latex, Sage, and Mathematica implementations. Currently I have a single CSV for all the inference rules in Latex. Implement each inference rule in the relevant language:
multiplyBothSidesBy_latex_20151228.tex
multiplyBothSidesBy_sage_20151228.sagews
multiplyBothSidesBy_mathematica_20151228.nb

Again, there may be multiple ways to implement an inference rule. Which should be used when checking with the Computer Algebra System?
The inference rule representations might not be synchronized. This would be detectable if the derivation checks out using one CAS and not another. 

Friday, December 25, 2015

Sage as a candidate Computer Algebra System for the Physics Derivation Graph

I was excited to use Sage's online notebook interface to see whether it could handle the variety of expressions and inference rules in the Physics Derivation Graph.

I found a few unexpected behaviors. There's good support for many of the inference rules. When I tried to apply Sage to more advanced uses, either I don't understand the math well enough, or support in Sage doesn't exist.

Expectation value doesn't render Latex

Expectation values are used in the variance relation identity. I was impressed by the ability of Sage to use Expectation value from SymPy.
x=var('x')
from sympy.stats import E # expectation value
expr1=E((x-E(x))^2)==E(x^2)-(E(x))^2
expr2=E(x^2-2*x*E(x)+E(x)^2)==E(x^2)-(E(x))^2
print(bool(expr1.lhs() == expr2.lhs()))
expr3=E(x^2)-2*E(x)*E(x)+E(x)^2==E(x^2)-(E(x))^2
print(bool(expr3.lhs() == expr2.lhs()))
True
True

However, I wasn't able to display the content in LaTeX:
print(latex(expr3))
0 == 0

This is unfortunate but not a blocker

Real Part of Expression isn't what I was expecting

Sage doesn't produce the output I expected from .real_part() 

forget()
x=var('x')
assume(x,'real')
this=cos(x) + I*sin(x)
this.real_part()
cos(real_part(x))*cosh(imag_part(x)) - cos(real_part(x))*sinh(imag_part(x))

What I was looking for was that this.real_part() would return cos(x); similarly this.imag_part() should return sin(x).

Symbolic Levi-Civita not supported in Sage?

A Levi-Civita operator can be defined
levicivita = SymmetricGroup(3)
levicivita([1,2,3]).sign()
1

However, I can't use symbols as arguments
forget()
h,j,k=var('h,j,k')
assume(h,'integer')
assume(j,'integer')
assume(k,'integer')
levicivita = SymmetricGroup(3)
levicivita([j,k,m]).sign()
Invalid permutation vector: [h,j, k]

Del (aka Nabla) lacks symbolic support in Sage?

Symbolic cross-products work as desired
h,j,k=var('h,j,k')
m,n,p=var('m,n,p')
E = vector(SR, [h,j,k])
F = vector(SR, [m,n,p])
print(E.cross_product(F))
(-k*n + j*p, k*m - h*p, -j*m + h*n)

Other vector calculus operations appear to lack support for symbolic manipulation
https://en.wikipedia.org/wiki/Del#Gradient
https://en.wikipedia.org/wiki/Del#Divergence
https://en.wikipedia.org/wiki/Del#Curl

I don't quite understand what's being done with the following:
forget()
V = VectorSpace(SR,3)
h,j,k=var('h,j,k')
m,n,p=var('m,n,p')
E = vector(SR, [h,j,k])
print(E.curl([1,2,3]))
print(E.div([1,2,3]))
(0, -1, 1)
1


I want to be able to do Math with Latex as Input

Now that I'm using EquationMap for Latex input, the interface problem is effectively solved. Prior to that I developed the d3js-based web browser visualization of the Physics Derivation Graph. The remaining tasks are content entry and checking the graph using a Computer Algebra System (CAS).

The goal would be to enter a derivation (ie the quadratic equation) in Latex via EquationMap.com, then have Sage check the resulting graph for correctness.

Although I could do the content entry, I felt there wasn't a point to entering content in a format that isn't amenable to checking with a CAS. Ideally, I want a format that is easy to enter manually, and universally exportable (ie to Maple, Mathematica, Sage, SymPy).

I stumbled upon "Extracting Mathematical Semantics from LATEX Documents" which converts LaTeX math into Abstract Syntax Trees as the universal structure.

The idea of using Latex as the method of entry for mathematical calculations is a common objective, though no one has solved it.

Wednesday, December 16, 2015

relations between famous physics equations

Update 20190728: this content has been copied to this page

The Einstein and the Navier-Stokes Equations: Connecting the Two by Bredberg, Irene, Ph.D., HARVARD UNIVERSITY, 2012, 132 pages; 3513905
Abstract: This thesis establishes a precise mathematical connection between the Einstein equations of general relativity and the incompressible Navier-Stokes equation of fluid dynamics.
see also http://arxiv.org/abs/1101.2451

Relation between uncertainty and the quantum harmonic oscillator
http://hyperphysics.phy-astr.gsu.edu/hbase/quantum/hosc4.html
https://www.eng.fsu.edu/~dommelen/quantum/style_a/nt_uprl.html
http://hitoshi.berkeley.edu/221a/coherentstate.pdf

Schrodinger equation and quantum harmonic oscillator
http://homepage.univie.ac.at/reinhold.bertlmann/pdfs/T2_Skript_Ch_5.pdf

Schrodinger equation and wave equation
http://physics.stackexchange.com/questions/75363/how-is-the-schroedinger-equation-a-wave-equation
http://www.tcm.phy.cam.ac.uk/~bds10/aqp/handout_foundations.pdf

Friday, December 11, 2015

building content for the Physics Derivation Graph

Update 20190728: this content has been copied to this page.

I've decided to focus on building content for the Physics Derivation Graph. Since I don't think it's reasonable to enter all the mathematical physics content manually on my own, in this post I'll define some bounds.

There are expressions, domains, and notations that need to be included to demonstrate the comprehensive nature of the project and the capability of the framework.


ExpressionsDomainsNotation
Schrodinger's equationQuantumDirac/bra-ket

integration
Maxwell's equationsElectromagneticsdifferentiation
contravariant/covariantElectrodynamics
Navier StokesFluid Mechanics
mass-energy relation
Special Relativity
Thermodynamics
Uncertainty relationQuantum Mechanics
energy conservationclassical mechanics
string theory
wave equation
statistical mechanics
aerodynamics
simple harmonic oscillator

Other comprehensive lists of "things to know" in Physics






I'm stuck -- I don't know how to proceed

Current status:
I've written a translator that takes exported .tex files from EquationMap.com and converts the output to syntax for the Physics Derivation Graph. This effectively "solves" the interface problem for me, but not anyone else. That is, if someone else wanted to provide content for the PDG, they could use EquationMap, but then they'd need to submit the content to me. That clearly doesn't scale. However, I don't have a huge number of contributors to contend with.

Given that I have a user input interface, that leaves a few major tasks:
  • building content
  • checking content using a CAS
  • talk to potential users

I don't know how to deal with the CAS, as Mathematica is useful but not free and Sympy is free but not as useful.

I'm hesitant to build content, given that I can't do anything useful when viewing the graph of everything. Also, queries are not possible; current state is display only.

Wednesday, December 2, 2015

Using EquationMap for content entry

For the Physics Derivation Graph, I started out entering expressions manually into a plaintext file. I then graduated to manually entering expressions into a XML, then CSV file. Rendering was done in GraphViz and then d3js. In the past few months, I created an interactive terminal prompt for a more automated entry using Python, still rendering with d3js. I experimented with a web-based interface using Flask, but recognized I was slowly evolving towards the EquationMap interface for both display and entry.

Instead of re-inventing EquationMap, I realized I could use EquationMap as a front end. I would then export the graph .tex file and parse it into the Physics Derivation Graph. This benefits both EquationMap and the Physics Derivation Graph: EquationMap gets more traffic and more use cases, and PDG doesn't need to create a front-end.

Here's two different examples of using EquationMap with Inference Rules:
http://equationmap.com/#sSCdqOvUii
http://equationmap.com/#6NXnawarhb
I like the second instance better.

Here's an example of completing the square without inference rules
http://equationmap.com/#OZbmPo15Ha
and with inference rules
http://equationmap.com/#7xXumkNaTH
and generalized symbolically
http://equationmap.com/#xq8KZ0bnkT

I like the fact that I can easily refer to different iterations of the development

The ease of entering Latex and connecting nodes is very convenient!

The export function produces a combination of JSON and Latex.
I've written a parser for the .tex output from EquationMap

https://github.com/allofphysicsgraph/proofofconcept/tree/gh-pages/sandbox/equationMap_tex_parser

Monday, November 30, 2015

read-only static page (web 1.0) versus user-editable dynamic content (web 2.0)

I recently found a use case for user-editable dynamic web content, which is a significant shift from the previous use case of read-only static web pages. I've spent the day exploring how to enable user-editable dynamic content using Flask as a web framework.

I realized that d3js is a distractingly pretty interface for the static graph, but it doesn't move me towards EquationMap.com's intuitive interface. My Flask-based interface for dynamic content is driven by conventional form-based input. While this would accomplish the functionality, it's not as sexy as EquationMap.

There remains important work to be done with the static read-only content, namely a "zoom" interface which connects the concept map to specific derivations.


Update 20151207: a generated "overview" concept map showing the relations between derivations was created

SQLite on Mac and in Python

http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html

https://www.sqlite.org/datatype3.html

http://zetcode.com/db/sqlitepythontutorial/

Python
http://sebastianraschka.com/Articles/2014_sqlite_in_python_tutorial.html

import sqlite3

Mac

sqlite3

sqlite3 test.db

moving from local terminal interface with CSV to web interface with a database backend

The existing Physics Derivation Graph is centered on command-line input with PNG output. Recently I've been exploring use of d3js as a web frontend.

I'm considering moving the Physics Derivation Graph to something which supports a web frontend connected to a hosted database backend. No command-line interaction or installation required.

I've been using CSV to store the data because it is the most common format. That works fine as long as the PDG is local and command-line driven. Now I want to move to a website, (ie openshift --
https://openshift.redhat.com/app/console/application_type/ )
I've set up a Django cartridge

I realized I don't need to sketch a design for the PDG web interface. Instead, I can start with determining minimum functionality:
  • user login (don't want spammers writing to the database)
  • user view existing content
  • user add new content
I've used Flask previously, but I think the functionality I want is sufficiently complex that Flask wouldn't be enough.

I don't know whether I could continue to use the existing CSV as a backend storage. At this point I don't need scalability in terms of user latency or amount of data.


Vision: enable users of the PDG to interact with content in a web interface

Goal: use Django on Openshift to enable authentication, storage of content, and manipulating content

Path:

  1. Flask local instance
  2. Flask read values from database - CSV
  3. convert PDG CSV to local SQL database
  4. read from local SQL database
  5. write to local SQL database - https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sqlite3.1.html
  6. Flask read values from database - SQL
  7. Django local instance
  8. Django local instance read values from database
  9. Django local instance write values from database
  10. Django on Openshift - http://physicsderivationgraph.blogspot.com/2015/11/django-and-openshift.html
  11. Django on Openshift read values from database
  12. Django on Openshift write values from database
  13. Django on Openshift write values from database by authenticated user


Database choices

https://www.digitalocean.com/community/tutorials/sqlite-vs-mysql-vs-postgresql-a-comparison-of-relational-database-management-systems
https://www.digitalocean.com/community/tutorials/a-comparison-of-nosql-database-management-systems-and-models

CSV

SQLite

SQLite only supports a single writer at a time (meaning the execution of an individual transaction). SQLite locks the entire database when it needs a lock (either read or write) and only one writer can hold a write lock at a time.
SQLite 3.7.0 added a new journal mode called Write Ahead Locking that supports concurrent reading while writing.

Saturday, November 28, 2015

django and openshift

created a django cartridge on openshift
physicsderivationgraph-beanno.rhcloud.com

physicsderivationgraph-beanno.rhcloud.com/admin

On my computer I ran
sudo pip install django


python wsgi/myproject/manage.py migrate
python wsgi/myproject/manage.py runserver
python wsgi/myproject/manage.py syncdb
--> prompted to create a superuser

Saturday, October 10, 2015

timing Latex entry on Wacom tablet

Process description:
Using the site  https://webdemo.myscript.com/ we entered Latex equations, then pasted those into a text document

datepersontimetimed entrymethodnumber of expressionsderivationnotes
minutesseconds
20151005B8:40 PM1025wacom tablet13quadratic equationcopied Latex, pasted into text document; no errors
20151005M8:55 PM920wacom tablet13quadratic equationwith some errors to be corrected
20151005B9:05 PM544by hand13quadratic equationtyped directly into text document; no errors

Wednesday, October 7, 2015

heroku on mac

  502  sudo pip install virtualenv
  503  heroku
  505  cd ~/version_controlled/
  507  git clone https://github.com/heroku/python-getting-started.git
  508  cd python-getting-started/
  510  heroku create
  511  git push heroku master
  512  heroku ps:scale web=1
  514  heroku open


django on Ubuntu

https://www.howtoforge.com/tutorial/django-install-ubuntu-14.04/

https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-framework-on-ubuntu-14-04



cd ~
django-admin startproject mysite
cd mysite
sudo pip install -U django
python manage.py migrate
python manage.py runserver
firefox 127.0.0.1:8000

Monday, September 28, 2015

jupyter installation

Installation of Jupyter ( https://jupyter.readthedocs.org/en/latest/install.html ) and
https://github.com/ipython/ipyparallel

sudo pip install jupyter

sudo pip install ipyparallel

jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py 
       c.NotebookApp.server_extensions.append('ipyparallel.nbextension')

Sunday, September 27, 2015

autocomplete and variations


Suppose I'm given a list of words, {dog, cat, tv, boing}. When the user enters a new word, I want to let them know that there are exact or similar matches which already exist.

This will happen in a sequence of steps. From simplest to more complex,

phase 1: exact match the beginning of the word.
If I type "d", I am provided "dog"
If I type "o", I have no prompts
If I type "k", I have no prompts

phase 2: exact match anywhere in the word
If I type "d", I am provided "dog"
If I type "o", I am provided "dog" and "boing"
If I type "k", I have no prompts

phase 3: similar match anywhere in the word. Return exact matches and top X% of similar, ranked by similarity
If I type "d", I am provided "dog"
If I type "o", I am provided "dog" and "boing"
If I type "og", I am provided "dog" (exact) and "boing" (similar)
If I type "k", I have no prompts


http://stackoverflow.com/questions/7821661/how-to-code-autocompletion-in-python
https://pymotw.com/2/readline/

I'm not looking for tab completion. Instead, as I type I want the top n matches to automatically refresh


Saturday, September 19, 2015

Neo4j on Ubuntu installation notes

fresh install of Ubuntu 14.04 desktop amd64

sudo apt-get install default-jre


http://py2neo.org/2.0/

sudo pip install py2neo

property graph representation for expressions

There are many ways to represent an expression, ie a*x^2+b*x+c=d
Representing algebraic expressions is a good place to start, but for the Physics Derivation Graph I care about covering the full scope of Physics - calculus, derivatives, linear algebra, tensors, Dirac notation, Einstein notation, etc. See
https://github.com/allofphysicsgraph/proofofconcept/issues/7

Mathematica has a "tree form" for expressions which yields an Abstract Syntax Tree. I think the AST is incomplete, and would be more accurate as a property tree.

As an example, suppose we want to expand
TreeForm[  (a*x^2)+(b*x)+c=d ]

The nodes are a,b,c,d,x,2,=,+,^,*
The (directed) edges are

  • x-->power
  • 2-->power
  • a-->times
  • power-->times
  • times-->plus
  • b-->times
  • x-->times
  • times-->plus
  • c-->plus
  • plus-->equal
  • d-->equal

However, this graph representation is incomplete. First, the nodes are not all of the same type:
CREATE ( x:variable )
CREATE ( a:constant )
CREATE ( b:constant )

CREATE ( c:constant )
CREATE ( d:constant )
CREATE ( 2:integer )
CREATE ( =:relation )
CREATE ( ^:operator { name:"power" } )
CREATE ( +:operator { name:"plus" } )

Then edges are created, similar to above
CREATE ( x )-->( power )
CREATE ( 2 )-->( power )
CREATE ( a )-->( times )
...

However, the bulleted list of edges has collisions -- there are two instances of "times-->plus", but they are not supposed to be the same. Thus, the edges require unique IDs to deal with collisions.
Similarly, the nodes in the graph feature collisions. The expression refers to a single "x", but the TreeForm representation has multiple separate "x" nodes.

CREATE ( 5938:variable { symbol:"x" } )
CREATE ( 5782:constant { symbol:"a" } )
CREATE ( 4525:constant
 { symbol:"b" } )
CREATE ( :constant { symbol:"c" } )
CREATE ( :constant { symbol:"d" } )
CREATE ( :integer { symbol:"2" } )
CREATE ( :relation { symbol:"=" } )
CREATE ( :operator { name:"power", symbol:"^" } )
CREATE ( :operator { name:"plus", symbol:"+" } )

converting the Physics Derivation Graph from CSV to a property graph

I started the Physics Derivation Graph as a plain-text CSV set of files. I then converted the content to XML files. The current instance of the Physics Derivation Graph is back to a set of CSVs. CSV is attractive for its universal parsability and human readability.

Recently I learned about property graphs. Expanding on the node/edge idea of graphs, a property graph adds types and properties:

Nodes have
  • node id
  • node type
  • node property (key-value pair)
Edges have
  • edge id
  • edge type
  • edge property (key-value pair)
Using syntax from Neo4j for a simple example,

CREATE ( 149832:Expression { latex:"k=m j" } )
CREATE ( 119831:Expression { latex:"k/j=m" } )
CREATE ( 149832 )-[:DIVIDEBOTHSIDESBY { feed_1:"j" } ]->( 119831 )

Each expression is a node, and inference rules are directed edges. 

Complications in translating: 
  • within each derivation, each expression has a local ID for latex labels. 
  • each expression belongs to one or more derivations
  • each expression has a different representation in various CASs
  • Latex uses a double quote ("), so parsing may break. Reference pictures instead?
CREATE ( 149832:Expression { picture: "149832.png", sympy:"k=m*j", local_tex_id:"59589", in_derivations:["maxwell","funky"] } )
CREATE ( 119831:Expression { picture: "119831.png", sympy:"k/j=m", local_tex_id:"58584", in_derivations:"maxwell" } )
CREATE ( 149832 )-[:DIVIDEBOTHSIDESBY { feed_1_picture: "4958.png" } ]->( 119831 )

Although property graphs could have an equivalent amount of information compared to the current CSV format, the complexity is not less than the current CSV method. Also, only Neo4j supports this context. Thus, I'm not currently motivated to switch to property graph representation.

Sunday, September 13, 2015

linear storytelling constrains how one thinks

Textbooks are linear. Knowledge is not.

Describing content in graph form makes storytelling more complicated, but is a closer knowledge represenation

major fields for the PDG to cover

Update 20190728: this content has been copied to this page

Step 1: identify major fields in Physics
  • Electromagnetism
  • relativity
    • astrophysics
  • quantum mechanics
  • classical mechanics
    • thermodynamics
    • astrophysics
Step 2: identify top derivations associated with each area
  • EM: Maxwell's equations
  • Relativity: Lorentz (time dilation, length contraction)
  • Quantum: Schrodinger, Uncertainty
  • Classical: F=ma, conservation of energy and momentum

Step 3: 

switching between different Computer Algebra Systems

Although the PDG can be done in a CAS (ie Mathematica), it won't translate to other CASes without having associated Godel indices.

Symbols can be composed of other symbols. Example: $E$ and $\vec{E}$, $\partial$ and $\frac{\partial}{\partial t}$

Symbols can be operators, ie $\frac{\partial}{\partial t}$

Operators, ie $+$, can act on symbols


derivations versus identities

A derivation in physics is distinct from a mathematical identity

The PDG is hierarchical

Physics derivation graph is hierarchical:
  • Symbol, operators 
  • Expressions, inference rules 
  • Step 
  • Derivation
  • PDG
This can probably be used for visualization, determining storage format

The PDG is a directed hypergraph.

Streamlining the current PDG process

[output] = inference_rule(input)

[output_1, output_2] = inference_rule(input_1, input_2, feed)



  1. select an inference rule from list
  2. correct number of inputs, outputs, feeds is prompted for user
  3. inputs can be selected from all previous expressions
  4. database is populated with required information