
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+298) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* (* z -4.0) (* z y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+298) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z * z) <= 5d+298) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (z * (-4.0d0)) * (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+298) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 5e+298: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (z * -4.0) * (z * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+298) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(z * -4.0) * Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 5e+298) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (z * -4.0) * (z * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+298], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * -4.0), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+298}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000003e298Initial program 96.4%
if 5.0000000000000003e298 < (*.f64 z z) Initial program 65.9%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6474.0
Applied rewrites74.0%
Applied rewrites92.0%
Final simplification95.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* z z) t)))
(if (<= t_1 -1e-107)
(* y (* 4.0 t))
(if (<= t_1 5e+203) (* x x) (* (* z -4.0) (* z y))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -1e-107) {
tmp = y * (4.0 * t);
} else if (t_1 <= 5e+203) {
tmp = x * x;
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (z * z) - t
if (t_1 <= (-1d-107)) then
tmp = y * (4.0d0 * t)
else if (t_1 <= 5d+203) then
tmp = x * x
else
tmp = (z * (-4.0d0)) * (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -1e-107) {
tmp = y * (4.0 * t);
} else if (t_1 <= 5e+203) {
tmp = x * x;
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * z) - t tmp = 0 if t_1 <= -1e-107: tmp = y * (4.0 * t) elif t_1 <= 5e+203: tmp = x * x else: tmp = (z * -4.0) * (z * y) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * z) - t) tmp = 0.0 if (t_1 <= -1e-107) tmp = Float64(y * Float64(4.0 * t)); elseif (t_1 <= 5e+203) tmp = Float64(x * x); else tmp = Float64(Float64(z * -4.0) * Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * z) - t; tmp = 0.0; if (t_1 <= -1e-107) tmp = y * (4.0 * t); elseif (t_1 <= 5e+203) tmp = x * x; else tmp = (z * -4.0) * (z * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-107], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+203], N[(x * x), $MachinePrecision], N[(N[(z * -4.0), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot z - t\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-107}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 z z) t) < -1e-107Initial program 98.2%
Taylor expanded in t around inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.5
Applied rewrites71.5%
if -1e-107 < (-.f64 (*.f64 z z) t) < 4.99999999999999994e203Initial program 97.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
if 4.99999999999999994e203 < (-.f64 (*.f64 z z) t) Initial program 74.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.6
Applied rewrites63.6%
Applied rewrites75.3%
Final simplification69.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* z z) t)))
(if (<= t_1 -1e-107)
(* y (* 4.0 t))
(if (<= t_1 5e+203) (* x x) (* -4.0 (* (* z z) y))))))
double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -1e-107) {
tmp = y * (4.0 * t);
} else if (t_1 <= 5e+203) {
tmp = x * x;
} else {
tmp = -4.0 * ((z * z) * y);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (z * z) - t
if (t_1 <= (-1d-107)) then
tmp = y * (4.0d0 * t)
else if (t_1 <= 5d+203) then
tmp = x * x
else
tmp = (-4.0d0) * ((z * z) * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z * z) - t;
double tmp;
if (t_1 <= -1e-107) {
tmp = y * (4.0 * t);
} else if (t_1 <= 5e+203) {
tmp = x * x;
} else {
tmp = -4.0 * ((z * z) * y);
}
return tmp;
}
def code(x, y, z, t): t_1 = (z * z) - t tmp = 0 if t_1 <= -1e-107: tmp = y * (4.0 * t) elif t_1 <= 5e+203: tmp = x * x else: tmp = -4.0 * ((z * z) * y) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z * z) - t) tmp = 0.0 if (t_1 <= -1e-107) tmp = Float64(y * Float64(4.0 * t)); elseif (t_1 <= 5e+203) tmp = Float64(x * x); else tmp = Float64(-4.0 * Float64(Float64(z * z) * y)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z * z) - t; tmp = 0.0; if (t_1 <= -1e-107) tmp = y * (4.0 * t); elseif (t_1 <= 5e+203) tmp = x * x; else tmp = -4.0 * ((z * z) * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-107], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+203], N[(x * x), $MachinePrecision], N[(-4.0 * N[(N[(z * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot z - t\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-107}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(z \cdot z\right) \cdot y\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 z z) t) < -1e-107Initial program 98.2%
Taylor expanded in t around inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.5
Applied rewrites71.5%
if -1e-107 < (-.f64 (*.f64 z z) t) < 4.99999999999999994e203Initial program 97.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
if 4.99999999999999994e203 < (-.f64 (*.f64 z z) t) Initial program 74.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.6
Applied rewrites63.6%
Final simplification65.5%
(FPCore (x y z t)
:precision binary64
(if (<= z 6.6e+52)
(fma y (* 4.0 t) (* x x))
(if (<= z 1.95e+217)
(- (* x x) (* z (* y (* z 4.0))))
(* (* z -4.0) (* z y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 6.6e+52) {
tmp = fma(y, (4.0 * t), (x * x));
} else if (z <= 1.95e+217) {
tmp = (x * x) - (z * (y * (z * 4.0)));
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 6.6e+52) tmp = fma(y, Float64(4.0 * t), Float64(x * x)); elseif (z <= 1.95e+217) tmp = Float64(Float64(x * x) - Float64(z * Float64(y * Float64(z * 4.0)))); else tmp = Float64(Float64(z * -4.0) * Float64(z * y)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 6.6e+52], N[(y * N[(4.0 * t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.95e+217], N[(N[(x * x), $MachinePrecision] - N[(z * N[(y * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * -4.0), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.6 \cdot 10^{+52}:\\
\;\;\;\;\mathsf{fma}\left(y, 4 \cdot t, x \cdot x\right)\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+217}:\\
\;\;\;\;x \cdot x - z \cdot \left(y \cdot \left(z \cdot 4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if z < 6.6e52Initial program 91.4%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.1
Applied rewrites78.1%
if 6.6e52 < z < 1.94999999999999997e217Initial program 77.3%
Taylor expanded in z around inf
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6480.1
Applied rewrites80.1%
if 1.94999999999999997e217 < z Initial program 77.5%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.9
Applied rewrites92.9%
Applied rewrites100.0%
Final simplification79.4%
(FPCore (x y z t) :precision binary64 (if (<= z 1e+97) (fma y (* 4.0 t) (* x x)) (* (* z -4.0) (* z y))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1e+97) {
tmp = fma(y, (4.0 * t), (x * x));
} else {
tmp = (z * -4.0) * (z * y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 1e+97) tmp = fma(y, Float64(4.0 * t), Float64(x * x)); else tmp = Float64(Float64(z * -4.0) * Float64(z * y)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 1e+97], N[(y * N[(4.0 * t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(z * -4.0), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{+97}:\\
\;\;\;\;\mathsf{fma}\left(y, 4 \cdot t, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if z < 1.0000000000000001e97Initial program 91.2%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6477.4
Applied rewrites77.4%
if 1.0000000000000001e97 < z Initial program 75.7%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.1
Applied rewrites73.1%
Applied rewrites83.3%
Final simplification78.3%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 2.6e-49) (* y (* 4.0 t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2.6e-49) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x * x) <= 2.6d-49) then
tmp = y * (4.0d0 * t)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2.6e-49) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 2.6e-49: tmp = y * (4.0 * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 2.6e-49) tmp = Float64(y * Float64(4.0 * t)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 2.6e-49) tmp = y * (4.0 * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.6e-49], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.6 \cdot 10^{-49}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.59999999999999995e-49Initial program 93.9%
Taylor expanded in t around inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
if 2.59999999999999995e-49 < (*.f64 x x) Initial program 85.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6464.7
Applied rewrites64.7%
Final simplification62.7%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x * x
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 89.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6441.8
Applied rewrites41.8%
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * x) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t): return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t)))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (4.0 * (y * ((z * z) - t))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}
herbie shell --seed 2024221
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))