How can I map associations to expressions?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite
1












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!










share|improve this question



























    up vote
    7
    down vote

    favorite
    1












    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!










    share|improve this question

























      up vote
      7
      down vote

      favorite
      1









      up vote
      7
      down vote

      favorite
      1






      1





      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!










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 9 at 17:35









      kglr

      159k8184384




      159k8184384










      asked Sep 9 at 17:15









      Jmeeks29ig

      1475




      1475




















          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.






          share|improve this answer




















          • Thanks a bunch, it worked!
            – Jmeeks29ig
            Sep 9 at 17:35

















          up vote
          5
          down vote













          Also



          With[f = assoc[f], p = assoc[p], Evaluate @ expr] 



          -0.0683299







          share|improve this answer




















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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.






            share|improve this answer




















            • Thanks a bunch, it worked!
              – Jmeeks29ig
              Sep 9 at 17:35














            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.






            share|improve this answer




















            • Thanks a bunch, it worked!
              – Jmeeks29ig
              Sep 9 at 17:35












            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.






            share|improve this answer












            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 9 at 17:23









            Carl Lange

            1,053214




            1,053214











            • 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




            Thanks a bunch, it worked!
            – Jmeeks29ig
            Sep 9 at 17:35










            up vote
            5
            down vote













            Also



            With[f = assoc[f], p = assoc[p], Evaluate @ expr] 



            -0.0683299







            share|improve this answer
























              up vote
              5
              down vote













              Also



              With[f = assoc[f], p = assoc[p], Evaluate @ expr] 



              -0.0683299







              share|improve this answer






















                up vote
                5
                down vote










                up vote
                5
                down vote









                Also



                With[f = assoc[f], p = assoc[p], Evaluate @ expr] 



                -0.0683299







                share|improve this answer












                Also



                With[f = assoc[f], p = assoc[p], Evaluate @ expr] 



                -0.0683299








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 9 at 18:42









                kglr

                159k8184384




                159k8184384



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery