Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, F

Percentage Accurate: 99.6% → 99.6%
Time: 2.3s
Alternatives: 2
Speedup: 1.0×

Specification

?
\[\left(x \cdot 27\right) \cdot y \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (* x 27.0) y))
double code(double x, double y) {
	return (x * 27.0) * y;
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * 27.0d0) * y
end function
public static double code(double x, double y) {
	return (x * 27.0) * y;
}
def code(x, y):
	return (x * 27.0) * y
function code(x, y)
	return Float64(Float64(x * 27.0) * y)
end
function tmp = code(x, y)
	tmp = (x * 27.0) * y;
end
code[x_, y_] := N[(N[(x * 27.0), $MachinePrecision] * y), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x * (27)) * y
END code
\left(x \cdot 27\right) \cdot y

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 2 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.6% accurate, 1.0× speedup?

\[\left(x \cdot 27\right) \cdot y \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (* x 27.0) y))
double code(double x, double y) {
	return (x * 27.0) * y;
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * 27.0d0) * y
end function
public static double code(double x, double y) {
	return (x * 27.0) * y;
}
def code(x, y):
	return (x * 27.0) * y
function code(x, y)
	return Float64(Float64(x * 27.0) * y)
end
function tmp = code(x, y)
	tmp = (x * 27.0) * y;
end
code[x_, y_] := N[(N[(x * 27.0), $MachinePrecision] * y), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x * (27)) * y
END code
\left(x \cdot 27\right) \cdot y

Alternative 1: 99.6% accurate, 0.5× speedup?

\[\left(\mathsf{min}\left(x, y\right) \cdot 27\right) \cdot \mathsf{max}\left(x, y\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (* (fmin x y) 27.0) (fmax x y)))
double code(double x, double y) {
	return (fmin(x, y) * 27.0) * fmax(x, y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (fmin(x, y) * 27.0d0) * fmax(x, y)
end function
public static double code(double x, double y) {
	return (fmin(x, y) * 27.0) * fmax(x, y);
}
def code(x, y):
	return (fmin(x, y) * 27.0) * fmax(x, y)
function code(x, y)
	return Float64(Float64(fmin(x, y) * 27.0) * fmax(x, y))
end
function tmp = code(x, y)
	tmp = (min(x, y) * 27.0) * max(x, y);
end
code[x_, y_] := N[(N[(N[Min[x, y], $MachinePrecision] * 27.0), $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	LET tmp = IF (x < y) THEN x ELSE y ENDIF IN
	LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN
	(tmp * (27)) * tmp_1
END code
\left(\mathsf{min}\left(x, y\right) \cdot 27\right) \cdot \mathsf{max}\left(x, y\right)
Derivation
  1. Initial program 99.6%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Add Preprocessing

Alternative 2: 99.6% accurate, 1.0× speedup?

\[27 \cdot \left(x \cdot y\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* 27.0 (* x y)))
double code(double x, double y) {
	return 27.0 * (x * y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 27.0d0 * (x * y)
end function
public static double code(double x, double y) {
	return 27.0 * (x * y);
}
def code(x, y):
	return 27.0 * (x * y)
function code(x, y)
	return Float64(27.0 * Float64(x * y))
end
function tmp = code(x, y)
	tmp = 27.0 * (x * y);
end
code[x_, y_] := N[(27.0 * N[(x * y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(27) * (x * y)
END code
27 \cdot \left(x \cdot y\right)
Derivation
  1. Initial program 99.6%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Taylor expanded in x around 0

    \[\leadsto 27 \cdot \left(x \cdot y\right) \]
  3. Step-by-step derivation
    1. Applied rewrites99.6%

      \[\leadsto 27 \cdot \left(x \cdot y\right) \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2026092 
    (FPCore (x y)
      :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, F"
      :precision binary64
      (* (* x 27.0) y))