logo

Demonstrations for the theory of proveit.numbers

In [1]:
import proveit
from proveit import defaults
%begin demonstrations

Demonstration of '..._both_sides' methods for number relations

In [2]:
from proveit import a, b, c, d, x, y
from proveit.logic import Equals, NotEquals, InSet
from proveit.numbers import Add, Mult, Less, LessEq, greater, greater_eq, Real, RealPos, Complex, zero
In [3]:
basic_assumptions = (InSet(a, Real), InSet(b, Real), InSet(c, Real), InSet(d, Real), 
                     InSet(x, Real), InSet(y, Real), 
                     greater(a, zero), greater_eq(b, zero), Less(c, zero), LessEq(d, zero), NotEquals(c, zero))
basic_assumptions:
In [4]:
defaults.assumptions = (*basic_assumptions, Equals(x, y))
defaults.assumptions:
In [5]:
num_rel = Equals(x, y).prove()
num_rel:  ⊢  
In [6]:
help(num_rel.right_add_both_sides)
Help on function right_add_both_sides_of_equals in module proveit.numbers.number_sets.real_numbers.real:

right_add_both_sides_of_equals(relation, addend, **defaults_config)
    Add both sides of the Equals relation by the 'addend'
    on the right.
    
    Keyword arguments are accepted for temporarily changing any
    of the attributes of proveit.defaults.

In [7]:
num_rel = num_rel.right_add_both_sides(b)
num_rel: , , ,  ⊢  
In [8]:
num_rel = num_rel.left_mult_both_sides(a)
num_rel: , , , ,  ⊢  
In [9]:
num_rel = num_rel.right_mult_both_sides(c)
num_rel: , , , , ,  ⊢  
In [10]:
num_rel.divide_both_sides(c)
, , , , , ,  ⊢  
In [11]:
num_rel.divide_both_sides(c, auto_simplify=False)
, , , , , ,  ⊢  
In [12]:
# After implementing some division closure automation, we should be able to get this to work 
#num_rel.square()
In [13]:
num_rel = Equals(x, y)
num_rel = num_rel.square_both_sides()
num_rel: , ,  ⊢  
In [14]:
num_rel.square_root_both_sides(auto_simplify=False)
, ,  ⊢  
In [15]:
num_rel = num_rel.square_root_both_sides()
num_rel: , ,  ⊢  
In [16]:
num_rel.left_add_both_sides(c)
, , ,  ⊢  
In [17]:
defaults.assumptions = (*basic_assumptions, Less(x, y))
defaults.assumptions:
In [18]:
num_rel = Less(x, y).prove()
num_rel:  ⊢  
In [19]:
num_rel = num_rel.left_add_both_sides(a)
num_rel: , , ,  ⊢  
In [20]:
num_rel = num_rel.right_add_both_sides(b)
num_rel: , , , ,  ⊢  
In [21]:
num_rel = num_rel.left_mult_both_sides(c)
num_rel: , , , , , ,  ⊢  
In [22]:
# After implementing NumberRelations for greater and greater_eq (or, better yet,
# Issue #180 which makes 'greater' as a style variant of Less, etc.), this should work
#num_rel.mult_left(d)
In [23]:
num_rel = Less(x, y).prove()
num_rel.left_mult_both_sides(d)
, , , ,  ⊢  
In [24]:
num_rel = Less(x, y).prove()
num_rel.right_mult_both_sides(c)
, , , ,  ⊢  
In [25]:
num_rel = Less(x, y).prove()
num_rel.right_mult_both_sides(d)
, , , ,  ⊢  
In [26]:
num_rel = Less(x, y).prove()
num_rel.divide_both_sides(a)
, , , ,  ⊢  
In [27]:
try:
    num_rel = Less(x, y).prove()
    num_rel.divide_both_sides(b)
    assert False, "Expected Exception"
except Exception as e:
    print("Expected error: ", e)
Expected error:  Cannot divide both sides of x < y by b without knowing the divisors relation to zero.
In [28]:
# Need some work on LesserSequences to get this to work.
#num_rel.square()
In [29]:
defaults.assumptions = (*basic_assumptions, NotEquals(x, y))
defaults.assumptions:
In [30]:
num_rel = NotEquals(x, y).prove()
num_rel:  ⊢  
In [31]:
help(num_rel.divide_both_sides)
Help on function divide_both_sides_of_notequals in module proveit.numbers.number_sets.real_numbers.real:

divide_both_sides_of_notequals(relation, divisor, **defaults_config)
    Divide both sides of the NotEquals relation by the 'divisor'.
    
    Keyword arguments are accepted for temporarily changing any
    of the attributes of proveit.defaults.

In [32]:
num_rel.divide_both_sides(c)
, , , ,  ⊢  
In [33]:
num_rel.left_mult_both_sides(c)
, , , ,  ⊢  

Test deducing bounds through multiple layers of operations

In [34]:
expr = Add(Mult(Add(a, b), Add(b, c)), Mult(Add(x, a), Add(c, y)))
expr:
In [35]:
defaults.assumptions = (InSet(a, RealPos), InSet(b, RealPos), InSet(c, RealPos), InSet(d, RealPos), 
                        InSet(x, RealPos), InSet(y, RealPos),
                        greater(a, d), greater(x, y))
defaults.assumptions:
In [36]:
InSet(Add(b, c), RealPos).prove()
In [37]:
InSet(Add(c, y), RealPos).prove()
In [38]:
expr.deduce_bound(greater(a, d))
, , , , , ,  ⊢  
In [39]:
expr.deduce_bound([greater(a, d), greater(x, y)])
, , , , , , ,  ⊢  
In [40]:
%end demonstrations