Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Symbolic number constructor and conversion #602

Closed
wants to merge 1 commit into from

Conversation

bowenszhu
Copy link
Member

@bowenszhu bowenszhu commented May 25, 2024

This pull request adds a constructor and a conversion function for Symbolic objects representing numbers.

Key changes:

  • Symbolic constructor:

    • The Symbolic(x::T) where {T<:Number} constructor now creates a Term object from a number x, inferring the type of the Symbolic object from the type of x.
    • The Symbolic{T}(x::Number) where {T} constructor now creates a Term object with the specified type T, converting x to that type if necessary.
  • convert function:

    • The convert(::Type{<:Symbolic{T}}, x::Number) where {T} function now converts a number x to a Term object of the specified type T.
  • Tests:

    • The test suite now includes tests for the Symbolic constructor and convert function, ensuring correct behavior for various numeric types, including Int, Float64, Rational, and Complex.
    • The test suite also includes a test case demonstrating how the convert function works when assigning a number to an array of Symbolic.

These changes provide a more convenient and flexible way to create and work with symbolic representations of numbers, and hide the internal Symbolic subtype system from external users.

Copy link
Contributor

github-actions bot commented May 25, 2024

Benchmark Results

master dfec04e... master/dfec04ec7c5196...
overhead/acrule/a+2 0.713 ± 0.016 μs 0.735 ± 0.017 μs 0.97
overhead/acrule/a+2+b 0.691 ± 0.015 μs 0.71 ± 0.018 μs 0.974
overhead/acrule/a+b 0.26 ± 0.0091 μs 0.255 ± 0.013 μs 1.02
overhead/acrule/noop:Int 25.9 ± 0.059 ns 24.7 ± 0.92 ns 1.05
overhead/acrule/noop:Sym 0.0363 ± 0.0056 μs 0.0421 ± 0.006 μs 0.863
overhead/rule/noop:Int 0.044 ± 0.0012 μs 0.0438 ± 0.0014 μs 1
overhead/rule/noop:Sym 0.0546 ± 0.0024 μs 0.0542 ± 0.0022 μs 1.01
overhead/rule/noop:Term 0.0544 ± 0.0024 μs 0.0545 ± 0.0016 μs 0.997
overhead/ruleset/noop:Int 0.132 ± 0.0037 μs 0.132 ± 0.0045 μs 0.999
overhead/ruleset/noop:Sym 0.155 ± 0.0051 μs 0.154 ± 0.0033 μs 1.01
overhead/ruleset/noop:Term 3.8 ± 0.14 μs 3.77 ± 0.14 μs 1.01
overhead/simplify/noop:Int 0.141 ± 0.0031 μs 0.138 ± 0.0031 μs 1.02
overhead/simplify/noop:Sym 0.154 ± 0.0029 μs 0.152 ± 0.0025 μs 1.01
overhead/simplify/noop:Term 0.038 ± 0.0019 ms 0.0377 ± 0.0023 ms 1.01
overhead/simplify/randterm (+, *):serial 0.117 ± 0.0034 s 0.119 ± 0.004 s 0.985
overhead/simplify/randterm (+, *):thread 0.0723 ± 0.021 s 0.0741 ± 0.024 s 0.975
overhead/simplify/randterm (/, *):serial 0.221 ± 0.005 ms 0.223 ± 0.0061 ms 0.987
overhead/simplify/randterm (/, *):thread 0.252 ± 0.0056 ms 0.252 ± 0.0069 ms 1
overhead/substitute/a 0.0609 ± 0.0014 ms 0.0603 ± 0.0014 ms 1.01
overhead/substitute/a,b 0.0534 ± 0.0014 ms 0.052 ± 0.0013 ms 1.03
overhead/substitute/a,b,c 17.5 ± 0.57 μs 16.3 ± 0.61 μs 1.07
polyform/easy_iszero 0.0337 ± 0.0016 ms 0.0341 ± 0.0017 ms 0.989
polyform/isone 3.1 ± 0.01 ns 2.79 ± 0.01 ns 1.11
polyform/iszero 1.79 ± 0.03 ms 1.8 ± 0.032 ms 0.993
polyform/simplify_fractions 2.41 ± 0.038 ms 2.4 ± 0.04 ms 1
time_to_load 4.52 ± 0.014 s 4.53 ± 0.029 s 0.999

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@bowenszhu bowenszhu force-pushed the b/symbolic_number_conversion branch 5 times, most recently from 093fbbe to 8fb2c41 Compare May 25, 2024 04:55
@bowenszhu bowenszhu force-pushed the b/symbolic_number_conversion branch from 8fb2c41 to dfec04e Compare May 25, 2024 05:03
@bowenszhu
Copy link
Member Author

I'm closing this pull request because we've decided to implement the feature using a different approach that will be more efficient and scalable. I'll create a new pull request for this alternative solution soon.

@bowenszhu bowenszhu closed this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Casts from float64, int64, to symbolic types are missing Simplifying construstion of symbolic numbers
1 participant