
(FPCore (x y) :precision binary64 :pre TRUE (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((1.0d0 - x) * (3.0d0 - x)) / (y * 3.0d0)
end function
public static double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
def code(x, y): return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
function code(x, y) return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0)) end
function tmp = code(x, y) tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0); end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (((1) - x) * ((3) - x)) / (y * (3)) END code
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((1.0d0 - x) * (3.0d0 - x)) / (y * 3.0d0)
end function
public static double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
def code(x, y): return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
function code(x, y) return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0)) end
function tmp = code(x, y) tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0); end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (((1) - x) * ((3) - x)) / (y * (3)) END code
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
(FPCore (x y) :precision binary64 :pre TRUE (* (- x 1.0) (/ (fma x 0.3333333333333333 -1.0) y)))
double code(double x, double y) {
return (x - 1.0) * (fma(x, 0.3333333333333333, -1.0) / y);
}
function code(x, y) return Float64(Float64(x - 1.0) * Float64(fma(x, 0.3333333333333333, -1.0) / y)) end
code[x_, y_] := N[(N[(x - 1.0), $MachinePrecision] * N[(N[(x * 0.3333333333333333 + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x - (1)) * (((x * (333333333333333314829616256247390992939472198486328125e-54)) + (-1)) / y) END code
\left(x - 1\right) \cdot \frac{\mathsf{fma}\left(x, 0.3333333333333333, -1\right)}{y}
Initial program 93.6%
Applied rewrites99.8%
(FPCore (x y) :precision binary64 :pre TRUE (* (/ (- x 3.0) y) (fma x 0.3333333333333333 -0.3333333333333333)))
double code(double x, double y) {
return ((x - 3.0) / y) * fma(x, 0.3333333333333333, -0.3333333333333333);
}
function code(x, y) return Float64(Float64(Float64(x - 3.0) / y) * fma(x, 0.3333333333333333, -0.3333333333333333)) end
code[x_, y_] := N[(N[(N[(x - 3.0), $MachinePrecision] / y), $MachinePrecision] * N[(x * 0.3333333333333333 + -0.3333333333333333), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((x - (3)) / y) * ((x * (333333333333333314829616256247390992939472198486328125e-54)) + (-333333333333333314829616256247390992939472198486328125e-54)) END code
\frac{x - 3}{y} \cdot \mathsf{fma}\left(x, 0.3333333333333333, -0.3333333333333333\right)
Initial program 93.6%
Applied rewrites99.5%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (* (- 1.0 x) (- 3.0 x)) 5.0) (/ (fma -1.3333333333333333 x 1.0) y) (* (- x 3.0) (/ (* 0.3333333333333333 x) y))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 5.0) {
tmp = fma(-1.3333333333333333, x, 1.0) / y;
} else {
tmp = (x - 3.0) * ((0.3333333333333333 * x) / y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 5.0) tmp = Float64(fma(-1.3333333333333333, x, 1.0) / y); else tmp = Float64(Float64(x - 3.0) * Float64(Float64(0.3333333333333333 * x) / y)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 5.0], N[(N[(-1.3333333333333333 * x + 1.0), $MachinePrecision] / y), $MachinePrecision], N[(N[(x - 3.0), $MachinePrecision] * N[(N[(0.3333333333333333 * x), $MachinePrecision] / 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 ((((1) - x) * ((3) - x)) <= (5)) THEN ((((-13333333333333332593184650249895639717578887939453125e-52) * x) + (1)) / y) ELSE ((x - (3)) * (((333333333333333314829616256247390992939472198486328125e-54) * x) / y)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 5:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1.3333333333333333, x, 1\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\left(x - 3\right) \cdot \frac{0.3333333333333333 \cdot x}{y}\\
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 5Initial program 93.6%
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites57.2%
Applied rewrites57.2%
if 5 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.6%
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites50.8%
Applied rewrites50.7%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (* (- 1.0 x) (- 3.0 x)) 5.0) (/ (fma -1.3333333333333333 x 1.0) y) (* (/ (- x 3.0) y) (* 0.3333333333333333 x))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 5.0) {
tmp = fma(-1.3333333333333333, x, 1.0) / y;
} else {
tmp = ((x - 3.0) / y) * (0.3333333333333333 * x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 5.0) tmp = Float64(fma(-1.3333333333333333, x, 1.0) / y); else tmp = Float64(Float64(Float64(x - 3.0) / y) * Float64(0.3333333333333333 * x)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 5.0], N[(N[(-1.3333333333333333 * x + 1.0), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(x - 3.0), $MachinePrecision] / y), $MachinePrecision] * N[(0.3333333333333333 * x), $MachinePrecision]), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF ((((1) - x) * ((3) - x)) <= (5)) THEN ((((-13333333333333332593184650249895639717578887939453125e-52) * x) + (1)) / y) ELSE (((x - (3)) / y) * ((333333333333333314829616256247390992939472198486328125e-54) * x)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 5:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1.3333333333333333, x, 1\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - 3}{y} \cdot \left(0.3333333333333333 \cdot x\right)\\
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 5Initial program 93.6%
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites57.2%
Applied rewrites57.2%
if 5 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.6%
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites50.8%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (* (- 1.0 x) (- 3.0 x)) 50.0) (/ (fma -1.3333333333333333 x 1.0) y) (* (/ x y) (fma x 0.3333333333333333 -0.3333333333333333))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 50.0) {
tmp = fma(-1.3333333333333333, x, 1.0) / y;
} else {
tmp = (x / y) * fma(x, 0.3333333333333333, -0.3333333333333333);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 50.0) tmp = Float64(fma(-1.3333333333333333, x, 1.0) / y); else tmp = Float64(Float64(x / y) * fma(x, 0.3333333333333333, -0.3333333333333333)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 50.0], N[(N[(-1.3333333333333333 * x + 1.0), $MachinePrecision] / y), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x * 0.3333333333333333 + -0.3333333333333333), $MachinePrecision]), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF ((((1) - x) * ((3) - x)) <= (50)) THEN ((((-13333333333333332593184650249895639717578887939453125e-52) * x) + (1)) / y) ELSE ((x / y) * ((x * (333333333333333314829616256247390992939472198486328125e-54)) + (-333333333333333314829616256247390992939472198486328125e-54))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 50:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1.3333333333333333, x, 1\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \mathsf{fma}\left(x, 0.3333333333333333, -0.3333333333333333\right)\\
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 50Initial program 93.6%
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites57.2%
Applied rewrites57.2%
if 50 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.6%
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites50.7%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= x -3.106191387612017) (/ (* -1.3333333333333333 x) y) (/ 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -3.106191387612017) {
tmp = (-1.3333333333333333 * x) / y;
} else {
tmp = 1.0 / y;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.106191387612017d0)) then
tmp = ((-1.3333333333333333d0) * x) / y
else
tmp = 1.0d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.106191387612017) {
tmp = (-1.3333333333333333 * x) / y;
} else {
tmp = 1.0 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.106191387612017: tmp = (-1.3333333333333333 * x) / y else: tmp = 1.0 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.106191387612017) tmp = Float64(Float64(-1.3333333333333333 * x) / y); else tmp = Float64(1.0 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.106191387612017) tmp = (-1.3333333333333333 * x) / y; else tmp = 1.0 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.106191387612017], N[(N[(-1.3333333333333333 * x), $MachinePrecision] / y), $MachinePrecision], N[(1.0 / y), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (x <= (-310619138761201707410464223357848823070526123046875e-50)) THEN (((-13333333333333332593184650249895639717578887939453125e-52) * x) / y) ELSE ((1) / y) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -3.106191387612017:\\
\;\;\;\;\frac{-1.3333333333333333 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y}\\
\end{array}
if x < -3.1061913876120171Initial program 93.6%
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites57.2%
Applied rewrites57.2%
Taylor expanded in x around inf
Applied rewrites9.7%
if -3.1061913876120171 < x Initial program 93.6%
Taylor expanded in x around 0
Applied rewrites51.7%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= x -3.106191387612017) (* (/ x y) -0.3333333333333333) (/ 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -3.106191387612017) {
tmp = (x / y) * -0.3333333333333333;
} else {
tmp = 1.0 / y;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.106191387612017d0)) then
tmp = (x / y) * (-0.3333333333333333d0)
else
tmp = 1.0d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.106191387612017) {
tmp = (x / y) * -0.3333333333333333;
} else {
tmp = 1.0 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.106191387612017: tmp = (x / y) * -0.3333333333333333 else: tmp = 1.0 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.106191387612017) tmp = Float64(Float64(x / y) * -0.3333333333333333); else tmp = Float64(1.0 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.106191387612017) tmp = (x / y) * -0.3333333333333333; else tmp = 1.0 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.106191387612017], N[(N[(x / y), $MachinePrecision] * -0.3333333333333333), $MachinePrecision], N[(1.0 / y), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (x <= (-310619138761201707410464223357848823070526123046875e-50)) THEN ((x / y) * (-333333333333333314829616256247390992939472198486328125e-54)) ELSE ((1) / y) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -3.106191387612017:\\
\;\;\;\;\frac{x}{y} \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y}\\
\end{array}
if x < -3.1061913876120171Initial program 93.6%
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites50.7%
Taylor expanded in x around 0
Applied rewrites9.7%
if -3.1061913876120171 < x Initial program 93.6%
Taylor expanded in x around 0
Applied rewrites51.7%
(FPCore (x y) :precision binary64 :pre TRUE (/ (fma -1.3333333333333333 x 1.0) y))
double code(double x, double y) {
return fma(-1.3333333333333333, x, 1.0) / y;
}
function code(x, y) return Float64(fma(-1.3333333333333333, x, 1.0) / y) end
code[x_, y_] := N[(N[(-1.3333333333333333 * x + 1.0), $MachinePrecision] / y), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (((-13333333333333332593184650249895639717578887939453125e-52) * x) + (1)) / y END code
\frac{\mathsf{fma}\left(-1.3333333333333333, x, 1\right)}{y}
Initial program 93.6%
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites57.2%
Applied rewrites57.2%
(FPCore (x y) :precision binary64 :pre TRUE (/ 1.0 y))
double code(double x, double y) {
return 1.0 / y;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / y
end function
public static double code(double x, double y) {
return 1.0 / y;
}
def code(x, y): return 1.0 / y
function code(x, y) return Float64(1.0 / y) end
function tmp = code(x, y) tmp = 1.0 / y; end
code[x_, y_] := N[(1.0 / y), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (1) / y END code
\frac{1}{y}
Initial program 93.6%
Taylor expanded in x around 0
Applied rewrites51.7%
herbie shell --seed 2026092
(FPCore (x y)
:name "Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3"
:precision binary64
(/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))