List the variables, parameters, constants, or atoms in a canonical expression.

variables(object)

parameters(object)

constants(object)

atoms(object)

object

A Leaf object.

## Value

A list of Variable, Parameter, Constant, or Atom objects.

## Examples

set.seed(67)
m <- 50
n <- 10
beta <- Variable(n)
y <- matrix(rnorm(m), nrow = m)
X <- matrix(rnorm(m*n), nrow = m, ncol = n)
lambda <- Parameter()

expr <- sum_squares(y - X %*% beta) + lambda*p_norm(beta, 1)
variables(expr)
#> [[1]]
#> [1] "Variable((10, 1), nonneg=FALSE, nonpos=FALSE, pos=FALSE, neg=FALSE, complex=FALSE, imag=FALSE, symmetric=FALSE, diag=FALSE, PSD=FALSE, NSD=FALSE, hermitian=FALSE, boolean=FALSE, integer=FALSE, )"
#>
parameters(expr)
#> [[1]]
#> Parameter(1, 1, nonneg=FALSE, nonpos=FALSE, pos=FALSE, neg=FALSE, complex=FALSE, imag=FALSE, symmetric=FALSE, diag=FALSE, PSD=FALSE, NSD=FALSE, hermitian=FALSE, boolean=FALSE, integer=FALSE, )
constants(expr)
#> [[1]]
#> Constant(CONSTANT, UNKNOWN, (50,10))
#> [[2]]
#> Constant(CONSTANT, UNKNOWN, (50,1))
#> [[3]]
#> Constant(CONSTANT, NONNEGATIVE, (1,1))
lapply(constants(expr), function(c) { value(c) })
#> [[1]]
#>              [,1]         [,2]         [,3]         [,4]        [,5]
#>  [1,]  0.63195736 -1.964895961  0.860008617 -0.842977656 -0.08861545
#>  [2,] -0.01203859 -0.137961474 -0.376804397  0.190060084 -0.68719707
#>  [3,]  0.88500272  1.397790875  0.049243816 -0.339555896 -1.87828705
#>  [4,] -0.19060391  1.344388759 -1.268777649 -0.875092410  0.90813144
#>  [5,]  0.31261464  0.184950624 -0.515801663  0.619409187  0.86796790
#>  [6,]  0.90503314 -0.109509276 -1.293598044  0.352984998  0.10595070
#>  [7,] -0.24450151  0.929821100 -1.165262967 -1.101171368  0.83778367
#>  [8,] -0.71798851 -1.896505146  0.812660428 -0.071818892 -0.28101686
#>  [9,] -1.50757654  0.647895086  2.182262426  1.441539349 -1.17964455
#> [10,]  0.24296954 -0.846855938  1.892583969 -3.031495648 -0.16642823
#> [11,]  0.50049536  0.912853796  0.317925505  0.640295418  0.02913952
#> [12,]  0.08669051 -1.231958876  0.939298109 -0.920240227 -1.49529864
#> [13,]  1.24622426  0.105592682 -0.720718942  1.916003549  3.49199508
#> [14,] -0.59614003  0.569142523 -0.742818285  1.482915638  0.26638570
#> [15,] -1.35991692  1.121283648 -0.383450750  0.613860988 -0.18741880
#> [16,] -0.70283034 -0.283219818 -2.029903891  0.266503894  0.79059621
#> [17,]  0.20780195 -0.687275691  1.499485948 -0.042250467 -0.05817170
#> [18,] -0.10490873 -0.058686385 -0.397508230  0.105058921 -0.44600585
#> [19,]  0.51016858  0.213021774  1.333485315  0.274450375 -0.46266106
#> [20,]  0.06842445  0.272568205 -0.703955035 -1.067679753 -1.88889261
#> [21,] -0.85826390 -0.826390215  0.605329294  0.411178931 -0.77439402
#> [22,]  1.45752339  0.457980792 -0.233614722  0.163015496 -0.60589575
#> [23,]  0.73888648  0.057879203 -1.382481185  0.705607617  0.78323641
#> [24,] -0.45180288  0.086504819  0.349358183 -0.753352940  0.63155311
#> [25,]  0.02189908 -1.149776655 -1.712506714  1.115389438 -1.05073368
#> [26,]  0.60465417  0.022147565 -0.114591501  0.201688095  1.68624022
#> [27,] -2.09079746  0.712116214  0.283016906  0.394310039 -0.60809607
#> [28,]  1.06127049  1.055137432 -0.643212071  0.204962106  0.99244467
#> [29,]  0.11114735 -0.310614342  0.007697771  0.904621373 -0.09620114
#> [30,] -1.02224724  1.096577160 -1.074293677 -0.291700200 -0.65087658
#> [31,] -1.36258364  0.476182767  0.716691864  0.451339231  0.06194850
#> [32,] -0.97172574  1.757395910 -0.811570284 -0.350781311 -1.88964973
#> [33,] -1.48613027 -1.171063387 -0.143626348  0.400029978  0.44229754
#> [34,]  0.44606733  2.263486941  1.521930221 -0.782472054 -0.12852919
#> [35,] -1.23474770 -1.268876731 -0.576666294  0.127052078  0.46550417
#> [36,] -2.27200877  0.002342348 -0.098376181 -0.446530859 -0.15540930
#> [37,]  1.57494757  0.443740245  0.387082901 -0.300527347  0.28642425
#> [38,]  0.46446258 -0.609090255 -1.939251860 -0.125543386  0.86317131
#> [39,] -0.51759038 -1.217686325  0.013450320  0.223125411 -0.31510555
#> [40,]  0.52454228  1.368238250 -0.329210607  1.589504716 -0.64676129
#> [41,]  0.47391445 -0.315885204  1.329507755  0.618024785 -0.32305503
#> [42,]  1.88788764 -0.240349904  0.687019045  0.756182047  0.77195661
#> [43,] -0.14832436  2.836184242  0.842066789  0.001415793 -0.52129863
#> [44,] -0.17159188  1.819086688 -0.233485969  1.406562202  1.04070740
#> [45,]  1.40102920 -0.024602093 -0.113244502 -0.907131429  0.59055751
#> [46,]  0.91003052  0.786560549 -0.532820029  0.497925310 -0.50231949
#> [47,]  2.15044477  0.578286066 -2.178290779 -1.838169419  0.55128414
#> [48,] -1.26782525  0.510858481  1.295307619 -1.226446232  0.99001587
#> [49,]  0.52759312  0.072901398  1.295103245 -0.819840718  0.12677239
#> [50,] -0.53374221 -1.042752157 -0.133471345  0.022019475  0.37640557
#>              [,6]         [,7]        [,8]          [,9]       [,10]
#>  [1,] -0.05443793 -0.606610885  0.11105976  0.0007414949 -1.58707438
#>  [2,]  0.27988123  0.366859479  1.49892129  0.3824260097 -0.97842104
#>  [3,]  0.49009414  2.223717045  0.01136356 -0.7480021661  0.23497781
#>  [4,] -0.69795958 -1.246636650  0.60458399 -0.5917989453 -0.59677170
#>  [5,]  0.31862250  1.348032732  0.42435662 -0.1705467458 -1.28014687
#>  [6,]  0.75719209  0.140119478  0.41928402  0.1267108248 -0.69868597
#>  [7,] -0.69973253  0.088259149  0.33014329  0.5189889220  0.79742075
#>  [8,]  0.37966457 -0.223239856 -1.60976164  0.7012080488  1.03733680
#>  [9,]  1.31080028  0.563227483  0.24695014  0.0873011380  0.56561105
#> [10,]  0.79336535  1.004293608 -0.28517473  0.2824039612 -0.93294933
#> [11,]  1.00490789 -0.329599526 -1.04718589 -0.1063878946 -0.64511614
#> [12,]  1.56962389  2.070730292 -0.54642026  0.4246935963 -0.52414475
#> [13,]  1.02124739  0.797099637  0.65117887 -1.1050647128 -0.78895662
#> [14,]  1.26393825 -1.241378027  0.30054851  0.1712922317  2.05517965
#> [15,]  2.21650049  0.177789596  0.36995154 -1.8577816199  1.19750008
#> [16,]  0.67300027 -0.647075128 -0.35416546 -1.2502629345  1.18892133
#> [17,]  0.29375854 -1.195292141 -0.13296235 -0.5685434044  1.03813364
#> [18,] -1.55635575  0.963198478 -0.20008581  0.8719180289  0.29553321
#> [19,]  0.10093960  1.550485315 -0.99883408 -1.1722943467 -0.20801916
#> [20,]  1.35444742  0.030664217 -0.16378557 -0.4215011030 -0.57164475
#> [21,]  0.02863044  0.068970577 -0.93167250  1.0111739424  0.44325482
#> [22,]  1.08801840  0.115423643  0.66821991  0.6090616238 -0.53142269
#> [23,]  1.05395246  0.151657944  0.75867749  1.0446097894 -0.41601657
#> [24,] -0.28994241 -0.864513685 -1.84675067 -0.1296353524  0.18771275
#> [25,] -0.57830668  0.620093710  0.72701679 -2.0934722906 -2.25992074
#> [26,]  0.35152606  0.263347334 -1.93802264  0.6555091002 -1.05190160
#> [27,]  1.41498901 -2.403991604  1.46231690  2.0719886597 -0.69559340
#> [28,]  0.57839624 -0.822413655 -0.38836415  0.9809903319  1.37748579
#> [29,] -1.51578052 -0.869306948 -0.25360399 -1.4512718289 -0.27610752
#> [30,]  0.31961505  1.205158731  0.50245107  1.2978497996  1.19344545
#> [31,]  2.10110519  1.041932888 -0.18598947 -0.0058174703  0.98798346
#> [32,] -0.71307255 -1.083425636 -0.97859022 -0.8592404493 -0.87795162
#> [33,]  0.59856344  2.735176018  0.30493282 -0.2737530400  0.43065117
#> [34,]  0.17287897 -0.147193617 -2.27986191 -0.4472411843 -2.04556154
#> [35,]  0.92853317 -1.326970716 -1.72680284  1.3525578564 -0.67290347
#> [36,]  0.57223167  0.179825356  1.09902353 -0.4412776000  1.45732739
#> [37,] -0.42849008 -1.760923272 -1.06430667 -0.3231614395  0.45275502
#> [38,]  1.32296899  1.632195201 -0.73231713  0.7715829370  1.09318417
#> [39,]  1.04032781 -1.730173282  1.76445144 -2.3754346242 -0.11640416
#> [40,]  0.27338329  0.463762226  0.18876260 -0.0246162581  0.47448021
#> [41,] -0.87616042  0.045431253 -1.00952391 -1.2608155240  0.51983995
#> [42,]  0.70496592 -0.009814463 -1.01235210 -0.9941601099 -0.64905679
#> [43,]  0.88066834 -0.297389063 -0.99611817 -1.8100011905  0.03483904
#> [44,] -1.45563176  0.132982429 -1.98682526  0.1648399080 -1.66358806
#> [45,]  1.37555601  0.204851037  1.80995121  0.8871570258 -0.55273474
#> [46,]  0.19642012 -0.643291931 -1.90764949  0.8958945749 -0.11294886
#> [47,] -1.40789602  0.005949535  1.59457038 -0.4029563453 -0.49922272
#> [48,] -0.16014569 -0.580978546  0.84688157 -1.4646843061  0.63620319
#> [49,]  0.34540263 -0.520293907 -0.79756689 -0.6109745706 -0.94191705
#> [50,] -0.81360608 -0.133207418 -0.27687867  0.2252913874 -0.75055187
#>
#> [[2]]
#>               [,1]
#>  [1,]  1.219401917
#>  [2,] -0.124400504
#>  [3,] -0.957498880
#>  [4,] -0.079169514
#>  [5,] -1.143411311
#>  [6,] -1.057187889
#>  [7,] -0.384534338
#>  [8,]  0.608341172
#>  [9,]  1.672466522
#> [10,] -1.537294348
#> [11,] -1.378291892
#> [12,]  0.495431136
#> [13,]  0.938149788
#> [14,] -0.375735281
#> [15,]  0.506424449
#> [16,] -0.709521894
#> [17,] -0.713970427
#> [18,]  0.131593097
#> [19,] -0.568898236
#> [20,] -0.098535501
#> [21,] -1.684572159
#> [22,]  1.283450112
#> [23,]  0.797401718
#> [24,]  1.278698884
#> [25,]  0.437544427
#> [26,] -1.155518925
#> [27,] -1.422846320
#> [28,]  1.584043929
#> [29,] -1.759629791
#> [30,] -0.374976381
#> [31,]  0.596146625
#> [32,] -0.002306772
#> [33,]  0.047815282
#> [34,] -1.761653383
#> [35,] -1.946314391
#> [36,]  1.042578183
#> [37,]  0.298843763
#> [38,]  0.622101833
#> [39,]  1.091471992
#> [40,]  1.755396157
#> [41,] -0.731823695
#> [42,] -0.249385509
#> [43,] -0.664764451
#> [44,] -0.032864061
#> [45,] -0.982648096
#> [46,] -1.054473141
#> [47,]  0.020122987
#> [48,] -0.350979889
#> [49,] -0.292278167
#> [50,] -0.705051819
#>
#> [[3]]
#>      [,1]
#> [1,]    1
#>