
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (+ (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) + x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) + x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (<= z -5e+29) (* (cos y) z) (if (<= z 1.05e+70) (+ (+ x (sin y)) (* z 1.0)) (fma (cos y) z (+ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e+29) {
tmp = cos(y) * z;
} else if (z <= 1.05e+70) {
tmp = (x + sin(y)) + (z * 1.0);
} else {
tmp = fma(cos(y), z, (x + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5e+29) tmp = Float64(cos(y) * z); elseif (z <= 1.05e+70) tmp = Float64(Float64(x + sin(y)) + Float64(z * 1.0)); else tmp = fma(cos(y), z, Float64(x + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5e+29], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 1.05e+70], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+29}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+70}:\\
\;\;\;\;\left(x + \sin y\right) + z \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\end{array}
\end{array}
if z < -5.0000000000000001e29Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6489.0
Applied rewrites89.0%
if -5.0000000000000001e29 < z < 1.05000000000000004e70Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.4%
if 1.05000000000000004e70 < z Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower-+.f6490.5
Applied rewrites90.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.9e+18) (* (cos y) z) (if (<= z 1.45e-14) (+ (sin y) x) (fma (cos y) z (+ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e+18) {
tmp = cos(y) * z;
} else if (z <= 1.45e-14) {
tmp = sin(y) + x;
} else {
tmp = fma(cos(y), z, (x + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.9e+18) tmp = Float64(cos(y) * z); elseif (z <= 1.45e-14) tmp = Float64(sin(y) + x); else tmp = fma(cos(y), z, Float64(x + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.9e+18], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 1.45e-14], N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+18}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-14}:\\
\;\;\;\;\sin y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\end{array}
\end{array}
if z < -1.9e18Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6487.9
Applied rewrites87.9%
if -1.9e18 < z < 1.4500000000000001e-14Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
+-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
lower-fma.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
associate-*l/N/A
associate-/l*N/A
*-rgt-identityN/A
Applied rewrites99.9%
Taylor expanded in z around 0
Applied rewrites92.8%
if 1.4500000000000001e-14 < z Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower-+.f6482.3
Applied rewrites82.3%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.9e+18) (not (<= z 1.75e+18))) (* (cos y) z) (+ (sin y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+18) || !(z <= 1.75e+18)) {
tmp = cos(y) * z;
} else {
tmp = sin(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.9d+18)) .or. (.not. (z <= 1.75d+18))) then
tmp = cos(y) * z
else
tmp = sin(y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+18) || !(z <= 1.75e+18)) {
tmp = Math.cos(y) * z;
} else {
tmp = Math.sin(y) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e+18) or not (z <= 1.75e+18): tmp = math.cos(y) * z else: tmp = math.sin(y) + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e+18) || !(z <= 1.75e+18)) tmp = Float64(cos(y) * z); else tmp = Float64(sin(y) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.9e+18) || ~((z <= 1.75e+18))) tmp = cos(y) * z; else tmp = sin(y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e+18], N[Not[LessEqual[z, 1.75e+18]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+18} \lor \neg \left(z \leq 1.75 \cdot 10^{+18}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y + x\\
\end{array}
\end{array}
if z < -1.9e18 or 1.75e18 < z Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6483.0
Applied rewrites83.0%
if -1.9e18 < z < 1.75e18Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
+-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
lower-fma.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
associate-*l/N/A
associate-/l*N/A
*-rgt-identityN/A
Applied rewrites99.9%
Taylor expanded in z around 0
Applied rewrites91.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -14500000.0) (not (<= y 0.026))) (+ (sin y) x) (+ (+ y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -14500000.0) || !(y <= 0.026)) {
tmp = sin(y) + x;
} else {
tmp = (y + x) + 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 ((y <= (-14500000.0d0)) .or. (.not. (y <= 0.026d0))) then
tmp = sin(y) + x
else
tmp = (y + x) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -14500000.0) || !(y <= 0.026)) {
tmp = Math.sin(y) + x;
} else {
tmp = (y + x) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -14500000.0) or not (y <= 0.026): tmp = math.sin(y) + x else: tmp = (y + x) + z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -14500000.0) || !(y <= 0.026)) tmp = Float64(sin(y) + x); else tmp = Float64(Float64(y + x) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -14500000.0) || ~((y <= 0.026))) tmp = sin(y) + x; else tmp = (y + x) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -14500000.0], N[Not[LessEqual[y, 0.026]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -14500000 \lor \neg \left(y \leq 0.026\right):\\
\;\;\;\;\sin y + x\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) + z\\
\end{array}
\end{array}
if y < -1.45e7 or 0.0259999999999999988 < y Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
+-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
lower-fma.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
associate-*l/N/A
associate-/l*N/A
*-rgt-identityN/A
Applied rewrites92.4%
Taylor expanded in z around 0
Applied rewrites61.3%
if -1.45e7 < y < 0.0259999999999999988Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e+31) (not (<= y 9.2e+18))) (+ z x) (+ (+ y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e+31) || !(y <= 9.2e+18)) {
tmp = z + x;
} else {
tmp = (y + x) + 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 ((y <= (-2.7d+31)) .or. (.not. (y <= 9.2d+18))) then
tmp = z + x
else
tmp = (y + x) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e+31) || !(y <= 9.2e+18)) {
tmp = z + x;
} else {
tmp = (y + x) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e+31) or not (y <= 9.2e+18): tmp = z + x else: tmp = (y + x) + z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e+31) || !(y <= 9.2e+18)) tmp = Float64(z + x); else tmp = Float64(Float64(y + x) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.7e+31) || ~((y <= 9.2e+18))) tmp = z + x; else tmp = (y + x) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e+31], N[Not[LessEqual[y, 9.2e+18]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+31} \lor \neg \left(y \leq 9.2 \cdot 10^{+18}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) + z\\
\end{array}
\end{array}
if y < -2.69999999999999986e31 or 9.2e18 < y Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6437.8
Applied rewrites37.8%
if -2.69999999999999986e31 < y < 9.2e18Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6493.3
Applied rewrites93.3%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.15e-93) (not (<= x 1.25e-246))) (+ z x) (+ z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.15e-93) || !(x <= 1.25e-246)) {
tmp = z + x;
} else {
tmp = z + 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 <= (-3.15d-93)) .or. (.not. (x <= 1.25d-246))) then
tmp = z + x
else
tmp = z + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.15e-93) || !(x <= 1.25e-246)) {
tmp = z + x;
} else {
tmp = z + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.15e-93) or not (x <= 1.25e-246): tmp = z + x else: tmp = z + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.15e-93) || !(x <= 1.25e-246)) tmp = Float64(z + x); else tmp = Float64(z + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.15e-93) || ~((x <= 1.25e-246))) tmp = z + x; else tmp = z + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.15e-93], N[Not[LessEqual[x, 1.25e-246]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(z + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.15 \cdot 10^{-93} \lor \neg \left(x \leq 1.25 \cdot 10^{-246}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;z + y\\
\end{array}
\end{array}
if x < -3.15000000000000014e-93 or 1.2499999999999999e-246 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6472.2
Applied rewrites72.2%
if -3.15000000000000014e-93 < x < 1.2499999999999999e-246Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
Applied rewrites53.9%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6462.4
Applied rewrites62.4%
Taylor expanded in y around 0
Applied rewrites32.6%
Final simplification32.6%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))