Ask Your Question

Revision history [back]

Enumerating solutions to linear system of equations with inequalities

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a set of linear equations. However, the "linear equations" can be a mixture of equalities and inequalities depending on the situation. I'll use a classic math textbook problem to illustrate.

Assume you have a collection of pennies, nickels, and dimes. Further, you want to identify all combinations of coins that sum to an exact value of >= 10 cents AND <= 15 cents. Here are two twists: you will only select from 5 to 7 coins, and only nickels and dimes will contribute to the wanted value. Assume you have more than 7 of each type of coin.

In the equations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the equations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (set notation used for pennies to conserve space):

pennies = [4,6], nickels = 0, dimes = 1
pennies = [3,5], nickels = 1, dimes = 1
pennies = [3,5], nickels = 2, dimes = 0
pennies = [2,4], nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes>=5)
sage: coins_min = (pennies+nickels+dimes<=7)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear system of equations with inequalities

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a set of linear equations. However, the "linear equations" can be a mixture of equalities and inequalities depending on the situation. I'll use a classic math textbook problem to illustrate.

Assume you have a collection of pennies, nickels, and dimes. Further, you want to identify all combinations of coins that sum to an exact value of >= 10 cents AND <= 15 cents. Here are two twists: you will only select from 5 to 7 coins, and only nickels and dimes will contribute to the wanted value. Assume you have more than 7 of each type of coin.

In the equations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the equations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (set (range notation used for pennies to conserve space):

pennies = [4,6], range(4,7), nickels = 0, dimes = 1
pennies = [3,5], range(3,6), nickels = 1, dimes = 1
pennies = [3,5], range(3,6), nickels = 2, dimes = 0
pennies = [2,4], range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes>=5)
sage: coins_min = (pennies+nickels+dimes<=7)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear equations with inequalities

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a set system of linear equations. However, the "linear equations" can be a mixture of equalities and inequalities depending on the situation. I'll use a classic math textbook problem to illustrate.

Assume you have a collection of pennies, nickels, and dimes. Further, you want to identify all combinations of coins that sum to an exact value of >= 10 cents AND <= 15 cents. Here are two twists: you will only select from 5 to 7 coins, and only nickels and dimes will contribute to the wanted value. Assume you have more than 7 of each type of coin.

In the equations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the equations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (range notation used for pennies to conserve space):

pennies = range(4,7), nickels = 0, dimes = 1
pennies = range(3,6), nickels = 1, dimes = 1
pennies = range(3,6), nickels = 2, dimes = 0
pennies = range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

pennies,nickels,dimes = var('pennies,nickels,dimes')
coins_max = (pennies+nickels+dimes>=5)
coins_min = (pennies+nickels+dimes<=7)
value_max = (5*nickels+10*dimes<=15)
value_min = (5*nickels+10*dimes>=10)
assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear equations with inequalitiesrelations

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a system of linear equations. However, the "linear equations" can relations. Depending on the situation, the system may be composed entirely of equalities, entirely of non-equalities, or a mixture of equalities and inequalities depending on the situation. the two. I'll use a classic math textbook problem to illustrate.

Assume you have a collection of pennies, nickels, and dimes. Further, you want to identify all combinations of coins that sum to an exact value of >= 10 cents AND <= 15 cents. Here are two twists: you will only select from between 5 to and 7 coins, coins (inclusive), and only nickels and dimes will contribute to the wanted value. Assume you have more than 7 of each type of coin.

In the equations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the equations relations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (range notation used for pennies to conserve space):

pennies = range(4,7), nickels = 0, dimes = 1
pennies = range(3,6), nickels = 1, dimes = 1
pennies = range(3,6), nickels = 2, dimes = 0
pennies = range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes>=5)
sage: coins_min = (pennies+nickels+dimes<=7)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear relations

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a system of linear relations. Depending on the situation, the system may might be composed entirely of equalities, entirely of non-equalities, or a mixture of the two. mixture. I'll use a classic math textbook problem exercise to illustrate.

Assume you You have a collection of pennies, nickels, and dimes. Further, you You want to identify know all combinations of coins that sum to an exact value of >= at least 10 cents AND <= cents, but no more than 15 cents. Here are two twists: you You will select between 5 and 7 coins (inclusive), and only nickels and dimes will contribute to the wanted value. sum. Assume you have more than 7 of each type of coin.

In the equations relations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the relations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (range notation used for pennies to conserve space):

pennies = range(4,7), nickels = 0, dimes = 1
pennies = range(3,6), nickels = 1, dimes = 1
pennies = range(3,6), nickels = 2, dimes = 0
pennies = range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes>=5)
sage: coins_min = (pennies+nickels+dimes<=7)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear relations

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use sagemath to identify all integer solutions to a system of linear relations. Depending on the situation, the system might be entirely equalities, entirely non-equalities, or a mixture. I'll use a classic math exercise to illustrate.

