Skip to content

Instantly share code, notes, and snippets.

@hwayne
Created April 17, 2020 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hwayne/5f46378dc05411c53759700eef140844 to your computer and use it in GitHub Desktop.
Save hwayne/5f46378dc05411c53759700eef140844 to your computer and use it in GitHub Desktop.
Taxes
//assumes no tax overrides
//assumes no tax can replace another tax
sig Location {} //states, cities
sig Category {}
sig Item {
, category: some Category
}
enum TaxRate {Percent, Flat}
sig Tax { //should probably have a general rules interface
, cost: TaxRate
, rules: some Rule
} //set means that a tax would ALWAYS apply if no rules
abstract sig Rule {}
sig LocationRule extends Rule {
rule: Location
}
sig CategoryRule extends Rule {
rule: some Category
} // can apply if Category A OR B
sig CountRule extends Rule {
rule: Int
} {rule > 0}
fact "One locationrule per location" {
LocationRule.rule = Location
#LocationRule = #Location
}
fact "Tax type restrictions" {
//no so far?!
}
pred tax_applies[t: Tax, i: Item] {
all r: t.rules |
r.rule_applies[i]
}
pred rule_applies[r: Rule, i: Item] {
r in LocationRule => r.rule_location[i] else
r in CategoryRule => r.rule_category[i] else
r in CountRule => r.rule_count[i]
}
pred rule_location[r: LocationRule, i: Item] {
r.rule in Cart.address
}
pred rule_category[r: CategoryRule, i: Item] {
i.category in r.rule
}
pred rule_count[r: CountRule, i: Item] {
Cart.contents[i] <= r.rule
}
one sig Cart {
, contents: set (Item -> lone Int) //gotta have to pay
//question: Int -> Item or Item -> Int???
, address: some Location // city in state etc
} {
no i: Item.contents | i <= 0
}
run {some t: Tax, i: Item | #t.rules > 1 and t.tax_applies[i]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment