
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
(FPCore (x y) :precision binary64 (- (+ 1.0 (* y x)) y))
double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (y * x)) - y
end function
public static double code(double x, double y) {
return (1.0 + (y * x)) - y;
}
def code(x, y): return (1.0 + (y * x)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(y * x)) - y) end
function tmp = code(x, y) tmp = (1.0 + (y * x)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(y * x), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + y \cdot x\right) - y
\end{array}
Initial program 78.4%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -3.35e-9)
(* y x)
(if (<= y 3.8e-34)
1.0
(if (<= y 1.56e+40) (* y x) (if (<= y 9e+302) (- y) (* y x))))))
double code(double x, double y) {
double tmp;
if (y <= -3.35e-9) {
tmp = y * x;
} else if (y <= 3.8e-34) {
tmp = 1.0;
} else if (y <= 1.56e+40) {
tmp = y * x;
} else if (y <= 9e+302) {
tmp = -y;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.35d-9)) then
tmp = y * x
else if (y <= 3.8d-34) then
tmp = 1.0d0
else if (y <= 1.56d+40) then
tmp = y * x
else if (y <= 9d+302) then
tmp = -y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.35e-9) {
tmp = y * x;
} else if (y <= 3.8e-34) {
tmp = 1.0;
} else if (y <= 1.56e+40) {
tmp = y * x;
} else if (y <= 9e+302) {
tmp = -y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.35e-9: tmp = y * x elif y <= 3.8e-34: tmp = 1.0 elif y <= 1.56e+40: tmp = y * x elif y <= 9e+302: tmp = -y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -3.35e-9) tmp = Float64(y * x); elseif (y <= 3.8e-34) tmp = 1.0; elseif (y <= 1.56e+40) tmp = Float64(y * x); elseif (y <= 9e+302) tmp = Float64(-y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.35e-9) tmp = y * x; elseif (y <= 3.8e-34) tmp = 1.0; elseif (y <= 1.56e+40) tmp = y * x; elseif (y <= 9e+302) tmp = -y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.35e-9], N[(y * x), $MachinePrecision], If[LessEqual[y, 3.8e-34], 1.0, If[LessEqual[y, 1.56e+40], N[(y * x), $MachinePrecision], If[LessEqual[y, 9e+302], (-y), N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.35 \cdot 10^{-9}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-34}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.56 \cdot 10^{+40}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+302}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.34999999999999981e-9 or 3.8000000000000001e-34 < y < 1.56e40 or 9.0000000000000003e302 < y Initial program 95.9%
Taylor expanded in x around inf 56.1%
mul-1-neg56.1%
unsub-neg56.1%
sub-neg56.1%
associate--r+59.8%
metadata-eval59.8%
neg-sub059.8%
remove-double-neg59.8%
Simplified59.8%
if -3.34999999999999981e-9 < y < 3.8000000000000001e-34Initial program 57.8%
Taylor expanded in y around 0 79.7%
if 1.56e40 < y < 9.0000000000000003e302Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
distribute-neg-in100.0%
metadata-eval100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 56.5%
neg-mul-156.5%
Simplified56.5%
Final simplification68.7%
(FPCore (x y) :precision binary64 (if (or (<= y -58000.0) (not (<= y 9.8e-34))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -58000.0) || !(y <= 9.8e-34)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-58000.0d0)) .or. (.not. (y <= 9.8d-34))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -58000.0) || !(y <= 9.8e-34)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -58000.0) or not (y <= 9.8e-34): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((y <= -58000.0) || !(y <= 9.8e-34)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -58000.0) || ~((y <= 9.8e-34))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -58000.0], N[Not[LessEqual[y, 9.8e-34]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -58000 \lor \neg \left(y \leq 9.8 \cdot 10^{-34}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -58000 or 9.79999999999999925e-34 < y Initial program 97.3%
Taylor expanded in y around inf 98.5%
mul-1-neg98.5%
distribute-rgt-neg-in98.5%
sub-neg98.5%
distribute-neg-in98.5%
metadata-eval98.5%
remove-double-neg98.5%
Simplified98.5%
if -58000 < y < 9.79999999999999925e-34Initial program 58.9%
Taylor expanded in x around 0 80.1%
Final simplification89.4%
(FPCore (x y) :precision binary64 (if (<= x -440.0) (* y x) (if (<= x 7.5e+51) (- 1.0 y) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -440.0) {
tmp = y * x;
} else if (x <= 7.5e+51) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-440.0d0)) then
tmp = y * x
else if (x <= 7.5d+51) then
tmp = 1.0d0 - y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -440.0) {
tmp = y * x;
} else if (x <= 7.5e+51) {
tmp = 1.0 - y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -440.0: tmp = y * x elif x <= 7.5e+51: tmp = 1.0 - y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -440.0) tmp = Float64(y * x); elseif (x <= 7.5e+51) tmp = Float64(1.0 - y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -440.0) tmp = y * x; elseif (x <= 7.5e+51) tmp = 1.0 - y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -440.0], N[(y * x), $MachinePrecision], If[LessEqual[x, 7.5e+51], N[(1.0 - y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -440:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+51}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -440 or 7.4999999999999999e51 < x Initial program 57.9%
Taylor expanded in x around inf 56.5%
mul-1-neg56.5%
unsub-neg56.5%
sub-neg56.5%
associate--r+79.0%
metadata-eval79.0%
neg-sub079.0%
remove-double-neg79.0%
Simplified79.0%
if -440 < x < 7.4999999999999999e51Initial program 95.2%
Taylor expanded in x around 0 96.0%
Final simplification88.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 1.7e-10) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.7e-10) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = -y
else if (y <= 1.7d-10) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 1.7e-10) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 1.7e-10: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 1.7e-10) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 1.7e-10) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 1.7e-10], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-10}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 1.70000000000000007e-10 < y Initial program 99.6%
Taylor expanded in y around inf 97.8%
mul-1-neg97.8%
distribute-rgt-neg-in97.8%
sub-neg97.8%
distribute-neg-in97.8%
metadata-eval97.8%
remove-double-neg97.8%
Simplified97.8%
Taylor expanded in x around 0 45.8%
neg-mul-145.8%
Simplified45.8%
if -1 < y < 1.70000000000000007e-10Initial program 57.0%
Taylor expanded in y around 0 76.9%
Final simplification61.2%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 78.4%
Taylor expanded in y around 0 39.7%
Final simplification39.7%
(FPCore (x y) :precision binary64 (- (* y x) (- y 1.0)))
double code(double x, double y) {
return (y * x) - (y - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * x) - (y - 1.0d0)
end function
public static double code(double x, double y) {
return (y * x) - (y - 1.0);
}
def code(x, y): return (y * x) - (y - 1.0)
function code(x, y) return Float64(Float64(y * x) - Float64(y - 1.0)) end
function tmp = code(x, y) tmp = (y * x) - (y - 1.0); end
code[x_, y_] := N[(N[(y * x), $MachinePrecision] - N[(y - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x - \left(y - 1\right)
\end{array}
herbie shell --seed 2023171
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))