programlibs/Equations/demos/symbols.xtl

source · imports e: libs/Equations/src/Equations.xtl libs/Equations/src/Equations.xtlm

W : Int

value · line 8
W ← 2 3 r̲eshape 1 2 3 4 5 6                    ⍝ weights: 2 outputs, 3 inputs
Used in: z

x : Int

value · line 9
x ← 1 0 -1                                     ⍝ the input
Used in: z

b : Int

value · line 10
b ← 10 20                                      ⍝ the bias
Used in: z

z : Int

value · line 11
z ←  ᵉe̲q< z_{i} = \left(\sum_{j=0}^{2} W_{i,j} \, x_{j}\right) + b_{i}
ᵉe̲q< expands to
(({ @ →
  g3:a̲t ← { A i → (1 + i) s̲elect r̲avel A }
  g2:c̲heck ← { (A, name, k, from) e →
    n ← k s̲elect s̲hape A
    bad ← w̲here n̲ot r̲avel (0 ≤ e) ∧ e < n
    0 = t̲ally bad ? e
    "index" ⎕S̲IGNAL name c̲at " axis " c̲at (f̲ormat k) c̲at ": index " c̲at (f̲ormat (f̲irst bad) s̲elect r̲avel e) c̲at " is outside 0.." c̲at (f̲ormat n − 1) c̲at " (from " c̲at from c̲at ")"
  }
  g1:r̲ank ← { (A, name, q, ref) →
    (t̲ally s̲hape A) = q ? A
    "rank" ⎕S̲IGNAL ref c̲at " indexes " c̲at (f̲ormat q) c̲at " axes, but " c̲at name c̲at " has rank " c̲at f̲ormat t̲ally s̲hape A
  }
  g4:grid ← 2
  g5:g̲rid ← { k → g4:grid r̲eshape (o̲ffsets k s̲elect g4:grid) 'l̲eft t̲able ('× r̲/ k d̲rop g4:grid) r̲eshape 0 }
  g4:grid r̲eshape ((({ @ →
  g6:grid ← 2 c̲at ({ v → (0 ≤ v) ? v◆ "bad-equation" ⎕S̲IGNAL "sum's range runs low..high: 0..2" } (1 + 2 − 0))
  g7:g̲rid ← { k → g6:grid r̲eshape (o̲ffsets k s̲elect g6:grid) 'l̲eft t̲able ('× r̲/ k d̲rop g6:grid) r̲eshape 0 }
  '+ r̲/₂ g6:grid r̲eshape ((
    ((g1:r̲ank (W, "W", 2, "W[i,j]")) g3:a̲t ((
      ((W, "W", 2, "j") g2:c̲heck (0 + g7:g̲rid 2)) + (2 s̲elect s̲hape W) × 
      ((W, "W", 1, "i") g2:c̲heck (0 + g7:g̲rid 1))))) × 
    ((g1:r̲ank (x, "x", 1, "x[j]")) g3:a̲t (
      ((x, "x", 1, "j") g2:c̲heck (0 + g7:g̲rid 2))))))
} @) + 
    ((g1:r̲ank (b, "b", 1, "b[i]")) g3:a̲t (
      ((b, "b", 1, "i") g2:c̲heck (0 + g5:g̲rid 1))))))
} @))