Class: Z3::ArithExpr

Inherits:
Expr show all
Defined in:
lib/z3/expr/arith_expr.rb

Direct Known Subclasses

IntExpr, RealExpr

Instance Attribute Summary

Attributes inherited from Expr

#sort

Attributes inherited from AST

#_ast

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#!=, #==, Add, And, Distinct, Eq, Ge, Gt, Le, Lt, Mul, Or, Sub, Xor, coerce_to_same_sort, #initialize, #inspect, new_from_pointer, sort_for_const

Methods inherited from AST

#arguments, #ast_kind, #func_decl, #initialize, #sexpr, #simplify, #to_s

Constructor Details

This class inherits a constructor from Z3::Expr

Class Method Details

.coerce_to_same_arith_sort(*args) ⇒ Object

Raises:



53
54
55
56
57
# File 'lib/z3/expr/arith_expr.rb', line 53

def coerce_to_same_arith_sort(*args)
  args = coerce_to_same_sort(*args)
  raise Z3::Exception, "Int or Real value expected" unless args[0].is_a?(IntExpr) or args[0].is_a?(RealExpr)
  args
end

.Div(a, b) ⇒ Object



59
60
61
62
# File 'lib/z3/expr/arith_expr.rb', line 59

def Div(a,b)
  a, b = coerce_to_same_arith_sort(a, b)
  a.sort.new(LowLevel.mk_div(a, b))
end

.Power(a, b) ⇒ Object



64
65
66
67
68
# File 'lib/z3/expr/arith_expr.rb', line 64

def Power(a, b)
  # Wait, is this even legitimate that it's I**I and R**R?
  a, b = coerce_to_same_arith_sort(a, b)
  a.sort.new(LowLevel.mk_power(a, b))
end

Instance Method Details

#*(other) ⇒ Object



11
12
13
# File 'lib/z3/expr/arith_expr.rb', line 11

def *(other)
  Expr.Mul(self, other)
end

#**(other) ⇒ Object



19
20
21
# File 'lib/z3/expr/arith_expr.rb', line 19

def **(other)
  ArithExpr.Power(self, other)
end

#+(other) ⇒ Object



3
4
5
# File 'lib/z3/expr/arith_expr.rb', line 3

def +(other)
  Expr.Add(self, other)
end

#-(other) ⇒ Object



7
8
9
# File 'lib/z3/expr/arith_expr.rb', line 7

def -(other)
  Expr.Sub(self, other)
end

#-@Object



39
40
41
# File 'lib/z3/expr/arith_expr.rb', line 39

def -@
  sort.new(LowLevel.mk_unary_minus(self))
end

#/(other) ⇒ Object



15
16
17
# File 'lib/z3/expr/arith_expr.rb', line 15

def /(other)
  ArithExpr.Div(self, other)
end

#<(other) ⇒ Object



35
36
37
# File 'lib/z3/expr/arith_expr.rb', line 35

def <(other)
  Expr.Lt(self, other)
end

#<=(other) ⇒ Object



31
32
33
# File 'lib/z3/expr/arith_expr.rb', line 31

def <=(other)
  Expr.Le(self, other)
end

#>(other) ⇒ Object



23
24
25
# File 'lib/z3/expr/arith_expr.rb', line 23

def >(other)
  Expr.Gt(self, other)
end

#>=(other) ⇒ Object



27
28
29
# File 'lib/z3/expr/arith_expr.rb', line 27

def >=(other)
  Expr.Ge(self, other)
end

#coerce(other) ⇒ Object

Recast so 1 + x:Float is: (+ 1.0 x) not: (+ (to_real 1) x)



46
47
48
49
50
# File 'lib/z3/expr/arith_expr.rb', line 46

def coerce(other)
  other_sort = Expr.sort_for_const(other)
  max_sort = [sort, other_sort].max
  [max_sort.from_const(other), max_sort.from_value(self)]
end