# Rewriting sin, cos, tan in terms of tan(x/2): halftan

### 5.23.19 Rewriting sin, cos, tan in terms of tan(x/2): halftan

The halftan command rewrites the trigonometric functions in terms of tan(x/2) using the identities:

sin(x)

=

2tan

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

tan2

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

+1

cos(x)

=

1−tan2

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

tan2

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

+1

tan(x)

=

2tan

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

1−tan2

⎛
⎜
⎜
⎝

x
2

⎞
⎟
⎟
⎠

- halftan takes one argument:
  expr, an expression containing trigonometric functions.
- halftan(expr) returns expr with any trigonometric functions replaced by the appropriate expression of tan(x/2).

#### Examples.

- Input:
  halftan(sin(2*x)/(1+cos(2*x)))
  Output:

  2tan

  ⎛
  ⎜
  ⎜
  ⎝

  2
  2

  x

  ⎞
  ⎟
  ⎟
  ⎠

  ⎛
  ⎜
  ⎜
  ⎝

  tan2

  ⎛
  ⎜
  ⎜
  ⎝

  2
  2

  x

  ⎞
  ⎟
  ⎟
  ⎠

  +1

  ⎞
  ⎟
  ⎟
  ⎠

  ⎛
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎝

  1+

  1−tan2

  ⎛
  ⎜
  ⎜
  ⎝

  2
  2

  x

  ⎞
  ⎟
  ⎟
  ⎠

  tan2

  ⎛
  ⎜
  ⎜
  ⎝

  2
  2

  x

  ⎞
  ⎟
  ⎟
  ⎠

  +1

  ⎞
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎠

  Output (after simplification with normal(ans())):

  tanx

- Input:
  halftan(sin(x)^2+cos(x)^2)
  Output:

  ⎛
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎝

  2 tan

  ⎛
  ⎜
  ⎜
  ⎝

  x
  2

  ⎞
  ⎟
  ⎟
  ⎠

  tan2

  ⎛
  ⎜
  ⎜
  ⎝

  x
  2

  ⎞
  ⎟
  ⎟
  ⎠

  +1

  ⎞
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎠

  2

  +

  ⎛
  ⎜
  ⎜
  ⎜
  ⎜
  ⎜
  ⎝

  1−tan2

  ⎛
  ⎜
  ⎜
  ⎝

  x
  2

  ⎞
  ⎟
  ⎟
  ⎠

  tan2

  ⎛
  ⎜
  ⎜
  ⎝

  x
  2

  ⎞
  ⎟
  ⎟
  ⎠

  +1

  ⎞
  ⎟
  ⎟
  ⎟
  ⎟
  ⎟
  ⎠

  2

  Output (after simplification with normal(ans())):

  1