Mode of #cas

trigExpand

Expands sines and cosines of sums, differences and double angles, with a theorem about Mathlib’s sine and cosine.

#cas [trigExpand] e
expands the sines and cosines of sums, differences and double angles in e and proves that the expansion equals e.

trigExpand applies the angle-addition formulas to sines and cosines, so that their products can be expanded and simplified. The theorem is an identity about Real.sin and Real.cos for all real values of the variables, so it needs no conditions.

It applies six formulas and nothing else, which keeps it predictable: you can tell from the input what the output will be. For identities that need more, such as sin2x+cos2x=1 or a triple angle, I use fullSimplify or the tactic cas.

Details and Options

  • The theorem is ∀x1,…,xn,e=e′ about Real.sin and Real.cos, where e′ is the printed expansion, proved by the addition and double-angle formulas.
  • The formulas are those for sin (a + b), cos (a + b), sin (a - b), cos (a - b), sin (2 * a) and cos (2 * a). The double angle of the cosine is written cos2a−sin2a.
  • Other expressions, such as sin (3 * x) or x ^ 2, are printed unchanged, and the theorem is then the trivial identity.
  • It plays the part of Mathematica’s TrigExpand and SymPy’s expand_trig for these formulas.
  • expand does not look inside functions. fullSimplify counts the trigonometric expansion among its candidates and keeps the smallest form.
  • There are no options.

Examples (11)#

Basic Examples (2)

The sine of a sum:

In[1]:=
#cas [trigExpand] (sin (x + y))
Out[1]=
sin(x)cos(y)+cos(x)sin(y)
sin(x)*cos(y) + cos(x)*sin(y)

Checked by Lean’s kernel: Identity with the trigonometric expansion

∀ (x y : ℝ), Real.sin (x + y) = Real.sin x * Real.cos y + Real.cos x * Real.sin y
The certificate: 1 checked step
  1. Identity with the trigonometric expansion

    ∀ (x y : ℝ), Real.sin (x + y) = Real.sin x * Real.cos y + Real.cos x * Real.sin y

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    trigonometric expansion: sin(x)*cos(y) + cos(x)*sin(y)  [leafCount 11, conditions 0]
    input: sin(x + y)  [leafCount 4, conditions 0]

The cosine of a double angle:

In[2]:=
#cas [trigExpand] (cos (2*x))
Out[2]=
cos2(x)−sin2(x)
cos(x)^2 - sin(x)^2

Checked by Lean’s kernel: Identity with the trigonometric expansion

∀ (x : ℝ), Real.cos (2 * x) = Real.cos x ^ 2 - Real.sin x ^ 2
The certificate: 1 checked step
  1. Identity with the trigonometric expansion

    ∀ (x : ℝ), Real.cos (2 * x) = Real.cos x ^ 2 - Real.sin x ^ 2

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    trigonometric expansion: cos(x)^2 - sin(x)^2  [leafCount 9, conditions 0]
    input: cos(2*x)  [leafCount 4, conditions 0]

Scope (1)

A difference and a double angle in one product. Each factor is expanded:

In[3]:=
#cas [trigExpand] (cos (x - y) * sin (2 * y))
Out[3]=
(cos(x)cos(y)+sin(x)sin(y))(2sin(y)cos(y))
(cos(x)*cos(y) + sin(x)*sin(y))*(2*sin(y)*cos(y))

Checked by Lean’s kernel: Identity with the trigonometric expansion

∀ (x y : ℝ),
  Real.cos (x - y) * Real.sin (2 * y) =
    (Real.cos x * Real.cos y + Real.sin x * Real.sin y) * (2 * Real.sin y * Real.cos y)
The certificate: 1 checked step
  1. Identity with the trigonometric expansion

    ∀ (x y : ℝ),
      Real.cos (x - y) * Real.sin (2 * y) =
        (Real.cos x * Real.cos y + Real.sin x * Real.sin y) * (2 * Real.sin y * Real.cos y)

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    trigonometric expansion: (cos(x)*cos(y) + sin(x)*sin(y))*(2*sin(y)*cos(y))  [leafCount 19, conditions 0]
    input: cos(x - y)*sin(2*y)  [leafCount 9, conditions 0]

Applications (3)

The addition formula as a theorem, for all real x and y. Only the three standard axioms are used:

