
(FPCore (x y z) :precision binary64 :pre TRUE (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x + (y * (z - x))) / z END code
\frac{x + y \cdot \left(z - x\right)}{z}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x + (y * (z - x))) / z END code
\frac{x + y \cdot \left(z - x\right)}{z}
(FPCore (x y z) :precision binary64 :pre TRUE (fma (- 1.0 y) (/ x z) y))
double code(double x, double y, double z) {
return fma((1.0 - y), (x / z), y);
}
function code(x, y, z) return fma(Float64(1.0 - y), Float64(x / z), y) end
code[x_, y_, z_] := N[(N[(1.0 - y), $MachinePrecision] * N[(x / z), $MachinePrecision] + y), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (((1) - y) * (x / z)) + y END code
\mathsf{fma}\left(1 - y, \frac{x}{z}, y\right)
Initial program 87.8%
Applied rewrites87.6%
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* y (/ (- z x) z))))
(if (<= y -83405507.39250578)
t_0
(if (<= y 254.09303055021542) (/ (fma (- z x) y x) z) t_0))))double code(double x, double y, double z) {
double t_0 = y * ((z - x) / z);
double tmp;
if (y <= -83405507.39250578) {
tmp = t_0;
} else if (y <= 254.09303055021542) {
tmp = fma((z - x), y, x) / z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(Float64(z - x) / z)) tmp = 0.0 if (y <= -83405507.39250578) tmp = t_0; elseif (y <= 254.09303055021542) tmp = Float64(fma(Float64(z - x), y, x) / z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -83405507.39250578], t$95$0, If[LessEqual[y, 254.09303055021542], N[(N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (y * ((z - x) / z)) IN LET tmp_1 = IF (y <= (254093030550215416951687075197696685791015625e-42)) THEN ((((z - x) * y) + x) / z) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-8340550739250577986240386962890625e-26)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := y \cdot \frac{z - x}{z}\\
\mathbf{if}\;y \leq -83405507.39250578:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 254.09303055021542:\\
\;\;\;\;\frac{\mathsf{fma}\left(z - x, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -83405507.39250578 or 254.09303055021542 < y Initial program 87.8%
Taylor expanded in y around inf
Applied rewrites53.6%
Applied rewrites67.6%
if -83405507.39250578 < y < 254.09303055021542Initial program 87.8%
Applied rewrites87.8%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* y (/ (- z x) z))))
(if (<= y -2509.0653284185646)
t_0
(if (<= y 3925.6693208389647) (fma y 1.0 (/ x z)) t_0))))double code(double x, double y, double z) {
double t_0 = y * ((z - x) / z);
double tmp;
if (y <= -2509.0653284185646) {
tmp = t_0;
} else if (y <= 3925.6693208389647) {
tmp = fma(y, 1.0, (x / z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(Float64(z - x) / z)) tmp = 0.0 if (y <= -2509.0653284185646) tmp = t_0; elseif (y <= 3925.6693208389647) tmp = fma(y, 1.0, Float64(x / z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2509.0653284185646], t$95$0, If[LessEqual[y, 3925.6693208389647], N[(y * 1.0 + N[(x / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (y * ((z - x) / z)) IN LET tmp_1 = IF (y <= (392566932083896472249762155115604400634765625e-41)) THEN ((y * (1)) + (x / z)) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-250906532841856460436247289180755615234375e-38)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := y \cdot \frac{z - x}{z}\\
\mathbf{if}\;y \leq -2509.0653284185646:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3925.6693208389647:\\
\;\;\;\;\mathsf{fma}\left(y, 1, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -2509.0653284185646 or 3925.6693208389647 < y Initial program 87.8%
Taylor expanded in y around inf
Applied rewrites53.6%
Applied rewrites67.6%
if -2509.0653284185646 < y < 3925.6693208389647Initial program 87.8%
Applied rewrites93.4%
Taylor expanded in x around 0
Applied rewrites78.2%
(FPCore (x y z) :precision binary64 :pre TRUE (fma x (/ (- 1.0 y) z) y))
double code(double x, double y, double z) {
return fma(x, ((1.0 - y) / z), y);
}
function code(x, y, z) return fma(x, Float64(Float64(1.0 - y) / z), y) end
code[x_, y_, z_] := N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision] + y), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (((1) - y) / z)) + y END code
\mathsf{fma}\left(x, \frac{1 - y}{z}, y\right)
Initial program 87.8%
Applied rewrites87.6%
Applied rewrites99.9%
Applied rewrites95.5%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= y 2.5235973101497354e+178) (fma y 1.0 (/ x z)) (* z (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.5235973101497354e+178) {
tmp = fma(y, 1.0, (x / z));
} else {
tmp = z * (y / z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.5235973101497354e+178) tmp = fma(y, 1.0, Float64(x / z)); else tmp = Float64(z * Float64(y / z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.5235973101497354e+178], N[(y * 1.0 + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp = IF (y <= (25235973101497354482214954917900760340524771587181319724948153287136140190976829088846080717156719018215736973452903454574359277303968890614466637516791816677995228882765573259264)) THEN ((y * (1)) + (x / z)) ELSE (z * (y / z)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq 2.5235973101497354 \cdot 10^{+178}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\end{array}
if y < 2.5235973101497354e178Initial program 87.8%
Applied rewrites93.4%
Taylor expanded in x around 0
Applied rewrites78.2%
if 2.5235973101497354e178 < y Initial program 87.8%
Taylor expanded in y around inf
Applied rewrites53.6%
Applied rewrites55.7%
Taylor expanded in x around 0
Applied rewrites36.9%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* z (/ y z))))
(if (<= y -1.3808892104572836)
t_0
(if (<= y 5.71392951001371e-24) (/ x z) t_0))))double code(double x, double y, double z) {
double t_0 = z * (y / z);
double tmp;
if (y <= -1.3808892104572836) {
tmp = t_0;
} else if (y <= 5.71392951001371e-24) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = z * (y / z)
if (y <= (-1.3808892104572836d0)) then
tmp = t_0
else if (y <= 5.71392951001371d-24) then
tmp = x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y / z);
double tmp;
if (y <= -1.3808892104572836) {
tmp = t_0;
} else if (y <= 5.71392951001371e-24) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y / z) tmp = 0 if y <= -1.3808892104572836: tmp = t_0 elif y <= 5.71392951001371e-24: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y / z)) tmp = 0.0 if (y <= -1.3808892104572836) tmp = t_0; elseif (y <= 5.71392951001371e-24) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y / z); tmp = 0.0; if (y <= -1.3808892104572836) tmp = t_0; elseif (y <= 5.71392951001371e-24) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.3808892104572836], t$95$0, If[LessEqual[y, 5.71392951001371e-24], N[(x / z), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (z * (y / z)) IN LET tmp_1 = IF (y <= (5713929510013710309954588345103281388526423837570695643911942366958978123392398629221133887767791748046875e-129)) THEN (x / z) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-13808892104572836334597241148003377020359039306640625e-52)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := z \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -1.3808892104572836:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.71392951001371 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -1.3808892104572836 or 5.7139295100137103e-24 < y Initial program 87.8%
Taylor expanded in y around inf
Applied rewrites53.6%
Applied rewrites55.7%
Taylor expanded in x around 0
Applied rewrites36.9%
if -1.3808892104572836 < y < 5.7139295100137103e-24Initial program 87.8%
Taylor expanded in y around 0
Applied rewrites39.8%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= y -4.396452877645846e-84) y (if (<= y 5.71392951001371e-24) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.396452877645846e-84) {
tmp = y;
} else if (y <= 5.71392951001371e-24) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-4.396452877645846d-84)) then
tmp = y
else if (y <= 5.71392951001371d-24) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.396452877645846e-84) {
tmp = y;
} else if (y <= 5.71392951001371e-24) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.396452877645846e-84: tmp = y elif y <= 5.71392951001371e-24: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.396452877645846e-84) tmp = y; elseif (y <= 5.71392951001371e-24) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.396452877645846e-84) tmp = y; elseif (y <= 5.71392951001371e-24) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.396452877645846e-84], y, If[LessEqual[y, 5.71392951001371e-24], N[(x / z), $MachinePrecision], y]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (y <= (5713929510013710309954588345103281388526423837570695643911942366958978123392398629221133887767791748046875e-129)) THEN (x / z) ELSE y ENDIF IN LET tmp = IF (y <= (-43964528776458464081694827798763004894182085276933175051225769637393906829390866746776185321362175168060435304308169415223731245090346098651524509615456527276516670822493343078795340840138714666963115911164916571607363948714919388294219970703125e-328)) THEN y ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -4.396452877645846 \cdot 10^{-84}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.71392951001371 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
if y < -4.3964528776458464e-84 or 5.7139295100137103e-24 < y Initial program 87.8%
Taylor expanded in x around 0
Applied rewrites40.8%
if -4.3964528776458464e-84 < y < 5.7139295100137103e-24Initial program 87.8%
Taylor expanded in y around 0
Applied rewrites39.8%
(FPCore (x y z) :precision binary64 :pre TRUE y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = y END code
y
Initial program 87.8%
Taylor expanded in x around 0
Applied rewrites40.8%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
(/ (+ x (* y (- z x))) z))