
(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 7 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 (if (or (<= z -1.45e-176) (not (<= z 1.35e-35))) (- (* x 1.0) (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e-176) || !(z <= 1.35e-35)) {
tmp = (x * 1.0) - (z * sin(y));
} else {
tmp = cos(y) * x;
}
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 <= (-1.45d-176)) .or. (.not. (z <= 1.35d-35))) then
tmp = (x * 1.0d0) - (z * sin(y))
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e-176) || !(z <= 1.35e-35)) {
tmp = (x * 1.0) - (z * Math.sin(y));
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.45e-176) or not (z <= 1.35e-35): tmp = (x * 1.0) - (z * math.sin(y)) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e-176) || !(z <= 1.35e-35)) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.45e-176) || ~((z <= 1.35e-35))) tmp = (x * 1.0) - (z * sin(y)); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e-176], N[Not[LessEqual[z, 1.35e-35]], $MachinePrecision]], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-176} \lor \neg \left(z \leq 1.35 \cdot 10^{-35}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -1.45000000000000003e-176 or 1.3499999999999999e-35 < z Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites87.4%
if -1.45000000000000003e-176 < z < 1.3499999999999999e-35Initial program 99.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6452.5
Applied rewrites52.5%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6490.8
Applied rewrites90.8%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.43) (not (<= x 1.6e-110))) (* (cos y) x) (* (- z) (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.43) || !(x <= 1.6e-110)) {
tmp = cos(y) * x;
} else {
tmp = -z * sin(y);
}
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 ((x <= (-0.43d0)) .or. (.not. (x <= 1.6d-110))) then
tmp = cos(y) * x
else
tmp = -z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.43) || !(x <= 1.6e-110)) {
tmp = Math.cos(y) * x;
} else {
tmp = -z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.43) or not (x <= 1.6e-110): tmp = math.cos(y) * x else: tmp = -z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.43) || !(x <= 1.6e-110)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(-z) * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.43) || ~((x <= 1.6e-110))) tmp = cos(y) * x; else tmp = -z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.43], N[Not[LessEqual[x, 1.6e-110]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.43 \lor \neg \left(x \leq 1.6 \cdot 10^{-110}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\end{array}
\end{array}
if x < -0.429999999999999993 or 1.60000000000000014e-110 < x Initial program 99.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6453.3
Applied rewrites53.3%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6481.9
Applied rewrites81.9%
if -0.429999999999999993 < x < 1.60000000000000014e-110Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6474.6
Applied rewrites74.6%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.45) (not (<= y 920000.0))) (* (cos y) x) (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.45) || !(y <= 920000.0)) {
tmp = cos(y) * x;
} else {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.45) || !(y <= 920000.0)) tmp = Float64(cos(y) * x); else tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.45], N[Not[LessEqual[y, 920000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.45 \lor \neg \left(y \leq 920000\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\end{array}
\end{array}
if y < -0.450000000000000011 or 9.2e5 < y Initial program 99.7%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6451.4
Applied rewrites51.4%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6450.0
Applied rewrites50.0%
if -0.450000000000000011 < y < 9.2e5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6498.5
Applied rewrites98.5%
Final simplification75.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e-37) (not (<= x 2.5e-171))) (* 1.0 x) (* (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-37) || !(x <= 2.5e-171)) {
tmp = 1.0 * 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 ((x <= (-1.55d-37)) .or. (.not. (x <= 2.5d-171))) then
tmp = 1.0d0 * x
else
tmp = -y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-37) || !(x <= 2.5e-171)) {
tmp = 1.0 * x;
} else {
tmp = -y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e-37) or not (x <= 2.5e-171): tmp = 1.0 * x else: tmp = -y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e-37) || !(x <= 2.5e-171)) tmp = Float64(1.0 * x); else tmp = Float64(Float64(-y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e-37) || ~((x <= 2.5e-171))) tmp = 1.0 * x; else tmp = -y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e-37], N[Not[LessEqual[x, 2.5e-171]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[((-y) * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-37} \lor \neg \left(x \leq 2.5 \cdot 10^{-171}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\end{array}
\end{array}
if x < -1.54999999999999997e-37 or 2.49999999999999996e-171 < x Initial program 99.9%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites98.2%
Taylor expanded in y around 0
Applied rewrites48.8%
if -1.54999999999999997e-37 < x < 2.49999999999999996e-171Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6454.4
Applied rewrites54.4%
Taylor expanded in x around 0
Applied rewrites40.0%
Final simplification46.1%
(FPCore (x y z) :precision binary64 (fma (- z) y x))
double code(double x, double y, double z) {
return fma(-z, y, x);
}
function code(x, y, z) return fma(Float64(-z), y, x) end
code[x_, y_, z_] := N[((-z) * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6452.9
Applied rewrites52.9%
Final simplification52.9%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites91.3%
Taylor expanded in y around 0
Applied rewrites39.2%
Final simplification39.2%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))