You have a collection of pennies, nickels, and dimes. You want to know all combinations of coins that sum to at least 10 cents, but no more than 15 cents. You will select between 5 and 7 coins (inclusive), and only nickels and dimes will contribute to the wanted sum. Assume you have more than 7 of each type of coin.

In the relations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the relations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this system (range notation used for pennies to conserve space):

pennies = range(4,7), nickels = 0, dimes = 1
pennies = range(3,6), nickels = 1, dimes = 1
pennies = range(3,6), nickels = 2, dimes = 0
pennies = range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce a list of dictionary solutions for all positive integer solutions. For example:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes<=7)
sage: coins_min = (pennies+nickels+dimes>=5)
sage: coins_min = (pennies+nickels+dimes<=7)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's another function I should call to process the results into a list of integer solutions, or if I have to write my own.

I'm hoping someone can point me in the right direction. Thank you for your time.

Enumerating solutions to a system of linear relations

Hi, I'm new to sagemath, and I've been away from math courses for a while now. Please be patient with me! :)

I'm trying to use I want to feed sagemath to identify a system of linear relations. I'd like sagemath to give back all positive integer solutions to a system of linear relations. Depending on the situation, the system might be entirely equalities, entirely non-equalities, or a mixture. the system. I'll use a classic math exercise to illustrate.

You have a collection of pennies, nickels, and dimes. You want to know Find all combinations of coins that sum to at least 10 cents, but no more than 15 cents. You will select Select between 5 and 7 coins (inclusive), and only (inclusive). Only nickels and dimes will contribute to the wanted sum. Assume you have more than 7 of each type of coin.

In the relations below, 'pennies', 'nickels', and 'dimes' represent the number of coins from the respective denomination. So, the relations are:

pennies + nickels + dimes >= 5
pennies + nickels + dimes <= 7
5*nickels + 10*dimes >= 10
5*nickels + 10*dimes <= 15

There are many solutions to this I'd like sagemath to process the above system (range notation used for pennies to conserve space):

pennies = range(4,7), nickels = 0, dimes = 1
pennies = range(3,6), nickels = 1, dimes = 1
pennies = range(3,6), nickels = 2, dimes = 0
pennies = range(2,5), nickels = 3, dimes = 0

I want to know if sagemath can produce into a list of dictionary solutions for all positive integer solutions. For example:similar to:

[
  { pennies: 4, nickels: 0, dimes: 1 },
  { pennies: 5, nickels: 0, dimes: 1 },
  { pennies: 6, nickels: 0, dimes: 1 },
  { pennies: 3, nickels: 1, dimes: 1 },
  ...
  { pennies: 4, nickels: 3, dimes: 0 }
]

This is what I've tried in sagemath so far:tried:

sage: pennies,nickels,dimes = var('pennies,nickels,dimes')
sage: coins_max = (pennies+nickels+dimes<=7)
sage: coins_min = (pennies+nickels+dimes>=5)
sage: value_max = (5*nickels+10*dimes<=15)
sage: value_min = (5*nickels+10*dimes>=10)
sage: assume( pennies>=0, pennies<=7, nickels>=0, nickels<=7, dimes>=0, dimes<=7 )
sage: coin_solve = solve( [coins_max, coins_min, value_max, value_min], pennies, nickels, dimes, solution_dict=True )
sage: print coin_solve
[
  {-2*pennies + 8: nickels, dimes: -1/2*nickels + 1, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, dimes: -1/2*nickels + 3/2, nickels: -2*pennies + 11},
  {-2*pennies + 7: nickels, dimes: -nickels - pennies + 5, nickels: -2*pennies + 8},
  {-2*pennies + 11: nickels, dimes: -nickels - pennies + 7, nickels: -2*pennies + 12},
  {-2*pennies + 7: nickels, max(-1/2*nickels + 1, -nickels - pennies + 5): dimes, dimes: min(-1/2*nickels + 3/2, -nickels - pennies + 7), nickels: -2*pennies + 12},
  {pennies: dimes + 3, nickels: -2*dimes + 2},
  {pennies: dimes + 5, nickels: -2*dimes + 2},
  {pennies: dimes + 2, nickels: -2*dimes + 3},
  {pennies: dimes + 4, nickels: -2*dimes + 3}
]

This is where my unfamiliarity with sagemath becomes a problem. I don't know if solve() is the right approach, if there's approach. Do I need another function to further process solve()'s results? Do I should call to process the results into a list of integer solutions, or if I have need to write my own.own?

I'm hoping someone can point me in the right direction. Thank you for your time.