ianhinder / Kranc

A Mathematica package for generating code for solving time dependent partial differential equations
http://kranccode.org
GNU General Public License v2.0
29 stars 10 forks source link

Add constant propagation stage #82

Open eschnett opened 12 years ago

eschnett commented 12 years ago

When code is auto-generated (e.g. in EinsteinExact), then there are often shorthands with special values, e.g. 0 or 1. Kranc should realise this and simplify expressions accordingly. For example:

a -> 0, b -> x + a

should be simplified to only

b -> x

ianhinder commented 12 years ago

We would have to carefully add logic to make sure that the resulting program is equivalent. Isn't this something that we can rely on the compiler to do?

eschnett commented 12 years ago

We can rely on the compiler in the same way as we can rely on its CSE and its vectorisation: in principle yes, but who knows.

It surely seems strange to define many variables with values such as 0, 1, or -1, and then multiply or add these later.

ianhinder commented 12 years ago

Indeed it is strange to do that. It is EinsteinExact which is behaving strangely, so maybe this logic should be in there? Or maybe we decide it is common to automatically generate the input to Kranc, and it is useful for Kranc to perform this sort of optimisation analysis. In any case, I don't think this is a high priority.