Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – manipulating expressions


Enter the following code into an input cell in a worksheet, and evaluate the cell:

var('x, y')
expr = (y - 7) / (x^2 + 1) == x^3 - 5
print("Expression:")
expr.show()

print("Two ways of multiplying both sides:")
show(expr.multiply_both_sides(x^2 + 1))
show(expr * (x^2 + 1))
# also divide_both_sides

expr = expr * (x^2 + 1)

print("Two ways of adding to both sides:")
show(expr.add_to_both_sides(7))
show(expr+7)
# also subtract_from_both_sides

The results are shown in the following screenshot:

What just happened?

This example showed how to perform one of the most basic algebraic re-arrangements: performing the same operation on both sides of a relation. We can do this by using methods of the symbolic expression object (add_to_both_sides, subtract_from_both_sides, multiply_both_sides, divide_both_sides). We can also use the arithmetic operators +, -, *, and / to perform the same operation on both sides of a relation. Note that these operations return...