
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (* (cos y) (+ x (* z (tan y)))))
double code(double x, double y, double z) {
return cos(y) * (x + (z * tan(y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = cos(y) * (x + (z * tan(y)))
end function
public static double code(double x, double y, double z) {
return Math.cos(y) * (x + (z * Math.tan(y)));
}
def code(x, y, z): return math.cos(y) * (x + (z * math.tan(y)))
function code(x, y, z) return Float64(cos(y) * Float64(x + Float64(z * tan(y)))) end
function tmp = code(x, y, z) tmp = cos(y) * (x + (z * tan(y))); end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * N[(x + N[(z * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot \left(x + z \cdot \tan y\right)
\end{array}
Initial program 99.8%
flip-+N/A
fmm-defN/A
*-commutativeN/A
div-subN/A
--lowering--.f64N/A
Applied egg-rr41.3%
Taylor expanded in z around 0
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
cos-lowering-cos.f64N/A
/-lowering-/.f64N/A
Simplified99.1%
+-commutativeN/A
Applied egg-rr99.5%
distribute-rgt-outN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
associate-/l*N/A
*-lowering-*.f64N/A
quot-tanN/A
tan-lowering-tan.f64N/A
cos-lowering-cos.f6499.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= y -1.45e+178)
(* x (cos y))
(if (<= y -0.23)
t_0
(if (<= y 435.0)
(+
x
(* y (+ z (* y (+ (* x -0.5) (* z (* y -0.16666666666666666)))))))
t_0)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (y <= -1.45e+178) {
tmp = x * cos(y);
} else if (y <= -0.23) {
tmp = t_0;
} else if (y <= 435.0) {
tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666))))));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = z * sin(y)
if (y <= (-1.45d+178)) then
tmp = x * cos(y)
else if (y <= (-0.23d0)) then
tmp = t_0
else if (y <= 435.0d0) then
tmp = x + (y * (z + (y * ((x * (-0.5d0)) + (z * (y * (-0.16666666666666666d0)))))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.sin(y);
double tmp;
if (y <= -1.45e+178) {
tmp = x * Math.cos(y);
} else if (y <= -0.23) {
tmp = t_0;
} else if (y <= 435.0) {
tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666))))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) tmp = 0 if y <= -1.45e+178: tmp = x * math.cos(y) elif y <= -0.23: tmp = t_0 elif y <= 435.0: tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666)))))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (y <= -1.45e+178) tmp = Float64(x * cos(y)); elseif (y <= -0.23) tmp = t_0; elseif (y <= 435.0) tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(Float64(x * -0.5) + Float64(z * Float64(y * -0.16666666666666666))))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); tmp = 0.0; if (y <= -1.45e+178) tmp = x * cos(y); elseif (y <= -0.23) tmp = t_0; elseif (y <= 435.0) tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666)))))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.45e+178], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -0.23], t$95$0, If[LessEqual[y, 435.0], N[(x + N[(y * N[(z + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(z * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{+178}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq -0.23:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 435:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5 + z \cdot \left(y \cdot -0.16666666666666666\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.45e178Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6466.1%
Simplified66.1%
if -1.45e178 < y < -0.23000000000000001 or 435 < y Initial program 99.7%
Taylor expanded in x around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6459.4%
Simplified59.4%
if -0.23000000000000001 < y < 435Initial program 100.0%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6498.6%
Simplified98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -8e+127) t_0 (if (<= x 1.12e+86) (+ x (* z (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -8e+127) {
tmp = t_0;
} else if (x <= 1.12e+86) {
tmp = x + (z * sin(y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (x <= (-8d+127)) then
tmp = t_0
else if (x <= 1.12d+86) then
tmp = x + (z * sin(y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -8e+127) {
tmp = t_0;
} else if (x <= 1.12e+86) {
tmp = x + (z * Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -8e+127: tmp = t_0 elif x <= 1.12e+86: tmp = x + (z * math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -8e+127) tmp = t_0; elseif (x <= 1.12e+86) tmp = Float64(x + Float64(z * sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -8e+127) tmp = t_0; elseif (x <= 1.12e+86) tmp = x + (z * sin(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8e+127], t$95$0, If[LessEqual[x, 1.12e+86], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -8 \cdot 10^{+127}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{+86}:\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.99999999999999964e127 or 1.12e86 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6492.2%
Simplified92.2%
if -7.99999999999999964e127 < x < 1.12e86Initial program 99.9%
Taylor expanded in y around 0
Simplified88.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.02)
t_0
(if (<= y 0.205)
(+ x (* y (+ z (* y (+ (* x -0.5) (* z (* y -0.16666666666666666)))))))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.02) {
tmp = t_0;
} else if (y <= 0.205) {
tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666))))));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-0.02d0)) then
tmp = t_0
else if (y <= 0.205d0) then
tmp = x + (y * (z + (y * ((x * (-0.5d0)) + (z * (y * (-0.16666666666666666d0)))))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (y <= -0.02) {
tmp = t_0;
} else if (y <= 0.205) {
tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666))))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.02: tmp = t_0 elif y <= 0.205: tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666)))))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.02) tmp = t_0; elseif (y <= 0.205) tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(Float64(x * -0.5) + Float64(z * Float64(y * -0.16666666666666666))))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -0.02) tmp = t_0; elseif (y <= 0.205) tmp = x + (y * (z + (y * ((x * -0.5) + (z * (y * -0.16666666666666666)))))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.02], t$95$0, If[LessEqual[y, 0.205], N[(x + N[(y * N[(z + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(z * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.02:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.205:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5 + z \cdot \left(y \cdot -0.16666666666666666\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0200000000000000004 or 0.204999999999999988 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6447.9%
Simplified47.9%
if -0.0200000000000000004 < y < 0.204999999999999988Initial program 100.0%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= z -4.6e+54) (* y z) (if (<= z 3e+168) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+54) {
tmp = y * z;
} else if (z <= 3e+168) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4.6d+54)) then
tmp = y * z
else if (z <= 3d+168) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+54) {
tmp = y * z;
} else if (z <= 3e+168) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.6e+54: tmp = y * z elif z <= 3e+168: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.6e+54) tmp = Float64(y * z); elseif (z <= 3e+168) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.6e+54) tmp = y * z; elseif (z <= 3e+168) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.6e+54], N[(y * z), $MachinePrecision], If[LessEqual[z, 3e+168], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+54}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+168}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.59999999999999988e54 or 2.9999999999999998e168 < z Initial program 99.8%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6452.0%
Simplified52.0%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f6436.1%
Simplified36.1%
if -4.59999999999999988e54 < z < 2.9999999999999998e168Initial program 99.9%
Taylor expanded in y around 0
Simplified48.9%
Final simplification44.2%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6452.7%
Simplified52.7%
Final simplification52.7%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Simplified37.3%
herbie shell --seed 2024161
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))