>  There are several different ways to rewrite one trig function in terms 
of another. 

  The `fu` patterns can be used to do different types of rewriting. But in 
the case you gave, rewriting as cos, Pow or Mul might make sense.

On Monday, May 17, 2021 at 3:26:36 AM UTC-5 JSS95 wrote:

> I opened a PR #21472 <https://github.com/sympy/sympy/pull/21472> for 
> this. I will wait for your review.
>
> Jisoo Song
>
> 2021년 5월 13일 목요일 오전 4시 42분 3초 UTC+9에 asme...@gmail.com님이 작성:
>
>> I would just pass the object through to the function, like 
>>
>> expr.rewrite(expr2) calls 
>>
>> expr._eval_rewrite(expr2) 
>>
>> except it should still prefer the existing API if a method matches. 
>>
>> This way, the function can do whatever dispatching is necessary. 
>>
>> Another thing to think about for this is that some of the existing 
>> rewrite methods are not as expressive as they could be. Consider for 
>> example trig functions. There are several different ways to rewrite 
>> one trig function in terms of another. For example, sin(x) = cos(pi/2 
>> - x) = sqrt(1 - cos(x)**2) = 2*sin(x/2)*cos(x/2) and so on. Right now 
>> sin(x).rewrite(cos) gives cos(x - pi/2), but the other forms could be 
>> useful depending on the context. Is there some way we could design the 
>> API to make it easy for people to pick which form they want to rewrite 
>> to (without having to explicitly remember the identities, which they 
>> could just do manually with replace()). 
>>
>> Aaron Meurer 
>>
>> On Wed, May 12, 2021 at 7:17 AM JSS95 <jeeso...@snu.ac.kr> wrote: 
>> > 
>> > Any idea to improve the API? The first that comes to my mind is 
>> singledispatch, but probably it's an overkill. 
>> > 
>> > Jisoo Song 
>> > 
>> > 2021년 5월 12일 수요일 오후 12시 40분 11초 UTC+9에 asme...@gmail.com님이 작성: 
>> >> 
>> >> I also never liked how rewrite transforms the class name into a string 
>> >> for the method name. That makes it simple to implement for the basic 
>> >> cases, but it limits how expressive it can be. I think we can make a 
>> >> more expressive API which overlaps with the existing one, so that 
>> >> doesn't break compatibility. 
>> >> 
>> >> Aaron Meurer 
>> >> 
>> >> On Tue, May 11, 2021 at 9:10 PM JSS95 <jeeso...@snu.ac.kr> wrote: 
>> >> > 
>> >> > Current Basic.rewrite() allows three types as the rule: a str, a 
>> function class, or a singleton instance. For example, 
>> fibonacci(n).rewrite(S.GoldenRatio) calls 
>> fibonacci(n)._eval_rewrite_as_GoldenRatio which returns the transformed 
>> expression. 
>> >> > 
>> >> > The problem is that current design does not allow non-singleton 
>> instance to be taken as rewrite rule. For example, I want to rewrite a 
>> boolean expression which contains Eq(x, y) so that the equality is 
>> transformed to Q.zero(x, y). expr.rewrite(Q.zero) calls 
>> expr._eval_rewrite_as_Predicate, and I cannot define a logic which 
>> selectively works for Q.zero (but not for Q.real, Q.infinite, etc). 
>> >> > 
>> >> > This will be even more problematic when we introduce functions as 
>> instances. I plan to resolve it by redesigning _eval_refine and 
>> _eval_rewrite_as_[...] methods, but it may break the backwards 
>> compatibility so I would like to hear other opinions first. 
>> >> > 
>> >> > Jisoo Song 
>> >> > 
>> >> > -- 
>> >> > You received this message because you are subscribed to the Google 
>> Groups "sympy" group. 
>> >> > To unsubscribe from this group and stop receiving emails from it, 
>> send an email to sympy+un...@googlegroups.com. 
>> >> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/d980c0ca-1a52-4a48-b0a5-1e959d8ce025n%40googlegroups.com.
>>  
>>
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "sympy" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to sympy+un...@googlegroups.com. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/d2661899-3c47-4523-8a58-29bd36048fddn%40googlegroups.com.
>>  
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/3e80d974-af4d-4fe0-8d26-3315aa7e2164n%40googlegroups.com.

Reply via email to