In[4]:=
theorem sin_add_expanded (x y : ℝ) :
    Real.sin (x + y) = Real.sin x * Real.cos y + Real.cos x * Real.sin y := by
  cas

#print axioms sin_add_expanded
Out[4]=

sin_add_expanded depends on the axioms propext, Classical.choice, Quot.sound.


The tactic cas proves the other forms of the double-angle formula, which also need sin2x+cos2x=1:

In[5]:=
example (x : ℝ) : Real.cos (2 * x) = 1 - 2 * Real.sin x ^ 2 := by
  cas
Out[5]=

Lean accepts the proof.


A product of a sum and a difference:

In[6]:=
example (x y : ℝ) :
    Real.sin (x + y) * Real.sin (x - y) = Real.sin x ^ 2 - Real.sin y ^ 2 := by
  cas
Out[6]=

Lean accepts the proof.

Properties and Relations (2)

expand leaves the argument of a function alone:

In[7]:=
#cas [expand] (sin (x + y))
Out[7]=
sin(x+y)
sin(x + y)

Checked by Lean’s kernel: Identity with the input

∀ (x y : ℝ), Real.sin (x + y) = Real.sin (x + y)
The certificate: 1 checked step
  1. Identity with the input

    ∀ (x y : ℝ), Real.sin (x + y) = Real.sin (x + y)

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    input: sin(x + y)  [leafCount 4, conditions 0]

fullSimplify tries the trigonometric expansion with the other candidates, so it finds identities that reduce to 0:

In[8]:=
#cas [fullSimplify] (sin (2*x) - 2*sin x*cos x)
Out[8]=
0

Checked by Lean’s kernel: Identity with the trigonometric expansion and simplification

∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0
The certificate: 1 checked step
  1. Identity with the trigonometric expansion and simplification

    ∀ (x : ℝ), Real.sin (2 * x) - 2 * Real.sin x * Real.cos x = 0

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    trigonometric expansion and simplification: 0  [leafCount 1, conditions 0]
    input: sin(2*x) - 2*sin(x)*cos(x)  [leafCount 12, conditions 0]
    configured simplification: sin(2*x) - 2*(sin(x)*cos(x))  [leafCount 12, conditions 0]
    trigonometric expansion: 2*sin(x)*cos(x) - 2*sin(x)*cos(x)  [leafCount 15, conditions 0]
In[9]:=
#cas [fullSimplify] (cos x ^ 2 - sin x ^ 2 - cos (2*x))
Out[9]=
0

Checked by Lean’s kernel: Identity with the trigonometric expansion and simplification

∀ (x : ℝ), Real.cos x ^ 2 - Real.sin x ^ 2 - Real.cos (2 * x) = 0
The certificate: 1 checked step
  1. Identity with the trigonometric expansion and simplification

    ∀ (x : ℝ), Real.cos x ^ 2 - Real.sin x ^ 2 - Real.cos (2 * x) = 0

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    trigonometric expansion and simplification: 0  [leafCount 1, conditions 0]
    configured simplification: 1 + -2*sin(x)^2 - cos(2*x)  [leafCount 13, conditions 0]
    input: cos(x)^2 - sin(x)^2 - cos(2*x)  [leafCount 14, conditions 0]
    exact passes: cos(x)^2 + -sin(x)^2 - cos(2*x)  [leafCount 16, conditions 0]
    trigonometric expansion: cos(x)^2 - sin(x)^2 - (cos(x)^2 - sin(x)^2)  [leafCount 19, conditions 0]

Possible Issues (3)

A multiple angle other than a double angle is not expanded, and the report proves the trivial identity sin3x=sin3x:

In[10]:=
#cas [trigExpand] (sin (3*x))
Out[10]=
sin(3x)
sin(3*x)

Checked by Lean’s kernel: Identity with the input

∀ (x : ℝ), Real.sin (3 * x) = Real.sin (3 * x)
The certificate: 1 checked step
  1. Identity with the input

    ∀ (x : ℝ), Real.sin (3 * x) = Real.sin (3 * x)

    Checked by Lean’s kernel

The computation
  • Ranked candidates (proposals, not proof)

    input: sin(3*x)  [leafCount 4, conditions 0]

The tactic cas proves the triple-angle formula:

In[11]:=
example (x : ℝ) : Real.cos (3 * x) = 4 * Real.cos x ^ 3 - 3 * Real.cos x := by
  cas
Out[11]=

