@@ -341,4 +341,90 @@ using Symbolics.SymbolicUtils: Term
341341 end
342342 end
343343
344+ # ============================================================================
345+ # Feature 063: Fix TypeError when converting power expressions (issue #1)
346+ # ============================================================================
347+ @testset " Feature 063: to_giac power expressions" begin
348+ @variables a x y
349+
350+ # US1: Basic power expressions
351+ @testset " US1: to_giac(a^2) — issue #1 reproducer" begin
352+ result = to_giac (a^ 2 )
353+ @test result isa GiacExpr
354+ @test occursin (" a" , string (result))
355+ @test occursin (" ^" , string (result)) || occursin (" 2" , string (result))
356+ end
357+
358+ @testset " US1: to_giac(x^3) — other integer exponents" begin
359+ result = to_giac (x^ 3 )
360+ @test result isa GiacExpr
361+ @test occursin (" x" , string (result))
362+ end
363+
364+ @testset " US1: to_giac(x^2 + y^2) — sum of squares" begin
365+ result = to_giac (x^ 2 + y^ 2 )
366+ @test result isa GiacExpr
367+ result_str = string (result)
368+ @test occursin (" x" , result_str)
369+ @test occursin (" y" , result_str)
370+ end
371+
372+ # US2: Compound expressions
373+ @testset " US2: to_giac(sin(x)^2) — function with power" begin
374+ result = to_giac (sin (x)^ 2 )
375+ @test result isa GiacExpr
376+ result_str = string (result)
377+ @test occursin (" sin" , result_str)
378+ end
379+
380+ @testset " US2: to_giac(x^2 * y) — power with multiplication" begin
381+ result = to_giac (x^ 2 * y)
382+ @test result isa GiacExpr
383+ result_str = string (result)
384+ @test occursin (" x" , result_str)
385+ @test occursin (" y" , result_str)
386+ end
387+
388+ @testset " US2: to_giac((x + y)^2) — power of sum" begin
389+ result = to_giac ((x + y)^ 2 )
390+ @test result isa GiacExpr
391+ result_str = string (result)
392+ @test occursin (" x" , result_str)
393+ @test occursin (" y" , result_str)
394+ end
395+
396+ # US2: Edge cases
397+ @testset " US2: edge cases — a^0, a^(-1), a^b" begin
398+ @variables b
399+
400+ result_zero = to_giac (a^ 0 )
401+ @test result_zero isa GiacExpr
402+
403+ result_neg = to_giac (a^ (- 1 ))
404+ @test result_neg isa GiacExpr
405+
406+ result_sym = to_giac (a^ b)
407+ @test result_sym isa GiacExpr
408+ result_str = string (result_sym)
409+ @test occursin (" a" , result_str)
410+ @test occursin (" b" , result_str)
411+ end
412+
413+ # US3: Roundtrip conversion
414+ @testset " US3: roundtrip to_symbolics(to_giac(a^2))" begin
415+ original = a^ 2
416+ roundtrip = to_symbolics (to_giac (original))
417+ @test roundtrip isa Num
418+ # Verify mathematical equivalence by substituting a value
419+ @test Symbolics. substitute (roundtrip, Dict (a => 3 )) == Symbolics. substitute (original, Dict (a => 3 ))
420+ end
421+
422+ @testset " US3: roundtrip to_symbolics(to_giac(x^2 + y))" begin
423+ original = x^ 2 + y
424+ roundtrip = to_symbolics (to_giac (original))
425+ @test roundtrip isa Num
426+ @test Symbolics. substitute (roundtrip, Dict (x => 2 , y => 5 )) == Symbolics. substitute (original, Dict (x => 2 , y => 5 ))
427+ end
428+ end
429+
344430end # @testset "Symbolics Extension"
0 commit comments