Idris2Doc : Algebra.Solver.Ring.Expr

Algebra.Solver.Ring.Expr

(source)

Reexports

importpublic Data.List.Elem
importpublic Algebra.Ring

Definitions

pow : Ringa=>a->Nat->a
  Multiplies a value `n` times with itself. In case of `n`
being zero, this returns `1`.

Totality: total
Visibility: public export
dataExpr : (a : Type) ->Lista->Type
  Data type representing expressions in a commutative ring.

This is used to at compile time compare different forms of
the same expression and proof that they evaluate to
the same result.

An example:

```idris example
0 binom1 : {x,y : Bits8} -> (x + y) * (x + y) === x * x + 2 * x * y + y * y
binom1 = solve [x,y]
((x .+. y) * (x .+. y))
(x .*. x + 2 *. x *. y + y .*. y)
```

@ a the type used in the arithmetic expression
@ as list of variables which don't reduce at compile time

In the example above, `x` and `y` are variables, while `2`
is a literal known at compile time. To make working with
variables more convenient (the have to be wrapped in data
constructor `Var`, by using function `var` for instance),
additional operators for addition, multiplication, and
subtraction are provided.

In order to proof that two expressions evaluate to the
same results, the following steps are taken at compile
time:

1. Both expressions are converted to a normal form via
`Algebra.Solver.Ring.Sum.normalize`.
2. The normal forms are compared for being identical.
3. Since in `Algebra.Solver.Ring.Sum` there is a proof that
converting an expression to its normal form does not
affect the result when evaluating it, if the normal
forms are identical, the two expressions must evaluate
to the same result.

You can find several examples of making use of this
in `Data.Prim.Integer.Extra`.

Totality: total
Visibility: public export
Constructors:
Lit : a->Expraas
  A literal. This should be a value known at compile time
so that it reduces during normalization.
Var : (x : a) ->Elemxas->Expraas
  A variabl. This is is for values not known at compile
time. In order to compare and merge variables, we need an
`Elem x as` proof.
Neg : Expraas->Expraas
  Negates and expression.
Plus : Expraas->Expraas->Expraas
  Addition of two expressions.
Mult : Expraas->Expraas->Expraas
  Multiplication of two expressions.
Minus : Expraas->Expraas->Expraas
  Subtraction of two expressions.

Hints:
Nega=>Neg (Expraas)
Numa=>Num (Expraas)
var : (x : a) ->Elemxas=>Expraas
  Like `Var` but takes the `Elem x as` as an auto implicit
argument.

Totality: total
Visibility: public export
(.+.) : (x : a) -> (y : a) ->Elemxas=>Elemyas=>Expraas
  Addition of variables. This is an alias for
`var x + var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(+.) : Expraas-> (y : a) ->Elemyas=>Expraas
  Addition of variables. This is an alias for
`x + var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(.+) : (x : a) ->Expraas->Elemxas=>Expraas
  Addition of variables. This is an alias for
`var x + y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(.-.) : (x : a) -> (y : a) ->Elemxas=>Elemyas=>Expraas
  Subtraction of variables. This is an alias for
`var x - var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(-.) : Expraas-> (y : a) ->Elemyas=>Expraas
  Subtraction of variables. This is an alias for
`x - var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(.-) : (x : a) ->Expraas->Elemxas=>Expraas
  Subtraction of variables. This is an alias for
`var x - y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 8
(.*.) : (x : a) -> (y : a) ->Elemxas=>Elemyas=>Expraas
  Multiplication of variables. This is an alias for
`var x * var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 9
(*.) : Expraas-> (y : a) ->Elemyas=>Expraas
  Multiplication of variables. This is an alias for
`var x * y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 9
(.*) : (x : a) ->Expraas->Elemxas=>Expraas
  Multiplication of variables. This is an alias for
`x * var y`.

Totality: total
Visibility: public export
Fixity Declaration: infixl operator, level 9
eval : Ringa=>Expraas->a
  Evaluation of expressions. This keeps the exact
structure of the expression tree. For instance
`eval $ x .*. (y .+. z)` evaluates to `x * (y + z)`.

Totality: total
Visibility: public export
0ppow : {auto{conArg:1523} : Ringa} -> (m : Nat) -> (n : Nat) -> (x : a) ->powx (m+n) =powxm*powxn
  Proof that addition of exponents is equivalent to multiplcation
of the two terms.

Totality: total
Visibility: export