Lean accepts the proof.


A false identity is refused. Here sin2x=2sinx fails at x=π/2, where the left side is 0 and the right side is 2. The refusal proves nothing: the message says that the statement may be false or outside what cas supports:

In[12]:=
example (x : ℝ) : Real.sin (2 * x) = 2 * Real.sin x := by
  cas
Out[12]=

Error

cas could not prove this arithmetic relation. The statement may be false, or it may lie outside the supported normalization and arithmetic fragment
The rest of the message
Polynomial equation route:
  `grind` failed
  case grind
  x : ℝ
  h : ¬Real.sin (2 * x) = 2 * Real.sin x
  ⊢ False
  [grind] Goal diagnostics
    [facts] Asserted facts
      [prop] ¬Real.sin (2 * x) = 2 * Real.sin x
    [eqc] False propositions
      [prop] Real.sin (2 * x) = 2 * Real.sin x
    [limits] Thresholds reached
      [limit] maximum number of E-matching rounds has been reached, threshold: `(ematch := 0)`
      [limit] maximum number of case-splits has been reached, threshold: `(splits := 0)`
Checked identity route:
  cas could not identify the two sides: the checked normalizer does not reduce their difference to zero.
  Normalized difference:
    ((CAS.Verified.Expr.nat 2).mul 𝕏[0]).sin.add ((CAS.Verified.Expr.int (-2)).mul 𝕏[0].sin)
  canonical form route: the canonical rational form of the difference is not zero.
  Canonical difference:
    ((CAS.Verified.Expr.int (-2)).mul 𝕏[0].sin).add ((CAS.Verified.Expr.nat 2).mul 𝕏[0]).sin
Elementary rewrite route:
  after the elementary rewrites, neither the arithmetic script nor polynomial reasoning modulo sin² + cos² = 1 proved the goal:
    linarith failed to find a contradiction
    case h1
    x : ℝ
    a✝ : 2 * Real.sin x * Real.cos x < 2 * Real.sin x
    ⊢ False
    failed
  
    `grind` failed
    case grind
    x : ℝ
    hcasPolynomialEquation : Real.sin x ^ 2 + Real.cos x ^ 2 = 1
    h : ¬Real.sin x * Real.cos x = Real.sin x
    ⊢ False
    [grind] Goal diagnostics
      [facts] Asserted facts
        [prop] Real.sin x ^ 2 + Real.cos x ^ 2 = 1
        [prop] ¬Real.sin x * Real.cos x = Real.sin x
      [eqc] False propositions
        [prop] Real.sin x * Real.cos x = Real.sin x
      [eqc] Equivalence classes
        [eqc] {1,
            Real.sin x ^ 2 + Real.cos x ^ 2,
            (Real.sin x * Real.cos x - Real.sin x) * (Real.sin x * Real.cos x - Real.sin x)⁻¹}
      [ematch] E-matching patterns
        [thm] Nat.pow_pos: [@HPow.hPow `[ℕ] `[ℕ] `[ℕ] `[instHPow] #2 #1]
        [thm] Nat.div_pow_of_pos: [@HPow.hPow `[ℕ] `[ℕ] `[ℕ] `[instHPow] #2 #1]
      [ring] Ring `ℝ`
        [basis] Basis
          [_] Real.cos x ^ 3 * (Real.sin x * Real.cos x - Real.sin x)⁻¹ +
                        -1 * (Real.cos x ^ 2 * (Real.sin x * Real.cos x - Real.sin x)⁻¹) +
                      -1 * (Real.cos x * (Real.sin x * Real.cos x - Real.sin x)⁻¹) +
                    Real.sin x +
                  (Real.sin x * Real.cos x - Real.sin x)⁻¹ =
                0
          [_] Real.sin x * Real.cos x * (Real.sin x * Real.cos x - Real.sin x)⁻¹ +
                    -1 * (Real.sin x * (Real.sin x * Real.cos x - Real.sin x)⁻¹) +
                  -1 =
                0
          [_] Real.sin x ^ 2 + Real.cos x ^ 2 + -1 = 0
      [limits] Thresholds reached
        [limit] maximum number of E-matching rounds has been reached, threshold: `(ematch := 0)`
        [limit] maximum number of case-splits has been reached, threshold: `(splits := 0)`
Grind fallback:
  `grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)

See Also

expand · fullSimplify · simplify · cas