
(FPCore (x y) :precision binary64 (/ (* (- 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)
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]
\begin{array}{l}
\\
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (- 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)
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]
\begin{array}{l}
\\
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\end{array}
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 5e+38) (/ (fma x (fma x 0.3333333333333333 -1.3333333333333333) 1.0) y) (* x (* x (/ 0.3333333333333333 y)))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 5e+38) {
tmp = fma(x, fma(x, 0.3333333333333333, -1.3333333333333333), 1.0) / y;
} else {
tmp = x * (x * (0.3333333333333333 / y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 5e+38) tmp = Float64(fma(x, fma(x, 0.3333333333333333, -1.3333333333333333), 1.0) / y); else tmp = Float64(x * Float64(x * Float64(0.3333333333333333 / y))); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 5e+38], N[(N[(x * N[(x * 0.3333333333333333 + -1.3333333333333333), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(x * N[(0.3333333333333333 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 5 \cdot 10^{+38}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.3333333333333333, -1.3333333333333333\right), 1\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 4.9999999999999997e38Initial program 99.4%
Taylor expanded in y around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-rgt-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
if 4.9999999999999997e38 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 86.6%
Taylor expanded in x around inf
*-commutativeN/A
unpow2N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Applied rewrites99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 5.0) (/ (fma -1.3333333333333333 x 1.0) y) (* (fma x 0.3333333333333333 -1.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 = fma(x, 0.3333333333333333, -1.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(fma(x, 0.3333333333333333, -1.3333333333333333) * Float64(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 * 0.3333333333333333 + -1.3333333333333333), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.3333333333333333, -1.3333333333333333\right) \cdot \frac{x}{y}\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 5Initial program 99.5%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
clear-numN/A
frac-timesN/A
lift--.f64N/A
flip--N/A
clear-numN/A
div-invN/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
if 5 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 87.6%
Taylor expanded in x around inf
sub-negN/A
associate-*r/N/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*l/N/A
*-lft-identityN/A
unpow2N/A
associate-/l*N/A
associate-*r*N/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
times-fracN/A
Applied rewrites98.0%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 5.0) (/ (fma -1.3333333333333333 x 1.0) y) (* x (* x (/ 0.3333333333333333 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 * (x * (0.3333333333333333 / 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(x * Float64(x * Float64(0.3333333333333333 / 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[(x * N[(x * N[(0.3333333333333333 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.3333333333333333}{y}\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 5Initial program 99.5%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
clear-numN/A
frac-timesN/A
lift--.f64N/A
flip--N/A
clear-numN/A
div-invN/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
if 5 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 87.6%
Taylor expanded in x around inf
*-commutativeN/A
unpow2N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6496.4
Applied rewrites96.4%
Applied rewrites96.4%
Final simplification97.8%
(FPCore (x y) :precision binary64 (/ (- 1.0 x) (* (/ 3.0 (- 3.0 x)) y)))
double code(double x, double y) {
return (1.0 - x) / ((3.0 / (3.0 - x)) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) / ((3.0d0 / (3.0d0 - x)) * y)
end function
public static double code(double x, double y) {
return (1.0 - x) / ((3.0 / (3.0 - x)) * y);
}
def code(x, y): return (1.0 - x) / ((3.0 / (3.0 - x)) * y)
function code(x, y) return Float64(Float64(1.0 - x) / Float64(Float64(3.0 / Float64(3.0 - x)) * y)) end
function tmp = code(x, y) tmp = (1.0 - x) / ((3.0 / (3.0 - x)) * y); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] / N[(N[(3.0 / N[(3.0 - x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{\frac{3}{3 - x} \cdot y}
\end{array}
Initial program 93.4%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
clear-numN/A
frac-timesN/A
lift--.f64N/A
flip--N/A
clear-numN/A
div-invN/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (* (fma x -0.3333333333333333 1.0) (/ (- 1.0 x) y)))
double code(double x, double y) {
return fma(x, -0.3333333333333333, 1.0) * ((1.0 - x) / y);
}
function code(x, y) return Float64(fma(x, -0.3333333333333333, 1.0) * Float64(Float64(1.0 - x) / y)) end
code[x_, y_] := N[(N[(x * -0.3333333333333333 + 1.0), $MachinePrecision] * N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, -0.3333333333333333, 1\right) \cdot \frac{1 - x}{y}
\end{array}
Initial program 93.4%
Taylor expanded in y around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-rgt-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval93.7
Applied rewrites93.7%
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (if (<= x -0.75) (* -1.3333333333333333 (/ x y)) (/ 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -0.75) {
tmp = -1.3333333333333333 * (x / y);
} else {
tmp = 1.0 / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.75d0)) 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 <= -0.75) {
tmp = -1.3333333333333333 * (x / y);
} else {
tmp = 1.0 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.75: tmp = -1.3333333333333333 * (x / y) else: tmp = 1.0 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -0.75) tmp = Float64(-1.3333333333333333 * Float64(x / y)); else tmp = Float64(1.0 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.75) tmp = -1.3333333333333333 * (x / y); else tmp = 1.0 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.75], N[(-1.3333333333333333 * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(1.0 / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75:\\
\;\;\;\;-1.3333333333333333 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y}\\
\end{array}
\end{array}
if x < -0.75Initial program 88.6%
Taylor expanded in x around 0
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-fma.f6430.8
Applied rewrites30.8%
Taylor expanded in x around inf
Applied rewrites30.8%
if -0.75 < x Initial program 95.1%
Taylor expanded in x around 0
lower-/.f6466.3
Applied rewrites66.3%
(FPCore (x y) :precision binary64 (/ (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]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(-1.3333333333333333, x, 1\right)}{y}
\end{array}
Initial program 93.4%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
clear-numN/A
frac-timesN/A
lift--.f64N/A
flip--N/A
clear-numN/A
div-invN/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites56.6%
(FPCore (x y) :precision binary64 (/ 1.0 y))
double code(double x, double y) {
return 1.0 / y;
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\frac{1}{y}
\end{array}
Initial program 93.4%
Taylor expanded in x around 0
lower-/.f6450.5
Applied rewrites50.5%
(FPCore (x y) :precision binary64 (* (/ (- 1.0 x) y) (/ (- 3.0 x) 3.0)))
double code(double x, double y) {
return ((1.0 - x) / y) * ((3.0 - x) / 3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((1.0d0 - x) / y) * ((3.0d0 - x) / 3.0d0)
end function
public static double code(double x, double y) {
return ((1.0 - x) / y) * ((3.0 - x) / 3.0);
}
def code(x, y): return ((1.0 - x) / y) * ((3.0 - x) / 3.0)
function code(x, y) return Float64(Float64(Float64(1.0 - x) / y) * Float64(Float64(3.0 - x) / 3.0)) end
function tmp = code(x, y) tmp = ((1.0 - x) / y) * ((3.0 - x) / 3.0); end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision] * N[(N[(3.0 - x), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{y} \cdot \frac{3 - x}{3}
\end{array}
herbie shell --seed 2024216
(FPCore (x y)
:name "Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (* (/ (- 1 x) y) (/ (- 3 x) 3)))
(/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))