createDR: A function to create objects of class 'DoubleRule'

Description Usage Arguments Details Value See Also Examples

Description

A function to generate objects of class DoubleRule.

Usage

1
createDR(a = NULL, fr = NULL, sr = NULL, ns = NULL)

Arguments

a

an index of DoubleRule stored on doubleRules list to be used while creating new object. If not specified, it will be generated automatically.

fr

(first rule) an object of class SingleRule. This rule will be applied to the first element of numeric sequence. If no firstRule argument is given , fr will be set to the identical function IdenSingleRule (fr=createSR("IdenSingleRule",n=0)) in 50 percent of cases and a randomly generated from a call to createSR in other cases. For details see example [3].

sr

(second rule) an object of class SingleRule, see fr for more details but with a 70 percent chance of the identical rule being chosen.

ns

(next single rule) an object of class SingleRule, see sr for more details.

Details

Parameters generated automatically have different probabilities assigned. Because too complicated rules are very difficult to solve, objects of class IdenSingleRule are generated with greater probability than other.

Value

A function returns an object that inherits from class DoubleRule. Returned object will be of class corresponding to applied DoubleRule.

See Also

SingleRule, DoubleRule, createSR, calculate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
##[1] DoubleRule object with random combination of rules

m<-createDR()
print(m)


##[2]DoubleRule object with only one argument specified

m<-createDR(sr=new("AddConstSingleRule",constantVal=3,previousRule=new("IdenSingleRule")))
#only secondRule argument is specyfied, all other arguments are generated automatically
print(m)


##[3]simple 'DoubleRule' object created manually (no nested rules)

b<-createSR(a1=1,n=0)#creating SingleRule that is identical function
# setting firstRule, secondRule and nextSingle are objects of class 'IdenSingleRule'
m<-createDR(a=1,fr=b,sr=b,ns=b) 
#altrnatively 'm<-createDR(a=1,fr=new("IdenSingleRule"),sr=new("IdenSingleRule"),ns=new("IdenSingleRule"))'
print(m)


##[4] Nesting many rules

b<-createSR(a1=2,cv1=1,n=2,2,14,3,6)
print(b) #two nested rules inside a 'SingleRule' b object 

#An object of class "AddConstSingleRule"
#Slot "constantVal":
#[1] 1

#Slot "previousRule":

#name: AddConstSingleRule, constant value:  14
#name: MultConstSingleRule, constant value:  6
#name: IdenSingleRule
#Slot ".S3Class":
#[1] "AddConstSingleRule" "SingleRule"


c<-createSR(a1=2,cv=45, n=3) # I want to nest three SingleRules 
#(no parameters for nested rules are specyfied - program generates them )
print(c)

#name: AddConstSingleRule, constant value:  45
#name: SubsConstSingleRule, constant value:  10 
# first nested rule (generated automatically - it will be different for every generation)
#name: AddConstSingleRule, constant value:  10 
# second nested rule (generated automatically- it will be different for every generation)
#name: MultConstSingleRule, constant value:  58 
# third nested rule (generated automatically- it will be different for every generation)


m<-createDR(a=1,fr=b,ns=c) #combining DoubleRule with SingleRules
print(m)

#AddDoubleRule
# FIRST RULE:
#name: DigSumSingleRule
#name: AddConstSingleRule, constant value:  14
#name: MultConstSingleRule, constant value:  6
# SECOND RULE:
#name: IdenSingleRule
# NEXT SINGLE:
#name: AddConstSingleRule, constant value:  45
#name: SubsConstSingleRule, constant value:  10
#name: AddConstSingleRule, constant value:  10
#name: MultConstSingleRule, constant value:  58


##note that UNLIMITED number of rules can be nested  !!! 

ruleR documentation built on May 2, 2019, 5:49 p.m.