# http://mathling.com/type/polynomial/quotient  library module

http://mathling.com/type/polynomial/quotient

One polynomial divided by another. The polynomial may be use real-values or
complex-valued coefficients. We attempt to simplify down where possible.

May 2022
Status: Bleeding edge

### Imports

http://mathling.com/core/utilities
```import module namespace util="http://mathling.com/core/utilities"
at "../core/utilities.xqy"```
http://mathling.com/type/polynomial
```import module namespace poly="http://mathling.com/type/polynomial"
at "../types/polynomial.xqy"```
http://mathling.com/type/polynomial/complex
```import module namespace zpoly="http://mathling.com/type/polynomial/complex"
at "../types/cpolynomial.xqy"```
http://mathling.com/core/errors
```import module namespace errors="http://mathling.com/core/errors"
at "../core/errors.xqy"```

### Functions

#### ```Function: quotientdeclare function quotient(\$u as map(xs:string,item()*), \$v as map(xs:string,item()*)) as map(xs:string,item()*)```

##### Params
• u as map(xs:string,item()*)
• v as map(xs:string,item()*)
##### Returns
• map(xs:string,item()*)
```declare function this:quotient(
\$u as map(xs:string,item()*),
\$v as map(xs:string,item()*)
) as map(xs:string,item()*)
{
if (util:kind(\$v)="polynomial" and poly:is-constant(\$v)) then (
(: u / constant :)
\$u=>poly:times(1 div poly:as-real(\$v))
) else if (util:kind(\$v)="complex-polynomial" and zpoly:is-real(\$v)) then (
this:quotient(\$u, zpoly:as-real-polynomial(\$v))
) else if (util:kind(\$u)="complex-polynomial" and zpoly:is-real(\$u)) then (
this:quotient(zpoly:as-real-polynomial(\$u), \$v)
) else (
map {
"kind": "polynomial-quotient",
"u": \$u,
"v": \$v
}
)
}```

#### `Function: udeclare function u(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)`

##### Params
• poly as map(xs:string,item()*)
##### Returns
• map(xs:string,item()*)
```declare function this:u(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)
{
\$poly("u")
}```

#### `Function: vdeclare function v(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)`

##### Params
• poly as map(xs:string,item()*)
##### Returns
• map(xs:string,item()*)
```declare function this:v(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)
{
\$poly("v")
}```

### Original Source Code

```xquery version "3.1";
(:~
: One polynomial divided by another. The polynomial may be use real-values or
: complex-valued coefficients. We attempt to simplify down where possible.
:
: @since May 2022
: @custom:Status Bleeding edge
:)
module namespace this="http://mathling.com/type/polynomial/quotient";

import module namespace errors="http://mathling.com/core/errors"
at "../core/errors.xqy";
import module namespace util="http://mathling.com/core/utilities"
at "../core/utilities.xqy";
import module namespace poly="http://mathling.com/type/polynomial"
at "../types/polynomial.xqy";
import module namespace zpoly="http://mathling.com/type/polynomial/complex"
at "../types/cpolynomial.xqy";

declare namespace map="http://www.w3.org/2005/xpath-functions/map";
declare namespace math="http://www.w3.org/2005/xpath-functions/math";

(:
: quotient()
: One polynomial divided by another: e.g. (2x³-x²+3)/(4x²-5x+1)
: The polynomials may have either real or complex values.
:
: \$u: one polynomial
: \$v: another polynomial
:)
declare function this:quotient(
\$u as map(xs:string,item()*),
\$v as map(xs:string,item()*)
) as map(xs:string,item()*)
{
if (util:kind(\$v)="polynomial" and poly:is-constant(\$v)) then (
(: u / constant :)
\$u=>poly:times(1 div poly:as-real(\$v))
) else if (util:kind(\$v)="complex-polynomial" and zpoly:is-real(\$v)) then (
this:quotient(\$u, zpoly:as-real-polynomial(\$v))
) else if (util:kind(\$u)="complex-polynomial" and zpoly:is-real(\$u)) then (
this:quotient(zpoly:as-real-polynomial(\$u), \$v)
) else (
map {
"kind": "polynomial-quotient",
"u": \$u,
"v": \$v
}
)
};

declare function this:u(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)
{
\$poly("u")
};

declare function this:v(\$poly as map(xs:string,item()*)) as map(xs:string,item()*)
{
\$poly("v")
};```