logicuit 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c670278d5f0547d3b3acdaa0f828731de1351c1d4148c2df2b57bae5a43a199
4
- data.tar.gz: f84a271fd5df3767035f77ba196a84638a5214d52b71cd7151c81b18162709a5
3
+ metadata.gz: 39f6a3f233ed3a159f05332a47d1d882051ad7e9e2102f51c3375883fe366755
4
+ data.tar.gz: ef51eb6f22d2b3f4e0f0073c16644ec9f8ee3e798626826f7abde59399714363
5
5
  SHA512:
6
- metadata.gz: 95e3514d3a0327f43becf3066a5a9ad6ecf4dcc51af6af0dfcbf1475fe055faaa715925878422fdc268c261006ea66514b7f6ad90a721c5f0f193cd66104231a
7
- data.tar.gz: 39f1237f88d0bcf06d8aed9b08d9e9fd0c7b6f9659c8b6843c8c320382aff5a249f82c2e180a508fb3e9dac14f7eef04d02f6ed2037d14481d6abf2b8fdd3cc6
6
+ metadata.gz: 6bfd774f4cadd41f070ec5c6cff8d2116775dfe6812ffd070c54478266756945b78426a2e89f3bea176008619930bc46387533a43376bc40a0c5f6ae49ac753c
7
+ data.tar.gz: 743a5e0ec704913583b98191320e1acde0d0332f8953f09ab88def5e8c162d5cd5130985e61f194c9fca295520816ffc024931f52ae859d6f2732278a67a6ac2
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Logicuit
4
+ module Circuits
5
+ module Combinational
6
+ # A Multiplexer with 4 inputs and 1 output
7
+ class Multiplexer4To1 < Base
8
+ define_inputs :c0, :c1, :c2, :c3, :b, :a
9
+
10
+ define_outputs y: lambda { |c0, c1, c2, c3, b, a|
11
+ (c0 && !b && !a) || (c1 && !b && a) || (c2 && b && !a) || (c3 && b && a)
12
+ }
13
+
14
+ diagram <<~DIAGRAM
15
+ (C0)---------------|
16
+ +---|AND|---+
17
+ | +-| |
18
+ | | |
19
+ (C1)---------------| +-|
20
+ +---|AND|-+ |
21
+ +-----------| +---|
22
+ | | | |OR|--(Y)
23
+ (C2)---------------| +---|
24
+ +-------------|AND|-+ |
25
+ | | | +-| +-|
26
+ | | | | |
27
+ (C3)---------------| |
28
+ +-------------|AND|---+
29
+ | +-----------|
30
+ | | | |
31
+ (B)--+---|NOT|-+ |
32
+ | |
33
+ (A)----+-|NOT|---+
34
+ DIAGRAM
35
+
36
+ truth_table <<~TRUTH_TABLE
37
+ | B | A | C0 | C1 | C2 | C3 | Y |
38
+ | - | - | -- | -- | -- | -- | - |
39
+ | 0 | 0 | 0 | x | x | x | 0 |
40
+ | 0 | 0 | 1 | x | x | x | 1 |
41
+ | 0 | 1 | x | 0 | x | x | 0 |
42
+ | 0 | 1 | x | 1 | x | x | 1 |
43
+ | 1 | 0 | x | x | 0 | x | 0 |
44
+ | 1 | 0 | x | x | 1 | x | 1 |
45
+ | 1 | 1 | x | x | x | 0 | 0 |
46
+ | 1 | 1 | x | x | x | 1 | 1 |
47
+ TRUTH_TABLE
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Logicuit
4
+ module Gates
5
+ # NAND gate
6
+ class Nand < Base
7
+ define_inputs :a, :b
8
+
9
+ define_outputs y: ->(a, b) { !(a && b) }
10
+
11
+ diagram <<~DIAGRAM
12
+ (A)-|
13
+ |NAND|-(Y)
14
+ (B)-|
15
+ DIAGRAM
16
+
17
+ truth_table <<~TRUTH_TABLE
18
+ | A | B | Y |
19
+ | - | - | - |
20
+ | 0 | 0 | 1 |
21
+ | 1 | 0 | 1 |
22
+ | 0 | 1 | 1 |
23
+ | 1 | 1 | 0 |
24
+ TRUTH_TABLE
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Logicuit
4
+ module Gates
5
+ # XOR gate
6
+ class Xor < Base
7
+ define_inputs :a, :b
8
+
9
+ define_outputs y: ->(a, b) { (a && !b) || (!a && b) }
10
+
11
+ diagram <<~DIAGRAM
12
+ (A)-|
13
+ |XOR|-(Y)
14
+ (B)-|
15
+ DIAGRAM
16
+
17
+ truth_table <<~TRUTH_TABLE
18
+ | A | B | Y |
19
+ | - | - | - |
20
+ | 0 | 0 | 0 |
21
+ | 1 | 0 | 1 |
22
+ | 0 | 1 | 1 |
23
+ | 1 | 1 | 0 |
24
+ TRUTH_TABLE
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Logicuit
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/logicuit.rb CHANGED
@@ -5,8 +5,11 @@ require_relative "logicuit/base"
5
5
  require_relative "logicuit/gates/and"
6
6
  require_relative "logicuit/gates/or"
7
7
  require_relative "logicuit/gates/not"
8
+ require_relative "logicuit/gates/nand"
9
+ require_relative "logicuit/gates/xor"
8
10
  require_relative "logicuit/signals/signal"
9
11
  require_relative "logicuit/signals/clock"
10
12
  require_relative "logicuit/circuits/sequential/d_flip_flop"
11
13
  require_relative "logicuit/circuits/combinational/multiplexer2to1"
14
+ require_relative "logicuit/circuits/combinational/multiplexer4to1"
12
15
  require_relative "logicuit/circuits/system_level/one_bit_cpu"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logicuit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji NAKAMURA
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-09 00:00:00.000000000 Z
10
+ date: 2025-03-12 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: logi(c cir)cuit -> logicuit
13
13
  email:
@@ -24,11 +24,14 @@ files:
24
24
  - lib/logicuit/base.rb
25
25
  - lib/logicuit/circuits/combinational/half_adder.rb
26
26
  - lib/logicuit/circuits/combinational/multiplexer2to1.rb
27
+ - lib/logicuit/circuits/combinational/multiplexer4to1.rb
27
28
  - lib/logicuit/circuits/sequential/d_flip_flop.rb
28
29
  - lib/logicuit/circuits/system_level/one_bit_cpu.rb
29
30
  - lib/logicuit/gates/and.rb
31
+ - lib/logicuit/gates/nand.rb
30
32
  - lib/logicuit/gates/not.rb
31
33
  - lib/logicuit/gates/or.rb
34
+ - lib/logicuit/gates/xor.rb
32
35
  - lib/logicuit/signals/clock.rb
33
36
  - lib/logicuit/signals/signal.rb
34
37
  - lib/logicuit/version.rb