2

Is there any way to stop automatically rationalizing denominators in sympy? I want to get non-rationalizing output 1/sqrt(2) as output of cos(pi/4). Now I get sqrt(2)/2 as output of cos(pi/4).

user6695701
  • 197
  • 1
  • 10
  • Similar question [here](http://stackoverflow.com/questions/37378902/how-do-i-get-sympy-to-simplify-an-expression-containing-sqrt2-2) – Stelios Oct 12 '16 at 17:50

1 Answers1

1

Rationalization happens automatically (see How do I get sympy to simplify an expression containing sqrt(2)/2?). You can manually avoid automatic evaluation with with evaluate(False)

In [39]: with evaluate(False):
   ....:     print(1/sqrt(2))
   ....:
1/(sqrt(2))
asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • Thank you for your answer. I want to get non-rationalizing output as calculation result like cos(pi/4). I think `with evaluate(False)` doesn't work for that. You mean there is not any way for this like disable rationalizing option, right? – user6695701 Oct 15 '16 at 19:49
  • There is not. You would need to write a function that takes a rationalized output (what cos(pi/4) returns) and de-rationalizes it with evaluate=False. I don't know of an existing function that does this. – asmeurer Oct 18 '16 at 17:58
  • I'm sorry for my incompleteness. – user6695701 Oct 23 '16 at 01:18
  • I tried bellow code. In [3]: with evaluate(False): ...: print(cos(pi/4)) cos(pi/4**1) I want to get de rationalized output 1/sqrt(2) as calculation result of cos(pi/4). `with evaluate(False):` seems not to calculate anything. – user6695701 Oct 23 '16 at 01:42
  • It won't be that simple, because `cos(pi/4)` is programmed to give the rationalized output (evaluated or no). That's why I said you'd have to write a function to de-rationalize it. – asmeurer Oct 23 '16 at 02:06
  • OK. I understand. It seems I have to give up that problem. Thank you so much. – user6695701 Oct 24 '16 at 03:26