ianhinder / Kranc

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

Want Block[] expression in Kranc #79

Open eschnett opened 12 years ago

eschnett commented 12 years ago

All local variables (aka shorthands) in a calculation need to be declared ahead of time. It is not possible to have a RHS of an equation in a calculation that defines a temporary variable. Allowing this would turn the equations in a calculation from a list into a tree structure, which would simplify certain cases.

For example, one could then write

gu[ua,ub] -> MatrixInverse[g[la,lb]

where MatrixInverse is defined as

Block[{detg}, { detg -> MatrixDeterminant[g[la,lb]] }, 1/detg MatrixDeterminant[g[la,lb]] MatrixInverse[g[la,lb]]]

where the Block[] expression could easily introduce the temporary variable to simplify calculating the inverse. Of course, other applications exist as well; for example, temporaries that are only needed for parts of the BSSN equations would not be visible to the whole BSSN calculation.