⍝ Polynomials.tc
⍝═══════════════

)COPY_ONCE 0 ASSERT.apl
³   ⍝ e.g. NEW )COPY_ONCE workspace: ASSERT.apl
³   ⍝ e.g. DUMPED 2023-03-22  20:07:13 (GMT+1) 


      ⍝ ⌹.poly_print...

      ⍝ one indeterminant x
      ⍝
      "A:"    (⌹.poly_print A ← 4 0 0 6 3 1)
 A: x⁵ + 3x⁴ + 6x³ + 4 

      "B:"    (⌹.poly_print B ← 5 0 2)
 B: 2x² + 5 

      "PROD:" (⌹.poly_print PROD ← A ⌹.poly_multiply B)
 PROD: 2x⁷ + 6x⁶ + 17x⁵ + 15x⁴ + 30x³ + 8x² + 20 

      ⍝ two indeterminants x and y
      ⍝
      "A:"    (⌹.poly_print A ← 2 2⍴0 1 1 0)
 A: x + y 

      "B:"    (⌹.poly_print B ← 2 2⍴0 ¯1 1 0)
 B: x - y 

      "PROD:" (⌹.poly_print PROD ← A ⌹.poly_multiply B)
 PROD: x² - y² 

      ⍝ ⌹.poly_scan...
      ⍝ check that ⌹.poly_scan is the inverse of ⌹.poly_print
      ⍝
∇POLY_CHECK B
 ⍝ verify that ⌹.poly_print is the inverse of ⌹.poly_scan
 ⍝ requires that the indeterminants in B are sorted properly
 ⍝
 ASSERT B ≡ ⌹.poly_print (⌹.poly_scan B)
∇

      POLY_CHECK ¨ "0" "1" "2" "¯2"
      POLY_CHECK ¨ "x" "y" "z"
      POLY_CHECK ¨ "-x" "-y" "-z"
      POLY_CHECK ¨ "x + 1" "y + 1" "z + 1"
      POLY_CHECK ¨ "x - 1" "y - 1" "z - 1"
      POLY_CHECK ¨ "x - 2" "y - 2" "z - 2"
      POLY_CHECK ¨ "xy + x + 1" "y² - 1" "xyz - xz² + 1"

      )ERASE A B PROD Q POLY_CHECK
      )CHECK BRIEF

