Monday, February 24, 2020

ASTs for Integrals

I've understood ASTs for simple expressions that only involve binary operators. I don't understand how ASTs deal with operators that have more than two arguments.
https://reference.wolfram.com/language/ref/TreeForm.html

https://demonstrations.wolfram.com/ExpressionTreesForIntegrals/

Sunday, February 23, 2020

Integration path for contributions

So far I've been hesitant on collaborations involving software in the Physics Derivation Graph. I didn't have a good path for integration of contributions, especially of complex features. I think I can provide both more details explanation of what would be helpful, as well as a clear integration path.

For example, in this post I provided a set of valid and invalid and ambiguous Latex examples. I did not provide details on how I would integrate a suggested solution written by a contributor.

Here are three specific aspects I would need for integration of contributed code:

  1. I will write doctests in Python. That way I can express the function as it would be integrated in the PDG project code
  2. The contributed Python script should run inside a Docker image. That way the dependencies are made explicit
  3. The "docker build" can assume to have Internet access, but the "docker run" process should assume no Internet connection

As an example from the above blog post, I can express the interface as a Python3 function
def is_expression_valid_latex(expr_latex: str) -> bool:
    """
    >>> is_expression_valid_latex("a = b")
    True
    >>> is_expression_valid_latex("a = b +")
    True
    >>> is_expression_valid_latex("\si a")
    False
    """

By using sys.stdin, we could expose that function to the container such that the following would be an acceptance test:
docker run -it --rm demo:latest python3 /opt/my_script.py "a = b"
True

Sunday, February 9, 2020

todo list for February 2020 (completed!)

Current status: I have an interactive web interface using Docker and Flask that I'm reasonably happy with. In this post I outline tasks that need to be done prior to wider exposure.

Functionality
  • list all 
    • operators
      • in which derivation is each used?
      • popularity: how many references are there to this operator?
    • symbols
      • in which derivation is each used?
      • popularity: how many references are there to this symbol?
    • derivations
      • popularity: include stats -- number of steps, number of inf rules, number of expressions
    • expressions
      • popularity: list which derivations use which expressions
    • inference rules
      • include number of inputs, outputs
      • popularity: which derivations use each inference rule?
  • show a complete derivation
  • edit 
    • an inference rule
      • how to address all the places that inference rule gets used?
    • a derivation
      • edit a step
        • how to address dangling steps?
    • an expression
      • where else is that expression used?

functionality
  • Latex to AST
    • suggest related expressions
  • Web interface
    • download pkl file
    • upload pkl file
    • export derivation PNG
    • export derivation to PDF
  • CAS integration
    • validate a single step of a derivation
Rendering
  • use d3.js instead of graphviz

visualize trace of flow
convert trace of flow to Selenium script
generate PDG website

host on DigitalOcean droplet
account management

Previous task list:
https://physicsderivationgraph.blogspot.com/2018/07/snapshot-of-milestones-for-physics.html
see also
https://physicsderivationgraph.blogspot.com/2017/06/not-getting-caught-in-details.html

type hinting and linting in the Docker image

See also
https://physicsderivationgraph.blogspot.com/2018/08/cleaning-up-code-using-pylint-and.html

Usually I start my Docker container using

$ python create_tmp_pkl.py ; docker build -t flask_ub .; docker run -it --rm --publish 5000:5000 flask_ub

However, if I need the command line to run mypy or flake8, I'll start a shell using

$ python create_tmp_pkl.py ; docker build -t flask_ub .; docker run -it --rm --entrypoint='' --publish 5000:5000 flask_ub /bin/bash

Then, in the container, I can run commands like

$ mypy compute.py
Success: no issues found in 1 source file
$ mypy --ignore-missing-imports controller.py 
Success: no issues found in 1 source file
see https://mypy.readthedocs.io/en/latest/running_mypy.html#ignore-missing-imports

and linting with

$ flake8 compute.py
compute.py:4:80: E501 line too long (89 > 79 characters)

and check doctest using

$ python3 -m doctest -v compute.py

Code complexity measurement:
$ python3 -m mccabe compute.py

Monday, February 3, 2020

example derivation steps for a CAS or theorem prover to validate

in order of increasing complexity, here are a set of derivation steps for a CAS or theorem prover to validate

start with "a = b"
add "2" to both sides
end with "a + 2 = b + 2"


start with "\sin x = f(x)"
multiply both sides by "2"
end with "2 \sin x = 2 f(x)"


start with "\sin x = f(x)"
substitute "2 y" for "x"
end with "\sin (2 y) = f(2 y)"