Skip to content

det, dot and cross of written-out matrices are computed at parse time, norm is not #2501

Open

Description

@Rafael-SOWNet

What happens

On 2.8.0, a function of written-out matrices is computed while parsing for det, dot and cross, but kept as a node for norm:

foreach (var s in new[] { "dot([a, b, c], [x, y, z])", "cross([a, b, c], [x, y, z])",
                          "cross([a, b, c], v)", "norm([a, b, c], 2)", "det([[a, b], [c, d]])" })
    Console.WriteLine($"{s} -> {(Entity)s}");
dot([a, b, c], [x, y, z])   -> a * x + b * y + c * z
cross([a, b, c], [x, y, z]) -> [b * z - c * y, c * x - a * z, a * y - b * x]
cross([a, b, c], v)         -> cross([a, b, c], v)
norm([a, b, c], 2)          -> norm([a, b, c], 2)
det([[a, b], [c, d]])       -> a * d - b * c

Each result round-trips (parsing ToString() again gives the same tree), so this is not a stringify bug. It is that the parser already did the computation.

#2455 kept this on purpose for dot and cross ("Vectors written out are still computed when parsed and print as before"), following det.

Why it matters

An expression written by a person and stored as text, for example a formula in a configuration file, cannot be parsed, edited and written back without losing its form. dot([AX, AY, AZ], [GX, GY, GZ]) comes back as a sum of products, and a cross as its three components. The numbers are the same; the readable form is gone. norm and cross with a name in it do not have this problem, so the same file ends up half expanded.

Proposal

One convention for functions of written-out matrices: keep det, dot and cross as nodes after parsing, as norm is, and compute them in InnerSimplify / Eval / compilation, as they already are once a name has been substituted. Then ToString() gives back what was written.

This changes what a parsed expression prints, so it is a breaking change. If that is not wanted for 2.x, an option (a setting, or a parse flag) to keep them as nodes would cover the use case too.

Related: #105, #2455.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions