Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Software
CoPaR
Commits
44672224
Commit
44672224
authored
Nov 02, 2020
by
Bastian Kauschke
Browse files
fix AbsorbingPolynomial innerFunctors
parent
0dd884dc
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
examples/ui-tests/tbeg-dist-paper-mvce
0 → 100644
View file @
44672224
(R^X)^{a,b}
s1: {a: {s1: 0.3}, b: {s1: 0.8}}
\ No newline at end of file
examples/ui-tests/tbeg-dist-paper-mvce.mini
0 → 100644
View file @
44672224
R^(X)^{a, b}
s0_s1: {a: {s0_s1: 0.3}, b: {s0_s1: 0.8}}
\ No newline at end of file
src/Copar/Functors/AbsorbingPolynomial.hs
View file @
44672224
...
...
@@ -59,7 +59,7 @@ import Copar.Parser.Types
import
qualified
Data.Vector.Utils
as
V
import
Data.Primitive.SmallArray
import
Data.Function
(
on
)
import
Data.Function
(
on
)
data
Inner
f
a
=
Direct
a
|
Absorbed
(
f
a
)
...
...
@@ -268,7 +268,7 @@ instance MinimizationInterface f => MinimizationInterface (AbsorbingPolynomial f
updateInner
((
PolyLabel
i
Nothing
)
:|
ll
)
=
(
PolyLabel
i
Nothing
)
:
ll
innerLbls
=
map
$
\
(
PolyLabel
_
lbl
)
->
fromJust
lbl
innerFunctors
=
V
.
fromList
$
toList
poly
innerFunctors
=
computeInnerFunctors
poly
innerFunctor
::
Int
->
f
()
innerFunctor
i
=
case
innerFunctors
V
.!
i
of
...
...
@@ -297,21 +297,19 @@ parseInner (Direct inner) = do
instance
(
PrintMorphism
f
,
Show1
f
,
Show
(
Label
f
),
Show
(
F1
f
))
=>
PrintMorphism
(
AbsorbingPolynomial
f
)
where
-- TODO: This currently has a runtime of O(n^2), which can still be improved
printMorphismPoint
(
AbsorbingPolynomial
poly
)
f1
edges
=
let
innerFunctors
=
toList
poly
f1'
=
Poly
.
PolyF1
(
polyF1Summand
f1
)
(
foldr
(
\
v
total
->
((
maybe
0
(
const
1
))
v
)
+
total
)
0
(
polyF1Variables
f1
))
(
polyF1Constants
f1
)
let
f1'
=
Poly
.
PolyF1
(
polyF1Summand
f1
)
(
foldr
(
\
v
total
->
((
maybe
0
(
const
1
))
v
)
+
total
)
0
(
polyF1Variables
f1
))
(
polyF1Constants
f1
)
in
printMorphismPoint
(
()
<$
poly
)
f1'
(
f
map
convertFunctor
(
zip
i
nnerFunctors
[
0
..
]
))
(
V
.
toList
$
V
.
i
map
convertFunctor
(
computeI
nnerFunctors
poly
))
where
convertFunctor
::
(
Inner
f
()
,
Int
)
->
(
Label
Polynomial
,
Build
.
Builder
)
convertFunctor
(
Direct
()
,
v
)
=
(
v
,
snd
$
fromJust
(
find
(
\
(
PolyLabel
n
_
,
_
)
->
n
==
v
)
(
edges
)))
convertFunctor
(
Absorbed
inner
,
v
)
=
(
v
,
convertFunctor
::
Int
->
Inner
f
()
->
(
Label
Polynomial
,
Build
.
Builder
)
convertFunctor
v
(
Direct
()
)
=
(
v
,
snd
$
fromJust
(
find
(
\
(
PolyLabel
n
_
,
_
)
->
n
==
v
)
(
edges
)))
convertFunctor
v
(
Absorbed
inner
)
=
(
v
,
printMorphismPoint
inner
(
fromJust
$
indexSmallArray
(
polyF1Variables
f1
)
v
)
...
...
src/Copar/Functors/Polynomial.hs
View file @
44672224
...
...
@@ -9,7 +9,8 @@
-- | Polynomial functor with co-products, products, exponentials and constants
module
Copar.Functors.Polynomial
(
printPolynomial
(
computeInnerFunctors
,
printPolynomial
-- * Types exported for easier testing
,
Polynomial
(
..
)
,
Sum
(
..
)
...
...
@@ -97,6 +98,18 @@ $(deriveEq1 ''Polynomial)
$
(
deriveShow1
''Factor
)
$
(
deriveShow1
''Polynomial
)
computeInnerFunctors
::
Polynomial
a
->
V
.
Vector
a
computeInnerFunctors
(
Polynomial
(
Sum
(
prods
)))
=
foldMap
products
prods
where
products
(
Product
(
fact
))
=
foldMap
factors
fact
factors
(
Const
_
)
=
V
.
empty
factors
(
Identity
x
)
=
V
.
singleton
x
factors
(
Exponential
a
kind
)
=
V
.
replicate
(
expSize
kind
)
a
expSize
(
FiniteNatExp
n
)
=
n
expSize
(
ExplicitExp
exp
)
=
V
.
length
exp
printPolynomial
::
PrintConfig
->
Polynomial
Build
.
Builder
->
Build
.
Builder
printPolynomial
_
(
Polynomial
(
Sum
(
prods
)))
=
fold
(
NonEmpty
.
intersperse
" + "
(
fmap
printProduct
prods
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment