Simplifying Cosh[a] + Sin[a] + Sinh[a]











up vote
9
down vote

favorite












Why does FullSimplify[Cosh[a] + Sinh[a] + Sin[a]] not return Exp[a]+Sin[a]
?



Is this some bug in Mathematica or am I being stupid? Is the latter not simpler by some measure?



I've ran into this several times so I guess others have too, therefore i find it hard to believe it is a bug (it should have been reported many times and surely have shown up during their testing).










share|improve this question




















  • 2




    use TrigToExp.
    – Kuba
    2 days ago










  • @Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
    – Michael E2
    2 days ago






  • 2




    @MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
    – Kuba
    2 days ago






  • 2




    @Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
    – Michael E2
    2 days ago










  • @Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
    – Petter
    2 days ago















up vote
9
down vote

favorite












Why does FullSimplify[Cosh[a] + Sinh[a] + Sin[a]] not return Exp[a]+Sin[a]
?



Is this some bug in Mathematica or am I being stupid? Is the latter not simpler by some measure?



I've ran into this several times so I guess others have too, therefore i find it hard to believe it is a bug (it should have been reported many times and surely have shown up during their testing).










share|improve this question




















  • 2




    use TrigToExp.
    – Kuba
    2 days ago










  • @Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
    – Michael E2
    2 days ago






  • 2




    @MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
    – Kuba
    2 days ago






  • 2




    @Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
    – Michael E2
    2 days ago










  • @Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
    – Petter
    2 days ago













up vote
9
down vote

favorite









up vote
9
down vote

favorite











Why does FullSimplify[Cosh[a] + Sinh[a] + Sin[a]] not return Exp[a]+Sin[a]
?



Is this some bug in Mathematica or am I being stupid? Is the latter not simpler by some measure?



I've ran into this several times so I guess others have too, therefore i find it hard to believe it is a bug (it should have been reported many times and surely have shown up during their testing).










share|improve this question















Why does FullSimplify[Cosh[a] + Sinh[a] + Sin[a]] not return Exp[a]+Sin[a]
?



Is this some bug in Mathematica or am I being stupid? Is the latter not simpler by some measure?



I've ran into this several times so I guess others have too, therefore i find it hard to believe it is a bug (it should have been reported many times and surely have shown up during their testing).







bugs simplifying-expressions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Petter

1154




1154








  • 2




    use TrigToExp.
    – Kuba
    2 days ago










  • @Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
    – Michael E2
    2 days ago






  • 2




    @MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
    – Kuba
    2 days ago






  • 2




    @Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
    – Michael E2
    2 days ago










  • @Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
    – Petter
    2 days ago














  • 2




    use TrigToExp.
    – Kuba
    2 days ago










  • @Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
    – Michael E2
    2 days ago






  • 2




    @MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
    – Kuba
    2 days ago






  • 2




    @Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
    – Michael E2
    2 days ago










  • @Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
    – Petter
    2 days ago








2




2




use TrigToExp.
– Kuba
2 days ago




use TrigToExp.
– Kuba
2 days ago












@Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
– Michael E2
2 days ago




@Kuba But FullSimplify[TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]] takes us back where we started.
– Michael E2
2 days ago




2




2




@MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
– Kuba
2 days ago




@MichaelE2 then don't do that. :) btw, I could bet it worked without ComplexExpand but now I tried and it seems necessary: ComplexExpand@TrigToExp[Cosh[a] + Sin[a] + Sinh[a]].
– Kuba
2 days ago




2




2




@Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
– Michael E2
2 days ago




@Kuba Cool (of course ComplexExpand treats a as if it were Real, which might give invalid results in similar cases). I was busy figuring out why FullSimplify fails. I think it's interesting and that this question should not be closed.
– Michael E2
2 days ago












@Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
– Petter
2 days ago




@Kuba, I'm not asking how to simplify the expression but why the above way of simplifying does not work. I can always find ways of simplifying by trial and error though if I understood why the above didn't work I could use a more direct approach.
– Petter
2 days ago










3 Answers
3






active

oldest

votes

















up vote
9
down vote



accepted










One problem seems to be that the only pair of terms in a Plus[t1, t2,...,] expression that are simplified are the last two. This shows up not only in the starting expression Cosh[a] + Sin[a] + Sinh[a] (in that order due to the Orderless attribute of Plus) but also in TrigToExp:



TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]
(* 1/2 I E^(-I a) - 1/2 I E^(I a) + E^a *)


When this is simplified we get the original expression back.



Probably it was thought that pointlessly simplifying $n(n-1)/2$ pairs of terms in a long expression would probably slow down simplification too much. Since one pair but not all pairs are checked, I feel this was a deliberate choice. I'd be reluctant to call it a bug, but it certainly is a shortcoming in this case.



A workaround is to create a transformation function that checks all pairs:



ClearAll[allpairs];
allpairs[e_Plus] :=
First@SortBy[e - # + FullSimplify[#] & /@ Subsets[e, {2}], Simplify`SimplifyCount];
allpairs[e_] := e;

FullSimplify[Cosh[a] + Sinh[a] + Sin[a], TransformationFunctions -> {Automatic, allpairs}]
(* E^a + Sin[a] *)


Another workaround, showing that some standard identities are missing from the automatic transformations:



FullSimplify[Cosh[a] + Sinh[a] + Sin[a], 
TransformationFunctions -> {Automatic,
# /. Cosh[z_] -> Exp[z] - Sinh[z] &,
# /. Sinh[z_] -> Exp[z] - Cosh[z] &}]

(* E^a + Sin[a] *)





share|improve this answer























  • The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
    – Petter
    2 days ago










  • @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
    – Michael E2
    2 days ago










  • not always as i pointed out above?
    – Petter
    2 days ago










  • @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
    – Michael E2
    2 days ago










  • I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
    – Petter
    2 days ago


















up vote
5
down vote













EDIT: As commented on by Kuba



expr = Cosh[a] + Sinh[a] + Sin[a];


Initially assume that a is real (default for ComplexExpand)



expr2 = expr // TrigToExp // ComplexExpand

(* E^a + Sin[a] *)


Then check if the expressions are equal for all (complex) values of a



expr == expr2 // Simplify

(* True *)


EDIT 2: Alternatively, since Michael E2 states that Mathematica "simplifies the last two terms in a sum", vary the ordering of the terms



SortBy[Total /@ FullSimplify@Table[TakeDrop[expr, {n}], {n, 3}], 
LeafCount][[1]]

(* E^a + Sin[a] *)





share|improve this answer






























    up vote
    1
    down vote













    EDIT: There is a simple specific to the case solution as well:



    FullSimplify[Cosh[a]+Sinh[a]+Sin[a],ExcludedForms->_Sin]
    (* E^a+Sin[a] *)


    The reason why it works is explained below.





    Firstly, the simple solution: You need to use ComplexExpand as a transformation function:



    FullSimplify[Cosh[a]+Sinh[a]+Sin[a],TransformationFunctions->{Automatic,ComplexExpand}]
    (* E^a+Sin[a] *)


    Explanation



    I do not know why this happens but my guess is as follows. The observation of OP is probably because of the way transformation functions work. If I have a transformation function g, then FullSimplify applies it to all subexpressions f[x1,x2,...,xn] and checks g[f[x1...xn]] is simpler than f[x1...xn] (well, not one by one for each subexpression but the whole expression). In particular, this means that FullSimplify compares



    Cosh[a] + Sin[a] + Sinh[a] 


    and



    1/2 I E^(-I a) - 1/2 I E^(I a) + E^a


    where second output follows from the transformation function TrigToExp. Here, the key point is this: Since Plus has the Flat attribute, TrigToExp also applies to Sin[a], and one cannot avoid that. Say, if Plus did not have this attribute, we could have had a scenario where the transformation is applied only the other two without affecting Sin[a], which is possible only if they are not at the same subexpression.



    This explanation is in contrast to @Michael's explanation as far as I understand. In particular, one can see that this simplification is no issue if the middle term was not expanded by TrigToExp:



    FullSimplify[Cosh[a]+Sinc[a]+Sinh[a]]
    (* E^a+Sinc[a] *)


    in contrast to, say,



    FullSimplify[Cosh[a]+Cos[a]+Sinh[a]]
    (* Cos[a]+Cosh[a]+Sinh[a] *)


    One can check that indeed TrigToExp expands Cos but not Sinc. So the issue is not the order of terms nor that Fullsimplify does not consider different pairs.



    Once we add ComplexExpand into the transformation functions, we now have FullSimplify comparing original expression with ComplexExpand[TrigToExp[#]]& transformation, and these are:



    {#,ComplexExpand[TrigToExp[#]]}&[Cosh[a]+Cos[a]+Sinh[a]]
    (* {Cos[a]+Cosh[a]+Sinh[a],E^a+Cos[a]} *)


    Now since one expression is shorter than the other, FullSimplify can immediately choose the correct one!



    Summary



    I would say that there is no bug with FullSimplify, at most a shortcoming. The solution I proposed above is actually inherently using another information we presented, that $a$ is real (even though the result is actually true for a bigger domain). That FullSimplify can do better simplifications under restricted domains even though the simplifications are actually correct for the original domain is disturbing, but it is not a bug, only a shortcoming.






    share|improve this answer



















    • 1




      It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
      – Michael E2
      15 hours ago










    • I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
      – Soner
      14 hours ago











    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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f186872%2fsimplifying-cosha-sina-sinha%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    9
    down vote



    accepted










    One problem seems to be that the only pair of terms in a Plus[t1, t2,...,] expression that are simplified are the last two. This shows up not only in the starting expression Cosh[a] + Sin[a] + Sinh[a] (in that order due to the Orderless attribute of Plus) but also in TrigToExp:



    TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]
    (* 1/2 I E^(-I a) - 1/2 I E^(I a) + E^a *)


    When this is simplified we get the original expression back.



    Probably it was thought that pointlessly simplifying $n(n-1)/2$ pairs of terms in a long expression would probably slow down simplification too much. Since one pair but not all pairs are checked, I feel this was a deliberate choice. I'd be reluctant to call it a bug, but it certainly is a shortcoming in this case.



    A workaround is to create a transformation function that checks all pairs:



    ClearAll[allpairs];
    allpairs[e_Plus] :=
    First@SortBy[e - # + FullSimplify[#] & /@ Subsets[e, {2}], Simplify`SimplifyCount];
    allpairs[e_] := e;

    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], TransformationFunctions -> {Automatic, allpairs}]
    (* E^a + Sin[a] *)


    Another workaround, showing that some standard identities are missing from the automatic transformations:



    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], 
    TransformationFunctions -> {Automatic,
    # /. Cosh[z_] -> Exp[z] - Sinh[z] &,
    # /. Sinh[z_] -> Exp[z] - Cosh[z] &}]

    (* E^a + Sin[a] *)





    share|improve this answer























    • The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
      – Petter
      2 days ago










    • @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
      – Michael E2
      2 days ago










    • not always as i pointed out above?
      – Petter
      2 days ago










    • @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
      – Michael E2
      2 days ago










    • I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
      – Petter
      2 days ago















    up vote
    9
    down vote



    accepted










    One problem seems to be that the only pair of terms in a Plus[t1, t2,...,] expression that are simplified are the last two. This shows up not only in the starting expression Cosh[a] + Sin[a] + Sinh[a] (in that order due to the Orderless attribute of Plus) but also in TrigToExp:



    TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]
    (* 1/2 I E^(-I a) - 1/2 I E^(I a) + E^a *)


    When this is simplified we get the original expression back.



    Probably it was thought that pointlessly simplifying $n(n-1)/2$ pairs of terms in a long expression would probably slow down simplification too much. Since one pair but not all pairs are checked, I feel this was a deliberate choice. I'd be reluctant to call it a bug, but it certainly is a shortcoming in this case.



    A workaround is to create a transformation function that checks all pairs:



    ClearAll[allpairs];
    allpairs[e_Plus] :=
    First@SortBy[e - # + FullSimplify[#] & /@ Subsets[e, {2}], Simplify`SimplifyCount];
    allpairs[e_] := e;

    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], TransformationFunctions -> {Automatic, allpairs}]
    (* E^a + Sin[a] *)


    Another workaround, showing that some standard identities are missing from the automatic transformations:



    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], 
    TransformationFunctions -> {Automatic,
    # /. Cosh[z_] -> Exp[z] - Sinh[z] &,
    # /. Sinh[z_] -> Exp[z] - Cosh[z] &}]

    (* E^a + Sin[a] *)





    share|improve this answer























    • The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
      – Petter
      2 days ago










    • @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
      – Michael E2
      2 days ago










    • not always as i pointed out above?
      – Petter
      2 days ago










    • @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
      – Michael E2
      2 days ago










    • I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
      – Petter
      2 days ago













    up vote
    9
    down vote



    accepted







    up vote
    9
    down vote



    accepted






    One problem seems to be that the only pair of terms in a Plus[t1, t2,...,] expression that are simplified are the last two. This shows up not only in the starting expression Cosh[a] + Sin[a] + Sinh[a] (in that order due to the Orderless attribute of Plus) but also in TrigToExp:



    TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]
    (* 1/2 I E^(-I a) - 1/2 I E^(I a) + E^a *)


    When this is simplified we get the original expression back.



    Probably it was thought that pointlessly simplifying $n(n-1)/2$ pairs of terms in a long expression would probably slow down simplification too much. Since one pair but not all pairs are checked, I feel this was a deliberate choice. I'd be reluctant to call it a bug, but it certainly is a shortcoming in this case.



    A workaround is to create a transformation function that checks all pairs:



    ClearAll[allpairs];
    allpairs[e_Plus] :=
    First@SortBy[e - # + FullSimplify[#] & /@ Subsets[e, {2}], Simplify`SimplifyCount];
    allpairs[e_] := e;

    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], TransformationFunctions -> {Automatic, allpairs}]
    (* E^a + Sin[a] *)


    Another workaround, showing that some standard identities are missing from the automatic transformations:



    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], 
    TransformationFunctions -> {Automatic,
    # /. Cosh[z_] -> Exp[z] - Sinh[z] &,
    # /. Sinh[z_] -> Exp[z] - Cosh[z] &}]

    (* E^a + Sin[a] *)





    share|improve this answer














    One problem seems to be that the only pair of terms in a Plus[t1, t2,...,] expression that are simplified are the last two. This shows up not only in the starting expression Cosh[a] + Sin[a] + Sinh[a] (in that order due to the Orderless attribute of Plus) but also in TrigToExp:



    TrigToExp[Cosh[a] + Sinh[a] + Sin[a]]
    (* 1/2 I E^(-I a) - 1/2 I E^(I a) + E^a *)


    When this is simplified we get the original expression back.



    Probably it was thought that pointlessly simplifying $n(n-1)/2$ pairs of terms in a long expression would probably slow down simplification too much. Since one pair but not all pairs are checked, I feel this was a deliberate choice. I'd be reluctant to call it a bug, but it certainly is a shortcoming in this case.



    A workaround is to create a transformation function that checks all pairs:



    ClearAll[allpairs];
    allpairs[e_Plus] :=
    First@SortBy[e - # + FullSimplify[#] & /@ Subsets[e, {2}], Simplify`SimplifyCount];
    allpairs[e_] := e;

    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], TransformationFunctions -> {Automatic, allpairs}]
    (* E^a + Sin[a] *)


    Another workaround, showing that some standard identities are missing from the automatic transformations:



    FullSimplify[Cosh[a] + Sinh[a] + Sin[a], 
    TransformationFunctions -> {Automatic,
    # /. Cosh[z_] -> Exp[z] - Sinh[z] &,
    # /. Sinh[z_] -> Exp[z] - Cosh[z] &}]

    (* E^a + Sin[a] *)






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    Michael E2

    144k11192462




    144k11192462












    • The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
      – Petter
      2 days ago










    • @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
      – Michael E2
      2 days ago










    • not always as i pointed out above?
      – Petter
      2 days ago










    • @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
      – Michael E2
      2 days ago










    • I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
      – Petter
      2 days ago


















    • The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
      – Petter
      2 days ago










    • @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
      – Michael E2
      2 days ago










    • not always as i pointed out above?
      – Petter
      2 days ago










    • @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
      – Michael E2
      2 days ago










    • I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
      – Petter
      2 days ago
















    The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
    – Petter
    2 days ago




    The documentation states that FullSimplify "tries a wide range of transformations on expr involving elementary and special functions and returns the simplest form it finds. ", sure a wide range is somewhat subjective but surely simplifying Cosh[a] + Sinh[a] is included in a wide range so I would call this a bug.
    – Petter
    2 days ago












    @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
    – Michael E2
    2 days ago




    @Petter FullSimplify does simplify Cosh[a] + Sinh[a].
    – Michael E2
    2 days ago












    not always as i pointed out above?
    – Petter
    2 days ago




    not always as i pointed out above?
    – Petter
    2 days ago












    @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
    – Michael E2
    2 days ago




    @Petter The point is that it only simplifies the last two terms in a sum, so it never tries to apply a transformation to Cosh[a] + Sinh[a] in your example. Another way to look at it, perhaps more to your liking, is that it does not apply transformations like Cosh[a] -> Exp[a] - Sinh[a]. From that viewpoint, one could argue that the range of transformations is not wide enough. You should report it to WRI, since you think it is a bug.
    – Michael E2
    2 days ago












    I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
    – Petter
    2 days ago




    I understand your explanation and thank you for figuring it out. I think that is how it works too after some testing. Though to me that is clearly a bug. I don't think quadratic complexity is too bad when simplifying an expression and especially not if it is this small. Technically this is subjective but in practice it makes no sense that fullsimplify can use identities of hypergeometric functions when this simple test case fails. By wri do you mean wolfram? I've reported several bugs to them, they have confirmed and told me it will be fixed. Several versions later they are still there...
    – Petter
    2 days ago










    up vote
    5
    down vote













    EDIT: As commented on by Kuba



    expr = Cosh[a] + Sinh[a] + Sin[a];


    Initially assume that a is real (default for ComplexExpand)



    expr2 = expr // TrigToExp // ComplexExpand

    (* E^a + Sin[a] *)


    Then check if the expressions are equal for all (complex) values of a



    expr == expr2 // Simplify

    (* True *)


    EDIT 2: Alternatively, since Michael E2 states that Mathematica "simplifies the last two terms in a sum", vary the ordering of the terms



    SortBy[Total /@ FullSimplify@Table[TakeDrop[expr, {n}], {n, 3}], 
    LeafCount][[1]]

    (* E^a + Sin[a] *)





    share|improve this answer



























      up vote
      5
      down vote













      EDIT: As commented on by Kuba



      expr = Cosh[a] + Sinh[a] + Sin[a];


      Initially assume that a is real (default for ComplexExpand)



      expr2 = expr // TrigToExp // ComplexExpand

      (* E^a + Sin[a] *)


      Then check if the expressions are equal for all (complex) values of a



      expr == expr2 // Simplify

      (* True *)


      EDIT 2: Alternatively, since Michael E2 states that Mathematica "simplifies the last two terms in a sum", vary the ordering of the terms



      SortBy[Total /@ FullSimplify@Table[TakeDrop[expr, {n}], {n, 3}], 
      LeafCount][[1]]

      (* E^a + Sin[a] *)





      share|improve this answer

























        up vote
        5
        down vote










        up vote
        5
        down vote









        EDIT: As commented on by Kuba



        expr = Cosh[a] + Sinh[a] + Sin[a];


        Initially assume that a is real (default for ComplexExpand)



        expr2 = expr // TrigToExp // ComplexExpand

        (* E^a + Sin[a] *)


        Then check if the expressions are equal for all (complex) values of a



        expr == expr2 // Simplify

        (* True *)


        EDIT 2: Alternatively, since Michael E2 states that Mathematica "simplifies the last two terms in a sum", vary the ordering of the terms



        SortBy[Total /@ FullSimplify@Table[TakeDrop[expr, {n}], {n, 3}], 
        LeafCount][[1]]

        (* E^a + Sin[a] *)





        share|improve this answer














        EDIT: As commented on by Kuba



        expr = Cosh[a] + Sinh[a] + Sin[a];


        Initially assume that a is real (default for ComplexExpand)



        expr2 = expr // TrigToExp // ComplexExpand

        (* E^a + Sin[a] *)


        Then check if the expressions are equal for all (complex) values of a



        expr == expr2 // Simplify

        (* True *)


        EDIT 2: Alternatively, since Michael E2 states that Mathematica "simplifies the last two terms in a sum", vary the ordering of the terms



        SortBy[Total /@ FullSimplify@Table[TakeDrop[expr, {n}], {n, 3}], 
        LeafCount][[1]]

        (* E^a + Sin[a] *)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        Bob Hanlon

        57.9k23593




        57.9k23593






















            up vote
            1
            down vote













            EDIT: There is a simple specific to the case solution as well:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],ExcludedForms->_Sin]
            (* E^a+Sin[a] *)


            The reason why it works is explained below.





            Firstly, the simple solution: You need to use ComplexExpand as a transformation function:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],TransformationFunctions->{Automatic,ComplexExpand}]
            (* E^a+Sin[a] *)


            Explanation



            I do not know why this happens but my guess is as follows. The observation of OP is probably because of the way transformation functions work. If I have a transformation function g, then FullSimplify applies it to all subexpressions f[x1,x2,...,xn] and checks g[f[x1...xn]] is simpler than f[x1...xn] (well, not one by one for each subexpression but the whole expression). In particular, this means that FullSimplify compares



            Cosh[a] + Sin[a] + Sinh[a] 


            and



            1/2 I E^(-I a) - 1/2 I E^(I a) + E^a


            where second output follows from the transformation function TrigToExp. Here, the key point is this: Since Plus has the Flat attribute, TrigToExp also applies to Sin[a], and one cannot avoid that. Say, if Plus did not have this attribute, we could have had a scenario where the transformation is applied only the other two without affecting Sin[a], which is possible only if they are not at the same subexpression.



            This explanation is in contrast to @Michael's explanation as far as I understand. In particular, one can see that this simplification is no issue if the middle term was not expanded by TrigToExp:



            FullSimplify[Cosh[a]+Sinc[a]+Sinh[a]]
            (* E^a+Sinc[a] *)


            in contrast to, say,



            FullSimplify[Cosh[a]+Cos[a]+Sinh[a]]
            (* Cos[a]+Cosh[a]+Sinh[a] *)


            One can check that indeed TrigToExp expands Cos but not Sinc. So the issue is not the order of terms nor that Fullsimplify does not consider different pairs.



            Once we add ComplexExpand into the transformation functions, we now have FullSimplify comparing original expression with ComplexExpand[TrigToExp[#]]& transformation, and these are:



            {#,ComplexExpand[TrigToExp[#]]}&[Cosh[a]+Cos[a]+Sinh[a]]
            (* {Cos[a]+Cosh[a]+Sinh[a],E^a+Cos[a]} *)


            Now since one expression is shorter than the other, FullSimplify can immediately choose the correct one!



            Summary



            I would say that there is no bug with FullSimplify, at most a shortcoming. The solution I proposed above is actually inherently using another information we presented, that $a$ is real (even though the result is actually true for a bigger domain). That FullSimplify can do better simplifications under restricted domains even though the simplifications are actually correct for the original domain is disturbing, but it is not a bug, only a shortcoming.






            share|improve this answer



















            • 1




              It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
              – Michael E2
              15 hours ago










            • I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
              – Soner
              14 hours ago















            up vote
            1
            down vote













            EDIT: There is a simple specific to the case solution as well:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],ExcludedForms->_Sin]
            (* E^a+Sin[a] *)


            The reason why it works is explained below.





            Firstly, the simple solution: You need to use ComplexExpand as a transformation function:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],TransformationFunctions->{Automatic,ComplexExpand}]
            (* E^a+Sin[a] *)


            Explanation



            I do not know why this happens but my guess is as follows. The observation of OP is probably because of the way transformation functions work. If I have a transformation function g, then FullSimplify applies it to all subexpressions f[x1,x2,...,xn] and checks g[f[x1...xn]] is simpler than f[x1...xn] (well, not one by one for each subexpression but the whole expression). In particular, this means that FullSimplify compares



            Cosh[a] + Sin[a] + Sinh[a] 


            and



            1/2 I E^(-I a) - 1/2 I E^(I a) + E^a


            where second output follows from the transformation function TrigToExp. Here, the key point is this: Since Plus has the Flat attribute, TrigToExp also applies to Sin[a], and one cannot avoid that. Say, if Plus did not have this attribute, we could have had a scenario where the transformation is applied only the other two without affecting Sin[a], which is possible only if they are not at the same subexpression.



            This explanation is in contrast to @Michael's explanation as far as I understand. In particular, one can see that this simplification is no issue if the middle term was not expanded by TrigToExp:



            FullSimplify[Cosh[a]+Sinc[a]+Sinh[a]]
            (* E^a+Sinc[a] *)


            in contrast to, say,



            FullSimplify[Cosh[a]+Cos[a]+Sinh[a]]
            (* Cos[a]+Cosh[a]+Sinh[a] *)


            One can check that indeed TrigToExp expands Cos but not Sinc. So the issue is not the order of terms nor that Fullsimplify does not consider different pairs.



            Once we add ComplexExpand into the transformation functions, we now have FullSimplify comparing original expression with ComplexExpand[TrigToExp[#]]& transformation, and these are:



            {#,ComplexExpand[TrigToExp[#]]}&[Cosh[a]+Cos[a]+Sinh[a]]
            (* {Cos[a]+Cosh[a]+Sinh[a],E^a+Cos[a]} *)


            Now since one expression is shorter than the other, FullSimplify can immediately choose the correct one!



            Summary



            I would say that there is no bug with FullSimplify, at most a shortcoming. The solution I proposed above is actually inherently using another information we presented, that $a$ is real (even though the result is actually true for a bigger domain). That FullSimplify can do better simplifications under restricted domains even though the simplifications are actually correct for the original domain is disturbing, but it is not a bug, only a shortcoming.






            share|improve this answer



















            • 1




              It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
              – Michael E2
              15 hours ago










            • I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
              – Soner
              14 hours ago













            up vote
            1
            down vote










            up vote
            1
            down vote









            EDIT: There is a simple specific to the case solution as well:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],ExcludedForms->_Sin]
            (* E^a+Sin[a] *)


            The reason why it works is explained below.





            Firstly, the simple solution: You need to use ComplexExpand as a transformation function:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],TransformationFunctions->{Automatic,ComplexExpand}]
            (* E^a+Sin[a] *)


            Explanation



            I do not know why this happens but my guess is as follows. The observation of OP is probably because of the way transformation functions work. If I have a transformation function g, then FullSimplify applies it to all subexpressions f[x1,x2,...,xn] and checks g[f[x1...xn]] is simpler than f[x1...xn] (well, not one by one for each subexpression but the whole expression). In particular, this means that FullSimplify compares



            Cosh[a] + Sin[a] + Sinh[a] 


            and



            1/2 I E^(-I a) - 1/2 I E^(I a) + E^a


            where second output follows from the transformation function TrigToExp. Here, the key point is this: Since Plus has the Flat attribute, TrigToExp also applies to Sin[a], and one cannot avoid that. Say, if Plus did not have this attribute, we could have had a scenario where the transformation is applied only the other two without affecting Sin[a], which is possible only if they are not at the same subexpression.



            This explanation is in contrast to @Michael's explanation as far as I understand. In particular, one can see that this simplification is no issue if the middle term was not expanded by TrigToExp:



            FullSimplify[Cosh[a]+Sinc[a]+Sinh[a]]
            (* E^a+Sinc[a] *)


            in contrast to, say,



            FullSimplify[Cosh[a]+Cos[a]+Sinh[a]]
            (* Cos[a]+Cosh[a]+Sinh[a] *)


            One can check that indeed TrigToExp expands Cos but not Sinc. So the issue is not the order of terms nor that Fullsimplify does not consider different pairs.



            Once we add ComplexExpand into the transformation functions, we now have FullSimplify comparing original expression with ComplexExpand[TrigToExp[#]]& transformation, and these are:



            {#,ComplexExpand[TrigToExp[#]]}&[Cosh[a]+Cos[a]+Sinh[a]]
            (* {Cos[a]+Cosh[a]+Sinh[a],E^a+Cos[a]} *)


            Now since one expression is shorter than the other, FullSimplify can immediately choose the correct one!



            Summary



            I would say that there is no bug with FullSimplify, at most a shortcoming. The solution I proposed above is actually inherently using another information we presented, that $a$ is real (even though the result is actually true for a bigger domain). That FullSimplify can do better simplifications under restricted domains even though the simplifications are actually correct for the original domain is disturbing, but it is not a bug, only a shortcoming.






            share|improve this answer














            EDIT: There is a simple specific to the case solution as well:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],ExcludedForms->_Sin]
            (* E^a+Sin[a] *)


            The reason why it works is explained below.





            Firstly, the simple solution: You need to use ComplexExpand as a transformation function:



            FullSimplify[Cosh[a]+Sinh[a]+Sin[a],TransformationFunctions->{Automatic,ComplexExpand}]
            (* E^a+Sin[a] *)


            Explanation



            I do not know why this happens but my guess is as follows. The observation of OP is probably because of the way transformation functions work. If I have a transformation function g, then FullSimplify applies it to all subexpressions f[x1,x2,...,xn] and checks g[f[x1...xn]] is simpler than f[x1...xn] (well, not one by one for each subexpression but the whole expression). In particular, this means that FullSimplify compares



            Cosh[a] + Sin[a] + Sinh[a] 


            and



            1/2 I E^(-I a) - 1/2 I E^(I a) + E^a


            where second output follows from the transformation function TrigToExp. Here, the key point is this: Since Plus has the Flat attribute, TrigToExp also applies to Sin[a], and one cannot avoid that. Say, if Plus did not have this attribute, we could have had a scenario where the transformation is applied only the other two without affecting Sin[a], which is possible only if they are not at the same subexpression.



            This explanation is in contrast to @Michael's explanation as far as I understand. In particular, one can see that this simplification is no issue if the middle term was not expanded by TrigToExp:



            FullSimplify[Cosh[a]+Sinc[a]+Sinh[a]]
            (* E^a+Sinc[a] *)


            in contrast to, say,



            FullSimplify[Cosh[a]+Cos[a]+Sinh[a]]
            (* Cos[a]+Cosh[a]+Sinh[a] *)


            One can check that indeed TrigToExp expands Cos but not Sinc. So the issue is not the order of terms nor that Fullsimplify does not consider different pairs.



            Once we add ComplexExpand into the transformation functions, we now have FullSimplify comparing original expression with ComplexExpand[TrigToExp[#]]& transformation, and these are:



            {#,ComplexExpand[TrigToExp[#]]}&[Cosh[a]+Cos[a]+Sinh[a]]
            (* {Cos[a]+Cosh[a]+Sinh[a],E^a+Cos[a]} *)


            Now since one expression is shorter than the other, FullSimplify can immediately choose the correct one!



            Summary



            I would say that there is no bug with FullSimplify, at most a shortcoming. The solution I proposed above is actually inherently using another information we presented, that $a$ is real (even though the result is actually true for a bigger domain). That FullSimplify can do better simplifications under restricted domains even though the simplifications are actually correct for the original domain is disturbing, but it is not a bug, only a shortcoming.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 14 hours ago

























            answered 15 hours ago









            Soner

            80349




            80349








            • 1




              It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
              – Michael E2
              15 hours ago










            • I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
              – Soner
              14 hours ago














            • 1




              It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
              – Michael E2
              15 hours ago










            • I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
              – Soner
              14 hours ago








            1




            1




            It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
            – Michael E2
            15 hours ago




            It seems trig functions are treated specially. So when a trig function separates Cosh[a] and Sinh[a], then the transformation does not occur in the plain FullSimplify. It's as if the trig functions are culled and simplified en masse. (I can't see inside the transformation, only what sub-expressions are treated.)
            – Michael E2
            15 hours ago












            I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
            – Soner
            14 hours ago




            I updated my answer with an IMO-better solution, which avoids this issue without domain restriction.
            – Soner
            14 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186872%2fsimplifying-cosha-sina-sinha%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre