Ascend FD-23R Manual do Utilizador

Consulte online ou descarregue Manual do Utilizador para não Ascend FD-23R. TOY(FD): Version 0.8 User Manual - Departamento de Lenguajes y Manual do Utilizador

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 81
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 0
TOY(FD): Version 0.8
User Manual
Antonio J. Fern´andez
1
Lenguajes y Ciencias de la Computaci´on
Campus Teatinos, University of alaga,
alaga 29071, Spain
e-mail: afdez@lcc.uma.es
http://www.lcc.uma.es/afdez/
Fax-number: +34-952-13 13 97
Teresa Hortal´a-Gonz´alez and Fernando aenz-P´erez
Sistemas Inform´aticos y Programaci´on,
Complutense University of Madrid
e-mails: {teresa,fernan}@sip.ucm.es
27th October 2003
1
This author has been partially supported by the projects TIC2001-2705-C03-02, and
TIC2002-04498-C05-02 funded by both the Spanish Ministry of Science and Technology and
FEDER.
Vista de página 0
1 2 3 4 5 6 ... 80 81

Resumo do Conteúdo

Página 1 - User Manual

TOY(FD): Version 0.8User ManualAntonio J. Fern´andez1Lenguajes y Ciencias de la Computaci´onCampus Teatinos, University of M´alaga,M´alaga 29071, Spai

Página 2

x LIST OF FIGURES

Página 3 - Acronyms

List of Tables1.1 Predefined Datatypes for FD Constraints . . . . . . . . . . . . . . . . . 91.2 The Predefined Set of FD Constraints . . . . . . . . .

Página 4

xii LIST OF TABLES

Página 5

Chapter 1The TOY(FD) System1.1 What is TOY(FD)?1.1.1 In Brief Words, TOY(FD) ...• ... is an implementation of a functional logic language with finite d

Página 6

2 CHAPTER 1. The TOY(FD) SystemIn TOY(FD), finite domain (FD) constraints are integrated as functions to makethem first-class citizens, which means that

Página 7 - Contents

1.2. The Current Implementation 31.2.5 DistributionThe current distribution is freely available as a compressed file toyfd.zip that containsthe files sh

Página 8

4 CHAPTER 1. The TOY(FD) System• primFunct.pl, primFunctGra.pl, primFunctIo.pl, primitivCod.pl,primitivCodClpr.pl, primitivCodGra.pl, primitivCodIo.pl

Página 9 - List of Figures

1.2. The Current Implementation 5• queens.toy The n-queens problem. Example in the FD.• scheduling.toy A task scheduling problem.• eq10.toy and eq20.t

Página 10

6 CHAPTER 1. The TOY(FD) System• Uncompress the file toyfd.zip in your working directory (e.g.,C:\SICSTUS382\bin\toyfd; observe that this path does not

Página 11 - List of Tables

1.3. Interpreter Commands 71.3.1 Calls to the Operating System (OS)Some commands calls directly to the operating system, as for example the following:

Página 13 - The TOY(FD) System

8 CHAPTER 1. The TOY(FD) SystemTo load the new definition choose ‘y’; however, if we have redefined a set of func-tions is useful to choose the option ‘

Página 14 - 1.2.3 Efficiency

1.4. FD Constraints 9• /cflpfdThis command is necessary to see important information about constraint solving.Below we show an example.TOY(FD)>doma

Página 15 - 1.2.5 Distribution

10 CHAPTER 1. The TOY(FD) SystemIn the following, we describe one by one all the FD constraints supported byTOY(FD). Table 1.2 shows the whole set of

Página 16

1.4. FD Constraints 11• Example in the TOY(FD)command level:Next goal returns true and constrains X and Y to have values in the range [1,10].TOY(FD)&g

Página 17 - 1.2.6 Runing TOY(FD)

12 CHAPTER 1. The TOY(FD) SystemTOY(FD)> domain [X,Y] 1 10, X #> YyesY in 1..9X in 2..10Elapsed time: 0 ms.(#∗)/2, (#+)/2, (#−)/2, (#/)/2• Type

Página 18 - 1.3 Interpreter Commands

1.4. FD Constraints 13• Type declaration:sum :: [int] → (int → int → bool) → int → bool• Definition: sum L Op V is true if the sum of all elements in L

Página 19

14 CHAPTER 1. The TOY(FD) System• Type declaration:assignment :: [int] → [int] → bool• Definition: ’assignment’ is a function applied over two lists of

Página 20 - + /load(< file >)

1.4. FD Constraints 15TOY(FD)> L == [X,1,2], domain [X] 1 2, count 1 L (#=) 2yesL == [ 1, 1, 2 ]X == 1Elapsed time: 0 ms.exactly/3• Type declaratio

Página 21 - 1.4 FD Constraints

16 CHAPTER 1. The TOY(FD) System• Type declaration:serialized :: [int] → [int] → boolserialized’ :: [int] → [int] → [newOptions] → boolcumulative :: [

Página 22 - 1.4.2 Membership Constraint

1.4. FD Constraints 17all different/1all different’/2all distinct/1all distinct’/2• Type declaration:all different :: [int] → boolall different’ :: [i

Página 23 - 1.4.3 Relational Constraints

AcronymsAcronym MeaningCFLP Constraint Functional Logic ProgrammingCFLP(FD) Constraint Functional Logic Programming over Finite DomainsCLP Constraint

Página 24 - 1.4.4 Arithmetic Constraints

18 CHAPTER 1. The TOY(FD) System• Type declaration:indomain :: int → bool• Definition: ‘indomain X’ assigns a value, from the minimum to the maximumin

Página 25

1.4. FD Constraints 193. The third group demands to find all the solutions (all) or only one solution tomaximize (resp. minimize) the domain of a varia

Página 26

20 CHAPTER 1. The TOY(FD) Systemfd statistics’ :: bool• Definition: fd statistics’ always returns true and displays a set of useful statistics(usually

Página 27

1.5. Some more constraints... 211.5 Some more constraints...TOY(FD) also provides a set of constraints (not shown in Table 1.2), called reflectionc

Página 28

22 CHAPTER 1. The TOY(FD) System

Página 29 - 1.4.6 Enumeration Constraints

Chapter 2TOY(FD) ProgrammingExamples2.1 Important Note about Programming with TOY(FD)In many cases, it can be useful to modularize a program and divid

Página 30

24 CHAPTER 2. TOY(FD) Programming Examples2.2 Introductory TOY(FD) Examples2.2.1 Send+More = MoneyBelow, a TOY(FD) program (included in the distributi

Página 31 - 1.4.7 Statistics Constraints

2.2. Introductory TOY(FD) Examples 25N queens in a chessboard in such a way that no queen attacks each other. Observe theuse of the directive include

Página 32

26 CHAPTER 2. TOY(FD) Programming ExamplesElapsed time: 0 ms.more solutions (y/n/d) [y]? ; %% Do not look for more solutionsTOY(FD)>2.2.3 A Cryptoa

Página 33

2.2. Introductory TOY(FD) Examples 27C #+ E #+ L #+ L #+ O #= 43,C #+ O #+ N #+ C #+ E #+ R #+ T #= 74,F #+ L #+ U #+ T #+ E #= 30,F #+ U #+ G #+ U #+

Página 35 - Examples

28 CHAPTER 2. TOY(FD) Programming Examplesconstrain L L 0 Cs, % essentialsum L (#=) N, % redundant #1scalar_product Cs L (#=) N, % redundant #2labelin

Página 36 - 2.2.2 N-queens

2.3. More Complex Examples 292.3 More Complex Examples2.3.1 A Scheduling ProblemHere, we consider the problem of scheduling tasks that require resourc

Página 37

30 CHAPTER 2. TOY(FD) Programming Examplesschedule :: [task] -> int -> int -> boolschedule TL Start End = true <== horizon TL Start End,sc

Página 38

2.3. More Complex Examples 31noOverlaps T1 T2 = true <== precedes T2 T1A task is modelled (via the type task) as a 5-tuple which holds its name, du

Página 39 - 2.2.4 Magic Sequences

32 CHAPTER 2. TOY(FD) Programming ExamplesS5 == 7S6 == 10Elapsed time: 0 ms.more solutions (y/n/d) [y]?yesS1 == 1S2 == 4S3 == 12S4 == 1S5 == 7S6 == 11

Página 40

2.3. More Complex Examples 33for specifying logical circuits, what are its weaknesses, and how they can effectively besolved with the integration of co

Página 41 - 2.3 More Complex Examples

34 CHAPTER 2. TOY(FD) Programming ExamplesFigure 2.2: Basic Modules.01sSymbolSum of products equivalenceFigure 2.3: Two-Input Multiplexer Circuit.TPY(

Página 42

2.3. More Complex Examples 35B==i0, P==0,B==i1, P==0,B==i2, P==0,B==not i0, P==1,. . .,B==not (not i0), P==2, . . ..Declaratively, it is fine; but our

Página 43

36 CHAPTER 2. TOY(FD) Programming Examplesreflect the current state of the circuit during its generation. By contrast with the firstexample, we do not “

Página 44

2.3. More Complex Examples 37because the add operation is monotonic. The mechanism which allows this “test”when “generating” is the set of propagators

Página 45

RemarkThis document is a user manual exclusively developed for TOY(FD) and, as a conse-quence, does not treat directly about TOY, although it provides

Página 46 - Figure 2.2: Basic Modules

38 CHAPTER 2. TOY(FD) Programming Examplesdomain [A] 0 maxArea,domain [P] 0 maxPower,domain [C] 0 maxCost,domain [D] 0 maxDelay,genCir (A,P,C,D) == (B

Página 47

2.3. More Complex Examples 39type behaviour = bool -> bool -> bool -> booltype circuit = (behaviour, state)type functionality = [bool]%%%%%%%

Página 48

40 CHAPTER 2. TOY(FD) Programming ExamplescircuitOutput4 = [true,true,true,true,true,true,true,false] % NANDcircuitOutput5 = [true,false,false,false,f

Página 49

2.3. More Complex Examples 41domain [C] ((fd_min C) + notGateCost) (fd_max C)genBeh (A, P, C, D) = andGate (genBeh (A, P, C, D)) (genBeh (A, P, C, D))

Página 50

42 CHAPTER 2. TOY(FD) Programming ExamplesgenCir’ (A, P, C, D) = (i0, (A, P, C, D))genCir’ (A, P, C, D) = (i1, (A, P, C, D))genCir’ (A, P, C, D) = (i2

Página 51

2.3. More Complex Examples 43(Behaviour false false true) == Outcome1,(Behaviour false true false) == Outcome2,(Behaviour false true true) == Outcome3

Página 52

44 CHAPTER 2. TOY(FD) Programming ExamplesyesF == [ true, false, false, false, false, false, false, false ]CIRCUIT == ((notGate (orGate i0 (orGate i2

Página 53

2.4. Colour Problem 451234567891011121314151617 1819202122232425Figure 2.4: puzzleall_different [I6, I7],all_different [I6, I13],all_different [I6, I1

Página 54

46 CHAPTER 2. TOY(FD) Programming Examplesproblem:TOY(FD)> color LyesL == [ 1, 2, 3, 2, 3, 1, 3, 1, 2, 1, 3, 1, 2, 3, 2, 1,2, 3, 1, 3, 2, 1, 2, 3,

Página 55

2.5. Lazy Constraint Programs 47where the operation α/2 is defined as follows:[] α V = V : []U α [] = U : [][X|Xs] α [Y |Y s] = X : (Xs α Y s) ⇐⇒ X ==

Página 57

48 CHAPTER 2. TOY(FD) Programming Examples2.5.2 Lazy Magic SequencesNow we present a lazy solution (included in the distribution in the directory Exam

Página 58 - 2.5 Lazy Constraint Programs

2.5. Lazy Constraint Programs 49%%%%%%%%%% NOW WE GENERATE AN INFINITE LIST OF LISTS%%%%%%%%%% CONTAINING THE MAGIC SEQUENCES FROM A NUMBER N%%%%%%%%%

Página 59

50 CHAPTER 2. TOY(FD) Programming ExamplesThis simple example gives an idea of the nice features of TOY(FD) that combinesFD constraint solving, manage

Página 60 - 2.5.2 Lazy Magic Sequences

BibliographyBeldiceanu, N. (2000). Global constraints as graph properties on a structured networkof elementary constraints of the same type. In Dechte

Página 61

52 BIBLIOGRAPHYMarriot, K. and Stuckey, P. J. (1998). Programming with constraints. The MIT Press,Cambridge, Massachusetts.R´egin, J.-C. (1994). A filt

Página 62

Appendix ATOY(FD) GrammarFD constraints are declared as classical TOY functions and, as a consequence, thegrammar of TOY(FD)is equivalent to the gramm

Página 63 - Bibliography

54 CHAPTER A. TOY(FD) GrammarThe identifiers let, where, in and subtype correspond to non-implemented con-structions in the current version, but they a

Página 64

55Also, it is allowed to use two different kinds of comments inserted in the programtext:• Comments in one sentence (i.e., in one line in a text) start

Página 65 - TOY(FD) Grammar

56 CHAPTER A. TOY(FD) GrammarBASIC GRAMMARprogram −→ ( { topdecl } )+top-level declarationstopdecl −→data typeLhs = constrs datatype declaration| type

Página 66

57FUNCTION RULES AND CLAUSESfunrule −→ ruleLhs = exp [conditionrule] function ruleruleLhs −→ function rule left-hand sidepat funop pat rule for infix o

Página 67

ContentsAcronyms iiiRemark v1 The TOY(FD) System 11.1 What is TOY(FD)? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.1 In Brief Words

Página 68

58 CHAPTER A. TOY(FD) Grammar| con constructor name| integer integer number| real real number| ( ) unit| exp parenthesised expression| ( atomic op ) l

Página 69

Appendix BDeclaration of Primitives (filebasic.toy)/*** THIS FILE DEFINES THE PREDEFINED FUNCTIONS AND TYPES OF THE SYSTEM ***/data bool = true | false

Página 70

60 CHAPTER B. Declaration of Primitives (file basic.toy):: real -> real -> real% integer powersprimitive (^) :: real -> int -> real% binary

Página 71 - Appendix B

Appendix CCommon Functions (filemisc.toy)% FILE: misc.toy% A collection of useful functions and type declarations,% many of them taken from Gofer’s pre

Página 72

62 CHAPTER C. Common Functions (file misc.toy)false ‘or‘ false = false% Sequential andfalse /\ _ = falsetrue /\ X = X% Sequential ortrue \/ X = truefal

Página 73 - Common Functions (file

63hnf X = X <== X /= _% (strict F) is the restriction of F to finite, totally defined arguments.% Operationally, it forces the evaluation to nf of

Página 74

64 CHAPTER C. Common Functions (file misc.toy)%% Fold primitives: The foldl and scanl functions, variants foldl1 and%% scanl1 for non-empty lists, and

Página 75

65scanr F Q0 [X|Xs] = auxForScanr F X (scanr F Q0 Xs)%whereauxForScanr F X Ys = [F X (head Ys)|Ys]scanr1 :: (A -> A -> A) -> [A] -> [A]sca

Página 76

66 CHAPTER C. Common Functions (file misc.toy)takeWhile P [X|Xs] = if P X then [X| takeWhile P Xs] else []takeUntil :: (A -> bool) -> [A] -> [

Página 77

67%% Standard combinators: %% %% %% %% %% %% %% %% %% %% %% %% %% %%const :: A -> B -> Aconst K X = Kid :: A -> Aid X = X% non-deterministic

Página 78

viii CONTENTS2 TOY(FD) Programming Examples 232.1 Important Note about Programming with TOY(FD) . . . . . . . . . . . 232.2 Introductory TOY(FD) Examp

Página 79

68 CHAPTER C. Common Functions (file misc.toy)lcm X Y = if ((X==0) \/ (Y == 0)) then 0else abs ((X ‘div‘ (gcd X Y)) * Y)%%%% Standard list processing f

Página 80

69transpose = foldrauxForTranspose[]%whereauxForTranspose Xs Xss = zipWith (:) Xs (Xss ++ repeat [])%% (\\) is used to remove the first occurrence of

Página 81

List of Figures2.1 Precedence Graph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292.2 Basic Modules. . . . . . . . . . . . . . . . .

Comentários a estes Manuais

Sem comentários