Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Write the value_equality method.
Given the two expressions ? and ?, first compute the set of variables ? that appear in either ? or ?. Then, the idea consists in performing num_sample times the following test for equality:

  • First, produce a variable assignment (a dictionary) mapping each variable in ? to a random value. Choose these random values from the gaussian distribution centered around 0 and with standard deviation 10 (for instance; any continuous distribution with infinite domain would work). You can obtain such numbers using random.gauss(0, 10).
  • Then, compute the values of ? and ? with respect to that variable evaluation. If the values are closer than a specified tolerance tolerance, you consider ? and ? equal (for that variable valuation). Otherwise, you can stop and return that ? and ? are different.

If you can repeat the process num_sample times, and ? and ? are considered equal every time, then you declare them equal.

WRITE CODE IN PYTHON

### Exercise: implementation of value equality
import random
def value_equality(e, f, num_samples=1000, tolerance=le-6) :
"""Return True if the two expressions self and other are numerically
equivalent.
Equivalence is tested by generating
num_samples assignments, and checking that equality holds
for all of them.
the values of the two expressions have to be closer than tolerance.
Equality is checked up to tolerance, that is,
It can be done in less than 10 lines of code."""
# YOUR CODE HERE
expand button
Transcribed Image Text:### Exercise: implementation of value equality import random def value_equality(e, f, num_samples=1000, tolerance=le-6) : """Return True if the two expressions self and other are numerically equivalent. Equivalence is tested by generating num_samples assignments, and checking that equality holds for all of them. the values of the two expressions have to be closer than tolerance. Equality is checked up to tolerance, that is, It can be done in less than 10 lines of code.""" # YOUR CODE HERE
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education