Skip to content

Canonical form of function expressions maybe a bit too simplistic #22

@andreasabel

Description

@andreasabel

I think canonicalize is maybe a bit too weak; for instance, does not include commutativity:

> canonify :: FunExpr -> FunExpr
Addition
> canonify (e :+ Const 0) = canonify e
> canonify (Const 0 :+ e) = canonify e
> canonify (Const x :+ Const y) = Const (x + y)
> canonify (e1 :+ e2) = canonify e1 :+ canonify e2

One way to improve this is to have a notion of canonical form which is a sorted lists of sum terms each consisting of a sorted list of factors which are functions which can again be composed with sums of products of functions... (recursive).

Further, I noticed the overlap with simplify:

> simplify (f :+ g) = case (simplify f, simplify g) of
> (Const 0, g') -> g'
> (f', Const 0) -> f'
> (Const a, Const b) -> Const (a + b)
> (f', g') | f' == g' -> simplify (Const 2 :* f')
> (Const a :* f', g') | f' == g' -> simplify (Const (a + 1) :* f')
> (f', Const a :* g') | f' == g' -> simplify (Const (a + 1) :* f')
> (Const a :* f', Const b :* g') | f' == g'
> -> simplify (Const (a + b) :* f')
> (f', g') -> f' :+ g'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions