| Alternative 1 | |
|---|---|
| Error | 44.1 |
| Cost | 64 |
\[x
\]
(FPCore (x y z t a b) :precision binary64 (* (* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0))) (cos (/ (* (* (+ (* a 2.0) 1.0) b) t) 16.0))))
(FPCore (x y z t a b)
:precision binary64
(if (<=
(*
(* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0)))
(cos (/ (* t (* (+ 1.0 (* 2.0 a)) b)) 16.0)))
1e+270)
(*
x
(* (cos (* t (* y (* z 0.125)))) (cos (* (* t b) (+ 0.0625 (* a 0.125))))))
x))double code(double x, double y, double z, double t, double a, double b) {
return (x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0));
}
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 1e+270) {
tmp = x * (cos((t * (y * (z * 0.125)))) * cos(((t * b) * (0.0625 + (a * 0.125)))));
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (x * cos((((((y * 2.0d0) + 1.0d0) * z) * t) / 16.0d0))) * cos((((((a * 2.0d0) + 1.0d0) * b) * t) / 16.0d0))
end function
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (((x * cos((((((y * 2.0d0) + 1.0d0) * z) * t) / 16.0d0))) * cos(((t * ((1.0d0 + (2.0d0 * a)) * b)) / 16.0d0))) <= 1d+270) then
tmp = x * (cos((t * (y * (z * 0.125d0)))) * cos(((t * b) * (0.0625d0 + (a * 0.125d0)))))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x * Math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * Math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0));
}
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * Math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * Math.cos(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 1e+270) {
tmp = x * (Math.cos((t * (y * (z * 0.125)))) * Math.cos(((t * b) * (0.0625 + (a * 0.125)))));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a, b): return (x * math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0))
def code(x, y, z, t, a, b): tmp = 0 if ((x * math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * math.cos(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 1e+270: tmp = x * (math.cos((t * (y * (z * 0.125)))) * math.cos(((t * b) * (0.0625 + (a * 0.125))))) else: tmp = x return tmp
function code(x, y, z, t, a, b) return Float64(Float64(x * cos(Float64(Float64(Float64(Float64(Float64(y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(Float64(Float64(Float64(Float64(Float64(a * 2.0) + 1.0) * b) * t) / 16.0))) end
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(Float64(x * cos(Float64(Float64(Float64(Float64(Float64(y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(Float64(Float64(t * Float64(Float64(1.0 + Float64(2.0 * a)) * b)) / 16.0))) <= 1e+270) tmp = Float64(x * Float64(cos(Float64(t * Float64(y * Float64(z * 0.125)))) * cos(Float64(Float64(t * b) * Float64(0.0625 + Float64(a * 0.125)))))); else tmp = x; end return tmp end
function tmp = code(x, y, z, t, a, b) tmp = (x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0)); end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 1e+270) tmp = x * (cos((t * (y * (z * 0.125)))) * cos(((t * b) * (0.0625 + (a * 0.125))))); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * N[Cos[N[(N[(N[(N[(N[(y * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(N[(N[(N[(a * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * b), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(N[(x * N[Cos[N[(N[(N[(N[(N[(y * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(t * N[(N[(1.0 + N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1e+270], N[(x * N[(N[Cos[N[(t * N[(y * N[(z * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(t * b), $MachinePrecision] * N[(0.0625 + N[(a * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)
\begin{array}{l}
\mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{t \cdot \left(\left(1 + 2 \cdot a\right) \cdot b\right)}{16}\right) \leq 10^{+270}:\\
\;\;\;\;x \cdot \left(\cos \left(t \cdot \left(y \cdot \left(z \cdot 0.125\right)\right)\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + a \cdot 0.125\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
Results
| Original | 45.9 |
|---|---|
| Target | 44.3 |
| Herbie | 43.5 |
if (*.f64 (*.f64 x (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 y 2) 1) z) t) 16))) (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 a 2) 1) b) t) 16))) < 1e270Initial program 33.9
Simplified34.2
[Start]33.9 | \[ \left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)
\] |
|---|---|
associate-*l* [=>]33.9 | \[ \color{blue}{x \cdot \left(\cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)\right)}
\] |
Taylor expanded in y around inf 34.4
Simplified34.4
[Start]34.4 | \[ x \cdot \left(\cos \left(0.125 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
|---|---|
*-commutative [=>]34.4 | \[ x \cdot \left(\cos \left(0.125 \cdot \left(y \cdot \color{blue}{\left(z \cdot t\right)}\right)\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
associate-*r* [=>]34.4 | \[ x \cdot \left(\cos \color{blue}{\left(\left(0.125 \cdot y\right) \cdot \left(z \cdot t\right)\right)} \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
associate-*r* [=>]34.4 | \[ x \cdot \left(\cos \color{blue}{\left(\left(\left(0.125 \cdot y\right) \cdot z\right) \cdot t\right)} \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
*-commutative [<=]34.4 | \[ x \cdot \left(\cos \color{blue}{\left(t \cdot \left(\left(0.125 \cdot y\right) \cdot z\right)\right)} \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
*-commutative [=>]34.4 | \[ x \cdot \left(\cos \left(t \cdot \left(\color{blue}{\left(y \cdot 0.125\right)} \cdot z\right)\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
associate-*l* [=>]34.4 | \[ x \cdot \left(\cos \left(t \cdot \color{blue}{\left(y \cdot \left(0.125 \cdot z\right)\right)}\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(0.0625 + 0.125 \cdot a\right)\right)\right)
\] |
if 1e270 < (*.f64 (*.f64 x (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 y 2) 1) z) t) 16))) (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 a 2) 1) b) t) 16))) Initial program 62.8
Simplified61.5
[Start]62.8 | \[ \left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)
\] |
|---|---|
associate-*l* [=>]62.8 | \[ \color{blue}{x \cdot \left(\cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)\right)}
\] |
Taylor expanded in z around 0 59.5
Taylor expanded in t around 0 56.3
Final simplification43.5
| Alternative 1 | |
|---|---|
| Error | 44.1 |
| Cost | 64 |
herbie shell --seed 2023066
(FPCore (x y z t a b)
:name "Codec.Picture.Jpg.FastDct:referenceDct from JuicyPixels-3.2.6.1"
:precision binary64
:herbie-target
(* x (cos (* (/ b 16.0) (/ t (+ (- 1.0 (* a 2.0)) (pow (* a 2.0) 2.0))))))
(* (* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0))) (cos (/ (* (* (+ (* a 2.0) 1.0) b) t) 16.0))))