Is there any way to use LaTex formulas in a programming language to make a real calculation

Viewed 206

We may write down the calculation formula of a distance measurement with the following LaTex string:

dist_{12} = \sqrt{ x^2 + y^2 }
dist_{13} = \sqrt{ z_{33}^2 + y^2 }

total = dist_{12} + dist_{13}

This looks good so far. If I really need to make a computer calculate these equations, then I need the following - eg. Python - code:

x = 1
y = 2
z_33 = 3
dist_12 = sqrt(x**2 + y**2)
dist_13 = sqrt(z_33**2 + y**2)
total = dist_12 + dist_13
print "Total distance is: ", total

As a result, I spent as twice as the effort actually needed.

However, if there was a way to use exact same LaTex formula (which may include integrals, derivatives, limits etc.) in a programming language (preferably Python, Javascript and Julia) we would re-use our efforts later in our real-world applications.

Is there any way to make this happen?

1 Answers
Related