casey/simp_rules.rb

24 lines
655 B
Ruby
Raw Permalink Normal View History

2023-05-09 21:20:50 -04:00
# frozen_string_literal: true
require 'rule'
class SimpRules
@@simp_rules = []
def self.register(rule)
@@simp_rules.push(rule)
end
def self.register_new(*args)
register(rule(*args))
end
end
SimpRules.register_new('one_plus_one', [1, :+, 1] => 2)
SimpRules.register_new('add_zero', [:x, :+, 0] => :x).forall(:x)
SimpRules.register_new('zero_add', [0, :+, :x] => :x).forall(:x)
SimpRules.register_new('mul_one', [:x, :*, 1] => :x).forall(:x)
SimpRules.register_new('one_mul', [1, :*, :x] => :x).forall(:x)
SimpRules.register_new('mul_zero', [:x, :*, 0] => 0).forall(:x)
SimpRules.register_new('zero_mul', [0, :*, :x] => 0).forall(:x)