Charles-Johnson / zia_programming

A language that can program itself
https://zia-lang.org
GNU General Public License v3.0
3 stars 0 forks source link

integers #19

Open Charles-Johnson opened 3 years ago

Charles-Johnson commented 3 years ago

Integers can be encoded as let 1 := successor_of 0, let 2 := successor_of 1 etc. and let -1 := predecessor_of 0, let -2 := predecessor_of -1 etc.

0, successor_of, predecessor_of would be concrete concepts

Charles-Johnson commented 2 years ago

If a new concrete concept stack is created so that e.g. 'abc' := stack 'a' , 'b' , 'c', multi digit numbers can be labeled, given a base

let assoc , -> left
let _x_ is a natural number => label_of _x_ -> map label_of digits_of _x_
let map _f_( _x_ , _y_) -> map _f_ _x_ , _f_ _y_
let map _f_ stack _x_ -> stack _x_
let 0 is a natural number
let _x_ is a natural number => _x_ +1 is a natural number
let digits_of 0 -> 0
let _x_ > base => digits_of _x_ / base , digits_of _x_ -> _x_ % base
let base > _x_ => digits_of _x_ -> stack  _x_
Charles-Johnson commented 2 years ago

% and / can be defined with the following commands

let _y_ % _y_ -> 0
let _x_ is a natural number and _y_ is a natural number and _x_ > _y_ => _x_ % _y_ -> (_x_ - _y_) % _y
let _x_ is a natural number and _y_ is a natural number and _y_ > _x_ => _x_ % _y_ -> _x_
let _x_ > _y_ => (_x_ +1) - (_y_ +1) -> _x_ - _y_
let (_x_ +1) > _x_
let _x_ > _y_ => _x_ / _y_ -> ((_x_ - _y_) / _y_) +1
let _y_ / _y_ => 0 +1
let _x_ is a natural number and _y_ is a natural number and _y_ > _x_=> _x_ / _y_ -> 0