How can I map associations to expressions?
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
I have a list of associations, and I would like to make it so that an expression automatically reads the associated data from the associations list, that has the same name, into the expression. An example would be better than words:
The expression:
-0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
The associations:
<|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
I would like the f
and p
, from the associations list, to be automatically mapped into the expression, so that, in the expression, f
would have the value -0.225, and p
would have the value 0.26.
Is there any way to do this? Thanks!
replacement associations
add a comment |Â
up vote
7
down vote
favorite
I have a list of associations, and I would like to make it so that an expression automatically reads the associated data from the associations list, that has the same name, into the expression. An example would be better than words:
The expression:
-0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
The associations:
<|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
I would like the f
and p
, from the associations list, to be automatically mapped into the expression, so that, in the expression, f
would have the value -0.225, and p
would have the value 0.26.
Is there any way to do this? Thanks!
replacement associations
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I have a list of associations, and I would like to make it so that an expression automatically reads the associated data from the associations list, that has the same name, into the expression. An example would be better than words:
The expression:
-0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
The associations:
<|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
I would like the f
and p
, from the associations list, to be automatically mapped into the expression, so that, in the expression, f
would have the value -0.225, and p
would have the value 0.26.
Is there any way to do this? Thanks!
replacement associations
I have a list of associations, and I would like to make it so that an expression automatically reads the associated data from the associations list, that has the same name, into the expression. An example would be better than words:
The expression:
-0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
The associations:
<|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
I would like the f
and p
, from the associations list, to be automatically mapped into the expression, so that, in the expression, f
would have the value -0.225, and p
would have the value 0.26.
Is there any way to do this? Thanks!
replacement associations
replacement associations
edited Sep 9 at 17:35
kglr
159k8184384
159k8184384
asked Sep 9 at 17:15
Jmeeks29ig
1475
1475
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
You can simply use your association as a list of rules to be passed to ReplaceAll
, also known as /.
.
expr = -0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
assoc = <|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
Now
expr /. assoc
or
ReplaceAll[expr, assoc]
will give you the answer, in this case -0.0683299.
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
add a comment |Â
up vote
5
down vote
Also
With[f = assoc[f], p = assoc[p], Evaluate @ expr]
-0.0683299
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
You can simply use your association as a list of rules to be passed to ReplaceAll
, also known as /.
.
expr = -0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
assoc = <|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
Now
expr /. assoc
or
ReplaceAll[expr, assoc]
will give you the answer, in this case -0.0683299.
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
add a comment |Â
up vote
8
down vote
accepted
You can simply use your association as a list of rules to be passed to ReplaceAll
, also known as /.
.
expr = -0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
assoc = <|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
Now
expr /. assoc
or
ReplaceAll[expr, assoc]
will give you the answer, in this case -0.0683299.
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
You can simply use your association as a list of rules to be passed to ReplaceAll
, also known as /.
.
expr = -0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
assoc = <|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
Now
expr /. assoc
or
ReplaceAll[expr, assoc]
will give you the answer, in this case -0.0683299.
You can simply use your association as a list of rules to be passed to ReplaceAll
, also known as /.
.
expr = -0.0441268 (-0.905134 - f + (3.24967 + p)^0.638117)
assoc = <|a -> -0.497445, b -> -0.12459, c -> 0.59053, d -> 0.26936,
e -> 0.745094, f -> -0.225087, g -> 0.744386, h -> 0.915999,
i -> 0.540287, j -> 0.406811, k -> -0.664433, l -> 0.355135,
m -> -0.880653, n -> -0.559651, o -> -0.23426, p -> 0.260966,
q -> 0.435459, r -> -0.105631, s -> 0.544961, t -> 0.347138,
u -> 0.958919, v -> 0.200587, w -> -0.656598, x -> 0.553327,
y -> -0.282113, z -> 0.178719|>
Now
expr /. assoc
or
ReplaceAll[expr, assoc]
will give you the answer, in this case -0.0683299.
answered Sep 9 at 17:23


Carl Lange
1,053214
1,053214
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
add a comment |Â
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
Thanks a bunch, it worked!
– Jmeeks29ig
Sep 9 at 17:35
add a comment |Â
up vote
5
down vote
Also
With[f = assoc[f], p = assoc[p], Evaluate @ expr]
-0.0683299
add a comment |Â
up vote
5
down vote
Also
With[f = assoc[f], p = assoc[p], Evaluate @ expr]
-0.0683299
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Also
With[f = assoc[f], p = assoc[p], Evaluate @ expr]
-0.0683299
Also
With[f = assoc[f], p = assoc[p], Evaluate @ expr]
-0.0683299
answered Sep 9 at 18:42
kglr
159k8184384
159k8184384
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181561%2fhow-can-i-map-associations-to-expressions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password