# Transistor

**Transistor** is one of those languages User:Rdococ likes to create once in a galactic year. It's about the fundamental building blocks of today's computing (assuming you're not reading this in the future when quantum computing has become widespread or in the past due to time travel).

## Contents

## The Three State Boolean

There are three boolean states in **Transistor**: true, false, and a floating or high impedance value we will call **floating**.

## Boring things first

Variables and loops and stuff.

let x = true // local variable definition let y = false let z = floating circuit id (a) { return a } circuit id2 (a, b) { return {id1 = a, id2 = b} // Multiple outputs in one function, like actual circuits, for convenience } let test = id2(true, false).id1 let a = true let b = true let c = true while (a) { // this code always runs three times. first time, c becomes false. second time, b becomes false. third time, a becomes false. a = or(b, c) // variable assignment b = c c = false }

## The Transistors

The Transistors are a pair of functions, both of which take in two inputs, A and B. The first function, TN, represents an N-type transistor. It returns B if A is true, and the high impedance value otherwise. The second function, TP, represents a P-type transistor, returning B if A is false. If A is the high impedance value, B will be one too.

## The Resistors

The Resistors are another pair of functions that takes in one input A and returns A - unless it is a high impedance value, which then it either returns false (as in the first function labeled RF) or true (RT).

## Examples

### And Gate

circuit and (a, b) { return RF(TN(b, TN(a, true))) }

If either A or B is false, one of the transistors will report a high impedance value and thus the whole program returns false.

### Not Gate

circuit not (a) { return RF(TP(a, true)) }

If A is true, then the result will be false. Otherwise, the result will be true.

### Or Gate

circuit and (a, b) { return RT(TP(b, TP(a, false))) }

If either A or B is true, one of the transistors will report a high impedance value and the whole program returns true. Replacing the TN with TP is equivalent to inverting A and B, and swapping RT for RT and false for true is equivalent to inverting the result, making this equivalent to **not ((not A) and (not B))**, which resolves to **A or B**.

### Adders

This one assumes you've defined the above, along with xor and numbers as boolean arrays. *n*.i*m* is the mth bit of n.

circuit add1 (a, b) { let a0 = a.i0 let b0 = b.i0 return {i0 = xor(a0, b0), i1 = and(a0, b0)} } circuit add2 (a, b) { let a0 = a.i0 let a1 = a.i1 let b0 = b.i0 let b1 = b.i1 return {i0 = xor(a0, b0), i1 = xor(and(a0, b0), xor(a1, b1)), i2 = or(and(a1, b1), and(and(a0, b0), xor(a1, b1)) )} }

## Turing Completeness?

idk and idc. if you care and wanna know, prove or disprove it here before admitting yourself to a mental hospital. (I'm joking, of course. I used to want turing completeness in my languages and I didn't admit myself to one)