Hi all,
since long I have a domain which respresents the elements of a list as a
elements of the domain: FiniteSet(S, List S) and a special case OneToN =
{1,2,3,...,n}.
Two problems:
1. < of PartialOrder does not work properly. Note, that the order of the
elements in the finite set is the given order in the list.
2. OneToN: my attempts to make it as comfortable for the user by using
as underlying domain PositiveInteger gives an error message:
(14) -> enumerate()$Q10
>> System error:
The value
#:G2267
is not of type
LIST
Using Integer instead gives confusion for coercing from positive
integers to OneToN by missing retractIfCan, but could not be identified,
what the system means.
Is the list argument ln a problem?
If the problems can be fixed, the domains could go into the system.
-- Here is an example computation:
FS4 := FiniteSet(Integer, [2,1,3,4])
(1) FiniteSet(Integer,[2,1,3,4])
Type: Type
eFS4 := enumerate()$FS4
(2) [2, 1, 3, 4]
Type:
List(FiniteSet(Integer,[2,1,3,4]))
a : FS4 := first eFS4
(3) 2
Type:
FiniteSet(Integer,[2,1,3,4])
b : FS4 := second eFS4
(4) 1
Type:
FiniteSet(Integer,[2,1,3,4])
a <= b
(5) true
Type: Boolean
b <= a
(6) false
Type: Boolean
a < b
(7) false
Type: Boolean
"in the interpreter this is true, in accordance with the implementation
of <= in the domain!"
(8) "in the interpreter this is true, in accordance with the
implementation of <= in the domain!"
Type: String
(a <= b) and not(b <= a)
(9) true
Type: Boolean
Q10 := OneToN 10
(10) OneToN(10)
Type: Type
enumerate()$Q10
>> System error:
The value
#:G2456
is not of type
LIST
--
Mit freundlichen Grüßen
Johannes Grabmeier
Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Tel. +49-(0)-991-3615-141 (d), Fax: +49-(0)-32224-192688
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
)co finiteSet
FS4 := FiniteSet(Integer, [2,1,3,4])
eFS4 := enumerate()$FS4
a : FS4 := first eFS4
b : FS4 := second eFS4
a <= b
b <= a
a < b
"in the interpreter this is true, in accordance with the implementation of <=
in the domain!"
(a <= b) and not(b <= a)
Q10 := OneToN 10
enumerate()$Q10
)abbrev domain FINSET FiniteSet
)abbrev domain OTN OneToN
++ Authors: Johannes Grabmeier
++ Date Created: 2010-08-29
++ Date Last Updated:
++ 2018-06-29 JG
++ 2014-01-03 JG
++ Basic Operations:
++ Related Constructors: Finite, SetCategory
++ Also See:
++ AMS Classifications:
++ Keywords:
++ Reference:
++ Description: FiniteSet(S: SetCategory, lS: List S) represents the domain of
++ the elements of the given list. The ordering in lS defines the total order
++ on %. Note, that multiple entries in lS are removed.
FiniteSet(S: SetCategory, lS: List S): public == private where
public ==> Join(SetCategory, Finite, StepThrough,
OrderedFinite, RetractableFrom S, CoercibleFrom S)--, RetractableTo S)
private ==> S add
----------------------------------------------------------------------------
-- representation of the object:
----------------------------------------------------------------------------
Rep := S
rep(s : %) : Rep == s @ Rep
per(rp : Rep) : % == rp @ %
----------------------------------------------------------------------------
-- import of domains and packages
----------------------------------------------------------------------------
import OutputForm
----------------------------------------------------------------------------
-- local variables
----------------------------------------------------------------------------
lS := removeDuplicates! lS
n : NonNegativeInteger := #lS
----------------------------------------------------------------------------
-- local functions
----------------------------------------------------------------------------
-- global functions
----------------------------------------------------------------------------
-- from SetCategory
----------------------------------------------------------------------------
(a: % = b: %): Boolean == a =$Rep b
coerce(p: %): OutputForm == coerce(p)$Rep@OutputForm
----------------------------------------------------------------------------
-- from Finite:
----------------------------------------------------------------------------
size(): NonNegativeInteger == n
index(p: PositiveInteger): % ==
p > n => error "index: argument is too large!"
lS.p
lookup(x: %): PositiveInteger == position(x::Rep, lS) :: PositiveInteger
random(): % ==
zero? n => error "random: cannot create an element from an empty set!"
lS.(1+random(n)$Integer)
----------------------------------------------------------------------------
-- from StepThrough:
----------------------------------------------------------------------------
init(): % ==
zero? n => error "init: cannot create an element from an empty set!"
first lS
nextItem(x: %): Union(%, "failed") ==
p: PositiveInteger := lookup(x)
p::NonNegativeInteger = n => "failed"
index(1+p)
----------------------------------------------------------------------------
-- from OrderedFinite
----------------------------------------------------------------------------
-- we do not use a possible available order in S, but the ordering of lS!
-- from PartialOrder:
((x: %) <= (y: %)): Boolean ==
position(rep x, lS) <= position(rep y, lS)
-- from Comparable
smaller?(x: %, y: %): Boolean ==
position(rep x, lS) < position(rep y, lS)
----------------------------------------------------------------------------
-- from RetractableFrom S
----------------------------------------------------------------------------
coerce(x: %): S == rep x
retractIfCan(s: S): Union(%, "failed") ==
zero? position(s, lS)$List(S) => "failed"
per s
----------------------------------------------------------------------------
-- from CoercibleFrom S
----------------------------------------------------------------------------
coerce(s: S): % == --retractIfCan(x) :: %
zero? position(s, lS)$List(S) => error
"coerce: argument cannot be coerced to FiniteSet."
per s
)abbrev domain OTN OneToN
++ Authors: Johannes Grabmeier
++ Date Created: 2015-10-31
++ Date Last Updated:
++ 2018-06-29 JG
++ 2015-10-31 JG
++ Basic Operations:
++
++ Related Constructors: FiniteSet
++ Also See:
++ AMS Classifications:
++ Keywords:
++ Reference:
++ Description: OneToN(n: PositiveInteger) represents the domain of the natural
++ numbers from 1 to n as a finite set.
OneToN(n: PositiveInteger): public == private where
public ==> Join(SetCategory, Finite, StepThrough, OrderedFinite,
RetractableFrom PositiveInteger, CoercibleFrom PositiveInteger,
CoercibleFrom Integer)
ln ==> [i :: PositiveInteger for i in 1..n]$List(PositiveInteger)
private ==> FiniteSet(PositiveInteger, ln) add
----------------------------------------------------------------------------
-- global functions
----------------------------------------------------------------------------
-- from CoercibleFrom Integer
----------------------------------------------------------------------------
coerce(s: Integer): % ==
s > n => error "coerce: argument is greater than n."
n < 0 => error "coerce: argument is smaller than 1."
s :: PositiveInteger :: %
-- retractIfCan(p: Integer): Union(%, "failed") ==
-- p > n => "failed"
-- p :: %
-- retractIfCan(x: %): Union(PositiveInteger, "failed") ==
-- coerce(x)@Integer :: PositiveInteger